diff --git a/Plugins/Wox.Plugin.Clipboard/plugin.json b/Plugins/Wox.Plugin.Clipboard/plugin.json index 50f32957f5..112bbf34a3 100644 --- a/Plugins/Wox.Plugin.Clipboard/plugin.json +++ b/Plugins/Wox.Plugin.Clipboard/plugin.json @@ -8,5 +8,4 @@ "Language":"csharp", "Website":"http://www.getwox.com", "ExecuteFileName":"Wox.Plugin.Clipboard.dll" -} - +} \ No newline at end of file diff --git a/Wox.UAC/MainWindow.xaml.cs b/Wox.UAC/MainWindow.xaml.cs index 594161b669..9b8e500fc1 100644 --- a/Wox.UAC/MainWindow.xaml.cs +++ b/Wox.UAC/MainWindow.xaml.cs @@ -1,33 +1,33 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace Wox.UAC { public partial class MainWindow : Window { + PluginInstaller installer = new PluginInstaller(); + public MainWindow() { InitializeComponent(); string[] param = Environment.GetCommandLineArgs(); - if (param.Length > 2) + if (param.Length > 1) { switch (param[1]) { case "UAC": Invoke(param[2], param[3], param[4]); break; + + case "AssociatePluginInstaller": + installer.RegisterInstaller(); + break; + + case "InstallPlugin": + var path = param[2]; + installer.Install(path); + break; } } Application.Current.Shutdown(0); diff --git a/Wox/Helper/PluginInstaller.cs b/Wox.UAC/PluginInstaller.cs similarity index 75% rename from Wox/Helper/PluginInstaller.cs rename to Wox.UAC/PluginInstaller.cs index dfa2f20120..044a84c660 100644 --- a/Wox/Helper/PluginInstaller.cs +++ b/Wox.UAC/PluginInstaller.cs @@ -5,10 +5,10 @@ using System.Runtime.InteropServices; using System.Windows; using ICSharpCode.SharpZipLib.Zip; using Microsoft.Win32; -using Wox.Infrastructure; +using Newtonsoft.Json; using Wox.Plugin; -namespace Wox.Helper +namespace Wox.UAC { public class PluginInstaller { @@ -51,7 +51,7 @@ namespace Wox.Helper openKey = shellKey.OpenSubKey("open", true); openKey.CreateSubKey("command"); RegistryKey commandKey = openKey.OpenSubKey("command", true); - string pathString = "\"" + filePath + "\" \"%1\""; + string pathString = "\"" + filePath + "\" \"installPlugin\" \"%1\""; commandKey.SetValue("", pathString); //refresh cache @@ -60,51 +60,51 @@ namespace Wox.Helper public void RegisterInstaller() { - string filePath = Directory.GetCurrentDirectory() + "\\Wox.Installer.exe"; + string filePath = Directory.GetCurrentDirectory() + "\\Wox.UAC.exe"; string iconPath = Directory.GetCurrentDirectory() + "\\app.ico"; - SaveReg(filePath, ".wox", iconPath, false); + SaveReg(filePath, ".wox", iconPath, true); } public void Install(string path) { if (File.Exists(path)) { - string tempFoler = System.IO.Path.GetTempPath() + "\\wox\\workflows"; + string tempFoler = System.IO.Path.GetTempPath() + "\\wox\\plugins"; if (Directory.Exists(tempFoler)) { Directory.Delete(tempFoler, true); } UnZip(path, tempFoler, true); - string iniPath = tempFoler + "\\plugin.ini"; + string iniPath = tempFoler + "\\plugin.json"; if (!File.Exists(iniPath)) { MessageBox.Show("Install failed: config is missing"); return; } - PluginMetadata plugin = GetMetadataFromIni(tempFoler); + PluginMetadata plugin = GetMetadataFromJson(tempFoler); if (plugin == null || plugin.Name == null) { - MessageBox.Show("Install failed: config of this workflow is invalid"); + MessageBox.Show("Install failed: config of this plugin is invalid"); return; } string pluginFolerPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins"; if (!Directory.Exists(pluginFolerPath)) { - MessageBox.Show("Install failed: cound't find workflow directory"); + MessageBox.Show("Install failed: cound't find plugin directory"); return; } string newPluginPath = pluginFolerPath + "\\" + plugin.Name; string content = string.Format( - "Do you want to install following workflow?\r\nName: {0}\r\nVersion: {1}\r\nAuthor: {2}", + "Do you want to install following plugin?\r\nName: {0}\r\nVersion: {1}\r\nAuthor: {2}", plugin.Name, plugin.Version, plugin.Author); if (Directory.Exists(newPluginPath)) { - PluginMetadata existingPlugin = GetMetadataFromIni(newPluginPath); + PluginMetadata existingPlugin = GetMetadataFromJson(newPluginPath); if (existingPlugin == null || existingPlugin.Name == null) { //maybe broken plugin, just delete it @@ -113,12 +113,12 @@ namespace Wox.Helper else { content = string.Format( - "Do you want to update following workflow?\r\nName: {0}\r\nOld Version: {1}\r\nNew Version: {2}\r\nAuthor: {3}", + "Do you want to update following plugin?\r\nName: {0}\r\nOld Version: {1}\r\nNew Version: {2}\r\nAuthor: {3}", plugin.Name, existingPlugin.Version, plugin.Version, plugin.Author); } } - MessageBoxResult result = MessageBox.Show(content, "Install workflow", + MessageBoxResult result = MessageBox.Show(content, "Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { @@ -133,63 +133,73 @@ namespace Wox.Helper string wox = AppDomain.CurrentDomain.BaseDirectory + "Wox.exe"; if (File.Exists(wox)) { - ProcessStartInfo info = new ProcessStartInfo(wox, "reloadWorkflows") + ProcessStartInfo info = new ProcessStartInfo(wox, "reloadplugin") { UseShellExecute = true }; Process.Start(info); - MessageBox.Show("You have installed workflow " + plugin.Name + " successfully."); + MessageBox.Show("You have installed plugin " + plugin.Name + " successfully."); } else { - MessageBox.Show("You have installed workflow " + plugin.Name + " successfully. Please restart your wox to use new workflow."); + MessageBox.Show("You have installed plugin " + plugin.Name + " successfully. Please restart your wox to use new plugin."); } } } } - private PluginMetadata GetMetadataFromIni(string directory) - { - string iniPath = directory + "\\plugin.ini"; + private static PluginMetadata GetMetadataFromJson(string pluginDirectory) + { + string configPath = Path.Combine(pluginDirectory, "plugin.json"); + PluginMetadata metadata; - if (!File.Exists(iniPath)) + if (!File.Exists(configPath)) { return null; } try { - PluginMetadata metadata = new PluginMetadata(); - IniParser ini = new IniParser(iniPath); - metadata.Name = ini.GetSetting("plugin", "Name"); - metadata.Author = ini.GetSetting("plugin", "Author"); - metadata.Description = ini.GetSetting("plugin", "Description"); - metadata.Language = ini.GetSetting("plugin", "Language"); - metadata.Version = ini.GetSetting("plugin", "Version"); + metadata = JsonConvert.DeserializeObject(File.ReadAllText(configPath)); metadata.PluginType = PluginType.ThirdParty; - metadata.ActionKeyword = ini.GetSetting("plugin", "ActionKeyword"); - metadata.PluginDirecotry = directory + "\\"; - metadata.ExecuteFileName = ini.GetSetting("plugin", "ExecuteFile"); - - if (!AllowedLanguage.IsAllowed(metadata.Language)) - { - string error = string.Format("Parse ini {0} failed: invalid language {1}", iniPath, - metadata.Language); - return null; - } - if (!File.Exists(metadata.ExecuteFilePath)) - { - string error = string.Format("Parse ini {0} failed: ExecuteFilePath didn't exist {1}", iniPath, - metadata.ExecuteFilePath); - return null; - } - - return metadata; + metadata.PluginDirecotry = pluginDirectory; } - catch (Exception e) + catch (Exception) { + string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath); +#if (DEBUG) + { + throw new Exception(error); + } +#endif return null; } + + + if (!AllowedLanguage.IsAllowed(metadata.Language)) + { + string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath, + metadata.Language); +#if (DEBUG) + { + throw new Exception(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); +#if (DEBUG) + { + throw new Exception(error); + } +#endif + return null; + } + + return metadata; } /// diff --git a/Wox.UAC/Wox.UAC.csproj b/Wox.UAC/Wox.UAC.csproj index 84abe0597f..57d5bf8398 100644 --- a/Wox.UAC/Wox.UAC.csproj +++ b/Wox.UAC/Wox.UAC.csproj @@ -42,9 +42,17 @@ app.manifest + + False + ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll + ..\packages\log4net.2.0.3\lib\net35-full\log4net.dll + + False + ..\packages\Newtonsoft.Json.6.0.1\lib\net35\Newtonsoft.Json.dll + @@ -74,6 +82,7 @@ + Code @@ -104,18 +113,10 @@ {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} Wox.Infrastructure - - {69ce0206-cb41-453d-88af-df86092ef9b8} - Wox.Plugin.System - {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} Wox.Plugin - - {DB90F671-D861-46BB-93A3-F1304F5BA1C5} - Wox - diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 9706af9777..215525fd56 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.CompilerServices; using System.Threading; using System.Windows; using System.Windows.Controls; @@ -13,6 +14,7 @@ using WindowsInput.Native; using NHotkey; using NHotkey.Wpf; using Wox.Commands; +using Wox.Helper; using Wox.Infrastructure; using Wox.Infrastructure.UserSettings; using Wox.Plugin; @@ -58,6 +60,8 @@ namespace Wox } } + + public void SetHotkey(string hotkeyStr, EventHandler action) { var hotkey = new HotkeyModel(hotkeyStr); diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 1e2dfba0ab..e120aef13c 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -130,7 +130,6 @@ -