diff --git a/Wox.Core/Updater/Release.cs b/Wox.Core/Updater/Release.cs deleted file mode 100644 index 4808ffefb1..0000000000 --- a/Wox.Core/Updater/Release.cs +++ /dev/null @@ -1,16 +0,0 @@ -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; } - - public override string ToString() - { - return version; - } - } -} \ No newline at end of file diff --git a/Wox.Core/Updater/SemanticVersion.cs b/Wox.Core/Updater/SemanticVersion.cs deleted file mode 100644 index 01012183dd..0000000000 --- a/Wox.Core/Updater/SemanticVersion.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System; -using Wox.Infrastructure.Exception; - -namespace Wox.Core.Updater -{ - public class SemanticVersion : IComparable - { - public int MAJOR { get; set; } - public int MINOR { get; set; } - public int PATCH { get; set; } - - public SemanticVersion(Version version) - { - MAJOR = version.Major; - MINOR = version.Minor; - PATCH = version.Build; - } - - public SemanticVersion(int major, int minor, int patch) - { - MAJOR = major; - MINOR = minor; - PATCH = patch; - } - - public SemanticVersion(string version) - { - var strings = version.Split('.'); - if (strings.Length != 3) - { - throw new WoxException("Invalid semantic version"); - } - MAJOR = int.Parse(strings[0]); - MINOR = int.Parse(strings[1]); - PATCH = int.Parse(strings[2]); - } - - public static bool operator >(SemanticVersion v1, SemanticVersion v2) - { - return v1.CompareTo(v2) > 0; - } - - public static bool operator <(SemanticVersion v1, SemanticVersion v2) - { - return v1.CompareTo(v2) < 0; - } - - public static bool operator ==(SemanticVersion v1, SemanticVersion v2) - { - if (ReferenceEquals(v1, null)) - { - return ReferenceEquals(v2, null); - } - if (ReferenceEquals(v2, null)) - { - return false; - } - return v1.Equals(v2); - } - - public static bool operator !=(SemanticVersion v1, SemanticVersion v2) - { - return !(v1 == v2); - } - - public override string ToString() - { - return string.Format("{0}.{1}.{2}", MAJOR, MINOR, PATCH); - } - - public override bool Equals(object version) - { - var v2 = (SemanticVersion)version; - return MAJOR == v2.MAJOR && MINOR == v2.MINOR && PATCH == v2.PATCH; - } - - public int CompareTo(object version) - { - var v2 = (SemanticVersion)version; - if (MAJOR == v2.MAJOR) - { - if (MINOR == v2.MINOR) - { - if (PATCH == v2.PATCH) - { - return 0; - } - return PATCH - v2.PATCH; - } - return MINOR - v2.MINOR; - } - return MAJOR - v2.MAJOR; - } - } -} diff --git a/Wox.Core/Updater/UpdaterManager.cs b/Wox.Core/Updater/UpdaterManager.cs deleted file mode 100644 index 62ea312919..0000000000 --- a/Wox.Core/Updater/UpdaterManager.cs +++ /dev/null @@ -1,182 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Forms; -using NAppUpdate.Framework; -using NAppUpdate.Framework.Common; -using NAppUpdate.Framework.Sources; -using NAppUpdate.Framework.Tasks; -using Newtonsoft.Json; -using Wox.Core.Resource; -using Wox.Core.UserSettings; -using Wox.Infrastructure.Http; -using Wox.Infrastructure.Logger; - -namespace Wox.Core.Updater -{ - public class UpdaterManager - { - private static UpdaterManager instance; - private const string VersionCheckURL = "http://api.getwox.com/release/latest/"; - private const string UpdateFeedURL = "http://upgrade.getwox.com/update.xml"; - //private const string UpdateFeedURL = "http://127.0.0.1:8888/update.xml"; - private static SemanticVersion currentVersion; - public UserSettings.Settings Settings { get; set; } - - public event EventHandler PrepareUpdateReady; - public event EventHandler UpdateError; - - public Release NewRelease { get; set; } - - public static UpdaterManager Instance - { - get - { - if (instance == null) - { - instance = new UpdaterManager(); - } - return instance; - } - } - - private UpdaterManager() - { - UpdateManager.Instance.UpdateSource = GetUpdateSource(); - } - - public SemanticVersion CurrentVersion - { - 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 List GetAvailableUpdateFiles() - { - List files = new List(); - foreach (var task in UpdateManager.Instance.Tasks) - { - if (task is FileUpdateTask) - { - files.Add(((FileUpdateTask)task).LocalPath); - } - } - return files; - } - - public void CheckUpdate() - { - Task.Run(() => - { - string json = HttpRequest.Get(VersionCheckURL, HttpProxy.Instance); - if (!string.IsNullOrEmpty(json)) - { - try - { - NewRelease = JsonConvert.DeserializeObject(json); - if (IsNewerThanCurrent(NewRelease) && !Settings.DontPromptUpdateMsg) - { - StartUpdate(); - } - } - catch (Exception e) - { - Log.Error(e); - } - } - }); - } - - private void StartUpdate() - { - UpdateManager updManager = UpdateManager.Instance; - updManager.BeginCheckForUpdates(asyncResult => - { - if (asyncResult.IsCompleted) - { - // still need to check for caught exceptions if any and rethrow - try - { - ((UpdateProcessAsyncResult)asyncResult).EndInvoke(); - } - catch (Exception e) - { - updManager.CleanUp(); - Log.Error(e); - return; - } - - // No updates were found, or an error has occured. We might want to check that... - if (updManager.UpdatesAvailable == 0) - { - return; - } - } - - updManager.BeginPrepareUpdates(result => - { - ((UpdateProcessAsyncResult)result).EndInvoke(); - OnPrepareUpdateReady(); - }, null); - }, null); - } - - public void CleanUp() - { - UpdateManager.Instance.CleanUp(); - } - - public void ApplyUpdates() - { - // ApplyUpdates is a synchronous method by design. Make sure to save all user work before calling - // it as it might restart your application - // get out of the way so the console window isn't obstructed - try - { - UpdateManager.Instance.ApplyUpdates(true, Settings.EnableUpdateLog, false); - } - catch (Exception e) - { - string updateError = InternationalizationManager.Instance.GetTranslation("update_wox_update_error"); - Log.Error(e); - MessageBox.Show(updateError); - OnUpdateError(); - } - - UpdateManager.Instance.CleanUp(); - } - - private IUpdateSource GetUpdateSource() - { - var source = new WoxUpdateSource(UpdateFeedURL, HttpRequest.GetWebProxy(HttpProxy.Instance)); - return source; - } - - protected virtual void OnPrepareUpdateReady() - { - var handler = PrepareUpdateReady; - if (handler != null) handler(this, EventArgs.Empty); - } - - protected virtual void OnUpdateError() - { - var handler = UpdateError; - if (handler != null) handler(this, EventArgs.Empty); - } - } -} diff --git a/Wox.Core/Updater/WoxUpdateSource.cs b/Wox.Core/Updater/WoxUpdateSource.cs deleted file mode 100644 index a9f86807d3..0000000000 --- a/Wox.Core/Updater/WoxUpdateSource.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.IO; -using System.Net; -using NAppUpdate.Framework.Common; -using NAppUpdate.Framework.Sources; -using NAppUpdate.Framework.Utils; - -namespace Wox.Core.Updater -{ - internal class WoxUpdateSource : IUpdateSource - { - public IWebProxy Proxy { get; set; } - - public string FeedUrl { get; set; } - - public WoxUpdateSource(string feedUrl,IWebProxy proxy) - { - FeedUrl = feedUrl; - Proxy = proxy; - } - - private void TryResolvingHost() - { - Uri uri = new Uri(FeedUrl); - try - { - Dns.GetHostEntry(uri.Host); - } - catch (Exception ex) - { - throw new WebException(string.Format("Failed to resolve {0}. Check your connectivity.", uri.Host), WebExceptionStatus.ConnectFailure); - } - } - - public string GetUpdatesFeed() - { - TryResolvingHost(); - string str = string.Empty; - WebRequest webRequest = WebRequest.Create(FeedUrl); - webRequest.Method = "GET"; - webRequest.Proxy = Proxy; - using (WebResponse response = webRequest.GetResponse()) - { - Stream responseStream = response.GetResponseStream(); - if (responseStream != null) - { - using (StreamReader streamReader = new StreamReader(responseStream, true)) - str = streamReader.ReadToEnd(); - } - } - return str; - } - - public bool GetData(string url, string baseUrl, Action onProgress, ref string tempLocation) - { - if (!string.IsNullOrEmpty(baseUrl) && !baseUrl.EndsWith("/")) - baseUrl += "/"; - FileDownloader fileDownloader = !Uri.IsWellFormedUriString(url, UriKind.Absolute) ? (!Uri.IsWellFormedUriString(baseUrl, UriKind.Absolute) ? (string.IsNullOrEmpty(baseUrl) ? new FileDownloader(url) : new FileDownloader(new Uri(new Uri(baseUrl), url))) : new FileDownloader(new Uri(new Uri(baseUrl, UriKind.Absolute), url))) : new FileDownloader(url); - fileDownloader.Proxy = Proxy; - if (string.IsNullOrEmpty(tempLocation) || !Directory.Exists(Path.GetDirectoryName(tempLocation))) - tempLocation = Path.GetTempFileName(); - return fileDownloader.DownloadToFile(tempLocation, onProgress); - } - } -} diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index 78e8244d23..099a5bf468 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -67,9 +67,6 @@ - - - @@ -90,7 +87,6 @@ - diff --git a/Wox.CrashReporter/ReportWindow.xaml.cs b/Wox.CrashReporter/ReportWindow.xaml.cs index 584e73f3a3..e16fc09bcb 100644 --- a/Wox.CrashReporter/ReportWindow.xaml.cs +++ b/Wox.CrashReporter/ReportWindow.xaml.cs @@ -5,7 +5,7 @@ using System.Windows; using System.Windows.Documents; using Exceptionless; using Wox.Core.Resource; -using Wox.Core.Updater; +using Wox.Infrastructure; namespace Wox.CrashReporter { @@ -23,7 +23,7 @@ namespace Wox.CrashReporter private void SetException(Exception exception) { tbSummary.AppendText(exception.Message); - tbVersion.Text = UpdaterManager.Instance.CurrentVersion.ToString(); + tbVersion.Text = Infrastructure.Wox.Version; tbDatetime.Text = DateTime.Now.ToString(); tbStackTrace.AppendText(exception.StackTrace); tbSource.Text = exception.Source; diff --git a/Wox.CrashReporter/Wox.CrashReporter.csproj b/Wox.CrashReporter/Wox.CrashReporter.csproj index 6a9d6ae48e..dd42697968 100644 --- a/Wox.CrashReporter/Wox.CrashReporter.csproj +++ b/Wox.CrashReporter/Wox.CrashReporter.csproj @@ -78,6 +78,10 @@ {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2} Wox.Core + + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} + Wox.Infrastructure + diff --git a/Wox.Infrastructure/Wox.cs b/Wox.Infrastructure/Wox.cs index 3e04189dac..c6353acfb8 100644 --- a/Wox.Infrastructure/Wox.cs +++ b/Wox.Infrastructure/Wox.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using System.Reflection; @@ -10,11 +11,13 @@ namespace Wox.Infrastructure public const string Plugins = "Plugins"; public const string Settings = "Settings"; - public static readonly string ProgramPath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString(); + private static readonly Assembly Assembly = Assembly.GetExecutingAssembly(); + public static readonly string ProgramPath = Directory.GetParent(Assembly.Location).ToString(); public static readonly string DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Name); public static readonly string UserDirectory = Path.Combine(DataPath, Plugins); public static readonly string PreinstalledDirectory = Path.Combine(ProgramPath, Plugins); public static readonly string SettingsPath = Path.Combine(DataPath, Settings); public const string Github = "https://github.com/Wox-launcher/Wox"; + public static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location).ProductVersion; } } diff --git a/Wox.Test/SemanticVersionTest.cs b/Wox.Test/SemanticVersionTest.cs deleted file mode 100644 index 5b7097b69a..0000000000 --- a/Wox.Test/SemanticVersionTest.cs +++ /dev/null @@ -1,23 +0,0 @@ -using NUnit.Framework; -using Wox.Core.Updater; - -namespace Wox.Test -{ - [TestFixture] - public class SemanticVersionTest - { - [Test] - public void CompareTest() - { - SemanticVersion v1 = new SemanticVersion(1, 1, 0); - SemanticVersion v2 = new SemanticVersion(1, 2, 0); - SemanticVersion v3 = new SemanticVersion(1, 1, 0); - SemanticVersion v4 = new SemanticVersion("1.1.0"); - Assert.IsTrue(v1 < v2); - Assert.IsTrue(v2 > v1); - Assert.IsTrue(v1 == v3); - Assert.IsTrue(v1.Equals(v3)); - Assert.IsTrue(v1 == v4); - } - } -} diff --git a/Wox.Test/Wox.Test.csproj b/Wox.Test/Wox.Test.csproj index e1b65e45b5..0827bde5ad 100644 --- a/Wox.Test/Wox.Test.csproj +++ b/Wox.Test/Wox.Test.csproj @@ -52,7 +52,6 @@ - diff --git a/Wox/CommandArgs/CommandArgsFactory.cs b/Wox/CommandArgs/CommandArgsFactory.cs deleted file mode 100644 index 2b7a7b8b5b..0000000000 --- a/Wox/CommandArgs/CommandArgsFactory.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Wox.Helper; - -namespace Wox.CommandArgs -{ - internal static class CommandArgsFactory - { - private static List commandArgs; - - static CommandArgsFactory() - { - var type = typeof(ICommandArg); - commandArgs = Assembly.GetExecutingAssembly() - .GetTypes() - .Where(p => type.IsAssignableFrom(p) && !p.IsInterface) - .Select(t => Activator.CreateInstance(t) as ICommandArg).ToList(); - } - - public static void Execute(IList args) - { - // todo restart command line args? - //if (args.Count > 0 && args[0] != SingleInstance.Restart) - if (args.Count > 0) - { - string command = args[0]; - ICommandArg cmd = commandArgs.FirstOrDefault(o => o.Command.ToLower() == command); - if (cmd != null) - { - args.RemoveAt(0); //remove command itself - cmd.Execute(args); - } - } - else - { - App.API.ShowApp(); - } - } - } -} diff --git a/Wox/CommandArgs/HideStartCommandArg.cs b/Wox/CommandArgs/HideStartCommandArg.cs deleted file mode 100644 index 1918858b1f..0000000000 --- a/Wox/CommandArgs/HideStartCommandArg.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; - -namespace Wox.CommandArgs -{ - public class HideStartCommandArg : ICommandArg - { - public string Command - { - get { return "hidestart"; } - } - - public void Execute(IList args) - { - //App.Window.ShowApp(); - //App.Window.HideApp(); - } - } -} diff --git a/Wox/CommandArgs/ICommandArg.cs b/Wox/CommandArgs/ICommandArg.cs deleted file mode 100644 index 11db545571..0000000000 --- a/Wox/CommandArgs/ICommandArg.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; - -namespace Wox.CommandArgs -{ - interface ICommandArg - { - string Command { get; } - void Execute(IList args); - } -} diff --git a/Wox/CommandArgs/InstallPluginCommandArg.cs b/Wox/CommandArgs/InstallPluginCommandArg.cs deleted file mode 100644 index 524115b4d6..0000000000 --- a/Wox/CommandArgs/InstallPluginCommandArg.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Windows; -using Wox.Core.Plugin; - -namespace Wox.CommandArgs -{ - public class InstallPluginCommandArg : ICommandArg - { - public string Command - { - get { return "installplugin"; } - } - - public void Execute(IList args) - { - if (args.Count > 0) - { - var path = args[0]; - if (!File.Exists(path)) - { - MessageBox.Show("Plugin " + path + " didn't exist"); - return; - } - PluginManager.InstallPlugin(path); - } - } - } -} \ No newline at end of file diff --git a/Wox/CommandArgs/QueryCommandArg.cs b/Wox/CommandArgs/QueryCommandArg.cs deleted file mode 100644 index d1df8e0a5b..0000000000 --- a/Wox/CommandArgs/QueryCommandArg.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Wox.CommandArgs -{ - public class QueryCommandArg : ICommandArg - { - public string Command - { - get { return "query"; } - } - - public void Execute(IList args) - { - Console.WriteLine("test"); - if (args.Count > 0) - { - string query = args[0]; - App.API.ChangeQuery(query); - } - App.API.ShowApp(); - } - } -} diff --git a/Wox/CommandArgs/ToggleCommandArg.cs b/Wox/CommandArgs/ToggleCommandArg.cs deleted file mode 100644 index e509316291..0000000000 --- a/Wox/CommandArgs/ToggleCommandArg.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; - -namespace Wox.CommandArgs -{ - public class ToggleCommandArg:ICommandArg - { - public string Command - { - get { return "toggle"; } - } - - public void Execute(IList args) - { - if (App.Window.IsVisible) - { - App.API.HideApp(); - } - else - { - App.API.ShowApp(); - } - } - } -} diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index cf9e20e62d..4d94ef8d9a 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -7,7 +7,6 @@ using System.Windows.Media.Animation; using System.Windows.Controls; using Wox.Core.Plugin; using Wox.Core.Resource; -using Wox.Core.Updater; using Wox.Core.UserSettings; using Wox.Helper; using Wox.Infrastructure.Hotkey; @@ -47,8 +46,6 @@ namespace Wox private void OnLoaded(object sender, RoutedEventArgs _) { - CheckUpdate(); - InitProgressbarAnimation(); WindowIntelopHelper.DisableControlBox(this); @@ -110,27 +107,6 @@ namespace Wox return top; } - private void CheckUpdate() - { - UpdaterManager.Instance.PrepareUpdateReady += OnPrepareUpdateReady; - UpdaterManager.Instance.UpdateError += OnUpdateError; - UpdaterManager.Instance.CheckUpdate(); - } - - void OnUpdateError(object sender, EventArgs e) - { - string updateError = InternationalizationManager.Instance.GetTranslation("update_wox_update_error"); - MessageBox.Show(updateError); - } - - private void OnPrepareUpdateReady(object sender, EventArgs e) - { - Dispatcher.Invoke(() => - { - new WoxUpdate().ShowDialog(); - }); - } - private void InitProgressbarAnimation() { var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs index a8a8e7f1fe..4a7978c6ad 100644 --- a/Wox/ViewModel/MainViewModel.cs +++ b/Wox/ViewModel/MainViewModel.cs @@ -7,7 +7,6 @@ using System.Windows; using System.Windows.Input; using Wox.Core.Plugin; using Wox.Core.Resource; -using Wox.Core.Updater; using Wox.Core.UserSettings; using Wox.Helper; using Wox.Infrastructure; @@ -64,7 +63,6 @@ namespace Wox.ViewModel // happlebao todo temp fix for instance code logic HttpProxy.Instance.Settings = _settings; - UpdaterManager.Instance.Settings = _settings; InternationalizationManager.Instance.Settings = _settings; InternationalizationManager.Instance.ChangeLanguage(_settings.Language); ThemeManager.Instance.Settings = _settings; diff --git a/Wox/WoxUpdate.xaml b/Wox/WoxUpdate.xaml deleted file mode 100644 index 23687ff5a9..0000000000 --- a/Wox/WoxUpdate.xaml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -