Skip to content

Commit

Permalink
fix #108
Browse files Browse the repository at this point in the history
0.80.0+fixes+Debug Option
  • Loading branch information
lin-ycv committed May 25, 2024
1 parent 3d743f1 commit 6097e4b
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 28 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/packageManagers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:
jobs:
build:
if: "!github.event.release.prerelease"
permissions: write-all
runs-on: windows-latest

steps:
Expand Down Expand Up @@ -50,7 +49,7 @@ jobs:
cd .\EverythingPowerToys
rm .git -Recurse -Force -Confirm:$false
Get-ChildItem *.* -Recurse | ForEach { (Get-Content $_) | ForEach {$_ -Replace '_VERSION_', $ver} | ForEach {$_ -Replace '_URL_', $exe} | ForEach {$_ -Replace '_CRC_', $exehash} | Set-Content $_ }
..\wingetcreate submit -p "New version: lin-ycv.EverythingPowerToys version $ver" -t ${{ secrets.GITHUB_TOKEN }} .
..\wingetcreate submit -p "New version: lin-ycv.EverythingPowerToys version $ver" -t ${{ secrets.EVERYTHINGPT }} .
# scoop # takes too long to get approvaed, impractical to implement
# cd ..
Expand Down
14 changes: 14 additions & 0 deletions Debugger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.IO;
namespace Community.PowerToys.Run.Plugin.Everything
{
internal static class Debugger
{
private static readonly string FilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "EverythingPT.log");
public static void Write(string message)
{
using StreamWriter writer = new(FilePath, true);
writer.WriteLine(message);
}
}
}
40 changes: 35 additions & 5 deletions Everything.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ internal sealed class Everything
{
internal Everything(Settings setting)
{
Everything_SetRequestFlags(Request.FULL_PATH_AND_FILE_NAME);
UpdateSettings(setting);
Everything_SetRequestFlags(Request.FULL_PATH_AND_FILE_NAME);
UpdateSettings(setting);
}

internal void UpdateSettings(Settings setting)
Expand All @@ -27,15 +27,29 @@ internal void UpdateSettings(Settings setting)

internal IEnumerable<Result> Query(string query, Settings setting)
{
if (setting.Log > LogLevel.None)
{
Debugger.Write($"\r\n\r\nNew Query: {query}\r\n" +
$"Sort {(int)setting.Sort}_{Everything_GetSort()} | " +
$"Max {setting.Max}_{Everything_GetMax()} | " +
$"Match Path {setting.MatchPath}_{Everything_GetMatchPath()} | " +
$"Regex {setting.RegEx}_{Everything_GetRegex()}");
}

string orgqry = query;
if (orgqry.Contains('\"') && !setting.MatchPath)
{
if (setting.Log > LogLevel.None)
Debugger.Write("MatchPath");

Everything_SetMatchPath(true);
}

if (setting.EnvVar && orgqry.Contains('%'))
{
query = Environment.ExpandEnvironmentVariables(query).Replace(';', '|');
if (setting.Log > LogLevel.None)
Debugger.Write($"EnvVariable\r\n{query}");
}

if (orgqry.Contains(':'))
Expand All @@ -45,13 +59,18 @@ internal IEnumerable<Result> Query(string query, Settings setting)
if (query.Contains(kv.Key, StringComparison.OrdinalIgnoreCase))
{
query = query.Replace(kv.Key, kv.Value);
if (setting.Log > LogLevel.None)
Debugger.Write($"Contains Filter: {kv.Key}\r\n{query}");
}
}
}

Everything_SetSearchW(query);
if (!Everything_QueryW(true))
{
if (setting.Log > LogLevel.None)
Debugger.Write("\r\nUnable to Query\r\n");

throw new Win32Exception("Unable to Query");
}

Expand All @@ -61,16 +80,27 @@ internal IEnumerable<Result> Query(string query, Settings setting)
}

uint resultCount = Everything_GetNumResults();
if (setting.Log > LogLevel.None)
Debugger.Write($"Results: {resultCount}");

