Skip to content

Commit 8677421

Browse files
authored
Merge pull request #33 from Flow-Launcher/load-environment-variables-dynamically
Load environment variables from system
2 parents 484eb9c + cfdbd19 commit 8677421

File tree

1 file changed

+16
-25
lines changed
  • Plugins/Flow.Launcher.Plugin.Folder

1 file changed

+16
-25
lines changed

Plugins/Flow.Launcher.Plugin.Folder/Main.cs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
3-
using System.Diagnostics;
44
using System.IO;
55
using System.Linq;
66
using System.Windows;
@@ -58,10 +58,12 @@ public List<Result> Query(Query query)
5858
var results = GetUserFolderResults(query);
5959

6060
string search = query.Search.ToLower();
61-
if (!IsDriveOrSharedFolder(search))
61+
if (!IsDriveOrSharedFolder(search) && !IsEnvironmentVariableSearch(search))
62+
{
6263
return results;
64+
}
6365

64-
if (search.StartsWith("%"))
66+
if (IsEnvironmentVariableSearch(search))
6567
{
6668
results.AddRange(GetEnvironmentStringPathResults(search, query));
6769
}
@@ -79,18 +81,18 @@ public List<Result> Query(Query query)
7981
return results;
8082
}
8183

84+
private static bool IsEnvironmentVariableSearch(string search)
85+
{
86+
return _envStringPaths != null && search.StartsWith("%");
87+
}
88+
8289
private static bool IsDriveOrSharedFolder(string search)
8390
{
8491
if (search.StartsWith(@"\\"))
8592
{ // shared folder
8693
return true;
8794
}
8895

89-
if (_envStringPaths != null && search.StartsWith("%"))
90-
{ // environment string formatted folder
91-
return true;
92-
}
93-
9496
if (_driverNames != null && _driverNames.Any(search.StartsWith))
9597
{ // normal drive letter
9698
return true;
@@ -164,25 +166,14 @@ private void InitialDriverList()
164166
private void LoadEnvironmentStringPaths()
165167
{
166168
_envStringPaths = new Dictionary<string, string>();
167-
168-
var specialPaths =
169-
new Dictionary<string,Environment.SpecialFolder> {
170-
{ "appdata", Environment.SpecialFolder.ApplicationData },
171-
{ "localappdata", Environment.SpecialFolder.LocalApplicationData },
172-
{ "programfiles", Environment.SpecialFolder.ProgramFiles },
173-
{ "programfiles(x86)", Environment.SpecialFolder.ProgramFilesX86 },
174-
{ "programdata", Environment.SpecialFolder.CommonApplicationData },
175-
{ "userprofile", Environment.SpecialFolder.UserProfile }
176-
};
177-
178-
foreach (var special in specialPaths)
169+
170+
foreach (DictionaryEntry special in Environment.GetEnvironmentVariables())
179171
{
180-
_envStringPaths.Add(special.Key, Environment.GetFolderPath(special.Value));
172+
if (Directory.Exists(special.Value.ToString()))
173+
{
174+
_envStringPaths.Add(special.Key.ToString().ToLower(), special.Value.ToString());
175+
}
181176
}
182-
183-
var tempDirectoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Temp");
184-
185-
_envStringPaths.Add("temp", tempDirectoryPath);
186177
}
187178

188179
private static readonly char[] _specialSearchChars = new char[]

0 commit comments

Comments
 (0)