Added filter macros, adjustments for StyleCop..etc

Resolves #14
This commit is contained in:
Lin Yu-Chieh (Victor) 2022-05-18 15:19:39 +08:00
parent 6e8dc04fbf
commit 5e9b035c76
8 changed files with 196 additions and 76 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>
@ -17,6 +17,8 @@
<PackageProjectUrl>https://github.com/lin-ycv/EverythingPowerToys</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>Everything.light.png</PackageIcon>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<NoWarn>$(NoWarn),1573,1591,1712</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -46,23 +48,6 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
<AdditionalFiles Include="..\..\..\..\codeAnalysis\StyleCop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
<Private>false</Private>
<CopyLocal>False</CopyLocal>
<CopyLocalSatelliteAssemblies>False</CopyLocalSatelliteAssemblies>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@ -82,6 +67,10 @@
<PackageReference Include="System.Runtime" Version="4.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Wox.Infrastructure\Wox.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
@ -131,7 +120,7 @@
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="del /Q &quot;$(TargetDir)*.pdb&quot;&#xD;&#xA;del /Q &quot;$(TargetDir)PowerToys*.dll&quot;&#xD;&#xA;del /Q &quot;$(TargetDir)Wox*.dll&quot;&#xD;&#xA;del /Q &quot;$(TargetDir)Ijwhost.dll&quot;" />
<Exec Command="del /Q &quot;$(TargetDir)*.pdb&quot;&#xD;&#xA;del /Q &quot;$(TargetDir)PowerToys*.dll&quot;&#xD;&#xA;del /Q &quot;$(TargetDir)Wox*.dll&quot;&#xD;&#xA;del /Q &quot;$(TargetDir)Ijwhost.dll&quot;&#xD;&#xA;del /Q &quot;$(TargetDir)*.xml&quot;" />
</Target>
</Project>

View File

@ -0,0 +1,99 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>Community.PowerToys.Run.Plugin.Everything</name>
</assembly>
<members>
<member name="T:Community.PowerToys.Run.Plugin.Everything.Properties.Resources">
<summary>
A strongly-typed resource class, for looking up localized strings, etc.
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.ResourceManager">
<summary>
Returns the cached ResourceManager instance used by this class.
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.Culture">
<summary>
Overrides the current thread's CurrentUICulture property for all
resource lookups using this strongly typed resource class.
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.clipboard_failed">
<summary>
Looks up a localized string similar to Fail to set text in clipboard.
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.copy_path">
<summary>
Looks up a localized string similar to Copy path (Ctrl+C).
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.enable_wait">
<summary>
Looks up a localized string similar to Enable Wait setting under PowerToys Run &gt; Everything.
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.Everything_ini">
<summary>
Looks up a localized string similar to Install Everything if not installed.
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.Everything_not_running">
<summary>
Looks up a localized string similar to Everything is not running.
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.folder_open_failed">
<summary>
Looks up a localized string similar to Fail to open folder at.
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.open_containing_folder">
<summary>
Looks up a localized string similar to Open containing folder (Ctrl+Shift+E).
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.open_in_console">
<summary>
Looks up a localized string similar to Open path in console (Ctrl+Shift+C).
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.plugin_description">
<summary>
Looks up a localized string similar to Get search results from Everything.
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.plugin_name">
<summary>
Looks up a localized string similar to Everything.
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.Preview">
<summary>
Looks up a localized string similar to Preview - Preview file content as icon, may cause freezing if file is not local..
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.run_as_admin">
<summary>
Looks up a localized string similar to Run as administrator (Ctrl+Shift+Enter).
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.timeout">
<summary>
Looks up a localized string similar to Timed out before finishing the query.
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.Top">
<summary>
Looks up a localized string similar to Top - Insert result at the top of the list, may cause pre-selection issue..
</summary>
</member>
<member name="P:Community.PowerToys.Run.Plugin.Everything.Properties.Resources.Wait">
<summary>
Looks up a localized string similar to Wait - Wait longer for the query to finish, enable only if prompted to..
</summary>
</member>
</members>
</doc>

View File

