diff --git a/Community.PowerToys.Run.Plugin.Everything.csproj b/Community.PowerToys.Run.Plugin.Everything.csproj index f4f326e..44e7b9e 100644 --- a/Community.PowerToys.Run.Plugin.Everything.csproj +++ b/Community.PowerToys.Run.Plugin.Everything.csproj @@ -1,5 +1,5 @@  - + net6.0-windows @@ -23,7 +23,7 @@ true - ..\..\..\..\..\..\x64\Debug\modules\launcher\Plugins\Everything\ + ..\..\..\..\..\x64\Debug\modules\launcher\Plugins\Everything\ DEBUG;TRACE full x64 @@ -36,7 +36,7 @@ - ..\..\..\..\..\..\x64\Release\modules\launcher\Plugins\Everything\ + ..\..\..\..\..\x64\Release\modules\launcher\Plugins\Everything\ TRACE true none @@ -68,7 +68,7 @@ - + diff --git a/ContextMenuLoader.cs b/ContextMenuLoader.cs index cbb86b3..3ef5f95 100644 --- a/ContextMenuLoader.cs +++ b/ContextMenuLoader.cs @@ -39,7 +39,7 @@ namespace Community.PowerToys.Run.Plugin.Everything if (isFile) { - contextMenus.Add(CreateOpenContainingFolderResult(record)); + contextMenus.Add(this.CreateOpenContainingFolderResult(record)); } // Test to check if File can be Run as admin, if yes, we add a 'run as admin' context menu item @@ -155,7 +155,7 @@ namespace Community.PowerToys.Run.Plugin.Everything } [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive, and instead log and show an error message")] - private static ContextMenuResult CreateOpenContainingFolderResult(SearchResult record) + private ContextMenuResult CreateOpenContainingFolderResult(SearchResult record) { return new ContextMenuResult { @@ -167,34 +167,14 @@ namespace Community.PowerToys.Run.Plugin.Everything AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift, Action = _ => { - try - { - var openDir = new ProcessStartInfo - { - FileName = $"{Path.GetDirectoryName(record.Path)}", - UseShellExecute = true, - }; - Process.Start(openDir); - return true; - } - catch (Exception e) + if (!Helper.OpenInShell("explorer.exe", $"/select,\"{record.Path}\"")) { var message = $"{Properties.Resources.folder_open_failed} {Path.GetDirectoryName(record.Path)}"; - MessageBox.Show(message + "\n" + e.Message); + this.context.API.ShowMsg(message); return false; } - // Throws exception: Reason Unknown - // System.MissingMethodException: Method not found: 'Boolean Wox.Infrastructure.Helper.OpenInShell(System.String, System.String, System.String, Boolean, Boolean)'. - - // if (!Helper.OpenInShell("explorer.exe", $"/select,\"{Path.GetDirectoryName(record.Path)}\"")) - // { - // var message = $"{Properties.Resources.folder_open_failed} {Path.GetDirectoryName(record.Path)}"; - // _context.API.ShowMsg(message); - // return false; - // } - - // return true; + return true; }, }; } diff --git a/GlobalSuppressions.cs b/GlobalSuppressions.cs index e0f865e..17b3abf 100644 --- a/GlobalSuppressions.cs +++ b/GlobalSuppressions.cs @@ -15,3 +15,4 @@ using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1516:Elements should be separated by blank line", Justification = "don't care")] [assembly: SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1503:Braces should not be omitted", Justification = "don't care")] [assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1005:Single line comments should begin with single space", Justification = "don't care")] +[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)")] diff --git a/Main.cs b/Main.cs index 871cd98..3cd6d00 100644 --- a/Main.cs +++ b/Main.cs @@ -24,13 +24,13 @@ namespace Community.PowerToys.Run.Plugin.Everything { public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu, ISettingProvider, IPluginI18n { - private const string Legacy = nameof(Legacy); + private const string AltIcon = nameof(AltIcon); private const string Top = nameof(Top); private const string NoPreview = nameof(NoPreview); private readonly string reservedStringPattern = @"^[\/\\\$\%]+$|^.*[<>].*$"; private bool top; private bool preview; - private bool legacy; + private bool altIcon; public string Name => Resources.plugin_name; @@ -40,8 +40,8 @@ namespace Community.PowerToys.Run.Plugin.Everything { new PluginAdditionalOption() { - Key = Top, - DisplayLabel = Resources.Top, + Key = AltIcon, + DisplayLabel = Resources.AltIcon, Value = false, }, new PluginAdditionalOption() @@ -52,8 +52,8 @@ namespace Community.PowerToys.Run.Plugin.Everything }, new PluginAdditionalOption() { - Key = Legacy, - DisplayLabel = "Legacy Icon Logic", + Key = Top, + DisplayLabel = Resources.Top, Value = false, }, }; @@ -88,7 +88,7 @@ namespace Community.PowerToys.Run.Plugin.Everything { try { - results.AddRange(EverythingSearch(searchQuery, this.top, this.preview, this.legacy)); + results.AddRange(EverythingSearch(searchQuery, this.top, this.preview, this.altIcon)); } catch (System.ComponentModel.Win32Exception) { @@ -125,17 +125,17 @@ namespace Community.PowerToys.Run.Plugin.Everything { var top = false; var nopreview = false; - var leg = false; + var alt = false; if (settings != null && settings.AdditionalOptions != null) { top = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Top)?.Value ?? false; nopreview = settings.AdditionalOptions.FirstOrDefault(x => x.Key == NoPreview)?.Value ?? false; - leg = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Legacy)?.Value ?? false; + alt = settings.AdditionalOptions.FirstOrDefault(x => x.Key == AltIcon)?.Value ?? false; } this.top = top; this.preview = nopreview; - this.legacy = leg; + this.altIcon = alt; } protected virtual void Dispose(bool disposing) diff --git a/NativeMethods.cs b/NativeMethods.cs index c175fc0..88e2da7 100644 --- a/NativeMethods.cs +++ b/NativeMethods.cs @@ -6,6 +6,7 @@ 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; @@ -124,7 +125,7 @@ namespace Community.PowerToys.Run.Plugin.Everything [DllImport(dllName)] internal static extern uint Everything_GetNumResults(); [DllImport(dllName, CharSet = CharSet.Unicode)] - internal static extern void Everything_GetResultFullPathName(uint nIndex, char[] lpString, uint nMaxCount); + internal static extern void Everything_GetResultFullPathName(uint nIndex, StringBuilder lpString, uint nMaxCount); [DllImport(dllName)] internal static extern bool Everything_QueryW(bool bWait); [DllImport(dllName)] @@ -177,11 +178,18 @@ namespace Community.PowerToys.Run.Plugin.Everything 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)); +#endif } public static IEnumerable EverythingSearch(string qry, bool top, bool preview, bool legacy) { - if (legacy && firstrun) +#if DEBUG + string orgqry = qry; +#endif + if (!preview && legacy && firstrun) Icons = GetFileTypeAndIcon(); Everything_SetMax(max); if (qry.Contains(':')) @@ -203,9 +211,9 @@ namespace Community.PowerToys.Run.Plugin.Everything uint resultCount = Everything_GetNumResults(); for (uint i = 0; i < resultCount; i++) { - char[] buffer = new char[260]; + StringBuilder buffer = new StringBuilder(260); Everything_GetResultFullPathName(i, buffer, 260); - string fullPath = new string(buffer); + string fullPath = buffer.ToString(); string name = Path.GetFileName(fullPath); string path; bool isFolder = !Path.HasExtension(fullPath.Replace(".lnk", string.Empty)); @@ -218,7 +226,12 @@ namespace Community.PowerToys.Run.Plugin.Everything var r = new Result() { Title = name, - ToolTipData = new ToolTipData("Name : " + name, "Path : " + path), + ToolTipData = +#if DEBUG + new ToolTipData(orgqry, qry), +#else + new ToolTipData("Name : " + name, fullPath), +#endif SubTitle = Resources.plugin_name + ": " + fullPath, IcoPath = isFolder ? "Images/folder.png" : (preview ? fullPath : @@ -249,7 +262,7 @@ namespace Community.PowerToys.Run.Plugin.Everything } }, - // QueryTextDisplay = isFolder ? path : name, + QueryTextDisplay = isFolder ? path : name, }; if (top) r.Score = (int)(max - i); yield return r; @@ -330,7 +343,8 @@ namespace Community.PowerToys.Run.Plugin.Everything if (path.Length > 0 && path[0].Contains('.')) { string fileParam = Environment.ExpandEnvironmentVariables(path[0].Replace("\"", string.Empty, StringComparison.CurrentCulture).Trim()); - iconsInfo.Add(keyName, fileParam); + if (!fileParam.EndsWith("dll", StringComparison.CurrentCulture)) + iconsInfo.Add(keyName, fileParam); } } catch (Exception e) diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index ed78f68..772131e 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -60,6 +60,15 @@ namespace Community.PowerToys.Run.Plugin.Everything.Properties { } } + /// + /// Looks up a localized string similar to Alternative - if the icon for your files aren't displaying correctly, try this alternative method of getting icons.. + /// + public static string AltIcon { + get { + return ResourceManager.GetString("AltIcon", resourceCulture); + } + } + /// /// Looks up a localized string similar to Fail to set text in clipboard. /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index ba48cf4..80d41dd 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Alternative - if the icon for your files aren't displaying correctly, try this alternative method of getting icons. + Fail to set text in clipboard diff --git a/plugin.json b/plugin.json index 19852d0..bc2eb06 100644 --- a/plugin.json +++ b/plugin.json @@ -4,7 +4,7 @@ "IsGlobal": true, "Name": "Everything", "Author": "Yu Chieh (Victor) Lin", - "Version": "0.58.0.3", + "Version": "0.59.1", "Language": "csharp", "Website": "https://github.com/lin-ycv/EverythingPowerToys", "ExecuteFileName": "Community.PowerToys.Run.Plugin.Everything.dll",