diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml index 2a0349ac8..6269c570a 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml @@ -26,6 +26,7 @@ Quick Access Links Everything Setting Sort Option: + Everything Path: Launch Hidden Editor Path Shell Path diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs index 3b6096e20..7eb48d0d2 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs @@ -35,11 +35,11 @@ namespace Flow.Launcher.Plugin.Explorer public Task InitAsync(PluginInitContext context) { Context = context; - + Settings = context.API.LoadSettingJsonStorage(); viewModel = new SettingsViewModel(context, Settings); - + // as at v1.7.0 this is to maintain backwards compatibility, need to be removed afterwards. if (Settings.QuickFolderAccessLinks.Any()) @@ -52,8 +52,18 @@ namespace Flow.Launcher.Plugin.Explorer searchManager = new SearchManager(Settings, Context); ResultManager.Init(Context, Settings); + if (Settings.EverythingEnabled) + { + _ = EverythingDownloadHelper.PromptDownloadIfNotInstallAsync(Settings.EverythingInstalledPath, context.API) + .ContinueWith(s => + { + if (s.IsCompletedSuccessfully) + Settings.EverythingInstalledPath = s.Result; + }, TaskScheduler.Default); + } + SortOptionTranslationHelper.API = context.API; - + EverythingApiDllImport.Load(Path.Combine(Context.CurrentPluginMetadata.PluginDirectory, "EverythingSDK", Environment.Is64BitProcess ? "Everything64.dll" : "Everything86.dll")); return Task.CompletedTask; @@ -79,4 +89,4 @@ namespace Flow.Launcher.Plugin.Explorer return Context.API.GetTranslation("plugin_explorer_plugin_description"); } } -} +} \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingDownloadHelper.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingDownloadHelper.cs new file mode 100644 index 000000000..75bbd2b79 --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingDownloadHelper.cs @@ -0,0 +1,99 @@ +using Droplex; +using Flow.Launcher.Plugin.SharedCommands; +using Microsoft.Win32; +using System; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace Flow.Launcher.Plugin.Explorer.Search.Everything; + +public class EverythingDownloadHelper +{ + public static async Task PromptDownloadIfNotInstallAsync(string installedLocation, IPublicAPI api) + { + if (installedLocation.FileExists()) + return installedLocation; + + if (!string.IsNullOrEmpty(installedLocation)) + return installedLocation; + + installedLocation = GetInstalledPath(); + + if (string.IsNullOrEmpty(installedLocation) && + System.Windows.Forms.MessageBox.Show( + string.Format(api.GetTranslation("flowlauncher_plugin_everything_installing_select"), Environment.NewLine), + api.GetTranslation("flowlauncher_plugin_everything_installing_title"), + System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) + { + // Solves single thread apartment (STA) mode requirement error when using OpenFileDialog + var t = new Thread(() => + { + var dlg = new System.Windows.Forms.OpenFileDialog + { + InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + }; + + var result = dlg.ShowDialog(); + if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrEmpty(dlg.FileName)) + installedLocation = dlg.FileName; + + }); + + // Run your code from a thread that joins the STA Thread + t.SetApartmentState(ApartmentState.STA); + t.Start(); + t.Join(); + } + + if (!string.IsNullOrEmpty(installedLocation)) + { + return installedLocation; + } + + api.ShowMsg(api.GetTranslation("flowlauncher_plugin_everything_installing_title"), + api.GetTranslation("flowlauncher_plugin_everything_installing_subtitle"), "", useMainWindowAsOwner: false); + + await DroplexPackage.Drop(App.Everything1_4_1_1009).ConfigureAwait(false); + + api.ShowMsg(api.GetTranslation("flowlauncher_plugin_everything_installing_title"), + api.GetTranslation("flowlauncher_plugin_everything_installationsuccess_subtitle"), "", useMainWindowAsOwner: false); + + installedLocation = "C:\\Program Files\\Everything\\Everything.exe"; + + FilesFolders.OpenPath(installedLocation); + + return installedLocation; + + } + + internal static string GetInstalledPath() + { + using var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); + if (key is not null) + { + foreach (var subKey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName))) + { + if (subKey?.GetValue("DisplayName") is not string displayName || !displayName.Contains("Everything")) + { + continue; + } + if (subKey.GetValue("UninstallString") is not string uninstallString) + { + continue; + } + + if (Path.GetDirectoryName(uninstallString) is not { } uninstallDirectory) + { + continue; + } + return Path.Combine(uninstallDirectory, "Everything.exe"); + } + } + + var scoopInstalledPath = Environment.ExpandEnvironmentVariables(@"%userprofile%\scoop\apps\everything\current\Everything.exe"); + return File.Exists(scoopInstalledPath) ? scoopInstalledPath : string.Empty; + + } +} \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs index c1e1ea8b9..0b2c8eea2 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs @@ -137,6 +137,10 @@ namespace Flow.Launcher.Plugin.Explorer public bool EnableEverythingContentSearch { get; set; } = false; + public bool EverythingEnabled => IndexSearchEngine==IndexSearchEngineOption.Everything || + PathEnumerationEngine == PathEnumerationEngineOption.Everything || + ContentSearchEngine == ContentIndexSearchEngineOption.Everything; + #endregion internal enum ActionKeyword diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs index 11aff92f4..5d6eca0ad 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs @@ -395,6 +395,16 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels } } + public string EverythingInstalledPath + { + get => Settings.EverythingInstalledPath; + set + { + Settings.EverythingInstalledPath = value; + OnPropertyChanged(); + } + } + #endregion diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml index f9e37c1c2..3905dffcc 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml @@ -1,5 +1,4 @@ - - - + + - + - - @@ -61,10 +69,10 @@ - + - @@ -74,56 +82,47 @@ - - - - - -