コード例 #1
0
ファイル: Arma3SyncService.cs プロジェクト: Exitera/launcher
        private void DeserializeRemoteRepository(string javaPath, Repository repository)
        {
            try
            {
                string        tempPath = Path.GetTempPath() + repository.Name + "repoInfo";
                FtpWebRequest request  = (FtpWebRequest)WebRequest.Create(string.Format(ApplicationConfig.Arma3SyncRemoteServerInfo, repository.Address));
                request.Method      = WebRequestMethods.Ftp.DownloadFile;
                request.Credentials = new NetworkCredential(repository.Login, repository.Password);

                FtpWebResponse response       = (FtpWebResponse)_networkAccessor.GetWebResponse(request);
                Stream         responseStream = response.GetResponseStream();
                using (Stream s = _fileAccessor.CreateFile(tempPath))
                {
                    responseStream?.CopyTo(s);
                }

                Process p = new Process
                {
                    StartInfo =
                    {
                        UseShellExecute        = false,
                        RedirectStandardOutput = true,
                        CreateNoWindow         = true,
                        FileName  = !string.IsNullOrEmpty(javaPath) ? javaPath : ApplicationConfig.JavaPathCommand,
                        Arguments = " -jar " + ApplicationConfig.A3SdsPath + " -deserializeServerInfo \"" + tempPath + "\""
                    }
                };
                _processAccessor.Start(p);
                string   remoteRepository     = _processAccessor.GetStandardOutput(p).ReadToEnd();
                string[] remoteRepositoryInfo = remoteRepository.TrimEnd('\r', '\n').Split(',');
                _processAccessor.WaitForExit(p);

                //Delete temp file
                _fileAccessor.DeleteFile(tempPath);

                if (remoteRepositoryInfo.Length == 2)
                {
                    repository.RemoteRevision = remoteRepositoryInfo[0];
                }
            }
            catch (WebException e)
            {
                Logger.LogException("Arma3SyncService", "Error deserializing remote repository", e);
            }
        }