public async Task DownloadLatestVersion(ITaskProgress taskProgress) { cachedResponse ??= await InternalCheckForUpdates(); if (cachedResponse != null) { var progress = new Progress <(long downloaded, long?totalBytes)>((v) => { var isDownloaded = (v.totalBytes.HasValue && v.totalBytes.Value == v.downloaded) || v.downloaded == -1; var isStatusKnown = v.totalBytes.HasValue; var currentProgress = v.totalBytes.HasValue ? (int)v.downloaded : (v.downloaded < 0 ? 1 : 0); var maxProgress = v.totalBytes ?? 1; if (taskProgress.State == TaskState.InProgress) { taskProgress.Report(currentProgress, (int)maxProgress, isDownloaded ? "finished" : (isStatusKnown ? $"{v.downloaded / 1_000_000f:0.00}/{maxProgress / 1_000_000f:0.00}MB" : $"{v.downloaded / 1_000_000f:0.00}MB")); } }); var physPath = fileSystem.ResolvePhysicalPath(platformService.UpdateZipFilePath); await UpdateClient.DownloadUpdate(cachedResponse, physPath.FullName, progress); if (cachedResponse.ChangeLog?.Length > 0) { fileSystem.WriteAllText("~/changelog.json", JsonConvert.SerializeObject(cachedResponse.ChangeLog)); } } taskProgress.ReportFinished(); }
public async Task <bool> DownloadLatestVersion(ITaskProgress taskProgress) { cachedResponse ??= await InternalCheckForUpdates(); if (cachedResponse != null) { var physPath = fileSystem.ResolvePhysicalPath(platformService.UpdateZipFilePath); bool success = false; int trial = 0; do { trial++; success = true; await UpdateClient.DownloadUpdate(cachedResponse, physPath.FullName, taskProgress.ToProgress()); if (!string.IsNullOrEmpty(cachedResponse.DownloadMd5)) { success = await updateVerifier.IsUpdateValid((FileInfo)physPath, cachedResponse.DownloadMd5); } } while (!success && trial < 3); if (!success) { physPath.Delete(); taskProgress.ReportFinished(); return(false); } if (cachedResponse.ChangeLog?.Length > 0) { fileSystem.WriteAllText("~/changelog.json", JsonConvert.SerializeObject(cachedResponse.ChangeLog)); } taskProgress.ReportFinished(); return(true); } taskProgress.ReportFinished(); return(false); }
public async Task DownloadLatestVersion(ITaskProgress taskProgress) { cachedResponse ??= await InternalCheckForUpdates(); if (cachedResponse != null) { var physPath = fileSystem.ResolvePhysicalPath(platformService.UpdateZipFilePath); await UpdateClient.DownloadUpdate(cachedResponse, physPath.FullName, taskProgress.ToProgress()); if (cachedResponse.ChangeLog?.Length > 0) { fileSystem.WriteAllText("~/changelog.json", JsonConvert.SerializeObject(cachedResponse.ChangeLog)); } } taskProgress.ReportFinished(); }