Also fixed preview option not working
This commit is contained in:
Lin Yu-Chieh (Victor) 2022-07-04 14:24:13 +08:00
parent 69b10312bf
commit 4c727ee656
No known key found for this signature in database
GPG Key ID: 3AEF72AE8F846207
8 changed files with 54 additions and 47 deletions

View File

@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\..\Version.props" />
<Import Project="..\..\..\..\Version.props" />
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
@ -23,7 +23,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\..\..\..\..\x64\Debug\modules\launcher\Plugins\Everything\</OutputPath>
<OutputPath>..\..\..\..\..\x64\Debug\modules\launcher\Plugins\Everything\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
@ -36,7 +36,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutputPath>..\..\..\..\..\..\x64\Release\modules\launcher\Plugins\Everything\</OutputPath>
<OutputPath>..\..\..\..\..\x64\Release\modules\launcher\Plugins\Everything\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>none</DebugType>
@ -68,7 +68,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Wox.Infrastructure\Wox.Infrastructure.csproj" />
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -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;
},
};
}

View File

@ -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)")]

20
Main.cs
View File

@ -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)

View File

@ -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<Result> 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)

View File

@ -60,6 +60,15 @@ namespace Community.PowerToys.Run.Plugin.Everything.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Alternative - if the icon for your files aren&apos;t displaying correctly, try this alternative method of getting icons..
/// </summary>
public static string AltIcon {
get {
return ResourceManager.GetString("AltIcon", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Fail to set text in clipboard.
/// </summary>

View File

@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AltIcon" xml:space="preserve">
<value>Alternative - if the icon for your files aren't displaying correctly, try this alternative method of getting icons.</value>
</data>
<data name="clipboard_failed" xml:space="preserve">
<value>Fail to set text in clipboard</value>
</data>

View File

@ -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",