diff --git a/Wox.Core/Updater.cs b/Wox.Core/Updater.cs new file mode 100644 index 0000000000..77550c2e27 --- /dev/null +++ b/Wox.Core/Updater.cs @@ -0,0 +1,86 @@ +using System; +using System.Diagnostics; +using System.Net; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Squirrel; +using Wox.Core.UserSettings; +using Wox.Infrastructure.Http; +using Wox.Infrastructure.Logger; + +namespace Wox.Core +{ + public static class Updater + { + [Conditional("RELEASE")] + public static async void UpdateApp() + { + try + { + // todo 5/9 the return value of UpdateApp() is NULL, fucking useless! + using (var updater= await UpdateManager.GitHubUpdateManager(Infrastructure.Wox.Github)) + { + await updater.UpdateApp(); + } + } + catch (WebException ex) + { + Log.Error(ex); + } + catch (Exception exception) + { + const string info = "Update.exe not found, not a Squirrel-installed app?"; + if (exception.Message == info) + { + Log.Warn(info); + } + else + { + throw; + } + } + } + + public static async Task NewVersion() + { + const string githubAPI = @"https://api.github.com/repos/wox-launcher/wox/releases/latest"; + var response = await HttpRequest.Get(githubAPI, HttpProxy.Instance); + + if (!string.IsNullOrEmpty(response)) + { + JContainer json; + try + { + json = (JContainer)JsonConvert.DeserializeObject(response); + } + catch (JsonSerializationException e) + { + Log.Error(e); + return string.Empty; + } + var version = json?["tag_name"]?.ToString(); + if (!string.IsNullOrEmpty(version)) + { + return version; + } + else + { + Log.Warn("Can't find tag_name from Github API response"); + return string.Empty; + } + } + else + { + Log.Warn("Can't get response from Github API"); + return string.Empty; + } + } + + public static int NumericVersion(string version) + { + var newVersion = version.Replace("v", ".").Replace(".", "").Replace("*", ""); + return int.Parse(newVersion); + } + } +} diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index 92b58b27c1..2ce8b41646 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -34,24 +34,60 @@ false - - ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll + + ..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.dll + True + + + ..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.MsDelta.dll + True + + + ..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.PatchApi.dll + True + + + ..\packages\squirrel.windows.1.4.0\lib\Net45\ICSharpCode.SharpZipLib.dll True ..\packages\JetBrains.Annotations.10.1.4\lib\net20\JetBrains.Annotations.dll True - - ..\packages\NAppUpdate.Framework.0.3.2.0\lib\net20\NAppUpdate.Framework.dll + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll + True + + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll + True + + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll + True + + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll True ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll True + + ..\packages\squirrel.windows.1.4.0\lib\Net45\NuGet.Squirrel.dll + True + + + ..\packages\Splat.1.6.2\lib\Net45\Splat.dll + True + + + ..\packages\squirrel.windows.1.4.0\lib\Net45\Squirrel.dll + True + @@ -66,6 +102,7 @@ + diff --git a/Wox.Core/packages.config b/Wox.Core/packages.config index 4061bf7b4c..ebbc95d4a4 100644 --- a/Wox.Core/packages.config +++ b/Wox.Core/packages.config @@ -1,8 +1,11 @@  + - + + + \ No newline at end of file diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 2412eb3d90..c4eac247f5 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -1,14 +1,12 @@ using System; using System.Diagnostics; -using System.Net; using System.Windows; -using Squirrel; +using Wox.Core; using Wox.Core.Plugin; using Wox.Helper; using Wox.Infrastructure.Image; using Wox.ViewModel; using Stopwatch = Wox.Infrastructure.Stopwatch; -using Wox.Infrastructure.Logger; namespace Wox { @@ -18,7 +16,6 @@ namespace Wox public static MainWindow Window { get; private set; } public static PublicAPIInstance API { get; private set; } private static bool _disposed; - public static UpdateManager Updater; [STAThread] public static void Main() @@ -56,29 +53,7 @@ namespace Wox private async void OnActivated(object sender, EventArgs e) { - try - { - using (Updater = await UpdateManager.GitHubUpdateManager(Infrastructure.Wox.Github)) - { - await Updater.UpdateApp(); - } - } - catch (WebException ex) - { - Log.Error(ex); - } - catch (Exception exception) - { - const string info = "Update.exe not found, not a Squirrel-installed app?"; - if (exception.Message == info) - { - Log.Warn(info); - } - else - { - throw; - } - } + Updater.UpdateApp(); } private void RegisterExitEvents() @@ -123,7 +98,6 @@ namespace Wox if (!_disposed) { Save(); - Updater?.Dispose(); SingleInstance.Cleanup(); } } diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 46d8128ebb..95070080c1 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -4,8 +4,6 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Net; -using System.Reflection; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -15,19 +13,15 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using Microsoft.Win32; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using NHotkey; using NHotkey.Wpf; -using Squirrel; +using Wox.Core; using Wox.Core.Plugin; using Wox.Core.Resource; using Wox.Core.UserSettings; using Wox.Helper; using Wox.Infrastructure.Hotkey; -using Wox.Infrastructure.Http; using Wox.Infrastructure.Image; -using Wox.Infrastructure.Logger; using Wox.Plugin; using Wox.ViewModel; using Application = System.Windows.Forms.Application; @@ -834,15 +828,6 @@ namespace Wox #endregion - #region About - - private void tbWebsite_MouseUp(object sender, MouseButtonEventArgs e) - { - Process.Start(Infrastructure.Wox.Github); - } - - #endregion - private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { // Hide window with ESC, but make sure it is not pressed as a hotkey @@ -854,78 +839,20 @@ namespace Wox private async void OnCheckUpdates(object sender, RoutedEventArgs e) { - var version = await NewVersion(); + var version = await Updater.NewVersion(); if (!string.IsNullOrEmpty(version)) { - var newVersion = NumericVersion(version); - var oldVersion = NumericVersion(Infrastructure.Wox.Version); + var newVersion = Updater.NumericVersion(version); + var oldVersion = Updater.NumericVersion(Infrastructure.Wox.Version); if (newVersion > oldVersion) { NewVersionTips.Text = string.Format(NewVersionTips.Text, version); NewVersionTips.Visibility = Visibility.Visible; - UpdateApp(); + Updater.UpdateApp(); } } } - private async void UpdateApp() - { - try - { - using (var updater = await UpdateManager.GitHubUpdateManager(Infrastructure.Wox.Github)) - { - // todo 5/9 the return value of UpdateApp() is NULL, fucking useless! - await updater.UpdateApp(); - } - } - catch (WebException ex) - { - Log.Error(ex); - } - catch (Exception ex) - { - Log.Error(ex); - } - } - private async Task NewVersion() - { - const string githubAPI = @"https://api.github.com/repos/wox-launcher/wox/releases/latest"; - var response = await HttpRequest.Get(githubAPI, HttpProxy.Instance); - - if (!string.IsNullOrEmpty(response)) - { - JContainer json; - try - { - json = (JContainer)JsonConvert.DeserializeObject(response); - } - catch (JsonSerializationException e) - { - Log.Error(e); - return string.Empty; - } - var version = json?["tag_name"]?.ToString(); - if (!string.IsNullOrEmpty(version)) - { - return version; - } - else - { - return string.Empty; - } - } - else - { - return string.Empty; - } - } - - private - int NumericVersion(string version) - { - var newVersion = version.Replace("v", ".").Replace(".", "").Replace("*", ""); - return int.Parse(newVersion); - } private void OnRequestNavigate(object sender, RequestNavigateEventArgs e) { Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));