From b744f3a3a79ab4543b9b8e2128e03bdf8d76fc94 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 21 Feb 2017 14:15:46 +0900 Subject: [PATCH] Re-nest code and handle even more potential exceptions. --- osu.Desktop/Overlays/VersionManager.cs | 66 ++++++++++++++++---------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/osu.Desktop/Overlays/VersionManager.cs b/osu.Desktop/Overlays/VersionManager.cs index a853c375ca..a2dc0cb5c3 100644 --- a/osu.Desktop/Overlays/VersionManager.cs +++ b/osu.Desktop/Overlays/VersionManager.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using System.ComponentModel; using System.Diagnostics; using osu.Framework.Allocation; @@ -18,6 +19,7 @@ using osu.Game.Graphics; using OpenTK; using OpenTK.Graphics; using System.Net.Http; +using osu.Framework.Logging; namespace osu.Desktop.Overlays { @@ -118,25 +120,32 @@ namespace osu.Desktop.Overlays private async void updateChecker(bool useDeltaPatching = true, UpdateProgressNotification notification = null) { + //should we schedule a retry on completion of this check? + bool scheduleRetry = true; + try { if (updateManager == null) updateManager = await UpdateManager.GitHubUpdateManager(@"https://github.com/ppy/osu", @"osulazer", null, null, true); var info = await updateManager.CheckForUpdate(!useDeltaPatching); - if (info.ReleasesToApply.Count > 0) + if (info.ReleasesToApply.Count == 0) + //no updates available. bail and retry later. + return; + + if (notification == null) { - if (notification == null) - { - notification = new UpdateProgressNotification { State = ProgressNotificationState.Active }; - Schedule(() => notificationManager.Post(notification)); - } + notification = new UpdateProgressNotification { State = ProgressNotificationState.Active }; + Schedule(() => notificationManager.Post(notification)); + } - Schedule(() => - { - notification.Progress = 0; - notification.Text = @"Downloading update..."; - }); + Schedule(() => + { + notification.Progress = 0; + notification.Text = @"Downloading update..."; + }); + try + { await updateManager.DownloadReleases(info.ReleasesToApply, p => Schedule(() => notification.Progress = p / 100f)); Schedule(() => @@ -145,30 +154,35 @@ namespace osu.Desktop.Overlays notification.Text = @"Installing update..."; }); - try - { - await updateManager.ApplyReleases(info, p => Schedule(() => notification.Progress = p / 100f)); - } - catch (Win32Exception) + await updateManager.ApplyReleases(info, p => Schedule(() => notification.Progress = p / 100f)); + + Schedule(() => notification.State = ProgressNotificationState.Completed); + } + catch (Exception) + { + if (useDeltaPatching) { //could fail if deltas are unavailable for full update path (https://github.com/Squirrel/Squirrel.Windows/issues/959) //try again without deltas. updateChecker(false, notification); - return; + scheduleRetry = false; } - - Schedule(() => notification.State = ProgressNotificationState.Completed); - } - else - { - //check again every 30 minutes. - Scheduler.AddDelayed(() => updateChecker(), 60000 * 30); } } catch (HttpRequestException) { - //check again every 30 minutes. - Scheduler.AddDelayed(() => updateChecker(), 60000 * 30); + //likely have no internet connection. + //we'll ignore this and retry later. + } + finally + { + if (scheduleRetry) + { + //check again in 30 minutes. + Scheduler.AddDelayed(() => updateChecker(), 60000 * 30); + if (notification != null) + notification.State = ProgressNotificationState.Cancelled; + } } }