mirror of
https://github.com/lin-ycv/EverythingPowerToys.git
synced 2025-01-08 11:57:59 +08:00
Empty result bug fixes #2
This commit is contained in:
parent
438758407e
commit
46f9dfde41
@ -4,6 +4,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
@ -17,16 +18,8 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
internal class ContextMenuLoader : IContextMenu
|
||||
{
|
||||
private readonly IPath _path = new FileSystem().Path;
|
||||
|
||||
private readonly PluginInitContext _context;
|
||||
|
||||
public enum ResultType
|
||||
{
|
||||
Folder,
|
||||
File,
|
||||
}
|
||||
|
||||
// Extensions for adding run as admin context menu item for applications
|
||||
private readonly string[] appExtensions = { ".exe", ".bat", ".appref-ms", ".lnk" };
|
||||
|
||||
@ -41,9 +34,9 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
var contextMenus = new List<ContextMenuResult>();
|
||||
if (selectedResult.ContextData is SearchResult record)
|
||||
{
|
||||
ResultType type = _path.HasExtension(record.Path) ? ResultType.File : ResultType.Folder;
|
||||
bool isFile = Path.HasExtension(record.Path);
|
||||
|
||||
if (type == ResultType.File)
|
||||
if (isFile)
|
||||
{
|
||||
contextMenus.Add(CreateOpenContainingFolderResult(record));
|
||||
}
|
||||
@ -93,9 +86,9 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
try
|
||||
{
|
||||
if (type == ResultType.File)
|
||||
if (isFile)
|
||||
{
|
||||
Helper.OpenInConsole(_path.GetDirectoryName(record.Path));
|
||||
Helper.OpenInConsole(Path.GetDirectoryName(record.Path));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -147,7 +140,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
// Function to test if the file can be run as admin
|
||||
private bool CanFileBeRunAsAdmin(string path)
|
||||
{
|
||||
string fileExtension = _path.GetExtension(path);
|
||||
string fileExtension = Path.GetExtension(path);
|
||||
foreach (string extension in appExtensions)
|
||||
{
|
||||
// Using OrdinalIgnoreCase since this is internal
|
||||
|
66
Main.cs
66
Main.cs
@ -11,6 +11,7 @@ using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Windows.Controls;
|
||||
using Community.PowerToys.Run.Plugin.Everything.Properties;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Wox.Infrastructure;
|
||||
@ -21,13 +22,25 @@ using static Community.PowerToys.Run.Plugin.Everything.NativeMethods;
|
||||
|
||||
namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu
|
||||
public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu, ISettingProvider
|
||||
{
|
||||
private const string Wait = nameof(Wait);
|
||||
private readonly string reservedStringPattern = @"^[\/\\\$\%]+$|^.*[<>].*$";
|
||||
private bool _wait;
|
||||
|
||||
public string Name => Properties.Resources.plugin_name;
|
||||
public string Name => Resources.plugin_name;
|
||||
|
||||
public string Description => Properties.Resources.plugin_description;
|
||||
public string Description => Resources.plugin_description;
|
||||
|
||||
public IEnumerable<PluginAdditionalOption> AdditionalOptions => new List<PluginAdditionalOption>()
|
||||
{
|
||||
new PluginAdditionalOption()
|
||||
{
|
||||
Key = Wait,
|
||||
DisplayLabel = Resources.Wait,
|
||||
Value = false,
|
||||
},
|
||||
};
|
||||
|
||||
private string IconPath { get; set; }
|
||||
|
||||
@ -65,21 +78,26 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
try
|
||||
{
|
||||
var found = EverythingSearch(searchQuery);
|
||||
if (found.ElementAt(0).Title == "!")
|
||||
results.AddRange(EverythingSearch(searchQuery, _wait));
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
results.Add(new Result()
|
||||
{
|
||||
results.Add(new Result()
|
||||
{
|
||||
Title = Properties.Resources.Everything_not_running,
|
||||
SubTitle = Properties.Resources.Everything_ini,
|
||||
IcoPath = _warningIconPath,
|
||||
QueryTextDisplay = Properties.Resources.Everything_url,
|
||||
});
|
||||
}
|
||||
else
|
||||
Title = Resources.timeout,
|
||||
SubTitle = Resources.enable_wait,
|
||||
IcoPath = _warningIconPath,
|
||||
});
|
||||
}
|
||||
catch (EntryPointNotFoundException)
|
||||
{
|
||||
results.Add(new Result()
|
||||
{
|
||||
results.AddRange(found);
|
||||
}
|
||||
Title = Resources.Everything_not_running,
|
||||
SubTitle = Resources.Everything_ini,
|
||||
IcoPath = _warningIconPath,
|
||||
QueryTextDisplay = Resources.Everything_url,
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -115,6 +133,22 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
return _contextMenuLoader.LoadContextMenus(selectedResult);
|
||||
}
|
||||
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void UpdateSettings(PowerLauncherPluginSettings settings)
|
||||
{
|
||||
var wait = false;
|
||||
if (settings != null && settings.AdditionalOptions != null)
|
||||
{
|
||||
wait = settings.AdditionalOptions.FirstOrDefault(x => x.Key == Wait)?.Value ?? false;
|
||||
}
|
||||
|
||||
_wait = wait;
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
|
@ -237,43 +237,41 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
[DllImport(dllName)]
|
||||
public static extern bool Everything_UpdateAllFolderIndexes();
|
||||
|
||||
private static readonly IFileSystem _fileSystem = new FileSystem();
|
||||
private const int max = 5;
|
||||
private const int max = 20;
|
||||
private static CancellationTokenSource source;
|
||||
#pragma warning disable SA1503 // Braces should not be omitted
|
||||
public static IEnumerable<Result> EverythingSearch(string qry)
|
||||
public static IEnumerable<Result> EverythingSearch(string qry, bool wait)
|
||||
{
|
||||
source?.Cancel();
|
||||
source = new CancellationTokenSource();
|
||||
CancellationToken token = source.Token;
|
||||
source.CancelAfter(50);
|
||||
source.CancelAfter(wait ? 1000 : 75);
|
||||
|
||||
_ = Everything_SetSearchW(qry);
|
||||
if (token.IsCancellationRequested) yield return new Result();
|
||||
Everything_SetRequestFlags(Request.FULL_PATH_AND_FILE_NAME | Request.DATE_MODIFIED);
|
||||
if (token.IsCancellationRequested) yield return new Result();
|
||||
if (token.IsCancellationRequested) token.ThrowIfCancellationRequested();
|
||||
Everything_SetRequestFlags(Request.FULL_PATH_AND_FILE_NAME);
|
||||
if (token.IsCancellationRequested) token.ThrowIfCancellationRequested();
|
||||
Everything_SetSort(Sort.DATE_MODIFIED_DESCENDING);
|
||||
if (token.IsCancellationRequested) yield return new Result();
|
||||
if (token.IsCancellationRequested) token.ThrowIfCancellationRequested();
|
||||
Everything_SetMax(max);
|
||||
if (token.IsCancellationRequested) yield return new Result();
|
||||
if (token.IsCancellationRequested) token.ThrowIfCancellationRequested();
|
||||
|
||||
if (!Everything_QueryW(true))
|
||||
{
|
||||
yield return new Result() { Title = "!", };
|
||||
throw new EntryPointNotFoundException();
|
||||
}
|
||||
|
||||
uint resultCount = Everything_GetNumResults();
|
||||
|
||||
if (token.IsCancellationRequested) yield return new Result();
|
||||
if (token.IsCancellationRequested) token.ThrowIfCancellationRequested();
|
||||
for (uint i = 0; i < resultCount; i++)
|
||||
{
|
||||
/*Marshal.PtrToStringUni(*/
|
||||
StringBuilder sb = new StringBuilder(260);
|
||||
Everything_GetResultFullPathName(i, sb, 260);
|
||||
string fullPath = sb.ToString();
|
||||
string name = Path.GetFileName(fullPath);
|
||||
string path;
|
||||
bool isFolder = _fileSystem.Directory.Exists(fullPath);
|
||||
bool isFolder = Path.HasExtension(fullPath);
|
||||
if (isFolder)
|
||||
path = fullPath;
|
||||
else
|
||||
@ -288,7 +286,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
Score = (int)(max - i),
|
||||
ContextData = new SearchResult()
|
||||
{
|
||||
Path = path,
|
||||
Path = fullPath,
|
||||
Title = name,
|
||||
},
|
||||
Action = e =>
|
||||
@ -312,7 +310,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
},
|
||||
QueryTextDisplay = isFolder ? path : name,
|
||||
};
|
||||
if (token.IsCancellationRequested) break;
|
||||
if (token.IsCancellationRequested) yield break/*token.ThrowIfCancellationRequested()*/;
|
||||
}
|
||||
}
|
||||
#pragma warning restore SA1503 // Braces should not be omitted
|
||||
|
27
Properties/Resources.Designer.cs
generated
27
Properties/Resources.Designer.cs
generated
@ -78,6 +78,15 @@ namespace Community.PowerToys.Run.Plugin.Everything.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Enable Wait setting under PowerToys Run > Everything.
|
||||
/// </summary>
|
||||
public static string enable_wait {
|
||||
get {
|
||||
return ResourceManager.GetString("enable_wait", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Install Everything if not installed.
|
||||
/// </summary>
|
||||
@ -158,5 +167,23 @@ namespace Community.PowerToys.Run.Plugin.Everything.Properties {
|
||||
return ResourceManager.GetString("run_as_admin", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Timed out before finishing the query.
|
||||
/// </summary>
|
||||
public static string timeout {
|
||||
get {
|
||||
return ResourceManager.GetString("timeout", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Wait - Wait longer for the query to finish..
|
||||
/// </summary>
|
||||
public static string Wait {
|
||||
get {
|
||||
return ResourceManager.GetString("Wait", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,6 +123,9 @@
|
||||
<data name="copy_path" xml:space="preserve">
|
||||
<value>Copy path (Ctrl+C)</value>
|
||||
</data>
|
||||
<data name="enable_wait" xml:space="preserve">
|
||||
<value>Enable Wait setting under PowerToys Run > Everything</value>
|
||||
</data>
|
||||
<data name="Everything_ini" xml:space="preserve">
|
||||
<value>Install Everything if not installed</value>
|
||||
</data>
|
||||
@ -150,4 +153,10 @@
|
||||
<data name="run_as_admin" xml:space="preserve">
|
||||
<value>Run as administrator (Ctrl+Shift+Enter)</value>
|
||||
</data>
|
||||
<data name="timeout" xml:space="preserve">
|
||||
<value>Timed out before finishing the query</value>
|
||||
</data>
|
||||
<data name="Wait" xml:space="preserve">
|
||||
<value>Wait - Wait longer for the query to finish.</value>
|
||||
</data>
|
||||
</root>
|
@ -4,7 +4,7 @@
|
||||
"IsGlobal": true,
|
||||
"Name": "Everything",
|
||||
"Author": "Yu Chieh (Victor) Lin",
|
||||
"Version": "0.1.0",
|
||||
"Version": "0.2.0",
|
||||
"Language": "csharp",
|
||||
"Website": "https://aka.ms/powertoys",
|
||||
"ExecuteFileName": "Community.PowerToys.Run.Plugin.Everything.dll",
|
||||
|
Loading…
Reference in New Issue
Block a user