From 06bd65b7f88b5b923deacf1014d7ab805e04ff9e Mon Sep 17 00:00:00 2001 From: chylex <contact@chylex.com> Date: Sun, 15 Apr 2018 19:01:39 +0200 Subject: [PATCH] Fix wrong behavior when an update is canceled during download & multiple check errors in some cases --- Core/FormBrowser.cs | 6 +++--- Updates/FormUpdateDownload.cs | 1 + Updates/UpdateDownloadStatus.cs | 5 +++-- Updates/UpdateHandler.cs | 4 ++++ Updates/UpdateInfo.cs | 5 +++++ 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index 47e5ba1d..8da6dea1 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -250,11 +250,11 @@ private void updates_CheckFinished(object sender, UpdateCheckEventArgs e){ }, ex => { if (!ignoreUpdateCheckError){ Program.Reporter.HandleException("Update Check Error", "An error occurred while checking for updates.", true, ex); - - ignoreUpdateCheckError = true; updates.StartTimer(); } }); + + ignoreUpdateCheckError = true; }); } @@ -274,7 +274,7 @@ private void updates_UpdateAccepted(object sender, UpdateEventArgs e){ UpdateInstallerPath = update.InstallerPath; ForceClose(); } - else if (FormMessage.Error("Update Has Failed", "Could not automatically download the update: "+(update.DownloadError?.Message ?? "unknown error")+"\n\nWould you like to open the website and try downloading the update manually?", FormMessage.Yes, FormMessage.No)){ + else if (status != UpdateDownloadStatus.Canceled && FormMessage.Error("Update Has Failed", "Could not automatically download the update: "+(update.DownloadError?.Message ?? "unknown error")+"\n\nWould you like to open the website and try downloading the update manually?", FormMessage.Yes, FormMessage.No)){ BrowserUtils.OpenExternalBrowser(Program.Website); ForceClose(); } diff --git a/Updates/FormUpdateDownload.cs b/Updates/FormUpdateDownload.cs index 9b85519f..d90c3979 100644 --- a/Updates/FormUpdateDownload.cs +++ b/Updates/FormUpdateDownload.cs @@ -22,6 +22,7 @@ private void btnCancel_Click(object sender, EventArgs e){ private void timerDownloadCheck_Tick(object sender, EventArgs e){ if (updateInfo.DownloadStatus.IsFinished()){ timerDownloadCheck.Stop(); + DialogResult = DialogResult.OK; Close(); } } diff --git a/Updates/UpdateDownloadStatus.cs b/Updates/UpdateDownloadStatus.cs index 7a47aad9..85de1b66 100644 --- a/Updates/UpdateDownloadStatus.cs +++ b/Updates/UpdateDownloadStatus.cs @@ -2,9 +2,10 @@ public enum UpdateDownloadStatus{ None = 0, InProgress, + Canceled, AssetMissing, - Done, - Failed + Failed, + Done } public static class UpdateDownloadStatusExtensions{ diff --git a/Updates/UpdateHandler.cs b/Updates/UpdateHandler.cs index d757fa5d..3be87a14 100644 --- a/Updates/UpdateHandler.cs +++ b/Updates/UpdateHandler.cs @@ -101,6 +101,10 @@ public void BeginUpdateDownload(Form ownerForm, UpdateInfo updateInfo, Action<Up }; downloadForm.FormClosed += (sender, args) => { + if (downloadForm.DialogResult != DialogResult.OK){ + updateInfo.CancelDownload(); + } + downloadForm.Dispose(); onFinished(updateInfo); }; diff --git a/Updates/UpdateInfo.cs b/Updates/UpdateInfo.cs index c7d02c74..f2953cd3 100644 --- a/Updates/UpdateInfo.cs +++ b/Updates/UpdateInfo.cs @@ -72,6 +72,11 @@ public void DeleteInstaller(){ } } + public void CancelDownload(){ + DeleteInstaller(); + DownloadStatus = UpdateDownloadStatus.Canceled; + } + public override bool Equals(object obj){ return obj is UpdateInfo info && VersionTag == info.VersionTag; }