2014-07-17 23:14:58 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2014-07-18 14:09:52 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Wox.Infrastructure;
|
2014-07-17 23:14:58 +08:00
|
|
|
|
|
|
|
|
|
namespace Wox.Plugin.SystemPlugins.ControlPanel
|
|
|
|
|
{
|
|
|
|
|
public class ControlPanel : BaseSystemPlugin
|
|
|
|
|
{
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
private PluginInitContext context;
|
|
|
|
|
|
|
|
|
|
public override string Description
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return "Search within the Control Panel.";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ID
|
|
|
|
|
{
|
|
|
|
|
get { return "209621585B9B4D81813913C507C058C6"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name { get { return "Control Panel"; } }
|
|
|
|
|
|
|
|
|
|
public override string IcoPath { get { return @"Images\ControlPanel.png"; } }
|
|
|
|
|
|
|
|
|
|
private List<ControlPanelItem> controlPanelItems;
|
|
|
|
|
private string iconFolder;
|
2014-07-18 01:37:51 +08:00
|
|
|
|
private string fileType;
|
2014-07-17 23:14:58 +08:00
|
|
|
|
|
|
|
|
|
#endregion Properties
|
|
|
|
|
|
|
|
|
|
protected override void InitInternal(PluginInitContext context)
|
|
|
|
|
{
|
|
|
|
|
this.context = context;
|
2014-07-18 14:09:52 +08:00
|
|
|
|
controlPanelItems = ControlPanelList.Create(48);
|
2014-07-17 23:14:58 +08:00
|
|
|
|
iconFolder = @"Images\ControlPanelIcons\";
|
2014-07-18 01:37:51 +08:00
|
|
|
|
fileType = ".bmp";
|
2014-07-17 23:14:58 +08:00
|
|
|
|
|
2014-07-18 14:09:52 +08:00
|
|
|
|
if (!Directory.Exists(iconFolder))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(iconFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 23:14:58 +08:00
|
|
|
|
foreach (ControlPanelItem item in controlPanelItems)
|
|
|
|
|
{
|
2014-07-19 20:31:19 +08:00
|
|
|
|
if (!File.Exists(iconFolder + item.GUID + fileType) && item.Icon != null)
|
2014-07-17 23:14:58 +08:00
|
|
|
|
{
|
2014-07-19 20:31:19 +08:00
|
|
|
|
item.Icon.ToBitmap().Save(iconFolder + item.GUID + fileType);
|
2014-07-17 23:14:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override List<Result> QueryInternal(Query query)
|
|
|
|
|
{
|
2014-07-17 23:36:19 +08:00
|
|
|
|
if (query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
|
|
|
|
|
string myQuery = query.RawQuery.Trim();
|
|
|
|
|
|
2014-07-17 23:14:58 +08:00
|
|
|
|
List<Result> results = new List<Result>();
|
|
|
|
|
|
|
|
|
|
foreach (var item in controlPanelItems)
|
|
|
|
|
{
|
2014-07-18 14:09:52 +08:00
|
|
|
|
var fuzzyMather = FuzzyMatcher.Create(myQuery);
|
|
|
|
|
if (MatchProgram(item, fuzzyMather))
|
2014-07-18 02:05:09 +08:00
|
|
|
|
{
|
|
|
|
|
results.Add(new Result()
|
2014-07-17 23:43:29 +08:00
|
|
|
|
{
|
2014-07-18 02:05:09 +08:00
|
|
|
|
Title = item.LocalizedString,
|
|
|
|
|
SubTitle = item.InfoTip,
|
2014-07-18 14:09:52 +08:00
|
|
|
|
Score = item.Score,
|
2014-07-19 20:31:19 +08:00
|
|
|
|
IcoPath = "Images\\ControlPanelIcons\\" + item.GUID + fileType,
|
2014-07-18 02:05:09 +08:00
|
|
|
|
Action = e =>
|
2014-07-17 23:43:29 +08:00
|
|
|
|
{
|
2014-07-18 02:05:09 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Process.Start(item.ExecutablePath);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
2014-07-17 23:14:58 +08:00
|
|
|
|
{
|
2014-07-18 02:05:09 +08:00
|
|
|
|
//Silently Fail for now..
|
2014-07-17 23:14:58 +08:00
|
|
|
|
}
|
2014-07-18 02:05:09 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-07-17 23:14:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-17 23:47:58 +08:00
|
|
|
|
|
2014-07-21 19:45:47 +08:00
|
|
|
|
List<Result> panelItems = results.OrderByDescending(o => o.Score).Take(5).ToList();
|
|
|
|
|
return panelItems;
|
2014-07-18 14:09:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool MatchProgram(ControlPanelItem item, FuzzyMatcher matcher)
|
|
|
|
|
{
|
|
|
|
|
if (item.LocalizedString != null && (item.Score = matcher.Evaluate(item.LocalizedString).Score) > 0) return true;
|
|
|
|
|
if (item.InfoTip != null && (item.Score = matcher.Evaluate(item.InfoTip).Score) > 0) return true;
|
|
|
|
|
|
|
|
|
|
if (item.LocalizedString != null && (item.Score = matcher.Evaluate(item.LocalizedString.Unidecode()).Score) > 0) return true;
|
2014-07-19 08:15:51 +08:00
|
|
|
|
|
2014-07-18 14:09:52 +08:00
|
|
|
|
return false;
|
2014-07-17 23:14:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|