Browse Source

fix #715 - Add a Check for Updates menu item to the Help Tab.

pull/724/head
Siegfried Pammer 9 years ago
parent
commit
037e12b301
  1. 41
      ILSpy/AboutPage.cs
  2. 36
      ILSpy/CheckForUpdates.cs
  3. 1
      ILSpy/ILSpy.csproj
  4. 8
      ILSpy/MainWindow.xaml
  5. 45
      ILSpy/MainWindow.xaml.cs

41
ILSpy/AboutPage.cs

@ -289,20 +289,7 @@ namespace ICSharpCode.ILSpy @@ -289,20 +289,7 @@ namespace ICSharpCode.ILSpy
|| s.LastSuccessfulUpdateCheck < DateTime.UtcNow.AddDays(-7)
|| s.LastSuccessfulUpdateCheck > DateTime.UtcNow)
{
GetLatestVersionAsync().ContinueWith(
delegate (Task<AvailableVersionInfo> 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 @@ -311,6 +298,32 @@ namespace ICSharpCode.ILSpy
}
return tcs.Task;
}
public static Task<string> CheckForUpdatesAsync(ILSpySettings spySettings)
{
var tcs = new TaskCompletionSource<string>();
UpdateSettings s = new UpdateSettings(spySettings);
CheckForUpdateInternal(tcs, s);
return tcs.Task;
}
static void CheckForUpdateInternal(TaskCompletionSource<string> tcs, UpdateSettings s)
{
GetLatestVersionAsync().ContinueWith(
delegate (Task<AvailableVersionInfo> 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);
}
});
}
}
/// <summary>

36
ILSpy/CheckForUpdates.cs

@ -0,0 +1,36 @@ @@ -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);
}
}
}

1
ILSpy/ILSpy.csproj

@ -101,6 +101,7 @@ @@ -101,6 +101,7 @@
<Compile Include="AssemblyListManager.cs" />
<Compile Include="AvalonEdit\ITextMarker.cs" />
<Compile Include="AvalonEdit\TextMarkerService.cs" />
<Compile Include="CheckForUpdates.cs" />
<Compile Include="Commands\BrowseBackCommand.cs" />
<Compile Include="Commands\BrowseForwardCommand.cs" />
<Compile Include="CommandLineArguments.cs" />

8
ILSpy/MainWindow.xaml

@ -141,12 +141,12 @@ @@ -141,12 +141,12 @@
<RowDefinition Height="0" />
<RowDefinition Height="0" Name="bottomPaneRow" />
</Grid.RowDefinitions>
<Border BorderBrush="Black" BorderThickness="1" Name="updateAvailablePanel" Visibility="Collapsed">
<Border BorderBrush="Black" BorderThickness="1" Name="updatePanel" Visibility="Collapsed">
<DockPanel>
<Button DockPanel.Dock="Right" Click="updateAvailablePanelCloseButtonClick" MinWidth="0">X</Button>
<Button DockPanel.Dock="Right" Click="updatePanelCloseButtonClick" MinWidth="0">X</Button>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="4,0" VerticalAlignment="Center">A new ILSpy version is available.</TextBlock>
<Button Click="downloadUpdateButtonClick">Download</Button>
<TextBlock Name="updatePanelMessage" Margin="4,0" VerticalAlignment="Center">A new ILSpy version is available.</TextBlock>
<Button Name="downloadOrCheckUpdateButton" Click="downloadOrCheckUpdateButtonClick">Download</Button>
</StackPanel>
</DockPanel>
</Border>

45
ILSpy/MainWindow.xaml.cs

@ -399,27 +399,44 @@ namespace ICSharpCode.ILSpy @@ -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<string> task) {
if (task.Result != null) {
updateAvailableDownloadUrl = task.Result;
updateAvailablePanel.Visibility = Visibility.Visible;
}
},
TaskScheduler.FromCurrentSynchronizationContext()
);
Task<string> 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<string> 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

Loading…
Cancel
Save