From 50f6044a2f5d06b6987f5f367fc153b16fa88d01 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Fri, 26 Dec 2014 19:36:43 +0800 Subject: [PATCH 01/38] Refactoring [WIP] --- Wox.Core/Plugin/CSharpPluginLoader.cs | 61 ++++++++ Wox.Core/Plugin/IPluginLoader.cs | 10 ++ .../Plugin}/JsonPRCModel.cs | 2 +- .../Plugin/JsonRPCPlugin.cs | 23 ++- Wox.Core/Plugin/JsonRPCPluginLoader.cs | 21 +++ Wox.Core/Plugin/PluginConfig.cs | 141 ++++++++++++++++++ Wox.Core/Plugin/PluginManager.cs | 99 ++++++++++++ .../Plugin}/PythonPlugin.cs | 15 +- Wox.Core/Properties/AssemblyInfo.cs | 36 +++++ Wox.Core/README.txt | 4 + Wox.Core/Wox.Core.csproj | 86 +++++++++++ Wox.Core/packages.config | 4 + Wox.sln | 8 +- Wox/ActionKeyword.xaml.cs | 6 +- Wox/CommandArgs/PluginDebuggerCommandArg.cs | 3 +- Wox/CommandArgs/ReloadPluginCommandArg.cs | 4 +- Wox/Commands/CommandFactory.cs | 4 +- Wox/Commands/PluginCommand.cs | 4 +- Wox/Commands/SystemCommand.cs | 4 +- Wox/Helper/PluginInstaller.cs | 4 +- Wox/MainWindow.xaml.cs | 11 +- Wox/PluginLoader/BasePluginLoader.cs | 23 --- Wox/PluginLoader/CSharpPluginLoader.cs | 55 ------- Wox/PluginLoader/IPluginLoader.cs | 13 -- Wox/PluginLoader/PluginConfigLoader.cs | 121 --------------- Wox/PluginLoader/Plugins.cs | 58 ------- Wox/SettingWindow.xaml.cs | 8 +- Wox/Wox.csproj | 12 +- 28 files changed, 515 insertions(+), 325 deletions(-) create mode 100644 Wox.Core/Plugin/CSharpPluginLoader.cs create mode 100644 Wox.Core/Plugin/IPluginLoader.cs rename {Wox/JsonRPC => Wox.Core/Plugin}/JsonPRCModel.cs (99%) rename Wox/PluginLoader/BasePlugin.cs => Wox.Core/Plugin/JsonRPCPlugin.cs (93%) create mode 100644 Wox.Core/Plugin/JsonRPCPluginLoader.cs create mode 100644 Wox.Core/Plugin/PluginConfig.cs create mode 100644 Wox.Core/Plugin/PluginManager.cs rename {Wox/PluginLoader => Wox.Core/Plugin}/PythonPlugin.cs (87%) create mode 100644 Wox.Core/Properties/AssemblyInfo.cs create mode 100644 Wox.Core/README.txt create mode 100644 Wox.Core/Wox.Core.csproj create mode 100644 Wox.Core/packages.config delete mode 100644 Wox/PluginLoader/BasePluginLoader.cs delete mode 100644 Wox/PluginLoader/CSharpPluginLoader.cs delete mode 100644 Wox/PluginLoader/IPluginLoader.cs delete mode 100644 Wox/PluginLoader/PluginConfigLoader.cs delete mode 100644 Wox/PluginLoader/Plugins.cs diff --git a/Wox.Core/Plugin/CSharpPluginLoader.cs b/Wox.Core/Plugin/CSharpPluginLoader.cs new file mode 100644 index 0000000000..9cfdc56734 --- /dev/null +++ b/Wox.Core/Plugin/CSharpPluginLoader.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Wox.Infrastructure.Logger; +using Wox.Plugin; +using Wox.Plugin.SystemPlugins; + +namespace Wox.Core.Plugin +{ + internal class CSharpPluginLoader : IPluginLoader + { + public IEnumerable LoadPlugin(List pluginMetadatas) + { + var plugins = new List(); + List CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList(); + + foreach (PluginMetadata metadata in CSharpPluginMetadatas) + { + 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 that 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.Core/Plugin/IPluginLoader.cs b/Wox.Core/Plugin/IPluginLoader.cs new file mode 100644 index 0000000000..a85e7e361e --- /dev/null +++ b/Wox.Core/Plugin/IPluginLoader.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using Wox.Plugin; + +namespace Wox.Core.Plugin +{ + internal interface IPluginLoader + { + IEnumerable LoadPlugin(List pluginMetadatas); + } +} diff --git a/Wox/JsonRPC/JsonPRCModel.cs b/Wox.Core/Plugin/JsonPRCModel.cs similarity index 99% rename from Wox/JsonRPC/JsonPRCModel.cs rename to Wox.Core/Plugin/JsonPRCModel.cs index 84ecc35180..480d1e386d 100644 --- a/Wox/JsonRPC/JsonPRCModel.cs +++ b/Wox.Core/Plugin/JsonPRCModel.cs @@ -17,7 +17,7 @@ using System.Collections.Generic; using System.Linq; using Wox.Plugin; -namespace Wox.JsonRPC +namespace Wox.Core.Plugin { public class JsonRPCErrorModel { diff --git a/Wox/PluginLoader/BasePlugin.cs b/Wox.Core/Plugin/JsonRPCPlugin.cs similarity index 93% rename from Wox/PluginLoader/BasePlugin.cs rename to Wox.Core/Plugin/JsonRPCPlugin.cs index da6f653de4..1b878dfce3 100644 --- a/Wox/PluginLoader/BasePlugin.cs +++ b/Wox.Core/Plugin/JsonRPCPlugin.cs @@ -2,30 +2,29 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; using System.Reflection; -using System.Text; using System.Threading; -using System.Windows.Forms; using Newtonsoft.Json; -using Wox.Helper; -using Wox.Helper.ErrorReporting; using Wox.Infrastructure.Exceptions; using Wox.Infrastructure.Logger; -using Wox.JsonRPC; using Wox.Plugin; -using MessageBox = System.Windows.MessageBox; -namespace Wox.PluginLoader +namespace Wox.Core.Plugin { - public abstract class BasePlugin : IPlugin + /// + /// Represent the plugin that using JsonPRC + /// + internal abstract class JsonRPCPlugin : IPlugin { protected PluginInitContext context; + /// + /// The language this JsonRPCPlugin support + /// public abstract string SupportedLanguage { get; } protected abstract string ExecuteQuery(Query query); - protected abstract string ExecuteAction(JsonRPCRequestModel rpcRequest); + protected abstract string ExecuteCallback(JsonRPCRequestModel rpcRequest); public List Query(Query query) { @@ -56,7 +55,7 @@ namespace Wox.PluginLoader { ThreadPool.QueueUserWorkItem(state => { - string actionReponse = ExecuteAction(result1.JsonRPCAction); + string actionReponse = ExecuteCallback(result1.JsonRPCAction); JsonRPCRequestModel jsonRpcRequestModel = JsonConvert.DeserializeObject(actionReponse); if (jsonRpcRequestModel != null && !string.IsNullOrEmpty(jsonRpcRequestModel.Method) @@ -161,7 +160,7 @@ namespace Wox.PluginLoader public void Init(PluginInitContext ctx) { - this.context = ctx; + context = ctx; } } } diff --git a/Wox.Core/Plugin/JsonRPCPluginLoader.cs b/Wox.Core/Plugin/JsonRPCPluginLoader.cs new file mode 100644 index 0000000000..234da6a25d --- /dev/null +++ b/Wox.Core/Plugin/JsonRPCPluginLoader.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Linq; +using Wox.Plugin; + +namespace Wox.Core.Plugin +{ + internal class JsonRPCPluginLoader : IPluginLoader where T : JsonRPCPlugin, new() + { + public virtual IEnumerable LoadPlugin(List pluginMetadatas) + { + T jsonRPCPlugin = new T(); + List jsonRPCPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == jsonRPCPlugin.SupportedLanguage.ToUpper()).ToList(); + + return jsonRPCPluginMetadatas.Select(metadata => new PluginPair() + { + Plugin = jsonRPCPlugin, + Metadata = metadata + }).ToList(); + } + } +} diff --git a/Wox.Core/Plugin/PluginConfig.cs b/Wox.Core/Plugin/PluginConfig.cs new file mode 100644 index 0000000000..0359ef6483 --- /dev/null +++ b/Wox.Core/Plugin/PluginConfig.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using Newtonsoft.Json; +using Wox.Infrastructure.Exceptions; +using Wox.Infrastructure.Logger; +using Wox.Infrastructure.Storage.UserSettings; +using Wox.Plugin; + +namespace Wox.Core.Plugin +{ + + internal abstract class PluginConfig + { + private const string pluginConfigName = "plugin.json"; + private static List pluginMetadatas = new List(); + + /// + /// Parse plugin metadata in giving directories + /// + /// + /// + public static List Parse(List pluginDirectories) + { + pluginMetadatas.Clear(); + ParseSystemPlugins(); + foreach (string pluginDirectory in pluginDirectories) + { + ParseThirdPartyPlugins(pluginDirectory); + } + + if (PluginManager.DebuggerMode != null) + { + PluginMetadata metadata = GetPluginMetadata(PluginManager.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.0", + PluginType = PluginType.System, + ActionKeyword = "*", + ExecuteFileName = "Wox.Plugin.SystemPlugins.dll", + PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + }); + } + + private static void ParseThirdPartyPlugins(string pluginDirectory) + { + + string[] directories = Directory.GetDirectories(pluginDirectory); + foreach (string directory in directories) + { + if (File.Exists((Path.Combine(directory, "NeedDelete.txt")))) + { + Directory.Delete(directory, true); + continue; + } + PluginMetadata metadata = GetPluginMetadata(directory); + if (metadata != null) + { + pluginMetadatas.Add(metadata); + } + } + } + + private static PluginMetadata GetPluginMetadata(string pluginDirectory) + { + string configPath = Path.Combine(pluginDirectory, pluginConfigName); + if (!File.Exists(configPath)) + { + Log.Warn(string.Format("parse plugin {0} failed: didn't find config file.", configPath)); + return null; + } + + PluginMetadata metadata; + 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; + } + + //replace action keyword if user customized it. + 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.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs new file mode 100644 index 0000000000..91af115ba8 --- /dev/null +++ b/Wox.Core/Plugin/PluginManager.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Threading; +using Wox.Infrastructure.Http; +using Wox.Plugin; + +namespace Wox.Core.Plugin +{ + /// + /// The entry for managing Wox plugins + /// + public static class PluginManager + { + public static String DebuggerMode { get; private set; } + private static List plugins = new List(); + + /// + /// Directories that will hold Wox plugin directory + /// + private static List pluginDirectories = new List(); + + static PluginManager() + { + pluginDirectories.Add( + Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Plugins")); + pluginDirectories.Add( + Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), ".Wox"),"Plugins")); + + MakesurePluginDirectoriesExist(); + } + + private static void MakesurePluginDirectoriesExist() + { + foreach (string pluginDirectory in pluginDirectories) + { + if (!Directory.Exists(pluginDirectory)) + { + Directory.CreateDirectory(pluginDirectory); + } + } + } + + /// + /// Load and init all Wox plugins + /// + public static void Init() + { + plugins.Clear(); + + List pluginMetadatas = PluginConfig.Parse(pluginDirectories); + plugins.AddRange(new CSharpPluginLoader().LoadPlugin(pluginMetadatas)); + plugins.AddRange(new JsonRPCPluginLoader().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; + } + + /// + /// get specified plugin, return null if not found + /// + /// + /// + public static PluginPair GetPlugin(string id) + { + return AllPlugins.FirstOrDefault(o => o.Metadata.ID == id); + } + } +} diff --git a/Wox/PluginLoader/PythonPlugin.cs b/Wox.Core/Plugin/PythonPlugin.cs similarity index 87% rename from Wox/PluginLoader/PythonPlugin.cs rename to Wox.Core/Plugin/PythonPlugin.cs index b62bd32182..7704ea7a3d 100644 --- a/Wox/PluginLoader/PythonPlugin.cs +++ b/Wox.Core/Plugin/PythonPlugin.cs @@ -1,17 +1,14 @@ -using System.Collections.Generic; -using System.Diagnostics; +using System.Diagnostics; using System.IO; -using Wox.Helper; -using Wox.Infrastructure; +using System.Reflection; using Wox.Infrastructure.Http; -using Wox.JsonRPC; using Wox.Plugin; -namespace Wox.PluginLoader +namespace Wox.Core.Plugin { - public class PythonPlugin : BasePlugin + internal class PythonPlugin : JsonRPCPlugin { - private static string woxDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath); + private static string woxDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); private ProcessStartInfo startInfo; public override string SupportedLanguage @@ -57,7 +54,7 @@ namespace Wox.PluginLoader return Execute(startInfo); } - protected override string ExecuteAction(JsonRPCRequestModel rpcRequest) + protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest) { startInfo.FileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe"); startInfo.Arguments = string.Format("-B \"{0}\" \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath, rpcRequest); diff --git a/Wox.Core/Properties/AssemblyInfo.cs b/Wox.Core/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..dd5baa0e63 --- /dev/null +++ b/Wox.Core/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Wox.Core")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Oracle Corporation")] +[assembly: AssemblyProduct("Wox.Core")] +[assembly: AssemblyCopyright("Copyright © Oracle Corporation 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("693aa0e5-741b-4759-b740-fdbb011a3280")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wox.Core/README.txt b/Wox.Core/README.txt new file mode 100644 index 0000000000..3cd91680db --- /dev/null +++ b/Wox.Core/README.txt @@ -0,0 +1,4 @@ +What does Wox.Core do? + +* Handle Query +* Loading Plugins \ No newline at end of file diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj new file mode 100644 index 0000000000..34f0938d78 --- /dev/null +++ b/Wox.Core/Wox.Core.csproj @@ -0,0 +1,86 @@ + + + + + Debug + AnyCPU + {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2} + Library + Properties + Wox.Core + Wox.Core + v3.5 + 512 + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + + + + + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} + Wox.Infrastructure + + + {69ce0206-cb41-453d-88af-df86092ef9b8} + Wox.Plugin.SystemPlugins + + + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + Wox.Plugin + + + + + + + + + \ No newline at end of file diff --git a/Wox.Core/packages.config b/Wox.Core/packages.config new file mode 100644 index 0000000000..4185726464 --- /dev/null +++ b/Wox.Core/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Wox.sln b/Wox.sln index 120076914c..7ef3724a6f 100644 --- a/Wox.sln +++ b/Wox.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 +VisualStudioVersion = 12.0.21005.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Test", "Wox.Test\Wox.Test.csproj", "{FF742965-9A80-41A5-B042-D6C7D3A21708}" EndProject @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Infrastructure", "Wox.I 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 Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -47,6 +49,10 @@ 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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Wox/ActionKeyword.xaml.cs b/Wox/ActionKeyword.xaml.cs index a2a1037434..4851a979b6 100644 --- a/Wox/ActionKeyword.xaml.cs +++ b/Wox/ActionKeyword.xaml.cs @@ -11,9 +11,9 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using Wox.Core.Plugin; using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; -using Wox.PluginLoader; using MessageBox = System.Windows.MessageBox; namespace Wox @@ -25,7 +25,7 @@ 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"); @@ -56,7 +56,7 @@ namespace Wox } //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"); return; 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..825f4439f6 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(); } } } diff --git a/Wox/Commands/CommandFactory.cs b/Wox/Commands/CommandFactory.cs index fc18439b46..b7b2eb9c20 100644 --- a/Wox/Commands/CommandFactory.cs +++ b/Wox/Commands/CommandFactory.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Wox.Core.Plugin; using Wox.Helper; using Wox.Plugin; -using Wox.PluginLoader; namespace Wox.Commands { @@ -15,7 +15,7 @@ namespace Wox.Commands public static void DispatchCommand(Query query) { - if (Plugins.HitThirdpartyKeyword(query)) + if (PluginManager.HitThirdpartyKeyword(query)) { pluginCmd.Dispatch(query); } diff --git a/Wox/Commands/PluginCommand.cs b/Wox/Commands/PluginCommand.cs index 34707e9daa..d233f766b9 100644 --- a/Wox/Commands/PluginCommand.cs +++ b/Wox/Commands/PluginCommand.cs @@ -2,11 +2,11 @@ using System.Collections.Generic; using System.Linq; using System.Threading; +using Wox.Core.Plugin; using Wox.Helper; using Wox.Infrastructure.Logger; using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; -using Wox.PluginLoader; namespace Wox.Commands { @@ -14,7 +14,7 @@ namespace Wox.Commands { public override void Dispatch(Query query) { - PluginPair thirdPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionName); + PluginPair thirdPlugin = PluginManager.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); diff --git a/Wox/Commands/SystemCommand.cs b/Wox/Commands/SystemCommand.cs index a1fc477a82..d1ca9eb4fc 100644 --- a/Wox/Commands/SystemCommand.cs +++ b/Wox/Commands/SystemCommand.cs @@ -3,16 +3,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; +using Wox.Core.Plugin; 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); + private IEnumerable allSytemPlugins = PluginManager.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System); public override void Dispatch(Query query) { diff --git a/Wox/Helper/PluginInstaller.cs b/Wox/Helper/PluginInstaller.cs index 15c6e55129..ed66f5eb24 100644 --- a/Wox/Helper/PluginInstaller.cs +++ b/Wox/Helper/PluginInstaller.cs @@ -5,8 +5,8 @@ using System.Linq; using System.Windows; using ICSharpCode.SharpZipLib.Zip; using Newtonsoft.Json; +using Wox.Core.Plugin; using Wox.Plugin; -using Wox.PluginLoader; namespace Wox.Helper { @@ -57,7 +57,7 @@ namespace Wox.Helper string content = string.Format( "Do you want to install following plugin?\r\n\r\nName: {0}\r\nVersion: {1}\r\nAuthor: {2}", plugin.Name, plugin.Version, plugin.Author); - PluginPair existingPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ID == plugin.ID); + PluginPair existingPlugin = PluginManager.GetPlugin(plugin.ID); if (existingPlugin != null) { diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 27b395354d..3fe95171dc 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -15,14 +15,13 @@ using WindowsInput.Native; using NHotkey; using NHotkey.Wpf; using Wox.Commands; +using Wox.Core.Plugin; 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.Update; using Application = System.Windows.Application; using Brushes = System.Windows.Media.Brushes; @@ -128,12 +127,12 @@ namespace Wox public void ReloadPlugins() { - Dispatcher.Invoke(new Action(Plugins.Init)); + Dispatcher.Invoke(new Action(PluginManager.Init)); } public List GetAllPlugins() { - return Plugins.AllPlugins; + return PluginManager.AllPlugins; } public event WoxKeyDownEventHandler BackKeyDownEvent; @@ -193,7 +192,7 @@ namespace Wox ThreadPool.QueueUserWorkItem(o => { Thread.Sleep(50); - Plugins.Init(); + PluginManager.Init(); }); ThreadPool.QueueUserWorkItem(o => { @@ -360,7 +359,7 @@ namespace Wox var q = new Query(lastQuery); CommandFactory.DispatchCommand(q); BackToResultMode(); - if (Plugins.HitThirdpartyKeyword(q)) + if (PluginManager.HitThirdpartyKeyword(q)) { Dispatcher.DelayInvoke("ShowProgressbar", originQuery => { 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/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 4c752ad13c..a356bdec9c 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -11,11 +11,11 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using IWshRuntimeLibrary; +using Wox.Core.Plugin; using Wox.Infrastructure.Storage.UserSettings; 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; @@ -187,7 +187,7 @@ namespace Wox new CollectionContainer { Collection = - PluginLoader.Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System) + PluginManager.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System) .Select(o => o.Plugin) .Cast() }, @@ -195,7 +195,7 @@ namespace Wox new CollectionContainer { Collection = - PluginLoader.Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.ThirdParty) + PluginManager.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.ThirdParty) } }; lbPlugins.ItemsSource = plugins; @@ -576,7 +576,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; } } diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index cca06f9642..66bb922123 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -153,17 +153,9 @@ HotkeyControl.xaml - Msg.xaml - - - - - - - ResultPanel.xaml @@ -272,6 +264,10 @@ + + {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2} + Wox.Core + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} Wox.Infrastructure From ccc8d7e5cdf637d6f4572859f6fd3142a39ad353 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Fri, 26 Dec 2014 22:51:04 +0800 Subject: [PATCH 02/38] Refactoring. --- Plugins/Wox.Plugin.PluginManagement/Main.cs | 8 +++--- Wox.Core/Plugin/JsonRPCPlugin.cs | 13 +++++---- Wox.Core/Plugin/PluginConfig.cs | 6 ++-- Wox.Core/Plugin/PluginManager.cs | 28 +++++++++++++------ .../QueryDispatcher/IQueryDispatcher.cs | 7 +++++ .../Plugin/QueryDispatcher/QueryDispatcher.cs | 21 ++++++++++++++ .../SystemPluginQueryDispatcher.cs | 13 ++++----- .../UserPluginQueryDispatcher.cs | 22 +++++++-------- Wox.Core/README.txt | 2 +- Wox.Core/Wox.Core.csproj | 7 ++++- Wox.Infrastructure/ChineseToPinYin.cs | 15 ---------- Wox.Infrastructure/Wox.Infrastructure.csproj | 11 +++----- .../Program/ProgramSetting.xaml | 3 +- .../Program}/StringEmptyConverter.cs | 5 +--- ...ginIndicator.cs => UserPluginIndicator.cs} | 2 +- .../Wox.Plugin.SystemPlugins.csproj | 3 +- Wox.Plugin/IPublicAPI.cs | 7 ++++- Wox.Plugin/PluginType.cs | 2 +- Wox/CommandArgs/ReloadPluginCommandArg.cs | 2 +- Wox/Commands/BaseCommand.cs | 18 ------------ Wox/Commands/CommandFactory.cs | 28 ------------------- Wox/Helper/PluginInstaller.cs | 2 +- Wox/ImageLoader/ImageCacheStroage.cs | 4 +-- Wox/MainWindow.xaml.cs | 10 +++---- Wox/SettingWindow.xaml.cs | 2 +- .../Storage/UserSelectedRecordStorage.cs | 7 ++--- Wox/Wox.csproj | 5 +--- 27 files changed, 114 insertions(+), 139 deletions(-) create mode 100644 Wox.Core/Plugin/QueryDispatcher/IQueryDispatcher.cs create mode 100644 Wox.Core/Plugin/QueryDispatcher/QueryDispatcher.cs rename Wox/Commands/SystemCommand.cs => Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs (79%) rename Wox/Commands/PluginCommand.cs => Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs (57%) delete mode 100644 Wox.Infrastructure/ChineseToPinYin.cs rename {Wox.Infrastructure => Wox.Plugin.SystemPlugins/Program}/StringEmptyConverter.cs (87%) rename Wox.Plugin.SystemPlugins/{ThirdpartyPluginIndicator.cs => UserPluginIndicator.cs} (97%) delete mode 100644 Wox/Commands/BaseCommand.cs delete mode 100644 Wox/Commands/CommandFactory.cs rename {Wox.Infrastructure => Wox}/Storage/UserSelectedRecordStorage.cs (88%) diff --git a/Plugins/Wox.Plugin.PluginManagement/Main.cs b/Plugins/Wox.Plugin.PluginManagement/Main.cs index 960a2c328c..a2153610d7 100644 --- a/Plugins/Wox.Plugin.PluginManagement/Main.cs +++ b/Plugins/Wox.Plugin.PluginManagement/Main.cs @@ -197,7 +197,7 @@ namespace Wox.Plugin.PluginManagement private List ListUnInstalledPlugins(Query query) { List results = new List(); - List allInstalledPlugins = ParseThirdPartyPlugins(); + List allInstalledPlugins = ParseUserPlugins(); if (query.ActionParameters.Count > 1) { string pluginName = query.ActionParameters[1]; @@ -235,7 +235,7 @@ namespace Wox.Plugin.PluginManagement private List ListInstalledPlugins() { List results = new List(); - foreach (PluginMetadata plugin in ParseThirdPartyPlugins()) + foreach (PluginMetadata plugin in ParseUserPlugins()) { results.Add(new Result() { @@ -247,7 +247,7 @@ namespace Wox.Plugin.PluginManagement return results; } - private static List ParseThirdPartyPlugins() + private static List ParseUserPlugins() { List pluginMetadatas = new List(); if (!Directory.Exists(PluginPath)) @@ -276,7 +276,7 @@ namespace Wox.Plugin.PluginManagement try { metadata = JsonConvert.DeserializeObject(File.ReadAllText(configPath)); - metadata.PluginType = PluginType.ThirdParty; + metadata.PluginType = PluginType.User; metadata.PluginDirectory = pluginDirectory; } catch (Exception) diff --git a/Wox.Core/Plugin/JsonRPCPlugin.cs b/Wox.Core/Plugin/JsonRPCPlugin.cs index 1b878dfce3..0809826300 100644 --- a/Wox.Core/Plugin/JsonRPCPlugin.cs +++ b/Wox.Core/Plugin/JsonRPCPlugin.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.IO; using System.Reflection; using System.Threading; +using System.Windows.Forms; using Newtonsoft.Json; using Wox.Infrastructure.Exceptions; using Wox.Infrastructure.Logger; @@ -74,7 +75,6 @@ namespace Wox.Core.Plugin } catch (Exception e) { - ErrorReporting.TryShowErrorMessageBox(e.Message, e); Log.Error(e.Message); } } @@ -83,12 +83,12 @@ namespace Wox.Core.Plugin private void ExecuteWoxAPI(string method, object[] parameters) { - MethodInfo methodInfo = App.Window.GetType().GetMethod(method); - if (methodInfo != null) + MethodInfo methodInfo = PluginManager.API.GetType().GetMethod(method); + if (methodInfo != null) { try { - methodInfo.Invoke(App.Window, parameters); + methodInfo.Invoke(PluginManager.API, parameters); } catch (Exception) { @@ -132,7 +132,7 @@ namespace Wox.Core.Plugin string result = reader.ReadToEnd(); if (result.StartsWith("DEBUG:")) { - System.Windows.Forms.MessageBox.Show(new Form { TopMost = true }, result.Substring(6)); + MessageBox.Show(new Form { TopMost = true }, result.Substring(6)); return ""; } if (string.IsNullOrEmpty(result)) @@ -142,7 +142,8 @@ namespace Wox.Core.Plugin string error = errorReader.ReadToEnd(); if (!string.IsNullOrEmpty(error)) { - ErrorReporting.TryShowErrorMessageBox(error, new WoxJsonRPCException(error)); + //todo: + // ErrorReporting.TryShowErrorMessageBox(error, new WoxJsonRPCException(error)); } } } diff --git a/Wox.Core/Plugin/PluginConfig.cs b/Wox.Core/Plugin/PluginConfig.cs index 0359ef6483..5d6c8137d4 100644 --- a/Wox.Core/Plugin/PluginConfig.cs +++ b/Wox.Core/Plugin/PluginConfig.cs @@ -28,7 +28,7 @@ namespace Wox.Core.Plugin ParseSystemPlugins(); foreach (string pluginDirectory in pluginDirectories) { - ParseThirdPartyPlugins(pluginDirectory); + ParseUserPlugins(pluginDirectory); } if (PluginManager.DebuggerMode != null) @@ -56,7 +56,7 @@ namespace Wox.Core.Plugin }); } - private static void ParseThirdPartyPlugins(string pluginDirectory) + private static void ParseUserPlugins(string pluginDirectory) { string[] directories = Directory.GetDirectories(pluginDirectory); @@ -88,7 +88,7 @@ namespace Wox.Core.Plugin try { metadata = JsonConvert.DeserializeObject(File.ReadAllText(configPath)); - metadata.PluginType = PluginType.ThirdParty; + metadata.PluginType = PluginType.User; metadata.PluginDirectory = pluginDirectory; } catch (Exception) diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 91af115ba8..e3b0217869 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -15,8 +15,10 @@ namespace Wox.Core.Plugin public static class PluginManager { public static String DebuggerMode { get; private set; } + public static IPublicAPI API { get; private set; } + private static List plugins = new List(); - + /// /// Directories that will hold Wox plugin directory /// @@ -26,10 +28,14 @@ namespace Wox.Core.Plugin { pluginDirectories.Add( Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Plugins")); - pluginDirectories.Add( - Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), ".Wox"),"Plugins")); - MakesurePluginDirectoriesExist(); + string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE"); + if (userProfilePath != null) + { + pluginDirectories.Add(Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Plugins")); + } + + MakesurePluginDirectoriesExist(); } private static void MakesurePluginDirectoriesExist() @@ -46,8 +52,9 @@ namespace Wox.Core.Plugin /// /// Load and init all Wox plugins /// - public static void Init() + public static void Init(IPublicAPI api) { + API = api; plugins.Clear(); List pluginMetadatas = PluginConfig.Parse(pluginDirectories); @@ -61,11 +68,16 @@ namespace Wox.Core.Plugin { CurrentPluginMetadata = pair.Metadata, Proxy = HttpProxy.Instance, - API = App.Window + API = API })); } } + public static void Query(Query query) + { + QueryDispatcher.QueryDispatcher.Dispatch(query); + } + public static List AllPlugins { get @@ -74,11 +86,11 @@ namespace Wox.Core.Plugin } } - public static bool HitThirdpartyKeyword(Query query) + public static bool IsUserPluginQuery(Query query) { if (string.IsNullOrEmpty(query.ActionName)) return false; - return plugins.Any(o => o.Metadata.PluginType == PluginType.ThirdParty && o.Metadata.ActionKeyword == query.ActionName); + return plugins.Any(o => o.Metadata.PluginType == PluginType.User && o.Metadata.ActionKeyword == query.ActionName); } public static void ActivatePluginDebugger(string path) diff --git a/Wox.Core/Plugin/QueryDispatcher/IQueryDispatcher.cs b/Wox.Core/Plugin/QueryDispatcher/IQueryDispatcher.cs new file mode 100644 index 0000000000..c5312a0332 --- /dev/null +++ b/Wox.Core/Plugin/QueryDispatcher/IQueryDispatcher.cs @@ -0,0 +1,7 @@ +namespace Wox.Core.Plugin.QueryDispatcher +{ + internal interface IQueryDispatcher + { + void Dispatch(Wox.Plugin.Query query); + } +} diff --git a/Wox.Core/Plugin/QueryDispatcher/QueryDispatcher.cs b/Wox.Core/Plugin/QueryDispatcher/QueryDispatcher.cs new file mode 100644 index 0000000000..0e0eb62fb9 --- /dev/null +++ b/Wox.Core/Plugin/QueryDispatcher/QueryDispatcher.cs @@ -0,0 +1,21 @@ + +namespace Wox.Core.Plugin.QueryDispatcher +{ + internal static class QueryDispatcher + { + private static IQueryDispatcher pluginCmd = new UserPluginQueryDispatcher(); + private static IQueryDispatcher systemCmd = new SystemPluginQueryDispatcher(); + + public static void Dispatch(Wox.Plugin.Query query) + { + if (PluginManager.IsUserPluginQuery(query)) + { + pluginCmd.Dispatch(query); + } + else + { + systemCmd.Dispatch(query); + } + } + } +} diff --git a/Wox/Commands/SystemCommand.cs b/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs similarity index 79% rename from Wox/Commands/SystemCommand.cs rename to Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs index d1ca9eb4fc..b72c2e0760 100644 --- a/Wox/Commands/SystemCommand.cs +++ b/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs @@ -1,20 +1,17 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading; -using Wox.Core.Plugin; using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; using Wox.Plugin.SystemPlugins; -namespace Wox.Commands +namespace Wox.Core.Plugin.QueryDispatcher { - public class SystemCommand : BaseCommand + public class SystemPluginQueryDispatcher : IQueryDispatcher { private IEnumerable allSytemPlugins = PluginManager.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System); - public override void Dispatch(Query query) + public void Dispatch(Query query) { var queryPlugins = allSytemPlugins; if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == query.ActionName && o.Enabled)) @@ -34,7 +31,7 @@ namespace Wox.Commands List results = pair1.Plugin.Query(query); results.ForEach(o => { o.AutoAjustScore = true; }); - App.Window.PushResults(query, pair1.Metadata, results); + PluginManager.API.PushResults(query, pair1.Metadata, results); }); } } diff --git a/Wox/Commands/PluginCommand.cs b/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs similarity index 57% rename from Wox/Commands/PluginCommand.cs rename to Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs index d233f766b9..6c709e5bdc 100644 --- a/Wox/Commands/PluginCommand.cs +++ b/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs @@ -2,26 +2,24 @@ using System.Collections.Generic; using System.Linq; using System.Threading; -using Wox.Core.Plugin; -using Wox.Helper; using Wox.Infrastructure.Logger; using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; -namespace Wox.Commands +namespace Wox.Core.Plugin.QueryDispatcher { - public class PluginCommand : BaseCommand + public class UserPluginQueryDispatcher : IQueryDispatcher { - public override void Dispatch(Query query) + public void Dispatch(Query query) { - PluginPair thirdPlugin = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionName); - if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword)) + PluginPair userPlugin = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionName); + if (userPlugin != null && !string.IsNullOrEmpty(userPlugin.Metadata.ActionKeyword)) { - var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == thirdPlugin.Metadata.ID); + var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == userPlugin.Metadata.ID); if (customizedPluginConfig != null && customizedPluginConfig.Disabled) { //need to stop the loading animation - UpdateResultView(null); + PluginManager.API.StopLoadingBar(); return; } @@ -29,12 +27,12 @@ namespace Wox.Commands { try { - List results = thirdPlugin.Plugin.Query(query) ?? new List(); - App.Window.PushResults(query,thirdPlugin.Metadata,results); + List results = userPlugin.Plugin.Query(query) ?? new List(); + PluginManager.API.PushResults(query,userPlugin.Metadata,results); } catch (Exception queryException) { - Log.Error(string.Format("Plugin {0} query failed: {1}", thirdPlugin.Metadata.Name, + Log.Error(string.Format("Plugin {0} query failed: {1}", userPlugin.Metadata.Name, queryException.Message)); #if (DEBUG) { diff --git a/Wox.Core/README.txt b/Wox.Core/README.txt index 3cd91680db..5a0b695dc5 100644 --- a/Wox.Core/README.txt +++ b/Wox.Core/README.txt @@ -1,4 +1,4 @@ What does Wox.Core do? * Handle Query -* Loading Plugins \ No newline at end of file +* Loading Plugins (including system plugin and user plugin) \ No newline at end of file diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index 34f0938d78..ec5cf28ca2 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -18,7 +18,7 @@ true full false - bin\Debug\ + ..\Output\Debug\ DEBUG;TRACE prompt 4 @@ -38,12 +38,17 @@ + + + + + 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/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index c50978f96d..e3cfa6398a 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -67,21 +67,18 @@ + + + + - - - - - - - diff --git a/Wox.Plugin.SystemPlugins/Program/ProgramSetting.xaml b/Wox.Plugin.SystemPlugins/Program/ProgramSetting.xaml index ded91a25c2..6f00f4cd5c 100644 --- a/Wox.Plugin.SystemPlugins/Program/ProgramSetting.xaml +++ b/Wox.Plugin.SystemPlugins/Program/ProgramSetting.xaml @@ -4,6 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:infrastructure="clr-namespace:Wox.Infrastructure;assembly=Wox.Infrastructure" + xmlns:program="clr-namespace:Wox.Plugin.SystemPlugins.Program" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="600"> @@ -26,7 +27,7 @@ - + diff --git a/Wox.Infrastructure/StringEmptyConverter.cs b/Wox.Plugin.SystemPlugins/Program/StringEmptyConverter.cs similarity index 87% rename from Wox.Infrastructure/StringEmptyConverter.cs rename to Wox.Plugin.SystemPlugins/Program/StringEmptyConverter.cs index f553695737..c2d5366306 100644 --- a/Wox.Infrastructure/StringEmptyConverter.cs +++ b/Wox.Plugin.SystemPlugins/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.SystemPlugins.Program { public class StringEmptyConverter : MarkupExtension, IValueConverter { diff --git a/Wox.Plugin.SystemPlugins/ThirdpartyPluginIndicator.cs b/Wox.Plugin.SystemPlugins/UserPluginIndicator.cs similarity index 97% rename from Wox.Plugin.SystemPlugins/ThirdpartyPluginIndicator.cs rename to Wox.Plugin.SystemPlugins/UserPluginIndicator.cs index 31e3ab0acf..cc1d492a3b 100644 --- a/Wox.Plugin.SystemPlugins/ThirdpartyPluginIndicator.cs +++ b/Wox.Plugin.SystemPlugins/UserPluginIndicator.cs @@ -8,7 +8,7 @@ using Wox.Infrastructure.Storage.UserSettings; namespace Wox.Plugin.SystemPlugins { - public class ThirdpartyPluginIndicator : BaseSystemPlugin + public class UserPluginIndicator : BaseSystemPlugin { private List allPlugins = new List(); private PluginInitContext context; diff --git a/Wox.Plugin.SystemPlugins/Wox.Plugin.SystemPlugins.csproj b/Wox.Plugin.SystemPlugins/Wox.Plugin.SystemPlugins.csproj index 7fb13e044d..75604f9377 100644 --- a/Wox.Plugin.SystemPlugins/Wox.Plugin.SystemPlugins.csproj +++ b/Wox.Plugin.SystemPlugins/Wox.Plugin.SystemPlugins.csproj @@ -86,6 +86,7 @@ ProgramSuffixes.xaml + @@ -102,7 +103,7 @@ - + diff --git a/Wox.Plugin/IPublicAPI.cs b/Wox.Plugin/IPublicAPI.cs index 64ff13ab08..5ae94e0a40 100644 --- a/Wox.Plugin/IPublicAPI.cs +++ b/Wox.Plugin/IPublicAPI.cs @@ -6,7 +6,12 @@ namespace Wox.Plugin { public interface IPublicAPI { - + /// + /// Push result to query window + /// + /// + /// + /// void PushResults(Query query,PluginMetadata plugin, List results); bool ShellRun(string cmd, bool runAsAdministrator = false); diff --git a/Wox.Plugin/PluginType.cs b/Wox.Plugin/PluginType.cs index a36cc50b27..d046b579f0 100644 --- a/Wox.Plugin/PluginType.cs +++ b/Wox.Plugin/PluginType.cs @@ -8,6 +8,6 @@ namespace Wox.Plugin public enum PluginType { System, - ThirdParty + User } } diff --git a/Wox/CommandArgs/ReloadPluginCommandArg.cs b/Wox/CommandArgs/ReloadPluginCommandArg.cs index 825f4439f6..f287e08c85 100644 --- a/Wox/CommandArgs/ReloadPluginCommandArg.cs +++ b/Wox/CommandArgs/ReloadPluginCommandArg.cs @@ -15,7 +15,7 @@ namespace Wox.CommandArgs public void Execute(IList args) { - PluginManager.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 b7b2eb9c20..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.Core.Plugin; -using Wox.Helper; -using Wox.Plugin; - -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 (PluginManager.HitThirdpartyKeyword(query)) - { - pluginCmd.Dispatch(query); - } - else - { - systemCmd.Dispatch(query); - } - } - } -} diff --git a/Wox/Helper/PluginInstaller.cs b/Wox/Helper/PluginInstaller.cs index ed66f5eb24..5cc0a9568a 100644 --- a/Wox/Helper/PluginInstaller.cs +++ b/Wox/Helper/PluginInstaller.cs @@ -116,7 +116,7 @@ namespace Wox.Helper try { metadata = JsonConvert.DeserializeObject(File.ReadAllText(configPath)); - metadata.PluginType = PluginType.ThirdParty; + metadata.PluginType = PluginType.User; metadata.PluginDirectory = pluginDirectory; } catch (Exception) diff --git a/Wox/ImageLoader/ImageCacheStroage.cs b/Wox/ImageLoader/ImageCacheStroage.cs index 88526e3e45..a090d95cf9 100644 --- a/Wox/ImageLoader/ImageCacheStroage.cs +++ b/Wox/ImageLoader/ImageCacheStroage.cs @@ -9,8 +9,8 @@ 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 ConfigName diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 3fe95171dc..79befea4d8 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -14,7 +14,6 @@ using WindowsInput; using WindowsInput.Native; using NHotkey; using NHotkey.Wpf; -using Wox.Commands; using Wox.Core.Plugin; using Wox.Helper; using Wox.Infrastructure; @@ -22,6 +21,7 @@ using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; +using Wox.Storage; using Wox.Update; using Application = System.Windows.Application; using Brushes = System.Windows.Media.Brushes; @@ -127,7 +127,7 @@ namespace Wox public void ReloadPlugins() { - Dispatcher.Invoke(new Action(PluginManager.Init)); + Dispatcher.Invoke(new Action(()=> PluginManager.Init(this))); } public List GetAllPlugins() @@ -192,7 +192,7 @@ namespace Wox ThreadPool.QueueUserWorkItem(o => { Thread.Sleep(50); - PluginManager.Init(); + PluginManager.Init(this); }); ThreadPool.QueueUserWorkItem(o => { @@ -357,9 +357,9 @@ namespace Wox }, TimeSpan.FromMilliseconds(100), null); queryHasReturn = false; var q = new Query(lastQuery); - CommandFactory.DispatchCommand(q); + PluginManager.Query(q); BackToResultMode(); - if (PluginManager.HitThirdpartyKeyword(q)) + if (PluginManager.IsUserPluginQuery(q)) { Dispatcher.DelayInvoke("ShowProgressbar", originQuery => { diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index a356bdec9c..c8ae9cd0b3 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -195,7 +195,7 @@ namespace Wox new CollectionContainer { Collection = - PluginManager.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.ThirdParty) + PluginManager.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.User) } }; lbPlugins.ItemsSource = plugins; diff --git a/Wox.Infrastructure/Storage/UserSelectedRecordStorage.cs b/Wox/Storage/UserSelectedRecordStorage.cs similarity index 88% rename from Wox.Infrastructure/Storage/UserSelectedRecordStorage.cs rename to Wox/Storage/UserSelectedRecordStorage.cs index 0b21e320e7..2b6c4d217c 100644 --- a/Wox.Infrastructure/Storage/UserSelectedRecordStorage.cs +++ b/Wox/Storage/UserSelectedRecordStorage.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; using Newtonsoft.Json; using Wox.Infrastructure.Storage; using Wox.Plugin; -namespace Wox.Infrastructure.Storage +namespace Wox.Storage { public class UserSelectedRecordStorage : JsonStrorage { diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 66bb922123..dc218d536d 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -105,6 +105,7 @@ + NewVersionWindow.xaml @@ -124,10 +125,6 @@ - - - - From d9b28633825d075960723a134846e6f8af40ad7e Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sat, 27 Dec 2014 12:34:51 +0800 Subject: [PATCH 03/38] Refactoring. --- .../Plugin}/PluginInstaller.cs | 25 ++--- Wox.Core/Plugin/PluginManager.cs | 31 +++++- .../SystemPluginQueryDispatcher.cs | 2 +- Wox.Core/Wox.Core.csproj | 5 + Wox.Core/packages.config | 1 + .../UserSettings/UserSettingStorage.cs | 10 +- Wox.Plugin/PluginType.cs | 2 +- Wox/CommandArgs/InstallPluginCommandArg.cs | 3 +- Wox/Converters/AsyncConverter.cs | 38 ------- Wox/ImageLoader/ImageLoader.cs | 30 ++--- Wox/MainWindow.xaml.cs | 52 +-------- Wox/SettingWindow.xaml.cs | 17 ++- Wox/ThemeManager.cs | 104 ++++++++++++++++++ Wox/Wox.csproj | 12 +- 14 files changed, 184 insertions(+), 148 deletions(-) rename {Wox/Helper => Wox.Core/Plugin}/PluginInstaller.cs (90%) delete mode 100644 Wox/Converters/AsyncConverter.cs create mode 100644 Wox/ThemeManager.cs diff --git a/Wox/Helper/PluginInstaller.cs b/Wox.Core/Plugin/PluginInstaller.cs similarity index 90% rename from Wox/Helper/PluginInstaller.cs rename to Wox.Core/Plugin/PluginInstaller.cs index 5cc0a9568a..3388c8c621 100644 --- a/Wox/Helper/PluginInstaller.cs +++ b/Wox.Core/Plugin/PluginInstaller.cs @@ -1,18 +1,17 @@ using System; using System.Diagnostics; using System.IO; -using System.Linq; using System.Windows; +using System.Windows.Forms; using ICSharpCode.SharpZipLib.Zip; using Newtonsoft.Json; -using Wox.Core.Plugin; using Wox.Plugin; -namespace Wox.Helper +namespace Wox.Core.Plugin { - public class PluginInstaller + internal class PluginInstaller { - public static void Install(string path) + internal static void Install(string path) { if (File.Exists(path)) { @@ -37,11 +36,7 @@ namespace Wox.Helper return; } - string pluginFolerPath = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Plugins"); - if (!Directory.Exists(pluginFolerPath)) - { - Directory.CreateDirectory(pluginFolerPath); - } + string pluginFolerPath = PluginManager.DefaultPluginDirectory; string newPluginName = plugin.Name .Replace("/", "_") @@ -66,9 +61,9 @@ namespace Wox.Helper plugin.Name, existingPlugin.Metadata.Version, plugin.Version, plugin.Author); } - MessageBoxResult result = MessageBox.Show(content, "Install plugin", - MessageBoxButton.YesNo, MessageBoxImage.Question); - if (result == MessageBoxResult.Yes) + DialogResult result = MessageBox.Show(content, "Install plugin", MessageBoxButtons.YesNo, + MessageBoxIcon.Question); + if (result == DialogResult.Yes) { if (existingPlugin != null && Directory.Exists(existingPlugin.Metadata.PluginDirectory)) { @@ -88,7 +83,7 @@ namespace Wox.Helper // Plugins.Init(); //} if (MessageBox.Show("You have installed plugin " + plugin.Name + " successfully.\r\n Restart Wox to take effect?", "Install plugin", - MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ProcessStartInfo Info = new ProcessStartInfo(); Info.Arguments = "/C ping 127.0.0.1 -n 1 && \"" + @@ -97,7 +92,7 @@ namespace Wox.Helper Info.CreateNoWindow = true; Info.FileName = "cmd.exe"; Process.Start(Info); - App.Window.CloseApp(); + PluginManager.API.CloseApp(); } } } diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index e3b0217869..fbe46db441 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -24,17 +24,31 @@ namespace Wox.Core.Plugin /// private static List pluginDirectories = new List(); + + /// + /// Default plugin directory + /// new plugin will be installed to this directory + /// + public static string DefaultPluginDirectory + { + get + { + string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE"); + if (userProfilePath != null) + { + return Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Plugins"); + } + + return string.Empty; + } + } + static PluginManager() { + pluginDirectories.Add(DefaultPluginDirectory); pluginDirectories.Add( Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Plugins")); - string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE"); - if (userProfilePath != null) - { - pluginDirectories.Add(Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Plugins")); - } - MakesurePluginDirectoriesExist(); } @@ -73,6 +87,11 @@ namespace Wox.Core.Plugin } } + public static void InstallPlugin(string path) + { + PluginInstaller.Install(path); + } + public static void Query(Query query) { QueryDispatcher.QueryDispatcher.Dispatch(query); diff --git a/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs b/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs index b72c2e0760..a20aa8ebf7 100644 --- a/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs +++ b/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs @@ -19,7 +19,7 @@ namespace Wox.Core.Plugin.QueryDispatcher //websearch mode queryPlugins = new List() { - allSytemPlugins.First(o => ((ISystemPlugin)o.Plugin).ID == "565B73353DBF4806919830B9202EE3BF") + allSytemPlugins.First(o => o.Metadata.ID == "565B73353DBF4806919830B9202EE3BF") }; } diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index ec5cf28ca2..237c191560 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -32,6 +32,10 @@ 4 + + False + ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll + False ..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll @@ -45,6 +49,7 @@ + diff --git a/Wox.Core/packages.config b/Wox.Core/packages.config index 4185726464..6311fc40d5 100644 --- a/Wox.Core/packages.config +++ b/Wox.Core/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs b/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs index 229e100a2a..beb156a4fd 100644 --- a/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs +++ b/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs @@ -174,7 +174,15 @@ namespace Wox.Infrastructure.Storage.UserSettings if (string.IsNullOrEmpty(storage.ProgramSuffixes)) { storage.ProgramSuffixes = "lnk;exe;appref-ms;bat"; - } + } + if (storage.QueryBoxFont == null) + { + storage.QueryBoxFont = FontFamily.GenericSansSerif.Name; + } + if (storage.ResultItemFont == null) + { + storage.ResultItemFont = FontFamily.GenericSansSerif.Name; + } } } diff --git a/Wox.Plugin/PluginType.cs b/Wox.Plugin/PluginType.cs index d046b579f0..b8ffc6e124 100644 --- a/Wox.Plugin/PluginType.cs +++ b/Wox.Plugin/PluginType.cs @@ -10,4 +10,4 @@ namespace Wox.Plugin System, User } -} +} \ No newline at end of file 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/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/ImageLoader/ImageLoader.cs b/Wox/ImageLoader/ImageLoader.cs index 5eccebb2b0..55b89da82c 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 { @@ -54,23 +53,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))); } } } @@ -78,7 +74,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) @@ -112,13 +108,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/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 79befea4d8..d192dd9f37 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -122,7 +122,7 @@ namespace Wox public void InstallPlugin(string path) { - Dispatcher.Invoke(new Action(() => PluginInstaller.Install(path))); + Dispatcher.Invoke(new Action(() => PluginManager.InstallPlugin(path))); } public void ReloadPlugins() @@ -172,14 +172,8 @@ namespace Wox pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent; ThreadPool.SetMaxThreads(30, 10); - try - { - SetTheme(UserSettingStorage.Instance.Theme); - } - catch (Exception) - { - SetTheme(UserSettingStorage.Instance.Theme = "Dark"); - } + ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme); + SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey); SetCustomPluginHotkey(); @@ -676,44 +670,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 @@ -739,7 +695,7 @@ namespace Wox string[] files = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop); if (files[0].ToLower().EndsWith(".wox")) { - PluginInstaller.Install(files[0]); + PluginManager.InstallPlugin(files[0]); } else { diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index c8ae9cd0b3..a8107ce46e 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -172,8 +172,7 @@ namespace Wox } //PreviewPanel - App.Window.SetTheme(UserSettingStorage.Instance.Theme); - + ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme); #endregion #region Plugin @@ -366,7 +365,7 @@ namespace Wox private void ThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { string themeName = themeComboBox.SelectedItem.ToString(); - MainWindow.SetTheme(themeName); + ThemeManager.ChangeTheme(themeName); UserSettingStorage.Instance.Theme = themeName; UserSettingStorage.Instance.Save(); } @@ -379,7 +378,7 @@ namespace Wox this.cbQueryBoxFontFaces.SelectedItem = ((FontFamily)cbQueryBoxFont.SelectedItem).ChooseRegularFamilyTypeface(); UserSettingStorage.Instance.Save(); - App.Window.SetTheme(UserSettingStorage.Instance.Theme); + ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme); } private void CbQueryBoxFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e) @@ -399,7 +398,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.ChangeTheme(UserSettingStorage.Instance.Theme); } } @@ -411,7 +410,7 @@ namespace Wox this.cbResultItemFontFaces.SelectedItem = ((FontFamily)cbResultItemFont.SelectedItem).ChooseRegularFamilyTypeface(); UserSettingStorage.Instance.Save(); - App.Window.SetTheme(UserSettingStorage.Instance.Theme); + ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme); } private void CbResultItemFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e) @@ -422,8 +421,6 @@ namespace Wox { if (cbResultItemFontFaces.Items.Count > 0) cbResultItemFontFaces.SelectedIndex = 0; - - return; } else { @@ -431,7 +428,7 @@ namespace Wox UserSettingStorage.Instance.ResultItemFontWeight = typeface.Weight.ToString(); UserSettingStorage.Instance.ResultItemFontStyle = typeface.Style.ToString(); UserSettingStorage.Instance.Save(); - App.Window.SetTheme(UserSettingStorage.Instance.Theme); + ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme); } } @@ -445,7 +442,7 @@ namespace Wox else PreviewMainPanel.Opacity = 1; - App.Window.SetTheme(UserSettingStorage.Instance.Theme); + ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme); } #endregion diff --git a/Wox/ThemeManager.cs b/Wox/ThemeManager.cs new file mode 100644 index 0000000000..ce30c8161a --- /dev/null +++ b/Wox/ThemeManager.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using Wox.Helper; +using Wox.Infrastructure.Storage.UserSettings; + +namespace Wox +{ + internal class ThemeManager + { + private static List themeDirectories = new List(); + + static ThemeManager() + { + themeDirectories.Add( + Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Themes")); + + string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE"); + if (userProfilePath != null) + { + themeDirectories.Add(Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Themes")); + } + + MakesureThemeDirectoriesExist(); + } + + private static void MakesureThemeDirectoriesExist() + { + foreach (string pluginDirectory in themeDirectories) + { + if (!Directory.Exists(pluginDirectory)) + { + Directory.CreateDirectory(pluginDirectory); + } + } + } + + public static void ChangeTheme(string themeName) + { + string themePath = GetThemePath(themeName); + if (string.IsNullOrEmpty(themePath)) + { + themePath = GetThemePath("Dark"); + if (string.IsNullOrEmpty(themePath)) + { + throw new Exception("Change theme failed"); + } + } + + var dict = new ResourceDictionary + { + Source = new Uri(themePath, 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); + + } + + private static string GetThemePath(string themeName) + { + foreach (string themeDirectory in themeDirectories) + { + string path = Path.Combine(themeDirectory, themeName + ".xaml"); + if (File.Exists(path)) + { + return path; + } + } + + return string.Empty; + } + } +} diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index dc218d536d..b4e29e6d42 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -106,6 +106,7 @@ + NewVersionWindow.xaml @@ -125,7 +126,6 @@ - @@ -145,7 +145,6 @@ - HotkeyControl.xaml @@ -202,11 +201,6 @@ Designer MSBuild:Compile - - MSBuild:Compile - Designer - PreserveNewest - MSBuild:Compile Designer @@ -227,6 +221,10 @@ Designer PreserveNewest + + MSBuild:Compile + Designer + Designer MSBuild:Compile From 890397bae7061cdd8d05acefa4d1bd58c46eeb9e Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sun, 28 Dec 2014 15:17:58 +0800 Subject: [PATCH 04/38] Refactoring. Move plugin related work to Wox.Core --- Wox.Core/Exception/WoxCritialException.cs | 17 +++++++++++++++++ Wox.Core/Exception/WoxException.cs | 14 ++++++++++++++ .../Exception}/WoxHttpException.cs | 7 +------ .../Exception}/WoxJsonRPCException.cs | 2 +- Wox.Core/Plugin/CSharpPluginLoader.cs | 2 +- Wox.Core/Plugin/JsonRPCPlugin.cs | 5 ++--- Wox.Core/Plugin/JsonRPCPluginLoader.cs | 2 +- Wox.Core/Plugin/PluginConfig.cs | 4 ++-- Wox.Core/Plugin/PluginInstaller.cs | 8 ++++---- .../UserPluginQueryDispatcher.cs | 2 +- Wox.Core/Wox.Core.csproj | 4 ++++ Wox.Infrastructure/Exceptions/WoxException.cs | 13 ------------- Wox.Infrastructure/Wox.Infrastructure.csproj | 3 --- .../ControlPanel/ControlPanelItem.cs | 2 +- 14 files changed, 49 insertions(+), 36 deletions(-) create mode 100644 Wox.Core/Exception/WoxCritialException.cs create mode 100644 Wox.Core/Exception/WoxException.cs rename {Wox.Infrastructure/Exceptions => Wox.Core/Exception}/WoxHttpException.cs (51%) rename {Wox.Infrastructure/Exceptions => Wox.Core/Exception}/WoxJsonRPCException.cs (78%) delete mode 100644 Wox.Infrastructure/Exceptions/WoxException.cs diff --git a/Wox.Core/Exception/WoxCritialException.cs b/Wox.Core/Exception/WoxCritialException.cs new file mode 100644 index 0000000000..76aea3dea6 --- /dev/null +++ b/Wox.Core/Exception/WoxCritialException.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Wox.Core.Exception +{ + /// + /// Represent exceptions that wox can't handle and MUST close running Wox. + /// + public class WoxCritialException : WoxException + { + public WoxCritialException(string msg) : base(msg) + { + } + } +} diff --git a/Wox.Core/Exception/WoxException.cs b/Wox.Core/Exception/WoxException.cs new file mode 100644 index 0000000000..a5df7a3d34 --- /dev/null +++ b/Wox.Core/Exception/WoxException.cs @@ -0,0 +1,14 @@ +namespace Wox.Core.Exception +{ + /// + /// Base Wox Exceptions + /// + public class WoxException : System.Exception + { + public WoxException(string msg) + : base(msg) + { + + } + } +} diff --git a/Wox.Infrastructure/Exceptions/WoxHttpException.cs b/Wox.Core/Exception/WoxHttpException.cs similarity index 51% rename from Wox.Infrastructure/Exceptions/WoxHttpException.cs rename to Wox.Core/Exception/WoxHttpException.cs index 026d1d8ab9..55e3431a0e 100644 --- a/Wox.Infrastructure/Exceptions/WoxHttpException.cs +++ b/Wox.Core/Exception/WoxHttpException.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Wox.Infrastructure.Exceptions +namespace Wox.Core.Exception { public class WoxHttpException :WoxException { diff --git a/Wox.Infrastructure/Exceptions/WoxJsonRPCException.cs b/Wox.Core/Exception/WoxJsonRPCException.cs similarity index 78% rename from Wox.Infrastructure/Exceptions/WoxJsonRPCException.cs rename to Wox.Core/Exception/WoxJsonRPCException.cs index 0e984a3e6f..d3c0bfb0da 100644 --- a/Wox.Infrastructure/Exceptions/WoxJsonRPCException.cs +++ b/Wox.Core/Exception/WoxJsonRPCException.cs @@ -1,4 +1,4 @@ -namespace Wox.Infrastructure.Exceptions +namespace Wox.Core.Exception { public class WoxJsonRPCException : WoxException { diff --git a/Wox.Core/Plugin/CSharpPluginLoader.cs b/Wox.Core/Plugin/CSharpPluginLoader.cs index 9cfdc56734..5910a6bebf 100644 --- a/Wox.Core/Plugin/CSharpPluginLoader.cs +++ b/Wox.Core/Plugin/CSharpPluginLoader.cs @@ -44,7 +44,7 @@ namespace Wox.Core.Plugin plugins.Add(pair); } } - catch (Exception e) + catch (System.Exception e) { Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message)); #if (DEBUG) diff --git a/Wox.Core/Plugin/JsonRPCPlugin.cs b/Wox.Core/Plugin/JsonRPCPlugin.cs index 0809826300..fd0514af36 100644 --- a/Wox.Core/Plugin/JsonRPCPlugin.cs +++ b/Wox.Core/Plugin/JsonRPCPlugin.cs @@ -6,7 +6,6 @@ using System.Reflection; using System.Threading; using System.Windows.Forms; using Newtonsoft.Json; -using Wox.Infrastructure.Exceptions; using Wox.Infrastructure.Logger; using Wox.Plugin; @@ -73,7 +72,7 @@ namespace Wox.Core.Plugin } return results; } - catch (Exception e) + catch (System.Exception e) { Log.Error(e.Message); } @@ -90,7 +89,7 @@ namespace Wox.Core.Plugin { methodInfo.Invoke(PluginManager.API, parameters); } - catch (Exception) + catch (System.Exception) { #if (DEBUG) { diff --git a/Wox.Core/Plugin/JsonRPCPluginLoader.cs b/Wox.Core/Plugin/JsonRPCPluginLoader.cs index 234da6a25d..0bf35979c9 100644 --- a/Wox.Core/Plugin/JsonRPCPluginLoader.cs +++ b/Wox.Core/Plugin/JsonRPCPluginLoader.cs @@ -13,7 +13,7 @@ namespace Wox.Core.Plugin return jsonRPCPluginMetadatas.Select(metadata => new PluginPair() { - Plugin = jsonRPCPlugin, + Plugin = new T(), //every JsonRPC plugin should has its own plugin instance Metadata = metadata }).ToList(); } diff --git a/Wox.Core/Plugin/PluginConfig.cs b/Wox.Core/Plugin/PluginConfig.cs index 5d6c8137d4..6d2cba1488 100644 --- a/Wox.Core/Plugin/PluginConfig.cs +++ b/Wox.Core/Plugin/PluginConfig.cs @@ -4,7 +4,7 @@ using System.IO; using System.Linq; using System.Reflection; using Newtonsoft.Json; -using Wox.Infrastructure.Exceptions; +using Wox.Core.Exception; using Wox.Infrastructure.Logger; using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; @@ -91,7 +91,7 @@ namespace Wox.Core.Plugin metadata.PluginType = PluginType.User; metadata.PluginDirectory = pluginDirectory; } - catch (Exception) + catch (System.Exception) { string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath); Log.Warn(error); diff --git a/Wox.Core/Plugin/PluginInstaller.cs b/Wox.Core/Plugin/PluginInstaller.cs index 3388c8c621..25e7d3b3c1 100644 --- a/Wox.Core/Plugin/PluginInstaller.cs +++ b/Wox.Core/Plugin/PluginInstaller.cs @@ -114,12 +114,12 @@ namespace Wox.Core.Plugin metadata.PluginType = PluginType.User; metadata.PluginDirectory = pluginDirectory; } - catch (Exception) + catch (System.Exception) { string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath); #if (DEBUG) { - throw new Exception(error); + throw new System.Exception(error); } #endif return null; @@ -132,7 +132,7 @@ namespace Wox.Core.Plugin metadata.Language); #if (DEBUG) { - throw new Exception(error); + throw new System.Exception(error); } #endif return null; @@ -143,7 +143,7 @@ namespace Wox.Core.Plugin metadata.ExecuteFilePath); #if (DEBUG) { - throw new Exception(error); + throw new System.Exception(error); } #endif return null; diff --git a/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs b/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs index 6c709e5bdc..3b96d2c3a8 100644 --- a/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs +++ b/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs @@ -30,7 +30,7 @@ namespace Wox.Core.Plugin.QueryDispatcher List results = userPlugin.Plugin.Query(query) ?? new List(); PluginManager.API.PushResults(query,userPlugin.Metadata,results); } - catch (Exception queryException) + catch (System.Exception queryException) { Log.Error(string.Format("Plugin {0} query failed: {1}", userPlugin.Metadata.Name, queryException.Message)); diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index 237c191560..1aacac6d10 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -49,6 +49,10 @@ + + + + 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/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index e3cfa6398a..7c84bf829c 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -56,9 +56,6 @@ - - - diff --git a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs index 6d76e269a0..5781fa2910 100644 --- a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs +++ b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs @@ -22,4 +22,4 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel GUID = newGUID; } } -} +} \ No newline at end of file From ba0bda6aa6645c3459b01ff4f0ece42656fc583f Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Mon, 29 Dec 2014 21:55:27 +0800 Subject: [PATCH 05/38] Update the installer --- Deploy/Installer/Installer.iss | 14 ++++++++--- Wox.Core/Plugin/PluginManager.cs | 3 --- Wox.Core/{README.txt => README.md} | 1 + Wox.Core/Wox.Core.csproj | 2 +- Wox.Infrastructure/Storage/BaseStorage.cs | 29 ++++++++++++++++++----- Wox.Plugin/README.md | 5 ++++ Wox.Plugin/Wox.Plugin.csproj | 3 +++ Wox/App.config | 8 ++++++- Wox/Helper/WoxLogPathConverter.cs | 17 +++++++++++++ Wox/MainWindow.xaml.cs | 1 + Wox/ThemeManager.cs | 3 --- Wox/Wox.csproj | 1 + 12 files changed, 70 insertions(+), 17 deletions(-) rename Wox.Core/{README.txt => README.md} (94%) create mode 100644 Wox.Plugin/README.md create mode 100644 Wox/Helper/WoxLogPathConverter.cs diff --git a/Deploy/Installer/Installer.iss b/Deploy/Installer/Installer.iss index 21f08fd913..253572eef3 100644 --- a/Deploy/Installer/Installer.iss +++ b/Deploy/Installer/Installer.iss @@ -29,11 +29,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\*,Themes\*; DestDir: {app}; Flags: ignoreversion recursesubdirs +Source: {#MyAppPath}\Plugins\*; DestDir: {%USERPROFILE}\.Wox\Plugins; Flags: ignoreversion recursesubdirs +Source: {#MyAppPath}\Themes\*; DestDir: {%USERPROFILE}\.Wox\Themes; Flags: ignoreversion recursesubdirs [Icons] Name: {group}\{#MyAppName}; Filename: {app}\{#MyAppExeName} @@ -42,4 +44,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/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index fbe46db441..70d2918e26 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -46,9 +46,6 @@ namespace Wox.Core.Plugin static PluginManager() { pluginDirectories.Add(DefaultPluginDirectory); - pluginDirectories.Add( - Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Plugins")); - MakesurePluginDirectoriesExist(); } diff --git a/Wox.Core/README.txt b/Wox.Core/README.md similarity index 94% rename from Wox.Core/README.txt rename to Wox.Core/README.md index 5a0b695dc5..2c191d0856 100644 --- a/Wox.Core/README.txt +++ b/Wox.Core/README.md @@ -1,4 +1,5 @@ What does Wox.Core do? +===== * Handle Query * Loading Plugins (including system plugin and user plugin) \ No newline at end of file diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index 1aacac6d10..ce60a7f391 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -69,7 +69,7 @@ - + diff --git a/Wox.Infrastructure/Storage/BaseStorage.cs b/Wox.Infrastructure/Storage/BaseStorage.cs index d899cb6908..c72bf63c35 100644 --- a/Wox.Infrastructure/Storage/BaseStorage.cs +++ b/Wox.Infrastructure/Storage/BaseStorage.cs @@ -10,18 +10,35 @@ 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"); + private string configFolder; + + private string ConfigFolder + { + get + { + if (string.IsNullOrEmpty(configFolder)) + { + string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE"); + if (userProfilePath == null) + { + throw new ArgumentException("Environment variable USERPROFILE is empty"); + } + configFolder = Path.Combine(Path.Combine(userProfilePath, ".Wox"), "Config"); + } + return configFolder; + } + } 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; } @@ -72,9 +89,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.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..d915ddd7bc 100644 --- a/Wox.Plugin/Wox.Plugin.csproj +++ b/Wox.Plugin/Wox.Plugin.csproj @@ -59,6 +59,9 @@ + + + + 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 + + + + About + Website + Version + + \ No newline at end of file diff --git a/Wox/Languages/中文.xaml b/Wox/Languages/中文.xaml new file mode 100644 index 0000000000..243352f307 --- /dev/null +++ b/Wox/Languages/中文.xaml @@ -0,0 +1,51 @@ + + + 通用 + 开机启动 + 失去焦点时自动隐藏Wox + 不显示新版本提示 + 语言 + + + 插件 + 浏览更多插件 + 禁用 + 触发关键字 + 插件目录 + 作者 + + + 主题 + 浏览更多主题 + 你好,Wox + 查询框字体 + 结果项字体 + 窗口模式 + 透明度 + + + 热键 + Wox激活热键 + 自定义查询热键 + 删除 + 编辑 + 增加 + + + 代理 + 启用代理 + 服务器 + 端口 + 用户名 + 密码 + 测试代理 + 保存 + + + 关于 + 网站 + 版本 + + \ No newline at end of file diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 20f6daca39..261a549253 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -174,7 +174,7 @@ namespace Wox ThreadPool.SetMaxThreads(30, 10); ThemeManager.ChangeTheme(UserSettingStorage.Instance.Theme); - + LanguageManager.ChangeLanguage(UserSettingStorage.Instance.Language); SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey); SetCustomPluginHotkey(); diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 1ab4866c0f..8e213dbbd6 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -20,27 +20,31 @@ - + - - Start Wox on system startup + + - Hide Wox when loses focus + - Don't show upgrade msg if new version available + + + + + - + - + @@ -102,14 +106,18 @@ - + - Disable - ActionKeyword: + + + + + + - + @@ -121,14 +129,14 @@ - + - + @@ -150,7 +158,7 @@ - + @@ -159,7 +167,7 @@ - + - + - + Normal LayeredWindow @@ -209,7 +217,7 @@ - + @@ -218,7 +226,7 @@ - + @@ -226,7 +234,7 @@ - + @@ -234,18 +242,18 @@ - + - + - + @@ -258,15 +266,17 @@ - - + + - + @@ -320,10 +330,10 @@ - Website: + - Version: + diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index a8107ce46e..c25849c461 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -70,6 +70,8 @@ namespace Wox cbHideWhenDeactive.IsChecked = UserSettingStorage.Instance.HideWhenDeactive; cbDontPromptUpdateMsg.IsChecked = UserSettingStorage.Instance.DontPromptUpdateMsg; + LoadLanguages(); + #endregion #region Theme @@ -148,7 +150,7 @@ namespace Wox } }); - foreach (string theme in LoadAvailableThemes()) + foreach (string theme in ThemeManager.LoadAvailableThemes()) { string themeName = System.IO.Path.GetFileNameWithoutExtension(theme); themeComboBox.Items.Add(themeName); @@ -240,6 +242,19 @@ namespace Wox settingsLoaded = true; } + private void LoadLanguages() + { + cbLanguages.ItemsSource = LanguageManager.LoadAvailableLanguages(); + cbLanguages.SelectedValue = UserSettingStorage.Instance.Language; + cbLanguages.SelectionChanged += cbLanguages_SelectionChanged; + } + + void cbLanguages_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + string language = cbLanguages.SelectedValue.ToString(); + LanguageManager.ChangeLanguage(language); + } + private void EnableProxy() { tbProxyPassword.IsEnabled = true; @@ -256,12 +271,6 @@ 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(); @@ -319,19 +328,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(LanguageManager.GetTranslation("pleaseSelectAnItem")); + return; + } + + string deleteWarning = string.Format(LanguageManager.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey); + if (MessageBox.Show(deleteWarning, LanguageManager.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) @@ -345,7 +355,7 @@ namespace Wox } else { - MessageBox.Show("Please select an item"); + MessageBox.Show(LanguageManager.GetTranslation("pleaseSelectAnItem")); } } @@ -640,17 +650,17 @@ namespace Wox { if (string.IsNullOrEmpty(tbProxyServer.Text)) { - MessageBox.Show("Server can't be empty"); + MessageBox.Show(LanguageManager.GetTranslation("serverCantBeEmpty")); return; } if (string.IsNullOrEmpty(tbProxyPort.Text)) { - MessageBox.Show("Server port can't be empty"); + MessageBox.Show(LanguageManager.GetTranslation("portCantBeEmpty")); return; } if (!int.TryParse(tbProxyPort.Text, out port)) { - MessageBox.Show("Invalid port format"); + MessageBox.Show(LanguageManager.GetTranslation("invalidPortFormat")); return; } } @@ -661,25 +671,25 @@ namespace Wox UserSettingStorage.Instance.ProxyPassword = tbProxyPassword.Password; UserSettingStorage.Instance.Save(); - MessageBox.Show("Save Proxy Successfully"); + MessageBox.Show(LanguageManager.GetTranslation("saveProxySuccessfully")); } private void btnTestProxy_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(tbProxyServer.Text)) { - MessageBox.Show("Server can't be empty"); + MessageBox.Show(LanguageManager.GetTranslation("serverCantBeEmpty")); return; } if (string.IsNullOrEmpty(tbProxyPort.Text)) { - MessageBox.Show("Server port can't be empty"); + MessageBox.Show(LanguageManager.GetTranslation("portCantBeEmpty")); return; } int port; if (!int.TryParse(tbProxyPort.Text, out port)) { - MessageBox.Show("Invalid port format"); + MessageBox.Show(LanguageManager.GetTranslation("invalidPortFormat")); return; } @@ -697,10 +707,10 @@ 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(LanguageManager.GetTranslation("proxyIsCorrect")); } else { 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"> - +