mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-10 21:41:51 +02:00
Add wox plugin installer.
This commit is contained in:
@@ -9,4 +9,3 @@
|
|||||||
"Website":"http://www.getwox.com",
|
"Website":"http://www.getwox.com",
|
||||||
"ExecuteFileName":"Wox.Plugin.Clipboard.dll"
|
"ExecuteFileName":"Wox.Plugin.Clipboard.dll"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +1,33 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
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
|
namespace Wox.UAC
|
||||||
{
|
{
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
|
PluginInstaller installer = new PluginInstaller();
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
string[] param = Environment.GetCommandLineArgs();
|
string[] param = Environment.GetCommandLineArgs();
|
||||||
if (param.Length > 2)
|
if (param.Length > 1)
|
||||||
{
|
{
|
||||||
switch (param[1])
|
switch (param[1])
|
||||||
{
|
{
|
||||||
case "UAC":
|
case "UAC":
|
||||||
Invoke(param[2], param[3], param[4]);
|
Invoke(param[2], param[3], param[4]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "AssociatePluginInstaller":
|
||||||
|
installer.RegisterInstaller();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "InstallPlugin":
|
||||||
|
var path = param[2];
|
||||||
|
installer.Install(path);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Application.Current.Shutdown(0);
|
Application.Current.Shutdown(0);
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using ICSharpCode.SharpZipLib.Zip;
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using Wox.Infrastructure;
|
using Newtonsoft.Json;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
|
||||||
namespace Wox.Helper
|
namespace Wox.UAC
|
||||||
{
|
{
|
||||||
public class PluginInstaller
|
public class PluginInstaller
|
||||||
{
|
{
|
||||||
@@ -51,7 +51,7 @@ namespace Wox.Helper
|
|||||||
openKey = shellKey.OpenSubKey("open", true);
|
openKey = shellKey.OpenSubKey("open", true);
|
||||||
openKey.CreateSubKey("command");
|
openKey.CreateSubKey("command");
|
||||||
RegistryKey commandKey = openKey.OpenSubKey("command", true);
|
RegistryKey commandKey = openKey.OpenSubKey("command", true);
|
||||||
string pathString = "\"" + filePath + "\" \"%1\"";
|
string pathString = "\"" + filePath + "\" \"installPlugin\" \"%1\"";
|
||||||
commandKey.SetValue("", pathString);
|
commandKey.SetValue("", pathString);
|
||||||
|
|
||||||
//refresh cache
|
//refresh cache
|
||||||
@@ -60,51 +60,51 @@ namespace Wox.Helper
|
|||||||
|
|
||||||
public void RegisterInstaller()
|
public void RegisterInstaller()
|
||||||
{
|
{
|
||||||
string filePath = Directory.GetCurrentDirectory() + "\\Wox.Installer.exe";
|
string filePath = Directory.GetCurrentDirectory() + "\\Wox.UAC.exe";
|
||||||
string iconPath = Directory.GetCurrentDirectory() + "\\app.ico";
|
string iconPath = Directory.GetCurrentDirectory() + "\\app.ico";
|
||||||
|
|
||||||
SaveReg(filePath, ".wox", iconPath, false);
|
SaveReg(filePath, ".wox", iconPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Install(string path)
|
public void Install(string path)
|
||||||
{
|
{
|
||||||
if (File.Exists(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))
|
if (Directory.Exists(tempFoler))
|
||||||
{
|
{
|
||||||
Directory.Delete(tempFoler, true);
|
Directory.Delete(tempFoler, true);
|
||||||
}
|
}
|
||||||
UnZip(path, tempFoler, true);
|
UnZip(path, tempFoler, true);
|
||||||
|
|
||||||
string iniPath = tempFoler + "\\plugin.ini";
|
string iniPath = tempFoler + "\\plugin.json";
|
||||||
if (!File.Exists(iniPath))
|
if (!File.Exists(iniPath))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Install failed: config is missing");
|
MessageBox.Show("Install failed: config is missing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginMetadata plugin = GetMetadataFromIni(tempFoler);
|
PluginMetadata plugin = GetMetadataFromJson(tempFoler);
|
||||||
if (plugin == null || plugin.Name == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string pluginFolerPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins";
|
string pluginFolerPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins";
|
||||||
if (!Directory.Exists(pluginFolerPath))
|
if (!Directory.Exists(pluginFolerPath))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Install failed: cound't find workflow directory");
|
MessageBox.Show("Install failed: cound't find plugin directory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string newPluginPath = pluginFolerPath + "\\" + plugin.Name;
|
string newPluginPath = pluginFolerPath + "\\" + plugin.Name;
|
||||||
string content = string.Format(
|
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);
|
plugin.Name, plugin.Version, plugin.Author);
|
||||||
if (Directory.Exists(newPluginPath))
|
if (Directory.Exists(newPluginPath))
|
||||||
{
|
{
|
||||||
PluginMetadata existingPlugin = GetMetadataFromIni(newPluginPath);
|
PluginMetadata existingPlugin = GetMetadataFromJson(newPluginPath);
|
||||||
if (existingPlugin == null || existingPlugin.Name == null)
|
if (existingPlugin == null || existingPlugin.Name == null)
|
||||||
{
|
{
|
||||||
//maybe broken plugin, just delete it
|
//maybe broken plugin, just delete it
|
||||||
@@ -113,12 +113,12 @@ namespace Wox.Helper
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
content = string.Format(
|
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);
|
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);
|
MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||||
if (result == MessageBoxResult.Yes)
|
if (result == MessageBoxResult.Yes)
|
||||||
{
|
{
|
||||||
@@ -133,63 +133,73 @@ namespace Wox.Helper
|
|||||||
string wox = AppDomain.CurrentDomain.BaseDirectory + "Wox.exe";
|
string wox = AppDomain.CurrentDomain.BaseDirectory + "Wox.exe";
|
||||||
if (File.Exists(wox))
|
if (File.Exists(wox))
|
||||||
{
|
{
|
||||||
ProcessStartInfo info = new ProcessStartInfo(wox, "reloadWorkflows")
|
ProcessStartInfo info = new ProcessStartInfo(wox, "reloadplugin")
|
||||||
{
|
{
|
||||||
UseShellExecute = true
|
UseShellExecute = true
|
||||||
};
|
};
|
||||||
Process.Start(info);
|
Process.Start(info);
|
||||||
MessageBox.Show("You have installed workflow " + plugin.Name + " successfully.");
|
MessageBox.Show("You have installed plugin " + plugin.Name + " successfully.");
|
||||||
}
|
}
|
||||||
else
|
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)
|
private static PluginMetadata GetMetadataFromJson(string pluginDirectory)
|
||||||
{
|
{
|
||||||
string iniPath = directory + "\\plugin.ini";
|
string configPath = Path.Combine(pluginDirectory, "plugin.json");
|
||||||
|
PluginMetadata metadata;
|
||||||
|
|
||||||
if (!File.Exists(iniPath))
|
if (!File.Exists(configPath))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PluginMetadata metadata = new PluginMetadata();
|
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
|
||||||
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.PluginType = PluginType.ThirdParty;
|
metadata.PluginType = PluginType.ThirdParty;
|
||||||
metadata.ActionKeyword = ini.GetSetting("plugin", "ActionKeyword");
|
metadata.PluginDirecotry = pluginDirectory;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
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;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -42,9 +42,17 @@
|
|||||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="log4net">
|
<Reference Include="log4net">
|
||||||
<HintPath>..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
|
<HintPath>..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
@@ -74,6 +82,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="PluginInstaller.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs">
|
<Compile Include="Properties\AssemblyInfo.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -104,18 +113,10 @@
|
|||||||
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
||||||
<Name>Wox.Infrastructure</Name>
|
<Name>Wox.Infrastructure</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Wox.Plugin.System\Wox.Plugin.System.csproj">
|
|
||||||
<Project>{69ce0206-cb41-453d-88af-df86092ef9b8}</Project>
|
|
||||||
<Name>Wox.Plugin.System</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\Wox.Plugin\Wox.Plugin.csproj">
|
<ProjectReference Include="..\Wox.Plugin\Wox.Plugin.csproj">
|
||||||
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
|
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
|
||||||
<Name>Wox.Plugin</Name>
|
<Name>Wox.Plugin</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Wox\Wox.csproj">
|
|
||||||
<Project>{DB90F671-D861-46BB-93A3-F1304F5BA1C5}</Project>
|
|
||||||
<Name>Wox</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Resource Include="app.ico" />
|
<Resource Include="app.ico" />
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
@@ -13,6 +14,7 @@ using WindowsInput.Native;
|
|||||||
using NHotkey;
|
using NHotkey;
|
||||||
using NHotkey.Wpf;
|
using NHotkey.Wpf;
|
||||||
using Wox.Commands;
|
using Wox.Commands;
|
||||||
|
using Wox.Helper;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.UserSettings;
|
using Wox.Infrastructure.UserSettings;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
@@ -58,6 +60,8 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
|
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
|
||||||
{
|
{
|
||||||
var hotkey = new HotkeyModel(hotkeyStr);
|
var hotkey = new HotkeyModel(hotkeyStr);
|
||||||
|
|||||||
@@ -130,7 +130,6 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="DispatcherExtensions.cs" />
|
<Compile Include="DispatcherExtensions.cs" />
|
||||||
<Compile Include="Helper\Log.cs" />
|
<Compile Include="Helper\Log.cs" />
|
||||||
<Compile Include="Helper\PluginInstaller.cs" />
|
|
||||||
<Compile Include="Helper\WoxException.cs" />
|
<Compile Include="Helper\WoxException.cs" />
|
||||||
<Compile Include="Helper\WoxPythonException.cs" />
|
<Compile Include="Helper\WoxPythonException.cs" />
|
||||||
<Compile Include="HotkeyControl.xaml.cs">
|
<Compile Include="HotkeyControl.xaml.cs">
|
||||||
|
|||||||
Reference in New Issue
Block a user