Skip to content

Commit

Permalink
Display Drive detection warning only for multiple drives (#7589)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alekhyareddy28 committed Oct 29, 2020
1 parent e30393e commit fdffe20
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ public class IndexerDriveDetection

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
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class Main : ISettingProvider, IPlugin, ISavable, IPluginI18n, IContext
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 = @"^[\/\\\$\%]+$|^.*[<>].*$";
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
<value>Path</value>
</data>
<data name="Microsoft_plugin_indexer_drivedetectionwarning" xml:space="preserve">
<value>Warning: Not all drives are indexed.</value>
<value>Warning: Not all files are indexed.</value>
</data>
<data name="Microsoft_plugin_indexer_disable_warning_in_settings" xml:space="preserve">
<value>Click to go to Windows Search settings to fix.</value>
Expand Down
16 changes: 10 additions & 6 deletions src/modules/launcher/Wox.Test/Plugins/WindowsIndexerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,21 @@ public void LoadContextMenusMustNotLoadRunAsAdminAndOpenContainingFolderForFolde
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<IRegistryWrapper>();
mockRegistry.Setup(r => r.GetHKLMRegistryValue(It.IsAny<string>(), It.IsAny<string>())).Returns(enhancedModeStatus); // Enhanced mode is disabled

IndexerDriveDetection driveDetection = new IndexerDriveDetection(mockRegistry.Object);
var mockDriveInfo = new Mock<IDriveInfoWrapper>();
mockDriveInfo.Setup(d => d.GetDriveCount()).Returns(driveCount);

IndexerDriveDetection driveDetection = new IndexerDriveDetection(mockRegistry.Object, mockDriveInfo.Object);
driveDetection.IsDriveDetectionWarningCheckBoxSelected = disableWarningCheckBoxStatus;

// Act & Assert
Expand Down

0 comments on commit fdffe20

Please sign in to comment.