diff --git a/ILSpy/AboutPage.cs b/ILSpy/AboutPage.cs index d751d3664..0966cbb2c 100644 --- a/ILSpy/AboutPage.cs +++ b/ILSpy/AboutPage.cs @@ -289,20 +289,7 @@ namespace ICSharpCode.ILSpy || s.LastSuccessfulUpdateCheck < DateTime.UtcNow.AddDays(-7) || s.LastSuccessfulUpdateCheck > DateTime.UtcNow) { - GetLatestVersionAsync().ContinueWith( - delegate (Task task) { - try { - s.LastSuccessfulUpdateCheck = DateTime.UtcNow; - AvailableVersionInfo v = task.Result; - if (v.Version > currentVersion) - tcs.SetResult(v.DownloadUrl); - else - tcs.SetResult(null); - } catch (AggregateException) { - // ignore errors getting the version info - tcs.SetResult(null); - } - }); + CheckForUpdateInternal(tcs, s); } else { tcs.SetResult(null); } @@ -311,6 +298,32 @@ namespace ICSharpCode.ILSpy } return tcs.Task; } + + public static Task CheckForUpdatesAsync(ILSpySettings spySettings) + { + var tcs = new TaskCompletionSource(); + UpdateSettings s = new UpdateSettings(spySettings); + CheckForUpdateInternal(tcs, s); + return tcs.Task; + } + + static void CheckForUpdateInternal(TaskCompletionSource tcs, UpdateSettings s) + { + GetLatestVersionAsync().ContinueWith( + delegate (Task task) { + try { + s.LastSuccessfulUpdateCheck = DateTime.UtcNow; + AvailableVersionInfo v = task.Result; + if (v.Version > currentVersion) + tcs.SetResult(v.DownloadUrl); + else + tcs.SetResult(null); + } catch (AggregateException) { + // ignore errors getting the version info + tcs.SetResult(null); + } + }); + } } /// diff --git a/ILSpy/CheckForUpdates.cs b/ILSpy/CheckForUpdates.cs new file mode 100644 index 000000000..ed1adbfd1 --- /dev/null +++ b/ILSpy/CheckForUpdates.cs @@ -0,0 +1,36 @@ +// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace ICSharpCode.ILSpy +{ + [ExportMainMenuCommand(Menu = "_Help", Header = "_Check for Updates", MenuOrder = 5000)] + sealed class CheckForUpdates : SimpleCommand + { + public override void Execute(object parameter) + { + MainWindow.Instance.ShowMessageIfUpdatesAvailableAsync(ILSpySettings.Load(), forceCheck: true); + } + } +} diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index 243e2275a..cc72c5403 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -101,6 +101,7 @@ + diff --git a/ILSpy/MainWindow.xaml b/ILSpy/MainWindow.xaml index 9aec1acde..2c12afc6c 100644 --- a/ILSpy/MainWindow.xaml +++ b/ILSpy/MainWindow.xaml @@ -141,12 +141,12 @@ - + - + - A new ILSpy version is available. - + A new ILSpy version is available. + diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index 8dfd45e53..1cdfe40ed 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -399,27 +399,44 @@ namespace ICSharpCode.ILSpy #region Update Check string updateAvailableDownloadUrl; - void ShowMessageIfUpdatesAvailableAsync(ILSpySettings spySettings) + public void ShowMessageIfUpdatesAvailableAsync(ILSpySettings spySettings, bool forceCheck = false) { - AboutPage.CheckForUpdatesIfEnabledAsync(spySettings).ContinueWith( - delegate (Task task) { - if (task.Result != null) { - updateAvailableDownloadUrl = task.Result; - updateAvailablePanel.Visibility = Visibility.Visible; - } - }, - TaskScheduler.FromCurrentSynchronizationContext() - ); + Task result; + if (forceCheck) { + result = AboutPage.CheckForUpdatesAsync(spySettings); + } else { + result = AboutPage.CheckForUpdatesIfEnabledAsync(spySettings); + } + result.ContinueWith(task => AdjustUpdateUIAfterCheck(task, forceCheck), TaskScheduler.FromCurrentSynchronizationContext()); } - void updateAvailablePanelCloseButtonClick(object sender, RoutedEventArgs e) + void updatePanelCloseButtonClick(object sender, RoutedEventArgs e) { - updateAvailablePanel.Visibility = Visibility.Collapsed; + updatePanel.Visibility = Visibility.Collapsed; } - void downloadUpdateButtonClick(object sender, RoutedEventArgs e) + void downloadOrCheckUpdateButtonClick(object sender, RoutedEventArgs e) { - Process.Start(updateAvailableDownloadUrl); + if (updateAvailableDownloadUrl != null) { + Process.Start(updateAvailableDownloadUrl); + } else { + updatePanel.Visibility = Visibility.Collapsed; + AboutPage.CheckForUpdatesAsync(spySettings ?? ILSpySettings.Load()) + .ContinueWith(task => AdjustUpdateUIAfterCheck(task, true), TaskScheduler.FromCurrentSynchronizationContext()); + } + } + + void AdjustUpdateUIAfterCheck(Task task, bool displayMessage) + { + updateAvailableDownloadUrl = task.Result; + updatePanel.Visibility = displayMessage ? Visibility.Visible : Visibility.Collapsed; + if (task.Result != null) { + updatePanelMessage.Text = "A new ILSpy version is available."; + downloadOrCheckUpdateButton.Content = "Download"; + } else { + updatePanelMessage.Text = "No update for ILSpy found."; + downloadOrCheckUpdateButton.Content = "Check again"; + } } #endregion