2013-12-19 23:51:20 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-01-30 00:53:15 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2014-01-30 00:53:15 +08:00
|
|
|
|
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>();
|
2013-12-21 01:20:17 +08:00
|
|
|
|
if (query.ActionParameters.Count > 0 && query.ActionParameters[0].Length > 0)
|
2013-12-19 23:51:20 +08:00
|
|
|
|
{
|
2014-03-19 21:23:17 +08:00
|
|
|
|
var keyword = string.Join(" ", query.ActionParameters.ToArray());
|
|
|
|
|
IEnumerable<string> enumerable = api.Search(keyword, 0, 100);
|
2013-12-21 01:20:17 +08:00
|
|
|
|
foreach (string s in enumerable)
|
|
|
|
|
{
|
2014-03-18 18:49:03 +08:00
|
|
|
|
var path = s;
|
2013-12-21 01:20:17 +08:00
|
|
|
|
Result r = new Result();
|
2014-03-18 18:49:03 +08:00
|
|
|
|
r.Title = Path.GetFileName(path);
|
|
|
|
|
r.SubTitle = path;
|
2014-02-09 20:55:18 +08:00
|
|
|
|
r.Action = (c) =>
|
2014-01-30 00:53:15 +08:00
|
|
|
|
{
|
|
|
|
|
context.HideApp();
|
|
|
|
|
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
|
|
|
|
|
info.UseShellExecute = true;
|
2014-03-18 18:49:03 +08:00
|
|
|
|
info.FileName = path;
|
2014-01-30 00:53:15 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
System.Diagnostics.Process.Start(info);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
context.ShowMsg("Could not start " + r.Title, ex.Message, null);
|
|
|
|
|
}
|
2014-02-28 23:21:01 +08:00
|
|
|
|
return true;
|
2014-01-30 00:53:15 +08:00
|
|
|
|
};
|
2013-12-21 01:20:17 +08:00
|
|
|
|
results.Add(r);
|
|
|
|
|
}
|
2013-12-19 23:51:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-30 00:53:15 +08:00
|
|
|
|
api.Reset();
|
|
|
|
|
|
2013-12-19 23:51:20 +08:00
|
|
|
|
return results;
|
|
|
|
|
}
|
2014-01-30 00:53:15 +08:00
|
|
|
|
|
|
|
|
|
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
|
|
|
|
|
private static extern int LoadLibrary(string name);
|
2013-12-19 23:51:20 +08:00
|
|
|
|
|
2014-01-30 00:53:15 +08:00
|
|
|
|
public void Init(Wox.Plugin.PluginInitContext context)
|
2013-12-19 23:51:20 +08:00
|
|
|
|
{
|
2014-01-30 00:53:15 +08:00
|
|
|
|
this.context = context;
|
|
|
|
|
|
|
|
|
|
LoadLibrary(Path.Combine(
|
2014-03-01 15:42:33 +08:00
|
|
|
|
Path.Combine(context.CurrentPluginMetadata.PluginDirecotry, (IntPtr.Size == 4) ? "x86" : "x64"),
|
2014-01-30 00:53:15 +08:00
|
|
|
|
"Everything.dll"
|
|
|
|
|
));
|
2013-12-19 23:51:20 +08:00
|
|
|
|
//init everything
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|