From fdffe20c0bb0613942469dbffa3ea3013586383b Mon Sep 17 00:00:00 2001 From: Alekhya Date: Thu, 29 Oct 2020 10:38:15 -0700 Subject: [PATCH] Display Drive detection warning only for multiple drives (#7589) * indexer drive detection helper code to not show the warning for a single drive * removed interface from the namespace due to stylecop * removed interfac which no longer exists * filter out only fixed drives in the system and ignore the removable drives * changed text to not all files are indexed, from not all drives are idnexed * add additional info in the comment --- .../DriveDetection/DriveInfoWrapper.cs | 22 +++++++++++++++++++ .../DriveDetection/IndexerDriveDetection.cs | 11 +++++++--- .../Interface/IDriveInfoWrapper.cs | 11 ++++++++++ .../Plugins/Microsoft.Plugin.Indexer/Main.cs | 2 +- .../Properties/Resources.Designer.cs | 2 +- .../Properties/Resources.resx | 2 +- .../Wox.Test/Plugins/WindowsIndexerTest.cs | 16 +++++++++----- 7 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/DriveDetection/DriveInfoWrapper.cs create mode 100644 src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Interface/IDriveInfoWrapper.cs diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/DriveDetection/DriveInfoWrapper.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/DriveDetection/DriveInfoWrapper.cs new file mode 100644 index 0000000000..9e0768b980 --- /dev/null +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/DriveDetection/DriveInfoWrapper.cs @@ -0,0 +1,22 @@ +// 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.IO; +using System.Linq; + +namespace Microsoft.Plugin.Indexer.DriveDetection +{ + public class DriveInfoWrapper : IDriveInfoWrapper + { + private static readonly int DriveCount = GetDriveInfo(); + + private static int GetDriveInfo() + { + // To ignore removable type drives, CD ROMS, no root partitions which may not be formatted and only return the fixed drives in the system. + return DriveInfo.GetDrives().Where(d => d.DriveType == DriveType.Fixed).Count(); + } + + public int GetDriveCount() => DriveCount; + } +} 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 9bf2eed7b5..a7002c2111 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/DriveDetection/IndexerDriveDetection.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/DriveDetection/IndexerDriveDetection.cs @@ -10,18 +10,23 @@ namespace Microsoft.Plugin.Indexer.DriveDetection private readonly IRegistryWrapper _registryHelper; + private readonly IDriveInfoWrapper _driveHelper; + public bool IsDriveDetectionWarningCheckBoxSelected { get; set; } - public IndexerDriveDetection(IRegistryWrapper registryHelper) + public IndexerDriveDetection(IRegistryWrapper registryHelper, IDriveInfoWrapper driveHelper) { _registryHelper = registryHelper; + _driveHelper = driveHelper; GetEnhancedModeStatus(); } - // To display the warning when Enhanced mode is disabled and the Disable Drive detection check box in settings is unchecked + // To display the drive detection warning only when enhanced mode is disabled on a system which has multiple drives. + // Currently the warning would not be displayed if the enhanced mode is disabled when the user system has only a single fixed drive. However, this warning may be added in the future. + // This warning can be disabled by checking the disabled drive detection warning checkbox in settings. public bool DisplayWarning() { - return !(IsDriveDetectionWarningCheckBoxSelected || IsEnhancedModeEnabled); + return !(IsDriveDetectionWarningCheckBoxSelected || IsEnhancedModeEnabled || (_driveHelper.GetDriveCount() == 1)); } // To look up the registry entry for enhanced search diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Interface/IDriveInfoWrapper.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Interface/IDriveInfoWrapper.cs new file mode 100644 index 0000000000..786a5d7efb --- /dev/null +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Interface/IDriveInfoWrapper.cs @@ -0,0 +1,11 @@ +// 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 Microsoft.Plugin.Indexer +{ + public interface IDriveInfoWrapper + { + int GetDriveCount(); + } +} diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs index 9fadb5a1c3..4b85bb2bb6 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Main.cs @@ -38,7 +38,7 @@ namespace Microsoft.Plugin.Indexer private readonly WindowsSearchAPI _api = new WindowsSearchAPI(_search); // To obtain information regarding the drives that are indexed - private readonly IndexerDriveDetection _driveDetection = new IndexerDriveDetection(new RegistryWrapper()); + private readonly IndexerDriveDetection _driveDetection = new IndexerDriveDetection(new RegistryWrapper(), new DriveInfoWrapper()); // Reserved keywords in oleDB private readonly string reservedStringPattern = @"^[\/\\\$\%]+$|^.*[<>].*$"; diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Properties/Resources.Designer.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Properties/Resources.Designer.cs index b25772fc31..ce29d12cb2 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Properties/Resources.Designer.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Properties/Resources.Designer.cs @@ -88,7 +88,7 @@ namespace Microsoft.Plugin.Indexer.Properties { } /// - /// Looks up a localized string similar to Warning: Not all drives are indexed.. + /// Looks up a localized string similar to Warning: Not all files are indexed.. /// public static string Microsoft_plugin_indexer_drivedetectionwarning { get { diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Properties/Resources.resx b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Properties/Resources.resx index 9efd728a0d..dfa4703b16 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Properties/Resources.resx +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Properties/Resources.resx @@ -136,7 +136,7 @@ Path - Warning: Not all drives are indexed. + Warning: Not all files are indexed. Click to go to Windows Search settings to fix. diff --git a/src/modules/launcher/Wox.Test/Plugins/WindowsIndexerTest.cs b/src/modules/launcher/Wox.Test/Plugins/WindowsIndexerTest.cs index a88383b620..8d9a2b5155 100644 --- a/src/modules/launcher/Wox.Test/Plugins/WindowsIndexerTest.cs +++ b/src/modules/launcher/Wox.Test/Plugins/WindowsIndexerTest.cs @@ -348,17 +348,21 @@ namespace Wox.Test.Plugins Assert.AreEqual(Microsoft.Plugin.Indexer.Properties.Resources.Microsoft_plugin_indexer_open_in_console, contextMenuItems[1].Title); } - [TestCase(0, false, ExpectedResult = true)] - [TestCase(0, true, ExpectedResult = false)] - [TestCase(1, false, ExpectedResult = false)] - [TestCase(1, true, ExpectedResult = false)] - public bool DriveDetectionMustDisplayWarningWhenEnhancedModeIsOffAndWhenWarningIsNotDisabled(int enhancedModeStatus, bool disableWarningCheckBoxStatus) + [TestCase(0, 2, false, ExpectedResult = true)] + [TestCase(0, 3, true, ExpectedResult = false)] + [TestCase(1, 2, false, ExpectedResult = false)] + [TestCase(1, 4, true, ExpectedResult = false)] + [TestCase(0, 1, false, ExpectedResult = false)] + public bool DriveDetectionMustDisplayWarningWhenEnhancedModeIsOffAndWhenWarningIsNotDisabled(int enhancedModeStatus, int driveCount, bool disableWarningCheckBoxStatus) { // Arrange var mockRegistry = new Mock(); mockRegistry.Setup(r => r.GetHKLMRegistryValue(It.IsAny(), It.IsAny())).Returns(enhancedModeStatus); // Enhanced mode is disabled - IndexerDriveDetection driveDetection = new IndexerDriveDetection(mockRegistry.Object); + var mockDriveInfo = new Mock(); + mockDriveInfo.Setup(d => d.GetDriveCount()).Returns(driveCount); + + IndexerDriveDetection driveDetection = new IndexerDriveDetection(mockRegistry.Object, mockDriveInfo.Object); driveDetection.IsDriveDetectionWarningCheckBoxSelected = disableWarningCheckBoxStatus; // Act & Assert