public async Task DownloadUpdate(UpdateManifest.Package package, Action <DownloadProgressChangedEventArgs> progressHandler) { if (updateManifest == null) { DownloadManifest(); } if (File.Exists(updaterPath)) { if (VerifyUpdateFile(package.Checksum, updaterPath)) { logger.Info("Update already downloaded skipping download."); return; } } try { var downloadUrls = updateManifest.DownloadServers.Select(a => Url.Combine(a, updateManifest.LatestVersion.ToString(), package.FileName)); await downloader.DownloadFileAsync(downloadUrls, updaterPath, progressHandler); } catch (Exception e) { logger.Error(e, "Failed to download update file."); throw new Exception("Failed to download update file."); } if (!VerifyUpdateFile(package.Checksum, updaterPath)) { throw new Exception($"Update file integrity check failed."); } }
public async Task DownloadUpdate(UpdateManifest.Package package, Action <DownloadProgressChangedEventArgs> progressHandler) { if (updateManifest == null) { DownloadManifest(); } if (File.Exists(updaterPath)) { var md5 = FileSystem.GetMD5(updaterPath); if (md5 == package.Checksum) { logger.Info("Update already downloaded skipping download."); return; } } try { var downloadUrls = updateManifest.DownloadServers.Select(a => Url.Combine(a, updateManifest.LatestVersion.ToString(), package.FileName)); await downloader.DownloadFileAsync(downloadUrls, updaterPath, progressHandler); var md5 = FileSystem.GetMD5(updaterPath); if (md5 != package.Checksum) { throw new Exception($"Checksum of downloaded file doesn't match: {md5} vs {package.Checksum}"); } } catch (Exception e) { logger.Warn(e, "Failed to download update file."); throw new Exception("Failed to download update file."); } }