From 4ecff94aecf345ca917cbaf1b028f9c087450482 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Tue, 27 Jan 2015 21:51:29 +0800 Subject: [PATCH] Change update logic --- .../Wox.Plugin.Everything.csproj | 8 ++-- Wox.Core/Updater/Release.cs | 11 +++++ .../{Version => Updater}/SemanticVersion.cs | 6 +-- Wox.Core/Updater/UpdaterManager.cs | 48 +++++++++++++++++-- Wox.Core/Version/VersionManager.cs | 36 -------------- Wox.Core/Wox.Core.csproj | 4 +- Wox.CrashReporter/ReportWindow.xaml.cs | 4 +- Wox.Test/SemanticVersionTest.cs | 2 +- Wox/SettingWindow.xaml.cs | 4 +- 9 files changed, 66 insertions(+), 57 deletions(-) create mode 100644 Wox.Core/Updater/Release.cs rename Wox.Core/{Version => Updater}/SemanticVersion.cs (95%) delete mode 100644 Wox.Core/Version/VersionManager.cs diff --git a/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj b/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj index 31883d659f..66e78298e8 100644 --- a/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj +++ b/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj @@ -36,9 +36,9 @@ - - packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll - True + + False + ..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll @@ -82,6 +82,7 @@ PreserveNewest + PreserveNewest @@ -93,7 +94,6 @@ - PreserveNewest diff --git a/Wox.Core/Updater/Release.cs b/Wox.Core/Updater/Release.cs new file mode 100644 index 0000000000..e2e157a943 --- /dev/null +++ b/Wox.Core/Updater/Release.cs @@ -0,0 +1,11 @@ +namespace Wox.Core.Updater +{ + public class Release + { + public string version { get; set; } + public string download_link { get; set; } + public string download_link1 { get; set; } + public string download_link2 { get; set; } + public string description { get; set; } + } +} \ No newline at end of file diff --git a/Wox.Core/Version/SemanticVersion.cs b/Wox.Core/Updater/SemanticVersion.cs similarity index 95% rename from Wox.Core/Version/SemanticVersion.cs rename to Wox.Core/Updater/SemanticVersion.cs index 9ba46238c0..693ce73eef 100644 --- a/Wox.Core/Version/SemanticVersion.cs +++ b/Wox.Core/Updater/SemanticVersion.cs @@ -1,11 +1,7 @@ using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; using Wox.Core.Exception; -namespace Wox.Core.Version +namespace Wox.Core.Updater { public class SemanticVersion : IComparable { diff --git a/Wox.Core/Updater/UpdaterManager.cs b/Wox.Core/Updater/UpdaterManager.cs index c89d651db5..6d8b9705ff 100644 --- a/Wox.Core/Updater/UpdaterManager.cs +++ b/Wox.Core/Updater/UpdaterManager.cs @@ -1,13 +1,15 @@ - -using System; +using System; using System.IO; +using System.Reflection; using System.Windows.Forms; using System.Windows.Threading; using NAppUpdate.Framework; using NAppUpdate.Framework.Common; using NAppUpdate.Framework.Sources; +using Newtonsoft.Json; using Wox.Core.i18n; using Wox.Core.UserSettings; +using Wox.Infrastructure.Http; using Wox.Infrastructure.Logger; namespace Wox.Core.Updater @@ -15,6 +17,9 @@ namespace Wox.Core.Updater public class UpdaterManager { private static UpdaterManager instance; + private const string VersionCheckURL = "https://api.getwox.com/release/latest/"; + private const string UpdateFeedURL = "http://127.0.0.1:8888/Update.xml"; + private static SemanticVersion currentVersion; public static UpdaterManager Instance { @@ -33,12 +38,45 @@ namespace Wox.Core.Updater UpdateManager.Instance.UpdateSource = GetUpdateSource(); } - public bool IsUpdateAvailable() + public SemanticVersion CurrentVersion { - return UpdateManager.Instance.UpdatesAvailable > 0; + get + { + if (currentVersion == null) + { + currentVersion = new SemanticVersion(Assembly.GetExecutingAssembly().GetName().Version); + } + return currentVersion; + } + } + + private bool IsNewerThanCurrent(Release release) + { + if (release == null) return false; + + return new SemanticVersion(release.version) > CurrentVersion; } public void CheckUpdate() + { + string json = HttpRequest.Get(VersionCheckURL, HttpProxy.Instance); + if (!string.IsNullOrEmpty(json)) + { + try + { + Release newRelease = JsonConvert.DeserializeObject(json); + if (IsNewerThanCurrent(newRelease)) + { + StartUpdate(); + } + } + catch + { + } + } + } + + private void StartUpdate() { UpdateManager updManager = UpdateManager.Instance; updManager.BeginCheckForUpdates(asyncResult => @@ -104,7 +142,7 @@ namespace Wox.Core.Updater { // Normally this would be a web based source. // But for the demo app, we prepare an in-memory source. - var source = new SimpleWebSource("http://127.0.0.1:8888/Update.xml"); + var source = new SimpleWebSource(UpdateFeedURL); return source; } } diff --git a/Wox.Core/Version/VersionManager.cs b/Wox.Core/Version/VersionManager.cs deleted file mode 100644 index 994e46e164..0000000000 --- a/Wox.Core/Version/VersionManager.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; - -namespace Wox.Core.Version -{ - public class VersionManager - { - private static VersionManager versionManager; - private static SemanticVersion currentVersion; - - public static VersionManager Instance - { - get - { - if (versionManager == null) - { - versionManager = new VersionManager(); - } - return versionManager; - } - } - - private VersionManager() { } - - public SemanticVersion CurrentVersion - { - get - { - if (currentVersion == null) - { - currentVersion = new SemanticVersion(Assembly.GetExecutingAssembly().GetName().Version); - } - return currentVersion; - } - } - } -} diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index e4d2764109..032f760103 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -69,6 +69,7 @@ + @@ -99,8 +100,7 @@ - - + diff --git a/Wox.CrashReporter/ReportWindow.xaml.cs b/Wox.CrashReporter/ReportWindow.xaml.cs index ec041fb7cd..7a6ec983c5 100644 --- a/Wox.CrashReporter/ReportWindow.xaml.cs +++ b/Wox.CrashReporter/ReportWindow.xaml.cs @@ -16,8 +16,8 @@ using Wox.Core; using Wox.Core.Exception; using Wox.Core.i18n; using Wox.Core.UI; +using Wox.Core.Updater; using Wox.Core.UserSettings; -using Wox.Core.Version; using Wox.Infrastructure.Http; namespace Wox.CrashReporter @@ -36,7 +36,7 @@ namespace Wox.CrashReporter private void SetException(Exception exception) { tbSummary.AppendText(exception.Message); - tbVersion.Text = VersionManager.Instance.CurrentVersion.ToString(); + tbVersion.Text = UpdaterManager.Instance.CurrentVersion.ToString(); tbDatetime.Text = DateTime.Now.ToString(); tbStackTrace.AppendText(exception.StackTrace); tbSource.Text = exception.Source; diff --git a/Wox.Test/SemanticVersionTest.cs b/Wox.Test/SemanticVersionTest.cs index c4abdcbbde..81e6e5ddac 100644 --- a/Wox.Test/SemanticVersionTest.cs +++ b/Wox.Test/SemanticVersionTest.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using NUnit.Framework; -using Wox.Core.Version; +using Wox.Core.Updater; namespace Wox.Test { diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 9b8b5f78be..b607281b01 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -20,8 +20,8 @@ using System.Windows.Data; using Microsoft.Win32; using Wox.Core.i18n; using Wox.Core.Theme; +using Wox.Core.Updater; using Wox.Core.UserSettings; -using Wox.Core.Version; namespace Wox { @@ -217,7 +217,7 @@ namespace Wox #region About - tbVersion.Text = VersionManager.Instance.CurrentVersion.ToString(); + tbVersion.Text = UpdaterManager.Instance.CurrentVersion.ToString(); string activateTimes = string.Format(InternationalizationManager.Instance.GetTranslation("about_activate_times"), UserSettingStorage.Instance.ActivateTimes); tbActivatedTimes.Text = activateTimes;