Skip to content

Commit

Permalink
closes #10, closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
lin-ycv committed May 5, 2022
1 parent e6fab42 commit 015383b
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 38 deletions.
3 changes: 3 additions & 0 deletions Community.PowerToys.Run.Plugin.Everything.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Update="settings.toml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
Expand Down
21 changes: 2 additions & 19 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu,
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;

Expand All @@ -44,12 +43,6 @@ public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu,
DisplayLabel = Resources.Top,
Value = false,
},
/*new PluginAdditionalOption()
{
Key = Wait,
DisplayLabel = Resources.Wait,
Value = false,
},*/
new PluginAdditionalOption()
{
Key = NoPreview,
Expand All @@ -71,8 +64,6 @@ internal static string WarningIcon
}
}

/*private static CancellationTokenSource source;*/

public void Init(PluginInitContext context)
{
_context = context;
Expand All @@ -90,7 +81,7 @@ public List<Result> Query(Query query)

[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))
Expand All @@ -101,13 +92,9 @@ public List<Result> Query(Query query, bool isFullQuery)

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)
{
Expand All @@ -132,7 +119,6 @@ public List<Result> Query(Query query, bool isFullQuery)
}
catch (Exception e)
{
/*source.Cancel();*/
Log.Exception("Everything Exception", e, GetType());
}
}
Expand Down Expand Up @@ -170,18 +156,15 @@ public Control CreateSettingPanel()

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

Expand Down
50 changes: 34 additions & 16 deletions NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,49 @@ internal enum Sort
[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");
Expand All @@ -114,7 +144,6 @@ public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool pr

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();
Expand Down Expand Up @@ -162,17 +191,6 @@ public static IEnumerable<Result> EverythingSearch(string qry, bool top, bool pr
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();
Expand Down
2 changes: 1 addition & 1 deletion Properties/Resources.Designer.cs

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

2 changes: 1 addition & 1 deletion Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
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.56.2.2",
"Version": "0.58.0",
"Language": "csharp",
"Website": "https://github.com/lin-ycv/EverythingPowerToys",
"ExecuteFileName": "Community.PowerToys.Run.Plugin.Everything.dll",
Expand Down
13 changes: 13 additions & 0 deletions settings.toml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 015383b

Please sign in to comment.