This commit is contained in:
qianlifeng 2014-03-02 11:04:30 +08:00
Родитель fce020f4dd
Коммит 13ed55ac10
6 изменённых файлов: 83 добавлений и 70 удалений

Просмотреть файл

@ -8,5 +8,4 @@
"Language":"csharp",
"Website":"http://www.getwox.com",
"ExecuteFileName":"Wox.Plugin.Clipboard.dll"
}
}

Просмотреть файл

@ -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);

Просмотреть файл

@ -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<PluginMetadata>(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;
}
/// <summary>

Просмотреть файл

@ -42,9 +42,17 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<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">
<HintPath>..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
</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.Data" />
<Reference Include="System.Xml" />
@ -74,6 +82,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="PluginInstaller.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
@ -104,18 +113,10 @@
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
<Name>Wox.Infrastructure</Name>
</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">
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
<Name>Wox.Plugin</Name>
</ProjectReference>
<ProjectReference Include="..\Wox\Wox.csproj">
<Project>{DB90F671-D861-46BB-93A3-F1304F5BA1C5}</Project>
<Name>Wox</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Resource Include="app.ico" />

Просмотреть файл

@ -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<HotkeyEventArgs> action)
{
var hotkey = new HotkeyModel(hotkeyStr);

Просмотреть файл

@ -130,7 +130,6 @@
</Compile>
<Compile Include="DispatcherExtensions.cs" />
<Compile Include="Helper\Log.cs" />
<Compile Include="Helper\PluginInstaller.cs" />
<Compile Include="Helper\WoxException.cs" />
<Compile Include="Helper\WoxPythonException.cs" />
<Compile Include="HotkeyControl.xaml.cs">