for (uint i = 0; i < resultCount; i++)
{
char[] buffer = new char[260];
uint length = Everything_GetResultFullPathName(i, buffer, (uint)buffer.Length);
if (setting.Log > LogLevel.None)
Debugger.Write($"\r\n===== RESULT #{i} =====");

char[] buffer = new char[32767];
uint length = Everything_GetResultFullPathNameW(i, buffer, (uint)buffer.Length);

string fullPath = new(buffer, 0, (int)length);
if (setting.Log > LogLevel.None)
Debugger.Write($"{length} {(setting.Log == LogLevel.Verbose ? fullPath : string.Empty)}");
string name = Path.GetFileName(fullPath);
bool isFolder = Everything_IsFolderResult(i);

string path = isFolder ? fullPath : Path.GetDirectoryName(fullPath);
string ext = Path.GetExtension(fullPath.Replace(".lnk", string.Empty));
if (setting.Log > LogLevel.None)
Debugger.Write($"Folder: {isFolder}\r\nFile Path {(setting.Log == LogLevel.Verbose ? path : path.Length)}\r\nFile Name {(setting.Log == LogLevel.Verbose ? name : name.Length)}\r\nExt: {ext}");

var r = new Result()
{
Expand All @@ -96,7 +126,7 @@ internal IEnumerable<Result> Query(string query, Settings setting)
try
{
process.Start();
_ = Everything_IncRunCountFromFileName(fullPath);
_ = Everything_IncRunCountFromFileNameW(fullPath);
return true;
}
catch (Win32Exception)
Expand Down
16 changes: 13 additions & 3 deletions Interop/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,20 @@ internal enum AssocStr
internal const string dllName = "Everything64.dll";
[LibraryImport(dllName)]
internal static partial uint Everything_GetNumResults();
[LibraryImport(dllName, EntryPoint = "Everything_GetResultFullPathNameW", StringMarshalling = StringMarshalling.Utf16)]
internal static partial uint Everything_GetResultFullPathName(uint nIndex, [Out] char[] lpString, uint nMaxCount);
[LibraryImport(dllName)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static partial bool Everything_GetMatchPath();
[LibraryImport(dllName)]
internal static partial uint Everything_GetMax();
[LibraryImport(dllName)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static partial bool Everything_GetRegex();
[LibraryImport(dllName, StringMarshalling = StringMarshalling.Utf16)]
internal static partial uint Everything_GetResultFullPathNameW(uint nIndex, [Out] char[] lpString, uint nMaxCount);
[LibraryImport(dllName)]
internal static partial uint Everything_GetSort();
[LibraryImport(dllName, StringMarshalling = StringMarshalling.Utf16)]
internal static partial uint Everything_IncRunCountFromFileName(string lpFileName);
internal static partial uint Everything_IncRunCountFromFileNameW(string lpFileName);
[LibraryImport(dllName)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static partial bool Everything_IsFolderResult(uint index);
Expand Down
27 changes: 23 additions & 4 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu,
private ContextMenuLoader _contextMenuLoader;
private bool _disposed;

public IEnumerable<PluginAdditionalOption> AdditionalOptions => new List<PluginAdditionalOption>()
{
public IEnumerable<PluginAdditionalOption> AdditionalOptions =>
[
new()
{
Key = nameof(Settings.Context),
Expand Down Expand Up @@ -102,7 +102,15 @@ public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu,
DisplayDescription = $"v{Assembly.GetExecutingAssembly().GetName().Version}",
Value = _setting.Updates,
},
};
new()
{
Key = nameof(Settings.Log),
DisplayLabel = "Debug Mode",
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Combobox,
ComboBoxItems = Enum.GetValues(typeof(LogLevel)).Cast<int>().Select(d => new KeyValuePair<string, string>(((LogLevel)d).ToString(), d + string.Empty)).ToList(),
ComboBoxValue = (int)_setting.Log,
},
];

private void CheckArm()
{
Expand All @@ -111,6 +119,8 @@ private void CheckArm()
if (File.Exists(arm))
{
Architecture arch = RuntimeInformation.ProcessArchitecture;
if (_setting.Log > LogLevel.None)
Debugger.Write("0.Checking ARM..." + (_setting.Log == LogLevel.Verbose ? $"\r\n\tArchitecture: {arch}" : string.Empty));
if (arch == Architecture.Arm64)
{
File.Delete(Path.Combine(dir, "Everything64.dll"));
Expand All @@ -121,6 +131,9 @@ private void CheckArm()
File.Delete(arm);
}
}

if (_setting.Log > LogLevel.None)
Debugger.Write(" Checking ARM...Done");
}

public void Init(PluginInitContext context)
Expand All @@ -132,6 +145,8 @@ public void Init(PluginInitContext context)
_everything = new Everything(_setting);
_contextMenuLoader = new ContextMenuLoader(context, _setting.Context);
_contextMenuLoader.Update(_setting);
if (_setting.Log > LogLevel.None)
Debugger.Write("Init Complete\r\n");
}

public void UpdateSettings(PowerLauncherPluginSettings settings)
Expand All @@ -148,6 +163,7 @@ public void UpdateSettings(PowerLauncherPluginSettings settings)
_setting.QueryText = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.QueryText)).Value;
_setting.EnvVar = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.EnvVar)).Value;
_setting.Updates = settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Updates)).Value;
_setting.Log = (LogLevel)settings.AdditionalOptions.FirstOrDefault(x => x.Key == nameof(_setting.Log)).ComboBoxValue;

