mirror of
https://github.com/lin-ycv/EverythingPowerToys.git
synced 2025-01-08 11:57:59 +08:00
Implemented update check, Code cleanup
This commit is contained in:
parent
d00bfe3266
commit
e1324baa16
@ -48,6 +48,10 @@
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="NativeMethods.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="plugin.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
@ -1,20 +1,15 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
|
||||
namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
internal class ContextMenuLoader : IContextMenu
|
||||
{
|
||||
private readonly PluginInitContext _context;
|
||||
|
115
Everything.cs
Normal file
115
Everything.cs
Normal file
@ -0,0 +1,115 @@
|
||||
namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
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 Wox.Plugin.Logger;
|
||||
using static Interop.NativeMethods;
|
||||
|
||||
internal class Everything
|
||||
{
|
||||
internal Everything(Settings setting)
|
||||
{
|
||||
Everything_SetRequestFlags(Request.FULL_PATH_AND_FILE_NAME);
|
||||
Everything_SetSort((Sort)setting.Sort);
|
||||
Everything_SetMax(setting.Max);
|
||||
}
|
||||
|
||||
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(':');
|
||||
if (setting.Filters.ContainsKey(nqry[0].ToLowerInvariant()))
|
||||
{
|
||||
Everything_SetMax(0xffffffff);
|
||||
query = nqry[1].Trim() + " ext:" + setting.Filters[nqry[0].Trim()];
|
||||
}
|
||||
}
|
||||
|
||||
_ = 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();
|
||||
|
||||
if (setting.Debug)
|
||||
{
|
||||
Log.Info(query + " => " + resultCount, typeof(Everything), "EverythingSearch.ResultCount", string.Empty, 217);
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
if (setting.Debug)
|
||||
{
|
||||
Log.Info(i + " : " + ext, typeof(Everything), "EverythingSearch.Result", string.Empty, 229);
|
||||
}
|
||||
|
||||
var r = new Result()
|
||||
{
|
||||
Title = name,
|
||||
ToolTipData = setting.Debug ?
|
||||
new ToolTipData(orgqry, query) :
|
||||
new ToolTipData("Name : " + name, fullPath),
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
catch (Win32Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
QueryTextDisplay = setting.QueryText ? (isFolder ? path : name) : orgqry,
|
||||
};
|
||||
yield return r;
|
||||
}
|
||||
|
||||
Everything_SetMax(setting.Max);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,12 +5,11 @@
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1124:Do not use regions", Justification = "Reviewed.")]
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501:Statement should not be on a single line", Justification = "Reviewed")]
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "Reviewed")]
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1503:Braces should not be omitted", Justification = "Reviewed")]
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1516:Elements should be separated by blank line", Justification = "Reviewed")]
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1602:Enumeration items should be documented", Justification = "Reviewed")]
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "Reviewed")]
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1516:Elements should be separated by blank line", Justification = "Reviewed")]
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1503:Braces should not be omitted", Justification = "Reviewed")]
|
||||
[assembly: SuppressMessage("Performance", "CA1838:Avoid 'StringBuilder' parameters for P/Invokes", Justification = "breaks icon preview for some reason when using char[]", Scope = "member", Target = "~M:Community.PowerToys.Run.Plugin.Everything.NativeMethods.Everything_GetResultFullPathName(System.UInt32,System.Text.StringBuilder,System.UInt32)")]
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1636:FileHeaderCopyrightTextMustMatch", Justification = "Reviewed.")]
|
||||
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1124:Do not use regions", Justification = "Reviewed")]
|
||||
[assembly: SuppressMessage("Performance", "CA1838:Avoid 'StringBuilder' parameters for P/Invokes", Justification = "breaks icon preview for some reason when using char[]", Scope = "member", Target = "~M:Community.PowerToys.Run.Plugin.Everything.NativeMethods.Everything_GetResultFullPathName(System.UInt32,System.Text.StringBuilder,System.UInt32)")]
|
||||
|
135
Interop/NativeMethods.cs
Normal file
135
Interop/NativeMethods.cs
Normal file
@ -0,0 +1,135 @@
|
||||
namespace Community.PowerToys.Run.Plugin.Everything.Interop
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
internal class NativeMethods
|
||||
{
|
||||
#region FlagsEnums
|
||||
[Flags]
|
||||
internal enum Request
|
||||
{
|
||||
FILE_NAME = 0x00000001,
|
||||
PATH = 0x00000002,
|
||||
FULL_PATH_AND_FILE_NAME = 0x00000004,
|
||||
EXTENSION = 0x00000008,
|
||||
SIZE = 0x00000010,
|
||||
DATE_CREATED = 0x00000020,
|
||||
DATE_MODIFIED = 0x00000040,
|
||||
DATE_ACCESSED = 0x00000080,
|
||||
ATTRIBUTES = 0x00000100,
|
||||
FILE_LIST_FILE_NAME = 0x00000200,
|
||||
RUN_COUNT = 0x00000400,
|
||||
DATE_RUN = 0x00000800,
|
||||
DATE_RECENTLY_CHANGED = 0x00001000,
|
||||
HIGHLIGHTED_FILE_NAME = 0x00002000,
|
||||
HIGHLIGHTED_PATH = 0x00004000,
|
||||
HIGHLIGHTED_FULL_PATH_AND_FILE_NAME = 0x00008000,
|
||||
}
|
||||
|
||||
internal enum Sort
|
||||
{
|
||||
NAME_ASCENDING = 1,
|
||||
NAME_DESCENDING,
|
||||
PATH_ASCENDING,
|
||||
PATH_DESCENDING,
|
||||
SIZE_ASCENDING,
|
||||
SIZE_DESCENDING,
|
||||
EXTENSION_ASCENDING,
|
||||
EXTENSION_DESCENDING,
|
||||
TYPE_NAME_ASCENDING,
|
||||
TYPE_NAME_DESCENDING,
|
||||
DATE_CREATED_ASCENDING,
|
||||
DATE_CREATED_DESCENDING,
|
||||
DATE_MODIFIED_ASCENDING,
|
||||
DATE_MODIFIED_DESCENDING,
|
||||
ATTRIBUTES_ASCENDING,
|
||||
ATTRIBUTES_DESCENDING,
|
||||
FILE_LIST_FILENAME_ASCENDING,
|
||||
FILE_LIST_FILENAME_DESCENDING,
|
||||
RUN_COUNT_ASCENDING,
|
||||
RUN_COUNT_DESCENDING,
|
||||
DATE_RECENTLY_CHANGED_ASCENDING,
|
||||
DATE_RECENTLY_CHANGED_DESCENDING,
|
||||
DATE_ACCESSED_ASCENDING,
|
||||
DATE_ACCESSED_DESCENDING,
|
||||
DATE_RUN_ASCENDING,
|
||||
DATE_RUN_DESCENDING,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
internal enum AssocF
|
||||
{
|
||||
NONE = 0x00000000,
|
||||
INIT_NOREMAPCLSID = 0x00000001,
|
||||
INIT_BYEXENAME = 0x00000002,
|
||||
INIT_DEFAULTTOSTAR = 0x00000004,
|
||||
INIT_DEFAULTTOFOLDER = 0x00000008,
|
||||
NOUSERSETTINGS = 0x00000010,
|
||||
NOTRUNCATE = 0x00000020,
|
||||
VERIFY = 0x00000040,
|
||||
REMAPRUNDLL = 0x00000080,
|
||||
NOFIXUPS = 0x00000100,
|
||||
IGNOREBASECLASS = 0x00000200,
|
||||
INIT_IGNOREUNKNOWN = 0x00000400,
|
||||
INIT_FIXED_PROGID = 0x00000800,
|
||||
IS_PROTOCOL = 0x00001000,
|
||||
INIT_FOR_FILE = 0x00002000,
|
||||
}
|
||||
|
||||
internal enum AssocStr
|
||||
{
|
||||
COMMAND = 1,
|
||||
EXECUTABLE,
|
||||
FRIENDLYDOCNAME,
|
||||
FRIENDLYAPPNAME,
|
||||
NOOPEN,
|
||||
SHELLNEWVALUE,
|
||||
DDECOMMAND,
|
||||
DDEIFEXEC,
|
||||
DDEAPPLICATION,
|
||||
DDETOPIC,
|
||||
INFOTIP,
|
||||
QUICKTIP,
|
||||
TILEINFO,
|
||||
CONTENTTYPE,
|
||||
DEFAULTICON,
|
||||
SHELLEXTENSION,
|
||||
DROPTARGET,
|
||||
DELEGATEEXECUTE,
|
||||
SUPPORTED_URI_PROTOCOLS,
|
||||
PROGID,
|
||||
APPID,
|
||||
APPPUBLISHER,
|
||||
APPICONREFERENCE,
|
||||
MAX,
|
||||
}
|
||||
#endregion
|
||||
|
||||
internal const string dllName = "Everything64.dll";
|
||||
[DllImport(dllName)]
|
||||
internal static extern uint Everything_GetNumResults();
|
||||
[DllImport(dllName, CharSet = CharSet.Unicode)]
|
||||
internal static extern void Everything_GetResultFullPathName(uint nIndex, StringBuilder lpString, uint nMaxCount);
|
||||
[DllImport(dllName)]
|
||||
internal static extern bool Everything_IsFolderResult(uint index);
|
||||
[DllImport(dllName)]
|
||||
internal static extern bool Everything_QueryW(bool bWait);
|
||||
[DllImport(dllName)]
|
||||
internal static extern void Everything_SetMax(uint dwMax);
|
||||
[DllImport(dllName)]
|
||||
internal static extern void Everything_SetRegex(bool bEnable);
|
||||
[DllImport(dllName)]
|
||||
internal static extern void Everything_SetRequestFlags(Request RequestFlags);
|
||||
[DllImport(dllName, CharSet = CharSet.Unicode)]
|
||||
internal static extern uint Everything_SetSearchW(string lpSearchString);
|
||||
[DllImport(dllName)]
|
||||
internal static extern bool Everything_SetMatchPath(bool bEnable);
|
||||
[DllImport(dllName)]
|
||||
internal static extern void Everything_SetSort(Sort SortType);
|
||||
|
||||
[DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
internal static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] char[] pszOut, [In][Out] ref uint pcchOut);
|
||||
}
|
||||
}
|
125
Main.cs
125
Main.cs
@ -1,41 +1,26 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows.Controls;
|
||||
using Community.PowerToys.Run.Plugin.Everything.Properties;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
using static Community.PowerToys.Run.Plugin.Everything.NativeMethods;
|
||||
|
||||
namespace Community.PowerToys.Run.Plugin.Everything
|
||||
namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using Community.PowerToys.Run.Plugin.Everything.Properties;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
using static Community.PowerToys.Run.Plugin.Everything.Interop.NativeMethods;
|
||||
public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu, ISettingProvider, IPluginI18n
|
||||
{
|
||||
private const string RegEx = nameof(RegEx);
|
||||
private const string NoPreview = nameof(NoPreview);
|
||||
private const string MatchPath = nameof(MatchPath);
|
||||
private const string SwapCopy = nameof(SwapCopy);
|
||||
private const string QueryTextDisplay = nameof(QueryTextDisplay);
|
||||
private bool _regEx;
|
||||
private bool _preview;
|
||||
private bool _matchPath;
|
||||
private bool _swapCopy;
|
||||
private bool _queryTextDisplay;
|
||||
private IContextMenu _contextMenuLoader;
|
||||
private PluginInitContext _context;
|
||||
private bool _disposed;
|
||||
|
||||
private const string Debug = nameof(Debug);
|
||||
private bool _debug;
|
||||
private Settings _setting;
|
||||
private Everything _everything;
|
||||
|
||||
public string Name => Resources.plugin_name;
|
||||
|
||||
@ -45,42 +30,42 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
new PluginAdditionalOption()
|
||||
{
|
||||
Key = MatchPath,
|
||||
DisplayLabel = Resources.Match_path,
|
||||
DisplayDescription = Resources.Match_path_Description,
|
||||
Value = false,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
{
|
||||
Key = NoPreview,
|
||||
DisplayLabel = Resources.Preview,
|
||||
DisplayDescription = Resources.Preview_Description,
|
||||
Value = false,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
{
|
||||
Key = RegEx,
|
||||
DisplayLabel = Resources.RegEx,
|
||||
DisplayDescription = Resources.RegEx_Description,
|
||||
Value = false,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
{
|
||||
Key = SwapCopy,
|
||||
Key = nameof(Settings.Copy),
|
||||
DisplayLabel = Resources.SwapCopy,
|
||||
DisplayDescription = Resources.SwapCopy_Description,
|
||||
Value = false,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
{
|
||||
Key = QueryTextDisplay,
|
||||
Key = nameof(Settings.MatchPath),
|
||||
DisplayLabel = Resources.Match_path,
|
||||
DisplayDescription = Resources.Match_path_Description,
|
||||
Value = false,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
{
|
||||
Key = nameof(Settings.Preview),
|
||||
DisplayLabel = Resources.Preview,
|
||||
DisplayDescription = Resources.Preview_Description,
|
||||
Value = false,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
{
|
||||
Key = nameof(Settings.QueryText),
|
||||
DisplayLabel = Resources.QueryText,
|
||||
DisplayDescription = Resources.QueryText_Description,
|
||||
Value = false,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
{
|
||||
Key = Debug,
|
||||
Key = nameof(Settings.RegEx),
|
||||
DisplayLabel = Resources.RegEx,
|
||||
DisplayDescription = Resources.RegEx_Description,
|
||||
Value = false,
|
||||
},
|
||||
new PluginAdditionalOption()
|
||||
{
|
||||
Key = nameof(Settings.Debug),
|
||||
DisplayLabel = "Log debug data",
|
||||
DisplayDescription = $"v{Assembly.GetExecutingAssembly().GetName().Version}",
|
||||
Value = false,
|
||||
@ -89,10 +74,12 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
Task.Run(() => new Update(Assembly.GetExecutingAssembly().GetName().Version));
|
||||
_context = context;
|
||||
_contextMenuLoader = new ContextMenuLoader(context);
|
||||
((ContextMenuLoader)_contextMenuLoader).UpdateCopy(_swapCopy);
|
||||
EverythingSetup(_debug);
|
||||
((ContextMenuLoader)_contextMenuLoader).UpdateCopy(_setting.Copy);
|
||||
_everything = new Everything(_setting);
|
||||
if (_setting.SkipUpdate) return;
|
||||
}
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
@ -110,7 +97,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
|
||||
try
|
||||
{
|
||||
results.AddRange(EverythingSearch(searchQuery, _preview, _matchPath, _queryTextDisplay, _debug));
|
||||
results.AddRange(_everything.Query(searchQuery, _setting));
|
||||
}
|
||||
catch (System.ComponentModel.Win32Exception)
|
||||
{
|
||||
@ -119,7 +106,6 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
Title = Resources.Everything_not_running,
|
||||
SubTitle = Resources.Everything_ini,
|
||||
IcoPath = "Images/warning.png",
|
||||
QueryTextDisplay = '.' + Resources.plugin_name,
|
||||
Score = int.MaxValue,
|
||||
});
|
||||
}
|
||||
@ -146,17 +132,18 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
if (settings != null && settings.AdditionalOptions != null)
|
||||
{
|
||||
_regEx = settings.AdditionalOptions.FirstOrDefault(x => x.Key == RegEx)?.Value ?? false;
|
||||
_preview = settings.AdditionalOptions.FirstOrDefault(x => x.Key == NoPreview)?.Value ?? false;
|
||||
_matchPath = settings.AdditionalOptions.FirstOrDefault(x => x.Key == MatchPath)?.Value ?? false;
|
||||
_swapCopy = settings.AdditionalOptions.FirstOrDefault(x => x.Key == SwapCopy)?.Value ?? false;
|
||||
_queryTextDisplay = settings.AdditionalOptions.FirstOrDefault(x => x.Key == QueryTextDisplay)?.Value ?? false;
|
||||
_debug = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Debug)?.Value ?? true;
|
||||
_setting ??= new Settings();
|
||||
_setting.RegEx = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.RegEx))?.Value ?? false;
|
||||
_setting.Preview = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Preview))?.Value ?? false;
|
||||
_setting.MatchPath = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.MatchPath))?.Value ?? false;
|
||||
_setting.Copy = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Copy))?.Value ?? false;
|
||||
_setting.QueryText = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.QueryText))?.Value ?? false;
|
||||
_setting.Debug = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Debug))?.Value ?? true;
|
||||
|
||||
if (_contextMenuLoader != null) ((ContextMenuLoader)_contextMenuLoader).UpdateCopy(_swapCopy);
|
||||
if (_contextMenuLoader != null) ((ContextMenuLoader)_contextMenuLoader).UpdateCopy(_setting.Copy);
|
||||
|
||||
Everything_SetRegex(_regEx);
|
||||
Everything_SetMatchPath(_matchPath);
|
||||
Everything_SetRegex(_setting.RegEx);
|
||||
Everything_SetMatchPath(_setting.MatchPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
294
NativeMethods.cs
294
NativeMethods.cs
@ -1,294 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Community.PowerToys.Run.Plugin.Everything.Properties;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
|
||||
namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
internal static class NativeMethods
|
||||
{
|
||||
private static readonly Dictionary<string, string> Filters = new Dictionary<string, string>();
|
||||
private static uint max = 20;
|
||||
private static Sort sort = Sort.DATE_MODIFIED_DESCENDING;
|
||||
|
||||
#region FlagsEnums
|
||||
[Flags]
|
||||
internal enum Request
|
||||
{
|
||||
FILE_NAME = 0x00000001,
|
||||
PATH = 0x00000002,
|
||||
FULL_PATH_AND_FILE_NAME = 0x00000004,
|
||||
EXTENSION = 0x00000008,
|
||||
SIZE = 0x00000010,
|
||||
DATE_CREATED = 0x00000020,
|
||||
DATE_MODIFIED = 0x00000040,
|
||||
DATE_ACCESSED = 0x00000080,
|
||||
ATTRIBUTES = 0x00000100,
|
||||
FILE_LIST_FILE_NAME = 0x00000200,
|
||||
RUN_COUNT = 0x00000400,
|
||||
DATE_RUN = 0x00000800,
|
||||
DATE_RECENTLY_CHANGED = 0x00001000,
|
||||
HIGHLIGHTED_FILE_NAME = 0x00002000,
|
||||
HIGHLIGHTED_PATH = 0x00004000,
|
||||
HIGHLIGHTED_FULL_PATH_AND_FILE_NAME = 0x00008000,
|
||||
}
|
||||
|
||||
internal enum Sort
|
||||
{
|
||||
NAME_ASCENDING = 1,
|
||||
NAME_DESCENDING,
|
||||
PATH_ASCENDING,
|
||||
PATH_DESCENDING,
|
||||
SIZE_ASCENDING,
|
||||
SIZE_DESCENDING,
|
||||
EXTENSION_ASCENDING,
|
||||
EXTENSION_DESCENDING,
|
||||
TYPE_NAME_ASCENDING,
|
||||
TYPE_NAME_DESCENDING,
|
||||
DATE_CREATED_ASCENDING,
|
||||
DATE_CREATED_DESCENDING,
|
||||
DATE_MODIFIED_ASCENDING,
|
||||
DATE_MODIFIED_DESCENDING,
|
||||
ATTRIBUTES_ASCENDING,
|
||||
ATTRIBUTES_DESCENDING,
|
||||
FILE_LIST_FILENAME_ASCENDING,
|
||||
FILE_LIST_FILENAME_DESCENDING,
|
||||
RUN_COUNT_ASCENDING,
|
||||
RUN_COUNT_DESCENDING,
|
||||
DATE_RECENTLY_CHANGED_ASCENDING,
|
||||
DATE_RECENTLY_CHANGED_DESCENDING,
|
||||
DATE_ACCESSED_ASCENDING,
|
||||
DATE_ACCESSED_DESCENDING,
|
||||
DATE_RUN_ASCENDING,
|
||||
DATE_RUN_DESCENDING,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
internal enum AssocF
|
||||
{
|
||||
NONE = 0x00000000,
|
||||
INIT_NOREMAPCLSID = 0x00000001,
|
||||
INIT_BYEXENAME = 0x00000002,
|
||||
INIT_DEFAULTTOSTAR = 0x00000004,
|
||||
INIT_DEFAULTTOFOLDER = 0x00000008,
|
||||
NOUSERSETTINGS = 0x00000010,
|
||||
NOTRUNCATE = 0x00000020,
|
||||
VERIFY = 0x00000040,
|
||||
REMAPRUNDLL = 0x00000080,
|
||||
NOFIXUPS = 0x00000100,
|
||||
IGNOREBASECLASS = 0x00000200,
|
||||
INIT_IGNOREUNKNOWN = 0x00000400,
|
||||
INIT_FIXED_PROGID = 0x00000800,
|
||||
IS_PROTOCOL = 0x00001000,
|
||||
INIT_FOR_FILE = 0x00002000,
|
||||
}
|
||||
|
||||
internal enum AssocStr
|
||||
{
|
||||
COMMAND = 1,
|
||||
EXECUTABLE,
|
||||
FRIENDLYDOCNAME,
|
||||
FRIENDLYAPPNAME,
|
||||
NOOPEN,
|
||||
SHELLNEWVALUE,
|
||||
DDECOMMAND,
|
||||
DDEIFEXEC,
|
||||
DDEAPPLICATION,
|
||||
DDETOPIC,
|
||||
INFOTIP,
|
||||
QUICKTIP,
|
||||
TILEINFO,
|
||||
CONTENTTYPE,
|
||||
DEFAULTICON,
|
||||
SHELLEXTENSION,
|
||||
DROPTARGET,
|
||||
DELEGATEEXECUTE,
|
||||
SUPPORTED_URI_PROTOCOLS,
|
||||
PROGID,
|
||||
APPID,
|
||||
APPPUBLISHER,
|
||||
APPICONREFERENCE,
|
||||
MAX,
|
||||
}
|
||||
#endregion
|
||||
#region DllImports
|
||||
internal const string dllName = "Everything64.dll";
|
||||
|
||||
[DllImport(dllName)]
|
||||
internal static extern uint Everything_GetNumResults();
|
||||
[DllImport(dllName, CharSet = CharSet.Unicode)]
|
||||
internal static extern void Everything_GetResultFullPathName(uint nIndex, StringBuilder lpString, uint nMaxCount);
|
||||
[DllImport(dllName)]
|
||||
internal static extern bool Everything_IsFolderResult(uint index);
|
||||
[DllImport(dllName)]
|
||||
internal static extern bool Everything_QueryW(bool bWait);
|
||||
[DllImport(dllName)]
|
||||
internal static extern void Everything_SetMax(uint dwMax);
|
||||
[DllImport(dllName)]
|
||||
internal static extern void Everything_SetRegex(bool bEnable);
|
||||
[DllImport(dllName)]
|
||||
internal static extern void Everything_SetRequestFlags(Request RequestFlags);
|
||||
[DllImport(dllName, CharSet = CharSet.Unicode)]
|
||||
internal static extern uint Everything_SetSearchW(string lpSearchString);
|
||||
[DllImport(dllName)]
|
||||
internal static extern bool Everything_SetMatchPath(bool bEnable);
|
||||
[DllImport(dllName)]
|
||||
internal static extern void Everything_SetSort(Sort SortType);
|
||||
[DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
internal static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] char[] pszOut, [In][Out] ref uint pcchOut);
|
||||
#endregion
|
||||
public static void EverythingSetup(bool debug)
|
||||
{
|
||||
Everything_SetRequestFlags(Request.FULL_PATH_AND_FILE_NAME);
|
||||
GetCustomSettings(debug);
|
||||
Everything_SetSort(sort);
|
||||
}
|
||||
|
||||
private static void GetCustomSettings(bool debug)
|
||||
{
|
||||
string[] strArr;
|
||||
try { strArr = File.ReadAllLines("modules\\launcher\\Plugins\\Everything\\settings.toml"); }
|
||||
catch { return; }
|
||||
var culture = new System.Globalization.CultureInfo("en-US");
|
||||
foreach (string str in strArr)
|
||||
{
|
||||
if (str.Length == 0 || str[0] == '#') continue;
|
||||
string[] kv = str.Split('=');
|
||||
if (kv.Length != 2) continue;
|
||||
string key = kv[0].Trim();
|
||||
if (key == "max")
|
||||
{
|
||||
try { max = uint.Parse(kv[1].Trim(), culture.NumberFormat); }
|
||||
catch { }
|
||||
}
|
||||
else if (key == "sort")
|
||||
{
|
||||
try { sort = (Sort)int.Parse(kv[1].Trim(), culture.NumberFormat); }
|
||||
catch { }
|
||||
}
|
||||
else if (key.Contains(':'))
|
||||
{
|
||||
Filters.TryAdd(key.Split(':')[0].ToLowerInvariant(), kv[1].Trim());
|
||||
}
|
||||
}
|
||||
|
||||
if (debug)
|
||||
{
|
||||
string msg = $"Max: {max}\nSort: {sort}\nFilters: {string.Join("\n - ", Filters.Select(x => { return x.Key + "_" + x.Value; }))}";
|
||||
Log.Info(msg, typeof(NativeMethods));
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<Result> EverythingSearch(string qry, bool preview, bool matchpath, bool updateQuery, bool debug)
|
||||
{
|
||||
string orgqry = qry;
|
||||
Everything_SetMax(max);
|
||||
if (orgqry.Contains('\"') && !matchpath)
|
||||
{
|
||||
Everything_SetMatchPath(true);
|
||||
}
|
||||
|
||||
if (orgqry.Contains(':'))
|
||||
{
|
||||
string[] nqry = qry.Split(':');
|
||||
if (Filters.ContainsKey(nqry[0].ToLowerInvariant()))
|
||||
{
|
||||
Everything_SetMax(0xffffffff);
|
||||
qry = nqry[1].Trim() + " ext:" + Filters[nqry[0].Trim()];
|
||||
}
|
||||
}
|
||||
|
||||
_ = Everything_SetSearchW(qry);
|
||||
if (!Everything_QueryW(true))
|
||||
{
|
||||
throw new Win32Exception("Unable to Query");
|
||||
}
|
||||
|
||||
if (orgqry.Contains('\"') && !matchpath)
|
||||
{
|
||||
Everything_SetMatchPath(false);
|
||||
}
|
||||
|
||||
uint resultCount = Everything_GetNumResults();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Log.Info(qry + " => " + resultCount, typeof(NativeMethods), "EverythingSearch.ResultCount", string.Empty, 217);
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Log.Info(i + " : " + ext, typeof(NativeMethods), "EverythingSearch.Result", string.Empty, 229);
|
||||
}
|
||||
|
||||
var r = new Result()
|
||||
{
|
||||
Title = name,
|
||||
ToolTipData = debug ?
|
||||
new ToolTipData(orgqry, qry) :
|
||||
new ToolTipData("Name : " + name, fullPath),
|
||||
SubTitle = Resources.plugin_name + ": " + fullPath,
|
||||
|
||||
IcoPath = isFolder ? "Images/folder.png" : (preview ?
|
||||
fullPath : (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();
|
||||
return true;
|
||||
}
|
||||
catch (Win32Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
QueryTextDisplay = updateQuery ? (isFolder ? path : name) : orgqry,
|
||||
};
|
||||
yield return r;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
|
||||
internal static string? Icon(string doctype)
|
||||
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
|
||||
{
|
||||
uint pcchOut = 0;
|
||||
_ = AssocQueryString(AssocF.NONE, AssocStr.DEFAULTICON, doctype, null, null, ref pcchOut);
|
||||
char[] pszOut = new char[pcchOut];
|
||||
if (AssocQueryString(AssocF.NONE, AssocStr.DEFAULTICON, doctype, null, pszOut, ref pcchOut) != 0) return null;
|
||||
string doc = Environment.ExpandEnvironmentVariables(new string(pszOut).Split(new char[] { '\"', ',' }, StringSplitOptions.RemoveEmptyEntries)[0].Replace("\"", string.Empty, StringComparison.CurrentCulture).Trim());
|
||||
|
||||
return File.Exists(doc) ? doc : null;
|
||||
}
|
||||
}
|
||||
}
|
22
SearchHelper/IconLoader.cs
Normal file
22
SearchHelper/IconLoader.cs
Normal file
@ -0,0 +1,22 @@
|
||||
namespace Community.PowerToys.Run.Plugin.Everything.SearchHelper
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using static Interop.NativeMethods;
|
||||
|
||||
internal class IconLoader
|
||||
{
|
||||
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
|
||||
internal static string? Icon(string doctype)
|
||||
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
|
||||
{
|
||||
uint pcchOut = 0;
|
||||
_ = AssocQueryString(AssocF.NONE, AssocStr.DEFAULTICON, doctype, null, null, ref pcchOut);
|
||||
char[] pszOut = new char[pcchOut];
|
||||
if (AssocQueryString(AssocF.NONE, AssocStr.DEFAULTICON, doctype, null, pszOut, ref pcchOut) != 0) return null;
|
||||
string doc = Environment.ExpandEnvironmentVariables(new string(pszOut).Split(new char[] { '\"', ',' }, StringSplitOptions.RemoveEmptyEntries)[0].Replace("\"", string.Empty, StringComparison.CurrentCulture).Trim());
|
||||
|
||||
return File.Exists(doc) ? doc : null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,4 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace Community.PowerToys.Run.Plugin.Everything
|
||||
namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
public class SearchResult
|
||||
{
|
||||
|
62
Settings.cs
Normal file
62
Settings.cs
Normal file
@ -0,0 +1,62 @@
|
||||
namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Community.PowerToys.Run.Plugin.Everything.Interop;
|
||||
using Wox.Plugin.Logger;
|
||||
|
||||
internal class Settings
|
||||
{
|
||||
// Settings from PTR settings
|
||||
internal bool Copy { get; set; } = false;
|
||||
internal bool MatchPath { get; set; } = false;
|
||||
internal bool Preview { get; set; } = false;
|
||||
internal bool QueryText { get; set; } = false;
|
||||
internal bool RegEx { get; set; } = false;
|
||||
internal bool Debug { get; set; } = false;
|
||||
|
||||
// Settings from settings.toml
|
||||
internal uint Max { get; set; } = 20;
|
||||
internal int Sort { get; set; } = 14;
|
||||
internal Dictionary<string, string> Filters { get; set; } = new Dictionary<string, string>();
|
||||
internal bool SkipUpdate { get; set; } = false;
|
||||
internal Settings()
|
||||
{
|
||||
string[] strArr;
|
||||
try { strArr = File.ReadAllLines("modules\\launcher\\Plugins\\Everything\\settings.toml"); }
|
||||
catch { return; }
|
||||
var culture = new System.Globalization.CultureInfo("en-US");
|
||||
foreach (string str in strArr)
|
||||
{
|
||||
if (str.Length == 0 || str[0] == '#') continue;
|
||||
string[] kv = str.Split('=', System.StringSplitOptions.RemoveEmptyEntries | System.StringSplitOptions.TrimEntries);
|
||||
if (kv.Length != 2) continue;
|
||||
switch (kv[0])
|
||||
{
|
||||
case "max":
|
||||
try { Max = uint.Parse(kv[1], culture.NumberFormat); }
|
||||
catch { }
|
||||
break;
|
||||
case "sort":
|
||||
try { Sort = int.Parse(kv[1], culture.NumberFormat); }
|
||||
catch { }
|
||||
break;
|
||||
case "skip":
|
||||
if (kv[1][0] == 'Y') SkipUpdate = true;
|
||||
break;
|
||||
default:
|
||||
if (kv[0].Contains(':'))
|
||||
Filters.TryAdd(kv[0].Split(':')[0].ToLowerInvariant(), kv[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Debug)
|
||||
{
|
||||
string msg = $"Max: {Max}\nSort: {Sort}\nFilters: {string.Join("\n - ", Filters.Select(x => { return x.Key + "_" + x.Value; }))}";
|
||||
Log.Info(msg, typeof(NativeMethods));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
35
Update.cs
Normal file
35
Update.cs
Normal file
@ -0,0 +1,35 @@
|
||||
namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Xml;
|
||||
|
||||
internal class Update
|
||||
{
|
||||
private const string URL = "https://img.shields.io/github/v/release/lin-ycv/everythingpowertoys";
|
||||
internal Update(Version v)
|
||||
{
|
||||
try
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(URL);
|
||||
Version latest = Version.Parse(doc.GetElementsByTagName("title")[0].InnerXml.Split(':', StringSplitOptions.TrimEntries)[1].Remove(0, 1));
|
||||
if (latest > v)
|
||||
{
|
||||
MessageBoxResult mbox = MessageBox.Show($"New version available for EverythingPowerToys.\n\nInstalled:\t {v}\nLatest:\t {latest}", "Download Update?", MessageBoxButton.OKCancel);
|
||||
if (mbox == MessageBoxResult.OK)
|
||||
{
|
||||
ProcessStartInfo p = new ProcessStartInfo("https://github.com/lin-ycv/EverythingPowerToys/releases/latest")
|
||||
{
|
||||
UseShellExecute = true,
|
||||
Verb = "Open",
|
||||
};
|
||||
Process.Start(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) { MessageBox.Show(e.ToString()); }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
# This is the settings file to override the behaviour for "Everything for PowerToys"
|
||||
# to override a setting, uncomment that line by uncommenting and changing the value
|
||||
# ie: "# max = 20" -> "max = 10"
|
||||
# Restart of powertoys is needed if values are changed
|
||||
|
||||
# Set max amount of results to return [default: 20]
|
||||
# max = 20
|
||||
@ -9,13 +10,13 @@
|
||||
# https://www.voidtools.com/support/everything/sdk/everything_getsort/
|
||||
# sort = 14
|
||||
|
||||
# Skip update check at start [Y/N default: N]
|
||||
# skip = N
|
||||
|
||||
# Search filters, filters result with extension type, seperated by ;
|
||||
Audio: = aac;ac3;aif;aifc;aiff;amr;ape;au;cda;dts;fla;flac;it;m1a;m2a;m3u;m4a;m4b;m4p;mid;midi;mka;mod;mp2;mp3;mpa;ogg;opus;ra;rmi;spc;rmi;snd;umx;voc;wav;weba;wma;xm
|
||||
Zip: = 7z;ace;arj;bz2;cab;gz;gzip;jar;r00;r01;r02;r03;r04;r05;r06;r07;r08;r09;r10;r11;r12;r13;r14;r15;r16;r17;r18;r19;r20;r21;r22;r23;r24;r25;r26;r27;r28;r29;rar;tar;tgz;z;zip
|
||||
Doc: = c;cc;chm;cpp;cs;css;csv;cxx;doc;docm;docx;dot;dotm;dotx;epub;gh;h;hpp;htm;html;hxx;ini;java;js;json;lua;mht;mhtml;mobi;odp;ods;odt;pdf;php;potx;potm;ppam;ppsm;ppsx;pps;ppt;pptm;pptx;pub;py;rtf;sldm;sldx;thmx;txt;vsd;wpd;wps;wri;xlam;xls;xlsb;xlsm;xlsx;xltm;xltx;xml;vb
|
||||
Exe: = bat;cmd;exe;msi;msp;msu;ps1;scr
|
||||
Pic: = ani;apng;bmp;bpg;cur;gif;ico;jfi;jfif;jif;jpe;jpeg;jpg;pcx;png;psb;psd;rle;svg;tga;tif;tiff;webp;wmf
|
||||
Video: = 3g2;3gp;3gp2;3gpp;amv;asf;asx;avi;bdmv;bik;d2v;divx;drc;dsa;dsm;dss;dsv;evo;f4v;flc;fli;flic;flv;hdmov;ifo;ivf;m1v;m2p;m2t;m2ts;m2v;m4v;mkv;mp2v;mp4;mp4v;mpe;mpeg;mpg;mpls;mpv2;mpv4;mov;mts;ogm;ogv;pss;pva;qt;ram;ratdvd;rm;rmm;rmvb;roq;rpm;smil;smk;swf;tp;tpr;ts;vob;vp6;webm;wm;wmp;wmv
|
||||
|
||||
# There are no more override options
|
||||
# Restart of powertoys is needed if values are changed
|
||||
Video: = 3g2;3gp;3gp2;3gpp;amv;asf;asx;avi;bdmv;bik;d2v;divx;drc;dsa;dsm;dss;dsv;evo;f4v;flc;fli;flic;flv;hdmov;ifo;ivf;m1v;m2p;m2t;m2ts;m2v;m4v;mkv;mp2v;mp4;mp4v;mpe;mpeg;mpg;mpls;mpv2;mpv4;mov;mts;ogm;ogv;pss;pva;qt;ram;ratdvd;rm;rmm;rmvb;roq;rpm;smil;smk;swf;tp;tpr;ts;vob;vp6;webm;wm;wmp;wmv
|
Loading…
Reference in New Issue
Block a user