diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/DriveDetection/IndexerDriveDetection.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/DriveDetection/IndexerDriveDetection.cs index 56710babf..06bb7abe1 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/DriveDetection/IndexerDriveDetection.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/DriveDetection/IndexerDriveDetection.cs @@ -18,10 +18,10 @@ namespace Microsoft.Plugin.Indexer.DriveDetection GetEnhancedModeStatus(); } - // To display the results if either enhanced mode is on or if the disable drive detection checkbox is checked - public bool DisplayResults() + // To display the warning when Enhanced mode is disabled and the Disable Drive detection check box in settings is unchecked + public bool DisplayWarning() { - return IsDriveDetectionWarningCheckBoxSelected || IsEnhancedModeEnabled; + return !(IsDriveDetectionWarningCheckBoxSelected || IsEnhancedModeEnabled); } // To look up the registry entry for diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs index c589cf694..a715e6f34 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs @@ -52,102 +52,100 @@ namespace Microsoft.Plugin.Indexer { var results = new List(); - if (_driveDetection.DisplayResults()) + if (!string.IsNullOrEmpty(query.Search)) { - if (!string.IsNullOrEmpty(query.Search)) + var searchQuery = query.Search; + if (_settings.MaxSearchCount <= 0) { - var searchQuery = query.Search; - if (_settings.MaxSearchCount <= 0) - { - _settings.MaxSearchCount = 50; - } + _settings.MaxSearchCount = 50; + } - var regexMatch = Regex.Match(searchQuery, ReservedStringPattern); + var regexMatch = Regex.Match(searchQuery, ReservedStringPattern); - if (!regexMatch.Success) + if (!regexMatch.Success) + { + try { - try + if(_driveDetection.DisplayWarning()) { - var searchResultsList = _api.Search(searchQuery, maxCount: _settings.MaxSearchCount).ToList(); - foreach (var searchResult in searchResultsList) + results.Add(new Result { - var path = searchResult.Path; - var toolTipTitle = string.Format("{0} : {1}", _context.API.GetTranslation("Microsoft_plugin_indexer_name"), searchResult.Title); - var toolTipText = string.Format("{0} : {1}", _context.API.GetTranslation("Microsoft_plugin_indexer_path"), path); - string workingDir = null; - if (_settings.UseLocationAsWorkingDir) - workingDir = Path.GetDirectoryName(path); - - Result r = new Result(); - r.Title = searchResult.Title; - r.SubTitle = "Search: " + path; - r.IcoPath = path; - r.ToolTipData = new ToolTipData(toolTipTitle, toolTipText); - r.Action = c => + Title = _context.API.GetTranslation("Microsoft_plugin_indexer_drivedetectionwarning"), + SubTitle = _context.API.GetTranslation("Microsoft_plugin_indexer_disable_warning_in_settings"), + IcoPath = WarningIconPath, + Action = e => { - bool hide; try { - Process.Start(new ProcessStartInfo - { - FileName = path, - UseShellExecute = true, - WorkingDirectory = workingDir - }); - hide = true; + Process.Start(GetWindowsSearchSettingsProcessInfo()); } - catch (Win32Exception) + catch (Exception ex) { - var name = $"Plugin: {_context.CurrentPluginMetadata.Name}"; - var msg = "Can't Open this file"; - _context.API.ShowMsg(name, msg, string.Empty); - hide = false; + Log.Exception("Microsoft.Plugin.Indexer", $"Unable to launch Windows Search Settings: {ex.Message}", ex, "Query"); } - return hide; - }; - r.ContextData = searchResult; - - //If the result is a directory, then it's display should show a directory. - if (Directory.Exists(path)) - { - r.QueryTextDisplay = path; + return true; } + }); + } - results.Add(r); + var searchResultsList = _api.Search(searchQuery, maxCount: _settings.MaxSearchCount).ToList(); + foreach (var searchResult in searchResultsList) + { + var path = searchResult.Path; + var toolTipTitle = string.Format("{0} : {1}", _context.API.GetTranslation("Microsoft_plugin_indexer_name"), searchResult.Title); + var toolTipText = string.Format("{0} : {1}", _context.API.GetTranslation("Microsoft_plugin_indexer_path"), path); + string workingDir = null; + if (_settings.UseLocationAsWorkingDir) + workingDir = Path.GetDirectoryName(path); + + Result r = new Result(); + r.Title = searchResult.Title; + r.SubTitle = "Search: " + path; + r.IcoPath = path; + r.ToolTipData = new ToolTipData(toolTipTitle, toolTipText); + r.Action = c => + { + bool hide; + try + { + Process.Start(new ProcessStartInfo + { + FileName = path, + UseShellExecute = true, + WorkingDirectory = workingDir + }); + hide = true; + } + catch (Win32Exception) + { + var name = $"Plugin: {_context.CurrentPluginMetadata.Name}"; + var msg = "Can't Open this file"; + _context.API.ShowMsg(name, msg, string.Empty); + hide = false; + } + return hide; + }; + r.ContextData = searchResult; + + //If the result is a directory, then it's display should show a directory. + if (Directory.Exists(path)) + { + r.QueryTextDisplay = path; } - } - catch (InvalidOperationException) - { - //The connection has closed, internal error of ExecuteReader() - //Not showing this exception to the users - } - catch (Exception ex) - { - Log.Info(ex.ToString()); + + results.Add(r); } } - } - } - else - { - results.Add(new Result - { - Title = _context.API.GetTranslation("Microsoft_plugin_indexer_drivedetectionwarning"), - SubTitle = _context.API.GetTranslation("Microsoft_plugin_indexer_disable_warning_in_settings"), - IcoPath = WarningIconPath, - Action = e => + catch (InvalidOperationException) { - try - { - Process.Start(GetWindowsSearchSettingsProcessInfo()); - } - catch (Exception ex) - { - Log.Exception("Microsoft.Plugin.Indexer", $"Unable to launch Windows Search Settings: {ex.Message}", ex, "Query"); - } - return true; + //The connection has closed, internal error of ExecuteReader() + //Not showing this exception to the users } - }); + catch (Exception ex) + { + Log.Info(ex.ToString()); + } + } } return results; diff --git a/src/modules/launcher/Wox.Test/Plugins/WindowsIndexerTest.cs b/src/modules/launcher/Wox.Test/Plugins/WindowsIndexerTest.cs index d94368661..6fab74925 100644 --- a/src/modules/launcher/Wox.Test/Plugins/WindowsIndexerTest.cs +++ b/src/modules/launcher/Wox.Test/Plugins/WindowsIndexerTest.cs @@ -299,11 +299,11 @@ namespace Wox.Test.Plugins mockapi.Verify(m => m.GetTranslation("Microsoft_plugin_indexer_open_in_console"), Times.Once()); } - [TestCase(0, false, ExpectedResult = false)] - [TestCase(0, true, ExpectedResult = true)] - [TestCase(1, false, ExpectedResult = true)] - [TestCase(1, true, ExpectedResult = true)] - public bool DriveDetection_MustDisplayResults_WhenEnhancedModeIsOnOrWhenWarningIsDisabled(int enhancedModeStatus, bool disableWarningCheckBoxStatus) + [TestCase(0, false, ExpectedResult = true)] + [TestCase(0, true, ExpectedResult = false)] + [TestCase(1, false, ExpectedResult = false)] + [TestCase(1, true, ExpectedResult = false)] + public bool DriveDetection_MustDisplayWarning_WhenEnhancedModeIsOffAndWhenWarningIsNotDisabled(int enhancedModeStatus, bool disableWarningCheckBoxStatus) { // Arrange var mockRegistry = new Mock(); @@ -313,7 +313,7 @@ namespace Wox.Test.Plugins _driveDetection.IsDriveDetectionWarningCheckBoxSelected = disableWarningCheckBoxStatus; // Act & Assert - return _driveDetection.DisplayResults(); + return _driveDetection.DisplayWarning(); } }