_everything?.UpdateSettings(_setting);
_contextMenuLoader?.Update(_setting);
Expand All @@ -165,7 +181,7 @@ public List<Result> Query(Query query, bool delayedExecution)
List<Result> results = [];
if (!string.IsNullOrEmpty(query.Search))
{
var searchQuery = query.Search;
string searchQuery = query.Search;

try
{
Expand All @@ -183,6 +199,9 @@ public List<Result> Query(Query query, bool delayedExecution)
}
catch (Exception e)
{
if (_setting.Log > LogLevel.None)
Debugger.Write($"Everything Exception: {e.Message}\r\n{e.StackTrace}\r\n");

Log.Exception("Everything Exception", e, GetType());
}
}
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 @@ -195,7 +195,7 @@
</data>
<data name="RegEx_Description" xml:space="preserve">
<value>Enable regular expression in search.
Recommend using r: in query instead of enabling this option</value>
Recommend using regex: in query instead of enabling this option</value>
</data>
<data name="run_as_admin" xml:space="preserve">
<value>Run as administrator (Ctrl+Shift+Enter)</value>
Expand Down
2 changes: 1 addition & 1 deletion Properties/Resources.zh.resx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
</data>
<data name="RegEx_Description" xml:space="preserve">
<value>RegEx 正規表示式搜尋
不建議啟用,建議在收尋詞裡使用 r:</value>
不建議啟用,建議在收尋詞裡使用 regex:</value>
</data>
<data name="run_as_admin" xml:space="preserve">
<value>以系統管理員身分執行 (Ctrl+Shift+Enter)</value>
Expand Down
23 changes: 21 additions & 2 deletions Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,42 @@ public class Settings
public bool EnvVar { get; set; }
public bool Updates { get; set; } = true;
public string Skip { get; set; }
public LogLevel Log { get; set; } = LogLevel.None;

// Get Filters from settings.toml
public Dictionary<string, string> Filters { get; } = [];
internal void Getfilters()
{
if (Log > LogLevel.None)
Debugger.Write("2.Getting Filters...");
string[] strArr;
try { strArr = File.ReadAllLines(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "settings.toml")); }
catch { return; }
catch (Exception e)
{
if (Log > LogLevel.None)
Debugger.Write($"\r\nERROR: {e.Message}\r\n");
return;
}

foreach (string str in strArr)
{
if (str.Length == 0 || str[0] == '#') continue;
string[] kv = str.Split('=', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if (kv.Length != 2) continue;

if (kv[0].Contains(':'))
Filters.TryAdd(kv[0].ToLowerInvariant(), kv[1]);
Filters.TryAdd(kv[0].ToLowerInvariant(), kv[1] + (kv[1].EndsWith(';') ? ' ' : string.Empty));
}

if (Log > LogLevel.None)
Debugger.Write(Log > LogLevel.Debug ? string.Join(Environment.NewLine, Filters) + "\r\n" : string.Empty + " GettingFilters...Done");
}
}

public enum LogLevel
{
None,
Debug,
Verbose,
}
}
14 changes: 13 additions & 1 deletion Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ internal sealed class Update
internal async Task UpdateAsync(Version v, Settings s)
{
string apiUrl = "https://api.github.com/repos/lin-ycv/EverythingPowerToys/releases/latest";
if (s.Log > LogLevel.None)
Debugger.Write("1.Checking Update...");

try
{
using HttpClient httpClient = new();
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0");

HttpResponseMessage response = await httpClient.GetAsync(apiUrl);

if (s.Log == LogLevel.Verbose) Debugger.Write($"\tResponse: {response.StatusCode}");

if (response.IsSuccessStatusCode)
{
using JsonDocument jsonDocument = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync());
Expand Down Expand Up @@ -69,7 +75,13 @@ internal async Task UpdateAsync(Version v, Settings s)
}
}
}
catch { }
catch (Exception e)
{
if (s.Log > LogLevel.None)
Debugger.Write($"\r\nERROR: {e.Message}\r\n{e.StackTrace}\r\n");
}

Debugger.Write(" Checking Update...Done");
}
}
}
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.81.0",
"Version": "0.81.0.1",
"Language": "csharp",
"Website": "https://github.com/Lin-ycv/EverythingPowerToys",
"ExecuteFileName": "Community.PowerToys.Run.Plugin.Everything.dll",
Expand Down
13 changes: 6 additions & 7 deletions settings.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Lines starting with # are comments
# Search filters, filters result with extension type, seperated by ;
Audio: = ext: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
Zip: = ext: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
Doc: = ext:c;cc;chm;cpp;cs;css;csv;cxx;doc;docm;docx;dot;dotm;dotx;epub;gh;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
Exe: = ext:bat;cmd;exe;msi;msp;msu;ps1;scr
Pic: = ext: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: = ext: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
r: = regex:
Audio: = ext: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;
Zip: = ext: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;
Doc: = ext:c;cc;chm;cpp;cs;css;csv;cxx;doc;docm;docx;dot;dotm;dotx;epub;gh;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;
Exe: = ext:bat;cmd;exe;msi;msp;msu;ps1;scr;
Pic: = ext: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: = ext: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;

# Search filters, filters result with custom path(s), seperated by |
# Demo: = C:\Windows\|C:\ProgramData

0 comments on commit 6097e4b

Please sign in to comment.