From a66b4cd057c661d5ca43ee184d8f49f46c22b8b5 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Sun, 3 May 2020 15:57:32 +0200 Subject: [PATCH 1/4] New method to check for environment variable --- Plugins/Flow.Launcher.Plugin.Folder/Main.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Folder/Main.cs b/Plugins/Flow.Launcher.Plugin.Folder/Main.cs index dafd1a90e..663574c98 100644 --- a/Plugins/Flow.Launcher.Plugin.Folder/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Folder/Main.cs @@ -58,10 +58,12 @@ namespace Flow.Launcher.Plugin.Folder var results = GetUserFolderResults(query); string search = query.Search.ToLower(); - if (!IsDriveOrSharedFolder(search)) + if (!IsDriveOrSharedFolder(search) && !IsEnvironmentVariableSearch(search)) + { return results; + } - if (search.StartsWith("%")) + if (IsEnvironmentVariableSearch(search)) { results.AddRange(GetEnvironmentStringPathResults(search, query)); } @@ -79,6 +81,11 @@ namespace Flow.Launcher.Plugin.Folder return results; } + private static bool IsEnvironmentVariableSearch(string search) + { + return _envStringPaths != null && search.StartsWith("%"); + } + private static bool IsDriveOrSharedFolder(string search) { if (search.StartsWith(@"\\")) @@ -86,11 +93,6 @@ namespace Flow.Launcher.Plugin.Folder return true; } - if (_envStringPaths != null && search.StartsWith("%")) - { // environment string formatted folder - return true; - } - if (_driverNames != null && _driverNames.Any(search.StartsWith)) { // normal drive letter return true; From 31501a1a9e1f22070b475c49bbd1b6322fdab516 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Sun, 3 May 2020 16:01:38 +0200 Subject: [PATCH 2/4] Load environment variables from system --- Plugins/Flow.Launcher.Plugin.Folder/Main.cs | 22 ++++++--------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Folder/Main.cs b/Plugins/Flow.Launcher.Plugin.Folder/Main.cs index 663574c98..d8ad5d748 100644 --- a/Plugins/Flow.Launcher.Plugin.Folder/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Folder/Main.cs @@ -166,25 +166,15 @@ namespace Flow.Launcher.Plugin.Folder private void LoadEnvironmentStringPaths() { _envStringPaths = new Dictionary(); - - var specialPaths = - new Dictionary { - { "appdata", Environment.SpecialFolder.ApplicationData }, - { "localappdata", Environment.SpecialFolder.LocalApplicationData }, - { "programfiles", Environment.SpecialFolder.ProgramFiles }, - { "programfiles(x86)", Environment.SpecialFolder.ProgramFilesX86 }, - { "programdata", Environment.SpecialFolder.CommonApplicationData }, - { "userprofile", Environment.SpecialFolder.UserProfile } - }; - foreach (var special in specialPaths) + var specialPaths = System.Environment.GetEnvironmentVariables(); + foreach (DictionaryEntry special in specialPaths) { - _envStringPaths.Add(special.Key, Environment.GetFolderPath(special.Value)); + if (Directory.Exists(special.Value.ToString())) + { + _envStringPaths.Add(special.Key.ToString().ToLower(), special.Value.ToString()); + } } - - var tempDirectoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Temp"); - - _envStringPaths.Add("temp", tempDirectoryPath); } private static readonly char[] _specialSearchChars = new char[] From 64de0ceef33da28cf7297691247e54fa53dea48c Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Sun, 3 May 2020 16:02:31 +0200 Subject: [PATCH 3/4] Remove unused usings --- Plugins/Flow.Launcher.Plugin.Folder/Main.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Folder/Main.cs b/Plugins/Flow.Launcher.Plugin.Folder/Main.cs index d8ad5d748..4f6d26590 100644 --- a/Plugins/Flow.Launcher.Plugin.Folder/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Folder/Main.cs @@ -1,6 +1,6 @@ using System; +using System.Collections; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Windows; From cfdbd19d99f0ba78c6c69e63084dfe6192cee775 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Sun, 3 May 2020 18:05:01 +0200 Subject: [PATCH 4/4] Remove variable and use returned dictionary directly --- Plugins/Flow.Launcher.Plugin.Folder/Main.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Folder/Main.cs b/Plugins/Flow.Launcher.Plugin.Folder/Main.cs index 4f6d26590..7b44b110f 100644 --- a/Plugins/Flow.Launcher.Plugin.Folder/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Folder/Main.cs @@ -167,8 +167,7 @@ namespace Flow.Launcher.Plugin.Folder { _envStringPaths = new Dictionary(); - var specialPaths = System.Environment.GetEnvironmentVariables(); - foreach (DictionaryEntry special in specialPaths) + foreach (DictionaryEntry special in Environment.GetEnvironmentVariables()) { if (Directory.Exists(special.Value.ToString())) {