From b426dd10d1b1b6b60d4c40b85fbdc8444675d708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Fri, 22 Jan 2021 16:19:03 +0800 Subject: [PATCH 1/8] Rewrite LocationPathString match --- .../SharedCommands/FilesFolders.cs | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs index 27cd1a5584e..a185b2a1c00 100644 --- a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs +++ b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Text.RegularExpressions; using System.Windows; namespace Flow.Launcher.Plugin.SharedCommands @@ -142,35 +143,28 @@ public static void OpenContainingFolder(string path) Process.Start(FileExplorerProgramEXE, $" /select,\"{path}\""); } + /// /// This checks whether a given string is a directory path or network location string. /// It does not check if location actually exists. /// public static bool IsLocationPathString(string querySearchString) { - if (string.IsNullOrEmpty(querySearchString)) + if (string.IsNullOrEmpty(querySearchString) || querySearchString.Length < 3) return false; // // shared folder location, and not \\\location\ - if (querySearchString.Length >= 3 - && querySearchString.StartsWith(@"\\") - && char.IsLetter(querySearchString[2])) + if (querySearchString.StartsWith(@"\\") + && querySearchString[2] != '\\') return true; // c:\ - if (querySearchString.Length == 3 - && char.IsLetter(querySearchString[0]) + if (char.IsLetter(querySearchString[0]) && querySearchString[1] == ':' && querySearchString[2] == '\\') - return true; - - // c:\\ - if (querySearchString.Length >= 4 - && char.IsLetter(querySearchString[0]) - && querySearchString[1] == ':' - && querySearchString[2] == '\\' - && char.IsLetter(querySearchString[3])) - return true; + { + return querySearchString.Length == 3 || querySearchString[3] != '\\'; + } return false; } From 3effb401b7c0124ea9628e1a2c7d7d6b22343d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Fri, 22 Jan 2021 16:22:52 +0800 Subject: [PATCH 2/8] make it become an extension method --- Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs | 2 +- Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs index a185b2a1c00..98beba98732 100644 --- a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs +++ b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs @@ -148,7 +148,7 @@ public static void OpenContainingFolder(string path) /// This checks whether a given string is a directory path or network location string. /// It does not check if location actually exists. /// - public static bool IsLocationPathString(string querySearchString) + public static bool IsLocationPathString(this string querySearchString) { if (string.IsNullOrEmpty(querySearchString) || querySearchString.Length < 3) return false; diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 6b3a969122a..452d16105c0 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -58,7 +58,7 @@ internal async Task> SearchAsync(Query query, CancellationToken tok // Query is a location path with a full environment variable, eg. %appdata%\somefolder\ var isEnvironmentVariablePath = querySearch[1..].Contains("%\\"); - if (!FilesFolders.IsLocationPathString(querySearch) && !isEnvironmentVariablePath) + if (!querySearch.IsLocationPathString() && !isEnvironmentVariablePath) { results.AddRange(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false)); @@ -70,7 +70,7 @@ internal async Task> SearchAsync(Query query, CancellationToken tok if (isEnvironmentVariablePath) locationPath = EnvironmentVariables.TranslateEnvironmentVariablePath(locationPath); - if (!FilesFolders.LocationExists(FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath))) + if (!FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath).IsLocationPathString()) return results; var useIndexSearch = UseWindowsIndexForDirectorySearch(locationPath); From 19d23afbfc3224d85a5b339c37681a93c55eb859 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 24 Jan 2021 20:51:56 +1100 Subject: [PATCH 3/8] add test for when using wildcard directory search --- Flow.Launcher.Test/Plugins/ExplorerTest.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Flow.Launcher.Test/Plugins/ExplorerTest.cs b/Flow.Launcher.Test/Plugins/ExplorerTest.cs index 09c7d9a30df..c84380c8e08 100644 --- a/Flow.Launcher.Test/Plugins/ExplorerTest.cs +++ b/Flow.Launcher.Test/Plugins/ExplorerTest.cs @@ -243,6 +243,9 @@ public void GivenQuery_WhenActionKeywordForFileContentSearchExists_ThenFileConte [TestCase(@"cc:\", false)] [TestCase(@"\\\SomeNetworkLocation\", false)] [TestCase("RandomFile", false)] + [TestCase(@"c:\>*", true)] + [TestCase(@"c:\>", true)] + [TestCase(@"c:\SomeLocation\SomeOtherLocation\>", true)] public void WhenGivenQuerySearchString_ThenShouldIndicateIfIsLocationPathString(string querySearchString, bool expectedResult) { // When, Given From d583078a673e555347cb75a1f729927d6e2918cc Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 24 Jan 2021 20:52:39 +1100 Subject: [PATCH 4/8] version bump Explorer --- Plugins/Flow.Launcher.Plugin.Explorer/plugin.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json index 8c7adb3a423..76fd36bb5d9 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json @@ -7,7 +7,7 @@ "Name": "Explorer", "Description": "Search and manage files and folders. Explorer utilises Windows Index Search", "Author": "Jeremy Wu", - "Version": "1.4.0", + "Version": "1.4.1", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Explorer.dll", From 51c7b693c0d4c2b4c16d5fd4f5ff810c2492a733 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 24 Jan 2021 21:01:29 +1100 Subject: [PATCH 5/8] fix formatting --- Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs index 98beba98732..369be036459 100644 --- a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs +++ b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs @@ -1,8 +1,6 @@ using System; using System.Diagnostics; using System.IO; -using System.Text.RegularExpressions; -using System.Windows; namespace Flow.Launcher.Plugin.SharedCommands { @@ -143,7 +141,6 @@ public static void OpenContainingFolder(string path) Process.Start(FileExplorerProgramEXE, $" /select,\"{path}\""); } - /// /// This checks whether a given string is a directory path or network location string. /// It does not check if location actually exists. From e9462e8994c5cf06ebf3929710855497b180d33b Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 24 Jan 2021 21:05:39 +1100 Subject: [PATCH 6/8] revert change from check string is path back to check location exists --- Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 452d16105c0..b7174e5ef38 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -70,7 +70,7 @@ internal async Task> SearchAsync(Query query, CancellationToken tok if (isEnvironmentVariablePath) locationPath = EnvironmentVariables.TranslateEnvironmentVariablePath(locationPath); - if (!FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath).IsLocationPathString()) + if (!FilesFolders.LocationExists(FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath))) return results; var useIndexSearch = UseWindowsIndexForDirectorySearch(locationPath); From bfa1aabe35525db30ef00e1a30769d549c3abbbd Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 24 Jan 2021 21:08:48 +1100 Subject: [PATCH 7/8] add comment explaining why location check is needed --- Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index b7174e5ef38..912c5f42896 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -70,6 +70,7 @@ internal async Task> SearchAsync(Query query, CancellationToken tok if (isEnvironmentVariablePath) locationPath = EnvironmentVariables.TranslateEnvironmentVariablePath(locationPath); + // Check that actual location exists, otherwise directory search will throw directory not found exception if (!FilesFolders.LocationExists(FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath))) return results; From 2968a59b4281bcb77f9164ce721949c545fcdf34 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 24 Jan 2021 21:15:30 +1100 Subject: [PATCH 8/8] revert unintended deletion --- Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs index 369be036459..37222a1d0b7 100644 --- a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs +++ b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Windows; namespace Flow.Launcher.Plugin.SharedCommands {