diff --git a/Community.PowerToys.Run.Plugin.Everything.csproj b/Community.PowerToys.Run.Plugin.Everything.csproj index 103be97..5bb09a6 100644 --- a/Community.PowerToys.Run.Plugin.Everything.csproj +++ b/Community.PowerToys.Run.Plugin.Everything.csproj @@ -7,12 +7,17 @@ Properties Community.PowerToys.Run.Plugin.Everything Community.PowerToys.Run.Plugin.Everything - $(Version).0 + 0.0.2.1 true false false x64 en-US + Yu Chieh (Victor) Lin + + + 0.0.2.1 + 0.0.2.1 @@ -98,6 +103,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Everything64.dll b/Everything64.dll index 6d093b7..f8db5a5 100644 Binary files a/Everything64.dll and b/Everything64.dll differ diff --git a/Everything64_Official.dll b/Everything64_Official.dll new file mode 100644 index 0000000..6d093b7 Binary files /dev/null and b/Everything64_Official.dll differ diff --git a/Main.cs b/Main.cs index c21b596..9a7342a 100644 --- a/Main.cs +++ b/Main.cs @@ -25,8 +25,10 @@ namespace Community.PowerToys.Run.Plugin.Everything public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu, ISettingProvider { private const string Wait = nameof(Wait); + private const string Top = nameof(Top); private readonly string reservedStringPattern = @"^[\/\\\$\%]+$|^.*[<>].*$"; private bool _wait; + private bool _top; public string Name => Resources.plugin_name; @@ -34,6 +36,12 @@ namespace Community.PowerToys.Run.Plugin.Everything public IEnumerable AdditionalOptions => new List() { + new PluginAdditionalOption() + { + Key = Top, + DisplayLabel = Resources.Top, + Value = true, + }, new PluginAdditionalOption() { Key = Wait, @@ -42,12 +50,18 @@ namespace Community.PowerToys.Run.Plugin.Everything }, }; - private string IconPath { get; set; } - private IContextMenu _contextMenuLoader; private PluginInitContext _context; private bool disposed; - private string _warningIconPath; + private static string _warningIconPath; + + internal static string WarningIcon + { + get + { + return _warningIconPath; + } + } public void Init(PluginInitContext context) { @@ -55,6 +69,7 @@ namespace Community.PowerToys.Run.Plugin.Everything _contextMenuLoader = new ContextMenuLoader(context); _context.API.ThemeChanged += OnThemeChanged; UpdateIconPath(_context.API.GetCurrentTheme()); + EverythingSetup(); } public List Query(Query query) @@ -78,7 +93,7 @@ namespace Community.PowerToys.Run.Plugin.Everything { try { - results.AddRange(EverythingSearch(searchQuery, _wait)); + results.AddRange(EverythingSearch(searchQuery, _wait, _top)); } catch (OperationCanceledException) { @@ -87,21 +102,23 @@ namespace Community.PowerToys.Run.Plugin.Everything Title = Resources.timeout, SubTitle = Resources.enable_wait, IcoPath = _warningIconPath, + Score = int.MaxValue, }); } - catch (EntryPointNotFoundException) + catch (System.ComponentModel.Win32Exception) { results.Add(new Result() { Title = Resources.Everything_not_running, SubTitle = Resources.Everything_ini, IcoPath = _warningIconPath, - QueryTextDisplay = Resources.Everything_url, + QueryTextDisplay = '.' + Resources.plugin_name, + Score = int.MaxValue, }); } catch (Exception e) { - Log.Exception("Something failed", e, GetType()); + Log.Exception("Everything Exception", e, GetType()); } } } @@ -114,16 +131,14 @@ namespace Community.PowerToys.Run.Plugin.Everything UpdateIconPath(newTheme); } - private void UpdateIconPath(Theme theme) + private static void UpdateIconPath(Theme theme) { if (theme == Theme.Light || theme == Theme.HighContrastWhite) { - IconPath = "Images/Everything.light.png"; _warningIconPath = "Images/Warning.light.png"; } else { - IconPath = "Images/Everything.dark.png"; _warningIconPath = "Images/Warning.dark.png"; } } @@ -141,11 +156,14 @@ namespace Community.PowerToys.Run.Plugin.Everything public void UpdateSettings(PowerLauncherPluginSettings settings) { var wait = false; + var top = true; if (settings != null && settings.AdditionalOptions != null) { wait = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Wait)?.Value ?? false; + top = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Top)?.Value ?? true; } + _top = top; _wait = wait; } diff --git a/NativeMethods.cs b/NativeMethods.cs index b17d842..9cd56c2 100644 --- a/NativeMethods.cs +++ b/NativeMethods.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; @@ -12,24 +13,13 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; +using Community.PowerToys.Run.Plugin.Everything.Properties; using Wox.Plugin; namespace Community.PowerToys.Run.Plugin.Everything { internal static class NativeMethods { - internal enum ErrorCode - { - OK, - ERROR_MEMORY, - ERROR_IPC, - ERROR_REGISTERCLASSEX, - ERROR_CREATEWINDOW, - ERROR_CREATETHREAD, - ERROR_INVALIDINDEX, - ERROR_INVALIDCALL, - } - internal enum Request { FILE_NAME = 0x00000001, @@ -80,167 +70,35 @@ namespace Community.PowerToys.Run.Plugin.Everything DATE_RUN_DESCENDING, } - internal const int TARGET_MACHINE_X86 = 1; - internal const int TARGET_MACHINE_X64 = 2; - internal const int TARGET_MACHINE_ARM = 3; - private const string dllName = "Everything64.dll"; + internal const string dllName = "Everything64.dll"; // Included dll is a modified file without locking, if this creates issues, replace with official dll #pragma warning disable SA1516 // Elements should be separated by blank line - [DllImport(dllName)] - public static extern void Everything_CleanUp(); - [DllImport(dllName)] - public static extern uint Everything_DeleteRunHistory(); - [DllImport(dllName)] - public static extern uint Everything_Exit(); - - [DllImport(dllName)] - public static extern uint Everything_GetBuildNumber(); - [DllImport(dllName)] - public static extern uint Everything_GetLastError(); - [DllImport(dllName)] - public static extern uint Everything_GetMajorVersion(); - [DllImport(dllName)] - public static extern bool Everything_GetMatchCase(); - [DllImport(dllName)] - public static extern bool Everything_GetMatchPath(); - [DllImport(dllName)] - public static extern bool Everything_GetMatchWholeWord(); - [DllImport(dllName)] - public static extern uint Everything_GetMax(); - [DllImport(dllName)] - public static extern uint Everything_GetMinorVersion(); - [DllImport(dllName)] - public static extern uint Everything_GetNumFileResults(); - [DllImport(dllName)] - public static extern uint Everything_GetNumFolderResults(); [DllImport(dllName)] public static extern uint Everything_GetNumResults(); - [DllImport(dllName)] - public static extern uint Everything_GetOffset(); - [DllImport(dllName)] - public static extern bool Everything_GetRegex(); - [DllImport(dllName)] - public static extern uint Everything_GetReplyID(); - [DllImport(dllName)] - public static extern uint Everything_GetRequestFlags(); - [DllImport(dllName)] - - public static extern uint Everything_GetResultAttributes(uint nIndex); - [DllImport(dllName)] - public static extern bool Everything_GetResultDateAccessed(uint nIndex, out long lpFileTime); - [DllImport(dllName)] - public static extern bool Everything_GetResultDateCreated(uint nIndex, out long lpFileTime); - [DllImport(dllName)] - public static extern bool Everything_GetResultDateModified(uint nIndex, out long lpFileTime); - [DllImport(dllName)] - public static extern bool Everything_GetResultDateRecentlyChanged(uint nIndex, out long lpFileTime); - [DllImport(dllName)] - public static extern bool Everything_GetResultDateRun(uint nIndex, out long lpFileTime); - [DllImport(dllName, CharSet = CharSet.Unicode)] - public static extern IntPtr Everything_GetResultExtension(uint nIndex); - [DllImport(dllName, CharSet = CharSet.Unicode)] - public static extern IntPtr Everything_GetResultFileListFileName(uint nIndex); - [DllImport(dllName, CharSet = CharSet.Unicode)] - public static extern IntPtr Everything_GetResultFileName(uint nIndex); [DllImport(dllName, CharSet = CharSet.Unicode)] public static extern void Everything_GetResultFullPathName(uint nIndex, StringBuilder lpString, uint nMaxCount); - [DllImport(dllName, CharSet = CharSet.Unicode)] - public static extern IntPtr Everything_GetResultHighlightedFileName(uint nIndex); - [DllImport(dllName, CharSet = CharSet.Unicode)] - public static extern IntPtr Everything_GetResultHighlightedFullPathAndFileName(uint nIndex); - [DllImport(dllName, CharSet = CharSet.Unicode)] - public static extern IntPtr Everything_GetResultHighlightedPath(uint nIndex); - [DllImport(dllName)] - public static extern uint Everything_GetResultListRequestFlags(); - [DllImport(dllName)] - public static extern uint Everything_GetResultListSort(); - [DllImport(dllName)] - public static extern IntPtr Everything_GetResultPath(uint nIndex); - [DllImport(dllName)] - public static extern uint Everything_GetResultRunCount(uint nIndex); - [DllImport(dllName)] - public static extern bool Everything_GetResultSize(uint nIndex, out long lpFileSize); - - [DllImport(dllName)] - public static extern uint Everything_GetRevision(); - [DllImport(dllName, CharSet = CharSet.Unicode)] - public static extern uint Everything_GetRunCountFromFileName(string lpFileName); - [DllImport(dllName)] - public static extern IntPtr Everything_GetSearchW(); - [DllImport(dllName)] - public static extern uint Everything_GetSort(); - - [DllImport(dllName)] - public static extern uint Everything_GetTotFileResults(); - [DllImport(dllName)] - public static extern uint Everything_GetTotFolderResults(); - [DllImport(dllName)] - public static extern uint Everything_GetTotResults(); - - [DllImport(dllName, CharSet = CharSet.Unicode)] - public static extern uint Everything_IncRunCountFromFileName(string lpFileName); - [DllImport(dllName)] - public static extern bool Everything_IsAdmin(); - [DllImport(dllName)] - public static extern bool Everything_IsAppData(); - [DllImport(dllName)] - public static extern bool Everything_IsDBLoaded(); - [DllImport(dllName)] - public static extern bool Everything_IsFastSort(uint sortType); - [DllImport(dllName)] - public static extern bool Everything_IsFileInfoIndexed(uint fileInfoType); - [DllImport(dllName)] - public static extern bool Everything_IsFileResult(uint nIndex); - [DllImport(dllName)] - public static extern bool Everything_IsFolderResult(uint nIndex); - [DllImport(dllName)] - public static extern bool Everything_IsQueryReply(uint message, uint wParam, long lParam, uint nId); - [DllImport(dllName)] - public static extern bool Everything_IsVolumeResult(uint nIndex); - [DllImport(dllName)] public static extern bool Everything_QueryW(bool bWait); [DllImport(dllName)] - public static extern bool Everything_RebuildDB(); - [DllImport(dllName)] - public static extern void Everything_Reset(); - [DllImport(dllName)] - public static extern bool Everything_SaveDB(); - [DllImport(dllName)] - public static extern bool Everything_SaveRunHistory(); - - [DllImport(dllName)] - public static extern void Everything_SetMatchCase(bool bEnable); - [DllImport(dllName)] - public static extern void Everything_SetMatchPath(bool bEnable); - [DllImport(dllName)] - public static extern void Everything_SetMatchWholeWord(bool bEnable); - [DllImport(dllName)] public static extern void Everything_SetMax(uint dwMax); [DllImport(dllName)] - public static extern void Everything_SetOffset(uint dwOffset); - [DllImport(dllName)] - public static extern void Everything_SetRegex(bool bEnable); - [DllImport(dllName)] - public static extern void Everything_SetReplyID(uint nId); - [DllImport(dllName)] public static extern void Everything_SetRequestFlags(Request RequestFlags); [DllImport(dllName, CharSet = CharSet.Unicode)] - public static extern bool Everything_SetRunCountFromFileName(string lpFileName, uint dwRunCount); - [DllImport(dllName, CharSet = CharSet.Unicode)] public static extern uint Everything_SetSearchW(string lpSearchString); [DllImport(dllName)] public static extern void Everything_SetSort(Sort SortType); - [DllImport(dllName)] - public static extern void Everything_SortResultsByPath(); - [DllImport(dllName)] - public static extern bool Everything_UpdateAllFolderIndexes(); - private const int max = 20; private static CancellationTokenSource source; #pragma warning disable SA1503 // Braces should not be omitted - public static IEnumerable EverythingSearch(string qry, bool wait) + public static void EverythingSetup() + { + Everything_SetRequestFlags(Request.FULL_PATH_AND_FILE_NAME); + Everything_SetSort(Sort.DATE_MODIFIED_DESCENDING); + Everything_SetMax(max); + } + + public static IEnumerable EverythingSearch(string qry, bool wait, bool top) { source?.Cancel(); source = new CancellationTokenSource(); @@ -249,23 +107,16 @@ namespace Community.PowerToys.Run.Plugin.Everything _ = Everything_SetSearchW(qry); if (token.IsCancellationRequested) token.ThrowIfCancellationRequested(); - Everything_SetRequestFlags(Request.FULL_PATH_AND_FILE_NAME); - if (token.IsCancellationRequested) token.ThrowIfCancellationRequested(); - Everything_SetSort(Sort.DATE_MODIFIED_DESCENDING); - if (token.IsCancellationRequested) token.ThrowIfCancellationRequested(); - Everything_SetMax(max); - if (token.IsCancellationRequested) token.ThrowIfCancellationRequested(); - if (!Everything_QueryW(true)) { - throw new EntryPointNotFoundException(); + throw new Win32Exception("Unable to Query"); } uint resultCount = Everything_GetNumResults(); - if (token.IsCancellationRequested) token.ThrowIfCancellationRequested(); for (uint i = 0; i < resultCount; i++) { + if (token.IsCancellationRequested) break; StringBuilder sb = new StringBuilder(260); Everything_GetResultFullPathName(i, sb, 260); string fullPath = sb.ToString(); @@ -277,13 +128,12 @@ namespace Community.PowerToys.Run.Plugin.Everything else path = Path.GetDirectoryName(fullPath); - yield return new Result() + var r = new Result() { Title = name, ToolTipData = new ToolTipData("Name : " + name, "Path : " + path), - SubTitle = Properties.Resources.plugin_name + ": " + fullPath, + SubTitle = Resources.plugin_name + ": " + fullPath, IcoPath = fullPath, - Score = (int)(max - i), ContextData = new SearchResult() { Path = fullPath, @@ -302,7 +152,7 @@ namespace Community.PowerToys.Run.Plugin.Everything process.Start(); return true; } - catch (System.ComponentModel.Win32Exception) + catch (Win32Exception) { return false; } @@ -310,7 +160,19 @@ namespace Community.PowerToys.Run.Plugin.Everything }, QueryTextDisplay = isFolder ? path : name, }; - if (token.IsCancellationRequested) yield break/*token.ThrowIfCancellationRequested()*/; + if (top) r.Score = (int)(max - i); + yield return r; + } + + if (token.IsCancellationRequested) + { + yield return new Result() + { + Title = Resources.timeout, + SubTitle = Resources.enable_wait, + IcoPath = Main.WarningIcon, + Score = int.MaxValue, + }; } } #pragma warning restore SA1503 // Braces should not be omitted diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 636f43e..e8108cc 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -105,15 +105,6 @@ namespace Community.PowerToys.Run.Plugin.Everything.Properties { } } - /// - /// Looks up a localized string similar to https://www.voidtools.com/downloads/. - /// - public static string Everything_url { - get { - return ResourceManager.GetString("Everything_url", resourceCulture); - } - } - /// /// Looks up a localized string similar to Fail to open folder at. /// @@ -177,6 +168,15 @@ namespace Community.PowerToys.Run.Plugin.Everything.Properties { } } + /// + /// Looks up a localized string similar to Insert result at the top of the list.. + /// + public static string Top { + get { + return ResourceManager.GetString("Top", resourceCulture); + } + } + /// /// Looks up a localized string similar to Wait - Wait longer for the query to finish.. /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 22a80cc..83aa97e 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -132,9 +132,6 @@ Everything is not running - - https://www.voidtools.com/downloads/ - Fail to open folder at @@ -156,6 +153,9 @@ Timed out before finishing the query + + Insert result at the top of the list. + Wait - Wait longer for the query to finish. diff --git a/plugin.json b/plugin.json index c0150da..2a02cda 100644 --- a/plugin.json +++ b/plugin.json @@ -4,7 +4,7 @@ "IsGlobal": true, "Name": "Everything", "Author": "Yu Chieh (Victor) Lin", - "Version": "0.2.0", + "Version": "0.2.1", "Language": "csharp", "Website": "https://aka.ms/powertoys", "ExecuteFileName": "Community.PowerToys.Run.Plugin.Everything.dll",