diff --git a/Community.PowerToys.Run.Plugin.Everything.csproj b/Community.PowerToys.Run.Plugin.Everything.csproj index d862678..0147245 100644 --- a/Community.PowerToys.Run.Plugin.Everything.csproj +++ b/Community.PowerToys.Run.Plugin.Everything.csproj @@ -1,23 +1,22 @@ - + - netcoreapp3.1 + net5.0-windows {64467D32-4786-4ADD-9B77-FBF3C965D3D1} Properties Community.PowerToys.Run.Plugin.Everything Community.PowerToys.Run.Plugin.Everything - 0.0.2.5 + $([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)plugin.json').Split(',')[5].Split(':')[1].Trim().Trim('"')) true false false x64 en-US Yu Chieh (Victor) Lin - - - 0.0.2.5 - 0.0.2.5 + false + + true @@ -38,13 +37,15 @@ ..\..\..\..\..\x64\Release\modules\launcher\Plugins\Everything\ TRACE true - pdbonly + none x64 7.3 prompt MinimumRecommendedRules.ruleset 4 true + false + Auto @@ -59,9 +60,11 @@ false + false false + false @@ -106,9 +109,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest @@ -121,7 +121,7 @@ - + diff --git a/Images/Everything.ico.png b/Images/Everything.ico.png deleted file mode 100644 index 67bbe09..0000000 Binary files a/Images/Everything.ico.png and /dev/null differ diff --git a/Main.cs b/Main.cs index 3c76962..fe8d21a 100644 --- a/Main.cs +++ b/Main.cs @@ -26,11 +26,11 @@ public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu, { private const string Wait = nameof(Wait); private const string Top = nameof(Top); - private const string NoPreview = nameof(NoPreview); + private const string Preview = nameof(Preview); private readonly string reservedStringPattern = @"^[\/\\\$\%]+$|^.*[<>].*$"; private bool _wait; private bool _top; - private bool _noPreview; + private bool _preview; public string Name => Resources.plugin_name; @@ -52,8 +52,8 @@ public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu, }, new PluginAdditionalOption() { - Key = NoPreview, - DisplayLabel = Resources.NoPreview, + Key = Preview, + DisplayLabel = Resources.Preview, Value = false, }, }; @@ -104,10 +104,10 @@ public List Query(Query query, bool isFullQuery) source?.Cancel(); source = new CancellationTokenSource(); CancellationToken token = source.Token; - source.CancelAfter(_wait ? 1000 : 75); + source.CancelAfter(_wait ? 1000 : 120); try { - results.AddRange(EverythingSearch(searchQuery, _top, _noPreview, token)); + results.AddRange(EverythingSearch(searchQuery, _top, _preview, token)); } catch (OperationCanceledException) { @@ -177,12 +177,12 @@ public void UpdateSettings(PowerLauncherPluginSettings settings) { wait = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Wait)?.Value ?? false; top = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Top)?.Value ?? false; - nopreview = settings.AdditionalOptions.FirstOrDefault(x => x.Key == NoPreview)?.Value ?? false; + nopreview = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Preview)?.Value ?? false; } _top = top; _wait = wait; - _noPreview = nopreview; + _preview = nopreview; } protected virtual void Dispose(bool disposing) diff --git a/NativeMethods.cs b/NativeMethods.cs index 4c4bd83..56afcc4 100644 --- a/NativeMethods.cs +++ b/NativeMethods.cs @@ -3,17 +3,20 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.IO.Abstractions; +using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using Community.PowerToys.Run.Plugin.Everything.Properties; +using Microsoft.Win32; using Wox.Plugin; namespace Community.PowerToys.Run.Plugin.Everything @@ -97,7 +100,7 @@ public static void EverythingSetup() Everything_SetMax(max); } - public static IEnumerable EverythingSearch(string qry, bool top, bool noPreview, CancellationToken token) + public static IEnumerable EverythingSearch(string qry, bool top, bool preview, CancellationToken token) { _ = Everything_SetSearchW(qry); if (token.IsCancellationRequested) token.ThrowIfCancellationRequested(); @@ -121,13 +124,14 @@ public static IEnumerable EverythingSearch(string qry, bool top, bool no path = fullPath; else path = Path.GetDirectoryName(fullPath); + string ext = Path.GetExtension(fullPath); var r = new Result() { Title = name, ToolTipData = new ToolTipData("Name : " + name, "Path : " + path), SubTitle = Resources.plugin_name + ": " + fullPath, - IcoPath = noPreview ? "Images/Everything.ico.png" : fullPath, + IcoPath = (preview || string.IsNullOrEmpty(ext) || string.IsNullOrEmpty((string)Icons[ext])) ? fullPath : (string)Icons[ext], ContextData = new SearchResult() { Path = fullPath, @@ -154,7 +158,7 @@ public static IEnumerable EverythingSearch(string qry, bool top, bool no }, QueryTextDisplay = isFolder ? path : name, }; - if (top) r.Score = (int)(max - i); + if (top) r.Score = (int)(300 - i); yield return r; } @@ -169,6 +173,56 @@ public static IEnumerable EverythingSearch(string qry, bool top, bool no }; } } + + // Credits https://www.codeproject.com/Articles/29137/Get-Registered-File-Types-and-Their-Associated-Ico + [DllImport("shell32.dll", EntryPoint = "ExtractIconA", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)] + private static extern IntPtr ExtractIcon(int hInst, string lpszExeFileName, int nIconIndex); + internal static readonly Hashtable Icons = GetFileTypeAndIcon(); + internal static Hashtable GetFileTypeAndIcon() + { + try + { + RegistryKey rkRoot = Registry.ClassesRoot; + string[] keyNames = rkRoot.GetSubKeyNames(); + Hashtable iconsInfo = new Hashtable(StringComparer.InvariantCultureIgnoreCase); + foreach (string keyName in keyNames) + { + if (string.IsNullOrEmpty(keyName)) + continue; + int indexOfPoint = keyName.IndexOf(".", StringComparison.CurrentCulture); + if (indexOfPoint != 0) + continue; + RegistryKey rkFileType = rkRoot.OpenSubKey(keyName); + if (rkFileType == null) + continue; + object defaultValue = rkFileType.GetValue(string.Empty); + if (defaultValue == null) + continue; + string defaultIcon = defaultValue.ToString() + "\\DefaultIcon"; + RegistryKey rkFileIcon = rkRoot.OpenSubKey(defaultIcon); + if (rkFileIcon != null) + { + object value = rkFileIcon.GetValue(string.Empty); + if (value != null) + { + string fileParam = value.ToString().Replace("\"", string.Empty, StringComparison.CurrentCulture).Split(',')[0].Trim(); + iconsInfo.Add(keyName, fileParam); + } + + rkFileIcon.Close(); + } + + rkFileType.Close(); + } + + rkRoot.Close(); + return iconsInfo; + } + catch (Exception) + { + throw; + } + } #pragma warning restore SA1503 // Braces should not be omitted } } diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index ff4485d..8a0d9f7 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -114,15 +114,6 @@ public static string folder_open_failed { } } - /// - /// Looks up a localized string similar to Fast - Disable icon preview, fetching icons for non-local files may cause freezing.. - /// - public static string NoPreview { - get { - return ResourceManager.GetString("NoPreview", resourceCulture); - } - } - /// /// Looks up a localized string similar to Open containing folder (Ctrl+Shift+E). /// @@ -159,6 +150,15 @@ public static string plugin_name { } } + /// + /// Looks up a localized string similar to Preview - Preview file content as icon, may cause freezing if file not local.. + /// + public static string Preview { + get { + return ResourceManager.GetString("Preview", resourceCulture); + } + } + /// /// Looks up a localized string similar to Run as administrator (Ctrl+Shift+Enter). /// @@ -178,7 +178,7 @@ public static string timeout { } /// - /// Looks up a localized string similar to Top - Insert result at the top of the list.. + /// Looks up a localized string similar to Top - Insert result at the top of the list, may cause pre-selection issue.. /// public static string Top { get { @@ -187,7 +187,7 @@ public static string Top { } /// - /// Looks up a localized string similar to Wait - Wait longer for the query to finish.. + /// Looks up a localized string similar to Wait - Wait longer for the query to finish, enable only if prompted to.. /// public static string Wait { get { diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 8ef0602..2d7da90 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -135,9 +135,6 @@ Fail to open folder at - - Fast - Disable icon preview, fetching icons for non-local files may cause freezing. - Open containing folder (Ctrl+Shift+E) @@ -150,6 +147,9 @@ Everything + + Preview - Preview file content as icon, may cause freezing if file not local. + Run as administrator (Ctrl+Shift+Enter) @@ -157,9 +157,9 @@ Timed out before finishing the query - Top - Insert result at the top of the list. + Top - Insert result at the top of the list, may cause pre-selection issue. - Wait - Wait longer for the query to finish. + Wait - Wait longer for the query to finish, enable only if prompted to. \ No newline at end of file diff --git a/plugin.json b/plugin.json index 655207d..f0df61d 100644 --- a/plugin.json +++ b/plugin.json @@ -4,7 +4,7 @@ "IsGlobal": true, "Name": "Everything", "Author": "Yu Chieh (Victor) Lin", - "Version": "0.2.5", + "Version": "0.55.1.0", "Language": "csharp", "Website": "https://github.com/lin-ycv/EverythingPowerToys", "ExecuteFileName": "Community.PowerToys.Run.Plugin.Everything.dll",