public static void DownloadMissingFilesNew(InstallationDataModel version) { _client = new TcpClient(_ip, _port); if (version.MissingFiles.Count == 0) { version = ChecksumTool.RecheckVersion(version); RequestVersionMissingFiles(ref version); } DownloadProgressEventArgs args = new DownloadProgressEventArgs(); PatchDataModel model = new PatchDataModel() { RequestType = PatchNetworkRequest.DownloadFiles, InstalledVersion = new InstallationDataModel { VersionName = version.VersionName, VersionBranch = version.VersionBranch, MissingFiles = version.MissingFiles } }; args.Version = version.VersionBranch; args.TotalSize = version.TotalSize; ConnectionHandler.SendObject(model, _client); _downloadingFiles = true; //While there's still files missing and there's still an active connection while (version.MissingFiles.Count > 0 && ConnectionHandler.Connected(_client)) { if (_client.GetStream().DataAvailable) { //Raise download progress event args.NextFileName = version.MissingFiles[0].FilePath; OnDownloadProgress(args); //Handle incoming file // await ConnectionHandler.ReadFileAsync(_client, version.MissingFiles[0].FilePath, InstallPath + '/' + version.VersionName); ConnectionHandler.ReadFileStream(_client, version.MissingFiles[0].FilePath, version.MissingFiles[0].Size, version.InstallPath); Console.WriteLine(ConsoleExtension.AddTimestamp(version.MissingFiles[0].FilePath + " downloaded")); args.DownloadedTotal += version.MissingFiles[0].Size; lock (version) version.MissingFiles.RemoveAt(0); } } _downloadingFiles = false; Console.WriteLine(ConsoleExtension.AddTimestamp("All missing files received!")); version = ChecksumTool.RecheckVersion(version); RequestVerifyVersion(ref version); _client.GetStream().Close(); _client.Close(); DownloadDone?.Invoke(version); }
/// <summary> /// アプリを更新するかどうかイベントを通して確認します。 /// </summary> private bool OnDownloadDone(bool cancelled, Exception ex) { var e = new DownloadDoneEventArgs { IsUpdate = false, ApplicationConfig = this.config, LatestVersion = this.latestVersion, IsCancelled = cancelled, Error = ex, }; DownloadDone.SafeRaiseEvent(this, e); return(e.IsUpdate); }