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

76 lines
2.4 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;
using System.Text.RegularExpressions;
2013-12-19 23:51:20 +08:00
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();
2014-03-20 10:01:00 +08:00
private static List<string> imageExts = new List<string>() { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".ico" };
2013-12-19 23:51:20 +08:00
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
{
var keyword = string.Join(" ", query.ActionParameters.ToArray());
var enumerable = api.Search(keyword, 0, 100);
foreach (var s in enumerable)
{
var path = s.FullPath;
Result r = new Result();
r.Title = Path.GetFileName(path);
r.SubTitle = path;
r.IcoPath = GetIconPath(s);
r.Action = (c) =>
{
context.HideApp();
context.ShellRun(path);
2014-02-28 23:21:01 +08:00
return true;
};
results.Add(r);
}
2013-12-19 23:51:20 +08:00
}
api.Reset();
2013-12-19 23:51:20 +08:00
return results;
}
private string GetIconPath(SearchResult s)
{
if (s.Type == ResultType.Folder)
{
return "Images\\folder.png";
}
else
{
var ext = Path.GetExtension(s.FullPath);
if (!string.IsNullOrEmpty(ext) && imageExts.Contains(ext.ToLower()))
return "Images\\image.png";
else
return s.FullPath;
}
}
[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.CurrentPluginMetadata.PluginDirecotry, (IntPtr.Size == 4) ? "x86" : "x64"),
"Everything.dll"
));
2013-12-19 23:51:20 +08:00
//init everything
}
}
}