PowerToys/Plugins/Wox.Plugin.Everything/Main.cs

64 lines
2.0 KiB
C#
Raw Normal View History

2013-12-19 23:51:20 +08:00
using System;
using System.Collections.Generic;
using System.IO;
2013-12-19 23:51:20 +08:00
using System.Linq;
using System.Text;
2014-01-29 18:33:24 +08:00
namespace Wox.Plugin.Everything
2013-12-19 23:51:20 +08:00
{
public class Main : IPlugin
{
Wox.Plugin.PluginInitContext context;
2013-12-19 23:51:20 +08:00
EverythingAPI api = new EverythingAPI();
public List<Result> Query(Query query)
{
var results = new List<Result>();
if (query.ActionParameters.Count > 0 && query.ActionParameters[0].Length > 0)
2013-12-19 23:51:20 +08:00
{
IEnumerable<string> enumerable = api.Search(query.ActionParameters[0], 0, 100);
foreach (string s in enumerable)
{
Result r = new Result();
r.Title = Path.GetFileName(s);
r.SubTitle = s;
r.Action = () =>
{
context.HideApp();
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
info.UseShellExecute = true;
info.FileName = s;
try
{
System.Diagnostics.Process.Start(info);
}
catch (Exception ex)
{
context.ShowMsg("Could not start " + r.Title, ex.Message, null);
}
};
results.Add(r);
}
2013-12-19 23:51:20 +08:00
}
api.Reset();
2013-12-19 23:51:20 +08:00
return results;
}
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
private static extern int LoadLibrary(string name);
2013-12-19 23:51:20 +08:00
public void Init(Wox.Plugin.PluginInitContext context)
2013-12-19 23:51:20 +08:00
{
this.context = context;
LoadLibrary(Path.Combine(
Path.Combine(context.PluginMetadata.PluginDirecotry, (IntPtr.Size == 4) ? "x86" : "x64"),
"Everything.dll"
));
2013-12-19 23:51:20 +08:00
//init everything
}
}
}