Skip to content

Commit 4d267fe

Browse files
Fix incorrect %homepath% parsing
Parse environment variables before checking path existence
1 parent 504fb4a commit 4d267fe

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,5 +261,15 @@ public static bool PathContains(string parentPath, string subPath, bool allowEqu
261261
&& !rel.StartsWith(@"..\")
262262
&& !Path.IsPathRooted(rel);
263263
}
264+
265+
/// <summary>
266+
/// Returns path ended with "\"
267+
/// </summary>
268+
/// <param name="path"></param>
269+
/// <returns></returns>
270+
public static string EnsureTrailingSlash(this string path)
271+
{
272+
return path.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
273+
}
264274
}
265275
}

Plugins/Flow.Launcher.Plugin.Explorer/Search/EnvironmentVariables.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.IO;
5-
using System.Text;
5+
using Flow.Launcher.Plugin.SharedCommands;
66

77
namespace Flow.Launcher.Plugin.Explorer.Search
88
{
@@ -37,20 +37,22 @@ internal static bool BeginsWithEnvironmentVar(string search)
3737
internal static Dictionary<string, string> LoadEnvironmentStringPaths()
3838
{
3939
var envStringPaths = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
40+
var homedrive = Environment.GetEnvironmentVariable("HOMEDRIVE")?.EnsureTrailingSlash() ?? "C:\\";
4041

4142
foreach (DictionaryEntry special in Environment.GetEnvironmentVariables())
4243
{
4344
var path = special.Value.ToString();
44-
if (Directory.Exists(path))
45-
{
46-
// we add a trailing slash to the path to make sure drive paths become valid absolute paths.
47-
// for example, if %systemdrive% is C: we turn it to C:\
48-
path = path.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
45+
// we add a trailing slash to the path to make sure drive paths become valid absolute paths.
46+
// for example, if %systemdrive% is C: we turn it to C:\
47+
path = path.EnsureTrailingSlash();
4948

50-
// if we don't have an absolute path, we use Path.GetFullPath to get one.
51-
// for example, if %homepath% is \Users\John we turn it to C:\Users\John
52-
path = Path.IsPathFullyQualified(path) ? path : Path.GetFullPath(path);
49+
// if we don't have an absolute path, we use Path.GetFullPath to get one.
50+
// for example, if %homepath% is \Users\John we turn it to C:\Users\John
51+
// Add basepath for GetFullPath() to parse %HOMEPATH% correctly
52+
path = Path.IsPathFullyQualified(path) ? path : Path.GetFullPath(path, homedrive);
5353

54+
if (Directory.Exists(path))
55+
{
5456
// Variables are returned with a mixture of all upper/lower case.
5557
// Call ToUpper() to make the results look consistent
5658
envStringPaths.Add(special.Key.ToString().ToUpper(), path);

0 commit comments

Comments
 (0)