mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Pack python env to zip
This commit is contained in:
@@ -8,15 +8,20 @@ from wox import Wox,WoxAPI
|
||||
class HackerNews(Wox):
|
||||
|
||||
def query(self,key):
|
||||
r = requests.get('https://news.ycombinator.com/')
|
||||
proxies = {}
|
||||
if self.proxy and self.proxy.get("enabled") and self.proxy.get("server"):
|
||||
proxies = {
|
||||
"http": "http://{}:{}".format(self.proxy.get("server"),self.proxy.get("port")),
|
||||
"http": "https://{}:{}".format(self.proxy.get("server"),self.proxy.get("port"))
|
||||
}
|
||||
#self.debug(proxies)
|
||||
r = requests.get('https://news.ycombinator.com/',proxies = proxies)
|
||||
bs = BeautifulSoup(r.text)
|
||||
results = []
|
||||
for i in bs.select(".comhead"):
|
||||
title = i.previous_sibling.text
|
||||
url = i.previous_sibling["href"]
|
||||
#results.append({"Title": title ,"IcoPath":"Images/app.ico","JsonRPCAction":{"method": "Wox.ChangeQuery","parameters":[url,True]}})
|
||||
results.append({"Title": title ,"IcoPath":"Images/app.ico","JsonRPCAction":{"method": "openUrl","parameters":[url],"dontHideAfterAction":True}})
|
||||
#results.append({"Title": title ,"IcoPath":"Images/app.ico","JsonRPCAction":{"method": "Wox.ShowApp"}})
|
||||
|
||||
return results
|
||||
|
||||
|
||||
@@ -1,113 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
|
||||
//From:http://blog.csdn.net/zhoufoxcn/article/details/6404236
|
||||
|
||||
namespace Wox.Plugin.PluginManagement
|
||||
{
|
||||
public class HttpRequest
|
||||
{
|
||||
private static readonly string DefaultUserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
|
||||
|
||||
public static HttpWebResponse CreateGetHttpResponse(string url, int? timeout, string userAgent, CookieCollection cookies)
|
||||
public static HttpWebResponse CreateGetHttpResponse(string url,IHttpProxy proxy)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
throw new ArgumentNullException("url");
|
||||
}
|
||||
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
|
||||
if (proxy != null && proxy.Enabled && !string.IsNullOrEmpty(proxy.Server))
|
||||
{
|
||||
if (string.IsNullOrEmpty(proxy.UserName) || string.IsNullOrEmpty(proxy.Password))
|
||||
{
|
||||
request.Proxy = new WebProxy(proxy.Server, proxy.Port);
|
||||
}
|
||||
else
|
||||
{
|
||||
request.Proxy = new WebProxy(proxy.Server, proxy.Port);
|
||||
request.Proxy.Credentials = new NetworkCredential(proxy.UserName, proxy.Password);
|
||||
}
|
||||
}
|
||||
request.Method = "GET";
|
||||
request.UserAgent = DefaultUserAgent;
|
||||
if (!string.IsNullOrEmpty(userAgent))
|
||||
{
|
||||
request.UserAgent = userAgent;
|
||||
}
|
||||
if (timeout.HasValue)
|
||||
{
|
||||
request.Timeout = timeout.Value;
|
||||
}
|
||||
if (cookies != null)
|
||||
{
|
||||
request.CookieContainer = new CookieContainer();
|
||||
request.CookieContainer.Add(cookies);
|
||||
}
|
||||
return request.GetResponse() as HttpWebResponse;
|
||||
}
|
||||
|
||||
public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters, int? timeout, string userAgent, Encoding requestEncoding, CookieCollection cookies)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
throw new ArgumentNullException("url");
|
||||
}
|
||||
if (requestEncoding == null)
|
||||
{
|
||||
throw new ArgumentNullException("requestEncoding");
|
||||
}
|
||||
HttpWebRequest request = null;
|
||||
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
|
||||
request = WebRequest.Create(url) as HttpWebRequest;
|
||||
request.ProtocolVersion = HttpVersion.Version10;
|
||||
}
|
||||
else
|
||||
{
|
||||
request = WebRequest.Create(url) as HttpWebRequest;
|
||||
}
|
||||
request.Method = "POST";
|
||||
request.ContentType = "application/x-www-form-urlencoded";
|
||||
|
||||
if (!string.IsNullOrEmpty(userAgent))
|
||||
{
|
||||
request.UserAgent = userAgent;
|
||||
}
|
||||
else
|
||||
{
|
||||
request.UserAgent = DefaultUserAgent;
|
||||
}
|
||||
|
||||
if (timeout.HasValue)
|
||||
{
|
||||
request.Timeout = timeout.Value;
|
||||
}
|
||||
if (cookies != null)
|
||||
{
|
||||
request.CookieContainer = new CookieContainer();
|
||||
request.CookieContainer.Add(cookies);
|
||||
}
|
||||
if (!(parameters == null || parameters.Count == 0))
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
int i = 0;
|
||||
foreach (string key in parameters.Keys)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
buffer.AppendFormat("&{0}={1}", key, parameters[key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.AppendFormat("{0}={1}", key, parameters[key]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
byte[] data = requestEncoding.GetBytes(buffer.ToString());
|
||||
using (Stream stream = request.GetRequestStream())
|
||||
{
|
||||
stream.Write(data, 0, data.Length);
|
||||
}
|
||||
}
|
||||
return request.GetResponse() as HttpWebResponse;
|
||||
}
|
||||
|
||||
private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,246 +8,301 @@ using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Wox.Plugin.PluginManagement {
|
||||
public class WoxPlugin {
|
||||
public int apiVersion { get; set; }
|
||||
public List<WoxPluginResult> result { get; set; }
|
||||
}
|
||||
namespace Wox.Plugin.PluginManagement
|
||||
{
|
||||
public class WoxPlugin
|
||||
{
|
||||
public int apiVersion { get; set; }
|
||||
public List<WoxPluginResult> result { get; set; }
|
||||
}
|
||||
|
||||
public class WoxPluginResult {
|
||||
public string actionkeyword;
|
||||
public string download;
|
||||
public string author;
|
||||
public string description;
|
||||
public string id;
|
||||
public int star;
|
||||
public string name;
|
||||
public string version;
|
||||
public string website;
|
||||
}
|
||||
public class WoxPluginResult
|
||||
{
|
||||
public string actionkeyword;
|
||||
public string download;
|
||||
public string author;
|
||||
public string description;
|
||||
public string id;
|
||||
public int star;
|
||||
public string name;
|
||||
public string version;
|
||||
public string website;
|
||||
}
|
||||
|
||||
public class Main : IPlugin {
|
||||
private static string PluginPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins";
|
||||
private static string PluginConfigName = "plugin.json";
|
||||
private static string pluginSearchUrl = "http://www.getwox.com/api/plugin/search/";
|
||||
private PluginInitContext context;
|
||||
public class Main : IPlugin
|
||||
{
|
||||
private static string PluginPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins";
|
||||
private static string PluginConfigName = "plugin.json";
|
||||
private static string pluginSearchUrl = "http://www.getwox.com/api/plugin/search/";
|
||||
private PluginInitContext context;
|
||||
|
||||
public List<Result> Query(Query query) {
|
||||
List<Result> results = new List<Result>();
|
||||
if (query.ActionParameters.Count == 0) {
|
||||
results.Add(new Result("wpm install <pluginName>", "Images\\plugin.png", "search and install wox plugins") {
|
||||
Action = e => {
|
||||
context.ChangeQuery("wpm install ");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
results.Add(new Result("wpm uninstall <pluginName>", "Images\\plugin.png", "uninstall plugin") {
|
||||
Action = e => {
|
||||
context.ChangeQuery("wpm uninstall ");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
results.Add(new Result("wpm list", "Images\\plugin.png", "list plugins installed") {
|
||||
Action = e => {
|
||||
context.ChangeQuery("wpm list");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return results;
|
||||
}
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
if (query.ActionParameters.Count == 0)
|
||||
{
|
||||
results.Add(new Result("wpm install <pluginName>", "Images\\plugin.png", "search and install wox plugins")
|
||||
{
|
||||
Action = e =>
|
||||
{
|
||||
context.ChangeQuery("wpm install ");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
results.Add(new Result("wpm uninstall <pluginName>", "Images\\plugin.png", "uninstall plugin")
|
||||
{
|
||||
Action = e =>
|
||||
{
|
||||
context.ChangeQuery("wpm uninstall ");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
results.Add(new Result("wpm list", "Images\\plugin.png", "list plugins installed")
|
||||
{
|
||||
Action = e =>
|
||||
{
|
||||
context.ChangeQuery("wpm list");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return results;
|
||||
}
|
||||
|
||||
if (query.ActionParameters.Count > 0) {
|
||||
bool hit = false;
|
||||
switch (query.ActionParameters[0].ToLower()) {
|
||||
case "list":
|
||||
hit = true;
|
||||
results = ListInstalledPlugins();
|
||||
break;
|
||||
if (query.ActionParameters.Count > 0)
|
||||
{
|
||||
bool hit = false;
|
||||
switch (query.ActionParameters[0].ToLower())
|
||||
{
|
||||
case "list":
|
||||
hit = true;
|
||||
results = ListInstalledPlugins();
|
||||
break;
|
||||
|
||||
case "uninstall":
|
||||
hit = true;
|
||||
results = ListUnInstalledPlugins(query);
|
||||
break;
|
||||
case "uninstall":
|
||||
hit = true;
|
||||
results = ListUnInstalledPlugins(query);
|
||||
break;
|
||||
|
||||
case "install":
|
||||
hit = true;
|
||||
if (query.ActionParameters.Count > 1) {
|
||||
results = InstallPlugin(query);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "install":
|
||||
hit = true;
|
||||
if (query.ActionParameters.Count > 1)
|
||||
{
|
||||
results = InstallPlugin(query);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!hit) {
|
||||
if ("install".Contains(query.ActionParameters[0].ToLower())) {
|
||||
results.Add(new Result("wpm install <pluginName>", "Images\\plugin.png", "search and install wox plugins") {
|
||||
Action = e => {
|
||||
context.ChangeQuery("wpm install ");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
if ("uninstall".Contains(query.ActionParameters[0].ToLower())) {
|
||||
results.Add(new Result("wpm uninstall <pluginName>", "Images\\plugin.png", "uninstall plugin") {
|
||||
Action = e => {
|
||||
context.ChangeQuery("wpm uninstall ");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
if ("list".Contains(query.ActionParameters[0].ToLower())) {
|
||||
results.Add(new Result("wpm list", "Images\\plugin.png", "list plugins installed") {
|
||||
Action = e => {
|
||||
context.ChangeQuery("wpm list");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hit)
|
||||
{
|
||||
if ("install".Contains(query.ActionParameters[0].ToLower()))
|
||||
{
|
||||
results.Add(new Result("wpm install <pluginName>", "Images\\plugin.png", "search and install wox plugins")
|
||||
{
|
||||
Action = e =>
|
||||
{
|
||||
context.API.ChangeQuery("wpm install ");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
if ("uninstall".Contains(query.ActionParameters[0].ToLower()))
|
||||
{
|
||||
results.Add(new Result("wpm uninstall <pluginName>", "Images\\plugin.png", "uninstall plugin")
|
||||
{
|
||||
Action = e =>
|
||||
{
|
||||
context.API.ChangeQuery("wpm uninstall ");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
if ("list".Contains(query.ActionParameters[0].ToLower()))
|
||||
{
|
||||
results.Add(new Result("wpm list", "Images\\plugin.png", "list plugins installed")
|
||||
{
|
||||
Action = e =>
|
||||
{
|
||||
context.API.ChangeQuery("wpm list");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<Result> InstallPlugin(Query query) {
|
||||
List<Result> results = new List<Result>();
|
||||
HttpWebResponse response = HttpRequest.CreateGetHttpResponse(pluginSearchUrl + query.ActionParameters[1], null, null, null);
|
||||
Stream s = response.GetResponseStream();
|
||||
if (s != null) {
|
||||
StreamReader reader = new StreamReader(s, Encoding.UTF8);
|
||||
string json = reader.ReadToEnd();
|
||||
WoxPlugin o = JsonConvert.DeserializeObject<WoxPlugin>(json);
|
||||
foreach (WoxPluginResult r in o.result) {
|
||||
WoxPluginResult r1 = r;
|
||||
results.Add(new Result() {
|
||||
Title = r.name,
|
||||
SubTitle = r.description,
|
||||
IcoPath = "Images\\plugin.png",
|
||||
Action = e => {
|
||||
DialogResult result = MessageBox.Show("Are your sure to install " + r.name + " plugin",
|
||||
"Install plugin", MessageBoxButtons.YesNo);
|
||||
private List<Result> InstallPlugin(Query query)
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
HttpWebResponse response = HttpRequest.CreateGetHttpResponse(pluginSearchUrl + query.ActionParameters[1], context.Proxy);
|
||||
Stream s = response.GetResponseStream();
|
||||
if (s != null)
|
||||
{
|
||||
StreamReader reader = new StreamReader(s, Encoding.UTF8);
|
||||
string json = reader.ReadToEnd();
|
||||
WoxPlugin o = JsonConvert.DeserializeObject<WoxPlugin>(json);
|
||||
foreach (WoxPluginResult r in o.result)
|
||||
{
|
||||
WoxPluginResult r1 = r;
|
||||
results.Add(new Result()
|
||||
{
|
||||
Title = r.name,
|
||||
SubTitle = r.description,
|
||||
IcoPath = "Images\\plugin.png",
|
||||
Action = e =>
|
||||
{
|
||||
DialogResult result = MessageBox.Show("Are your sure to install " + r.name + " plugin",
|
||||
"Install plugin", MessageBoxButtons.YesNo);
|
||||
|
||||
if (result == DialogResult.Yes) {
|
||||
string folder = Path.Combine(Path.GetTempPath(), "WoxPluginDownload");
|
||||
if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
|
||||
string filePath = Path.Combine(folder, Guid.NewGuid().ToString() + ".wox");
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
string folder = Path.Combine(Path.GetTempPath(), "WoxPluginDownload");
|
||||
if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
|
||||
string filePath = Path.Combine(folder, Guid.NewGuid().ToString() + ".wox");
|
||||
|
||||
context.StartLoadingBar();
|
||||
ThreadPool.QueueUserWorkItem(delegate {
|
||||
using (WebClient Client = new WebClient()) {
|
||||
try {
|
||||
Client.DownloadFile(r1.download, filePath);
|
||||
context.InstallPlugin(filePath);
|
||||
context.ReloadPlugins();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
MessageBox.Show("download plugin " + r.name + "failed. " + exception.Message);
|
||||
}
|
||||
finally {
|
||||
context.StopLoadingBar();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
context.API.StartLoadingBar();
|
||||
ThreadPool.QueueUserWorkItem(delegate
|
||||
{
|
||||
using (WebClient Client = new WebClient())
|
||||
{
|
||||
try
|
||||
{
|
||||
Client.DownloadFile(r1.download, filePath);
|
||||
context.API.InstallPlugin(filePath);
|
||||
context.API.ReloadPlugins();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MessageBox.Show("download plugin " + r.name + "failed. " + exception.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.StopLoadingBar();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
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 false;
|
||||
}
|
||||
});
|
||||
}
|
||||
return results;
|
||||
}
|
||||
foreach (PluginMetadata plugin in allInstalledPlugins)
|
||||
{
|
||||
results.Add(new Result()
|
||||
{
|
||||
Title = plugin.Name,
|
||||
SubTitle = plugin.Description,
|
||||
IcoPath = "Images\\plugin.png",
|
||||
Action = e =>
|
||||
{
|
||||
UnInstalledPlugins(plugin);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
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.PluginDirectory, "NeedDelete.txt")).Close();
|
||||
MessageBox.Show("This plugin has been removed, restart Wox to take effect");
|
||||
}
|
||||
}
|
||||
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.PluginDirectory, "NeedDelete.txt")).Close();
|
||||
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 + " - " + plugin.ActionKeyword,
|
||||
SubTitle = plugin.Description,
|
||||
IcoPath = "Images\\plugin.png"
|
||||
});
|
||||
}
|
||||
return results;
|
||||
}
|
||||
private List<Result> ListInstalledPlugins()
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
foreach (PluginMetadata plugin in ParseThirdPartyPlugins())
|
||||
{
|
||||
results.Add(new Result()
|
||||
{
|
||||
Title = plugin.Name + " - " + plugin.ActionKeyword,
|
||||
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);
|
||||
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);
|
||||
}
|
||||
string[] directories = Directory.GetDirectories(PluginPath);
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
PluginMetadata metadata = GetMetadataFromJson(directory);
|
||||
if (metadata != null) pluginMetadatas.Add(metadata);
|
||||
}
|
||||
|
||||
return pluginMetadatas;
|
||||
}
|
||||
return pluginMetadatas;
|
||||
}
|
||||
|
||||
private static PluginMetadata GetMetadataFromJson(string pluginDirectory) {
|
||||
string configPath = Path.Combine(pluginDirectory, PluginConfigName);
|
||||
PluginMetadata metadata;
|
||||
private static PluginMetadata GetMetadataFromJson(string pluginDirectory)
|
||||
{
|
||||
string configPath = Path.Combine(pluginDirectory, PluginConfigName);
|
||||
PluginMetadata metadata;
|
||||
|
||||
if (!File.Exists(configPath)) {
|
||||
return null;
|
||||
}
|
||||
if (!File.Exists(configPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
|
||||
metadata.PluginType = PluginType.ThirdParty;
|
||||
metadata.PluginDirectory = pluginDirectory;
|
||||
}
|
||||
catch (Exception) {
|
||||
string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath);
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
|
||||
metadata.PluginType = PluginType.ThirdParty;
|
||||
metadata.PluginDirectory = 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
}
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user