2022-09-22 00:18:20 +00:00
|
|
|
|
using System;
|
2022-03-25 21:19:00 +00:00
|
|
|
|
using System.Collections.Generic;
|
2022-11-25 19:25:12 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.Runtime.CompilerServices;
|
2022-03-25 21:19:00 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2022-11-25 19:25:12 +00:00
|
|
|
|
using Flow.Launcher.Plugin.Explorer.Exceptions;
|
2022-09-10 15:45:41 +00:00
|
|
|
|
using Flow.Launcher.Plugin.Explorer.Search.IProvider;
|
2022-03-25 21:19:00 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Flow.Launcher.Plugin.Explorer.Search.Everything
|
|
|
|
|
|
{
|
2022-09-10 15:45:41 +00:00
|
|
|
|
public class EverythingSearchManager : IIndexProvider, IContentIndexProvider, IPathIndexProvider
|
2022-03-25 21:19:00 +00:00
|
|
|
|
{
|
|
|
|
|
|
private Settings Settings { get; }
|
2022-05-15 20:15:56 +00:00
|
|
|
|
|
2022-03-25 21:19:00 +00:00
|
|
|
|
public EverythingSearchManager(Settings settings)
|
|
|
|
|
|
{
|
|
|
|
|
|
Settings = settings;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-25 19:25:12 +00:00
|
|
|
|
private async ValueTask ThrowIfEverythingNotAvailableAsync(CancellationToken token = default)
|
|
|
|
|
|
{
|
2022-11-29 03:38:17 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!await EverythingApi.IsEverythingRunningAsync(token))
|
|
|
|
|
|
throw new EngineNotAvailableException(
|
|
|
|
|
|
Enum.GetName(Settings.IndexSearchEngineOption.Everything)!,
|
|
|
|
|
|
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_click_to_launch_or_install"),
|
|
|
|
|
|
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_is_not_running"),
|
2023-01-19 06:48:35 +00:00
|
|
|
|
Constants.EverythingErrorImagePath,
|
|
|
|
|
|
ClickToInstallEverythingAsync);
|
2022-11-29 03:38:17 +00:00
|
|
|
|
}
|
2022-12-04 17:39:53 +00:00
|
|
|
|
catch (DllNotFoundException)
|
2022-11-29 03:38:17 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new EngineNotAvailableException(
|
|
|
|
|
|
Enum.GetName(Settings.IndexSearchEngineOption.Everything)!,
|
|
|
|
|
|
"Please check whether your system is x86 or x64",
|
2023-01-19 06:48:35 +00:00
|
|
|
|
Constants.GeneralSearchErrorImagePath,
|
|
|
|
|
|
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_sdk_issue"));
|
2022-11-29 03:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-03-08 11:31:51 +00:00
|
|
|
|
|
2022-12-04 17:39:53 +00:00
|
|
|
|
private async ValueTask<bool> ClickToInstallEverythingAsync(ActionContext _)
|
2022-11-29 03:38:17 +00:00
|
|
|
|
{
|
|
|
|
|
|
var installedPath = await EverythingDownloadHelper.PromptDownloadIfNotInstallAsync(Settings.EverythingInstalledPath, Main.Context.API);
|
2023-02-11 16:35:26 +00:00
|
|
|
|
|
2022-11-29 03:38:17 +00:00
|
|
|
|
if (installedPath == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Main.Context.API.ShowMsgError("Unable to find Everything.exe");
|
2023-02-11 16:35:26 +00:00
|
|
|
|
|
2022-11-29 03:38:17 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-02-11 16:35:26 +00:00
|
|
|
|
|
2022-11-29 03:38:17 +00:00
|
|
|
|
Settings.EverythingInstalledPath = installedPath;
|
|
|
|
|
|
Process.Start(installedPath, "-startup");
|
2023-02-11 16:35:26 +00:00
|
|
|
|
|
2022-11-29 03:38:17 +00:00
|
|
|
|
return true;
|
2022-11-25 19:25:12 +00:00
|
|
|
|
}
|
2022-03-25 21:19:00 +00:00
|
|
|
|
|
2022-11-25 19:25:12 +00:00
|
|
|
|
public async IAsyncEnumerable<SearchResult> SearchAsync(string search, [EnumeratorCancellation] CancellationToken token)
|
2022-03-25 21:19:00 +00:00
|
|
|
|
{
|
2022-11-25 19:25:12 +00:00
|
|
|
|
await ThrowIfEverythingNotAvailableAsync(token);
|
2023-02-11 16:35:26 +00:00
|
|
|
|
|
2022-11-25 19:25:12 +00:00
|
|
|
|
if (token.IsCancellationRequested)
|
|
|
|
|
|
yield break;
|
2023-02-11 16:35:26 +00:00
|
|
|
|
|
2024-08-03 07:16:30 +00:00
|
|
|
|
var option = new EverythingSearchOption(search,
|
|
|
|
|
|
Settings.SortOption,
|
|
|
|
|
|
MaxCount: Settings.MaxResult,
|
|
|
|
|
|
IsFullPathSearch: Settings.EverythingSearchFullPath,
|
|
|
|
|
|
IsRunCounterEnabled: Settings.EverythingEnableRunCount);
|
2023-02-11 16:35:26 +00:00
|
|
|
|
|
2022-11-25 19:25:12 +00:00
|
|
|
|
await foreach (var result in EverythingApi.SearchAsync(option, token))
|
|
|
|
|
|
yield return result;
|
2022-03-25 21:19:00 +00:00
|
|
|
|
}
|
2023-03-08 11:31:51 +00:00
|
|
|
|
|
|
|
|
|
|
public async IAsyncEnumerable<SearchResult> ContentSearchAsync(string plainSearch, string contentSearch,
|
2023-02-11 16:35:26 +00:00
|
|
|
|
[EnumeratorCancellation] CancellationToken token)
|
2022-03-25 21:19:00 +00:00
|
|
|
|
{
|
2022-11-25 19:25:12 +00:00
|
|
|
|
await ThrowIfEverythingNotAvailableAsync(token);
|
2023-02-11 16:35:26 +00:00
|
|
|
|
|
2022-05-15 20:15:56 +00:00
|
|
|
|
if (!Settings.EnableEverythingContentSearch)
|
|
|
|
|
|
{
|
2022-12-04 17:39:53 +00:00
|
|
|
|
throw new EngineNotAvailableException(Enum.GetName(Settings.IndexSearchEngineOption.Everything)!,
|
2023-01-19 06:48:35 +00:00
|
|
|
|
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_enable_content_search"),
|
|
|
|
|
|
Main.Context.API.GetTranslation("flowlauncher_plugin_everything_enable_content_search_tips"),
|
|
|
|
|
|
Constants.EverythingErrorImagePath,
|
2022-11-25 19:25:12 +00:00
|
|
|
|
_ =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Settings.EnableEverythingContentSearch = true;
|
2023-02-11 16:35:26 +00:00
|
|
|
|
|
2022-11-25 19:25:12 +00:00
|
|
|
|
return ValueTask.FromResult(true);
|
2023-01-19 06:48:35 +00:00
|
|
|
|
});
|
2022-05-15 20:15:56 +00:00
|
|
|
|
}
|
2023-02-11 16:35:26 +00:00
|
|
|
|
|
2022-11-25 19:25:12 +00:00
|
|
|
|
if (token.IsCancellationRequested)
|
|
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
|
|
|
|
var option = new EverythingSearchOption(plainSearch,
|
|
|
|
|
|
Settings.SortOption,
|
2023-04-03 13:00:26 +00:00
|
|
|
|
IsContentSearch: true,
|
|
|
|
|
|
ContentSearchKeyword: contentSearch,
|
2024-08-03 07:16:30 +00:00
|
|
|
|
MaxCount: Settings.MaxResult,
|
2024-07-15 06:52:12 +00:00
|
|
|
|
IsFullPathSearch: Settings.EverythingSearchFullPath,
|
|
|
|
|
|
IsRunCounterEnabled: Settings.EverythingEnableRunCount);
|
2022-05-15 20:15:56 +00:00
|
|
|
|
|
2022-11-25 19:25:12 +00:00
|
|
|
|
await foreach (var result in EverythingApi.SearchAsync(option, token))
|
|
|
|
|
|
{
|
|
|
|
|
|
yield return result;
|
|
|
|
|
|
}
|
2022-03-25 21:19:00 +00:00
|
|
|
|
}
|
2023-03-08 11:31:51 +00:00
|
|
|
|
|
2022-11-25 19:25:12 +00:00
|
|
|
|
public async IAsyncEnumerable<SearchResult> EnumerateAsync(string path, string search, bool recursive, [EnumeratorCancellation] CancellationToken token)
|
2022-03-28 20:28:18 +00:00
|
|
|
|
{
|
2022-11-25 19:25:12 +00:00
|
|
|
|
await ThrowIfEverythingNotAvailableAsync(token);
|
2023-02-11 16:35:26 +00:00
|
|
|
|
|
2022-11-25 19:25:12 +00:00
|
|
|
|
if (token.IsCancellationRequested)
|
|
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
|
|
|
|
var option = new EverythingSearchOption(search,
|
|
|
|
|
|
Settings.SortOption,
|
|
|
|
|
|
ParentPath: path,
|
2023-02-11 16:35:26 +00:00
|
|
|
|
IsRecursive: recursive,
|
2024-08-03 07:16:30 +00:00
|
|
|
|
MaxCount: Settings.MaxResult,
|
2024-07-15 06:52:12 +00:00
|
|
|
|
IsFullPathSearch: Settings.EverythingSearchFullPath,
|
|
|
|
|
|
IsRunCounterEnabled: Settings.EverythingEnableRunCount);
|
2022-11-25 19:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
await foreach (var result in EverythingApi.SearchAsync(option, token))
|
|
|
|
|
|
yield return result;
|
2022-03-28 20:28:18 +00:00
|
|
|
|
}
|
2022-03-25 21:19:00 +00:00
|
|
|
|
}
|
2022-09-10 15:45:41 +00:00
|
|
|
|
}
|