public void TestContentLength() { const string uri = "https://raw.github.com/bdhero/bdhero/master/Assets/Icons/bdhero_gui_512.png"; var downloader = new FileDownloader { Uri = uri }; var actual = downloader.GetContentLength(); const long expected = 89485; Assert.AreEqual(expected, actual, "Incorrect Content-Length value"); }
public void TestContentLength() { const string uri = "http://www.gravatar.com/avatar/77a0d71856a3815b527de22e233a8827.png"; var downloader = new FileDownloader { Uri = uri }; var actual = downloader.GetContentLength(); const long expected = 5036; Assert.AreEqual(expected, actual, "Incorrect Content-Length value"); }
public void Test() { const string uri = "https://raw.github.com/bdhero/bdhero/master/Assets/Icons/bdhero_gui_512.png"; var path = Environment.ExpandEnvironmentVariables(@"%TEMP%\bdhero_gui_512.png"); var downloader = new FileDownloader { Uri = uri, Path = path }; downloader.DownloadSync(); const string expected = "945ec6311f160967a797eecd9648a38b10a662ec"; var actual = Hash(path); Assert.AreEqual(expected, actual, "Downloaded file's SHA-1 hash does not match the expected value"); }
public void Test() { const string uri = "http://www.gravatar.com/avatar/77a0d71856a3815b527de22e233a8827.png"; var path = Environment.ExpandEnvironmentVariables(Path.Combine("%TEMP%", "bdhero_gui_80.png")); var downloader = new FileDownloader { Uri = uri, Path = path }; downloader.DownloadSync(); const string expected = "e770bb640d0d97fcb29c0e7ee25844a6c302301f"; var actual = Hash(path); Assert.AreEqual(expected, actual, "Downloaded file's SHA-1 hash does not match the expected value"); }
/// <exception cref="IOException"> /// Thrown if a network error occurs or the SHA-1 hash of the downloaded file /// does not match the expected value in the update manifest. /// </exception> private void DownloadUpdateSync(Update update) { _cancellationTokenSource = new CancellationTokenSource(); var path = Path.Combine(Path.GetTempPath(), update.FileName); var downloader = new FileDownloader { Uri = update.Uri, Path = path, CancellationToken = _cancellationTokenSource.Token }; downloader.BeforeRequest += NotifyBeforeRequest; downloader.ProgressChanged += DownloaderOnProgressChanged; downloader.DownloadSync(); if (downloader.State != FileDownloadState.Success) return; var hash = new SHA1Algorithm().ComputeFile(path); if (!String.Equals(hash, update.SHA1, StringComparison.OrdinalIgnoreCase)) { _logger.ErrorFormat( "Unable to verify integrity of \"{0}\" via SHA-1 hash: expected {1}, but found {2}", path, update.SHA1, hash); throw new IOException("Update file is corrupt or has been tampered with; SHA-1 hash is incorrect"); } _latestInstallerPath = path; }