Change plugin config file format (from ini to json)

This commit is contained in:
qianlifeng
2014-03-01 15:42:33 +08:00
parent 1dde832e31
commit fce020f4dd
40 changed files with 159 additions and 145 deletions

View File

Before

Width:  |  Height:  |  Size: 924 B

After

Width:  |  Height:  |  Size: 924 B

View File

@@ -60,7 +60,7 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="plugin.ini">
<None Include="plugin.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

View File

@@ -0,0 +1,12 @@
{
"ID":"D2D2C23B084D411DB66FE0C79D6C2A6C",
"ActionKeyword":"cb",
"Name":"Wox.Plugin.Clipboard",
"Description":"clipboard history search",
"Author":"qianlifeng",
"Version":"1.0",
"Language":"csharp",
"Website":"http://www.getwox.com",
"ExecuteFileName":"Wox.Plugin.Clipboard.dll"
}

View File

@@ -53,7 +53,7 @@ namespace Wox.Plugin.Doc
public void Init(PluginInitContext context)
{
docsetBasePath = context.PluginMetadata.PluginDirecotry + @"Docset";
docsetBasePath = context.CurrentPluginMetadata.PluginDirecotry + @"Docset";
if (!Directory.Exists(docsetBasePath))
Directory.CreateDirectory(docsetBasePath);

View File

@@ -80,7 +80,7 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="plugin.ini">
<None Include="plugin.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="README.md" />

View File

@@ -1,8 +0,0 @@
[plugin]
ActionKeyword = doc
Name = Dash.Doc
Author = qianlifeng
Version = 0.1
Language = csharp
Description = Offline doc, inspired by dash
ExecuteFile = Wox.Plugin.Doc.dll

View File

@@ -0,0 +1,11 @@
{
"ID":"D2D2C23B084D411DB66FE0C79D6C2A6B",
"ActionKeyword":"doc",
"Name":"Dash.Doc",
"Description":"Offline doc, inspired by dash",
"Author":"qianlifeng",
"Version":"1.0",
"Language":"csharp",
"Website":"http://www.getwox.com",
"ExecuteFileName":"Wox.Plugin.Doc.dll"
}

View File

@@ -1,8 +0,0 @@
[plugin]
ActionKeyword = cb
Name = clipboard monitor
Author = qianlifeng
Version = 0.1
Language = csharp
Description = clipboard monitor
ExecuteFile = Wox.Plugin.Clipboard.dll

View File

@@ -1,8 +0,0 @@
[plugin]
ActionKeyword = movie
Name = douban
Author = qianlifeng
Version = 0.1
Language = python
Description = test
ExecuteFile = main.py

View File

@@ -0,0 +1,11 @@
{
"ID":"D2D2C23B084D411DB66FE0C79D6C2A6D",
"ActionKeyword":"movie",
"Name":"Wox.Plugin.Douban.Movie",
"Description":"search douban movies",
"Author":"qianlifeng",
"Version":"1.0",
"Language":"python",
"Website":"http://www.getwox.com",
"ExecuteFileName":"main.py"
}

View File

@@ -55,7 +55,7 @@ namespace Wox.Plugin.Everything
this.context = context;
LoadLibrary(Path.Combine(
Path.Combine(context.PluginMetadata.PluginDirecotry, (IntPtr.Size == 4) ? "x86" : "x64"),
Path.Combine(context.CurrentPluginMetadata.PluginDirecotry, (IntPtr.Size == 4) ? "x86" : "x64"),
"Everything.dll"
));
//init everything

View File

@@ -70,15 +70,15 @@
<Name>Wox.Plugin</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="plugin.ini">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="x64\Everything.dll" />
<Content Include="x86\Everything.dll" />
</ItemGroup>
<ItemGroup>
<None Include="plugin.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy /Y /E $(TargetDir)*.* $(SolutionDir)Wox\bin\Debug\Plugins\$(ProjectName)\

View File

@@ -1,8 +0,0 @@
[plugin]
ActionKeyword = ev
Name = everything
Author = qianlifeng
Version = 0.1
Language = csharp
Description = test
ExecuteFile = Wox.Plugin.Everything.dll

View File

@@ -0,0 +1,11 @@
{
"ID":"D2D2C23B084D411DB66FE0C79D6C2A6E",
"ActionKeyword":"ev",
"Name":"Wox.Plugin.Everything",
"Description":"Search Everything",
"Author":"orzfly",
"Version":"1.0",
"Language":"csharp",
"Website":"http://www.getwox.com",
"ExecuteFileName":"Wox.Plugin.Everything.dll"
}

View File

@@ -59,7 +59,7 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="plugin.ini">
<None Include="plugin.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

View File

@@ -1,8 +0,0 @@
[plugin]
ActionKeyword = fy
Name = Translator
Author = qianlifeng
Version = 0.1
Language = csharp
Description = Chinese and English Translator
ExecuteFile = Wox.Plugin.Fanyi.dll

View File

@@ -0,0 +1,11 @@
{
"ID":"D2D2C23B084D411DB66FE0C79D6C2A6A",
"ActionKeyword":"fy",
"Name":"Baidu Translator",
"Description":"Translate Chinese and English",
"Author":"qianlifeng",
"Version":"1.0",
"Language":"csharp",
"Website":"http://www.getwox.com",
"ExecuteFileName":"Wox.Plugin.Fanyi.dll"
}

View File

@@ -1,8 +0,0 @@
[plugin]
ActionKeyword = kill
Name = Wox.Kill
Author = qianlifeng
Version = 0.1
Language = python
Description = kill process
ExecuteFile = main.py

View File

@@ -0,0 +1,12 @@
{
"ID":"D2D2C23B084D411DB66FE0C79D6C2A6G",
"ActionKeyword":"kill",
"Name":"Wox.Plugin.kill",
"Description":"kill running program",
"Author":"qianlifeng",
"Version":"1.0",
"Language":"python",
"Website":"http://www.getwox.com",
"ExecuteFileName":"main.py"
}

View File

@@ -1,8 +0,0 @@
[plugin]
ActionKeyword = v2ex
Name = Wox.V2ex
Author = qianlifeng
Version = 0.1
Language = python
Description = workflow for v2ex
ExecuteFile = main.py

View File

@@ -0,0 +1,12 @@
{
"ID":"D2D2C23B084D411DB66FE0C79D6C2A6H",
"ActionKeyword":"v2ex",
"Name":"Wox.Plugin.v2ex",
"Description":"v2ex viewer",
"Author":"qianlifeng",
"Version":"1.0",
"Language":"python",
"Website":"http://www.getwox.com",
"ExecuteFileName":"main.py"
}

View File

@@ -82,7 +82,6 @@ namespace Python.Runtime {
//====================================================================
public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) {
// todo: add fast type check!
IntPtr pytype = Runtime.PyObject_TYPE(ob);
DelegateObject self = (DelegateObject)GetManagedObject(pytype);
CLRObject o = GetManagedObject(ob) as CLRObject;

View File

@@ -384,7 +384,6 @@ namespace Python.Runtime {
/// </remarks>
public static PythonException GetException() {
// TODO: implement this.
return null;
}

View File

@@ -330,7 +330,6 @@ namespace Python.Runtime {
public static int ValidVersionTag = (1 << 19);
public static int IsAbstract = (1 << 20);
public static int HaveNewBuffer = (1 << 21);
// TODO: Implement FastSubclass functions
public static int IntSubclass = (1 << 23);
public static int LongSubclass = (1 << 24);
public static int ListSubclass = (1 << 25);

View File

@@ -88,7 +88,6 @@ namespace Python.Runtime {
);
}
// hack for now... fix for 1.0
//return TypeManager.CreateSubType(args);

View File

@@ -17,7 +17,6 @@ namespace Python.Runtime {
// Implements a Python type that represents a CLR method. Method objects
// support a subscript syntax [] to allow explicit overload selection.
//========================================================================
// TODO: ForbidPythonThreadsAttribute per method info
internal class MethodObject : ExtensionType {

View File

@@ -37,11 +37,6 @@ namespace Python.Runtime {
}
// TODO: add all of the PyNumber_XXX methods.
}
}

View File

@@ -15,7 +15,7 @@ namespace Wox.Plugin.System
{
results.Add(new Result()
{
Title = "Wox Setting Dialog",
Title = "Wox Setting",
Score = 100,
IcoPath = "Images/app.png",
Action = (contenxt) =>

View File

@@ -8,7 +8,8 @@ namespace Wox.Plugin
public class PluginInitContext
{
public List<PluginPair> Plugins { get; set; }
public PluginMetadata PluginMetadata { get; set; }
public PluginMetadata CurrentPluginMetadata { get; set; }
public Action<string> ChangeQuery { get; set; }
public Action CloseApp { get; set; }

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
@@ -7,12 +8,29 @@ namespace Wox.Plugin
{
public class PluginMetadata
{
private int configVersion = 1;
/// <summary>
/// if we need to change the plugin config in the futher, use this to
/// indicate config version
/// </summary>
public int ConfigVersion
{
get { return configVersion; }
set { configVersion = value; }
}
public string ID { get; set; }
public string Name { get; set; }
public string Author { get; set; }
public string Version { get; set; }
public string Language { get; set; }
public string Description { get; set; }
public string ExecuteFilePath { get; set; }
public string ExecuteFilePath
{
get { return Path.Combine(PluginDirecotry, ExecuteFileName); }
}
public string ExecuteFileName { get; set; }
public string PluginDirecotry { get; set; }
public string ActionKeyword { get; set; }

View File

@@ -25,7 +25,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Everything", "Pl
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.UAC", "Wox.UAC\Wox.UAC.csproj", "{C9BC17A0-C2BC-4185-AC1F-32E3352C1233}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Clipboard", "Plugins\Wox.Plugin.DotnetPluginTest\Wox.Plugin.Clipboard.csproj", "{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Clipboard", "Plugins\Wox.Plugin.Clipboard\Wox.Plugin.Clipboard.csproj", "{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@@ -168,7 +168,6 @@ namespace Wox.Helper
metadata.Version = ini.GetSetting("plugin", "Version");
metadata.PluginType = PluginType.ThirdParty;
metadata.ActionKeyword = ini.GetSetting("plugin", "ActionKeyword");
metadata.ExecuteFilePath = directory + "\\" + ini.GetSetting("plugin", "ExecuteFile");
metadata.PluginDirecotry = directory + "\\";
metadata.ExecuteFileName = ini.GetSetting("plugin", "ExecuteFile");

View File

@@ -32,9 +32,9 @@ namespace Wox
{
resolvedPath = path;
}
else if (!string.IsNullOrEmpty(path) && File.Exists(pluginDirectory + path))
else if (!string.IsNullOrEmpty(path) && File.Exists(Path.Combine(pluginDirectory,path)))
{
resolvedPath = pluginDirectory + path;
resolvedPath = Path.Combine(pluginDirectory, path);
}
if (resolvedPath.ToLower().EndsWith(".exe") || resolvedPath.ToLower().EndsWith(".lnk"))

View File

@@ -67,7 +67,7 @@ namespace Wox
}
catch (Exception)
{
MessageBox.Show("Registe hotkey: " + CommonStorage.Instance.UserSetting.Hotkey + " failed.");
MessageBox.Show("Registe hotkey: " + hotkeyStr + " failed.");
}
}

View File

@@ -4,8 +4,8 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using Newtonsoft.Json;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Plugin;
using Wox.Plugin.System;
@@ -14,7 +14,7 @@ namespace Wox.PluginLoader
public abstract class BasePluginLoader
{
private static string PluginPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins";
private static string PluginConfigName = "plugin.ini";
private static string PluginConfigName = "plugin.json";
protected static List<PluginMetadata> pluginMetadatas = new List<PluginMetadata>();
public abstract List<PluginPair> LoadPlugin();
@@ -36,7 +36,6 @@ namespace Wox.PluginLoader
metadata.PluginType = PluginType.System;
metadata.ActionKeyword = "*";
metadata.ExecuteFileName = "Wox.Plugin.System.dll";
metadata.ExecuteFilePath = AppDomain.CurrentDomain.BaseDirectory + metadata.ExecuteFileName;
metadata.PluginDirecotry = AppDomain.CurrentDomain.BaseDirectory;
pluginMetadatas.Add(metadata);
}
@@ -49,39 +48,44 @@ namespace Wox.PluginLoader
string[] directories = Directory.GetDirectories(PluginPath);
foreach (string directory in directories)
{
PluginMetadata metadata = GetMetadataFromIni(directory);
PluginMetadata metadata = GetMetadataFromJson(directory);
if (metadata != null) pluginMetadatas.Add(metadata);
}
}
private static PluginMetadata GetMetadataFromIni(string directory)
private static PluginMetadata GetMetadataFromJson(string pluginDirectory)
{
string iniPath = directory + "\\" + PluginConfigName;
string configPath = Path.Combine(pluginDirectory, PluginConfigName);
PluginMetadata metadata;
if (!File.Exists(iniPath))
if (!File.Exists(configPath))
{
Log.Error(string.Format("parse plugin {0} failed: didn't find config file.", iniPath));
Log.Error(string.Format("parse plugin {0} failed: didn't find config file.", 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.ExecuteFilePath = directory + "\\" + ini.GetSetting("plugin", "ExecuteFile");
metadata.PluginDirecotry = directory + "\\";
metadata.ExecuteFileName = ini.GetSetting("plugin", "ExecuteFile");
metadata.PluginDirecotry = pluginDirectory;
}
catch (Exception)
{
string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath);
Log.Error(error);
#if (DEBUG)
{
throw new WoxException(error);
}
#endif
return null;
}
if (!AllowedLanguage.IsAllowed(metadata.Language))
{
string error = string.Format("Parse ini {0} failed: invalid language {1}", iniPath,
string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath,
metadata.Language);
Log.Error(error);
#if (DEBUG)
@@ -93,7 +97,7 @@ namespace Wox.PluginLoader
}
if (!File.Exists(metadata.ExecuteFilePath))
{
string error = string.Format("Parse ini {0} failed: ExecuteFilePath didn't exist {1}", iniPath,
string error = string.Format("Parse plugin config {0} failed: ExecuteFile {1} didn't exist", configPath,
metadata.ExecuteFilePath);
Log.Error(error);
#if (DEBUG)
@@ -106,27 +110,5 @@ namespace Wox.PluginLoader
return metadata;
}
catch (Exception e)
{
Log.Error(string.Format("Parse ini {0} failed: {1}", iniPath, e.Message));
#if (DEBUG)
{
throw;
}
#endif
return null;
}
}
///// <summary>
///// Change python execute file name to unique file name using GUID
///// this is because if two pythong plugin use the same
///// </summary>
///// <param name="metadata"></param>
///// <returns></returns>
//private static PluginMetadata filterPythonMetadata(PluginMetadata metadata)
//{
//}
}
}

View File

@@ -29,7 +29,7 @@ namespace Wox.PluginLoader
ThreadPool.QueueUserWorkItem(o => plugin1.Init(new PluginInitContext()
{
Plugins = plugins,
PluginMetadata = metadata,
CurrentPluginMetadata = metadata,
ChangeQuery = s => App.Window.ChangeQuery(s),
CloseApp = App.Window.CloseApp,
HideApp = App.Window.HideApp,