@ -19,14 +19,14 @@ namespace Community.PowerToys.Run.Plugin.Everything
{
internal class ContextMenuLoader : IContextMenu
{
private readonly PluginInitContext _context;
private readonly PluginInitContext context;
// Extensions for adding run as admin context menu item for applications
private readonly string[] appExtensions = { ".exe", ".bat", ".appref-ms", ".lnk" };
public ContextMenuLoader(PluginInitContext context)
{
_context = context;
this.context = context;
}
[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")]
@ -43,7 +43,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
}
// Test to check if File can be Run as admin, if yes, we add a 'run as admin' context menu item
if (CanFileBeRunAsAdmin(record.Path))
if (this.CanFileBeRunAsAdmin(record.Path))
{
contextMenus.Add(CreateRunAsAdminContextMenu(record));
}
@ -67,9 +67,9 @@ namespace Community.PowerToys.Run.Plugin.Everything
catch (Exception e)
{
var message = Properties.Resources.clipboard_failed;
Log.Exception(message, e, GetType());
Log.Exception(message, e, this.GetType());
_context.API.ShowMsg(message);
this.context.API.ShowMsg(message);
return false;
}
},
@ -100,7 +100,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
}
catch (Exception e)
{
Log.Exception($"Failed to open {record.Path} in console, {e.Message}", e, GetType());
Log.Exception($"Failed to open {record.Path} in console, {e.Message}", e, this.GetType());
return false;
}
},
@ -142,7 +142,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
private bool CanFileBeRunAsAdmin(string path)
{
string fileExtension = Path.GetExtension(path);
foreach (string extension in appExtensions)
foreach (string extension in this.appExtensions)
{
// Using OrdinalIgnoreCase since this is internal
if (extension.Equals(fileExtension, StringComparison.OrdinalIgnoreCase))
@ -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 ContextMenuResult CreateOpenContainingFolderResult(SearchResult record)
private static ContextMenuResult CreateOpenContainingFolderResult(SearchResult record)
{
return new ContextMenuResult
{

14
GlobalSuppressions.cs Normal file
View File

@ -0,0 +1,14 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:Using directives should be placed correctly", Justification = "don't care")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:Elements should be ordered by access", Justification = "dont care")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1204:Static elements should appear before instance elements", Justification = "don't care")]
[assembly: SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501:Statement should not be on a single line", Justification = "don't care")]
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "don't care")]
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1602:Enumeration items should be documented", Justification = "don't care")]
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "don't care")]

46
Main.cs
View File

@ -28,8 +28,8 @@ namespace Community.PowerToys.Run.Plugin.Everything
private const string Top = nameof(Top);
private const string NoPreview = nameof(NoPreview);
private readonly string reservedStringPattern = @"^[\/\\\$\%]+$|^.*[<>].*$";
private bool _top;
private bool _preview;
private bool top;
private bool preview;
public string Name => Resources.plugin_name;
@ -51,25 +51,25 @@ namespace Community.PowerToys.Run.Plugin.Everything
},
};
private IContextMenu _contextMenuLoader;
private PluginInitContext _context;
private IContextMenu contextMenuLoader;
private PluginInitContext context;
private bool disposed;
private static string _warningIconPath;
private static string warningIconPath;
internal static string WarningIcon
{
get
{
return _warningIconPath;
return warningIconPath;
}
}
public void Init(PluginInitContext context)
{
_context = context;
_contextMenuLoader = new ContextMenuLoader(context);
_context.API.ThemeChanged += OnThemeChanged;
UpdateIconPath(_context.API.GetCurrentTheme());
this.context = context;
this.contextMenuLoader = new ContextMenuLoader(context);
this.context.API.ThemeChanged += this.OnThemeChanged;
UpdateIconPath(this.context.API.GetCurrentTheme());
EverythingSetup();
}
@ -88,13 +88,13 @@ namespace Community.PowerToys.Run.Plugin.Everything
{
var searchQuery = query.Search;
var regexMatch = Regex.Match(searchQuery, reservedStringPattern);
var regexMatch = Regex.Match(searchQuery, this.reservedStringPattern);
if (!regexMatch.Success)
{
try
{
results.AddRange(EverythingSearch(searchQuery, _top, _preview));
results.AddRange(EverythingSearch(searchQuery, this.top, this.preview));
}
catch (OperationCanceledException)
{
@ -102,7 +102,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
{
Title = Resources.timeout,
SubTitle = Resources.enable_wait,
IcoPath = _warningIconPath,
IcoPath = warningIconPath,
Score = int.MaxValue,
});
}
@ -112,14 +112,14 @@ namespace Community.PowerToys.Run.Plugin.Everything
{
Title = Resources.Everything_not_running,
SubTitle = Resources.Everything_ini,
IcoPath = _warningIconPath,
IcoPath = warningIconPath,
QueryTextDisplay = '.' + Resources.plugin_name,
Score = int.MaxValue,
});
}
catch (Exception e)
{
Log.Exception("Everything Exception", e, GetType());
Log.Exception("Everything Exception", e, this.GetType());
}
}
}
@ -136,17 +136,17 @@ namespace Community.PowerToys.Run.Plugin.Everything
{
if (theme == Theme.Light || theme == Theme.HighContrastWhite)
{
_warningIconPath = "Images/Warning.light.png";
warningIconPath = "Images/Warning.light.png";
}
else
{
_warningIconPath = "Images/Warning.dark.png";
warningIconPath = "Images/Warning.dark.png";
}
}
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
{
return _contextMenuLoader.LoadContextMenus(selectedResult);
return this.contextMenuLoader.LoadContextMenus(selectedResult);
}
public Control CreateSettingPanel()
@ -164,26 +164,26 @@ namespace Community.PowerToys.Run.Plugin.Everything
nopreview = settings.AdditionalOptions.FirstOrDefault(x => x.Key == NoPreview)?.Value ?? false;
}
_top = top;
_preview = nopreview;
this.top = top;
this.preview = nopreview;
}
protected virtual void Dispose(bool disposing)
{
if (!disposed)
if (!this.disposed)
{
if (disposing)
{
}
disposed = true;
this.disposed = true;
}
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
this.Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}

