Skip to content

Commit

Permalink
Fixes #19
Browse files Browse the repository at this point in the history
Also fixed preview option not working
  • Loading branch information
lin-ycv committed Jul 4, 2022
1 parent 69b1031 commit 4c727ee
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 47 deletions.
8 changes: 4 additions & 4 deletions Community.PowerToys.Run.Plugin.Everything.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\..\Version.props" />
<Import Project="..\..\..\..\Version.props" />

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -68,7 +68,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Wox.Infrastructure\Wox.Infrastructure.csproj" />
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
30 changes: 5 additions & 25 deletions ContextMenuLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public List<ContextMenuResult> LoadContextMenus(Result selectedResult)

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
Expand Down Expand Up @@ -155,7 +155,7 @@ private bool CanFileBeRunAsAdmin(string path)
}

[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
{
Expand All @@ -167,34 +167,14 @@ private static ContextMenuResult CreateOpenContainingFolderResult(SearchResult r
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;
},
};
}
Expand Down
1 change: 1 addition & 0 deletions GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
[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 changes: 10 additions & 10 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,8 +40,8 @@ public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu,
{
new PluginAdditionalOption()
{
Key = Top,
DisplayLabel = Resources.Top,
Key = AltIcon,
DisplayLabel = Resources.AltIcon,
Value = false,
},
new PluginAdditionalOption()
Expand All @@ -52,8 +52,8 @@ public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu,
},
new PluginAdditionalOption()
{
Key = Legacy,
DisplayLabel = "Legacy Icon Logic",
Key = Top,
DisplayLabel = Resources.Top,
Value = false,
},
};
Expand Down Expand Up @@ -88,7 +88,7 @@ public List<Result> Query(Query query, bool delayedExecution)
{
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)
{
Expand Down Expand Up @@ -125,17 +125,17 @@ public void UpdateSettings(PowerLauncherPluginSettings settings)
{
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)
Expand Down
28 changes: 21 additions & 7 deletions NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -124,7 +125,7 @@ internal enum AssocStr
[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)]
Expand Down Expand Up @@ -177,11 +178,18 @@ private static void GetCustomSettings()
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(':'))
Expand All @@ -203,9 +211,9 @@ public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool pr
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));
Expand All @@ -218,7 +226,12 @@ public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool pr
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 :
Expand Down Expand Up @@ -249,7 +262,7 @@ public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool pr
}
},

// QueryTextDisplay = isFolder ? path : name,
QueryTextDisplay = isFolder ? path : name,
};
if (top) r.Score = (int)(max - i);
yield return r;
Expand Down Expand Up @@ -330,7 +343,8 @@ void FindExt(RegistryKey rkRoot)
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)
Expand Down
9 changes: 9 additions & 0 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4c727ee

Please sign in to comment.