diff --git a/.gitignore b/.gitignore index 89f4435724..fc8205cacb 100644 --- a/.gitignore +++ b/.gitignore @@ -120,3 +120,4 @@ Wox/Images/Thumbs.db Wox/Wox.csproj *.sublime-* +*.dgml diff --git a/Deploy/Installer/Installer.iss b/Deploy/Installer/Installer.iss index 21f08fd913..3a1f64b00f 100644 --- a/Deploy/Installer/Installer.iss +++ b/Deploy/Installer/Installer.iss @@ -7,7 +7,7 @@ #define MyAppVer = GetFileVersion(MyAppPath + "\Wox.exe") [Setup] -AppId={{A5AF4C34-70A7-4D3B-BA18-E49C0AEEA5E6} +AppId=05700E94-3DAD-4827-8AAA-9908178DE132-Wox AppMutex=DBDE24E4-91F6-11DF-B495-C536DFD72085-Wox AppName={#MyAppName} AppVerName={#MyAppName} v{#MyAppVer} @@ -21,6 +21,8 @@ OutputBaseFilename=Wox-setup OutputDir={#OutputPath} Compression=lzma SolidCompression=yes +DisableDirPage=auto +DisableProgramGroupPage=auto [Languages] Name: english; MessagesFile: compiler:Default.isl @@ -29,11 +31,13 @@ Name: english; MessagesFile: compiler:Default.isl Type: files; Name: "{commonstartup}\{#MyAppName}.lnk" [Tasks] -Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}; Flags: unchecked +Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}; Name: startupfolder; Description: Startup with Windows; [Files] -Source: {#MyAppPath}\*; DestDir: {app}; Flags: ignoreversion recursesubdirs +Source: {#MyAppPath}\*; Excludes: Plugins\*; DestDir: {app}; Flags: ignoreversion recursesubdirs +Source: {#MyAppPath}\Plugins\*; DestDir: {%USERPROFILE}\.Wox\Plugins; Flags: ignoreversion recursesubdirs +Source: {#MyAppPath}\Themes\Base.xaml; DestDir: {%USERPROFILE}\.Wox\Themes; Flags: ignoreversion recursesubdirs [Icons] Name: {group}\{#MyAppName}; Filename: {app}\{#MyAppExeName} @@ -42,4 +46,10 @@ Name: {userdesktop}\{#MyAppName}; Filename: {app}\{#MyAppExeName}; Tasks: deskto Name: {userstartup}\{#MyAppName}; Filename: {app}\{#MyAppExeName}; Tasks: startupfolder [Run] -Filename: {app}\{#MyAppExeName}; Description: {cm:LaunchProgram,{#MyAppName}}; Flags: nowait postinstall skipifsilent +Filename: {app}\{#MyAppExeName}; Description: {cm:LaunchProgram,{#MyAppName}}; Flags: nowait postinstall skipifsilent unchecked + +[UninstallDelete] +Type: filesandordirs; Name: "{%USERPROFILE}\.Wox" + +[UninstallRun] +Filename: {sys}\taskkill.exe; Parameters: "/f /im Wox.exe"; Flags: skipifdoesntexist runhidden diff --git a/Deploy/NAppUpdate/FeedBuilder.config b/Deploy/NAppUpdate/FeedBuilder.config new file mode 100644 index 0000000000..f06954dd29 --- /dev/null +++ b/Deploy/NAppUpdate/FeedBuilder.config @@ -0,0 +1,18 @@ + + + + True + False + True + True + <?xml version="1.0" encoding="utf-16"?> +<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /> + True + True + E:\github\Wox\Output\Debug + True + False + E:\github\Wox\Output\Update\Update.xml + + http://127.0.0.1:8888 + diff --git a/Deploy/NAppUpdate/FeedBuilder.exe b/Deploy/NAppUpdate/FeedBuilder.exe new file mode 100644 index 0000000000..fae2128316 Binary files /dev/null and b/Deploy/NAppUpdate/FeedBuilder.exe differ diff --git a/Deploy/NAppUpdate/FeedBuilder.exe.config b/Deploy/NAppUpdate/FeedBuilder.exe.config new file mode 100644 index 0000000000..ae58790841 --- /dev/null +++ b/Deploy/NAppUpdate/FeedBuilder.exe.config @@ -0,0 +1,54 @@ + + + + +
+ + + + + + + + + True + + + False + + + True + + + False + + + True + + + True + + + + + + True + + + + + *.pdb + *.config + + + + + True + + + + + + + \ No newline at end of file diff --git a/Deploy/NAppUpdate/NAppUpdate.Framework.dll b/Deploy/NAppUpdate/NAppUpdate.Framework.dll new file mode 100644 index 0000000000..60fac8ffc9 Binary files /dev/null and b/Deploy/NAppUpdate/NAppUpdate.Framework.dll differ diff --git a/Deploy/NAppUpdate/build.bat b/Deploy/NAppUpdate/build.bat new file mode 100644 index 0000000000..4cf7775756 --- /dev/null +++ b/Deploy/NAppUpdate/build.bat @@ -0,0 +1 @@ +FeedBuilder.exe "FeedBuilder.config" -Build diff --git a/Deploy/NAppUpdate/gui.bat b/Deploy/NAppUpdate/gui.bat new file mode 100644 index 0000000000..6c8eaf13e7 --- /dev/null +++ b/Deploy/NAppUpdate/gui.bat @@ -0,0 +1 @@ +FeedBuilder.exe "FeedBuilder.config" -ShowGUI diff --git a/Doc/app.psd b/Doc/app.psd index 1694f8d5dd..833fd6529a 100644 Binary files a/Doc/app.psd and b/Doc/app.psd differ diff --git a/Doc/app_error.png b/Doc/app_error.png new file mode 100644 index 0000000000..5106d6e8a9 Binary files /dev/null and b/Doc/app_error.png differ diff --git a/Doc/app_error.psd b/Doc/app_error.psd new file mode 100644 index 0000000000..174e9cb62d Binary files /dev/null and b/Doc/app_error.psd differ diff --git a/Wox.Plugin.SystemPlugins/CMD/CMD.cs b/Plugins/Wox.Plugin.CMD/CMD.cs similarity index 51% rename from Wox.Plugin.SystemPlugins/CMD/CMD.cs rename to Plugins/Wox.Plugin.CMD/CMD.cs index 7855c7d6fc..cde0bb6f89 100644 --- a/Wox.Plugin.SystemPlugins/CMD/CMD.cs +++ b/Plugins/Wox.Plugin.CMD/CMD.cs @@ -2,103 +2,39 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.Serialization.Formatters.Binary; +using System.Reflection; using System.Windows.Forms; +using WindowsInput; +using WindowsInput.Native; +using Wox.Infrastructure.Hotkey; using Control = System.Windows.Controls.Control; -namespace Wox.Plugin.SystemPlugins.CMD +namespace Wox.Plugin.CMD { - public class CMD : BaseSystemPlugin, ISettingProvider + public class CMD : IPlugin, ISettingProvider, IPluginI18n { private PluginInitContext context; + private bool WinRStroked; + private readonly KeyboardSimulator keyboardSimulator = new KeyboardSimulator(new InputSimulator()); - protected override List QueryInternal(Query query) + public List Query(Query query) { List results = new List(); List pushedResults = new List(); if (query.RawQuery == ">") { - IEnumerable history = CMDStorage.Instance.CMDHistory.OrderByDescending(o => o.Value) - .Select(m => new Result - { - Title = m.Key, - SubTitle = "this command has been executed " + m.Value + " times", - IcoPath = "Images/cmd.png", - Action = (c) => - { - ExecuteCmd(m.Key); - return true; - }, - ContextMenu = GetContextMenus(m.Key) - }).Take(5); - - results.AddRange(history); + return GetAllHistoryCmds(); } if (query.RawQuery.StartsWith(">") && query.RawQuery.Length > 1) { string cmd = query.RawQuery.Substring(1); - Result result = new Result - { - Title = cmd, - Score = 5000, - SubTitle = "execute command through command shell", - IcoPath = "Images/cmd.png", - Action = (c) => - { - ExecuteCmd(cmd); - return true; - }, - ContextMenu = GetContextMenus(cmd) - }; + var queryCmd = GetCurrentCmd(cmd); + context.API.PushResults(query, context.CurrentPluginMetadata, new List() { queryCmd }); + pushedResults.Add(queryCmd); - try - { - if (File.Exists(cmd) || Directory.Exists(cmd)) - { - result.IcoPath = cmd; - } - } - catch (Exception) { } - - context.API.PushResults(query, context.CurrentPluginMetadata, new List() { result }); - pushedResults.Add(result); - - IEnumerable history = CMDStorage.Instance.CMDHistory.Where(o => o.Key.Contains(cmd)) - .OrderByDescending(o => o.Value) - .Select(m => - { - if (m.Key == cmd) - { - result.SubTitle = "this command has been executed " + m.Value + " times"; - return null; - } - - var ret = new Result - { - Title = m.Key, - SubTitle = "this command has been executed " + m.Value + " times", - IcoPath = "Images/cmd.png", - Action = (c) => - { - ExecuteCmd(m.Key); - return true; - }, - ContextMenu = GetContextMenus(m.Key) - }; - try - { - if (File.Exists(m.Key) || Directory.Exists(m.Key)) - { - ret.IcoPath = m.Key; - } - } - catch (Exception) { } - - return ret; - }).Where(o => o != null).Take(4); - - context.API.PushResults(query, context.CurrentPluginMetadata, history.ToList()); + var history = GetHistoryCmds(cmd, queryCmd); + context.API.PushResults(query, context.CurrentPluginMetadata, history); pushedResults.AddRange(history); try @@ -125,8 +61,7 @@ namespace Wox.Plugin.SystemPlugins.CMD results.AddRange(autocomplete.ConvertAll(m => new Result() { Title = m, - SubTitle = "", - IcoPath = m, + IcoPath = "Images/cmd.png", Action = (c) => { ExecuteCmd(m); @@ -141,6 +76,72 @@ namespace Wox.Plugin.SystemPlugins.CMD return results; } + private List GetHistoryCmds(string cmd, Result result) + { + IEnumerable history = CMDStorage.Instance.CMDHistory.Where(o => o.Key.Contains(cmd)) + .OrderByDescending(o => o.Value) + .Select(m => + { + if (m.Key == cmd) + { + result.SubTitle = "this command has been executed " + m.Value + " times"; + return null; + } + + var ret = new Result + { + Title = m.Key, + SubTitle = "this command has been executed " + m.Value + " times", + IcoPath = "Images/cmd.png", + Action = (c) => + { + ExecuteCmd(m.Key); + return true; + }, + ContextMenu = GetContextMenus(m.Key) + }; + return ret; + }).Where(o => o != null).Take(4); + return history.ToList(); + } + + private Result GetCurrentCmd(string cmd) + { + Result result = new Result + { + Title = cmd, + Score = 5000, + SubTitle = "execute command through command shell", + IcoPath = "Images/cmd.png", + Action = (c) => + { + ExecuteCmd(cmd); + return true; + }, + ContextMenu = GetContextMenus(cmd) + }; + + return result; + } + + private List GetAllHistoryCmds() + { + IEnumerable history = CMDStorage.Instance.CMDHistory.OrderByDescending(o => o.Value) + .Select(m => new Result + { + Title = m.Key, + SubTitle = "this command has been executed " + m.Value + " times", + IcoPath = "Images/cmd.png", + Action = (c) => + { + ExecuteCmd(m.Key); + return true; + }, + ContextMenu = GetContextMenus(m.Key) + }).Take(5); + return history.ToList(); + } + private List GetContextMenus(string cmd) { return new List() @@ -165,34 +166,46 @@ namespace Wox.Plugin.SystemPlugins.CMD CMDStorage.Instance.AddCmdHistory(cmd); } - protected override void InitInternal(PluginInitContext context) + public void Init(PluginInitContext context) { this.context = context; + context.API.GlobalKeyboardEvent += API_GlobalKeyboardEvent; } - public override string ID + bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state) { - get { return "D409510CD0D2481F853690A07E6DC426"; } + if (CMDStorage.Instance.ReplaceWinR) + { + if (keyevent == (int)KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed) + { + WinRStroked = true; + OnWinRPressed(); + return false; + } + if (keyevent == (int)KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin) + { + WinRStroked = false; + keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL); + return false; + } + } + return true; } - public override string Name + private void OnWinRPressed() { - get { return "Shell"; } - } - - public override string IcoPath - { - get { return @"Images\cmd.png"; } - } - - public override string Description - { - get { return "Provide executing commands from Wox. Commands should start with >"; } + context.API.ShowApp(); + context.API.ChangeQuery(">"); } public Control CreateSettingPanel() { return new CMDSetting(); } + + public string GetLanguagesFolder() + { + return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); + } } } diff --git a/Wox.Plugin.SystemPlugins/CMD/CMDSetting.xaml b/Plugins/Wox.Plugin.CMD/CMDSetting.xaml similarity index 76% rename from Wox.Plugin.SystemPlugins/CMD/CMDSetting.xaml rename to Plugins/Wox.Plugin.CMD/CMDSetting.xaml index e7b5d5e2c0..88f6dd838c 100644 --- a/Wox.Plugin.SystemPlugins/CMD/CMDSetting.xaml +++ b/Plugins/Wox.Plugin.CMD/CMDSetting.xaml @@ -1,4 +1,4 @@ - - Replace Win+R + - - Do not close Command Prompt after command execution + + diff --git a/Plugins/Wox.Plugin.CMD/CMDSetting.xaml.cs b/Plugins/Wox.Plugin.CMD/CMDSetting.xaml.cs new file mode 100644 index 0000000000..6b93c30abe --- /dev/null +++ b/Plugins/Wox.Plugin.CMD/CMDSetting.xaml.cs @@ -0,0 +1,42 @@ +using System.Windows; +using System.Windows.Controls; + +namespace Wox.Plugin.CMD +{ + public partial class CMDSetting : UserControl + { + public CMDSetting() + { + InitializeComponent(); + } + + private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re) + { + cbReplaceWinR.IsChecked = CMDStorage.Instance.ReplaceWinR; + cbLeaveCmdOpen.IsChecked = CMDStorage.Instance.LeaveCmdOpen; + + cbLeaveCmdOpen.Checked += (o, e) => + { + CMDStorage.Instance.LeaveCmdOpen = true; + CMDStorage.Instance.Save(); + }; + + cbLeaveCmdOpen.Unchecked += (o, e) => + { + CMDStorage.Instance.LeaveCmdOpen = false; + CMDStorage.Instance.Save(); + }; + + cbReplaceWinR.Checked += (o, e) => + { + CMDStorage.Instance.ReplaceWinR = true; + CMDStorage.Instance.Save(); + }; + cbReplaceWinR.Unchecked += (o, e) => + { + CMDStorage.Instance.ReplaceWinR = false; + CMDStorage.Instance.Save(); + }; + } + } +} diff --git a/Wox.Plugin.SystemPlugins/CMD/CMDStorage.cs b/Plugins/Wox.Plugin.CMD/CMDStorage.cs similarity index 54% rename from Wox.Plugin.SystemPlugins/CMD/CMDStorage.cs rename to Plugins/Wox.Plugin.CMD/CMDStorage.cs index 3695ead3c7..1d719d17cd 100644 --- a/Wox.Plugin.SystemPlugins/CMD/CMDStorage.cs +++ b/Plugins/Wox.Plugin.CMD/CMDStorage.cs @@ -1,22 +1,38 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; +using System.Reflection; using Newtonsoft.Json; using Wox.Infrastructure.Storage; +using System.IO; -namespace Wox.Plugin.SystemPlugins.CMD +namespace Wox.Plugin.CMD { public class CMDStorage : JsonStrorage { + [JsonProperty] + public bool ReplaceWinR { get; set; } + + [JsonProperty] + public bool LeaveCmdOpen { get; set; } + [JsonProperty] public Dictionary CMDHistory = new Dictionary(); + protected override string ConfigFolder + { + get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } + } + protected override string ConfigName { get { return "CMDHistory"; } } + protected override CMDStorage LoadDefault() + { + ReplaceWinR = true; + return this; + } + public void AddCmdHistory(string cmdName) { if (CMDHistory.ContainsKey(cmdName)) diff --git a/Wox/Images/cmd.png b/Plugins/Wox.Plugin.CMD/Images/cmd.png similarity index 100% rename from Wox/Images/cmd.png rename to Plugins/Wox.Plugin.CMD/Images/cmd.png diff --git a/Plugins/Wox.Plugin.CMD/Languages/en.xaml b/Plugins/Wox.Plugin.CMD/Languages/en.xaml new file mode 100644 index 0000000000..309a4867db --- /dev/null +++ b/Plugins/Wox.Plugin.CMD/Languages/en.xaml @@ -0,0 +1,8 @@ + + + Replace Win+R + Do not close Command Prompt after command execution + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.CMD/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.CMD/Languages/zh-cn.xaml new file mode 100644 index 0000000000..0847dda6ce --- /dev/null +++ b/Plugins/Wox.Plugin.CMD/Languages/zh-cn.xaml @@ -0,0 +1,8 @@ + + + 替换 Win+R + 执行后不关闭命令窗口 + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.CMD/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.CMD/Languages/zh-tw.xaml new file mode 100644 index 0000000000..8ac28c3639 --- /dev/null +++ b/Plugins/Wox.Plugin.CMD/Languages/zh-tw.xaml @@ -0,0 +1,8 @@ + + + 替換 Win+R + 執行後不關閉命令窗口 + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.CMD/Properties/AssemblyInfo.cs b/Plugins/Wox.Plugin.CMD/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..fac890b6dd --- /dev/null +++ b/Plugins/Wox.Plugin.CMD/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Wox.Plugin.CMD")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Wox.Plugin.CMD")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("9283a32d-5d3c-4231-96e0-2150ed4716b9")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wox.UAC/Wox.UAC.csproj b/Plugins/Wox.Plugin.CMD/Wox.Plugin.CMD.csproj similarity index 56% rename from Wox.UAC/Wox.UAC.csproj rename to Plugins/Wox.Plugin.CMD/Wox.Plugin.CMD.csproj index a69735aec0..81bea53e1f 100644 --- a/Wox.UAC/Wox.UAC.csproj +++ b/Plugins/Wox.Plugin.CMD/Wox.Plugin.CMD.csproj @@ -4,128 +4,108 @@ Debug AnyCPU - {C9BC17A0-C2BC-4185-AC1F-32E3352C1233} - WinExe + {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} + Library Properties - Wox.UAC - Wox.UAC + Wox.Plugin.CMD + Wox.Plugin.CMD v3.5 512 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 - ..\ + ..\..\ true + - AnyCPU true full false - ..\Output\Debug\ + ..\..\Output\Debug\Plugins\Wox.Plugin.CMD\ DEBUG;TRACE prompt 4 + false - AnyCPU pdbonly true - ..\Output\Release\ + ..\..\Output\Release\Plugins\Wox.Plugin.CMD\ TRACE prompt 4 - - - app.ico - - - app.manifest + false - - False - ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll - - - ..\packages\log4net.2.0.3\lib\net35-full\log4net.dll - - ..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll + ..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll + True - - - - - - - - + + + + + + + + + + + False + ..\..\packages\WindowsInput.0.2.0.0\lib\net20\WindowsInput.dll + - - MSBuild:Compile - Designer - - + + + CMDSetting.xaml + + + + + + MSBuild:Compile Designer - - App.xaml - Code - - - MainWindow.xaml - Code - - - - - - Code - - - True - True - Resources.resx - - - True - Settings.settings - True - - - ResXFileCodeGenerator - Resources.Designer.cs - - - - - SettingsSingleFileGenerator - Settings.Designer.cs + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest - - + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} Wox.Infrastructure - + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} Wox.Plugin - + + + PreserveNewest + + + + + PreserveNewest + - - - - diff --git a/Plugins/Wox.Plugin.CMD/packages.config b/Plugins/Wox.Plugin.CMD/packages.config new file mode 100644 index 0000000000..5e64150e77 --- /dev/null +++ b/Plugins/Wox.Plugin.CMD/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.CMD/plugin.json b/Plugins/Wox.Plugin.CMD/plugin.json new file mode 100644 index 0000000000..949a499983 --- /dev/null +++ b/Plugins/Wox.Plugin.CMD/plugin.json @@ -0,0 +1,12 @@ +{ + "ID":"D409510CD0D2481F853690A07E6DC426", + "ActionKeyword":"*", + "Name":"Shell", + "Description":"Provide executing commands from Wox. Commands should start with >", + "Author":"qianlifeng", + "Version":"1.0.0", + "Language":"csharp", + "Website":"http://www.getwox.com/plugin", + "ExecuteFileName":"Wox.Plugin.CMD.dll", + "IcoPath":"Images\\cmd.png" +} diff --git a/Wox.Plugin.SystemPlugins/Calculator.cs b/Plugins/Wox.Plugin.Caculator/Calculator.cs similarity index 76% rename from Wox.Plugin.SystemPlugins/Calculator.cs rename to Plugins/Wox.Plugin.Caculator/Calculator.cs index 67602cc47b..55ddbc8a67 100644 --- a/Wox.Plugin.SystemPlugins/Calculator.cs +++ b/Plugins/Wox.Plugin.Caculator/Calculator.cs @@ -1,16 +1,11 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; +using System.Collections.Generic; using System.Text.RegularExpressions; -using System.Windows.Forms; +using System.Windows; using YAMP; -namespace Wox.Plugin.SystemPlugins +namespace Wox.Plugin.Caculator { - public class Calculator : BaseSystemPlugin + public class Calculator : IPlugin { private static Regex regValidExpressChar = new Regex( @"^(" + @@ -31,7 +26,7 @@ namespace Wox.Plugin.SystemPlugins Parser.UseScripting = false; } - protected override List QueryInternal(Query query) + public List Query(Query query) { if (query.RawQuery.Length <= 2 // don't affect when user only input "e" or "i" keyword || !regValidExpressChar.IsMatch(query.RawQuery) @@ -88,32 +83,9 @@ namespace Wox.Plugin.SystemPlugins return leftBracketCount == 0; } - protected override void InitInternal(PluginInitContext context) + public void Init(PluginInitContext context) { this.context = context; } - - public override string ID - { - get { return "CEA0FDFC6D3B4085823D60DC76F28855"; } - } - - public override string Name - { - get { return "Calculator"; } - } - - public override string IcoPath - { - get { return @"Images\calculator.png"; } - } - - public override string Description - { - get - { - return "Provide mathematical calculations.(Try 5*3-2 in Wox)"; - } - } } } diff --git a/Wox/Images/calculator.png b/Plugins/Wox.Plugin.Caculator/Images/calculator.png similarity index 100% rename from Wox/Images/calculator.png rename to Plugins/Wox.Plugin.Caculator/Images/calculator.png diff --git a/Plugins/Wox.Plugin.Caculator/Properties/AssemblyInfo.cs b/Plugins/Wox.Plugin.Caculator/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..a4ddfc5313 --- /dev/null +++ b/Plugins/Wox.Plugin.Caculator/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Wox.Plugin.Caculator")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Wox.Plugin.Caculator")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("ba698b90-59ed-4c2e-bce1-497eb2f9e76f")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Plugins/Wox.Plugin.Caculator/Wox.Plugin.Caculator.csproj b/Plugins/Wox.Plugin.Caculator/Wox.Plugin.Caculator.csproj new file mode 100644 index 0000000000..88dd34d162 --- /dev/null +++ b/Plugins/Wox.Plugin.Caculator/Wox.Plugin.Caculator.csproj @@ -0,0 +1,91 @@ + + + + + Debug + AnyCPU + {59BD9891-3837-438A-958D-ADC7F91F6F7E} + Library + Properties + Wox.Plugin.Caculator + Wox.Plugin.Caculator + v3.5 + 512 + ..\..\ + true + + + + true + full + false + ..\..\Output\Debug\Plugins\Wox.Plugin.Caculator\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + ..\..\Output\Release\Plugins\Wox.Plugin.Caculator\ + TRACE + prompt + 4 + false + + + + + + + + + + + + False + ..\..\packages\YAMP.1.4.0\lib\net35\YAMP.dll + + + + + + + + + + PreserveNewest + + + + + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} + Wox.Infrastructure + + + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + Wox.Plugin + + + + + PreserveNewest + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Caculator/packages.config b/Plugins/Wox.Plugin.Caculator/packages.config new file mode 100644 index 0000000000..4e151aa36f --- /dev/null +++ b/Plugins/Wox.Plugin.Caculator/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Caculator/plugin.json b/Plugins/Wox.Plugin.Caculator/plugin.json new file mode 100644 index 0000000000..f0371803f2 --- /dev/null +++ b/Plugins/Wox.Plugin.Caculator/plugin.json @@ -0,0 +1,12 @@ +{ + "ID":"CEA0FDFC6D3B4085823D60DC76F28855", + "ActionKeyword":"*", + "Name":"Calculator", + "Description":"Provide mathematical calculations.(Try 5*3-2 in Wox)", + "Author":"cxfksword", + "Version":"1.0.0", + "Language":"csharp", + "Website":"http://www.getwox.com/plugin", + "ExecuteFileName":"Wox.Plugin.Caculator.dll", + "IcoPath":"Images\\calculator.png" +} \ No newline at end of file diff --git a/Wox.Plugin.SystemPlugins/ColorsPlugin.cs b/Plugins/Wox.Plugin.Color/Color.cs similarity index 80% rename from Wox.Plugin.SystemPlugins/ColorsPlugin.cs rename to Plugins/Wox.Plugin.Color/Color.cs index d80f685db0..ab5a70cc19 100644 --- a/Wox.Plugin.SystemPlugins/ColorsPlugin.cs +++ b/Plugins/Wox.Plugin.Color/Color.cs @@ -6,9 +6,9 @@ using System.IO; using System.Linq; using System.Windows; -namespace Wox.Plugin.SystemPlugins +namespace Wox.Plugin.Color { - public sealed class ColorsPlugin : BaseSystemPlugin + public sealed class ColorsPlugin : IPlugin { private string DIR_PATH = Path.Combine(Path.GetTempPath(), @"Plugins\Colors\"); private const int IMG_SIZE = 32; @@ -27,7 +27,7 @@ namespace Wox.Plugin.SystemPlugins } } - protected override List QueryInternal(Query query) + public List Query(Query query) { var raw = query.RawQuery; if (!IsAvailable(raw)) return new List(0); @@ -101,30 +101,7 @@ namespace Wox.Plugin.SystemPlugins return string.Format("{0}{1}.png", ColorsDirectory.FullName, name.Substring(1)); } - public override string ID - { - get { return "9B36CE6181FC47FBB597AA2C29CD9B0A"; } - } - - public override string Name - { - get { return "Colors"; } - } - - public override string Description - { - get - { - return "Provide hex color preview.(Try #000 in Wox)"; - } - } - - public override string IcoPath - { - get { return "Images/color2.png"; } - } - - protected override void InitInternal(PluginInitContext context) + public void Init(PluginInitContext context) { } } diff --git a/Wox/Images/color2.png b/Plugins/Wox.Plugin.Color/Images/color.png similarity index 100% rename from Wox/Images/color2.png rename to Plugins/Wox.Plugin.Color/Images/color.png diff --git a/Plugins/Wox.Plugin.Color/Properties/AssemblyInfo.cs b/Plugins/Wox.Plugin.Color/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..7578ccd763 --- /dev/null +++ b/Plugins/Wox.Plugin.Color/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Wox.Plugin.Color")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Wox.Plugin.Color")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("46b03f84-5bf7-4ed4-a69b-f0274c8b3776")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Plugins/Wox.Plugin.Color/Wox.Plugin.Color.csproj b/Plugins/Wox.Plugin.Color/Wox.Plugin.Color.csproj new file mode 100644 index 0000000000..81347e2f19 --- /dev/null +++ b/Plugins/Wox.Plugin.Color/Wox.Plugin.Color.csproj @@ -0,0 +1,73 @@ + + + + + Debug + AnyCPU + {F35190AA-4758-4D9E-A193-E3BDF6AD3567} + Library + Properties + Wox.Plugin.Color + Wox.Plugin.Color + v3.5 + 512 + + + + true + full + false + ..\..\Output\Debug\Plugins\Wox.Plugin.Color\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + ..\..\Output\Release\Plugins\Wox.Plugin.Color\ + TRACE + prompt + 4 + false + + + + + + + + + + + + + + + + + + PreserveNewest + + + + + PreserveNewest + + + + + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + Wox.Plugin + + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Color/plugin.json b/Plugins/Wox.Plugin.Color/plugin.json new file mode 100644 index 0000000000..16eddbb6d7 --- /dev/null +++ b/Plugins/Wox.Plugin.Color/plugin.json @@ -0,0 +1,12 @@ +{ + "ID":"9B36CE6181FC47FBB597AA2C29CD9B0A", + "ActionKeyword":"*", + "Name":"Colors", + "Description":"Provide hex color preview.(Try #000 in Wox)", + "Author":"qianlifeng", + "Version":"1.0.0", + "Language":"csharp", + "Website":"http://www.getwox.com/plugin", + "ExecuteFileName":"Wox.Plugin.Color.dll", + "IcoPath":"Images\\color.png" +} diff --git a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanel.cs b/Plugins/Wox.Plugin.ControlPanel/ControlPanel.cs similarity index 75% rename from Wox.Plugin.SystemPlugins/ControlPanel/ControlPanel.cs rename to Plugins/Wox.Plugin.ControlPanel/ControlPanel.cs index 48c11882d7..e3f5918a4a 100644 --- a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanel.cs +++ b/Plugins/Wox.Plugin.ControlPanel/ControlPanel.cs @@ -5,42 +5,20 @@ using System.IO; using System.Linq; using Wox.Infrastructure; -namespace Wox.Plugin.SystemPlugins.ControlPanel +namespace Wox.Plugin.ControlPanel { - public class ControlPanel : BaseSystemPlugin + public class ControlPanel : IPlugin { - #region Properties - private PluginInitContext context; - - public override string Description - { - get - { - return "Search within the Control Panel."; - } - } - - public override string ID - { - get { return "209621585B9B4D81813913C507C058C6"; } - } - - public override string Name { get { return "Control Panel"; } } - - public override string IcoPath { get { return @"Images\ControlPanel.png"; } } - private List controlPanelItems = new List(); private string iconFolder; private string fileType; - #endregion Properties - - protected override void InitInternal(PluginInitContext context) + public void Init(PluginInitContext context) { this.context = context; controlPanelItems = ControlPanelList.Create(48); - iconFolder = @"Images\ControlPanelIcons\"; + iconFolder = Path.Combine(context.CurrentPluginMetadata.PluginDirectory, @"Images\ControlPanelIcons\"); fileType = ".bmp"; if (!Directory.Exists(iconFolder)) @@ -58,7 +36,7 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel } } - protected override List QueryInternal(Query query) + public List Query(Query query) { if (query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List(); string myQuery = query.RawQuery.Trim(); @@ -75,7 +53,7 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel Title = item.LocalizedString, SubTitle = item.InfoTip, Score = item.Score, - IcoPath = "Images\\ControlPanelIcons\\" + item.GUID + fileType, + IcoPath = Path.Combine(context.CurrentPluginMetadata.PluginDirectory, @"Images\\ControlPanelIcons\\" + item.GUID + fileType), Action = e => { try diff --git a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs b/Plugins/Wox.Plugin.ControlPanel/ControlPanelItem.cs similarity index 94% rename from Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs rename to Plugins/Wox.Plugin.ControlPanel/ControlPanelItem.cs index 6d76e269a0..a63c9a19c6 100644 --- a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs +++ b/Plugins/Wox.Plugin.ControlPanel/ControlPanelItem.cs @@ -1,7 +1,7 @@ using System.Diagnostics; using System.Drawing; -namespace Wox.Plugin.SystemPlugins.ControlPanel +namespace Wox.Plugin.ControlPanel { //from:https://raw.githubusercontent.com/CoenraadS/Windows-Control-Panel-Items public class ControlPanelItem @@ -22,4 +22,4 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel GUID = newGUID; } } -} +} \ No newline at end of file diff --git a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs b/Plugins/Wox.Plugin.ControlPanel/ControlPanelList.cs similarity index 99% rename from Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs rename to Plugins/Wox.Plugin.ControlPanel/ControlPanelList.cs index 9f3fbcfcbb..724688e4e1 100644 --- a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelList.cs +++ b/Plugins/Wox.Plugin.ControlPanel/ControlPanelList.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; -using System.Text; -using Microsoft.Win32; -using System.Runtime.InteropServices; using System.Diagnostics; using System.Drawing; +using System.Runtime.InteropServices; +using System.Text; +using Microsoft.Win32; -namespace Wox.Plugin.SystemPlugins.ControlPanel +namespace Wox.Plugin.ControlPanel { //from:https://raw.githubusercontent.com/CoenraadS/Windows-Control-Panel-Items public static class ControlPanelList diff --git a/Wox/Images/ControlPanel.png b/Plugins/Wox.Plugin.ControlPanel/Images/ControlPanel.png similarity index 100% rename from Wox/Images/ControlPanel.png rename to Plugins/Wox.Plugin.ControlPanel/Images/ControlPanel.png diff --git a/Plugins/Wox.Plugin.ControlPanel/Properties/AssemblyInfo.cs b/Plugins/Wox.Plugin.ControlPanel/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..dbbad24f59 --- /dev/null +++ b/Plugins/Wox.Plugin.ControlPanel/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Wox.Plugin.ControlPanel")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Wox.Plugin.ControlPanel")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("59141b10-8941-4e90-a0a6-bc9385a04cc6")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Plugins/Wox.Plugin.ControlPanel/Wox.Plugin.ControlPanel.csproj b/Plugins/Wox.Plugin.ControlPanel/Wox.Plugin.ControlPanel.csproj new file mode 100644 index 0000000000..8735e23d6d --- /dev/null +++ b/Plugins/Wox.Plugin.ControlPanel/Wox.Plugin.ControlPanel.csproj @@ -0,0 +1,78 @@ + + + + + Debug + AnyCPU + {1EE20B48-82FB-48A2-8086-675D6DDAB4F0} + Library + Properties + Wox.Plugin.ControlPanel + Wox.Plugin.ControlPanel + v3.5 + 512 + + + + true + full + false + ..\..\Output\Debug\Plugins\Wox.Plugin.ControlPanel\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + ..\..\Output\Release\Plugins\Wox.Plugin.ControlPanel\ + TRACE + prompt + 4 + false + + + + + + + + + + + + + + + + + + + PreserveNewest + + + + + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} + Wox.Infrastructure + + + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + Wox.Plugin + + + + + PreserveNewest + + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.ControlPanel/plugin.json b/Plugins/Wox.Plugin.ControlPanel/plugin.json new file mode 100644 index 0000000000..d0724a6ec2 --- /dev/null +++ b/Plugins/Wox.Plugin.ControlPanel/plugin.json @@ -0,0 +1,12 @@ +{ + "ID":"209621585B9B4D81813913C507C058C6", + "ActionKeyword":"*", + "Name":"Control Panel", + "Description":"Search within the Control Panel.", + "Author":"CoenraadS", + "Version":"1.0.0", + "Language":"csharp", + "Website":"http://www.getwox.com/plugin", + "ExecuteFileName":"Wox.Plugin.ControlPanel.dll", + "IcoPath":"Images\\ControlPanel.png" +} diff --git a/Wox.Infrastructure/Storage/UserSettings/FolderLink.cs b/Plugins/Wox.Plugin.Folder/FolderLink.cs similarity index 77% rename from Wox.Infrastructure/Storage/UserSettings/FolderLink.cs rename to Plugins/Wox.Plugin.Folder/FolderLink.cs index 69bb68b871..4f7fb440c4 100644 --- a/Wox.Infrastructure/Storage/UserSettings/FolderLink.cs +++ b/Plugins/Wox.Plugin.Folder/FolderLink.cs @@ -1,11 +1,10 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using Newtonsoft.Json; -namespace Wox.Infrastructure.Storage.UserSettings +namespace Wox.Plugin.Folder { + [Serializable] public class FolderLink { [JsonProperty] diff --git a/Wox.Plugin.SystemPlugins/Folder/FolderPlugin.cs b/Plugins/Wox.Plugin.Folder/FolderPlugin.cs similarity index 81% rename from Wox.Plugin.SystemPlugins/Folder/FolderPlugin.cs rename to Plugins/Wox.Plugin.Folder/FolderPlugin.cs index 00f94f06a6..32b41578f5 100644 --- a/Wox.Plugin.SystemPlugins/Folder/FolderPlugin.cs +++ b/Plugins/Wox.Plugin.Folder/FolderPlugin.cs @@ -3,59 +3,35 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using System.Windows.Forms; -using Wox.Infrastructure.Storage.UserSettings; +using System.Reflection; +using System.Windows; using Control = System.Windows.Controls.Control; -namespace Wox.Plugin.SystemPlugins.Folder +namespace Wox.Plugin.Folder { - public class FolderPlugin : BaseSystemPlugin, ISettingProvider + public class FolderPlugin : IPlugin, ISettingProvider,IPluginI18n { - #region Properties - private static List driverNames; private PluginInitContext context; - public override string Description - { - get { return "Provide opening folder from wox directorily. You can add your favorite folders."; } - } - - public override string ID - { - get { return "B4D3B69656E14D44865C8D818EAE47C4"; } - } - - public override string Name - { - get { return "Folder"; } - } - - public override string IcoPath - { - get { return @"Images\folder.png"; } - } - - #endregion Properties - public Control CreateSettingPanel() { - return new FileSystemSettings(); + return new FileSystemSettings(context); } - protected override void InitInternal(PluginInitContext context) + public void Init(PluginInitContext context) { this.context = context; this.context.API.BackKeyDownEvent += ApiBackKeyDownEvent; InitialDriverList(); - if (UserSettingStorage.Instance.FolderLinks == null) + if (FolderStorage.Instance.FolderLinks == null) { - UserSettingStorage.Instance.FolderLinks = new List(); - UserSettingStorage.Instance.Save(); + FolderStorage.Instance.FolderLinks = new List(); + FolderStorage.Instance.Save(); } } - private void ApiBackKeyDownEvent(object sender, WoxKeyDownEventArgs e) + private void ApiBackKeyDownEvent(WoxKeyDownEventArgs e) { string query = e.Query; if (Directory.Exists(query)) @@ -75,11 +51,12 @@ namespace Wox.Plugin.SystemPlugins.Folder } } - protected override List QueryInternal(Query query) + public List Query(Query query) { + if(string.IsNullOrEmpty(query.RawQuery)) return new List(); string input = query.RawQuery.ToLower(); - List userFolderLinks = UserSettingStorage.Instance.FolderLinks.Where( + List userFolderLinks = FolderStorage.Instance.FolderLinks.Where( x => x.Nickname.StartsWith(input, StringComparison.OrdinalIgnoreCase)).ToList(); List results = userFolderLinks.Select( @@ -105,7 +82,7 @@ namespace Wox.Plugin.SystemPlugins.Folder } }).ToList(); - if (!driverNames.Any(input.StartsWith)) + if (driverNames != null && !driverNames.Any(input.StartsWith)) return results; if (!input.EndsWith("\\")) @@ -207,5 +184,10 @@ namespace Wox.Plugin.SystemPlugins.Folder return results; } + + public string GetLanguagesFolder() + { + return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); + } } } \ No newline at end of file diff --git a/Wox.Plugin.SystemPlugins/Folder/FolderPluginSettings.xaml b/Plugins/Wox.Plugin.Folder/FolderPluginSettings.xaml similarity index 54% rename from Wox.Plugin.SystemPlugins/Folder/FolderPluginSettings.xaml rename to Plugins/Wox.Plugin.Folder/FolderPluginSettings.xaml index 59e57e906b..93b9178e01 100644 --- a/Wox.Plugin.SystemPlugins/Folder/FolderPluginSettings.xaml +++ b/Plugins/Wox.Plugin.Folder/FolderPluginSettings.xaml @@ -1,19 +1,21 @@ - + d:DesignHeight="300" d:DesignWidth="500"> - - + + - + @@ -24,9 +26,9 @@ - - + + - + - + - + @@ -36,12 +34,12 @@ - Indexing + - + diff --git a/Plugins/Wox.Plugin.Program/ProgramSuffixes.xaml.cs b/Plugins/Wox.Plugin.Program/ProgramSuffixes.xaml.cs new file mode 100644 index 0000000000..735c28bed5 --- /dev/null +++ b/Plugins/Wox.Plugin.Program/ProgramSuffixes.xaml.cs @@ -0,0 +1,34 @@ +using System.Windows; + +namespace Wox.Plugin.Program +{ + /// + /// ProgramSuffixes.xaml 的交互逻辑 + /// + public partial class ProgramSuffixes + { + private PluginInitContext context; + + public ProgramSuffixes(PluginInitContext context) + { + this.context = context; + InitializeComponent(); + + tbSuffixes.Text = ProgramStorage.Instance.ProgramSuffixes; + } + + private void ButtonBase_OnClick(object sender, RoutedEventArgs e) + { + if (string.IsNullOrEmpty(tbSuffixes.Text)) + { + string warning = context.API.GetTranslation("wox_plugin_program_suffixes_cannot_empty"); + MessageBox.Show(warning); + return; + } + + ProgramStorage.Instance.ProgramSuffixes = tbSuffixes.Text; + string msg = context.API.GetTranslation("wox_plugin_program_update_file_suffixes"); + MessageBox.Show(msg); + } + } +} diff --git a/Wox.Plugin.SystemPlugins/Program/Programs.cs b/Plugins/Wox.Plugin.Program/Programs.cs similarity index 82% rename from Wox.Plugin.SystemPlugins/Program/Programs.cs rename to Plugins/Wox.Plugin.Program/Programs.cs index f49bfcd38e..9c4d2d423d 100644 --- a/Wox.Plugin.SystemPlugins/Program/Programs.cs +++ b/Plugins/Wox.Plugin.Program/Programs.cs @@ -1,18 +1,17 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; -using System.Runtime.Serialization.Formatters.Binary; -using System.Windows.Forms; +using System.Threading; +using System.Windows; using Wox.Infrastructure; -using Wox.Infrastructure.Storage.UserSettings; -using Wox.Plugin.SystemPlugins.Program.ProgramSources; +using Wox.Plugin.Program.ProgramSources; -namespace Wox.Plugin.SystemPlugins.Program +namespace Wox.Plugin.Program { - public class Programs : BaseSystemPlugin, ISettingProvider + public class Programs : ISettingProvider, IPlugin, IPluginI18n { private static object lockObject = new object(); private static List programs = new List(); @@ -25,7 +24,7 @@ namespace Wox.Plugin.SystemPlugins.Program }; private PluginInitContext context; - protected override List QueryInternal(Query query) + public List Query(Query query) { if (query.RawQuery.Trim().Length <= 1) return new List(); @@ -73,10 +72,14 @@ namespace Wox.Plugin.SystemPlugins.Program return false; } - protected override void InitInternal(PluginInitContext context) + public void Init(PluginInitContext context) { this.context = context; - programs = ProgramCacheStorage.Instance.Programs; + using (new Timeit("Preload programs")) + { + programs = ProgramCacheStorage.Instance.Programs; + } + Debug.WriteLine(string.Format("Preload {0} programs from cache", programs.Count), "Wox"); using (new Timeit("Program Index")) { IndexPrograms(); @@ -89,10 +92,10 @@ namespace Wox.Plugin.SystemPlugins.Program { List programSources = new List(); programSources.AddRange(LoadDeaultProgramSources()); - if (UserSettingStorage.Instance.ProgramSources != null && - UserSettingStorage.Instance.ProgramSources.Count(o => o.Enabled) > 0) + if (ProgramStorage.Instance.ProgramSources != null && + ProgramStorage.Instance.ProgramSources.Count(o => o.Enabled) > 0) { - programSources.AddRange(UserSettingStorage.Instance.ProgramSources.Where(o => o.Enabled)); + programSources.AddRange(ProgramStorage.Instance.ProgramSources.Where(o => o.Enabled)); } sources.Clear(); @@ -172,33 +175,18 @@ namespace Wox.Plugin.SystemPlugins.Program p.Score -= 20; } - public override string ID - { - get { return "791FC278BA414111B8D1886DFE447410"; } - } - - public override string Name - { - get { return "Programs"; } - } - - public override string IcoPath - { - get { return @"Images\program.png"; } - } - - public override string Description - { - get { return "Provide searching programs in your computer."; } - } - #region ISettingProvider Members public System.Windows.Controls.Control CreateSettingPanel() { - return new ProgramSetting(); + return new ProgramSetting(context); } #endregion + + public string GetLanguagesFolder() + { + return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); + } } } diff --git a/Plugins/Wox.Plugin.Program/Properties/AssemblyInfo.cs b/Plugins/Wox.Plugin.Program/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..c2465d39d9 --- /dev/null +++ b/Plugins/Wox.Plugin.Program/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Wox.Plugin.Program")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Wox.Plugin.Program")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("82f60d9a-9280-4b6a-8b21-f3c694cb7e1d")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wox.Infrastructure/StringEmptyConverter.cs b/Plugins/Wox.Plugin.Program/StringEmptyConverter.cs similarity index 87% rename from Wox.Infrastructure/StringEmptyConverter.cs rename to Plugins/Wox.Plugin.Program/StringEmptyConverter.cs index f553695737..eb2e4b9c18 100644 --- a/Wox.Infrastructure/StringEmptyConverter.cs +++ b/Plugins/Wox.Plugin.Program/StringEmptyConverter.cs @@ -1,11 +1,8 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Windows.Data; using System.Windows.Markup; -namespace Wox.Infrastructure +namespace Wox.Plugin.Program { public class StringEmptyConverter : MarkupExtension, IValueConverter { diff --git a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj new file mode 100644 index 0000000000..324b0fb103 --- /dev/null +++ b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj @@ -0,0 +1,140 @@ + + + + + Debug + AnyCPU + {FDB3555B-58EF-4AE6-B5F1-904719637AB4} + Library + Properties + Wox.Plugin.Program + Wox.Plugin.Program + v3.5 + 512 + ..\..\ + true + + + + true + full + false + ..\..\Output\Debug\Plugins\Wox.Plugin.Program\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + ..\..\Output\Release\Plugins\Wox.Plugin.Program\ + TRACE + prompt + 4 + false + + + + False + ..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + ProgramSetting.xaml + + + + + + + + + ProgramSuffixes.xaml + + + + + + + + PreserveNewest + + + + + PreserveNewest + + + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + + + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} + Wox.Infrastructure + + + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + Wox.Plugin + + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/packages.config b/Plugins/Wox.Plugin.Program/packages.config new file mode 100644 index 0000000000..7a13476a54 --- /dev/null +++ b/Plugins/Wox.Plugin.Program/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/plugin.json b/Plugins/Wox.Plugin.Program/plugin.json new file mode 100644 index 0000000000..9185aa7fe8 --- /dev/null +++ b/Plugins/Wox.Plugin.Program/plugin.json @@ -0,0 +1,12 @@ +{ + "ID":"791FC278BA414111B8D1886DFE447410", + "ActionKeyword":"*", + "Name":"Program", + "Description":"Provide programs search for Wox.", + "Author":"qianlifeng", + "Version":"1.0.0", + "Language":"csharp", + "Website":"http://www.getwox.com/plugin", + "ExecuteFileName":"Wox.Plugin.Program.dll", + "IcoPath":"Images\\program.png" +} diff --git a/Plugins/Wox.Plugin.QueryHistory/HistoryItem.cs b/Plugins/Wox.Plugin.QueryHistory/HistoryItem.cs new file mode 100644 index 0000000000..0921a95203 --- /dev/null +++ b/Plugins/Wox.Plugin.QueryHistory/HistoryItem.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Wox.Plugin.QueryHistory +{ + public class HistoryItem + { + public string Query { get; set; } + public DateTime ExecutedDateTime { get; set; } + + public string GetTimeAgo() + { + return DateTimeAgo(ExecutedDateTime); + } + + private string DateTimeAgo(DateTime dt) + { + TimeSpan span = DateTime.Now - dt; + if (span.Days > 365) + { + int years = (span.Days / 365); + if (span.Days % 365 != 0) + years += 1; + return String.Format("about {0} {1} ago", + years, years == 1 ? "year" : "years"); + } + if (span.Days > 30) + { + int months = (span.Days / 30); + if (span.Days % 31 != 0) + months += 1; + return String.Format("about {0} {1} ago", + months, months == 1 ? "month" : "months"); + } + if (span.Days > 0) + return String.Format("about {0} {1} ago", + span.Days, span.Days == 1 ? "day" : "days"); + if (span.Hours > 0) + return String.Format("about {0} {1} ago", + span.Hours, span.Hours == 1 ? "hour" : "hours"); + if (span.Minutes > 0) + return String.Format("about {0} {1} ago", + span.Minutes, span.Minutes == 1 ? "minute" : "minutes"); + if (span.Seconds > 5) + return String.Format("about {0} seconds ago", span.Seconds); + if (span.Seconds <= 5) + return "just now"; + return string.Empty; + } + } +} diff --git a/Plugins/Wox.Plugin.QueryHistory/Images/history.png b/Plugins/Wox.Plugin.QueryHistory/Images/history.png new file mode 100644 index 0000000000..6bb070398f Binary files /dev/null and b/Plugins/Wox.Plugin.QueryHistory/Images/history.png differ diff --git a/Plugins/Wox.Plugin.QueryHistory/Properties/AssemblyInfo.cs b/Plugins/Wox.Plugin.QueryHistory/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..dce06522b6 --- /dev/null +++ b/Plugins/Wox.Plugin.QueryHistory/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Wox.Plugin.QueryHistory")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Wox.Plugin.QueryHistory")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("25ab1bbc-f625-4bf5-a2d0-73313abdaae5")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Plugins/Wox.Plugin.QueryHistory/QueryHistory.cs b/Plugins/Wox.Plugin.QueryHistory/QueryHistory.cs new file mode 100644 index 0000000000..6a77964e18 --- /dev/null +++ b/Plugins/Wox.Plugin.QueryHistory/QueryHistory.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; + +namespace Wox.Plugin.QueryHistory +{ + public class QueryHistory : IPlugin + { + private PluginInitContext context; + + public List Query(Query query) + { + var histories = QueryHistoryStorage.Instance.GetHistory(); + string filter = query.GetAllRemainingParameter(); + if (!string.IsNullOrEmpty(filter)) + { + histories = histories.Where(o => o.Query.Contains(filter)).ToList(); + } + return histories.Select(history => new Result() + { + Title = history.Query, + SubTitle = history.GetTimeAgo(), + IcoPath = "Images\\history.png", + Action = _ => + { + context.API.ChangeQuery(history.Query); + return false; + } + }).ToList(); + } + + public void Init(PluginInitContext context) + { + this.context = context; + context.API.AfterWoxQueryEvent += API_AfterWoxQueryEvent; + context.API.BeforeWoxQueryEvent += API_BeforeWoxQueryEvent; + } + + void API_BeforeWoxQueryEvent(WoxQueryEventArgs e) + { + Thread.Sleep(5000); + } + + private void API_AfterWoxQueryEvent(WoxQueryEventArgs e) + { + QueryHistoryStorage.Instance.Add(e.Query.RawQuery); + } + } +} diff --git a/Plugins/Wox.Plugin.QueryHistory/QueryHistoryStorage.cs b/Plugins/Wox.Plugin.QueryHistory/QueryHistoryStorage.cs new file mode 100644 index 0000000000..3d10f4a491 --- /dev/null +++ b/Plugins/Wox.Plugin.QueryHistory/QueryHistoryStorage.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using Newtonsoft.Json; +using Wox.Core.Exception; +using Wox.Infrastructure.Storage; + +namespace Wox.Plugin.QueryHistory +{ + public class QueryHistoryStorage : JsonStrorage + { + [JsonProperty] + private List History = new List(); + + private int MaxHistory = 300; + private int cursor = 0; + + protected override string ConfigFolder + { + get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } + } + + protected override string ConfigName + { + get { return "QueryHistory"; } + } + + public HistoryItem Pop() + { + if (History.Count == 0) return null; + + if (cursor > History.Count - 1) + { + cursor = History.Count - 1; + } + if (cursor < 0) + { + cursor = 0; + } + + return History[cursor--]; + } + + public void Reset() + { + cursor = History.Count - 1; + } + + public void Add(string query) + { + if (string.IsNullOrEmpty(query)) return; + if (History.Count > MaxHistory) + { + History.RemoveAt(0); + } + + if (History.Count > 0 && History.Last().Query == query) + { + History.Last().ExecutedDateTime = DateTime.Now; + } + else + { + History.Add(new HistoryItem() + { + Query = query, + ExecutedDateTime = DateTime.Now + }); + } + + if (History.Count % 5 == 0) + { + Save(); + } + } + + public List GetHistory() + { + return History.OrderByDescending(o => o.ExecutedDateTime).ToList(); + } + } +} diff --git a/Plugins/Wox.Plugin.QueryHistory/Wox.Plugin.QueryHistory.csproj b/Plugins/Wox.Plugin.QueryHistory/Wox.Plugin.QueryHistory.csproj new file mode 100644 index 0000000000..9ae22def69 --- /dev/null +++ b/Plugins/Wox.Plugin.QueryHistory/Wox.Plugin.QueryHistory.csproj @@ -0,0 +1,92 @@ + + + + + Debug + AnyCPU + {B552DCB6-692E-4B1D-9E0B-9096A2A7E6B0} + Library + Properties + Wox.Plugin.QueryHistory + Wox.Plugin.QueryHistory + v3.5 + 512 + ..\..\ + true + + + true + full + false + ..\..\Output\Debug\Plugins\Wox.Plugin.QueryHistory\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\Output\Release\Plugins\Wox.Plugin.Program\ + TRACE + prompt + 4 + + + + False + ..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2} + Wox.Core + + + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} + Wox.Infrastructure + + + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + Wox.Plugin + + + + + + PreserveNewest + + + + + PreserveNewest + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.QueryHistory/packages.config b/Plugins/Wox.Plugin.QueryHistory/packages.config new file mode 100644 index 0000000000..7a13476a54 --- /dev/null +++ b/Plugins/Wox.Plugin.QueryHistory/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.QueryHistory/plugin.json b/Plugins/Wox.Plugin.QueryHistory/plugin.json new file mode 100644 index 0000000000..959874b682 --- /dev/null +++ b/Plugins/Wox.Plugin.QueryHistory/plugin.json @@ -0,0 +1,12 @@ +{ + "ID":"54F327C503414B9489CDD331EE9472EF", + "ActionKeyword":"history", + "Name":"Query History", + "Description":"Remember Wox query history", + "Author":"qianlifeng", + "Version":"1.0.0", + "Language":"csharp", + "Website":"http://www.getwox.com/plugin", + "ExecuteFileName":"Wox.Plugin.QueryHistory.dll", + "IcoPath":"Images\\history.png" +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Sys/Images/app.png b/Plugins/Wox.Plugin.Sys/Images/app.png new file mode 100644 index 0000000000..8c9ca7971a Binary files /dev/null and b/Plugins/Wox.Plugin.Sys/Images/app.png differ diff --git a/Wox/Images/close.png b/Plugins/Wox.Plugin.Sys/Images/close.png similarity index 100% rename from Wox/Images/close.png rename to Plugins/Wox.Plugin.Sys/Images/close.png diff --git a/Wox/Images/exit.png b/Plugins/Wox.Plugin.Sys/Images/exit.png similarity index 100% rename from Wox/Images/exit.png rename to Plugins/Wox.Plugin.Sys/Images/exit.png diff --git a/Wox/Images/lock.png b/Plugins/Wox.Plugin.Sys/Images/lock.png similarity index 100% rename from Wox/Images/lock.png rename to Plugins/Wox.Plugin.Sys/Images/lock.png diff --git a/Wox/Images/logoff.png b/Plugins/Wox.Plugin.Sys/Images/logoff.png similarity index 100% rename from Wox/Images/logoff.png rename to Plugins/Wox.Plugin.Sys/Images/logoff.png diff --git a/Wox/Images/restart.png b/Plugins/Wox.Plugin.Sys/Images/restart.png similarity index 100% rename from Wox/Images/restart.png rename to Plugins/Wox.Plugin.Sys/Images/restart.png diff --git a/Plugins/Wox.Plugin.Sys/Languages/en.xaml b/Plugins/Wox.Plugin.Sys/Languages/en.xaml new file mode 100644 index 0000000000..280d5ff506 --- /dev/null +++ b/Plugins/Wox.Plugin.Sys/Languages/en.xaml @@ -0,0 +1,15 @@ + + + Command + Description + + Shutdown Computer + Log off + Lock this computer + Close Wox + Restart Wox + Tweak this app + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Sys/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.Sys/Languages/zh-cn.xaml new file mode 100644 index 0000000000..5abec64ce5 --- /dev/null +++ b/Plugins/Wox.Plugin.Sys/Languages/zh-cn.xaml @@ -0,0 +1,15 @@ + + + 命令 + 描述 + + 关闭电脑 + 注销 + 锁定这台电脑 + 退出Wox + 重启Wox + 设置 + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Sys/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.Sys/Languages/zh-tw.xaml new file mode 100644 index 0000000000..e393f0d8bd --- /dev/null +++ b/Plugins/Wox.Plugin.Sys/Languages/zh-tw.xaml @@ -0,0 +1,15 @@ + + + 命令 + 描述 + + 關閉電腦 + 註銷 + 鎖定這臺電腦 + 退出Wox + 重啟Wox + 設置 + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Sys/Properties/AssemblyInfo.cs b/Plugins/Wox.Plugin.Sys/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..c0e3221b08 --- /dev/null +++ b/Plugins/Wox.Plugin.Sys/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Wox.Plugin.Sys")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Wox.Plugin.Sys")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("e1eecff6-3f25-424d-9bbd-cbd7d6e1e11e")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wox.Plugin.SystemPlugins/Sys/Sys.cs b/Plugins/Wox.Plugin.Sys/Sys.cs similarity index 72% rename from Wox.Plugin.SystemPlugins/Sys/Sys.cs rename to Plugins/Wox.Plugin.Sys/Sys.cs index 50a2a6e859..2351f55735 100644 --- a/Wox.Plugin.SystemPlugins/Sys/Sys.cs +++ b/Plugins/Wox.Plugin.Sys/Sys.cs @@ -1,16 +1,16 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics; -using System.Linq; +using System.IO; +using System.Reflection; using System.Runtime.InteropServices; -using System.Text; using System.Windows.Forms; -namespace Wox.Plugin.SystemPlugins.Sys +namespace Wox.Plugin.Sys { - public class Sys : BaseSystemPlugin, ISettingProvider + public class Sys : IPlugin, ISettingProvider ,IPluginI18n { List availableResults = new List(); + private PluginInitContext context; #region DllImport @@ -27,41 +27,20 @@ namespace Wox.Plugin.SystemPlugins.Sys #endregion - #region Overrides - - public override string ID - { - get { return "CEA08895D2544B019B2E9C5009600DF4"; } - } - - public override string Name - { - get { return "System Commands"; } - } - - public override string IcoPath - { - get { return @"Images\lock.png"; } - } - - public override string Description - { - get { return "Provide System related commands. e.g. shutdown,lock,setting etc."; } - } - - #endregion - public System.Windows.Controls.Control CreateSettingPanel() { return new SysSettings(availableResults); } - protected override List QueryInternal(Query query) + public List Query(Query query) { if (query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List(); + if (availableResults.Count == 0) + { + LoadCommands(); + } List results = new List(); - foreach (Result availableResult in availableResults) { if (availableResult.Title.ToLower().StartsWith(query.RawQuery.ToLower())) @@ -72,13 +51,18 @@ namespace Wox.Plugin.SystemPlugins.Sys return results; } - protected override void InitInternal(PluginInitContext context) + public void Init(PluginInitContext context) { - availableResults.AddRange(new Result[] { + this.context = context; + } + + private void LoadCommands() + { + availableResults.AddRange(new Result[] { new Result { Title = "Shutdown", - SubTitle = "Shutdown Computer", + SubTitle = context.API.GetTranslation("wox_plugin_sys_shutdown_computer"), Score = 100, IcoPath = "Images\\exit.png", Action = (c) => @@ -92,7 +76,7 @@ namespace Wox.Plugin.SystemPlugins.Sys new Result { Title = "Log off", - SubTitle = "Log off current user", + SubTitle = context.API.GetTranslation("wox_plugin_sys_log_off"), Score = 100, IcoPath = "Images\\logoff.png", Action = (c) => ExitWindowsEx(EWX_LOGOFF, 0) @@ -100,7 +84,7 @@ namespace Wox.Plugin.SystemPlugins.Sys new Result { Title = "Lock", - SubTitle = "Lock this computer", + SubTitle = context.API.GetTranslation("wox_plugin_sys_lock"), Score = 100, IcoPath = "Images\\lock.png", Action = (c) => @@ -112,7 +96,7 @@ namespace Wox.Plugin.SystemPlugins.Sys new Result { Title = "Exit", - SubTitle = "Close this app", + SubTitle = context.API.GetTranslation("wox_plugin_sys_exit"), Score = 110, IcoPath = "Images\\app.png", Action = (c) => @@ -124,7 +108,7 @@ namespace Wox.Plugin.SystemPlugins.Sys new Result { Title = "Restart Wox", - SubTitle = "Restart Wox", + SubTitle = context.API.GetTranslation("wox_plugin_sys_restart"), Score = 110, IcoPath = "Images\\restart.png", Action = (c) => @@ -142,7 +126,7 @@ namespace Wox.Plugin.SystemPlugins.Sys new Result { Title = "Settings", - SubTitle = "Tweak this app", + SubTitle = context.API.GetTranslation("wox_plugin_sys_setting"), Score = 100, IcoPath = "Images\\app.png", Action = (c) => @@ -154,7 +138,10 @@ namespace Wox.Plugin.SystemPlugins.Sys }); } + public string GetLanguagesFolder() + { + return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); - + } } } diff --git a/Wox.Plugin.SystemPlugins/Sys/SysSettings.xaml b/Plugins/Wox.Plugin.Sys/SysSettings.xaml similarity index 80% rename from Wox.Plugin.SystemPlugins/Sys/SysSettings.xaml rename to Plugins/Wox.Plugin.Sys/SysSettings.xaml index 0ef8c5e05f..5ef2443a56 100644 --- a/Wox.Plugin.SystemPlugins/Sys/SysSettings.xaml +++ b/Plugins/Wox.Plugin.Sys/SysSettings.xaml @@ -1,4 +1,4 @@ - - + - + diff --git a/Plugins/Wox.Plugin.Sys/SysSettings.xaml.cs b/Plugins/Wox.Plugin.Sys/SysSettings.xaml.cs new file mode 100644 index 0000000000..6f91acc032 --- /dev/null +++ b/Plugins/Wox.Plugin.Sys/SysSettings.xaml.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Windows.Controls; + +namespace Wox.Plugin.Sys +{ + /// + /// Interaction logic for SysSettings.xaml + /// + public partial class SysSettings : UserControl + { + public SysSettings(List Results) + { + InitializeComponent(); + + foreach (var Result in Results) + { + this.lbxCommands.Items.Add(Result); + } + } + } +} diff --git a/Plugins/Wox.Plugin.Sys/Wox.Plugin.Sys.csproj b/Plugins/Wox.Plugin.Sys/Wox.Plugin.Sys.csproj new file mode 100644 index 0000000000..271194ab0a --- /dev/null +++ b/Plugins/Wox.Plugin.Sys/Wox.Plugin.Sys.csproj @@ -0,0 +1,138 @@ + + + + + Debug + AnyCPU + {0B9DE348-9361-4940-ADB6-F5953BFFCCEC} + Library + Properties + Wox.Plugin.Sys + Wox.Plugin.Sys + v3.5 + 512 + ..\..\ + true + + + + true + full + false + ..\..\Output\Debug\Plugins\Wox.Plugin.Sys\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + ..\..\Output\Release\Plugins\Wox.Plugin.Sys\ + TRACE + prompt + 4 + false + + + + + + + + + + + + + + + + + + + SysSettings.xaml + + + + + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} + Wox.Infrastructure + + + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + Wox.Plugin + + + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + + + + + PreserveNewest + + + + + PreserveNewest + + + + + PreserveNewest + + + + + PreserveNewest + + + + + PreserveNewest + + + + + PreserveNewest + + + + + PreserveNewest + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Sys/plugin.json b/Plugins/Wox.Plugin.Sys/plugin.json new file mode 100644 index 0000000000..9d0055e1c2 --- /dev/null +++ b/Plugins/Wox.Plugin.Sys/plugin.json @@ -0,0 +1,12 @@ +{ + "ID":"CEA08895D2544B019B2E9C5009600DF4", + "ActionKeyword":"*", + "Name":"System Commands", + "Description":"Provide System related commands. e.g. shutdown,lock,setting etc.", + "Author":"qianlifeng", + "Version":"1.0.0", + "Language":"csharp", + "Website":"http://www.getwox.com/plugin", + "ExecuteFileName":"Wox.Plugin.Sys.dll", + "IcoPath":"Images\\lock.png" +} diff --git a/Wox/Images/url.png b/Plugins/Wox.Plugin.Url/Images/url.png similarity index 100% rename from Wox/Images/url.png rename to Plugins/Wox.Plugin.Url/Images/url.png diff --git a/Plugins/Wox.Plugin.Url/Properties/AssemblyInfo.cs b/Plugins/Wox.Plugin.Url/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..894c83bff0 --- /dev/null +++ b/Plugins/Wox.Plugin.Url/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Wox.Plugin.Url")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Wox.Plugin.Url")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("ea42b60d-34ff-4656-8ee1-012afa397d3e")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wox.Plugin.SystemPlugins/UrlPlugin.cs b/Plugins/Wox.Plugin.Url/UrlPlugin.cs similarity index 83% rename from Wox.Plugin.SystemPlugins/UrlPlugin.cs rename to Plugins/Wox.Plugin.Url/UrlPlugin.cs index 0ba5080ad0..e578e7c253 100644 --- a/Wox.Plugin.SystemPlugins/UrlPlugin.cs +++ b/Plugins/Wox.Plugin.Url/UrlPlugin.cs @@ -1,15 +1,12 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.IO; -using System.Net; -using System.Security.Policy; using System.Text.RegularExpressions; using System.Windows; -namespace Wox.Plugin.SystemPlugins +namespace Wox.Plugin.Url { - public class UrlPlugin : BaseSystemPlugin + public class UrlPlugin : IPlugin { //based on https://gist.github.com/dperini/729294 private const string urlPattern ="^" + @@ -46,8 +43,10 @@ namespace Wox.Plugin.SystemPlugins "$"; Regex reg = new Regex(urlPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); - protected override List QueryInternal(Query query) + public List Query(Query query) { + if(string.IsNullOrEmpty(query.RawQuery)) return new List(); + var raw = query.RawQuery; if (IsURL(raw)) { @@ -99,17 +98,9 @@ namespace Wox.Plugin.SystemPlugins return false; } - public override string ID + public void Init(PluginInitContext context) { - get { return "0308FD86DE0A4DEE8D62B9B535370992"; } - } - public override string Name { get { return "URL handler"; } } - public override string Description { get { return "Provide Opening the typed URL from Wox."; } } - public override string IcoPath { get { return "Images/url.png"; } } - - protected override void InitInternal(PluginInitContext context) - { } } } \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Url/Wox.Plugin.Url.csproj b/Plugins/Wox.Plugin.Url/Wox.Plugin.Url.csproj new file mode 100644 index 0000000000..a35d32f5e1 --- /dev/null +++ b/Plugins/Wox.Plugin.Url/Wox.Plugin.Url.csproj @@ -0,0 +1,75 @@ + + + + + Debug + AnyCPU + {A3DCCBCA-ACC1-421D-B16E-210896234C26} + Library + Properties + Wox.Plugin.Url + Wox.Plugin.Url + v3.5 + 512 + + + + true + full + false + ..\..\Output\Debug\Plugins\Wox.Plugin.Url\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + ..\..\Output\Release\Plugins\Wox.Plugin.Url\ + TRACE + prompt + 4 + false + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + + + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + Wox.Plugin + + + + + PreserveNewest + + + + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Url/plugin.json b/Plugins/Wox.Plugin.Url/plugin.json new file mode 100644 index 0000000000..e4558f1c14 --- /dev/null +++ b/Plugins/Wox.Plugin.Url/plugin.json @@ -0,0 +1,12 @@ +{ + "ID":"0308FD86DE0A4DEE8D62B9B535370992", + "ActionKeyword":"*", + "Name":"URL handler", + "Description":"Provide Opening the typed URL from Wox.", + "Author":"qianlifeng", + "Version":"1.0.0", + "Language":"csharp", + "Website":"http://www.getwox.com/plugin", + "ExecuteFileName":"Wox.Plugin.Url.dll", + "IcoPath":"Images\\url.png" +} diff --git a/Wox/Images/web_search.png b/Plugins/Wox.Plugin.WebSearch/Images/web_search.png similarity index 100% rename from Wox/Images/web_search.png rename to Plugins/Wox.Plugin.WebSearch/Images/web_search.png diff --git a/Wox/Images/websearch/google.png b/Plugins/Wox.Plugin.WebSearch/Images/websearch/google.png similarity index 100% rename from Wox/Images/websearch/google.png rename to Plugins/Wox.Plugin.WebSearch/Images/websearch/google.png diff --git a/Wox/Images/websearch/pictures.png b/Plugins/Wox.Plugin.WebSearch/Images/websearch/pictures.png similarity index 100% rename from Wox/Images/websearch/pictures.png rename to Plugins/Wox.Plugin.WebSearch/Images/websearch/pictures.png diff --git a/Wox/Images/websearch/wiki.png b/Plugins/Wox.Plugin.WebSearch/Images/websearch/wiki.png similarity index 100% rename from Wox/Images/websearch/wiki.png rename to Plugins/Wox.Plugin.WebSearch/Images/websearch/wiki.png diff --git a/Plugins/Wox.Plugin.WebSearch/Languages/en.xaml b/Plugins/Wox.Plugin.WebSearch/Languages/en.xaml new file mode 100644 index 0000000000..e0a143f53c --- /dev/null +++ b/Plugins/Wox.Plugin.WebSearch/Languages/en.xaml @@ -0,0 +1,28 @@ + + + Delete + Edit + Add + Action Keyword + URL + Enable search suggestions + Please select a web search + Are your sure to delete {0}? + + + + Title + Enable + Select Icon + Icon + Cancel + Invalid web search + Please input title + Please input action keyword + Please input URL + ActionWord has existed, please input a new one + Succeed + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.WebSearch/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.WebSearch/Languages/zh-cn.xaml new file mode 100644 index 0000000000..f82419b67d --- /dev/null +++ b/Plugins/Wox.Plugin.WebSearch/Languages/zh-cn.xaml @@ -0,0 +1,28 @@ + + + 删除 + 编辑 + 添加 + 触发关键字 + URL + 启用搜索建议 + 请选择一项 + 你确定要删除 {0} 吗? + + + + 标题 + 启用 + 图标 + 选择图标 + 取消 + 非法的网页搜索 + 请输入标题 + 请输入触发关键字 + 请输入URL + 触发关键字已经存在,请选择一个新的关键字 + 操作成功 + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml new file mode 100644 index 0000000000..def9146a81 --- /dev/null +++ b/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml @@ -0,0 +1,28 @@ + + + 刪除 + 編輯 + 添加 + 觸發關鍵字 + URL + 啟用搜索建議 + 請選擇一項 + 你確定要刪除 {0} 嗎? + + + + 標題 + 啟用 + 圖標 + 選擇圖標 + 取消 + 非法的網頁搜索 + 請輸入標題 + 請輸入觸發關鍵字 + 請輸入URL + 觸發關鍵字已經存在,請選擇一個新的關鍵字 + 操作成功 + + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.WebSearch/Properties/AssemblyInfo.cs b/Plugins/Wox.Plugin.WebSearch/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..23f84e286a --- /dev/null +++ b/Plugins/Wox.Plugin.WebSearch/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Wox.Plugin.WebSearch")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Wox.Plugin.WebSearch")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("42c17706-44ba-4549-ab66-7bd994706cd1")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wox.Plugin.SystemPlugins/SuggestionSources/Baidu.cs b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Baidu.cs similarity index 74% rename from Wox.Plugin.SystemPlugins/SuggestionSources/Baidu.cs rename to Plugins/Wox.Plugin.WebSearch/SuggestionSources/Baidu.cs index edb81bcddd..40a24c6b61 100644 --- a/Wox.Plugin.SystemPlugins/SuggestionSources/Baidu.cs +++ b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Baidu.cs @@ -1,18 +1,13 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Text; using System.Text.RegularExpressions; -using System.Xml; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; -using Wox.Infrastructure; +using Wox.Core.UserSettings; using Wox.Infrastructure.Http; -using YAMP.Numerics; -namespace Wox.Plugin.SystemPlugins.SuggestionSources +namespace Wox.Plugin.WebSearch.SuggestionSources { public class Baidu : AbstractSuggestionSource { @@ -20,7 +15,7 @@ namespace Wox.Plugin.SystemPlugins.SuggestionSources public override List GetSuggestions(string query) { - var result = HttpRequest.Get("http://suggestion.baidu.com/su?json=1&wd=" + Uri.EscapeUriString(query), "GB2312"); + var result = HttpRequest.Get("http://suggestion.baidu.com/su?json=1&wd=" + Uri.EscapeUriString(query), HttpProxy.Instance, "GB2312"); if (string.IsNullOrEmpty(result)) return new List(); Match match = reg.Match(result); @@ -29,9 +24,9 @@ namespace Wox.Plugin.SystemPlugins.SuggestionSources JContainer json = null; try { - json =JsonConvert.DeserializeObject(match.Groups[1].Value) as JContainer; + json = JsonConvert.DeserializeObject(match.Groups[1].Value) as JContainer; } - catch{} + catch { } if (json != null) { diff --git a/Wox.Plugin.SystemPlugins/SuggestionSources/Google.cs b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Google.cs similarity index 78% rename from Wox.Plugin.SystemPlugins/SuggestionSources/Google.cs rename to Plugins/Wox.Plugin.WebSearch/SuggestionSources/Google.cs index e0ad8e0458..b09b8d8fc7 100644 --- a/Wox.Plugin.SystemPlugins/SuggestionSources/Google.cs +++ b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Google.cs @@ -1,23 +1,18 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Text; -using System.Xml; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; -using Wox.Infrastructure; +using Wox.Core.UserSettings; using Wox.Infrastructure.Http; -using YAMP.Numerics; -namespace Wox.Plugin.SystemPlugins.SuggestionSources +namespace Wox.Plugin.WebSearch.SuggestionSources { public class Google : AbstractSuggestionSource { public override List GetSuggestions(string query) { - var result = HttpRequest.Get("https://www.google.com/complete/search?output=chrome&q=" + Uri.EscapeUriString(query)); + var result = HttpRequest.Get("https://www.google.com/complete/search?output=chrome&q=" + Uri.EscapeUriString(query),HttpProxy.Instance); if (string.IsNullOrEmpty(result)) return new List(); try diff --git a/Wox.Plugin.SystemPlugins/SuggestionSources/ISuggestionSource.cs b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/ISuggestionSource.cs similarity index 56% rename from Wox.Plugin.SystemPlugins/SuggestionSources/ISuggestionSource.cs rename to Plugins/Wox.Plugin.WebSearch/SuggestionSources/ISuggestionSource.cs index 255ee40773..dd4b82fb6c 100644 --- a/Wox.Plugin.SystemPlugins/SuggestionSources/ISuggestionSource.cs +++ b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/ISuggestionSource.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Cryptography.X509Certificates; -using System.Text; +using System.Collections.Generic; -namespace Wox.Plugin.SystemPlugins.SuggestionSources +namespace Wox.Plugin.WebSearch.SuggestionSources { public interface ISuggestionSource { diff --git a/Wox.Plugin.SystemPlugins/SuggestionSources/SuggestionSourceFactory.cs b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/SuggestionSourceFactory.cs similarity index 74% rename from Wox.Plugin.SystemPlugins/SuggestionSources/SuggestionSourceFactory.cs rename to Plugins/Wox.Plugin.WebSearch/SuggestionSources/SuggestionSourceFactory.cs index 3262320b94..000cec8f72 100644 --- a/Wox.Plugin.SystemPlugins/SuggestionSources/SuggestionSourceFactory.cs +++ b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/SuggestionSourceFactory.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Wox.Plugin.SystemPlugins.SuggestionSources +namespace Wox.Plugin.WebSearch.SuggestionSources { public class SuggestionSourceFactory { diff --git a/Wox.Plugin.SystemPlugins/WebSearch/WebSearchPlugin.cs b/Plugins/Wox.Plugin.WebSearch/WebSearchPlugin.cs similarity index 76% rename from Wox.Plugin.SystemPlugins/WebSearch/WebSearchPlugin.cs rename to Plugins/Wox.Plugin.WebSearch/WebSearchPlugin.cs index 67e1687055..11989fb32c 100644 --- a/Wox.Plugin.SystemPlugins/WebSearch/WebSearchPlugin.cs +++ b/Plugins/Wox.Plugin.WebSearch/WebSearchPlugin.cs @@ -3,23 +3,21 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using Newtonsoft.Json; -using Wox.Infrastructure; -using Wox.Infrastructure.Storage; -using Wox.Infrastructure.Storage.UserSettings; -using Wox.Plugin.SystemPlugins.SuggestionSources; +using System.Reflection; +using Wox.Core.UserSettings; +using Wox.Plugin.WebSearch.SuggestionSources; -namespace Wox.Plugin.SystemPlugins +namespace Wox.Plugin.WebSearch { - public class WebSearchPlugin : BaseSystemPlugin, ISettingProvider + public class WebSearchPlugin : IPlugin, ISettingProvider,IPluginI18n { private PluginInitContext context; - protected override List QueryInternal(Query query) + public List Query(Query query) { List results = new List(); - WebSearch webSearch = + Core.UserSettings.WebSearch webSearch = UserSettingStorage.Instance.WebSearches.FirstOrDefault(o => o.ActionWord == query.ActionName && o.Enabled); if (webSearch != null) @@ -46,7 +44,7 @@ namespace Wox.Plugin.SystemPlugins return true; } } - }); + },true); if (UserSettingStorage.Instance.EnableWebSearchSuggestion && !string.IsNullOrEmpty(keyword)) { @@ -78,7 +76,7 @@ namespace Wox.Plugin.SystemPlugins return results; } - protected override void InitInternal(PluginInitContext context) + public void Init(PluginInitContext context) { this.context = context; @@ -86,33 +84,18 @@ namespace Wox.Plugin.SystemPlugins UserSettingStorage.Instance.WebSearches = UserSettingStorage.Instance.LoadDefaultWebSearches(); } - public override string ID - { - get { return "565B73353DBF4806919830B9202EE3BF"; } - } - - public override string Name - { - get { return "Web Searches"; } - } - - public override string IcoPath - { - get { return @"Images\web_search.png"; } - } - - public override string Description - { - get { return "Provide the web search ability."; } - } - #region ISettingProvider Members public System.Windows.Controls.Control CreateSettingPanel() { - return new WebSearchesSetting(); + return new WebSearchesSetting(context); } #endregion + + public string GetLanguagesFolder() + { + return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Languages"); + } } } diff --git a/Wox.Plugin.SystemPlugins/WebSearch/WebSearchSetting.xaml b/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml similarity index 77% rename from Wox.Plugin.SystemPlugins/WebSearch/WebSearchSetting.xaml rename to Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml index 31635038a0..86beaf2917 100644 --- a/Wox.Plugin.SystemPlugins/WebSearch/WebSearchSetting.xaml +++ b/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml @@ -1,4 +1,4 @@ - - Title: + - URL: + - ActionWord: + - Enable: + - Icon: + - + - - + + diff --git a/Wox.Plugin.SystemPlugins/WebSearch/WebSearchSetting.xaml.cs b/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml.cs similarity index 66% rename from Wox.Plugin.SystemPlugins/WebSearch/WebSearchSetting.xaml.cs rename to Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml.cs index 6f496b1b7b..c7e5138d06 100644 --- a/Wox.Plugin.SystemPlugins/WebSearch/WebSearchSetting.xaml.cs +++ b/Plugins/Wox.Plugin.WebSearch/WebSearchSetting.xaml.cs @@ -1,43 +1,37 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; +using System.Reflection; using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Forms; -using System.Windows.Input; -using System.Windows.Media; using System.Windows.Media.Imaging; -using System.Windows.Shapes; -using Wox.Infrastructure; -using Wox.Infrastructure.Storage; -using Wox.Infrastructure.Storage.UserSettings; -using MessageBox = System.Windows.MessageBox; +using Microsoft.Win32; +using Wox.Core.UserSettings; -namespace Wox.Plugin.SystemPlugins +namespace Wox.Plugin.WebSearch { public partial class WebSearchSetting : Window { - private string defaultWebSearchImageDirectory = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Images\\websearch"); + private string defaultWebSearchImageDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images\\websearch"); private WebSearchesSetting settingWindow; private bool update; - private WebSearch updateWebSearch; + private Core.UserSettings.WebSearch updateWebSearch; + private PluginInitContext context; - public WebSearchSetting(WebSearchesSetting settingWidow) + public WebSearchSetting(WebSearchesSetting settingWidow,PluginInitContext context) { + this.context = context; this.settingWindow = settingWidow; InitializeComponent(); } - public void UpdateItem(WebSearch webSearch) + public void UpdateItem(Core.UserSettings.WebSearch webSearch) { updateWebSearch = UserSettingStorage.Instance.WebSearches.FirstOrDefault(o => o == webSearch); if (updateWebSearch == null || string.IsNullOrEmpty(updateWebSearch.Url)) { - MessageBox.Show("Invalid web search"); + + string warning = context.API.GetTranslation("wox_plugin_websearch_invalid_web_search"); + MessageBox.Show(warning); Close(); return; } @@ -73,21 +67,24 @@ namespace Wox.Plugin.SystemPlugins string title = tbTitle.Text; if (string.IsNullOrEmpty(title)) { - MessageBox.Show("Please input Title field"); + string warning = context.API.GetTranslation("wox_plugin_websearch_input_title"); + MessageBox.Show(warning); return; } string url = tbUrl.Text; if (string.IsNullOrEmpty(url)) { - MessageBox.Show("Please input URL field"); + string warning = context.API.GetTranslation("wox_plugin_websearch_input_url"); + MessageBox.Show(warning); return; } string action = tbActionword.Text; if (string.IsNullOrEmpty(action)) { - MessageBox.Show("Please input ActionWord field"); + string warning = context.API.GetTranslation("wox_plugin_websearch_input_action_keyword"); + MessageBox.Show(warning); return; } @@ -96,10 +93,11 @@ namespace Wox.Plugin.SystemPlugins { if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == action)) { - MessageBox.Show("ActionWord has existed, please input a new one."); + string warning = context.API.GetTranslation("wox_plugin_websearch_action_keyword_exist"); + MessageBox.Show(warning); return; } - UserSettingStorage.Instance.WebSearches.Add(new WebSearch() + UserSettingStorage.Instance.WebSearches.Add(new Core.UserSettings.WebSearch() { ActionWord = action, Enabled = cbEnable.IsChecked ?? false, @@ -107,13 +105,15 @@ namespace Wox.Plugin.SystemPlugins Url = url, Title = title }); - MessageBox.Show(string.Format("Add {0} web search successfully!", title)); + string msg = context.API.GetTranslation("wox_plugin_websearch_succeed"); + MessageBox.Show(msg); } else { if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == action && o != updateWebSearch)) { - MessageBox.Show("ActionWord has existed, please input a new one."); + string warning = context.API.GetTranslation("wox_plugin_websearch_action_keyword_exist"); + MessageBox.Show(warning); return; } updateWebSearch.ActionWord = action; @@ -121,7 +121,8 @@ namespace Wox.Plugin.SystemPlugins updateWebSearch.Enabled = cbEnable.IsChecked ?? false; updateWebSearch.Url = url; updateWebSearch.Title= title; - MessageBox.Show(string.Format("Update {0} web search successfully!", title)); + string msg = context.API.GetTranslation("wox_plugin_websearch_succeed"); + MessageBox.Show(msg); } UserSettingStorage.Instance.Save(); settingWindow.ReloadWebSearchView(); @@ -133,10 +134,10 @@ namespace Wox.Plugin.SystemPlugins if(!Directory.Exists(defaultWebSearchImageDirectory)) { defaultWebSearchImageDirectory = - System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath); + Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); } - var dlg = new Microsoft.Win32.OpenFileDialog + var dlg = new OpenFileDialog { InitialDirectory = defaultWebSearchImageDirectory, Filter ="Image files (*.jpg, *.jpeg, *.gif, *.png, *.bmp) |*.jpg; *.jpeg; *.gif; *.png; *.bmp" diff --git a/Wox.Plugin.SystemPlugins/WebSearch/WebSearchesSetting.xaml b/Plugins/Wox.Plugin.WebSearch/WebSearchesSetting.xaml similarity index 72% rename from Wox.Plugin.SystemPlugins/WebSearch/WebSearchesSetting.xaml rename to Plugins/Wox.Plugin.WebSearch/WebSearchesSetting.xaml index 8e24a5993e..0a823dc7cd 100644 --- a/Wox.Plugin.SystemPlugins/WebSearch/WebSearchesSetting.xaml +++ b/Plugins/Wox.Plugin.WebSearch/WebSearchesSetting.xaml @@ -1,10 +1,10 @@ - + d:DesignHeight="300" d:DesignWidth="500"> @@ -12,21 +12,21 @@ - Enable search suggestions + - + - + @@ -37,9 +37,9 @@ - + + + + diff --git a/Wox.CrashReporter/ReportWindow.xaml.cs b/Wox.CrashReporter/ReportWindow.xaml.cs new file mode 100644 index 0000000000..55ec0555b7 --- /dev/null +++ b/Wox.CrashReporter/ReportWindow.xaml.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Wox.Core; +using Wox.Core.Exception; +using Wox.Core.i18n; +using Wox.Core.UI; +using Wox.Core.UserSettings; +using Wox.Core.Version; +using Wox.Infrastructure.Http; + +namespace Wox.CrashReporter +{ + internal partial class ReportWindow + { + private Exception exception; + + public ReportWindow(Exception exception) + { + this.exception = exception; + InitializeComponent(); + SetException(exception); + } + + private void SetException(Exception exception) + { + tbSummary.AppendText(exception.Message); + tbVersion.Text = VersionManager.Instance.CurrentVersion.ToString(); + tbDatetime.Text = DateTime.Now.ToString(); + tbStackTrace.AppendText(exception.StackTrace); + tbSource.Text = exception.Source; + tbType.Text = exception.GetType().ToString(); + } + + private void btnSend_Click(object sender, RoutedEventArgs e) + { + string sendingMsg = InternationalizationManager.Internationalization.GetTranslation("reportWindow_sending"); + tbSendReport.Content = sendingMsg; + btnSend.IsEnabled = false; + ThreadPool.QueueUserWorkItem(o => SendReport()); + } + + private void SendReport() + { + string error = string.Format("{{\"data\":{0}}}", ExceptionFormatter.FormatExcpetion(exception)); + string response = HttpRequest.Post(APIServer.ErrorReportURL, error, HttpProxy.Instance); + if (response.ToLower() == "ok") + { + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("reportWindow_report_succeed")); + } + else + { + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("reportWindow_report_failed")); + } + Dispatcher.Invoke(new Action(Close)); + } + + private void btnCancel_Click(object sender, RoutedEventArgs e) + { + Close(); + } + } +} diff --git a/Wox.CrashReporter/Wox.CrashReporter.csproj b/Wox.CrashReporter/Wox.CrashReporter.csproj new file mode 100644 index 0000000000..565c82d816 --- /dev/null +++ b/Wox.CrashReporter/Wox.CrashReporter.csproj @@ -0,0 +1,109 @@ + + + + + Debug + AnyCPU + {2FEB2298-7653-4009-B1EA-FFFB1A768BCC} + Library + Properties + Wox.CrashReporter + Wox.CrashReporter + v3.5 + 512 + ..\ + true + + + + true + full + false + ..\Output\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + ..\Output\Release\ + TRACE + prompt + 4 + false + + + + + + + + + + + + + + + + + + ReportWindow.xaml + + + + + Designer + MSBuild:Compile + + + + + {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2} + Wox.Core + + + {4FD29318-A8AB-4D8F-AA47-60BC241B8DA3} + Wox.Infrastructure + + + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80} + Wox.Plugin + + + + + PreserveNewest + + + PreserveNewest + + + + + PreserveNewest + + + + + PreserveNewest + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + + \ No newline at end of file diff --git a/Wox.Infrastructure/ChineseToPinYin.cs b/Wox.Infrastructure/ChineseToPinYin.cs deleted file mode 100644 index 1f59d7c282..0000000000 --- a/Wox.Infrastructure/ChineseToPinYin.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Wox.Infrastructure -{ - public static class ChineseToPinYin - { - [Obsolete] - public static string ToPinYin(string txt) - { - return txt.Unidecode(); - } - } -} diff --git a/Wox.Infrastructure/Exceptions/WoxException.cs b/Wox.Infrastructure/Exceptions/WoxException.cs deleted file mode 100644 index 581f36edb7..0000000000 --- a/Wox.Infrastructure/Exceptions/WoxException.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace Wox.Infrastructure.Exceptions -{ - public class WoxException : Exception - { - public WoxException(string msg) - : base(msg) - { - - } - } -} diff --git a/Wox.Infrastructure/Hotkey/GlobalHotkey.cs b/Wox.Infrastructure/Hotkey/GlobalHotkey.cs index 8a6f31323b..d07b5180db 100644 --- a/Wox.Infrastructure/Hotkey/GlobalHotkey.cs +++ b/Wox.Infrastructure/Hotkey/GlobalHotkey.cs @@ -1,114 +1,17 @@ using System; -using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Wox.Plugin; namespace Wox.Infrastructure.Hotkey { - public enum KeyEvent : int - { - /// - /// Key down - /// - WM_KEYDOWN = 256, - - /// - /// Key up - /// - WM_KEYUP = 257, - - /// - /// System key up - /// - WM_SYSKEYUP = 261, - - /// - /// System key down - /// - WM_SYSKEYDOWN = 260 - } - - public static class InterceptKeys - { - public delegate IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam); - - private static int WH_KEYBOARD_LL = 13; - - public static IntPtr SetHook(LowLevelKeyboardProc proc) - { - using (Process curProcess = Process.GetCurrentProcess()) - using (ProcessModule curModule = curProcess.MainModule) - { - return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0); - } - } - - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] - public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); - - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool UnhookWindowsHookEx(IntPtr hhk); - - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] - public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, UIntPtr wParam, IntPtr lParam); - - [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] - public static extern IntPtr GetModuleHandle(string lpModuleName); - - [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - public static extern short GetKeyState(int keyCode); - - [DllImport("user32.dll")] - internal static extern uint SendInput(uint nInputs, [MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs, int cbSize); - } - - [StructLayout(LayoutKind.Explicit)] - public struct INPUT - { - [FieldOffset(0)] - public Int32 type;//0-MOUSEINPUT;1-KEYBDINPUT;2-HARDWAREINPUT - [FieldOffset(4)] - public KEYBDINPUT ki; - [FieldOffset(4)] - public MOUSEINPUT mi; - [FieldOffset(4)] - public HARDWAREINPUT hi; - } - [StructLayout(LayoutKind.Sequential)] - public struct MOUSEINPUT - { - public Int32 dx; - public Int32 dy; - public Int32 mouseData; - public Int32 dwFlags; - public Int32 time; - public IntPtr dwExtraInfo; - } - [StructLayout(LayoutKind.Sequential)] - public struct KEYBDINPUT - { - public Int16 wVk; - public Int16 wScan; - public Int32 dwFlags; - public Int32 time; - public IntPtr dwExtraInfo; - } - [StructLayout(LayoutKind.Sequential)] - public struct HARDWAREINPUT - { - public Int32 uMsg; - public Int16 wParamL; - public Int16 wParamH; - } - /// /// Listens keyboard globally. /// Uses WH_KEYBOARD_LL. /// public class GlobalHotkey : IDisposable { + private static GlobalHotkey instance; private InterceptKeys.LowLevelKeyboardProc hookedLowLevelKeyboardProc; private IntPtr hookId = IntPtr.Zero; public delegate bool KeyboardCallback(KeyEvent keyEvent, int vkCode, SpecialKeyState state); @@ -120,7 +23,19 @@ namespace Wox.Infrastructure.Hotkey private const int VK_ALT = 0x12; private const int VK_WIN = 91; - public GlobalHotkey() + public static GlobalHotkey Instance + { + get + { + if (instance == null) + { + instance = new GlobalHotkey(); + } + return instance; + } + } + + private GlobalHotkey() { // We have to store the LowLevelKeyboardProc, so that it is not garbage collected runtime hookedLowLevelKeyboardProc = LowLevelKeyboardProc; diff --git a/Wox.Infrastructure/Hotkey/InterceptKeys.cs b/Wox.Infrastructure/Hotkey/InterceptKeys.cs new file mode 100644 index 0000000000..ef8dd576df --- /dev/null +++ b/Wox.Infrastructure/Hotkey/InterceptKeys.cs @@ -0,0 +1,38 @@ +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace Wox.Infrastructure.Hotkey +{ + internal static class InterceptKeys + { + public delegate IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam); + + private const int WH_KEYBOARD_LL = 13; + + public static IntPtr SetHook(LowLevelKeyboardProc proc) + { + using (Process curProcess = Process.GetCurrentProcess()) + using (ProcessModule curModule = curProcess.MainModule) + { + return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0); + } + } + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool UnhookWindowsHookEx(IntPtr hhk); + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, UIntPtr wParam, IntPtr lParam); + + [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern IntPtr GetModuleHandle(string lpModuleName); + + [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] + public static extern short GetKeyState(int keyCode); + } +} \ No newline at end of file diff --git a/Wox.Infrastructure/Hotkey/KeyEvent.cs b/Wox.Infrastructure/Hotkey/KeyEvent.cs new file mode 100644 index 0000000000..f1b6eefd0c --- /dev/null +++ b/Wox.Infrastructure/Hotkey/KeyEvent.cs @@ -0,0 +1,25 @@ +namespace Wox.Infrastructure.Hotkey +{ + public enum KeyEvent:int + { + /// + /// Key down + /// + WM_KEYDOWN = 256, + + /// + /// Key up + /// + WM_KEYUP = 257, + + /// + /// System key up + /// + WM_SYSKEYUP = 261, + + /// + /// System key down + /// + WM_SYSKEYDOWN = 260 + } +} \ No newline at end of file diff --git a/Wox.Infrastructure/Http/HttpRequest.cs b/Wox.Infrastructure/Http/HttpRequest.cs index eda68b9014..5c08377d6b 100644 --- a/Wox.Infrastructure/Http/HttpRequest.cs +++ b/Wox.Infrastructure/Http/HttpRequest.cs @@ -1,4 +1,5 @@ using System; +using System.Drawing; using System.IO; using System.Net; using System.Text; @@ -8,9 +9,9 @@ namespace Wox.Infrastructure.Http { public class HttpRequest { - public static string Get(string url, string encoding = "UTF-8") + public static string Get(string url, IHttpProxy proxy, string encoding = "UTF-8") { - return Get(url, encoding, HttpProxy.Instance); + return Get(url, encoding, proxy); } private static string Get(string url, string encoding, IHttpProxy proxy) @@ -52,6 +53,60 @@ namespace Wox.Infrastructure.Http } catch (Exception e) { + Logger.Log.Error(e); + return string.Empty; + } + + return string.Empty; + } + + public static string Post(string url, string jsonData, IHttpProxy proxy) + { + if (string.IsNullOrEmpty(url)) return string.Empty; + + HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; + request.Method = "POST"; + request.ContentType = "text/json"; + request.Timeout = 10 * 1000; + if (proxy != null && proxy.Enabled && !string.IsNullOrEmpty(proxy.Server)) + { + if (string.IsNullOrEmpty(proxy.UserName) || string.IsNullOrEmpty(proxy.Password)) + { + request.Proxy = new WebProxy(proxy.Server, proxy.Port); + } + else + { + request.Proxy = new WebProxy(proxy.Server, proxy.Port) + { + Credentials = new NetworkCredential(proxy.UserName, proxy.Password) + }; + } + } + using (var streamWriter = new StreamWriter(request.GetRequestStream())) + { + streamWriter.Write(jsonData); + streamWriter.Flush(); + streamWriter.Close(); + } + + try + { + HttpWebResponse response = request.GetResponse() as HttpWebResponse; + if (response != null) + { + Stream stream = response.GetResponseStream(); + if (stream != null) + { + using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8"))) + { + return reader.ReadToEnd(); + } + } + } + } + catch (Exception e) + { + Logger.Log.Error(e); return string.Empty; } diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index 3860b76173..8cfbc52bd5 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -1,35 +1,41 @@ -using System.Reflection; -using log4net; +using System; +using System.Reflection; +using NLog; namespace Wox.Infrastructure.Logger { public class Log { - private static ILog fileLogger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static NLog.Logger logger = LogManager.GetCurrentClassLogger(); public static void Error(string msg) { - fileLogger.Error(msg); + logger.Error(msg); + } + + public static void Error(Exception e) + { + logger.Error(e.Message + "\r\n" + e.StackTrace); } public static void Debug(string msg) { - fileLogger.Debug(msg); + logger.Debug(msg); } public static void Info(string msg) { - fileLogger.Info(msg); + logger.Info(msg); } public static void Warn(string msg) { - fileLogger.Warn(msg); + logger.Warn(msg); } public static void Fatal(string msg) { - fileLogger.Fatal(msg); + logger.Fatal(msg); } } } diff --git a/Wox.Infrastructure/Logger/NLog.xsd b/Wox.Infrastructure/Logger/NLog.xsd new file mode 100644 index 0000000000..481702860b --- /dev/null +++ b/Wox.Infrastructure/Logger/NLog.xsd @@ -0,0 +1,2694 @@ + + + + + + + + + + + + + + + Watch config file for changes and reload automatically. + + + + + Print internal NLog messages to the console. Default value is: false + + + + + Print internal NLog messages to the console error output. Default value is: false + + + + + Write internal NLog messages to the specified file. + + + + + Log level threshold for internal log messages. Default value is: Info. + + + + + Global log level threshold for application log messages. Messages below this level won't be logged.. + + + + + Pass NLog internal exceptions to the application. Default value is: false. + + + + + + + + + + + + + + Make all targets within this section asynchronous (creates additional threads but the calling thread isn't blocked by any target writes). + + + + + + + + + + + + + + + + + Prefix for targets/layout renderers/filters/conditions loaded from this assembly. + + + + + Load NLog extensions from the specified file (*.dll) + + + + + Load NLog extensions from the specified assembly. Assembly name should be fully qualified. + + + + + + + + + + Name of the logger. May include '*' character which acts like a wildcard. Allowed forms are: *, Name, *Name, Name* and *Name* + + + + + Comma separated list of levels that this rule matches. + + + + + Minimum level that this rule matches. + + + + + Maximum level that this rule matches. + + + + + Level that this rule matches. + + + + + Comma separated list of target names. + + + + + Ignore further rules if this one matches. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the file to be included. The name is relative to the name of the current config file. + + + + + Ignore any errors in the include file. + + + + + + + Variable name. + + + + + Variable value. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Maximum number of log events that the buffer can keep. + + + + + Number of log events to be buffered. + + + + + Indicates whether buffer should grow as needed. + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Indicates whether to add <!-- --> comments around all written texts. + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Number of log events that should be processed in a batch by the lazy writer thread. + + + + + Action to be taken when the lazy writer thread request queue count exceeds the set limit. + + + + + Limit on the number of requests in the lazy writer thread request queue. + + + + + Time in milliseconds to sleep between batches. + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + + + + + + + + + + + + + Name of the target. + + + + + Number of log events to be buffered. + + + + + Timeout (in milliseconds) after which the contents of buffer will be flushed if there's no write in the specified period of time. Use -1 to disable timed flushes. + + + + + Indicates whether to use sliding timeout. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Encoding to be used. + + + + + Instance of that is used to format log messages. + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Maximum queue size. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + NDC item separator. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include dictionary contents. + + + + + + + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Viewer parameter name. + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to use default row highlighting rules. + + + + + Indicates whether the error stream (stderr) should be used instead of the output stream (stdout). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Condition that must be met in order to set the specified foreground and background color. + + + + + Background color. + + + + + Foreground color. + + + + + + + + + + + + + + + Indicates whether to ignore case when comparing texts. + + + + + Regular expression to be matched. You must specify either text or regex. + + + + + Text to be matched. You must specify either text or regex. + + + + + Indicates whether to match whole words only. + + + + + Background color. + + + + + Foreground color. + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to send the log messages to the standard error instead of the standard output. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Connection string. When provided, it overrides the values specified in DBHost, DBUserName, DBPassword, DBDatabase. + + + + + Name of the connection string (as specified in <connectionStrings> configuration section. + + + + + Database name. If the ConnectionString is not provided this value will be used to construct the "Database=" part of the connection string. + + + + + Database host name. If the ConnectionString is not provided this value will be used to construct the "Server=" part of the connection string. + + + + + Database password. If the ConnectionString is not provided this value will be used to construct the "Password=" part of the connection string. + + + + + Name of the database provider. + + + + + Database user name. If the ConnectionString is not provided this value will be used to construct the "User ID=" part of the connection string. + + + + + Indicates whether to keep the database connection open between the log events. + + + + + Indicates whether to use database transactions. Some data providers require this. + + + + + Connection string using for installation and uninstallation. If not provided, regular ConnectionString is being used. + + + + + Text of the SQL command to be run on each log level. + + + + + Type of the SQL command to be run on each log level. + + + + + + + + + + + + + + + + + + + + + + + Type of the command. + + + + + Connection string to run the command against. If not provided, connection string from the target is used. + + + + + Indicates whether to ignore failures. + + + + + Command text. + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Database parameter name. + + + + + Database parameter precision. + + + + + Database parameter scale. + + + + + Database parameter size. + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Layout that renders event Category. + + + + + Layout that renders event ID. + + + + + Name of the Event Log to write to. This can be System, Application or any user-defined name. + + + + + Name of the machine on which Event Log service is running. + + + + + Value to be used as the event Source. + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether to return to the first target after any successful write. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + File encoding. + + + + + Line ending mode. + + + + + Way file archives are numbered. + + + + + Name of the file to be used for an archive. + + + + + Indicates whether to automatically archive log files every time the specified time passes. + + + + + Size in bytes above which log files will be automatically archived. + + + + + Maximum number of archive files that should be kept. + + + + + Gets ors set a value indicating whether a managed file stream is forced, instead of used the native implementation. + + + + + File attributes (Windows only). + + + + + Indicates whether to replace file contents on each write instead of appending log message at the end. + + + + + Indicates whether to delete old log file on startup. + + + + + Name of the file to write to. + + + + + Value specifying the date format to use when archving files. + + + + + Indicates whether to archive old log file on startup. + + + + + Indicates whether to create directories if they don't exist. + + + + + Indicates whether to enable log file(s) to be deleted. + + + + + Maximum number of seconds that files are kept open. If this number is negative the files are not automatically closed after a period of inactivity. + + + + + Indicates whether concurrent writes to the log file by multiple processes on different network hosts. + + + + + Indicates whether to keep log file open instead of opening and closing it on each logging event. + + + + + Indicates whether concurrent writes to the log file by multiple processes on the same host. + + + + + Number of times the write is appended on the file before NLog discards the log message. + + + + + Delay in milliseconds to wait before attempting to write to the file again. + + + + + Log file buffer size in bytes. + + + + + Number of files to be kept open. Setting this to a higher value may improve performance in a situation where a single File target is writing to many files (such as splitting by level or by logger). + + + + + Indicates whether to automatically flush the file buffers after each log message. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Condition expression. Log events who meet this condition will be forwarded to the wrapped target. + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Indicates whether log text should be appended to the text of the control instead of overwriting it. + + + + + Name of control to which NLog will log write log text. + + + + + Name of the Form on which the control is located. + + + + + Whether new log entry are added to the start or the end of the control + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Windows domain name to change context to. + + + + + Required impersonation level. + + + + + Type of the logon provider. + + + + + Logon Type. + + + + + User account password. + + + + + Indicates whether to revert to the credentials of the process instead of impersonating another user. + + + + + Username to change context to. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Endpoint address. + + + + + Name of the endpoint configuration in WCF configuration file. + + + + + Client ID. + + + + + Indicates whether to include per-event properties in the payload sent to the server. + + + + + Indicates whether to use binary message encoding. + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Name of the parameter. + + + + + Type of the parameter. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to send message as HTML instead of plain text. + + + + + Encoding to be used for sending e-mail. + + + + + Indicates whether to add new lines between log entries. + + + + + BCC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + Recipients' email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + CC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + Mail message body (repeated for each log message send in one mail). + + + + + Mail subject. + + + + + Sender's email address (e.g. joe@domain.com). + + + + + Indicates whether NewLine characters in the body should be replaced with tags. + + + + + Priority used for sending mails. + + + + + Indicates the SMTP client timeout. + + + + + SMTP Server to be used for sending. + + + + + SMTP Authentication mode. + + + + + Username used to connect to SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + Password used to authenticate against SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + Indicates whether SSL (secure sockets layer) should be used when communicating with SMTP server. + + + + + Port number that SMTP Server is listening on. + + + + + Indicates whether the default Settings from System.Net.MailSettings should be used. + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Message box title. + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Encoding to be used when writing text to the queue. + + + + + Indicates whether to use the XML format when serializing message. This will also disable creating queues. + + + + + Indicates whether to check if a queue exists before writing to it. + + + + + Indicates whether to create the queue if it doesn't exists. + + + + + Label to associate with each message. + + + + + Name of the queue to write to. + + + + + Indicates whether to use recoverable messages (with guaranteed delivery). + + + + + + + + + + + + + + + + + Name of the target. + + + + + Class name. + + + + + Method name. The method must be public and static. + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Encoding to be used. + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Network address. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Indicates whether to keep connection open whenever possible. + + + + + Maximum queue size. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Encoding to be used. + + + + + Instance of that is used to format log messages. + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Maximum queue size. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + NDC item separator. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include dictionary contents. + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Indicates whether to perform layout calculation. + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether performance counter should be automatically created. + + + + + Name of the performance counter category. + + + + + Counter help text. + + + + + Name of the performance counter. + + + + + Performance counter type. + + + + + Performance counter instance name. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Default filter to be applied when no specific rule matches. + + + + + + + + + + + + + Condition to be tested. + + + + + Resulting filter to be applied when the condition matches. + + + + + + + + + + + + Name of the target. + + + + + + + + + + + + + + + Name of the target. + + + + + Number of times to repeat each log message. + + + + + + + + + + + + + + + + Name of the target. + + + + + Number of retries that should be attempted on the wrapped target in case of a failure. + + + + + Time to wait between retries in milliseconds. + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Indicates whether scroll bar will be moved automatically to show most recent log entries. + + + + + Name of RichTextBox to which Nlog will write. + + + + + Name of the Form on which the control is located. If there is no open form of a specified name than NLog will create a new one. + + + + + Initial height of the form with rich text box. + + + + + Maximum number of lines the rich text box will store (or 0 to disable this feature). + + + + + Indicates whether the created form will be initially minimized. + + + + + Indicates whether the created window will be a tool window. + + + + + Initial width of the form with rich text box. + + + + + Indicates whether to use default coloring rules. + + + + + + + + + + + + + + + + + + + + + + + + Condition that must be met in order to set the specified font color. + + + + + Background color. + + + + + Font color. + + + + + Font style of matched text. + + + + + + + + + + + + + + + + Indicates whether to ignore case when comparing texts. + + + + + Regular expression to be matched. You must specify either text or regex. + + + + + Text to be matched. You must specify either text or regex. + + + + + Indicates whether to match whole words only. + + + + + Background color. Names are identical with KnownColor enum extended with Empty value which means that background color won't be changed. + + + + + Font color. Names are identical with KnownColor enum extended with Empty value which means that font color won't be changed. + + + + + Font style of matched text. Possible values are the same as in FontStyle enum in System.Drawing. + + + + + + + + + + + + Name of the target. + + + + + + + + + + + + + + Name of the target. + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Encoding. + + + + + Web service method name. + + + + + Web service namespace. + + + + + Protocol to be used when calling web service. + + + + + Web service URL. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Footer layout. + + + + + Header layout. + + + + + Body layout (can be repeated multiple times). + + + + + Custom column delimiter value (valid when ColumnDelimiter is set to 'Custom'). + + + + + Column delimiter. + + + + + Quote Character. + + + + + Quoting mode. + + + + + Indicates whether CVS should include header. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Layout of the column. + + + + + Name of the column. + + + + + + + + + + + + + + Footer layout. + + + + + Header layout. + + + + + Body layout (can be repeated multiple times). + + + + + + + + + + + + + + + + + + + + + Layout text. + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Condition expression. + + + + + + + + + + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Wox.Infrastructure/NLog.config b/Wox.Infrastructure/NLog.config new file mode 100644 index 0000000000..ec19a82787 --- /dev/null +++ b/Wox.Infrastructure/NLog.config @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Wox.Infrastructure/Properties/AssemblyInfo.cs b/Wox.Infrastructure/Properties/AssemblyInfo.cs index cc1640d88f..b40c421669 100644 --- a/Wox.Infrastructure/Properties/AssemblyInfo.cs +++ b/Wox.Infrastructure/Properties/AssemblyInfo.cs @@ -33,5 +33,4 @@ using System.Runtime.InteropServices; // 方法是按如下所示使用“*”: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] -[assembly: log4net.Config.XmlConfigurator(Watch = true)] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Wox.Infrastructure/Storage/BaseStorage.cs b/Wox.Infrastructure/Storage/BaseStorage.cs index d899cb6908..3db9bfee70 100644 --- a/Wox.Infrastructure/Storage/BaseStorage.cs +++ b/Wox.Infrastructure/Storage/BaseStorage.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Reflection; using System.Runtime.InteropServices.ComTypes; using System.Text; using System.Windows.Forms; @@ -10,18 +11,18 @@ using Newtonsoft.Json; namespace Wox.Infrastructure.Storage { [Serializable] - public abstract class BaseStorage : IStorage where T : class,IStorage,new() + public abstract class BaseStorage : IStorage where T : class,IStorage, new() { - private readonly string configFolder = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Config"); + protected abstract string ConfigFolder { get; } protected string ConfigPath { get { - return Path.Combine(configFolder, ConfigName + FileSuffix); + return Path.Combine(ConfigFolder, ConfigName + FileSuffix); } } - + protected abstract string FileSuffix { get; } protected abstract string ConfigName { get; } @@ -62,7 +63,7 @@ namespace Wox.Infrastructure.Storage /// protected virtual T LoadDefault() { - return serializedObject; + return new T(); } protected abstract void LoadInternal(); @@ -72,9 +73,9 @@ namespace Wox.Infrastructure.Storage { if (!File.Exists(ConfigPath)) { - if (!Directory.Exists(configFolder)) + if (!Directory.Exists(ConfigFolder)) { - Directory.CreateDirectory(configFolder); + Directory.CreateDirectory(ConfigFolder); } File.Create(ConfigPath).Close(); } diff --git a/Wox.Infrastructure/Storage/BinaryStorage.cs b/Wox.Infrastructure/Storage/BinaryStorage.cs index 39f1a43b7a..7561ba1149 100644 --- a/Wox.Infrastructure/Storage/BinaryStorage.cs +++ b/Wox.Infrastructure/Storage/BinaryStorage.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Reflection; +using System.Runtime.Serialization.Formatters; using System.Runtime.Serialization.Formatters.Binary; using System.Text; using Wox.Infrastructure.Logger; @@ -23,17 +25,64 @@ namespace Wox.Infrastructure.Storage protected override void LoadInternal() { + //http://stackoverflow.com/questions/2120055/binaryformatter-deserialize-gives-serializationexception + AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; try { - FileStream fileStream = new FileStream(ConfigPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - BinaryFormatter binaryFormatter = new BinaryFormatter(); - serializedObject = binaryFormatter.Deserialize(fileStream) as T; - fileStream.Close(); + using (FileStream fileStream = new FileStream(ConfigPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + if (fileStream.Length > 0) + { + BinaryFormatter binaryFormatter = new BinaryFormatter + { + AssemblyFormat = FormatterAssemblyStyle.Simple + }; + serializedObject = binaryFormatter.Deserialize(fileStream) as T; + if (serializedObject == null) + { + serializedObject = LoadDefault(); +#if (DEBUG) + { + throw new Exception("deserialize failed"); + } +#endif + } + } + else + { + serializedObject = LoadDefault(); + } + } } catch (Exception) { serializedObject = LoadDefault(); +#if (DEBUG) + { + throw; + } +#endif } + finally + { + AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve; + } + } + + private System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) + { + Assembly ayResult = null; + string sShortAssemblyName = args.Name.Split(',')[0]; + Assembly[] ayAssemblies = AppDomain.CurrentDomain.GetAssemblies(); + foreach (Assembly ayAssembly in ayAssemblies) + { + if (sShortAssemblyName == ayAssembly.FullName.Split(',')[0]) + { + ayResult = ayAssembly; + break; + } + } + return ayResult; } protected override void SaveInternal() @@ -41,18 +90,21 @@ namespace Wox.Infrastructure.Storage try { FileStream fileStream = new FileStream(ConfigPath, FileMode.Create); - BinaryFormatter binaryFormatter = new BinaryFormatter(); + BinaryFormatter binaryFormatter = new BinaryFormatter + { + AssemblyFormat = FormatterAssemblyStyle.Simple + }; binaryFormatter.Serialize(fileStream, serializedObject); fileStream.Close(); } catch (Exception e) { Log.Error(e.Message); - #if (DEBUG) - { - throw e; +#if (DEBUG) + { + throw; } - #endif +#endif } } } diff --git a/Wox.Infrastructure/Storage/JsonStrorage.cs b/Wox.Infrastructure/Storage/JsonStorage.cs similarity index 100% rename from Wox.Infrastructure/Storage/JsonStrorage.cs rename to Wox.Infrastructure/Storage/JsonStorage.cs diff --git a/Wox.Infrastructure/Timeit.cs b/Wox.Infrastructure/Timeit.cs index 5b020ac8c0..a29ea53ed8 100644 --- a/Wox.Infrastructure/Timeit.cs +++ b/Wox.Infrastructure/Timeit.cs @@ -20,7 +20,7 @@ namespace Wox.Infrastructure public void Dispose() { stopwatch.Stop(); - Debug.WriteLine(name + ":" + stopwatch.ElapsedMilliseconds + "ms"); + Debug.WriteLine(name + ":" + stopwatch.ElapsedMilliseconds + "ms","Wox"); } } } diff --git a/Wox.Infrastructure/WindowsShellRun.cs b/Wox.Infrastructure/WindowsShellRun.cs index f8ec456b4a..ba5d2673ab 100644 --- a/Wox.Infrastructure/WindowsShellRun.cs +++ b/Wox.Infrastructure/WindowsShellRun.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.IO; -using Wox.Infrastructure.Storage.UserSettings; namespace Wox.Infrastructure { @@ -78,7 +77,7 @@ namespace Wox.Infrastructure [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] static extern bool UrlIs(string pszUrl, int UrlIs); - static void ShellExecCmdLine(IntPtr hInstance, IntPtr hwnd, string command, string startDir, global::System.Diagnostics.ProcessWindowStyle nShow, ShellExecCmdLineFlags dwSeclFlags,bool runAsAdministrator = false) + static void ShellExecCmdLine(IntPtr hInstance, IntPtr hwnd, string command, string startDir, global::System.Diagnostics.ProcessWindowStyle nShow, ShellExecCmdLineFlags dwSeclFlags,bool runAsAdministrator = false,bool leaveCmdOpen = false) { string cmd = command; string args = null; @@ -103,7 +102,7 @@ namespace Wox.Infrastructure startDir = dir; } - if (UserSettingStorage.Instance.LeaveCmdOpen && File.Exists(cmd)) + if (leaveCmdOpen && File.Exists(cmd)) { bool needsCommandLine; diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index c50978f96d..ca13df96fb 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -13,6 +13,7 @@ 512 ..\ true + true @@ -23,6 +24,7 @@ prompt 4 true + false pdbonly @@ -32,16 +34,16 @@ prompt 4 false + false - - False - ..\packages\log4net.2.0.3\lib\net35-full\log4net.dll - False - ..\packages\Newtonsoft.Json.6.0.5\lib\net35\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll + + + ..\packages\NLog.3.2.0.0\lib\net35\NLog.dll @@ -56,45 +58,39 @@ - - - - + + - - - + - - - - - - - - - - {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} Wox.Plugin - + + + Always + + + Designer + + + - \ No newline at end of file diff --git a/Wox.Plugin.SystemPlugins/packages.config b/Wox.Plugin.SystemPlugins/packages.config deleted file mode 100644 index 5ada4eb8a9..0000000000 --- a/Wox.Plugin.SystemPlugins/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Wox.Plugin/EventHandler.cs b/Wox.Plugin/EventHandler.cs index 0fd8461deb..f3c6121f92 100644 --- a/Wox.Plugin/EventHandler.cs +++ b/Wox.Plugin/EventHandler.cs @@ -6,11 +6,26 @@ using System.Windows.Input; namespace Wox.Plugin { - public delegate void WoxKeyDownEventHandler(object sender, WoxKeyDownEventArgs e); + public delegate void WoxKeyDownEventHandler(WoxKeyDownEventArgs e); + public delegate void AfterWoxQueryEventHandler(WoxQueryEventArgs e); + + /// + /// Global keyboard events + /// + /// WM_KEYDOWN = 256,WM_KEYUP = 257,WM_SYSKEYUP = 261,WM_SYSKEYDOWN = 260 + /// + /// + /// return true to continue handling, return false to intercept system handling + public delegate bool WoxGlobalKeyboardEventHandler(int keyevent, int vkcode, SpecialKeyState state); public class WoxKeyDownEventArgs { public string Query { get; set; } public KeyEventArgs keyEventArgs { get; set; } } + + public class WoxQueryEventArgs + { + public Query Query { get; set; } + } } diff --git a/Wox.Plugin/IPluginI18n.cs b/Wox.Plugin/IPluginI18n.cs new file mode 100644 index 0000000000..cb13dd02bb --- /dev/null +++ b/Wox.Plugin/IPluginI18n.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace Wox.Plugin +{ + /// + /// Represent plugins that support internationalization + /// + public interface IPluginI18n + { + string GetLanguagesFolder(); + } +} diff --git a/Wox.Plugin/IPublicAPI.cs b/Wox.Plugin/IPublicAPI.cs index 64ff13ab08..40ce63ef53 100644 --- a/Wox.Plugin/IPublicAPI.cs +++ b/Wox.Plugin/IPublicAPI.cs @@ -4,35 +4,121 @@ using System.Windows.Documents; namespace Wox.Plugin { + /// + /// Public APIs that plugin can use + /// public interface IPublicAPI { + /// + /// Push result to query box + /// + /// + /// + /// + /// + void PushResults(Query query,PluginMetadata plugin, List results,bool clearBeforeInsert = false); - void PushResults(Query query,PluginMetadata plugin, List results); - + /// + /// Execute command + /// a replacement to RUN(win+r) function + /// + /// command that want to execute + /// run as administrator + /// bool ShellRun(string cmd, bool runAsAdministrator = false); + /// + /// Change Wox query + /// + /// query text + /// + /// force requery By default, Wox will not fire query if your query is same with existing one. + /// Set this to true to force Wox requerying + /// void ChangeQuery(string query, bool requery = false); + /// + /// Close Wox + /// void CloseApp(); + /// + /// Hide Wox + /// void HideApp(); + /// + /// Show Wox + /// void ShowApp(); + /// + /// Show message box + /// + /// Message title + /// Message subtitle + /// Message icon path (relative path to your plugin folder) void ShowMsg(string title, string subTitle, string iconPath); + /// + /// Open setting dialog + /// void OpenSettingDialog(); - + + /// + /// Show loading animation + /// void StartLoadingBar(); + /// + /// Stop loading animation + /// void StopLoadingBar(); + /// + /// Install Wox plugin + /// + /// Plugin path (ends with .wox) void InstallPlugin(string path); + /// + /// Reload all plugins + /// void ReloadPlugins(); + /// + /// Get translation of current language + /// You need to implement IPluginI18n if you want to support multiple languages for your plugin + /// + /// + /// + string GetTranslation(string key); + + /// + /// Get all loaded plugins + /// + /// List GetAllPlugins(); + /// + /// Fired after Back key down in the Wox query box + /// event WoxKeyDownEventHandler BackKeyDownEvent; + + /// + /// Fired after global keyboard events + /// if you want to hook something like Ctrl+R, you should use this event + /// + event WoxGlobalKeyboardEventHandler GlobalKeyboardEvent; + + /// + /// Fired after wox execute a query + /// + event AfterWoxQueryEventHandler AfterWoxQueryEvent; + + /// + /// Fired before wox start to execute a query + /// + event AfterWoxQueryEventHandler BeforeWoxQueryEvent; } } diff --git a/Wox.Plugin/PluginType.cs b/Wox.Plugin/PluginType.cs index a36cc50b27..b8ffc6e124 100644 --- a/Wox.Plugin/PluginType.cs +++ b/Wox.Plugin/PluginType.cs @@ -8,6 +8,6 @@ namespace Wox.Plugin public enum PluginType { System, - ThirdParty + User } -} +} \ No newline at end of file diff --git a/Wox.Plugin/README.md b/Wox.Plugin/README.md new file mode 100644 index 0000000000..1d5c7394da --- /dev/null +++ b/Wox.Plugin/README.md @@ -0,0 +1,5 @@ +What does Wox.Plugin do? +==== + +* Define base objects and interfaces for plugins +* Plugin Author who making C# plugin should reference this DLL via nuget \ No newline at end of file diff --git a/Wox.Plugin/Wox.Plugin.csproj b/Wox.Plugin/Wox.Plugin.csproj index abc3493ebb..8f7aa59418 100644 --- a/Wox.Plugin/Wox.Plugin.csproj +++ b/Wox.Plugin/Wox.Plugin.csproj @@ -47,6 +47,7 @@ + @@ -59,6 +60,9 @@ + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Wox.UAC/Properties/Settings.Designer.cs b/Wox.UAC/Properties/Settings.Designer.cs deleted file mode 100644 index 6dbc8f74b1..0000000000 --- a/Wox.UAC/Properties/Settings.Designer.cs +++ /dev/null @@ -1,30 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.18408 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Wox.UAC.Properties -{ - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { - return defaultInstance; - } - } - } -} diff --git a/Wox.UAC/Properties/Settings.settings b/Wox.UAC/Properties/Settings.settings deleted file mode 100644 index 033d7a5e9e..0000000000 --- a/Wox.UAC/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/Wox.UAC/app.ico b/Wox.UAC/app.ico deleted file mode 100644 index 8e914ac566..0000000000 Binary files a/Wox.UAC/app.ico and /dev/null differ diff --git a/Wox.UAC/app.manifest b/Wox.UAC/app.manifest deleted file mode 100644 index 4d02a83439..0000000000 --- a/Wox.UAC/app.manifest +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Wox.sln b/Wox.sln index 120076914c..cd2007ff85 100644 --- a/Wox.sln +++ b/Wox.sln @@ -7,16 +7,40 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Test", "Wox.Test\Wox.Te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin", "Wox.Plugin\Wox.Plugin.csproj", "{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugin", "Plugin", "{3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox", "Wox\Wox.csproj", "{DB90F671-D861-46BB-93A3-F1304F5BA1C5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.SystemPlugins", "Wox.Plugin.SystemPlugins\Wox.Plugin.SystemPlugins.csproj", "{69CE0206-CB41-453D-88AF-DF86092EF9B8}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Infrastructure", "Wox.Infrastructure\Wox.Infrastructure.csproj", "{4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.PluginManagement", "Plugins\Wox.Plugin.PluginManagement\Wox.Plugin.PluginManagement.csproj", "{049490F0-ECD2-4148-9B39-2135EC346EBE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Core", "Wox.Core\Wox.Core.csproj", "{B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Program", "Plugins\Wox.Plugin.Program\Wox.Plugin.Program.csproj", "{FDB3555B-58EF-4AE6-B5F1-904719637AB4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.CMD", "Plugins\Wox.Plugin.CMD\Wox.Plugin.CMD.csproj", "{C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.WebSearch", "Plugins\Wox.Plugin.WebSearch\Wox.Plugin.WebSearch.csproj", "{403B57F2-1856-4FC7-8A24-36AB346B763E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.ControlPanel", "Plugins\Wox.Plugin.ControlPanel\Wox.Plugin.ControlPanel.csproj", "{1EE20B48-82FB-48A2-8086-675D6DDAB4F0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Folder", "Plugins\Wox.Plugin.Folder\Wox.Plugin.Folder.csproj", "{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.PluginIndicator", "Plugins\Wox.Plugin.PluginIndicator\Wox.Plugin.PluginIndicator.csproj", "{FDED22C8-B637-42E8-824A-63B5B6E05A3A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Caculator", "Plugins\Wox.Plugin.Caculator\Wox.Plugin.Caculator.csproj", "{59BD9891-3837-438A-958D-ADC7F91F6F7E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Sys", "Plugins\Wox.Plugin.Sys\Wox.Plugin.Sys.csproj", "{0B9DE348-9361-4940-ADB6-F5953BFFCCEC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Url", "Plugins\Wox.Plugin.Url\Wox.Plugin.Url.csproj", "{A3DCCBCA-ACC1-421D-B16E-210896234C26}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Color", "Plugins\Wox.Plugin.Color\Wox.Plugin.Color.csproj", "{F35190AA-4758-4D9E-A193-E3BDF6AD3567}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.CrashReporter", "Wox.CrashReporter\Wox.CrashReporter.csproj", "{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.QueryHistory", "Plugins\Wox.Plugin.QueryHistory\Wox.Plugin.QueryHistory.csproj", "{B552DCB6-692E-4B1D-9E0B-9096A2A7E6B0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -35,10 +59,6 @@ Global {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Debug|Any CPU.Build.0 = Debug|Any CPU {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|Any CPU.ActiveCfg = Release|Any CPU {DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|Any CPU.Build.0 = Release|Any CPU - {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|Any CPU.Build.0 = Release|Any CPU {4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}.Debug|Any CPU.Build.0 = Debug|Any CPU {4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -47,11 +67,74 @@ Global {049490F0-ECD2-4148-9B39-2135EC346EBE}.Debug|Any CPU.Build.0 = Debug|Any CPU {049490F0-ECD2-4148-9B39-2135EC346EBE}.Release|Any CPU.ActiveCfg = Release|Any CPU {049490F0-ECD2-4148-9B39-2135EC346EBE}.Release|Any CPU.Build.0 = Release|Any CPU + {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}.Release|Any CPU.Build.0 = Release|Any CPU + {FDB3555B-58EF-4AE6-B5F1-904719637AB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDB3555B-58EF-4AE6-B5F1-904719637AB4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDB3555B-58EF-4AE6-B5F1-904719637AB4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDB3555B-58EF-4AE6-B5F1-904719637AB4}.Release|Any CPU.Build.0 = Release|Any CPU + {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0}.Release|Any CPU.Build.0 = Release|Any CPU + {403B57F2-1856-4FC7-8A24-36AB346B763E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {403B57F2-1856-4FC7-8A24-36AB346B763E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {403B57F2-1856-4FC7-8A24-36AB346B763E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {403B57F2-1856-4FC7-8A24-36AB346B763E}.Release|Any CPU.Build.0 = Release|Any CPU + {1EE20B48-82FB-48A2-8086-675D6DDAB4F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1EE20B48-82FB-48A2-8086-675D6DDAB4F0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1EE20B48-82FB-48A2-8086-675D6DDAB4F0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1EE20B48-82FB-48A2-8086-675D6DDAB4F0}.Release|Any CPU.Build.0 = Release|Any CPU + {787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Release|Any CPU.Build.0 = Release|Any CPU + {FDED22C8-B637-42E8-824A-63B5B6E05A3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDED22C8-B637-42E8-824A-63B5B6E05A3A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDED22C8-B637-42E8-824A-63B5B6E05A3A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDED22C8-B637-42E8-824A-63B5B6E05A3A}.Release|Any CPU.Build.0 = Release|Any CPU + {59BD9891-3837-438A-958D-ADC7F91F6F7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {59BD9891-3837-438A-958D-ADC7F91F6F7E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {59BD9891-3837-438A-958D-ADC7F91F6F7E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {59BD9891-3837-438A-958D-ADC7F91F6F7E}.Release|Any CPU.Build.0 = Release|Any CPU + {0B9DE348-9361-4940-ADB6-F5953BFFCCEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0B9DE348-9361-4940-ADB6-F5953BFFCCEC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0B9DE348-9361-4940-ADB6-F5953BFFCCEC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0B9DE348-9361-4940-ADB6-F5953BFFCCEC}.Release|Any CPU.Build.0 = Release|Any CPU + {A3DCCBCA-ACC1-421D-B16E-210896234C26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3DCCBCA-ACC1-421D-B16E-210896234C26}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3DCCBCA-ACC1-421D-B16E-210896234C26}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3DCCBCA-ACC1-421D-B16E-210896234C26}.Release|Any CPU.Build.0 = Release|Any CPU + {F35190AA-4758-4D9E-A193-E3BDF6AD3567}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F35190AA-4758-4D9E-A193-E3BDF6AD3567}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F35190AA-4758-4D9E-A193-E3BDF6AD3567}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F35190AA-4758-4D9E-A193-E3BDF6AD3567}.Release|Any CPU.Build.0 = Release|Any CPU + {2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Release|Any CPU.Build.0 = Release|Any CPU + {B552DCB6-692E-4B1D-9E0B-9096A2A7E6B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B552DCB6-692E-4B1D-9E0B-9096A2A7E6B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B552DCB6-692E-4B1D-9E0B-9096A2A7E6B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B552DCB6-692E-4B1D-9E0B-9096A2A7E6B0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {049490F0-ECD2-4148-9B39-2135EC346EBE} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87} + {FDB3555B-58EF-4AE6-B5F1-904719637AB4} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87} + {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87} + {403B57F2-1856-4FC7-8A24-36AB346B763E} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87} + {1EE20B48-82FB-48A2-8086-675D6DDAB4F0} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87} + {787B8AA6-CA93-4C84-96FE-DF31110AD1C4} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87} + {FDED22C8-B637-42E8-824A-63B5B6E05A3A} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87} + {59BD9891-3837-438A-958D-ADC7F91F6F7E} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87} + {0B9DE348-9361-4940-ADB6-F5953BFFCCEC} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87} + {A3DCCBCA-ACC1-421D-B16E-210896234C26} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87} + {F35190AA-4758-4D9E-A193-E3BDF6AD3567} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87} + {B552DCB6-692E-4B1D-9E0B-9096A2A7E6B0} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87} EndGlobalSection EndGlobal diff --git a/Wox/ActionKeyword.xaml b/Wox/ActionKeyword.xaml index 20288b6d15..27ed9ad171 100644 --- a/Wox/ActionKeyword.xaml +++ b/Wox/ActionKeyword.xaml @@ -17,18 +17,18 @@ - Old ActionKeyword: + Old ActionKeyword: - New ActionKeyword: + - + diff --git a/Wox/ActionKeyword.xaml.cs b/Wox/ActionKeyword.xaml.cs index a2a1037434..e6832be527 100644 --- a/Wox/ActionKeyword.xaml.cs +++ b/Wox/ActionKeyword.xaml.cs @@ -11,9 +11,10 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; -using Wox.Infrastructure.Storage.UserSettings; +using Wox.Core.i18n; +using Wox.Core.Plugin; +using Wox.Core.UserSettings; using Wox.Plugin; -using Wox.PluginLoader; using MessageBox = System.Windows.MessageBox; namespace Wox @@ -25,10 +26,10 @@ namespace Wox public ActionKeyword(string pluginId) { InitializeComponent(); - PluginPair plugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ID == pluginId); + PluginPair plugin = PluginManager.GetPlugin(pluginId); if (plugin == null) { - MessageBox.Show("Can't find specific plugin"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("cannotFindSpecifiedPlugin")); Close(); return; } @@ -51,14 +52,14 @@ namespace Wox { if (string.IsNullOrEmpty(tbAction.Text)) { - MessageBox.Show("New ActionKeyword can't be empty"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("newActionKeywordCannotBeEmpty")); return; } //check new action keyword didn't used by other plugin - if (Plugins.AllPlugins.Exists(o => o.Metadata.ActionKeyword == tbAction.Text.Trim())) + if (PluginManager.AllPlugins.Exists(o => o.Metadata.ActionKeyword == tbAction.Text.Trim())) { - MessageBox.Show("New ActionKeyword has been assigned to other plugin, please assign another new action keyword"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("newActionKeywordHasBeenAssigned")); return; } @@ -80,10 +81,8 @@ namespace Wox customizedPluginConfig.Actionword = tbAction.Text.Trim(); } UserSettingStorage.Instance.Save(); - MessageBox.Show("Sucessfully applied the new action keyword"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("succeed")); Close(); } - - } } diff --git a/Wox/App.config b/Wox/App.config index 092ef1ab88..af328919aa 100644 --- a/Wox/App.config +++ b/Wox/App.config @@ -1,33 +1,12 @@ - -
- - - - - - - - - - - - - - - - - - - - + + + + + - - - - diff --git a/Wox/App.xaml b/Wox/App.xaml index f02f489f06..449be94262 100644 --- a/Wox/App.xaml +++ b/Wox/App.xaml @@ -4,6 +4,10 @@ > + + + + - + \ No newline at end of file diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 8b4f9af495..d1b7f5f69b 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Threading; using Wox.CommandArgs; using Wox.Helper; -using Wox.Helper.ErrorReporting; using Application = System.Windows.Application; using MessageBox = System.Windows.MessageBox; using StartupEventArgs = System.Windows.StartupEventArgs; @@ -34,7 +33,6 @@ namespace Wox base.OnStartup(e); DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle; - System.Windows.Forms.Application.ThreadException += ErrorReporting.ThreadException; Window = new MainWindow(); CommandArgsFactory.Execute(e.Args.ToList()); diff --git a/Wox/CommandArgs/InstallPluginCommandArg.cs b/Wox/CommandArgs/InstallPluginCommandArg.cs index 2c921008f3..e69d20a633 100644 --- a/Wox/CommandArgs/InstallPluginCommandArg.cs +++ b/Wox/CommandArgs/InstallPluginCommandArg.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; using System.Windows; +using Wox.Core.Plugin; using Wox.Helper; namespace Wox.CommandArgs @@ -25,7 +26,7 @@ namespace Wox.CommandArgs MessageBox.Show("Plugin " + path + " didn't exist"); return; } - PluginInstaller.Install(path); + PluginManager.InstallPlugin(path); } } } diff --git a/Wox/CommandArgs/PluginDebuggerCommandArg.cs b/Wox/CommandArgs/PluginDebuggerCommandArg.cs index dadf639f9f..dab93500f8 100644 --- a/Wox/CommandArgs/PluginDebuggerCommandArg.cs +++ b/Wox/CommandArgs/PluginDebuggerCommandArg.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Input; +using Wox.Core.Plugin; namespace Wox.CommandArgs { @@ -18,7 +19,7 @@ namespace Wox.CommandArgs if (args.Count > 0) { var pluginFolderPath = args[0]; - PluginLoader.Plugins.ActivatePluginDebugger(pluginFolderPath); + PluginManager.ActivatePluginDebugger(pluginFolderPath); } } } diff --git a/Wox/CommandArgs/ReloadPluginCommandArg.cs b/Wox/CommandArgs/ReloadPluginCommandArg.cs index ccc1a25db5..f287e08c85 100644 --- a/Wox/CommandArgs/ReloadPluginCommandArg.cs +++ b/Wox/CommandArgs/ReloadPluginCommandArg.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using Wox.PluginLoader; +using Wox.Core.Plugin; namespace Wox.CommandArgs { @@ -15,7 +15,7 @@ namespace Wox.CommandArgs public void Execute(IList args) { - Plugins.Init(); + PluginManager.Init(App.Window); } } } diff --git a/Wox/Commands/BaseCommand.cs b/Wox/Commands/BaseCommand.cs deleted file mode 100644 index 8a5283e77a..0000000000 --- a/Wox/Commands/BaseCommand.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Wox.Plugin; - -namespace Wox.Commands -{ - public abstract class BaseCommand - { - public abstract void Dispatch(Query query); - - protected void UpdateResultView(List results) - { - App.Window.OnUpdateResultView(results); - } - } -} diff --git a/Wox/Commands/CommandFactory.cs b/Wox/Commands/CommandFactory.cs deleted file mode 100644 index fc18439b46..0000000000 --- a/Wox/Commands/CommandFactory.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Wox.Helper; -using Wox.Plugin; -using Wox.PluginLoader; - -namespace Wox.Commands -{ - internal static class CommandFactory - { - private static PluginCommand pluginCmd = new PluginCommand(); - private static SystemCommand systemCmd = new SystemCommand(); - - public static void DispatchCommand(Query query) - { - if (Plugins.HitThirdpartyKeyword(query)) - { - pluginCmd.Dispatch(query); - } - else - { - systemCmd.Dispatch(query); - } - } - } -} diff --git a/Wox/Commands/PluginCommand.cs b/Wox/Commands/PluginCommand.cs deleted file mode 100644 index 34707e9daa..0000000000 --- a/Wox/Commands/PluginCommand.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using Wox.Helper; -using Wox.Infrastructure.Logger; -using Wox.Infrastructure.Storage.UserSettings; -using Wox.Plugin; -using Wox.PluginLoader; - -namespace Wox.Commands -{ - public class PluginCommand : BaseCommand - { - public override void Dispatch(Query query) - { - PluginPair thirdPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionName); - if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword)) - { - var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == thirdPlugin.Metadata.ID); - if (customizedPluginConfig != null && customizedPluginConfig.Disabled) - { - //need to stop the loading animation - UpdateResultView(null); - return; - } - - ThreadPool.QueueUserWorkItem(t => - { - try - { - List results = thirdPlugin.Plugin.Query(query) ?? new List(); - App.Window.PushResults(query,thirdPlugin.Metadata,results); - } - catch (Exception queryException) - { - Log.Error(string.Format("Plugin {0} query failed: {1}", thirdPlugin.Metadata.Name, - queryException.Message)); -#if (DEBUG) - { - throw; - } -#endif - } - }); - } - } - } -} diff --git a/Wox/Commands/SystemCommand.cs b/Wox/Commands/SystemCommand.cs deleted file mode 100644 index a1fc477a82..0000000000 --- a/Wox/Commands/SystemCommand.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using Wox.Infrastructure.Storage.UserSettings; -using Wox.Plugin; -using Wox.Plugin.SystemPlugins; -using Wox.PluginLoader; - -namespace Wox.Commands -{ - public class SystemCommand : BaseCommand - { - private IEnumerable allSytemPlugins = Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System); - - public override void Dispatch(Query query) - { - var queryPlugins = allSytemPlugins; - if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == query.ActionName && o.Enabled)) - { - //websearch mode - queryPlugins = new List() - { - allSytemPlugins.First(o => ((ISystemPlugin)o.Plugin).ID == "565B73353DBF4806919830B9202EE3BF") - }; - } - - foreach (PluginPair pair in queryPlugins) - { - PluginPair pair1 = pair; - ThreadPool.QueueUserWorkItem(state => - { - List results = pair1.Plugin.Query(query); - results.ForEach(o => { o.AutoAjustScore = true; }); - - App.Window.PushResults(query, pair1.Metadata, results); - }); - } - } - } -} diff --git a/Wox/Converters/AsyncConverter.cs b/Wox/Converters/AsyncConverter.cs deleted file mode 100644 index 5df3bc7b5f..0000000000 --- a/Wox/Converters/AsyncConverter.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.ComponentModel; -using System.Threading; -using System.Windows.Data; -using System.Windows.Threading; - -namespace Wox.Converters -{ - public class AsyncTask : INotifyPropertyChanged - { - public AsyncTask(Func valueFunc) - { - LoadValue(valueFunc); - } - - private void LoadValue(Func valueFunc) - { - var frame = new DispatcherFrame(); - ThreadPool.QueueUserWorkItem(delegate - { - - object returnValue = - AsyncValue = valueFunc(); - if (PropertyChanged != null) - PropertyChanged(this, new PropertyChangedEventArgs("AsyncValue")); - - }); - } - - public event PropertyChangedEventHandler PropertyChanged; - - public object AsyncValue - { - get; - set; - } - } -} diff --git a/Wox/Converters/OpacityModeConverter.cs b/Wox/Converters/OpacityModeConverter.cs index 356bb5be7f..7eb94de814 100644 --- a/Wox/Converters/OpacityModeConverter.cs +++ b/Wox/Converters/OpacityModeConverter.cs @@ -1,6 +1,6 @@ using System; using System.Globalization; -using Wox.Infrastructure.Storage.UserSettings; +using Wox.Core.UserSettings; namespace Wox.Converters { diff --git a/Wox/CustomPluginHotkeySetting.xaml b/Wox/CustomQueryHotkeySetting.xaml similarity index 79% rename from Wox/CustomPluginHotkeySetting.xaml rename to Wox/CustomQueryHotkeySetting.xaml index ac3bc9f632..fc714d1b0d 100644 --- a/Wox/CustomPluginHotkeySetting.xaml +++ b/Wox/CustomQueryHotkeySetting.xaml @@ -1,4 +1,4 @@ - - Hotkey: + - Action Keyword: + - + - + diff --git a/Wox/CustomPluginHotkeySetting.xaml.cs b/Wox/CustomQueryHotkeySetting.xaml.cs similarity index 78% rename from Wox/CustomPluginHotkeySetting.xaml.cs rename to Wox/CustomQueryHotkeySetting.xaml.cs index 3cdb33dc8a..2c9bba0c1d 100644 --- a/Wox/CustomPluginHotkeySetting.xaml.cs +++ b/Wox/CustomQueryHotkeySetting.xaml.cs @@ -1,17 +1,18 @@ using System.Collections.Generic; using System.Linq; using System.Windows; -using Wox.Infrastructure.Storage.UserSettings; +using Wox.Core.i18n; +using Wox.Core.UserSettings; namespace Wox { - public partial class CustomPluginHotkeySetting : Window + public partial class CustomQueryHotkeySetting : Window { private SettingWindow settingWidow; private bool update; private CustomPluginHotkey updateCustomHotkey; - public CustomPluginHotkeySetting(SettingWindow settingWidow) + public CustomQueryHotkeySetting(SettingWindow settingWidow) { this.settingWidow = settingWidow; InitializeComponent(); @@ -28,7 +29,7 @@ namespace Wox { if (!ctlHotkey.CurrentHotkeyAvailable) { - MessageBox.Show("Hotkey is unavailable, please select a new hotkey"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("hotkeyIsNotUnavailable")); return; } @@ -48,13 +49,13 @@ namespace Wox settingWidow.MainWindow.ChangeQuery(pluginHotkey.ActionKeyword); settingWidow.MainWindow.ShowApp(); }); - MessageBox.Show("Add hotkey successfully!"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("succeed")); } else { if (updateCustomHotkey.Hotkey != ctlHotkey.CurrentHotkey.ToString() && !ctlHotkey.CurrentHotkeyAvailable) { - MessageBox.Show("Hotkey is unavailable, please select a new hotkey"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("hotkeyIsNotUnavailable")); return; } var oldHotkey = updateCustomHotkey.Hotkey; @@ -67,7 +68,7 @@ namespace Wox settingWidow.MainWindow.ShowApp(); settingWidow.MainWindow.ChangeQuery(updateCustomHotkey.ActionKeyword); }); - MessageBox.Show("Update successfully!"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("succeed")); } UserSettingStorage.Instance.Save(); @@ -80,7 +81,7 @@ namespace Wox updateCustomHotkey = UserSettingStorage.Instance.CustomPluginHotkeys.FirstOrDefault(o => o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey); if (updateCustomHotkey == null) { - MessageBox.Show("Invalid plugin hotkey"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("invalidPluginHotkey")); Close(); return; } @@ -88,7 +89,7 @@ namespace Wox tbAction.Text = updateCustomHotkey.ActionKeyword; ctlHotkey.SetHotkey(updateCustomHotkey.Hotkey, false); update = true; - lblAdd.Text = "Update"; + lblAdd.Text = InternationalizationManager.Internationalization.GetTranslation("update"); } private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e) diff --git a/Wox/Helper/ErrorReporting.cs b/Wox/Helper/ErrorReporting.cs new file mode 100644 index 0000000000..cff796318f --- /dev/null +++ b/Wox/Helper/ErrorReporting.cs @@ -0,0 +1,42 @@ +using System; +using System.Diagnostics; +using System.Windows; +using System.Windows.Forms; +using System.Windows.Threading; +using Wox.Core.Exception; +using Wox.Infrastructure.Logger; +using MessageBox = System.Windows.MessageBox; + +namespace Wox.Helper +{ + public static class ErrorReporting + { + public static void Report(Exception e) + { + if (Debugger.IsAttached) return; + Log.Error(ExceptionFormatter.FormatExcpetion(e)); + new CrashReporter.CrashReporter(e).Show(); + } + + public static void UnhandledExceptionHandle(object sender, UnhandledExceptionEventArgs e) + { + //handle non-ui thread exceptions + App.Window.Dispatcher.Invoke(new Action(() => + { + Report((Exception)e.ExceptionObject); + if (!(e.ExceptionObject is WoxException)) + { + Environment.Exit(0); + } + })); + } + + public static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) + { + //handle ui thread exceptions + Report(e.Exception); + //prevent crash + e.Handled = true; + } + } +} diff --git a/Wox/Helper/ErrorReporting/WPFErrorReportingDialog.xaml b/Wox/Helper/ErrorReporting/WPFErrorReportingDialog.xaml deleted file mode 100644 index 54d0f04bd9..0000000000 --- a/Wox/Helper/ErrorReporting/WPFErrorReportingDialog.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/Wox/Helper/ErrorReporting/WPFErrorReportingDialog.xaml.cs b/Wox/Helper/ErrorReporting/WPFErrorReportingDialog.xaml.cs deleted file mode 100644 index f16669bd36..0000000000 --- a/Wox/Helper/ErrorReporting/WPFErrorReportingDialog.xaml.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; - -namespace Wox.Helper.ErrorReporting -{ - /// - /// Interaction logic for WPFErrorReportingDialog.xaml - /// - public partial class WPFErrorReportingDialog : Window - { - private object exceptionObject; - - public WPFErrorReportingDialog(string error, string title, object exceptionObject) - { - InitializeComponent(); - - this.tbErrorReport.Text = error; - this.Title = title; - this.exceptionObject = exceptionObject; - } - } -} diff --git a/Wox/Helper/WoxLog4netPathConverter.cs b/Wox/Helper/WoxLog4netPathConverter.cs new file mode 100644 index 0000000000..98cd176206 --- /dev/null +++ b/Wox/Helper/WoxLog4netPathConverter.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace Wox.Helper +{ + public class WoxLog4netPathConverter : log4net.Util.PatternConverter + { + protected override void Convert(TextWriter writer, object state) + { + string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE"); + writer.Write(Path.Combine(userProfilePath, ".Wox")); + } + } +} diff --git a/Wox/HotkeyControl.xaml.cs b/Wox/HotkeyControl.xaml.cs index 83b3bb3bea..1725f64019 100644 --- a/Wox/HotkeyControl.xaml.cs +++ b/Wox/HotkeyControl.xaml.cs @@ -6,6 +6,7 @@ using System.Windows.Input; using System.Windows.Media; using NHotkey; using NHotkey.Wpf; +using Wox.Core.i18n; using Wox.Helper; using Wox.Infrastructure; using Wox.Infrastructure.Hotkey; @@ -42,7 +43,7 @@ namespace Wox Key key = (e.Key == Key.System ? e.SystemKey : e.Key); string text = string.Empty; - SpecialKeyState specialKeyState = new GlobalHotkey().CheckModifiers(); + SpecialKeyState specialKeyState = GlobalHotkey.Instance.CheckModifiers(); if (specialKeyState.AltPressed) { text += "Alt"; @@ -98,12 +99,12 @@ namespace Wox if (!CurrentHotkeyAvailable) { tbMsg.Foreground = new SolidColorBrush(Colors.Red); - tbMsg.Text = "hotkey unavailable"; + tbMsg.Text = InternationalizationManager.Internationalization.GetTranslation("hotkeyUnavailable"); } else { tbMsg.Foreground = new SolidColorBrush(Colors.Green); - tbMsg.Text = "succeed"; + tbMsg.Text = InternationalizationManager.Internationalization.GetTranslation("succeed"); } OnOnHotkeyChanged(); } diff --git a/Wox/ImageLoader/ImageCacheStroage.cs b/Wox/ImageLoader/ImageCacheStroage.cs index 88526e3e45..a545e891ac 100644 --- a/Wox/ImageLoader/ImageCacheStroage.cs +++ b/Wox/ImageLoader/ImageCacheStroage.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using Wox.Infrastructure.Storage; @@ -9,10 +10,23 @@ namespace Wox.ImageLoader [Serializable] public class ImageCacheStroage : BinaryStorage { - public int counter = 0; - public const int maxCached = 200; + private int counter = 0; + private const int maxCached = 200; public Dictionary TopUsedImages = new Dictionary(); + protected override string ConfigFolder + { + get + { + string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE"); + if (userProfilePath == null) + { + throw new ArgumentException("Environment variable USERPROFILE is empty"); + } + return Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Config"); + } + } + protected override string ConfigName { get { return "ImageCache"; } diff --git a/Wox/ImageLoader/ImageLoader.cs b/Wox/ImageLoader/ImageLoader.cs index eb9d002665..e0f87147e6 100644 --- a/Wox/ImageLoader/ImageLoader.cs +++ b/Wox/ImageLoader/ImageLoader.cs @@ -13,7 +13,6 @@ namespace Wox.ImageLoader public class ImageLoader { private static readonly Dictionary imageCache = new Dictionary(); - private static object locker = new object(); private static readonly List imageExts = new List { @@ -38,19 +37,17 @@ namespace Wox.ImageLoader private static ImageSource GetIcon(string fileName) { - if (System.IO.File.Exists(fileName) == false) + try { - return null; - } - - Icon icon = GetFileIcon(fileName); - if (icon == null) icon = Icon.ExtractAssociatedIcon(fileName); - - if (icon != null) - { - return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(icon.Handle, - new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions()); + if (File.Exists(fileName) == false) return null; + Icon icon = GetFileIcon(fileName) ?? Icon.ExtractAssociatedIcon(fileName); + if (icon != null) + { + return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(icon.Handle, + new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions()); + } } + catch{} return null; } @@ -59,23 +56,20 @@ namespace Wox.ImageLoader { //ImageCacheStroage.Instance.TopUsedImages can be changed during foreach, so we need to make a copy var imageList = new Dictionary(ImageCacheStroage.Instance.TopUsedImages); - using (new Timeit(string.Format("Preload {0} images",imageList.Count))) + using (new Timeit(string.Format("Preload {0} images", imageList.Count))) { foreach (var image in imageList) { - ImageSource img = Load(image.Key, false); - if (img != null) + if (!imageCache.ContainsKey(image.Key)) { - img.Freeze(); //to make it copy to UI thread - if (!imageCache.ContainsKey(image.Key)) + ImageSource img = Load(image.Key, false); + if (img != null) { - lock (locker) + img.Freeze(); //to make it copy to UI thread + if (!imageCache.ContainsKey(image.Key)) { - if (!imageCache.ContainsKey(image.Key)) - { - KeyValuePair copyedImg = image; - App.Window.Dispatcher.Invoke(new Action(() => imageCache.Add(copyedImg.Key, img))); - } + KeyValuePair copyedImg = image; + App.Window.Dispatcher.Invoke(new Action(() => imageCache.Add(copyedImg.Key, img))); } } } @@ -83,7 +77,7 @@ namespace Wox.ImageLoader } } - public static ImageSource Load(string path,bool addToCache = true) + public static ImageSource Load(string path, bool addToCache = true) { if (string.IsNullOrEmpty(path)) return null; if (addToCache) @@ -103,7 +97,7 @@ namespace Wox.ImageLoader { img = new BitmapImage(new Uri(path)); } - else if (selfExts.Contains(ext)) + else if (selfExts.Contains(ext) && File.Exists(path)) { img = GetIcon(path); } @@ -117,13 +111,7 @@ namespace Wox.ImageLoader { if (!imageCache.ContainsKey(path)) { - lock (locker) - { - if (!imageCache.ContainsKey(path)) - { - imageCache.Add(path, img); - } - } + imageCache.Add(path, img); } } diff --git a/Wox/Languages/en.xaml b/Wox/Languages/en.xaml new file mode 100644 index 0000000000..4f1561034b --- /dev/null +++ b/Wox/Languages/en.xaml @@ -0,0 +1,101 @@ + + + Register hotkey: {0} failed + Could not start {0} + Invalid wox plugin file format + + + + General + Start Wox on system startup + Hide Wox when loses focus + Don't show upgrade msg if new version available + Language + + + Plugin + Browse more plugins + Disable + Action keyword + Plugin Directory + Author + + + Theme + Browse more themes + Hello Wox + Query Box Font + Result Item Font + Window Mode + Opacity + + + Hotkey + Wox Hotkey + Custom Query Hotkey + Delete + Edit + Add + Please select an item + Are your sure to delete {0} plugin hotkey? + + + Proxy + Enable Proxy + Server + Port + User Name + Password + Test Proxy + Save + Server can't be empty + Server port can't be empty + Invalid port format + Save proxy successfully + Proxy is correct + Proxy connect failed + + + About + Website + Version + + + Old Action Keyword + New Action Keyword + Cancel + Done + Can't find specified plugin + New Action Keyword can't be empty + New ActionKeyword has been assigned to other plugin, please assign another new action keyword + Succeed + + + Preview + Hotkey is unavailable, please select a new hotkey + Invalid plugin hotkey + Update + + + Hotkey unavailable + + + + Version + Time + Please tell us how application crashed so we can fix it + Send Report + Cancel + General + Exceptions + Exception Type + Source + Stack Trace + Sending + Report succeed + Report failed + Wox got an error + + \ No newline at end of file diff --git a/Wox/Languages/zh-cn.xaml b/Wox/Languages/zh-cn.xaml new file mode 100644 index 0000000000..5e06761f1c --- /dev/null +++ b/Wox/Languages/zh-cn.xaml @@ -0,0 +1,100 @@ + + + 注册热键:{0} 失败 + 启动命令 {0} 失败 + 不是合法的Wox插件格式 + + + + 通用 + 开机启动 + 失去焦点时自动隐藏Wox + 不显示新版本提示 + 语言 + + + 插件 + 浏览更多插件 + 禁用 + 触发关键字 + 插件目录 + 作者 + + + 主题 + 浏览更多主题 + 你好,Wox + 查询框字体 + 结果项字体 + 窗口模式 + 透明度 + + + 热键 + Wox激活热键 + 自定义查询热键 + 删除 + 编辑 + 增加 + 请选择一项 + 你确定要删除插件 {0} 的热键吗? + + + 代理 + 启用代理 + 服务器 + 端口 + 用户名 + 密码 + 测试代理 + 保存 + 服务器不能为空 + 端口不能为空 + 非法的端口格式 + 保存代理设置成功 + 代理设置正确 + 代理连接失败 + + + 关于 + 网站 + 版本 + + + + 旧触发关键字 + 新触发关键字 + 取消 + 确定 + 找不到指定的插件 + 新触发关键字不能为空 + 新触发关键字已经被指派给其他插件了,请重新选择一个关键字 + 成功 + + + 预览 + 热键不可用,请选择一个新的热键 + 插件热键不合法 + 更新 + + + 热键不可用 + + + 版本 + 时间 + 请告诉我们如何重现此问题,以便我们进行修复 + 发送报告 + 取消 + 基本信息 + 异常信息 + 异常类型 + 异常源 + 堆栈信息 + 发送中 + 发送成功 + 发送失败 + Wox出错啦 + \ No newline at end of file diff --git a/Wox/Languages/zh-tw.xaml b/Wox/Languages/zh-tw.xaml new file mode 100644 index 0000000000..d3c8812995 --- /dev/null +++ b/Wox/Languages/zh-tw.xaml @@ -0,0 +1,101 @@ + + + 註冊熱鍵:{0} 失敗 + 啟動命令 {0} 失敗 + 不是合法的Wox插件格式 + + + + 通用 + 開機啟動 + 失去焦點時自動隱藏Wox + 不顯示新版本提示 + 語言 + + + 插件 + 瀏覽更多插件 + 禁用 + 觸發關鍵字 + 插件目錄 + 作者 + + + 主題 + 瀏覽更多主題 + 你好,Wox + 查詢框字體 + 結果項字體 + 窗口模式 + 透明度 + + + 熱鍵 + Wox激活熱鍵 + 自定義查詢熱鍵 + 刪除 + 編輯 + 增加 + 請選擇一項 + 你確定要刪除插件 {0} 的熱鍵嗎? + + + 代理 + 啟用代理 + 服務器 + 端口 + 用戶名 + 密碼 + 測試代理 + 保存 + 服務器不能為空 + 端口不能為空 + 非法的端口格式 + 保存代理設置成功 + 代理設置正確 + 代理連接失敗 + + + 關於 + 網站 + 版本 + + + + 舊觸發關鍵字 + 新觸發關鍵字 + 取消 + 確定 + 找不到指定的插件 + 新觸發關鍵字不能為空 + 新觸發關鍵字已經被指派給其他插件了,請重新選擇一個關鍵字 + 成功 + + + 預覽 + 熱鍵不可用,請選擇一個新的熱鍵 + 插件熱鍵不合法 + 更新 + + + 熱鍵不可用 + + + 版本 + 時間 + 請告訴我們如何重現此問題,以便我們進行修復 + 發送報告 + 取消 + 基本信息 + 異常信息 + 異常類型 + 異常源 + 堆棧信息 + 發送中 + 發送成功 + 發送失敗 + Wox出錯啦 + + \ No newline at end of file diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 27b395354d..7a4cd03db1 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; -using System.IO; +using System.Drawing; using System.Linq; +using System.Net; using System.Threading; using System.Windows; using System.Windows.Controls; @@ -10,34 +12,29 @@ using System.Windows.Forms; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media.Animation; -using WindowsInput; -using WindowsInput.Native; using NHotkey; using NHotkey.Wpf; -using Wox.Commands; +using Wox.Core.i18n; +using Wox.Core.Plugin; +using Wox.Core.Theme; +using Wox.Core.Updater; +using Wox.Core.UserSettings; using Wox.Helper; -using Wox.ImageLoader; using Wox.Infrastructure; using Wox.Infrastructure.Hotkey; -using Wox.Infrastructure.Storage; -using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; -using Wox.PluginLoader; +using Wox.Storage; using Wox.Update; -using Application = System.Windows.Application; using Brushes = System.Windows.Media.Brushes; using Color = System.Windows.Media.Color; using ContextMenu = System.Windows.Forms.ContextMenu; +using DataFormats = System.Windows.DataFormats; using DragEventArgs = System.Windows.DragEventArgs; -using FontFamily = System.Windows.Media.FontFamily; using KeyEventArgs = System.Windows.Input.KeyEventArgs; using MenuItem = System.Windows.Forms.MenuItem; using MessageBox = System.Windows.MessageBox; -using MouseButton = System.Windows.Input.MouseButton; -using Path = System.IO.Path; -using Rectangle = System.Drawing.Rectangle; -using TextBox = System.Windows.Controls.TextBox; using ToolTip = System.Windows.Controls.ToolTip; +using Wox.Infrastructure.Logger; namespace Wox { @@ -46,20 +43,14 @@ namespace Wox #region Properties - private static readonly object locker = new object(); - public static bool initialized = false; - - private static readonly List waitShowResultList = new List(); - private readonly GlobalHotkey globalHotkey = new GlobalHotkey(); - private readonly KeyboardSimulator keyboardSimulator = new KeyboardSimulator(new InputSimulator()); private readonly Storyboard progressBarStoryboard = new Storyboard(); - private bool WinRStroked; private NotifyIcon notifyIcon; private bool queryHasReturn; private string lastQuery; private ToolTip toolTip = new ToolTip(); private bool ignoreTextChange = false; + #endregion #region Public API @@ -123,22 +114,30 @@ namespace Wox public void InstallPlugin(string path) { - Dispatcher.Invoke(new Action(() => PluginInstaller.Install(path))); + Dispatcher.Invoke(new Action(() => PluginManager.InstallPlugin(path))); } public void ReloadPlugins() { - Dispatcher.Invoke(new Action(Plugins.Init)); + Dispatcher.Invoke(new Action(() => PluginManager.Init(this))); + } + + public string GetTranslation(string key) + { + return InternationalizationManager.Internationalization.GetTranslation(key); } public List GetAllPlugins() { - return Plugins.AllPlugins; + return PluginManager.AllPlugins; } public event WoxKeyDownEventHandler BackKeyDownEvent; + public event WoxGlobalKeyboardEventHandler GlobalKeyboardEvent; + public event AfterWoxQueryEventHandler AfterWoxQueryEvent; + public event AfterWoxQueryEventHandler BeforeWoxQueryEvent; - public void PushResults(Query query, PluginMetadata plugin, List results) + public void PushResults(Query query, PluginMetadata plugin, List results, bool clearBeforeInsert = false) { results.ForEach(o => { @@ -152,7 +151,7 @@ namespace Wox } o.OriginQuery = query; }); - OnUpdateResultView(results); + OnUpdateResultView(results, clearBeforeInsert); } #endregion @@ -160,47 +159,50 @@ namespace Wox public MainWindow() { InitializeComponent(); - + ThreadPool.SetMaxThreads(30, 10); + ThreadPool.SetMinThreads(10, 5); if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow) + { this.AllowsTransparency = true; + } - System.Net.WebRequest.RegisterPrefix("data", new DataWebRequestFactory()); - + WebRequest.RegisterPrefix("data", new DataWebRequestFactory()); + GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback; progressBar.ToolTip = toolTip; InitialTray(); pnlResult.LeftMouseClickEvent += SelectResult; pnlContextMenu.LeftMouseClickEvent += SelectResult; pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent; - ThreadPool.SetMaxThreads(30, 10); - try - { - SetTheme(UserSettingStorage.Instance.Theme); - } - catch (Exception) - { - SetTheme(UserSettingStorage.Instance.Theme = "Dark"); - } + ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme); + InternationalizationManager.Internationalization.ChangeLanguage(UserSettingStorage.Instance.Language); SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey); SetCustomPluginHotkey(); - globalHotkey.hookedKeyboardCallback += KListener_hookedKeyboardCallback; - Closing += MainWindow_Closing; //since MainWIndow implement IPublicAPI, so we need to finish ctor MainWindow object before //PublicAPI invoke in plugin init methods. E.g FolderPlugin ThreadPool.QueueUserWorkItem(o => { Thread.Sleep(50); - Plugins.Init(); + PluginManager.Init(this); }); ThreadPool.QueueUserWorkItem(o => { Thread.Sleep(50); PreLoadImages(); }); - ThreadPool.QueueUserWorkItem(o => CheckUpdate()); + CheckUpdate(); + } + + private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state) + { + if (GlobalKeyboardEvent != null) + { + return GlobalKeyboardEvent((int)keyevent, vkcode, state); + } + return true; } private void PreLoadImages() @@ -215,18 +217,21 @@ namespace Wox void CheckUpdate() { - Release release = new UpdateChecker().CheckUpgrade(); - if (release != null && !UserSettingStorage.Instance.DontPromptUpdateMsg) + ThreadPool.QueueUserWorkItem(o => { - Dispatcher.Invoke(new Action(() => + Release release = new UpdateChecker().CheckUpgrade(); + if (release != null && !UserSettingStorage.Instance.DontPromptUpdateMsg) { - NewVersionWindow newVersinoWindow = new NewVersionWindow(); - newVersinoWindow.Show(); - })); - } + Dispatcher.Invoke(new Action(() => + { + NewVersionWindow newVersinoWindow = new NewVersionWindow(); + newVersinoWindow.Show(); + })); + } + }); } - void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) + void MainWindow_Closing(object sender, CancelEventArgs e) { UserSettingStorage.Instance.WindowLeft = Left; UserSettingStorage.Instance.WindowTop = Top; @@ -261,6 +266,7 @@ namespace Wox HwndSource.FromHwnd(new WindowInteropHelper(this).Handle).CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0); WindowIntelopHelper.DisableControlBox(this); + UpdaterManager.Instance.CheckUpdate(); } public void SetHotkey(string hotkeyStr, EventHandler action) @@ -272,7 +278,8 @@ namespace Wox } catch (Exception) { - MessageBox.Show("Register hotkey: " + hotkeyStr + " failed."); + string errorMsg = string.Format(InternationalizationManager.Internationalization.GetTranslation("registerHotkeyFailed"), hotkeyStr); + MessageBox.Show(errorMsg); } } @@ -351,26 +358,63 @@ namespace Wox Dispatcher.DelayInvoke("ClearResults", i => { // first try to use clear method inside pnlResult, which is more closer to the add new results - // and this will not bring splash issues.After waiting 30ms, if there still no results added, we + // and this will not bring splash issues.After waiting 100ms, if there still no results added, we // must clear the result. otherwise, it will be confused why the query changed, but the results // didn't. if (pnlResult.Dirty) pnlResult.Clear(); }, TimeSpan.FromMilliseconds(100), null); queryHasReturn = false; var q = new Query(lastQuery); - CommandFactory.DispatchCommand(q); - BackToResultMode(); - if (Plugins.HitThirdpartyKeyword(q)) + FireBeforeWoxQueryEvent(q); + Query(q); + Dispatcher.DelayInvoke("ShowProgressbar", originQuery => { - Dispatcher.DelayInvoke("ShowProgressbar", originQuery => + if (!queryHasReturn && originQuery == lastQuery) { - if (!queryHasReturn && originQuery == lastQuery) - { - StartProgress(); - } - }, TimeSpan.FromSeconds(0), lastQuery); - } - }, TimeSpan.FromMilliseconds(ShouldNotDelayQuery ? 0 : 150)); + StartProgress(); + } + }, TimeSpan.FromMilliseconds(150), lastQuery); + FireAfterWoxQueryEvent(q); + }, TimeSpan.FromMilliseconds(200)); + } + + private void FireAfterWoxQueryEvent(Query q) + { + if (AfterWoxQueryEvent != null) + { + //We shouldn't let those events slow down real query + //so I put it in the new thread + ThreadPool.QueueUserWorkItem(o => + { + AfterWoxQueryEvent(new WoxQueryEventArgs() + { + Query = q + }); + }); + } + } + + private void FireBeforeWoxQueryEvent(Query q) + { + if (BeforeWoxQueryEvent != null) + { + //We shouldn't let those events slow down real query + //so I put it in the new thread + ThreadPool.QueueUserWorkItem(o => + { + BeforeWoxQueryEvent(new WoxQueryEventArgs() + { + Query = q + }); + }); + } + } + + private void Query(Query q) + { + PluginManager.Query(q); + StopProgress(); + BackToResultMode(); } private void BackToResultMode() @@ -379,22 +423,6 @@ namespace Wox pnlContextMenu.Visibility = Visibility.Collapsed; } - private bool ShouldNotDelayQuery - { - get - { - return IsCMDMode || IsWebSearchMode; - } - } - - private bool IsCMDMode - { - get - { - return tbQuery.Text.StartsWith(">"); - } - } - private bool IsWebSearchMode { get @@ -452,51 +480,6 @@ namespace Wox } } - private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state) - { - if (UserSettingStorage.Instance.ReplaceWinR) - { - //todo:need refactoring. move those codes to CMD file or expose events - if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed) - { - WinRStroked = true; - Dispatcher.BeginInvoke(new Action(OnWinRPressed)); - return false; - } - if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin) - { - WinRStroked = false; - keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL); - return false; - } - } - return true; - } - - private void OnWinRPressed() - { - ShowWox(false); - if (!tbQuery.Text.StartsWith(">")) - { - pnlResult.Clear(); - ChangeQuery(">"); - } - tbQuery.CaretIndex = tbQuery.Text.Length; - tbQuery.SelectionStart = 1; - tbQuery.SelectionLength = tbQuery.Text.Length - 1; - } - - private void updateCmdMode() - { - var currentSelectedItem = pnlResult.GetActiveResult(); - if (currentSelectedItem != null) - { - ignoreTextChange = true; - tbQuery.Text = ">" + currentSelectedItem.Title; - tbQuery.CaretIndex = tbQuery.Text.Length; - } - } - private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e) { //when alt is pressed, the real key should be e.SystemKey @@ -516,7 +499,7 @@ namespace Wox break; case Key.Tab: - if (globalHotkey.CheckModifiers().ShiftPressed) + if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed) { SelectPrevItem(); } @@ -539,14 +522,12 @@ namespace Wox case Key.PageDown: pnlResult.SelectNextPage(); - if (IsCMDMode) updateCmdMode(); toolTip.IsOpen = false; e.Handled = true; break; case Key.PageUp: pnlResult.SelectPrevPage(); - if (IsCMDMode) updateCmdMode(); toolTip.IsOpen = false; e.Handled = true; break; @@ -554,7 +535,7 @@ namespace Wox case Key.Back: if (BackKeyDownEvent != null) { - BackKeyDownEvent(tbQuery, new WoxKeyDownEventArgs() + BackKeyDownEvent(new WoxKeyDownEventArgs() { Query = tbQuery.Text, keyEventArgs = e @@ -563,18 +544,18 @@ namespace Wox break; case Key.F1: - Process.Start("https://github.com/qianlifeng/Wox/wiki/Wox-Function-Guide"); + Process.Start("http://doc.getwox.com"); break; case Key.Enter: Result activeResult = GetActiveResult(); - if (globalHotkey.CheckModifiers().ShiftPressed) + if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed) { ShowContextMenu(activeResult); } else { - SelectResult(activeResult); + SelectResult(activeResult); } e.Handled = true; break; @@ -596,7 +577,7 @@ namespace Wox { return pnlResult.GetActiveResult(); } - } + } private void SelectPrevItem() { @@ -607,7 +588,6 @@ namespace Wox else { pnlResult.SelectPrev(); - if (IsCMDMode) updateCmdMode(); } toolTip.IsOpen = false; } @@ -621,7 +601,6 @@ namespace Wox else { pnlResult.SelectNext(); - if (IsCMDMode) updateCmdMode(); } toolTip.IsOpen = false; } @@ -634,7 +613,7 @@ namespace Wox { bool hideWindow = result.Action(new ActionContext() { - SpecialKeyState = globalHotkey.CheckModifiers() + SpecialKeyState = GlobalHotkey.Instance.CheckModifiers() }); if (hideWindow) { @@ -645,7 +624,7 @@ namespace Wox } } - public void OnUpdateResultView(List list) + private void OnUpdateResultView(List list, bool clearBeforeInsert = false) { queryHasReturn = true; progressBar.Dispatcher.Invoke(new Action(StopProgress)); @@ -661,8 +640,13 @@ namespace Wox }); List l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList(); Dispatcher.Invoke(new Action(() => - pnlResult.AddResults(l)) - ); + { + if (clearBeforeInsert) + { + pnlResult.Clear(); + } + pnlResult.AddResults(l); + })); } } @@ -677,44 +661,6 @@ namespace Wox } } - public void SetTheme(string themeName) - { - var dict = new ResourceDictionary - { - Source = new Uri(Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Themes\\" + themeName + ".xaml"), UriKind.Absolute) - }; - - - Style queryBoxStyle = dict["QueryBoxStyle"] as Style; - if (queryBoxStyle != null) - { - queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont))); - queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStyle))); - queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontWeight))); - queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStretch))); - } - - Style resultItemStyle = dict["ItemTitleStyle"] as Style; - Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style; - Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style; - Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style; - if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null) - { - Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultItemFont)); - Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStyle)); - Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontWeight)); - Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStretch)); - - Setter[] setters = new Setter[] { fontFamily, fontStyle, fontWeight, fontStretch }; - Array.ForEach(new Style[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p))); - } - - Application.Current.Resources.MergedDictionaries.Clear(); - Application.Current.Resources.MergedDictionaries.Add(dict); - - this.Opacity = this.AllowsTransparency ? UserSettingStorage.Instance.Opacity : 1; - } - public bool ShellRun(string cmd, bool runAsAdministrator = false) { try @@ -727,24 +673,25 @@ namespace Wox } catch (Exception ex) { - ShowMsg("Could not start " + cmd, ex.Message, null); + string errorMsg = string.Format(InternationalizationManager.Internationalization.GetTranslation("couldnotStartCmd"), cmd); + ShowMsg(errorMsg, ex.Message, null); } return false; } private void MainWindow_OnDrop(object sender, DragEventArgs e) { - if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop)) + if (e.Data.GetDataPresent(DataFormats.FileDrop)) { // Note that you can have more than one file. - string[] files = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop); + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files[0].ToLower().EndsWith(".wox")) { - PluginInstaller.Install(files[0]); + PluginManager.InstallPlugin(files[0]); } else { - MessageBox.Show("incorrect wox plugin file."); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("invalidWoxPluginFileFormat")); } } } diff --git a/Wox/PluginLoader/BasePluginLoader.cs b/Wox/PluginLoader/BasePluginLoader.cs deleted file mode 100644 index ea2ad4f5df..0000000000 --- a/Wox/PluginLoader/BasePluginLoader.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Wox.Plugin; - -namespace Wox.PluginLoader -{ - public class BasePluginLoader : IPluginLoader where T : BasePlugin, new() - { - public virtual List LoadPlugin(List pluginMetadatas) - { - string supportedLanguage = new T().SupportedLanguage; - List metadatas = pluginMetadatas.Where(o => supportedLanguage.ToUpper() == o.Language.ToUpper()).ToList(); - - return metadatas.Select(metadata => new PluginPair() - { - Plugin = new T(), - Metadata = metadata - }).ToList(); - } - } -} diff --git a/Wox/PluginLoader/CSharpPluginLoader.cs b/Wox/PluginLoader/CSharpPluginLoader.cs deleted file mode 100644 index 8fa07c5801..0000000000 --- a/Wox/PluginLoader/CSharpPluginLoader.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Wox.Helper; -using Wox.Infrastructure.Logger; -using Wox.Plugin; -using Wox.Plugin.SystemPlugins; - -namespace Wox.PluginLoader { - - public class CSharpPluginLoader : IPluginLoader - { - public List LoadPlugin(List pluginMetadatas) - { - var plugins = new List(); - - List metadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList(); - foreach (PluginMetadata metadata in metadatas) { - try { - Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath)); - List types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && (o.BaseType == typeof(BaseSystemPlugin) || o.GetInterfaces().Contains(typeof(IPlugin)))).ToList(); - if (types.Count == 0) { - Log.Warn(string.Format("Couldn't load plugin {0}: didn't find the class who implement IPlugin", metadata.Name)); - continue; - } - - foreach (Type type in types) { - PluginPair pair = new PluginPair() { - Plugin = Activator.CreateInstance(type) as IPlugin, - Metadata = metadata - }; - - var sys = pair.Plugin as BaseSystemPlugin; - if (sys != null) { - sys.PluginDirectory = metadata.PluginDirectory; - } - - plugins.Add(pair); - } - } - catch (Exception e) { - Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message)); -#if (DEBUG) - { - throw; - } -#endif - } - } - - return plugins; - } - } -} \ No newline at end of file diff --git a/Wox/PluginLoader/IPluginLoader.cs b/Wox/PluginLoader/IPluginLoader.cs deleted file mode 100644 index 6eecec4d8c..0000000000 --- a/Wox/PluginLoader/IPluginLoader.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Wox.Plugin; - -namespace Wox.PluginLoader -{ - public interface IPluginLoader - { - List LoadPlugin(List pluginMetadatas); - } -} diff --git a/Wox/PluginLoader/PluginConfigLoader.cs b/Wox/PluginLoader/PluginConfigLoader.cs deleted file mode 100644 index 0953b902cf..0000000000 --- a/Wox/PluginLoader/PluginConfigLoader.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Windows.Forms; -using Newtonsoft.Json; -using Wox.Helper; -using Wox.Infrastructure.Exceptions; -using Wox.Infrastructure.Logger; -using Wox.Infrastructure.Storage.UserSettings; -using Wox.Plugin; -using Wox.Plugin.SystemPlugins; - -namespace Wox.PluginLoader { - public abstract class PluginConfigLoader { - private static string PluginPath = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Plugins"); - private static string PluginConfigName = "plugin.json"; - private static List pluginMetadatas = new List(); - - public static List ParsePluginsConfig() - { - pluginMetadatas.Clear(); - ParseSystemPlugins(); - ParseThirdPartyPlugins(); - - if (Plugins.DebuggerMode != null) { - PluginMetadata metadata = GetMetadataFromJson(Plugins.DebuggerMode); - if (metadata != null) pluginMetadatas.Add(metadata); - } - return pluginMetadatas; - } - - private static void ParseSystemPlugins() { - pluginMetadatas.Add(new PluginMetadata() { - Name = "System Plugins", - Author = "System", - Description = "system plugins collection", - Website = "http://www.getwox.com", - Language = AllowedLanguage.CSharp, - Version = "1.0", - PluginType = PluginType.System, - ActionKeyword = "*", - ExecuteFileName = "Wox.Plugin.SystemPlugins.dll", - PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) - }); - } - - private static void ParseThirdPartyPlugins() { - if (!Directory.Exists(PluginPath)) - Directory.CreateDirectory(PluginPath); - - string[] directories = Directory.GetDirectories(PluginPath); - foreach (string directory in directories) { - if (File.Exists((Path.Combine(directory, "NeedDelete.txt")))) { - Directory.Delete(directory, true); - continue; - } - PluginMetadata metadata = GetMetadataFromJson(directory); - if (metadata != null) pluginMetadatas.Add(metadata); - } - } - - private static PluginMetadata GetMetadataFromJson(string pluginDirectory) { - string configPath = Path.Combine(pluginDirectory, PluginConfigName); - PluginMetadata metadata; - - if (!File.Exists(configPath)) { - Log.Warn(string.Format("parse plugin {0} failed: didn't find config file.", configPath)); - return null; - } - - try { - metadata = JsonConvert.DeserializeObject(File.ReadAllText(configPath)); - metadata.PluginType = PluginType.ThirdParty; - metadata.PluginDirectory = pluginDirectory; - } - catch (Exception) { - string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath); - Log.Warn(error); -#if (DEBUG) - { - throw new WoxException(error); - } -#endif - return null; - } - - - if (!AllowedLanguage.IsAllowed(metadata.Language)) { - string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath, metadata.Language); - Log.Warn(error); -#if (DEBUG) - { - throw new WoxException(error); - } -#endif - return null; - } - if (!File.Exists(metadata.ExecuteFilePath)) { - string error = string.Format("Parse plugin config {0} failed: ExecuteFile {1} didn't exist", configPath, metadata.ExecuteFilePath); - Log.Warn(error); -#if (DEBUG) - { - throw new WoxException(error); - } -#endif - return null; - } - - var customizedPluginConfig = - UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID); - if (customizedPluginConfig != null && !string.IsNullOrEmpty(customizedPluginConfig.Actionword)) - { - metadata.ActionKeyword = customizedPluginConfig.Actionword; - } - - return metadata; - } - } -} diff --git a/Wox/PluginLoader/Plugins.cs b/Wox/PluginLoader/Plugins.cs deleted file mode 100644 index f4c7eedbfb..0000000000 --- a/Wox/PluginLoader/Plugins.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using Wox.Helper; -using Wox.Infrastructure; -using Wox.Infrastructure.Http; -using Wox.Infrastructure.Storage.UserSettings; -using Wox.Plugin; - -namespace Wox.PluginLoader -{ - public static class Plugins - { - public static String DebuggerMode { get; private set; } - private static List plugins = new List(); - - public static void Init() - { - plugins.Clear(); - List pluginMetadatas = PluginConfigLoader.ParsePluginsConfig(); - - plugins.AddRange(new CSharpPluginLoader().LoadPlugin(pluginMetadatas)); - plugins.AddRange(new BasePluginLoader().LoadPlugin(pluginMetadatas)); - - foreach (PluginPair pluginPair in plugins) - { - PluginPair pair = pluginPair; - ThreadPool.QueueUserWorkItem(o => pair.Plugin.Init(new PluginInitContext() - { - CurrentPluginMetadata = pair.Metadata, - Proxy = HttpProxy.Instance, - API = App.Window - })); - } - } - - public static List AllPlugins - { - get - { - return plugins; - } - } - - public static bool HitThirdpartyKeyword(Query query) - { - if (string.IsNullOrEmpty(query.ActionName)) return false; - - return plugins.Any(o => o.Metadata.PluginType == PluginType.ThirdParty && o.Metadata.ActionKeyword == query.ActionName); - } - - public static void ActivatePluginDebugger(string path) - { - DebuggerMode = path; - } - } -} diff --git a/Wox/Properties/Resources.Designer.cs b/Wox/Properties/Resources.Designer.cs index 6d1b535344..7665c71436 100644 --- a/Wox/Properties/Resources.Designer.cs +++ b/Wox/Properties/Resources.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.18444 +// 此代码由工具生成。 +// 运行时版本:4.0.30319.0 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ @@ -13,12 +13,12 @@ namespace Wox.Properties { /// - /// A strongly-typed resource class, for looking up localized strings, etc. + /// 一个强类型的资源类,用于查找本地化的字符串等。 /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] @@ -33,7 +33,7 @@ namespace Wox.Properties { } /// - /// Returns the cached ResourceManager instance used by this class. + /// 返回此类使用的缓存的 ResourceManager 实例。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { @@ -47,8 +47,8 @@ namespace Wox.Properties { } /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. + /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { @@ -61,7 +61,7 @@ namespace Wox.Properties { } /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// 查找类似于 (Icon) 的 System.Drawing.Icon 类型的本地化资源。 /// internal static System.Drawing.Icon app { get { diff --git a/Wox/Properties/Settings.Designer.cs b/Wox/Properties/Settings.Designer.cs index 07c3c5c393..eb3d4dc309 100644 --- a/Wox/Properties/Settings.Designer.cs +++ b/Wox/Properties/Settings.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // 此代码由工具生成。 -// 运行时版本:4.0.30319.18052 +// 运行时版本:4.0.30319.0 // // 对此文件的更改可能会导致不正确的行为,并且如果 // 重新生成代码,这些更改将会丢失。 @@ -12,7 +12,7 @@ namespace Wox.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 1ab4866c0f..50e5341b9d 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -2,10 +2,10 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wox="clr-namespace:Wox" - xmlns:UserSettings="clr-namespace:Wox.Infrastructure.Storage.UserSettings;assembly=Wox.Infrastructure" x:Class="Wox.SettingWindow" + x:Class="Wox.SettingWindow" xmlns:woxPlugin="clr-namespace:Wox.Plugin;assembly=Wox.Plugin" - xmlns:system="clr-namespace:Wox.Plugin.SystemPlugins;assembly=Wox.Plugin.SystemPlugins" xmlns:converters="clr-namespace:Wox.Converters" + xmlns:userSettings="clr-namespace:Wox.Core.UserSettings;assembly=Wox.Core" Icon="Images\app.png" Title="Wox Settings" ResizeMode="NoResize" @@ -20,47 +20,33 @@ - + - - Start Wox on system startup + + - Hide Wox when loses focus + - Don't show upgrade msg if new version available + + + + + - + - + - - - - - - - - - - - - - - - - - - @@ -102,14 +88,18 @@ - + - Disable - ActionKeyword: + + + + + + - + @@ -121,14 +111,14 @@ - + - + @@ -150,7 +140,7 @@ - + @@ -159,7 +149,7 @@ - + - + - + - Normal - LayeredWindow - DWM + Normal + LayeredWindow + DWM @@ -209,7 +199,7 @@ - + @@ -218,7 +208,7 @@ - + @@ -226,7 +216,7 @@ - + @@ -234,18 +224,18 @@ - + - + - + @@ -258,15 +248,17 @@ - - + + - + @@ -320,10 +312,10 @@ - Website: + - Version: + diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 4c752ad13c..56152f8c18 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -10,23 +10,23 @@ using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; -using IWshRuntimeLibrary; -using Wox.Infrastructure.Storage.UserSettings; +using Wox.Core.Plugin; using Wox.Plugin; using Wox.Helper; -using Wox.Plugin.SystemPlugins; -using Wox.PluginLoader; using Wox.Update; using Application = System.Windows.Forms.Application; using File = System.IO.File; using MessageBox = System.Windows.MessageBox; using System.Windows.Data; +using Microsoft.Win32; +using Wox.Core.i18n; +using Wox.Core.Theme; +using Wox.Core.UserSettings; namespace Wox { public partial class SettingWindow : Window { - string woxLinkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "wox.lnk"); public MainWindow MainWindow; bool settingsLoaded = false; private Dictionary featureControls = new Dictionary(); @@ -66,10 +66,12 @@ namespace Wox UserSettingStorage.Instance.Save(); }; - cbStartWithWindows.IsChecked = File.Exists(woxLinkPath); + cbStartWithWindows.IsChecked = CheckApplicationIsStartupWithWindow(); cbHideWhenDeactive.IsChecked = UserSettingStorage.Instance.HideWhenDeactive; cbDontPromptUpdateMsg.IsChecked = UserSettingStorage.Instance.DontPromptUpdateMsg; + LoadLanguages(); + #endregion #region Theme @@ -102,53 +104,53 @@ namespace Wox { Title = "Wox is an effective launcher for windows", SubTitle = "Wox provide bundles of features let you access infomations quickly.", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) }, new Result() { Title = "Search applications", SubTitle = "Search applications, files (via everything plugin) and browser bookmarks", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) }, new Result() { Title = "Search web contents with shortcuts", SubTitle = "e.g. search google with g keyword or youtube keyword)", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) }, new Result() { Title = "clipboard history ", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) }, new Result() { Title = "Themes support", SubTitle = "get more themes from http://www.getwox.com/theme", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) }, new Result() { Title = "Plugins support", SubTitle = "get more plugins from http://www.getwox.com/plugin", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) }, new Result() { Title = "Wox is an open-source software", SubTitle = "Wox benefits from the open-source community a lot", - IcoPath = "Images/work.png", + IcoPath = "Images/app.png", PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath) } }); - foreach (string theme in LoadAvailableThemes()) + foreach (string theme in ThemeManager.Theme.LoadAvailableThemes()) { string themeName = System.IO.Path.GetFileNameWithoutExtension(theme); themeComboBox.Items.Add(themeName); @@ -172,8 +174,7 @@ namespace Wox } //PreviewPanel - App.Window.SetTheme(UserSettingStorage.Instance.Theme); - + ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme); #endregion #region Plugin @@ -186,16 +187,7 @@ namespace Wox { new CollectionContainer { - Collection = - PluginLoader.Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System) - .Select(o => o.Plugin) - .Cast() - }, - FindResource("FeatureBoxSeperator"), - new CollectionContainer - { - Collection = - PluginLoader.Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.ThirdParty) + Collection = PluginManager.AllPlugins } }; lbPlugins.ItemsSource = plugins; @@ -241,6 +233,20 @@ namespace Wox settingsLoaded = true; } + private void LoadLanguages() + { + cbLanguages.ItemsSource = InternationalizationManager.Internationalization.LoadAvailableLanguages(); + cbLanguages.DisplayMemberPath = "Display"; + cbLanguages.SelectedValuePath = "LanguageCode"; + cbLanguages.SelectedValue = UserSettingStorage.Instance.Language; + cbLanguages.SelectionChanged += cbLanguages_SelectionChanged; + } + + void cbLanguages_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + InternationalizationManager.Internationalization.ChangeLanguage(cbLanguages.SelectedItem as Language); + } + private void EnableProxy() { tbProxyPassword.IsEnabled = true; @@ -257,41 +263,42 @@ namespace Wox tbProxyPort.IsEnabled = false; } - private List LoadAvailableThemes() - { - string themePath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Themes"); - return Directory.GetFiles(themePath).Where(filePath => filePath.EndsWith(".xaml") && !filePath.EndsWith("Default.xaml")).ToList(); - } - private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e) { - CreateStartupFolderShortcut(); + AddApplicationToStartup(); UserSettingStorage.Instance.StartWoxOnSystemStartup = true; UserSettingStorage.Instance.Save(); } private void CbStartWithWindows_OnUnchecked(object sender, RoutedEventArgs e) { - if (File.Exists(woxLinkPath)) - { - File.Delete(woxLinkPath); - } - + RemoveApplicationFromStartup(); UserSettingStorage.Instance.StartWoxOnSystemStartup = false; UserSettingStorage.Instance.Save(); } - private void CreateStartupFolderShortcut() + private void AddApplicationToStartup() { - WshShellClass wshShell = new WshShellClass(); + using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) + { + key.SetValue("Wox", "\"" + Application.ExecutablePath + "\" --hidestart"); + } + } - IWshShortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(woxLinkPath); - shortcut.TargetPath = Application.ExecutablePath; - shortcut.Arguments = "hideStart"; - shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath); - shortcut.Description = "Launch Wox"; - shortcut.IconLocation = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "App.ico"); - shortcut.Save(); + private void RemoveApplicationFromStartup() + { + using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) + { + key.DeleteValue("Wox", false); + } + } + + private bool CheckApplicationIsStartupWithWindow() + { + using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) + { + return key.GetValue("Wox") != null; + } } void ctlHotkey_OnHotkeyChanged(object sender, System.EventArgs e) @@ -320,19 +327,20 @@ namespace Wox private void BtnDeleteCustomHotkey_OnClick(object sender, RoutedEventArgs e) { CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey; - if (item != null && - MessageBox.Show("Are your sure to delete " + item.Hotkey + " plugin hotkey?", "Delete Custom Plugin Hotkey", - MessageBoxButton.YesNo) == MessageBoxResult.Yes) + if (item == null) + { + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("pleaseSelectAnItem")); + return; + } + + string deleteWarning = string.Format(InternationalizationManager.Internationalization.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey); + if (MessageBox.Show(deleteWarning, InternationalizationManager.Internationalization.GetTranslation("delete"), MessageBoxButton.YesNo) == MessageBoxResult.Yes) { UserSettingStorage.Instance.CustomPluginHotkeys.Remove(item); lvCustomHotkey.Items.Refresh(); UserSettingStorage.Instance.Save(); MainWindow.RemoveHotkey(item.Hotkey); } - else - { - MessageBox.Show("Please select an item"); - } } private void BtnEditCustomHotkey_OnClick(object sender, RoutedEventArgs e) @@ -340,19 +348,19 @@ namespace Wox CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey; if (item != null) { - CustomPluginHotkeySetting window = new CustomPluginHotkeySetting(this); + CustomQueryHotkeySetting window = new CustomQueryHotkeySetting(this); window.UpdateItem(item); window.ShowDialog(); } else { - MessageBox.Show("Please select an item"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("pleaseSelectAnItem")); } } private void BtnAddCustomeHotkey_OnClick(object sender, RoutedEventArgs e) { - new CustomPluginHotkeySetting(this).ShowDialog(); + new CustomQueryHotkeySetting(this).ShowDialog(); } public void ReloadCustomPluginHotkeyView() @@ -366,7 +374,7 @@ namespace Wox private void ThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { string themeName = themeComboBox.SelectedItem.ToString(); - MainWindow.SetTheme(themeName); + ThemeManager.Theme.ChangeTheme(themeName); UserSettingStorage.Instance.Theme = themeName; UserSettingStorage.Instance.Save(); } @@ -379,7 +387,7 @@ namespace Wox this.cbQueryBoxFontFaces.SelectedItem = ((FontFamily)cbQueryBoxFont.SelectedItem).ChooseRegularFamilyTypeface(); UserSettingStorage.Instance.Save(); - App.Window.SetTheme(UserSettingStorage.Instance.Theme); + ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme); } private void CbQueryBoxFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e) @@ -399,7 +407,7 @@ namespace Wox UserSettingStorage.Instance.QueryBoxFontWeight = typeface.Weight.ToString(); UserSettingStorage.Instance.QueryBoxFontStyle = typeface.Style.ToString(); UserSettingStorage.Instance.Save(); - App.Window.SetTheme(UserSettingStorage.Instance.Theme); + ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme); } } @@ -411,7 +419,7 @@ namespace Wox this.cbResultItemFontFaces.SelectedItem = ((FontFamily)cbResultItemFont.SelectedItem).ChooseRegularFamilyTypeface(); UserSettingStorage.Instance.Save(); - App.Window.SetTheme(UserSettingStorage.Instance.Theme); + ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme); } private void CbResultItemFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e) @@ -422,8 +430,6 @@ namespace Wox { if (cbResultItemFontFaces.Items.Count > 0) cbResultItemFontFaces.SelectedIndex = 0; - - return; } else { @@ -431,21 +437,24 @@ namespace Wox UserSettingStorage.Instance.ResultItemFontWeight = typeface.Weight.ToString(); UserSettingStorage.Instance.ResultItemFontStyle = typeface.Style.ToString(); UserSettingStorage.Instance.Save(); - App.Window.SetTheme(UserSettingStorage.Instance.Theme); + ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme); } } private void slOpacity_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { UserSettingStorage.Instance.Opacity = slOpacity.Value; - UserSettingStorage.Instance.Save(); if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow) PreviewMainPanel.Opacity = UserSettingStorage.Instance.Opacity; else PreviewMainPanel.Opacity = 1; - App.Window.SetTheme(UserSettingStorage.Instance.Theme); + ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme); + Dispatcher.DelayInvoke("delaySaveUserSetting", o => + { + UserSettingStorage.Instance.Save(); + }, TimeSpan.FromMilliseconds(1000)); } #endregion @@ -479,7 +488,7 @@ namespace Wox pluginTitle.Text = pair.Metadata.Name; pluginTitle.Cursor = Cursors.Hand; pluginActionKeyword.Text = pair.Metadata.ActionKeyword; - pluginAuthor.Text = "By: " + pair.Metadata.Author; + pluginAuthor.Text = InternationalizationManager.Internationalization.GetTranslation("author") + ": " + pair.Metadata.Author; pluginSubTitle.Text = pair.Metadata.Description; pluginId = pair.Metadata.ID; pluginIcon.Source = ImageLoader.ImageLoader.Load(pair.Metadata.FullIcoPath); @@ -488,19 +497,6 @@ namespace Wox { //system plugin provider = lbPlugins.SelectedItem as ISettingProvider; - var sys = lbPlugins.SelectedItem as BaseSystemPlugin; - if (sys != null) - { - pluginTitle.Text = sys.Name; - pluginId = sys.ID; - pluginSubTitle.Text = sys.Description; - pluginAuthor.Visibility = Visibility.Collapsed; - pluginActionKeyword.Visibility = Visibility.Collapsed; - tbOpenPluginDirecoty.Visibility = Visibility.Collapsed; - pluginActionKeywordTitle.Visibility = Visibility.Collapsed; - pluginTitle.Cursor = Cursors.Arrow; - pluginIcon.Source = ImageLoader.ImageLoader.Load(sys.FullIcoPath); - } } var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pluginId); @@ -519,8 +515,6 @@ namespace Wox control.Width = Double.NaN; control.Height = Double.NaN; } - // featureControls - // throw new NotImplementedException(); } private void CbDisablePlugin_OnClick(object sender, RoutedEventArgs e) @@ -537,16 +531,6 @@ namespace Wox id = pair.Metadata.ID; name = pair.Metadata.Name; } - else - { - //system plugin - var sys = lbPlugins.SelectedItem as BaseSystemPlugin; - if (sys != null) - { - id = sys.ID; - name = sys.Name; - } - } var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == id); if (customizedPluginConfig == null) { @@ -576,7 +560,7 @@ namespace Wox string id = pair.Metadata.ID; ActionKeyword changeKeywordWindow = new ActionKeyword(id); changeKeywordWindow.ShowDialog(); - PluginPair plugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ID == id); + PluginPair plugin = PluginManager.GetPlugin(id); if (plugin != null) pluginActionKeyword.Text = plugin.Metadata.ActionKeyword; } } @@ -643,17 +627,17 @@ namespace Wox { if (string.IsNullOrEmpty(tbProxyServer.Text)) { - MessageBox.Show("Server can't be empty"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("serverCantBeEmpty")); return; } if (string.IsNullOrEmpty(tbProxyPort.Text)) { - MessageBox.Show("Server port can't be empty"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("portCantBeEmpty")); return; } if (!int.TryParse(tbProxyPort.Text, out port)) { - MessageBox.Show("Invalid port format"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("invalidPortFormat")); return; } } @@ -664,25 +648,25 @@ namespace Wox UserSettingStorage.Instance.ProxyPassword = tbProxyPassword.Password; UserSettingStorage.Instance.Save(); - MessageBox.Show("Save Proxy Successfully"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("saveProxySuccessfully")); } private void btnTestProxy_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(tbProxyServer.Text)) { - MessageBox.Show("Server can't be empty"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("serverCantBeEmpty")); return; } if (string.IsNullOrEmpty(tbProxyPort.Text)) { - MessageBox.Show("Server port can't be empty"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("portCantBeEmpty")); return; } int port; if (!int.TryParse(tbProxyPort.Text, out port)) { - MessageBox.Show("Invalid port format"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("invalidPortFormat")); return; } @@ -700,19 +684,19 @@ namespace Wox } try { - HttpWebResponse response = (HttpWebResponse) request.GetResponse(); + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { - MessageBox.Show("Proxy is ok"); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("proxyIsCorrect")); } else { - MessageBox.Show("Proxy connect failed."); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("proxyConnectFailed")); } } catch { - MessageBox.Show("Proxy connect failed."); + MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("proxyConnectFailed")); } } diff --git a/Wox.Infrastructure/Storage/UserSelectedRecordStorage.cs b/Wox/Storage/UserSelectedRecordStorage.cs similarity index 66% rename from Wox.Infrastructure/Storage/UserSelectedRecordStorage.cs rename to Wox/Storage/UserSelectedRecordStorage.cs index 0b21e320e7..fa41090989 100644 --- a/Wox.Infrastructure/Storage/UserSelectedRecordStorage.cs +++ b/Wox/Storage/UserSelectedRecordStorage.cs @@ -1,18 +1,30 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using Newtonsoft.Json; using Wox.Infrastructure.Storage; using Wox.Plugin; +using System.IO; -namespace Wox.Infrastructure.Storage +namespace Wox.Storage { public class UserSelectedRecordStorage : JsonStrorage { [JsonProperty] private Dictionary records = new Dictionary(); + protected override string ConfigFolder + { + get + { + string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE"); + if (userProfilePath == null) + { + throw new ArgumentException("Environment variable USERPROFILE is empty"); + } + return Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Config"); + } + } + protected override string ConfigName { get { return "UserSelectedRecords"; } diff --git a/Wox/Themes/Default.xaml b/Wox/Themes/Base.xaml similarity index 100% rename from Wox/Themes/Default.xaml rename to Wox/Themes/Base.xaml diff --git a/Wox/Themes/Dark.xaml b/Wox/Themes/Dark.xaml index 4becca7ffa..e2d1679787 100644 --- a/Wox/Themes/Dark.xaml +++ b/Wox/Themes/Dark.xaml @@ -2,7 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System;assembly=mscorlib"> - +