View File

@ -1,8 +1,4 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
@ -80,7 +76,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
[DllImport(dllName)]
public static extern uint Everything_GetNumResults();
[DllImport(dllName, CharSet = CharSet.Unicode)]
public static extern void Everything_GetResultFullPathName(uint nIndex, StringBuilder lpString, uint nMaxCount);
public static extern void Everything_GetResultFullPathName(uint nIndex, char[] lpString, uint nMaxCount);
[DllImport(dllName)]
public static extern bool Everything_QueryW(bool bWait);
[DllImport(dllName)]
@ -94,6 +90,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
private static uint max = 20;
private static Sort sort = Sort.DATE_MODIFIED_DESCENDING;
private static Dictionary<string, string> filters = new Dictionary<string, string>();
#pragma warning disable SA1503 // Braces should not be omitted
#if DEBUG
private static StringBuilder log = new StringBuilder();
@ -108,11 +105,8 @@ namespace Community.PowerToys.Run.Plugin.Everything
Everything_SetRequestFlags(Request.FULL_PATH_AND_FILE_NAME);
GetCustomSettings();
Everything_SetSort(sort);
Everything_SetMax(max);
}
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1503:Braces should not be omitted", Justification = "stop wasting lines")]
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501:Statement should not be on a single line", Justification = "stop wasting lines")]
private static void GetCustomSettings()
{
string[] strArr;
@ -124,24 +118,37 @@ namespace Community.PowerToys.Run.Plugin.Everything
if (str.Length == 0 || str[0] == '#') continue;
string[] kv = str.Split('=');
if (kv.Length != 2) continue;
switch (kv[0].Trim())
string key = kv[0].Trim();
if (key == "max")
{
case "max":
try { max = uint.Parse(kv[1].Trim(), culture.NumberFormat); }
catch { }
break;
case "sort":
try { sort = (Sort)int.Parse(kv[1].Trim(), culture.NumberFormat); }
catch { }
break;
default:
continue;
try { max = uint.Parse(kv[1].Trim(), culture.NumberFormat); }
catch { }
}
else if (key == "sort")
{
try { sort = (Sort)int.Parse(kv[1].Trim(), culture.NumberFormat); }
catch { }
}
else if (key.Contains(':'))
{
filters.TryAdd(key.Split(':')[0].ToLowerInvariant(), kv[1].Trim());
}
}
}
public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool preview)
{
Everything_SetMax(max);
if (qry.Contains(':'))
{
string[] nqry = qry.Split(':');
if (filters.ContainsKey(nqry[0].ToLowerInvariant()))
{
Everything_SetMax(0xffffffff);
qry = nqry[1].Trim() + " ext:" + filters[nqry[0].Trim()];
}
}
_ = Everything_SetSearchW(qry);
if (!Everything_QueryW(true))
{
@ -151,9 +158,9 @@ namespace Community.PowerToys.Run.Plugin.Everything
uint resultCount = Everything_GetNumResults();
for (uint i = 0; i < resultCount; i++)
{
StringBuilder sb = new StringBuilder(260);
Everything_GetResultFullPathName(i, sb, 260);
string fullPath = sb.ToString();
char[] buffer = new char[260];
Everything_GetResultFullPathName(i, buffer, 260);
string fullPath = new string(buffer);
string name = Path.GetFileName(fullPath);
string path;
bool isFolder = Path.HasExtension(fullPath.Replace(".lnk", string.Empty));
@ -253,8 +260,9 @@ namespace Community.PowerToys.Run.Plugin.Everything
catch (Exception)
{
#endif
// If exceptions occurs for a key despite condition checks, just move onto the next key, plugin will still work, just without that icon info
continue;
// If exceptions occurs for a key despite condition checks, just move onto the next key, plugin will still work, just without that icon info
continue;
}
}
}
@ -268,6 +276,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
catch (Exception)
{
#endif
// User privillege probably too low to access Registry Keys, plugin will still work, just without icon info
}

View File

@ -4,7 +4,7 @@
"IsGlobal": true,
"Name": "Everything",
"Author": "Yu Chieh (Victor) Lin",
"Version": "0.58.0.1",
"Version": "0.58.0.2",
"Language": "csharp",
"Website": "https://github.com/lin-ycv/EverythingPowerToys",
"ExecuteFileName": "Community.PowerToys.Run.Plugin.Everything.dll",

View File

@ -9,5 +9,14 @@
# https://www.voidtools.com/support/everything/sdk/everything_getsort/
# sort = 14
# Search filters, filters result with extension type
Audio: = aac;ac3;aif;aifc;aiff;amr;ape;au;cda;dts;fla;flac;it;m1a;m2a;m3u;m4a;m4b;m4p;mid;midi;mka;mod;mp2;mp3;mpa;ogg;opus;ra;rmi;spc;rmi;snd;umx;voc;wav;weba;wma;xm
Compressed: = 7z;ace;arj;bz2;cab;gz;gzip;jar;r00;r01;r02;r03;r04;r05;r06;r07;r08;r09;r10;r11;r12;r13;r14;r15;r16;r17;r18;r19;r20;r21;r22;r23;r24;r25;r26;r27;r28;r29;rar;tar;tgz;z;zip
Document: = c;cc;chm;cpp;cs;css;csv;cxx;doc;docm;docx;dot;dotm;dotx;epub;h;hpp;htm;html;hxx;ini;java;js;json;lua;mht;mhtml;mobi;odp;ods;odt;pdf;php;potx;potm;ppam;ppsm;ppsx;pps;ppt;pptm;pptx;pub;py;rtf;sldm;sldx;thmx;txt;vsd;wpd;wps;wri;xlam;xls;xlsb;xlsm;xlsx;xltm;xltx;xml;vb
Executable: = bat;cmd;exe;msi;msp;msu;ps1;scr
Folder: =
Picture: = ani;apng;bmp;bpg;cur;gif;ico;jfi;jfif;jif;jpe;jpeg;jpg;pcx;png;psb;psd;rle;svg;tga;tif;tiff;webp;wmf
Video: = 3g2;3gp;3gp2;3gpp;amv;asf;asx;avi;bdmv;bik;d2v;divx;drc;dsa;dsm;dss;dsv;evo;f4v;flc;fli;flic;flv;hdmov;ifo;ivf;m1v;m2p;m2t;m2ts;m2v;m4v;mkv;mp2v;mp4;mp4v;mpe;mpeg;mpg;mpls;mpv2;mpv4;mov;mts;ogm;ogv;pss;pva;qt;ram;ratdvd;rm;rmm;rmvb;roq;rpm;smil;smk;swf;tp;tpr;ts;vob;vp6;webm;wm;wmp;wmv
# There are no more override options
# Restart of powertoys is needed if values are changed