Skip to content

Commit

Permalink
Fallback to user and machine PATH variables (#67)
Browse files Browse the repository at this point in the history
If the PATH variable changes during the execution of UET (such as a program being installed and adding itself to the PATH), this ensures that the path resolver can find the new binaries.
  • Loading branch information
hach-que authored Dec 1, 2024
1 parent d1faa24 commit 89d7f13
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions UET/Redpoint.PathResolution/DefaultPathResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@ internal class DefaultPathResolver : IPathResolver
{
public Task<string> ResolveBinaryPath(string binaryName)
{
var paths = (Environment.GetEnvironmentVariable("PATH") ?? string.Empty).Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries);
var pathExts = OperatingSystem.IsWindows() ? (Environment.GetEnvironmentVariable("PATHEXT") ?? string.Empty).Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries) : Array.Empty<string>();

foreach (var path in paths)
EnvironmentVariableTarget[] targets = OperatingSystem.IsWindows()
? [EnvironmentVariableTarget.Process, EnvironmentVariableTarget.User, EnvironmentVariableTarget.Machine]
: [EnvironmentVariableTarget.Process];
foreach (var target in targets)
{
if (pathExts.Length > 0)
var paths = (Environment.GetEnvironmentVariable("PATH") ?? string.Empty).Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries);
var pathExts = OperatingSystem.IsWindows() ? (Environment.GetEnvironmentVariable("PATHEXT") ?? string.Empty).Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries) : [];

foreach (var path in paths)
{
foreach (var pathExt in pathExts)
if (pathExts.Length > 0)
{
if (File.Exists(Path.Combine(path, $"{binaryName}{pathExt}")))
foreach (var pathExt in pathExts)
{
return Task.FromResult(Path.Combine(path, $"{binaryName}{pathExt}"));
if (File.Exists(Path.Combine(path, $"{binaryName}{pathExt}")))
{
return Task.FromResult(Path.Combine(path, $"{binaryName}{pathExt}"));
}
}
}
}
else
{
if (File.Exists(Path.Combine(path, binaryName)))
else
{
return Task.FromResult(Path.Combine(path, binaryName));
if (File.Exists(Path.Combine(path, binaryName)))
{
return Task.FromResult(Path.Combine(path, binaryName));
}
}
}
}
Expand Down

0 comments on commit 89d7f13

Please sign in to comment.