diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml index a989327be..031cb108b 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml @@ -10,6 +10,8 @@ Deletion successful Successfully deleted the {0} Assigning the global action keyword could bring up too many results during search. Please choose a specific action keyword + The required service for Windows Index Search does not appear to be running + To fix this, start the Windows Search service. Select here to remove this warning Delete diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 2aa389f89..c7b1b6180 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -12,13 +12,13 @@ namespace Flow.Launcher.Plugin.Explorer.Search { public class SearchManager { - private readonly PluginInitContext context; + internal static PluginInitContext Context; private readonly Settings settings; public SearchManager(Settings settings, PluginInitContext context) { - this.context = context; + Context = context; this.settings = settings; } @@ -99,7 +99,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search var isEnvironmentVariable = EnvironmentVariables.IsEnvironmentVariableSearch(querySearch); if (isEnvironmentVariable) - return EnvironmentVariables.GetEnvironmentStringPathSuggestions(querySearch, query, context); + return EnvironmentVariables.GetEnvironmentStringPathSuggestions(querySearch, query, Context); // Query is a location path with a full environment variable, eg. %appdata%\somefolder\ var isEnvironmentVariablePath = querySearch[1..].Contains("%\\"); @@ -141,8 +141,9 @@ namespace Flow.Launcher.Plugin.Explorer.Search if (string.IsNullOrEmpty(querySearchString)) return new List(); - return await IndexSearch.WindowsIndexSearchAsync(querySearchString, - queryConstructor.CreateQueryHelper().ConnectionString, + return await IndexSearch.WindowsIndexSearchAsync( + querySearchString, + queryConstructor.CreateQueryHelper, queryConstructor.QueryForFileContentSearch, settings.IndexSearchExcludedSubdirectoryPaths, query, @@ -178,8 +179,9 @@ namespace Flow.Launcher.Plugin.Explorer.Search { var queryConstructor = new QueryConstructor(settings); - return await IndexSearch.WindowsIndexSearchAsync(querySearchString, - queryConstructor.CreateQueryHelper().ConnectionString, + return await IndexSearch.WindowsIndexSearchAsync( + querySearchString, + queryConstructor.CreateQueryHelper, queryConstructor.QueryForAllFilesAndFolders, settings.IndexSearchExcludedSubdirectoryPaths, query, @@ -192,7 +194,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search var queryConstructor = new QueryConstructor(settings); return await IndexSearch.WindowsIndexSearchAsync(path, - queryConstructor.CreateQueryHelper().ConnectionString, + queryConstructor.CreateQueryHelper, queryConstructor.QueryForTopLevelDirectorySearch, settings.IndexSearchExcludedSubdirectoryPaths, query, diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs index cfb564924..c22b489e2 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs @@ -1,10 +1,9 @@ -using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks; using Microsoft.Search.Interop; using System; using System.Collections.Generic; using System.Data.OleDb; -using System.Linq; +using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -84,7 +83,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex return results; } - internal async static Task> WindowsIndexSearchAsync(string searchString, string connectionString, + internal async static Task> WindowsIndexSearchAsync(string searchString, + Func queryHelper, Func constructQuery, List exclusionList, Query query, @@ -94,12 +94,29 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex if (regexMatch.Success) return new List(); + + try + { + var constructedQuery = constructQuery(searchString); - var constructedQuery = constructQuery(searchString); - return RemoveResultsInExclusionList( - await ExecuteWindowsIndexSearchAsync(constructedQuery, connectionString, query, token).ConfigureAwait(false), + return RemoveResultsInExclusionList( + await ExecuteWindowsIndexSearchAsync(constructedQuery, queryHelper().ConnectionString, query, token).ConfigureAwait(false), exclusionList, token); + } + catch (COMException) + { + // Occurs because the Windows Indexing (WSearch) is turned off in services and unable to be used by Explorer plugin + return new List + { + new Result + { + Title = SearchManager.Context.API.GetTranslation("plugin_explorer_windowsSearchServiceNotRunning"), + SubTitle = SearchManager.Context.API.GetTranslation("plugin_explorer_windowsSearchServiceFix"), + IcoPath = Constants.ExplorerIconImagePath + } + }; + } } private static List RemoveResultsInExclusionList(List results, List exclusionList, CancellationToken token) @@ -137,9 +154,17 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex internal static bool PathIsIndexed(string path) { - var csm = new CSearchManager(); - var indexManager = csm.GetCatalog("SystemIndex").GetCrawlScopeManager(); - return indexManager.IncludedInCrawlScope(path) > 0; + try + { + var csm = new CSearchManager(); + var indexManager = csm.GetCatalog("SystemIndex").GetCrawlScopeManager(); + return indexManager.IncludedInCrawlScope(path) > 0; + } + catch(COMException) + { + // Occurs because the Windows Indexing (WSearch) is turned off in services and unable to be used by Explorer plugin + return false; + } } private static void LogException(string message, Exception e)