|
|
|
@ -129,20 +129,19 @@ namespace ICSharpCode.ILSpy
@@ -129,20 +129,19 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
button.Cursor = Cursors.Arrow; |
|
|
|
|
stackPanel.Children.Add(button); |
|
|
|
|
|
|
|
|
|
button.Click += delegate { |
|
|
|
|
button.Click += async delegate { |
|
|
|
|
button.Content = Resources.Checking; |
|
|
|
|
button.IsEnabled = false; |
|
|
|
|
GetLatestVersionAsync().ContinueWith( |
|
|
|
|
delegate (Task<AvailableVersionInfo> task) { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
AvailableVersionInfo vInfo = await GetLatestVersionAsync(); |
|
|
|
|
stackPanel.Children.Clear(); |
|
|
|
|
ShowAvailableVersion(task.Result, stackPanel); |
|
|
|
|
ShowAvailableVersion(vInfo, stackPanel); |
|
|
|
|
} catch (Exception ex) { |
|
|
|
|
AvalonEditTextOutput exceptionOutput = new AvalonEditTextOutput(); |
|
|
|
|
exceptionOutput.WriteLine(ex.ToString()); |
|
|
|
|
textView.ShowText(exceptionOutput); |
|
|
|
|
} |
|
|
|
|
}, TaskScheduler.FromCurrentSynchronizationContext()); |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -183,36 +182,25 @@ namespace ICSharpCode.ILSpy
@@ -183,36 +182,25 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static Task<AvailableVersionInfo> GetLatestVersionAsync() |
|
|
|
|
static async Task<AvailableVersionInfo> GetLatestVersionAsync() |
|
|
|
|
{ |
|
|
|
|
var tcs = new TaskCompletionSource<AvailableVersionInfo>(); |
|
|
|
|
new Action(() => { |
|
|
|
|
WebClient wc = new WebClient(); |
|
|
|
|
IWebProxy systemWebProxy = WebRequest.GetSystemWebProxy(); |
|
|
|
|
systemWebProxy.Credentials = CredentialCache.DefaultCredentials; |
|
|
|
|
wc.Proxy = systemWebProxy; |
|
|
|
|
wc.DownloadDataCompleted += delegate(object sender, DownloadDataCompletedEventArgs e) { |
|
|
|
|
if (e.Error != null) { |
|
|
|
|
tcs.SetException(e.Error); |
|
|
|
|
} else { |
|
|
|
|
try { |
|
|
|
|
XDocument doc = XDocument.Load(new MemoryStream(e.Result)); |
|
|
|
|
|
|
|
|
|
string data = await wc.DownloadStringTaskAsync(UpdateUrl); |
|
|
|
|
|
|
|
|
|
XDocument doc = XDocument.Load(new StringReader(data)); |
|
|
|
|
var bands = doc.Root.Elements("band"); |
|
|
|
|
var currentBand = bands.FirstOrDefault(b => (string)b.Attribute("id") == band) ?? bands.First(); |
|
|
|
|
Version version = new Version((string)currentBand.Element("latestVersion")); |
|
|
|
|
string url = (string)currentBand.Element("downloadUrl"); |
|
|
|
|
if (!(url.StartsWith("http://", StringComparison.Ordinal) || url.StartsWith("https://", StringComparison.Ordinal))) |
|
|
|
|
url = null; // don't accept non-urls
|
|
|
|
|
|
|
|
|
|
latestAvailableVersion = new AvailableVersionInfo { Version = version, DownloadUrl = url }; |
|
|
|
|
tcs.SetResult(latestAvailableVersion); |
|
|
|
|
} catch (Exception ex) { |
|
|
|
|
tcs.SetException(ex); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
wc.DownloadDataAsync(UpdateUrl); |
|
|
|
|
}).BeginInvoke(null, null); |
|
|
|
|
return tcs.Task; |
|
|
|
|
return latestAvailableVersion; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sealed class AvailableVersionInfo |
|
|
|
@ -274,9 +262,7 @@ namespace ICSharpCode.ILSpy
@@ -274,9 +262,7 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
|
|
|
|
|
void OnPropertyChanged(string propertyName) |
|
|
|
|
{ |
|
|
|
|
if (PropertyChanged != null) { |
|
|
|
|
PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); |
|
|
|
|
} |
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -285,10 +271,10 @@ namespace ICSharpCode.ILSpy
@@ -285,10 +271,10 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
/// Returns the download URL if an update is available.
|
|
|
|
|
/// Returns null if no update is available, or if no check was performed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Task<string> CheckForUpdatesIfEnabledAsync(ILSpySettings spySettings) |
|
|
|
|
public static async Task<string> CheckForUpdatesIfEnabledAsync(ILSpySettings spySettings) |
|
|
|
|
{ |
|
|
|
|
var tcs = new TaskCompletionSource<string>(); |
|
|
|
|
UpdateSettings s = new UpdateSettings(spySettings); |
|
|
|
|
|
|
|
|
|
// If we're in an MSIX package, updates work differently
|
|
|
|
|
if (s.AutomaticUpdateCheckEnabled && !WindowsVersionHelper.HasPackageIdentity) { |
|
|
|
|
// perform update check if we never did one before;
|
|
|
|
@ -297,40 +283,35 @@ namespace ICSharpCode.ILSpy
@@ -297,40 +283,35 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
|| s.LastSuccessfulUpdateCheck < DateTime.UtcNow.AddDays(-7) |
|
|
|
|
|| s.LastSuccessfulUpdateCheck > DateTime.UtcNow) |
|
|
|
|
{ |
|
|
|
|
CheckForUpdateInternal(tcs, s); |
|
|
|
|
return await CheckForUpdateInternal(s); |
|
|
|
|
} else { |
|
|
|
|
tcs.SetResult(null); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
tcs.SetResult(null); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
return tcs.Task; |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static Task<string> CheckForUpdatesAsync(ILSpySettings spySettings) |
|
|
|
|
{ |
|
|
|
|
var tcs = new TaskCompletionSource<string>(); |
|
|
|
|
UpdateSettings s = new UpdateSettings(spySettings); |
|
|
|
|
CheckForUpdateInternal(tcs, s); |
|
|
|
|
return tcs.Task; |
|
|
|
|
return CheckForUpdateInternal(s); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void CheckForUpdateInternal(TaskCompletionSource<string> tcs, UpdateSettings s) |
|
|
|
|
static async Task<string> CheckForUpdateInternal(UpdateSettings s) |
|
|
|
|
{ |
|
|
|
|
GetLatestVersionAsync().ContinueWith( |
|
|
|
|
delegate (Task<AvailableVersionInfo> task) { |
|
|
|
|
try { |
|
|
|
|
var v = await GetLatestVersionAsync(); |
|
|
|
|
s.LastSuccessfulUpdateCheck = DateTime.UtcNow; |
|
|
|
|
AvailableVersionInfo v = task.Result; |
|
|
|
|
if (v.Version > currentVersion) |
|
|
|
|
tcs.SetResult(v.DownloadUrl); |
|
|
|
|
return v.DownloadUrl; |
|
|
|
|
else |
|
|
|
|
tcs.SetResult(null); |
|
|
|
|
} catch (AggregateException) { |
|
|
|
|
return null; |
|
|
|
|
} catch (Exception) { |
|
|
|
|
// ignore errors getting the version info
|
|
|
|
|
tcs.SetResult(null); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|