From c6e65b4e24e406bd35912a869ada0c93f9f01ae4 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Mon, 6 Mar 2017 00:25:17 +0000 Subject: [PATCH 1/6] test --- Deploy/local_build.ps1 | 4 ++++ Wox.Core/Updater.cs | 34 +++++++++++++++++++++++++++++++--- Wox/App.xaml.cs | 2 +- 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 Deploy/local_build.ps1 diff --git a/Deploy/local_build.ps1 b/Deploy/local_build.ps1 new file mode 100644 index 0000000000..9dd7582b19 --- /dev/null +++ b/Deploy/local_build.ps1 @@ -0,0 +1,4 @@ +New-Alias nuget.exe ".\packages\NuGet.CommandLine.*\tools\NuGet.exe" +$env:APPVEYOR_BUILD_FOLDER = Convert-Path . +$env:APPVEYOR_BUILD_VERSION = "1.2.0" +& .\Deploy\squirrel_installer.ps1 \ No newline at end of file diff --git a/Wox.Core/Updater.cs b/Wox.Core/Updater.cs index e6ea1c7933..a39cab0df9 100644 --- a/Wox.Core/Updater.cs +++ b/Wox.Core/Updater.cs @@ -4,9 +4,12 @@ using System.Net; using System.Net.Http; using System.Net.Sockets; using System.Threading.Tasks; +using System.Windows; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Squirrel; +using Wox.Core.Resource; +using Wox.Infrastructure; using Wox.Infrastructure.Http; using Wox.Infrastructure.Logger; @@ -22,11 +25,28 @@ namespace Wox.Core try { - const string url = Infrastructure.Constant.Github; - // todo 5/9 the return value of UpdateApp() is NULL, fucking useless! + const string url = Constant.Github; + // UpdateApp() will return value only if the app is squirrel installed using (var m = await UpdateManager.GitHubUpdateManager(url, urlDownloader: d)) { - await m.UpdateApp(); + var e = await m.CheckForUpdate(); + var fe = e.FutureReleaseEntry; + var ce = e.CurrentlyInstalledVersion; + if (fe.Version > ce.Version) + { + var t = NewVersinoTips(fe.Version.ToString()); + MessageBox.Show(t); + + await m.DownloadReleases(e.ReleasesToApply); + await m.ApplyReleases(e); + await m.CreateUninstallerRegistryEntry(); + + Log.Info($"|Updater.UpdateApp|TEST <{e.Formatted()}>"); + Log.Info($"|Updater.UpdateApp|TEST <{fe.Formatted()}>"); + Log.Info($"|Updater.UpdateApp|TEST <{ce.Formatted()}>"); + Log.Info($"|Updater.UpdateApp|TEST <{e.ReleasesToApply.Formatted()}>"); + Log.Info($"|Updater.UpdateApp|TEST <{t.Formatted()}>"); + } } } catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException) @@ -99,5 +119,13 @@ namespace Wox.Core var newVersion = version.Replace("v", ".").Replace(".", "").Replace("*", ""); return int.Parse(newVersion); } + + public static string NewVersinoTips(string version) + { + var translater = InternationalizationManager.Instance; + var tips = string.Format(translater.GetTranslation("newVersionTips"), version); + return tips; + } + } } diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 012f2be7e9..14a798a6a7 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -95,7 +95,7 @@ namespace Wox } } - [Conditional("RELEASE")] + //[Conditional("RELEASE")] private void AutoUpdates() { Task.Run(async () => From 0862326a79e589c1c3599488db5d38fd6cf1a646 Mon Sep 17 00:00:00 2001 From: martian-f Date: Mon, 10 Apr 2017 23:43:23 +0200 Subject: [PATCH 2/6] Convert calculator numbers from/to user locale. Tries to convert numbers in query string to invariant culture format before passing to YAMP, and the other way around when presenting result from YAMP. Nothing fancy, just a regular expression scanning for substrings consisting of number, decimal separator and group separator, trying a parse and convert on them. Translation is skipped if no conversion between user locale and invariant culture number format is necessary. Closes #436. --- Plugins/Wox.Plugin.Calculator/Main.cs | 42 ++++---- .../Wox.Plugin.Calculator/NumberTranslator.cs | 95 +++++++++++++++++++ .../Wox.Plugin.Calculator.csproj | 1 + 3 files changed, 120 insertions(+), 18 deletions(-) create mode 100644 Plugins/Wox.Plugin.Calculator/NumberTranslator.cs diff --git a/Plugins/Wox.Plugin.Calculator/Main.cs b/Plugins/Wox.Plugin.Calculator/Main.cs index 9e7036e650..42f592b187 100644 --- a/Plugins/Wox.Plugin.Calculator/Main.cs +++ b/Plugins/Wox.Plugin.Calculator/Main.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Globalization; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Windows; @@ -20,6 +21,7 @@ namespace Wox.Plugin.Caculator private static Regex regBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled); private static ParseContext yampContext; private PluginInitContext context { get; set; } + private NumberTranslator _numberTranslator; static Main() { @@ -36,34 +38,37 @@ namespace Wox.Plugin.Caculator try { - var result = yampContext.Run(query.Search); + var result = yampContext.Run(this._numberTranslator?.Translate(query.Search) ?? query.Search); if (result.Output != null && !string.IsNullOrEmpty(result.Result)) { + string resultValue = this._numberTranslator?.TranslateBack(result.Result) ?? result.Result; return new List - { new Result - { - Title = result.Result, - IcoPath = "Images/calculator.png", - Score = 300, - SubTitle = "Copy this number to the clipboard", - Action = c => + { + new Result { - try + Title = resultValue, + IcoPath = "Images/calculator.png", + Score = 300, + SubTitle = "Copy this number to the clipboard", + Action = c => { - Clipboard.SetText(result.Result); - return true; - } - catch (ExternalException e) - { - MessageBox.Show("Copy failed, please try later"); - return false; + try + { + Clipboard.SetText(resultValue); + return true; + } + catch (ExternalException e) + { + MessageBox.Show("Copy failed, please try later"); + return false; + } } } - } }; + }; } } catch - {} + { } return new List(); } @@ -90,6 +95,7 @@ namespace Wox.Plugin.Caculator public void Init(PluginInitContext context) { this.context = context; + this._numberTranslator = NumberTranslator.Create(CultureInfo.CurrentCulture, CultureInfo.InvariantCulture); } public string GetTranslatedPluginTitle() diff --git a/Plugins/Wox.Plugin.Calculator/NumberTranslator.cs b/Plugins/Wox.Plugin.Calculator/NumberTranslator.cs new file mode 100644 index 0000000000..448301d4fb --- /dev/null +++ b/Plugins/Wox.Plugin.Calculator/NumberTranslator.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace Wox.Plugin.Caculator +{ + /// + /// Tries to convert all numbers in a text from one culture format to another. + /// + public class NumberTranslator + { + private readonly CultureInfo sourceCulture; + private readonly CultureInfo targetCulture; + private readonly Regex splitRegexForSource; + private readonly Regex splitRegexForTarget; + + private NumberTranslator(CultureInfo sourceCulture, CultureInfo targetCulture) + { + this.sourceCulture = sourceCulture; + this.targetCulture = targetCulture; + + this.splitRegexForSource = GetSplitRegex(this.sourceCulture); + this.splitRegexForTarget = GetSplitRegex(this.targetCulture); + } + + /// + /// Create a new - returns null if no number conversion + /// is required between the cultures. + /// + /// source culture + /// target culture + /// + public static NumberTranslator Create(CultureInfo sourceCulture, CultureInfo targetCulture) + { + bool conversionRequired = sourceCulture.NumberFormat.NumberDecimalSeparator != targetCulture.NumberFormat.NumberDecimalSeparator + || sourceCulture.NumberFormat.PercentGroupSeparator != targetCulture.NumberFormat.PercentGroupSeparator + || sourceCulture.NumberFormat.NumberGroupSizes != targetCulture.NumberFormat.NumberGroupSizes; + return conversionRequired + ? new NumberTranslator(sourceCulture, targetCulture) + : null; + } + + /// + /// Translate from source to target culture. + /// + /// + /// + public string Translate(string input) + { + return this.Translate(input, this.sourceCulture, this.targetCulture, this.splitRegexForSource); + } + + /// + /// Translate from target to source culture. + /// + /// + /// + public string TranslateBack(string input) + { + return this.Translate(input, this.targetCulture, this.sourceCulture, this.splitRegexForTarget); + } + + private string Translate(string input, CultureInfo cultureFrom, CultureInfo cultureTo, Regex splitRegex) + { + var outputBuilder = new StringBuilder(); + + string[] tokens = splitRegex.Split(input); + foreach (string token in tokens) + { + decimal number; + outputBuilder.Append( + decimal.TryParse(token, NumberStyles.Number, cultureFrom, out number) + ? number.ToString(cultureTo) + : token); + } + + return outputBuilder.ToString(); + } + + private Regex GetSplitRegex(CultureInfo culture) + { + var splitPattern = $"((?:\\d|{Regex.Escape(culture.NumberFormat.NumberDecimalSeparator)}"; + if (!string.IsNullOrEmpty(culture.NumberFormat.NumberGroupSeparator)) + { + splitPattern += $"|{Regex.Escape(culture.NumberFormat.NumberGroupSeparator)}"; + } + splitPattern += ")+)"; + return new Regex(splitPattern); + } + } +} diff --git a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj index 7d9aefe604..c65590ea74 100644 --- a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj +++ b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj @@ -51,6 +51,7 @@ Properties\SolutionAssemblyInfo.cs + From 36111aa001625824241c264adc16b03357c1b1bf Mon Sep 17 00:00:00 2001 From: Michael Wirth Date: Sun, 15 Oct 2017 20:21:23 +0200 Subject: [PATCH 3/6] since Yamp is not maintained anymore, i switched it for Mages https://github.com/FlorianRappl/Mages fixes also #1022 --- .../Wox.Plugin.Calculator/Languages/de.xaml | 4 +- .../Wox.Plugin.Calculator/Languages/en.xaml | 4 +- Plugins/Wox.Plugin.Calculator/Main.cs | 57 ++++++++++--------- .../Wox.Plugin.Calculator.csproj | 8 +-- Plugins/Wox.Plugin.Calculator/packages.config | 2 +- 5 files changed, 40 insertions(+), 35 deletions(-) diff --git a/Plugins/Wox.Plugin.Calculator/Languages/de.xaml b/Plugins/Wox.Plugin.Calculator/Languages/de.xaml index 02c51e8c78..286e4bc9b3 100644 --- a/Plugins/Wox.Plugin.Calculator/Languages/de.xaml +++ b/Plugins/Wox.Plugin.Calculator/Languages/de.xaml @@ -4,5 +4,7 @@ Rechner Stellt mathematische Berechnungen bereit.(Versuche 5*3-2 in Wox) - + Keine Zahl (NaN) + Ausdruck falsch oder nicht vollständig (Klammern vergessen?) + Diese Zahl in die Zwischenablage kopieren \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Calculator/Languages/en.xaml b/Plugins/Wox.Plugin.Calculator/Languages/en.xaml index 833a0c14bb..e354839e7c 100644 --- a/Plugins/Wox.Plugin.Calculator/Languages/en.xaml +++ b/Plugins/Wox.Plugin.Calculator/Languages/en.xaml @@ -4,5 +4,7 @@ Calculator Allows to do mathematical calculations.(Try 5*3-2 in Wox) - + Not a Number (NaN) + Expression wrong or incomplete (Did you forget some Brackets?) + Copy this Number to the clipboard \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Calculator/Main.cs b/Plugins/Wox.Plugin.Calculator/Main.cs index 42f592b187..cefb686b97 100644 --- a/Plugins/Wox.Plugin.Calculator/Main.cs +++ b/Plugins/Wox.Plugin.Calculator/Main.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; -using System.Globalization; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Windows; -using YAMP; +using Mages; +using Mages.Core; namespace Wox.Plugin.Caculator { @@ -19,15 +19,12 @@ namespace Wox.Plugin.Caculator @"[ei]|[0-9]|[\+\-\*\/\^\., ""]|[\(\)\|\!\[\]]" + @")+$", RegexOptions.Compiled); private static Regex regBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled); - private static ParseContext yampContext; + private static Mages.Core.Engine magesEngine; private PluginInitContext context { get; set; } - private NumberTranslator _numberTranslator; static Main() { - yampContext = Parser.PrimaryContext; - Parser.InteractiveMode = false; - Parser.UseScripting = false; + magesEngine = new Engine(); } public List Query(Query query) @@ -38,33 +35,38 @@ namespace Wox.Plugin.Caculator try { - var result = yampContext.Run(this._numberTranslator?.Translate(query.Search) ?? query.Search); - if (result.Output != null && !string.IsNullOrEmpty(result.Result)) + var result = magesEngine.Interpret(query.Search); + + if (result.ToString() == "NaN") + result = context.API.GetTranslation("wox_plugin_calculator_not_a_number"); + + if (result is Function) + result = context.API.GetTranslation("wox_plugin_calculator_expression_not_complete"); + + + if (result != null && !string.IsNullOrEmpty(result.ToString())) { - string resultValue = this._numberTranslator?.TranslateBack(result.Result) ?? result.Result; return new List + { new Result { - new Result + Title = result.ToString(), + IcoPath = "Images/calculator.png", + Score = 300, + SubTitle = context.API.GetTranslation("wox_plugin_calculator_copy_number_to_clipboard"), + Action = c => { - Title = resultValue, - IcoPath = "Images/calculator.png", - Score = 300, - SubTitle = "Copy this number to the clipboard", - Action = c => + try { - try - { - Clipboard.SetText(resultValue); - return true; - } - catch (ExternalException e) - { - MessageBox.Show("Copy failed, please try later"); - return false; - } + Clipboard.SetText(result.ToString()); + return true; + } + catch (ExternalException e) + { + MessageBox.Show("Copy failed, please try later"); + return false; } } - }; + } }; } } catch @@ -95,7 +97,6 @@ namespace Wox.Plugin.Caculator public void Init(PluginInitContext context) { this.context = context; - this._numberTranslator = NumberTranslator.Create(CultureInfo.CurrentCulture, CultureInfo.InvariantCulture); } public string GetTranslatedPluginTitle() diff --git a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj index c65590ea74..8fd3169a84 100644 --- a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj +++ b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj @@ -38,14 +38,14 @@ ..\..\packages\JetBrains.Annotations.10.3.0\lib\net\JetBrains.Annotations.dll True + + ..\..\packages\Mages.1.5.0\lib\net35\Mages.Core.dll + True + - - ..\..\packages\YAMP.1.4.0\lib\net35\YAMP.dll - True - diff --git a/Plugins/Wox.Plugin.Calculator/packages.config b/Plugins/Wox.Plugin.Calculator/packages.config index d1fce409f5..c17f6726fd 100644 --- a/Plugins/Wox.Plugin.Calculator/packages.config +++ b/Plugins/Wox.Plugin.Calculator/packages.config @@ -1,6 +1,6 @@  + - \ No newline at end of file From 742048f24e3413e31cd8a77bc51f2550229ea9da Mon Sep 17 00:00:00 2001 From: Michael Wirth Date: Mon, 16 Oct 2017 20:17:53 +0200 Subject: [PATCH 4/6] Fixed typos and swapped Brackets for parentheses, Corrections due to PR --- .../Wox.Plugin.Calculator/Languages/en.xaml | 6 +- Plugins/Wox.Plugin.Calculator/Main.cs | 67 ++++++++++--------- Wox.Infrastructure/Logger/Log.cs | 2 +- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/Plugins/Wox.Plugin.Calculator/Languages/en.xaml b/Plugins/Wox.Plugin.Calculator/Languages/en.xaml index e354839e7c..3b5fa32b33 100644 --- a/Plugins/Wox.Plugin.Calculator/Languages/en.xaml +++ b/Plugins/Wox.Plugin.Calculator/Languages/en.xaml @@ -4,7 +4,7 @@ Calculator Allows to do mathematical calculations.(Try 5*3-2 in Wox) - Not a Number (NaN) - Expression wrong or incomplete (Did you forget some Brackets?) - Copy this Number to the clipboard + Not a number (NaN) + Expression wrong or incomplete (Did you forget some parentheses?) + Copy this number to the clipboard \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Calculator/Main.cs b/Plugins/Wox.Plugin.Calculator/Main.cs index cefb686b97..fab0b8e030 100644 --- a/Plugins/Wox.Plugin.Calculator/Main.cs +++ b/Plugins/Wox.Plugin.Calculator/Main.cs @@ -2,14 +2,13 @@ using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Windows; -using Mages; using Mages.Core; namespace Wox.Plugin.Caculator { public class Main : IPlugin, IPluginI18n { - private static Regex regValidExpressChar = new Regex( + private static readonly Regex RegValidExpressChar = new Regex( @"^(" + @"ceil|floor|exp|pi|e|max|min|det|abs|log|ln|sqrt|" + @"sin|cos|tan|arcsin|arccos|arctan|" + @@ -18,66 +17,70 @@ namespace Wox.Plugin.Caculator @"==|~=|&&|\|\||" + @"[ei]|[0-9]|[\+\-\*\/\^\., ""]|[\(\)\|\!\[\]]" + @")+$", RegexOptions.Compiled); - private static Regex regBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled); - private static Mages.Core.Engine magesEngine; - private PluginInitContext context { get; set; } + private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled); + private static readonly Engine MagesEngine; + private PluginInitContext Context { get; set; } static Main() { - magesEngine = new Engine(); + MagesEngine = new Engine(); } public List Query(Query query) { if (query.Search.Length <= 2 // don't affect when user only input "e" or "i" keyword - || !regValidExpressChar.IsMatch(query.Search) + || !RegValidExpressChar.IsMatch(query.Search) || !IsBracketComplete(query.Search)) return new List(); try { - var result = magesEngine.Interpret(query.Search); + var result = MagesEngine.Interpret(query.Search); if (result.ToString() == "NaN") - result = context.API.GetTranslation("wox_plugin_calculator_not_a_number"); + result = Context.API.GetTranslation("wox_plugin_calculator_not_a_number"); if (result is Function) - result = context.API.GetTranslation("wox_plugin_calculator_expression_not_complete"); + result = Context.API.GetTranslation("wox_plugin_calculator_expression_not_complete"); - if (result != null && !string.IsNullOrEmpty(result.ToString())) + if (!string.IsNullOrEmpty(result?.ToString())) { return new List - { new Result { - Title = result.ToString(), - IcoPath = "Images/calculator.png", - Score = 300, - SubTitle = context.API.GetTranslation("wox_plugin_calculator_copy_number_to_clipboard"), - Action = c => + new Result { - try + Title = result.ToString(), + IcoPath = "Images/calculator.png", + Score = 300, + SubTitle = Context.API.GetTranslation("wox_plugin_calculator_copy_number_to_clipboard"), + Action = c => { - Clipboard.SetText(result.ToString()); - return true; + try + { + Clipboard.SetText(result.ToString()); + return true; + } + catch (ExternalException) + { + MessageBox.Show("Copy failed, please try later"); + return false; + } } - catch (ExternalException e) - { - MessageBox.Show("Copy failed, please try later"); - return false; - } - } - } }; + } + }; } } catch - { } + { + // ignored + } return new List(); } private bool IsBracketComplete(string query) { - var matchs = regBrackets.Matches(query); + var matchs = RegBrackets.Matches(query); var leftBracketCount = 0; foreach (Match match in matchs) { @@ -96,17 +99,17 @@ namespace Wox.Plugin.Caculator public void Init(PluginInitContext context) { - this.context = context; + Context = context; } public string GetTranslatedPluginTitle() { - return context.API.GetTranslation("wox_plugin_caculator_plugin_name"); + return Context.API.GetTranslation("wox_plugin_caculator_plugin_name"); } public string GetTranslatedPluginDescription() { - return context.API.GetTranslation("wox_plugin_caculator_plugin_description"); + return Context.API.GetTranslation("wox_plugin_caculator_plugin_description"); } } } diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index f7ea74b31c..d02654978d 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -72,7 +72,7 @@ namespace Wox.Infrastructure.Logger public static void Exception(string message, System.Exception e) { #if DEBUG - throw e; + //throw e; #else if (FormatValid(message)) { From cfe923b8c4447060bcde23b4283ff8f4851f4469 Mon Sep 17 00:00:00 2001 From: Michael Wirth Date: Tue, 17 Oct 2017 20:01:41 +0200 Subject: [PATCH 5/6] re-enabled exception during debug --- Wox.Infrastructure/Logger/Log.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index d02654978d..f7ea74b31c 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -72,7 +72,7 @@ namespace Wox.Infrastructure.Logger public static void Exception(string message, System.Exception e) { #if DEBUG - //throw e; + throw e; #else if (FormatValid(message)) { From 83282ebcb8f27bdb05c81059511c4254923b0d2d Mon Sep 17 00:00:00 2001 From: jhdxr Date: Sat, 21 Oct 2017 15:39:39 +0800 Subject: [PATCH 6/6] fix #1397 action keywords should not be set to empty string --- Wox/ActionKeywords.xaml.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Wox/ActionKeywords.xaml.cs b/Wox/ActionKeywords.xaml.cs index 2dc0e02bd1..c86671c6ef 100644 --- a/Wox/ActionKeywords.xaml.cs +++ b/Wox/ActionKeywords.xaml.cs @@ -40,6 +40,7 @@ namespace Wox { var oldActionKeyword = _plugin.Metadata.ActionKeywords[0]; var newActionKeyword = tbAction.Text.Trim(); + newActionKeyword = newActionKeyword.Length > 0 ? newActionKeyword : "*"; if (!PluginManager.ActionKeywordRegistered(newActionKeyword)) { var id = _plugin.Metadata.ID;