closes #10, closes #12

This commit is contained in:
Lin Yu-Chieh (Victor) 2022-05-06 01:53:32 +08:00
parent e6fab422f0
commit 015383b771
7 changed files with 55 additions and 38 deletions

View File

@ -122,6 +122,9 @@
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Update="settings.toml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">

21
Main.cs
View File

@ -28,7 +28,6 @@ namespace Community.PowerToys.Run.Plugin.Everything
private const string Top = nameof(Top);
private const string NoPreview = nameof(NoPreview);
private readonly string reservedStringPattern = @"^[\/\\\$\%]+$|^.*[<>].*$";
/*private bool _wait;*/
private bool _top;
private bool _preview;
@ -44,12 +43,6 @@ namespace Community.PowerToys.Run.Plugin.Everything
DisplayLabel = Resources.Top,
Value = false,
},
/*new PluginAdditionalOption()
{
Key = Wait,
DisplayLabel = Resources.Wait,
Value = false,
},*/
new PluginAdditionalOption()
{
Key = NoPreview,
@ -71,8 +64,6 @@ namespace Community.PowerToys.Run.Plugin.Everything
}
}
/*private static CancellationTokenSource source;*/
public void Init(PluginInitContext context)
{
_context = context;
@ -90,7 +81,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 but will log the exception")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "Already validated")]
public List<Result> Query(Query query, bool isFullQuery)
public List<Result> Query(Query query, bool delayedExecution)
{
List<Result> results = new List<Result>();
if (!string.IsNullOrEmpty(query.Search))
@ -101,13 +92,9 @@ namespace Community.PowerToys.Run.Plugin.Everything
if (!regexMatch.Success)
{
/*source?.Cancel();
source = new CancellationTokenSource();
CancellationToken token = source.Token;
source.CancelAfter(_wait ? 2500 : 150);*/
try
{
results.AddRange(EverythingSearch(searchQuery, _top, _preview/*, token, _wait*/));
results.AddRange(EverythingSearch(searchQuery, _top, _preview));
}
catch (OperationCanceledException)
{
@ -132,7 +119,6 @@ namespace Community.PowerToys.Run.Plugin.Everything
}
catch (Exception e)
{
/*source.Cancel();*/
Log.Exception("Everything Exception", e, GetType());
}
}
@ -170,18 +156,15 @@ namespace Community.PowerToys.Run.Plugin.Everything
public void UpdateSettings(PowerLauncherPluginSettings settings)
{
/*var wait = false;*/
var top = false;
var nopreview = false;
if (settings != null && settings.AdditionalOptions != null)
{
/*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;
}
_top = top;
/*_wait = wait;*/
_preview = nopreview;
}

View File

@ -92,19 +92,49 @@ namespace Community.PowerToys.Run.Plugin.Everything
[DllImport(dllName)]
public static extern void Everything_SetSort(Sort SortType);
private const int max = 20;
private static uint max = 20;
private static Sort sort = Sort.DATE_MODIFIED_DESCENDING;
#pragma warning disable SA1503 // Braces should not be omitted
public static void EverythingSetup()
{
Everything_SetRequestFlags(Request.FULL_PATH_AND_FILE_NAME);
Everything_SetSort(Sort.DATE_MODIFIED_DESCENDING);
GetCustomSettings();
Everything_SetSort(sort);
Everything_SetMax(max);
}
public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool preview/*, CancellationToken token, bool wait*/)
[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;
try { strArr = File.ReadAllLines("modules\\launcher\\Plugins\\Everything\\settings.toml"); }
catch { return; }
var culture = new System.Globalization.CultureInfo("en-US");
foreach (string str in strArr)
{
if (str.Length == 0 || str[0] == '#') continue;
string[] kv = str.Split('=');
if (kv.Length != 2) continue;
switch (kv[0].Trim())
{
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;
}
}
}
public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool preview)
{
_ = Everything_SetSearchW(qry);
/*if (token.IsCancellationRequested) token.ThrowIfCancellationRequested();*/
if (!Everything_QueryW(true))
{
throw new Win32Exception("Unable to Query");
@ -114,7 +144,6 @@ namespace Community.PowerToys.Run.Plugin.Everything
for (uint i = 0; i < resultCount; i++)
{
/*if (token.IsCancellationRequested) break;*/
StringBuilder sb = new StringBuilder(260);
Everything_GetResultFullPathName(i, sb, 260);
string fullPath = sb.ToString();
@ -162,17 +191,6 @@ namespace Community.PowerToys.Run.Plugin.Everything
if (top) r.Score = (int)(max - i);
yield return r;
}
/*if (token.IsCancellationRequested && !wait)
{
yield return new Result()
{
Title = Resources.timeout,
SubTitle = Resources.enable_wait,
IcoPath = Main.WarningIcon,
Score = int.MaxValue,
};
}*/
}
internal static readonly Hashtable Icons = GetFileTypeAndIcon();

View File

@ -178,7 +178,7 @@ namespace Community.PowerToys.Run.Plugin.Everything.Properties {
}
/// <summary>
/// Looks up a localized string similar to Top - Insert result at the top of the list, may cause pre-selectino issue..
/// Looks up a localized string similar to Top - Insert result at the top of the list, may cause pre-selection issue..
/// </summary>
public static string Top {
get {

View File

@ -162,4 +162,4 @@
<data name="Wait" xml:space="preserve">
<value>Wait - Wait longer for the query to finish, enable only if prompted to.</value>
</data>
</root>
</root>

View File

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

13
settings.toml Normal file
View File

@ -0,0 +1,13 @@
# This is the settings file to override the behaviour for "Everything for PowerToys"
# to override a setting, uncomment that line by uncommenting and changing the value
# ie: "# max = 20" -> "max = 10"
# Set max amount of results to return [default: 20]
# max = 20
# Set result sorting method [default: 14]
# https://www.voidtools.com/support/everything/sdk/everything_getsort/
# sort = 14
# There are no more override options
# Restart of powertoys is needed if values are changed