mirror of
https://github.com/lin-ycv/EverythingPowerToys.git
synced 2025-01-08 11:57:59 +08:00
Working Version
This commit is contained in:
parent
65f7bc88aa
commit
438758407e
@ -96,7 +96,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Everything64.dll">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Images\Everything.dark.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
@ -104,6 +104,16 @@
|
||||
<None Update="Images\Everything.light.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Images\Warning.dark.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Images\Warning.light.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="del /Q "$(TargetDir)*.pdb"
del /Q "$(TargetDir)PowerToys*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
188
ContextMenuLoader.cs
Normal file
188
ContextMenuLoader.cs
Normal file
@ -0,0 +1,188 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.IO.Abstractions;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
|
||||
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" };
|
||||
|
||||
public ContextMenuLoader(PluginInitContext context)
|
||||
{
|
||||
_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")]
|
||||
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
var contextMenus = new List<ContextMenuResult>();
|
||||
if (selectedResult.ContextData is SearchResult record)
|
||||
{
|
||||
ResultType type = _path.HasExtension(record.Path) ? ResultType.File : ResultType.Folder;
|
||||
|
||||
if (type == ResultType.File)
|
||||
{
|
||||
contextMenus.Add(CreateOpenContainingFolderResult(record));
|
||||
}
|
||||
|
||||
// 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))
|
||||
{
|
||||
contextMenus.Add(CreateRunAsAdminContextMenu(record));
|
||||
}
|
||||
|
||||
contextMenus.Add(new ContextMenuResult
|
||||
{
|
||||
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||
Title = Properties.Resources.copy_path,
|
||||
Glyph = "\xE8C8",
|
||||
FontFamily = "Segoe MDL2 Assets",
|
||||
AcceleratorKey = Key.C,
|
||||
AcceleratorModifiers = ModifierKeys.Control,
|
||||
|
||||
Action = (context) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Clipboard.SetText(record.Path);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var message = Properties.Resources.clipboard_failed;
|
||||
Log.Exception(message, e, GetType());
|
||||
|
||||
_context.API.ShowMsg(message);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
});
|
||||
contextMenus.Add(new ContextMenuResult
|
||||
{
|
||||
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||
Title = Properties.Resources.open_in_console,
|
||||
Glyph = "\xE756",
|
||||
FontFamily = "Segoe MDL2 Assets",
|
||||
AcceleratorKey = Key.C,
|
||||
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||
|
||||
Action = (context) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (type == ResultType.File)
|
||||
{
|
||||
Helper.OpenInConsole(_path.GetDirectoryName(record.Path));
|
||||
}
|
||||
else
|
||||
{
|
||||
Helper.OpenInConsole(record.Path);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Exception($"Failed to open {record.Path} in console, {e.Message}", e, GetType());
|
||||
return false;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return contextMenus;
|
||||
}
|
||||
|
||||
// Function to add the context menu item to run as admin
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive, and instead log the exception message")]
|
||||
private static ContextMenuResult CreateRunAsAdminContextMenu(SearchResult record)
|
||||
{
|
||||
return new ContextMenuResult
|
||||
{
|
||||
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||
Title = Properties.Resources.run_as_admin,
|
||||
Glyph = "\xE7EF",
|
||||
FontFamily = "Segoe MDL2 Assets",
|
||||
AcceleratorKey = Key.Enter,
|
||||
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||
Action = _ =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Task.Run(() => Helper.RunAsAdmin(record.Path));
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Exception($"Failed to run {record.Path} as admin, {e.Message}", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Function to test if the file can be run as admin
|
||||
private bool CanFileBeRunAsAdmin(string path)
|
||||
{
|
||||
string fileExtension = _path.GetExtension(path);
|
||||
foreach (string extension in appExtensions)
|
||||
{
|
||||
// Using OrdinalIgnoreCase since this is internal
|
||||
if (extension.Equals(fileExtension, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[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)
|
||||
{
|
||||
return new ContextMenuResult
|
||||
{
|
||||
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
|
||||
Title = Properties.Resources.open_containing_folder,
|
||||
Glyph = "\xE838",
|
||||
FontFamily = "Segoe MDL2 Assets",
|
||||
AcceleratorKey = Key.E,
|
||||
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||
Action = _ =>
|
||||
{
|
||||
if (!Helper.OpenInShell("explorer.exe", $"/select,\"{record.Path}\""))
|
||||
{
|
||||
var message = $"{Properties.Resources.folder_open_failed} {record.Path}";
|
||||
_context.API.ShowMsg(message);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
66
Main.cs
66
Main.cs
@ -14,13 +14,14 @@ using System.Windows.Controls;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
using static Community.PowerToys.Run.Plugin.Everything.NativeMethods;
|
||||
|
||||
namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin
|
||||
public class Main : IPlugin, IDisposable, IDelayedExecutionPlugin, IContextMenu
|
||||
{
|
||||
private readonly string reservedStringPattern = @"^[\/\\\$\%]+$|^.*[<>].*$";
|
||||
|
||||
@ -28,17 +29,17 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
|
||||
public string Description => Properties.Resources.plugin_description;
|
||||
|
||||
private PluginInitContext _context;
|
||||
private bool disposedValue;
|
||||
|
||||
private string _warningIconPath;
|
||||
private ErrorCode errorCode;
|
||||
|
||||
private string IconPath { get; set; }
|
||||
|
||||
private IContextMenu _contextMenuLoader;
|
||||
private PluginInitContext _context;
|
||||
private bool disposed;
|
||||
private string _warningIconPath;
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
_context = context ?? throw new ArgumentNullException(nameof(context));
|
||||
_context = context;
|
||||
_contextMenuLoader = new ContextMenuLoader(context);
|
||||
_context.API.ThemeChanged += OnThemeChanged;
|
||||
UpdateIconPath(_context.API.GetCurrentTheme());
|
||||
}
|
||||
@ -46,41 +47,39 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
uint major = Everything_GetMajorVersion();
|
||||
uint minor = Everything_GetMinorVersion();
|
||||
uint rev = Everything_GetRevision();
|
||||
if (major == 0 && minor == 0 && rev == 0 && (ErrorCode)Everything_GetLastError() != ErrorCode.EVERYTHING_OK)
|
||||
{
|
||||
errorCode = (ErrorCode)Everything_GetLastError();
|
||||
results.Add(new Result
|
||||
{
|
||||
Title = Properties.Resources.Everything_not_running,
|
||||
IcoPath = _warningIconPath,
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
errorCode = ErrorCode.EVERYTHING_OK;
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
[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)
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
if (query != null && !string.IsNullOrEmpty(query.Search))
|
||||
if (!string.IsNullOrEmpty(query.Search))
|
||||
{
|
||||
var searchQuery = query.RawQuery;
|
||||
var searchQuery = query.Search;
|
||||
|
||||
var regexMatch = Regex.Match(searchQuery, reservedStringPattern);
|
||||
|
||||
if (errorCode == ErrorCode.EVERYTHING_OK && !regexMatch.Success)
|
||||
if (!regexMatch.Success)
|
||||
{
|
||||
try
|
||||
{
|
||||
results.AddRange(EverythingSearch(searchQuery));
|
||||
var found = EverythingSearch(searchQuery);
|
||||
if (found.ElementAt(0).Title == "!")
|
||||
{
|
||||
results.Add(new Result()
|
||||
{
|
||||
Title = Properties.Resources.Everything_not_running,
|
||||
SubTitle = Properties.Resources.Everything_ini,
|
||||
IcoPath = _warningIconPath,
|
||||
QueryTextDisplay = Properties.Resources.Everything_url,
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
results.AddRange(found);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -111,15 +110,20 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
}
|
||||
}
|
||||
|
||||
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
return _contextMenuLoader.LoadContextMenus(selectedResult);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
if (!disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
231
NativeMethods.cs
231
NativeMethods.cs
@ -6,6 +6,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@ -18,63 +20,69 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
internal enum ErrorCode
|
||||
{
|
||||
EVERYTHING_OK,
|
||||
EVERYTHING_ERROR_MEMORY,
|
||||
EVERYTHING_ERROR_IPC,
|
||||
EVERYTHING_ERROR_REGISTERCLASSEX,
|
||||
EVERYTHING_ERROR_CREATEWINDOW,
|
||||
EVERYTHING_ERROR_CREATETHREAD,
|
||||
EVERYTHING_ERROR_INVALIDINDEX,
|
||||
EVERYTHING_ERROR_INVALIDCALL,
|
||||
OK,
|
||||
ERROR_MEMORY,
|
||||
ERROR_IPC,
|
||||
ERROR_REGISTERCLASSEX,
|
||||
ERROR_CREATEWINDOW,
|
||||
ERROR_CREATETHREAD,
|
||||
ERROR_INVALIDINDEX,
|
||||
ERROR_INVALIDCALL,
|
||||
}
|
||||
|
||||
internal const int EVERYTHING_REQUEST_FILE_NAME = 0x00000001;
|
||||
internal const int EVERYTHING_REQUEST_PATH = 0x00000002;
|
||||
internal const int EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME = 0x00000004;
|
||||
internal const int EVERYTHING_REQUEST_EXTENSION = 0x00000008;
|
||||
internal const int EVERYTHING_REQUEST_SIZE = 0x00000010;
|
||||
internal const int EVERYTHING_REQUEST_DATE_CREATED = 0x00000020;
|
||||
internal const int EVERYTHING_REQUEST_DATE_MODIFIED = 0x00000040;
|
||||
internal const int EVERYTHING_REQUEST_DATE_ACCESSED = 0x00000080;
|
||||
internal const int EVERYTHING_REQUEST_ATTRIBUTES = 0x00000100;
|
||||
internal const int EVERYTHING_REQUEST_FILE_LIST_FILE_NAME = 0x00000200;
|
||||
internal const int EVERYTHING_REQUEST_RUN_COUNT = 0x00000400;
|
||||
internal const int EVERYTHING_REQUEST_DATE_RUN = 0x00000800;
|
||||
internal const int EVERYTHING_REQUEST_DATE_RECENTLY_CHANGED = 0x00001000;
|
||||
internal const int EVERYTHING_REQUEST_HIGHLIGHTED_FILE_NAME = 0x00002000;
|
||||
internal const int EVERYTHING_REQUEST_HIGHLIGHTED_PATH = 0x00004000;
|
||||
internal const int EVERYTHING_REQUEST_HIGHLIGHTED_FULL_PATH_AND_FILE_NAME = 0x00008000;
|
||||
internal enum Request
|
||||
{
|
||||
FILE_NAME = 0x00000001,
|
||||
PATH = 0x00000002,
|
||||
FULL_PATH_AND_FILE_NAME = 0x00000004,
|
||||
EXTENSION = 0x00000008,
|
||||
SIZE = 0x00000010,
|
||||
DATE_CREATED = 0x00000020,
|
||||
DATE_MODIFIED = 0x00000040,
|
||||
DATE_ACCESSED = 0x00000080,
|
||||
ATTRIBUTES = 0x00000100,
|
||||
FILE_LIST_FILE_NAME = 0x00000200,
|
||||
RUN_COUNT = 0x00000400,
|
||||
DATE_RUN = 0x00000800,
|
||||
DATE_RECENTLY_CHANGED = 0x00001000,
|
||||
HIGHLIGHTED_FILE_NAME = 0x00002000,
|
||||
HIGHLIGHTED_PATH = 0x00004000,
|
||||
HIGHLIGHTED_FULL_PATH_AND_FILE_NAME = 0x00008000,
|
||||
}
|
||||
|
||||
internal const int EVERYTHING_SORT_NAME_ASCENDING = 1;
|
||||
internal const int EVERYTHING_SORT_NAME_DESCENDING = 2;
|
||||
internal const int EVERYTHING_SORT_PATH_ASCENDING = 3;
|
||||
internal const int EVERYTHING_SORT_PATH_DESCENDING = 4;
|
||||
internal const int EVERYTHING_SORT_SIZE_ASCENDING = 5;
|
||||
internal const int EVERYTHING_SORT_SIZE_DESCENDING = 6;
|
||||
internal const int EVERYTHING_SORT_EXTENSION_ASCENDING = 7;
|
||||
internal const int EVERYTHING_SORT_EXTENSION_DESCENDING = 8;
|
||||
internal const int EVERYTHING_SORT_TYPE_NAME_ASCENDING = 9;
|
||||
internal const int EVERYTHING_SORT_TYPE_NAME_DESCENDING = 10;
|
||||
internal const int EVERYTHING_SORT_DATE_CREATED_ASCENDING = 11;
|
||||
internal const int EVERYTHING_SORT_DATE_CREATED_DESCENDING = 12;
|
||||
internal const int EVERYTHING_SORT_DATE_MODIFIED_ASCENDING = 13;
|
||||
internal const int EVERYTHING_SORT_DATE_MODIFIED_DESCENDING = 14;
|
||||
internal const int EVERYTHING_SORT_ATTRIBUTES_ASCENDING = 15;
|
||||
internal const int EVERYTHING_SORT_ATTRIBUTES_DESCENDING = 16;
|
||||
internal const int EVERYTHING_SORT_FILE_LIST_FILENAME_ASCENDING = 17;
|
||||
internal const int EVERYTHING_SORT_FILE_LIST_FILENAME_DESCENDING = 18;
|
||||
internal const int EVERYTHING_SORT_RUN_COUNT_ASCENDING = 19;
|
||||
internal const int EVERYTHING_SORT_RUN_COUNT_DESCENDING = 20;
|
||||
internal const int EVERYTHING_SORT_DATE_RECENTLY_CHANGED_ASCENDING = 21;
|
||||
internal const int EVERYTHING_SORT_DATE_RECENTLY_CHANGED_DESCENDING = 22;
|
||||
internal const int EVERYTHING_SORT_DATE_ACCESSED_ASCENDING = 23;
|
||||
internal const int EVERYTHING_SORT_DATE_ACCESSED_DESCENDING = 24;
|
||||
internal const int EVERYTHING_SORT_DATE_RUN_ASCENDING = 25;
|
||||
internal const int EVERYTHING_SORT_DATE_RUN_DESCENDING = 26;
|
||||
internal enum Sort
|
||||
{
|
||||
NAME_ASCENDING = 1,
|
||||
NAME_DESCENDING,
|
||||
PATH_ASCENDING,
|
||||
PATH_DESCENDING,
|
||||
SIZE_ASCENDING,
|
||||
SIZE_DESCENDING,
|
||||
EXTENSION_ASCENDING,
|
||||
EXTENSION_DESCENDING,
|
||||
TYPE_NAME_ASCENDING,
|
||||
TYPE_NAME_DESCENDING,
|
||||
DATE_CREATED_ASCENDING,
|
||||
DATE_CREATED_DESCENDING,
|
||||
DATE_MODIFIED_ASCENDING,
|
||||
DATE_MODIFIED_DESCENDING,
|
||||
ATTRIBUTES_ASCENDING,
|
||||
ATTRIBUTES_DESCENDING,
|
||||
FILE_LIST_FILENAME_ASCENDING,
|
||||
FILE_LIST_FILENAME_DESCENDING,
|
||||
RUN_COUNT_ASCENDING,
|
||||
RUN_COUNT_DESCENDING,
|
||||
DATE_RECENTLY_CHANGED_ASCENDING,
|
||||
DATE_RECENTLY_CHANGED_DESCENDING,
|
||||
DATE_ACCESSED_ASCENDING,
|
||||
DATE_ACCESSED_DESCENDING,
|
||||
DATE_RUN_ASCENDING,
|
||||
DATE_RUN_DESCENDING,
|
||||
}
|
||||
|
||||
internal const int EVERYTHING_TARGET_MACHINE_X86 = 1;
|
||||
internal const int EVERYTHING_TARGET_MACHINE_X64 = 2;
|
||||
internal const int EVERYTHING_TARGET_MACHINE_ARM = 3;
|
||||
internal const int TARGET_MACHINE_X86 = 1;
|
||||
internal const int TARGET_MACHINE_X64 = 2;
|
||||
internal const int TARGET_MACHINE_ARM = 3;
|
||||
private const string dllName = "Everything64.dll";
|
||||
|
||||
#pragma warning disable SA1516 // Elements should be separated by blank line
|
||||
@ -216,88 +224,97 @@ namespace Community.PowerToys.Run.Plugin.Everything
|
||||
[DllImport(dllName)]
|
||||
public static extern void Everything_SetReplyID(uint nId);
|
||||
[DllImport(dllName)]
|
||||
public static extern void Everything_SetRequestFlags(uint dwRequestFlags);
|
||||
public static extern void Everything_SetRequestFlags(Request RequestFlags);
|
||||
[DllImport(dllName, CharSet = CharSet.Unicode)]
|
||||
public static extern bool Everything_SetRunCountFromFileName(string lpFileName, uint dwRunCount);
|
||||
[DllImport(dllName, CharSet = CharSet.Unicode)]
|
||||
public static extern uint Everything_SetSearchW(string lpSearchString);
|
||||
[DllImport(dllName)]
|
||||
public static extern void Everything_SetSort(uint dwSortType);
|
||||
public static extern void Everything_SetSort(Sort SortType);
|
||||
|
||||
[DllImport(dllName)]
|
||||
public static extern void Everything_SortResultsByPath();
|
||||
[DllImport(dllName)]
|
||||
public static extern bool Everything_UpdateAllFolderIndexes();
|
||||
|
||||
private static readonly IFileSystem _fileSystem = new FileSystem();
|
||||
private const int max = 5;
|
||||
private static CancellationTokenSource source;
|
||||
|
||||
#pragma warning disable SA1503 // Braces should not be omitted
|
||||
public static IEnumerable<Result> EverythingSearch(string qry)
|
||||
{
|
||||
source?.Cancel();
|
||||
source = new CancellationTokenSource();
|
||||
CancellationToken token = source.Token;
|
||||
source.CancelAfter(50);
|
||||
|
||||
_ = Everything_SetSearchW(qry);
|
||||
Everything_SetRequestFlags(EVERYTHING_REQUEST_FILE_NAME | EVERYTHING_REQUEST_PATH | EVERYTHING_REQUEST_DATE_MODIFIED | EVERYTHING_REQUEST_SIZE);
|
||||
Everything_SetSort(EVERYTHING_SORT_DATE_MODIFIED_DESCENDING);
|
||||
Everything_SetMax(20);
|
||||
Everything_SetRegex(false);
|
||||
if (qry.StartsWith("@", StringComparison.CurrentCulture))
|
||||
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();
|
||||
Everything_SetSort(Sort.DATE_MODIFIED_DESCENDING);
|
||||
if (token.IsCancellationRequested) yield return new Result();
|
||||
Everything_SetMax(max);
|
||||
if (token.IsCancellationRequested) yield return new Result();
|
||||
|
||||
if (!Everything_QueryW(true))
|
||||
{
|
||||
Everything_SetRegex(true);
|
||||
qry = qry.Substring(1);
|
||||
yield return new Result() { Title = "!", };
|
||||
}
|
||||
|
||||
_ = Everything_QueryW(true);
|
||||
uint resultCount = Everything_GetNumResults();
|
||||
|
||||
var t = Task.Run(
|
||||
() =>
|
||||
if (token.IsCancellationRequested) yield return new Result();
|
||||
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);
|
||||
if (isFolder)
|
||||
path = fullPath;
|
||||
else
|
||||
path = Path.GetDirectoryName(fullPath);
|
||||
|
||||
yield return new Result()
|
||||
{
|
||||
var results = new List<Result>();
|
||||
for (uint i = 0; i < resultCount; i++)
|
||||
Title = name,
|
||||
ToolTipData = new ToolTipData("Name : " + name, "Path : " + path),
|
||||
SubTitle = Properties.Resources.plugin_name + ": " + fullPath,
|
||||
IcoPath = fullPath,
|
||||
Score = (int)(max - i),
|
||||
ContextData = new SearchResult()
|
||||
{
|
||||
_ = Everything_GetResultDateModified(i, out long date_modified);
|
||||
_ = Everything_GetResultSize(i, out long size);
|
||||
string fileName = Marshal.PtrToStringUni(Everything_GetResultFileName(i));
|
||||
StringBuilder sb = new StringBuilder(999);
|
||||
Everything_GetResultFullPathName(i, sb, 999);
|
||||
string filePath = sb.ToString();
|
||||
|
||||
results.Add(new Result()
|
||||
Path = path,
|
||||
Title = name,
|
||||
},
|
||||
Action = e =>
|
||||
{
|
||||
using (var process = new Process())
|
||||
{
|
||||
Title = fileName,
|
||||
ToolTipData = new ToolTipData("Name : " + fileName, "Path : " + filePath),
|
||||
SubTitle = Properties.Resources.plugin_name + ":" + filePath,
|
||||
IcoPath = filePath,
|
||||
Score = (int)(Everything_GetTotResults() - i),
|
||||
Action = e =>
|
||||
process.StartInfo.FileName = fullPath;
|
||||
process.StartInfo.WorkingDirectory = path;
|
||||
process.StartInfo.UseShellExecute = true;
|
||||
|
||||
try
|
||||
{
|
||||
using (Process process = new Process())
|
||||
{
|
||||
process.StartInfo.FileName = System.IO.Path.Combine(filePath, fileName);
|
||||
process.StartInfo.WorkingDirectory = filePath;
|
||||
process.StartInfo.Arguments = string.Empty;
|
||||
|
||||
process.StartInfo.UseShellExecute = true;
|
||||
|
||||
try
|
||||
{
|
||||
_ = process.Start();
|
||||
return true;
|
||||
}
|
||||
catch (System.ComponentModel.Win32Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return results;
|
||||
}, token);
|
||||
return t.Result;
|
||||
process.Start();
|
||||
return true;
|
||||
}
|
||||
catch (System.ComponentModel.Win32Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
QueryTextDisplay = isFolder ? path : name,
|
||||
};
|
||||
if (token.IsCancellationRequested) break;
|
||||
}
|
||||
}
|
||||
#pragma warning restore SA1503 // Braces should not be omitted
|
||||
}
|
||||
}
|
||||
|
72
Properties/Resources.Designer.cs
generated
72
Properties/Resources.Designer.cs
generated
@ -60,6 +60,33 @@ namespace Community.PowerToys.Run.Plugin.Everything.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Fail to set text in clipboard.
|
||||
/// </summary>
|
||||
public static string clipboard_failed {
|
||||
get {
|
||||
return ResourceManager.GetString("clipboard_failed", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Copy path (Ctrl+C).
|
||||
/// </summary>
|
||||
public static string copy_path {
|
||||
get {
|
||||
return ResourceManager.GetString("copy_path", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Install Everything if not installed.
|
||||
/// </summary>
|
||||
public static string Everything_ini {
|
||||
get {
|
||||
return ResourceManager.GetString("Everything_ini", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Everything is not running.
|
||||
/// </summary>
|
||||
@ -69,6 +96,42 @@ namespace Community.PowerToys.Run.Plugin.Everything.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to https://www.voidtools.com/downloads/.
|
||||
/// </summary>
|
||||
public static string Everything_url {
|
||||
get {
|
||||
return ResourceManager.GetString("Everything_url", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Fail to open folder at.
|
||||
/// </summary>
|
||||
public static string folder_open_failed {
|
||||
get {
|
||||
return ResourceManager.GetString("folder_open_failed", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Open containing folder (Ctrl+Shift+E).
|
||||
/// </summary>
|
||||
public static string open_containing_folder {
|
||||
get {
|
||||
return ResourceManager.GetString("open_containing_folder", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Open path in console (Ctrl+Shift+C).
|
||||
/// </summary>
|
||||
public static string open_in_console {
|
||||
get {
|
||||
return ResourceManager.GetString("open_in_console", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Get search results from Everything.
|
||||
/// </summary>
|
||||
@ -86,5 +149,14 @@ namespace Community.PowerToys.Run.Plugin.Everything.Properties {
|
||||
return ResourceManager.GetString("plugin_name", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Run as administrator (Ctrl+Shift+Enter).
|
||||
/// </summary>
|
||||
public static string run_as_admin {
|
||||
get {
|
||||
return ResourceManager.GetString("run_as_admin", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,13 +117,37 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="clipboard_failed" xml:space="preserve">
|
||||
<value>Fail to set text in clipboard</value>
|
||||
</data>
|
||||
<data name="copy_path" xml:space="preserve">
|
||||
<value>Copy path (Ctrl+C)</value>
|
||||
</data>
|
||||
<data name="Everything_ini" xml:space="preserve">
|
||||
<value>Install Everything if not installed</value>
|
||||
</data>
|
||||
<data name="Everything_not_running" xml:space="preserve">
|
||||
<value>Everything is not running</value>
|
||||
</data>
|
||||
<data name="Everything_url" xml:space="preserve">
|
||||
<value>https://www.voidtools.com/downloads/</value>
|
||||
</data>
|
||||
<data name="folder_open_failed" xml:space="preserve">
|
||||
<value>Fail to open folder at</value>
|
||||
</data>
|
||||
<data name="open_containing_folder" xml:space="preserve">
|
||||
<value>Open containing folder (Ctrl+Shift+E)</value>
|
||||
</data>
|
||||
<data name="open_in_console" xml:space="preserve">
|
||||
<value>Open path in console (Ctrl+Shift+C)</value>
|
||||
</data>
|
||||
<data name="plugin_description" xml:space="preserve">
|
||||
<value>Get search results from Everything</value>
|
||||
</data>
|
||||
<data name="plugin_name" xml:space="preserve">
|
||||
<value>Everything</value>
|
||||
</data>
|
||||
<data name="run_as_admin" xml:space="preserve">
|
||||
<value>Run as administrator (Ctrl+Shift+Enter)</value>
|
||||
</data>
|
||||
</root>
|
15
SearchHelper/SearchResult.cs
Normal file
15
SearchHelper/SearchResult.cs
Normal file
@ -0,0 +1,15 @@
|
||||
// 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.
|
||||
|
||||
namespace Community.PowerToys.Run.Plugin.Everything
|
||||
{
|
||||
public class SearchResult
|
||||
{
|
||||
// Contains the Path of the file or folder
|
||||
public string Path { get; set; }
|
||||
|
||||
// Contains the Title of the file or folder
|
||||
public string Title { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user