mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Merge branch 'master' of https://github.com/qianlifeng/Wox.git
This commit is contained in:
@@ -53,7 +53,7 @@ namespace Wox.Plugin.Doc
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
docsetBasePath = context.CurrentPluginMetadata.PluginDirecotry + @"Docset";
|
||||
docsetBasePath = Path.Combine(context.CurrentPluginMetadata.PluginDirecotry, @"Docset");
|
||||
if (!Directory.Exists(docsetBasePath))
|
||||
Directory.CreateDirectory(docsetBasePath);
|
||||
|
||||
|
||||
BIN
Plugins/Wox.Plugin.PluginManagement/Images/plugin.png
Normal file
BIN
Plugins/Wox.Plugin.PluginManagement/Images/plugin.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
176
Plugins/Wox.Plugin.PluginManagement/Main.cs
Normal file
176
Plugins/Wox.Plugin.PluginManagement/Main.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Wox.Plugin.PluginManagement
|
||||
{
|
||||
public class Main : IPlugin
|
||||
{
|
||||
private static string PluginPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins";
|
||||
private static string PluginConfigName = "plugin.json";
|
||||
private PluginInitContext context;
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
if (query.ActionParameters.Count == 0)
|
||||
{
|
||||
results.Add(new Result()
|
||||
{
|
||||
Title = "wpm list",
|
||||
SubTitle = "list plugins installed",
|
||||
IcoPath = "Images\\plugin.png",
|
||||
Action = e =>
|
||||
{
|
||||
context.ChangeQuery("wpm list");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
results.Add(new Result()
|
||||
{
|
||||
Title = "wpm uninstall <pluginName>",
|
||||
SubTitle = "uninstall plugin",
|
||||
IcoPath = "Images\\plugin.png",
|
||||
Action = e =>
|
||||
{
|
||||
context.ChangeQuery("wpm uninstall ");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return results;
|
||||
}
|
||||
|
||||
if (query.ActionParameters.Count > 0)
|
||||
{
|
||||
switch (query.ActionParameters[0].ToLower())
|
||||
{
|
||||
case "list":
|
||||
results = ListInstalledPlugins();
|
||||
break;
|
||||
|
||||
case "uninstall":
|
||||
results = ListUnInstalledPlugins(query);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<Result> ListUnInstalledPlugins(Query query)
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
List<PluginMetadata> allInstalledPlugins = ParseThirdPartyPlugins();
|
||||
if (query.ActionParameters.Count > 1)
|
||||
{
|
||||
string pluginName = query.ActionParameters[1];
|
||||
allInstalledPlugins =
|
||||
allInstalledPlugins.Where(o => o.Name.ToLower().Contains(pluginName.ToLower())).ToList();
|
||||
}
|
||||
|
||||
foreach (PluginMetadata plugin in allInstalledPlugins)
|
||||
{
|
||||
results.Add(new Result()
|
||||
{
|
||||
Title = plugin.Name,
|
||||
SubTitle = plugin.Description,
|
||||
IcoPath = "Images\\plugin.png",
|
||||
Action = e =>
|
||||
{
|
||||
UnInstalledPlugins(plugin);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private void UnInstalledPlugins(PluginMetadata plugin)
|
||||
{
|
||||
string content = string.Format("Do you want to uninstall following plugin?\r\n\r\nName: {0}\r\nVersion: {1}\r\nAuthor: {2}",plugin.Name, plugin.Version, plugin.Author);
|
||||
if (MessageBox.Show(content, "Wox", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||||
{
|
||||
File.Create(Path.Combine(plugin.PluginDirecotry, "NeedDelete.txt"));
|
||||
MessageBox.Show("This plugin has been removed, restart Wox to take effect");
|
||||
}
|
||||
}
|
||||
|
||||
private List<Result> ListInstalledPlugins()
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
foreach (PluginMetadata plugin in ParseThirdPartyPlugins())
|
||||
{
|
||||
results.Add(new Result()
|
||||
{
|
||||
Title = plugin.Name,
|
||||
SubTitle = plugin.Description,
|
||||
IcoPath = "Images\\plugin.png"
|
||||
});
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<PluginMetadata> ParseThirdPartyPlugins()
|
||||
{
|
||||
List<PluginMetadata> pluginMetadatas = new List<PluginMetadata>();
|
||||
if (!Directory.Exists(PluginPath))
|
||||
Directory.CreateDirectory(PluginPath);
|
||||
|
||||
string[] directories = Directory.GetDirectories(PluginPath);
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
PluginMetadata metadata = GetMetadataFromJson(directory);
|
||||
if (metadata != null) pluginMetadatas.Add(metadata);
|
||||
}
|
||||
|
||||
return pluginMetadatas;
|
||||
}
|
||||
|
||||
private static PluginMetadata GetMetadataFromJson(string pluginDirectory)
|
||||
{
|
||||
string configPath = Path.Combine(pluginDirectory, PluginConfigName);
|
||||
PluginMetadata metadata;
|
||||
|
||||
if (!File.Exists(configPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
|
||||
metadata.PluginType = PluginType.ThirdParty;
|
||||
metadata.PluginDirecotry = pluginDirectory;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (!AllowedLanguage.IsAllowed(metadata.Language))
|
||||
{
|
||||
string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath,
|
||||
metadata.Language);
|
||||
return null;
|
||||
}
|
||||
if (!File.Exists(metadata.ExecuteFilePath))
|
||||
{
|
||||
string error = string.Format("Parse plugin config {0} failed: ExecuteFile {1} didn't exist", configPath,
|
||||
metadata.ExecuteFilePath);
|
||||
return null;
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的常规信息通过以下
|
||||
// 特性集控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("Wox.Plugin.PluginManagement")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Wox.Plugin.PluginManagement")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 使此程序集中的类型
|
||||
// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
|
||||
// 则将该类型上的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("92b59bab-5c8c-414b-a8d7-326c7be3a11d")]
|
||||
|
||||
// 程序集的版本信息由下面四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{049490F0-ECD2-4148-9B39-2135EC346EBE}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Wox.Plugin.PluginManagement</RootNamespace>
|
||||
<AssemblyName>Wox.Plugin.PluginManagement</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
|
||||
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
|
||||
<Name>Wox.Plugin</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="plugin.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Images\plugin.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>xcopy /Y /E $(TargetDir)*.* $(SolutionDir)Wox\bin\Debug\Plugins\$(ProjectName)\
|
||||
xcopy /Y /E $(ProjectDir)Images $(SolutionDir)Wox\bin\Debug\Plugins\$(ProjectName)\Images\</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
4
Plugins/Wox.Plugin.PluginManagement/packages.config
Normal file
4
Plugins/Wox.Plugin.PluginManagement/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net35" />
|
||||
</packages>
|
||||
11
Plugins/Wox.Plugin.PluginManagement/plugin.json
Normal file
11
Plugins/Wox.Plugin.PluginManagement/plugin.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ID":"D2D2C23B084D422DB66FE0C79D6C2A6A",
|
||||
"ActionKeyword":"wpm",
|
||||
"Name":"Wox Plugin Management",
|
||||
"Description":"Manage your plugins in Wox",
|
||||
"Author":"qianlifeng",
|
||||
"Version":"1.0",
|
||||
"Language":"csharp",
|
||||
"Website":"http://www.getwox.com/plugin",
|
||||
"ExecuteFileName":"Wox.Plugin.PluginManagement.dll"
|
||||
}
|
||||
Reference in New Issue
Block a user