2023-01-07 02:20:22 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Community.PowerToys.Run.Plugin.Everything.Properties;
|
|
|
|
|
using Wox.Plugin;
|
|
|
|
|
using static Community.PowerToys.Run.Plugin.Everything.Interop.NativeMethods;
|
2022-12-11 02:20:09 +08:00
|
|
|
|
|
2023-01-07 02:20:22 +08:00
|
|
|
|
namespace Community.PowerToys.Run.Plugin.Everything
|
|
|
|
|
{
|
2023-03-30 00:22:49 +08:00
|
|
|
|
internal sealed class Everything
|
2022-12-11 02:20:09 +08:00
|
|
|
|
{
|
|
|
|
|
internal Everything(Settings setting)
|
|
|
|
|
{
|
|
|
|
|
Everything_SetRequestFlags(Request.FULL_PATH_AND_FILE_NAME);
|
2023-10-04 10:13:24 +08:00
|
|
|
|
UpdateSettings(setting);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void UpdateSettings(Settings setting)
|
|
|
|
|
{
|
|
|
|
|
Everything_SetSort(setting.Sort);
|
2022-12-11 02:20:09 +08:00
|
|
|
|
Everything_SetMax(setting.Max);
|
2023-10-04 10:13:24 +08:00
|
|
|
|
Everything_SetMatchPath(setting.MatchPath);
|
|
|
|
|
Everything_SetRegex(setting.RegEx);
|
2022-12-11 02:20:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal IEnumerable<Result> Query(string query, Settings setting)
|
|
|
|
|
{
|
|
|
|
|
string orgqry = query;
|
|
|
|
|
if (orgqry.Contains('\"') && !setting.MatchPath)
|
|
|
|
|
{
|
|
|
|
|
Everything_SetMatchPath(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (orgqry.Contains(':'))
|
|
|
|
|
{
|
|
|
|
|
string[] nqry = query.Split(':');
|
2023-03-30 00:22:49 +08:00
|
|
|
|
if (setting.Filters.TryGetValue(nqry[0].ToLowerInvariant(), out string value))
|
|
|
|
|
query = nqry[1].Trim() + " ext:" + value;
|
2022-12-11 02:20:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ = Everything_SetSearchW(query);
|
|
|
|
|
if (!Everything_QueryW(true))
|
|
|
|
|
{
|
|
|
|
|
throw new Win32Exception("Unable to Query");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (orgqry.Contains('\"') && !setting.MatchPath)
|
|
|
|
|
{
|
|
|
|
|
Everything_SetMatchPath(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint resultCount = Everything_GetNumResults();
|
|
|
|
|
|
|
|
|
|
for (uint i = 0; i < resultCount; i++)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder buffer = new StringBuilder(260);
|
|
|
|
|
Everything_GetResultFullPathName(i, buffer, 260);
|
|
|
|
|
string fullPath = buffer.ToString();
|
|
|
|
|
string name = Path.GetFileName(fullPath);
|
|
|
|
|
bool isFolder = Everything_IsFolderResult(i);
|
|
|
|
|
string path = isFolder ? fullPath : Path.GetDirectoryName(fullPath);
|
|
|
|
|
string ext = Path.GetExtension(fullPath.Replace(".lnk", string.Empty));
|
|
|
|
|
|
|
|
|
|
var r = new Result()
|
|
|
|
|
{
|
|
|
|
|
Title = name,
|
2022-12-11 16:23:48 +08:00
|
|
|
|
ToolTipData = new ToolTipData(name, fullPath),
|
2022-12-11 02:20:09 +08:00
|
|
|
|
SubTitle = Resources.plugin_name + ": " + fullPath,
|
|
|
|
|
|
|
|
|
|
IcoPath = isFolder ? "Images/folder.png" : (setting.Preview ?
|
|
|
|
|
fullPath : (SearchHelper.IconLoader.Icon(ext) ?? "Images/file.png")),
|
|
|
|
|
ContextData = new SearchResult()
|
|
|
|
|
{
|
|
|
|
|
Path = fullPath,
|
|
|
|
|
Title = name,
|
|
|
|
|
File = !isFolder,
|
|
|
|
|
},
|
|
|
|
|
Action = e =>
|
|
|
|
|
{
|
|
|
|
|
using var process = new Process();
|
|
|
|
|
process.StartInfo.FileName = fullPath;
|
|
|
|
|
process.StartInfo.WorkingDirectory = path;
|
|
|
|
|
process.StartInfo.UseShellExecute = true;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
process.Start();
|
2023-09-02 13:21:32 +08:00
|
|
|
|
_ = Everything_IncRunCountFromFileName(fullPath);
|
2022-12-11 02:20:09 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Win32Exception)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
QueryTextDisplay = setting.QueryText ? (isFolder ? path : name) : orgqry,
|
|
|
|
|
};
|
|
|
|
|
yield return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|