From 0c53d76fec4db7248ebaa577b6e0c8a200a1fcb5 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 28 May 2020 21:33:18 +1000 Subject: [PATCH] fix TopLevelDirectory search activation --- .../SharedCommands/FilesFolders.cs | 18 ++++++++++++++++++ Flow.Launcher.Test/Plugins/ExplorerTest.cs | 13 +++++++++++++ .../DirectoryInfo/DirectoryInfoSearch.cs | 15 +++------------ .../Search/SearchManager.cs | 2 ++ 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs index a81ff8008..c41eddceb 100644 --- a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs +++ b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs @@ -185,5 +185,23 @@ namespace Flow.Launcher.Plugin.SharedCommands return previousDirectoryPath; } + + /// + /// Gets the previous level directory from a path string. + /// Does not check that previous level directory exists and returns + /// passed in string if is complete path + /// + public static string GetPreviousLevelDirectoryIfPathIncomplete(string path) + { + if (!path.EndsWith("\\")) + { + // not full path, get previous level directory string + var indexOfSeparator = path.LastIndexOf('\\'); + + return path.Substring(0, indexOfSeparator + 1); + } + + return path; + } } } diff --git a/Flow.Launcher.Test/Plugins/ExplorerTest.cs b/Flow.Launcher.Test/Plugins/ExplorerTest.cs index 508468ea1..7f049fe3e 100644 --- a/Flow.Launcher.Test/Plugins/ExplorerTest.cs +++ b/Flow.Launcher.Test/Plugins/ExplorerTest.cs @@ -228,6 +228,19 @@ namespace Flow.Launcher.Test.Plugins $"Actual path string is {previousDirectoryPath} {Environment.NewLine}"); } + [TestCase(@"C:\NonExistentFolder\SomeApp", @"C:\NonExistentFolder\")] + [TestCase(@"C:\NonExistentFolder\SomeApp\", @"C:\NonExistentFolder\SomeApp\")] + public void WhenGivenAPath_ThenShouldReturnThePreviousDirectoryPathIfIncompleteOrOriginalString( + string path, string expectedString) + { + var returnedPath = FilesFolders.GetPreviousLevelDirectoryIfPathIncomplete(path); + + //Then + Assert.IsTrue(returnedPath == expectedString, + $"Expected path string: {expectedString} {Environment.NewLine} " + + $"Actual path string is {returnedPath} {Environment.NewLine}"); + } + [TestCase("c:\\SomeFolder\\>", "scope='file:c:\\SomeFolder'")] [TestCase("c:\\SomeFolder\\>SomeName", "(System.FileName LIKE 'SomeName%' " + "OR CONTAINS(System.FileName,'\"SomeName*\"',1033)) AND " + diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs index 4ed63b7c3..c535fef99 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs @@ -21,7 +21,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo { var criteria = ConstructSearchCriteria(search); - if (search.IndexOfAny(Constants.SpecialSearchChars) >= 0) + if (search.LastIndexOf('>') > search.LastIndexOf('\\')) return DirectorySearch(SearchOption.AllDirectories, query, search, criteria); return DirectorySearch(SearchOption.TopDirectoryOnly, query, search, criteria); @@ -33,12 +33,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo if (!search.EndsWith("\\")) { - // not full path, get previous level directory string var indexOfSeparator = search.LastIndexOf('\\'); incompleteName = search.Substring(indexOfSeparator + 1).ToLower(); - if (incompleteName.StartsWith(">")) + if (incompleteName.StartsWith('>')) incompleteName = "*" + incompleteName.Substring(1); } @@ -51,15 +50,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo { var results = new List(); - var path = search; - - if (!search.EndsWith("\\")) - { - // not full path, get previous level directory string - var indexOfSeparator = search.LastIndexOf('\\'); - - path = search.Substring(0, indexOfSeparator + 1); - } + var path = FilesFolders.GetPreviousLevelDirectoryIfPathIncomplete(search); var folderList = new List(); var fileList = new List(); diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index f4d64157c..7bc038900 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -108,6 +108,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search private bool WindowsIndexExists(string path) { + path = FilesFolders.GetPreviousLevelDirectoryIfPathIncomplete(path); + return _indexSearch.PathIsIndexed(path); }