private UpdateInformation GetUpdateInfo() { if (UpdateInfoWebRequest is null) { throw new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.NotSet, nameof(UpdateInfoWebRequest))); } UpdateInfoWebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); var webResponse = UpdateInfoWebRequest.GetResponse(); UpdateInformation updateInfo = null; using (var appCastStream = webResponse.GetResponseStream()) { if (appCastStream != null) { using (var streamReader = new StreamReader(appCastStream)) { var data = streamReader.ReadToEnd(); updateInfo = JsonSerializer.Deserialize <UpdateInformation>(data); } } webResponse.Close(); } return(updateInfo); }
private async Task <string> DownloadZip(UpdateInformation updateInfo) { if (DownloadWebClient is null) { throw new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.NotSet, nameof(DownloadWebClient))); } DownloadWebClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); var zipSetupFilePath = Path.GetTempFileName(); if (File.Exists(zipSetupFilePath)) { File.Delete(zipSetupFilePath); } await DownloadWebClient.DownloadFileTaskAsync(updateInfo.DownloadURL, zipSetupFilePath).ConfigureAwait(false); if (File.Exists(zipSetupFilePath) == false) { throw new FileNotFoundException($"[{zipSetupFilePath}] does not exist"); } // use https://emn178.github.io/online-tools/sha512_file_hash.html var checkSum = CalculateCheckSum(zipSetupFilePath); if (updateInfo.Checksum.ToUpperInvariant() != checkSum) { throw new FileNotFoundException($"Zip file integrity check failed, [{updateInfo.Checksum}/{checkSum}]"); } return(zipSetupFilePath); }