mirror of https://github.com/icsharpcode/ILSpy.git
6 changed files with 277 additions and 163 deletions
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
// 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; |
||||
|
||||
namespace ICSharpCode.ILSpy.Updates |
||||
{ |
||||
internal enum UpdateStrategy |
||||
{ |
||||
NotifyOfUpdates, |
||||
// AutoUpdate
|
||||
} |
||||
|
||||
internal static class AppUpdateService |
||||
{ |
||||
public static readonly UpdateStrategy updateStrategy = UpdateStrategy.NotifyOfUpdates; |
||||
|
||||
public static readonly Version CurrentVersion = new Version(DecompilerVersionInfo.Major + "." + DecompilerVersionInfo.Minor + "." + DecompilerVersionInfo.Build + "." + DecompilerVersionInfo.Revision); |
||||
} |
||||
} |
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
// 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; |
||||
|
||||
namespace ICSharpCode.ILSpy.Updates |
||||
{ |
||||
sealed class AvailableVersionInfo |
||||
{ |
||||
public Version Version; |
||||
public string DownloadUrl; |
||||
} |
||||
} |
@ -0,0 +1,114 @@
@@ -0,0 +1,114 @@
|
||||
// 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.IO; |
||||
using System.Linq; |
||||
using System.Net.Http; |
||||
using System.Threading.Tasks; |
||||
using System.Xml.Linq; |
||||
|
||||
using ICSharpCode.ILSpyX.Settings; |
||||
|
||||
namespace ICSharpCode.ILSpy.Updates |
||||
{ |
||||
internal static class NotifyOfUpdatesStrategy |
||||
{ |
||||
static readonly Uri UpdateUrl = new Uri("https://ilspy.net/updates.xml"); |
||||
const string band = "stable"; |
||||
|
||||
public static AvailableVersionInfo LatestAvailableVersion { get; private set; } |
||||
|
||||
public static async Task<AvailableVersionInfo> GetLatestVersionAsync() |
||||
{ |
||||
var client = new HttpClient(new HttpClientHandler() { |
||||
UseProxy = true, |
||||
UseDefaultCredentials = true, |
||||
}); |
||||
string data = await client.GetStringAsync(UpdateUrl).ConfigureAwait(false); |
||||
|
||||
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 }; |
||||
return LatestAvailableVersion; |
||||
} |
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// If automatic update checking is enabled, checks if there are any updates available.
|
||||
/// 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 async Task<string> CheckForUpdatesIfEnabledAsync(ILSpySettings spySettings) |
||||
{ |
||||
UpdateSettings s = new UpdateSettings(spySettings); |
||||
|
||||
// If we're in an MSIX package, updates work differently
|
||||
if (s.AutomaticUpdateCheckEnabled) |
||||
{ |
||||
// perform update check if we never did one before;
|
||||
// or if the last check wasn't in the past 7 days
|
||||
if (s.LastSuccessfulUpdateCheck == null |
||||
|| s.LastSuccessfulUpdateCheck < DateTime.UtcNow.AddDays(-7) |
||||
|| s.LastSuccessfulUpdateCheck > DateTime.UtcNow) |
||||
{ |
||||
return await CheckForUpdateInternal(s).ConfigureAwait(false); |
||||
} |
||||
else |
||||
{ |
||||
return null; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public static Task<string> CheckForUpdatesAsync(ILSpySettings spySettings) |
||||
{ |
||||
UpdateSettings s = new UpdateSettings(spySettings); |
||||
return CheckForUpdateInternal(s); |
||||
} |
||||
|
||||
static async Task<string> CheckForUpdateInternal(UpdateSettings s) |
||||
{ |
||||
try |
||||
{ |
||||
var v = await GetLatestVersionAsync().ConfigureAwait(false); |
||||
s.LastSuccessfulUpdateCheck = DateTime.UtcNow; |
||||
if (v.Version > AppUpdateService.CurrentVersion) |
||||
return v.DownloadUrl; |
||||
else |
||||
return null; |
||||
} |
||||
catch (Exception) |
||||
{ |
||||
// ignore errors getting the version info
|
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,89 @@
@@ -0,0 +1,89 @@
|
||||
// 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.ComponentModel; |
||||
using System.Xml.Linq; |
||||
|
||||
using ICSharpCode.ILSpyX.Settings; |
||||
|
||||
namespace ICSharpCode.ILSpy.Updates |
||||
{ |
||||
sealed class UpdateSettings : INotifyPropertyChanged |
||||
{ |
||||
public UpdateSettings(ILSpySettings spySettings) |
||||
{ |
||||
XElement s = spySettings["UpdateSettings"]; |
||||
this.automaticUpdateCheckEnabled = (bool?)s.Element("AutomaticUpdateCheckEnabled") ?? true; |
||||
try |
||||
{ |
||||
this.lastSuccessfulUpdateCheck = (DateTime?)s.Element("LastSuccessfulUpdateCheck"); |
||||
} |
||||
catch (FormatException) |
||||
{ |
||||
// avoid crashing on settings files invalid due to
|
||||
// https://github.com/icsharpcode/ILSpy/issues/closed/#issue/2
|
||||
} |
||||
} |
||||
|
||||
bool automaticUpdateCheckEnabled; |
||||
|
||||
public bool AutomaticUpdateCheckEnabled { |
||||
get { return automaticUpdateCheckEnabled; } |
||||
set { |
||||
if (automaticUpdateCheckEnabled != value) |
||||
{ |
||||
automaticUpdateCheckEnabled = value; |
||||
Save(); |
||||
OnPropertyChanged(nameof(AutomaticUpdateCheckEnabled)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
DateTime? lastSuccessfulUpdateCheck; |
||||
|
||||
public DateTime? LastSuccessfulUpdateCheck { |
||||
get { return lastSuccessfulUpdateCheck; } |
||||
set { |
||||
if (lastSuccessfulUpdateCheck != value) |
||||
{ |
||||
lastSuccessfulUpdateCheck = value; |
||||
Save(); |
||||
OnPropertyChanged(nameof(LastSuccessfulUpdateCheck)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void Save() |
||||
{ |
||||
XElement updateSettings = new XElement("UpdateSettings"); |
||||
updateSettings.Add(new XElement("AutomaticUpdateCheckEnabled", automaticUpdateCheckEnabled)); |
||||
if (lastSuccessfulUpdateCheck != null) |
||||
updateSettings.Add(new XElement("LastSuccessfulUpdateCheck", lastSuccessfulUpdateCheck)); |
||||
ILSpySettings.SaveSettings(updateSettings); |
||||
} |
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged; |
||||
|
||||
void OnPropertyChanged(string propertyName) |
||||
{ |
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue