From 7989cad1f42ce9a5a6c970b8ab604673512c8056 Mon Sep 17 00:00:00 2001 From: Ravi Patel Date: Sat, 10 Feb 2018 14:46:44 +0530 Subject: [PATCH] Now integrity of the downloaded file will be checked using provided checksum as soon as the download completes. --- AutoUpdater.NET/DownloadUpdateDialog.cs | 20 ++++++++++---------- AutoUpdaterTest/FormMain.cs | 2 +- README.md | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/AutoUpdater.NET/DownloadUpdateDialog.cs b/AutoUpdater.NET/DownloadUpdateDialog.cs index a8415fdd..6744875b 100644 --- a/AutoUpdater.NET/DownloadUpdateDialog.cs +++ b/AutoUpdater.NET/DownloadUpdateDialog.cs @@ -66,6 +66,16 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent return; } + if (!string.IsNullOrEmpty(AutoUpdater.Checksum)) + { + if (!CompareChecksum(_tempFile, AutoUpdater.Checksum)) + { + _webClient = null; + Close(); + return; + } + } + string fileName; string contentDisposition = _webClient.ResponseHeaders["Content-Disposition"] ?? string.Empty; if (string.IsNullOrEmpty(contentDisposition)) @@ -122,16 +132,6 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent } } - if (!string.IsNullOrEmpty(AutoUpdater.Checksum)) - { - if (!CompareChecksum(tempPath, AutoUpdater.Checksum)) - { - _webClient = null; - Close(); - return; - } - } - try { Process.Start(processStartInfo); diff --git a/AutoUpdaterTest/FormMain.cs b/AutoUpdaterTest/FormMain.cs index 2ce22831..c3591d37 100644 --- a/AutoUpdaterTest/FormMain.cs +++ b/AutoUpdaterTest/FormMain.cs @@ -89,7 +89,7 @@ private void FormMain_Load(object sender, EventArgs e) //}; //timer.Start(); - //AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml"); + AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml"); } private void AutoUpdater_ApplicationExitEvent() diff --git a/README.md b/README.md index e7c2d38f..31073504 100644 --- a/README.md +++ b/README.md @@ -135,9 +135,9 @@ var proxy = new WebProxy("ProxyIP:ProxyPort", true) AutoUpdater.Proxy = proxy; ```` -### Specify where to download update file +### Specify where to download the update file -You can specify where you want to download update file by assigning DownloadPath field as shown below. It will be used for ZipExtractor too. +You can specify where you want to download the update file by assigning DownloadPath field as shown below. It will be used for ZipExtractor too. ````csharp AutoUpdater.DownloadPath = Environment.CurrentDirectory;