Skip to content

Commit

Permalink
Clean up previous PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Sep 18, 2024
1 parent 58718ef commit 0b30001
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions YoutubeDownloader.Core/Downloading/FFmpeg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,47 @@ static IEnumerable<string> GetProbeDirectoryPaths()
yield return AppContext.BaseDirectory;
yield return Directory.GetCurrentDirectory();

// User PATH environment variable
if (Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.User)?.Split(Path.PathSeparator) is { } userPaths)
// Process PATH
if (
Environment.GetEnvironmentVariable("PATH")?.Split(Path.PathSeparator) is
{ } processPaths
)
{
foreach (var path in userPaths)
foreach (var path in processPaths)
yield return path;
}

// System PATH environment variable
if (Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine)?.Split(Path.PathSeparator) is { } systemPaths)
// Registry-based PATH variables
if (OperatingSystem.IsWindows())
{
foreach (var path in systemPaths)
yield return path;
// User PATH
if (
Environment
.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.User)
?.Split(Path.PathSeparator) is
{ } userPaths
)
{
foreach (var path in userPaths)
yield return path;
}

// System PATH
if (
Environment
.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine)
?.Split(Path.PathSeparator) is
{ } systemPaths
)
{
foreach (var path in systemPaths)
yield return path;
}
}
}

return GetProbeDirectoryPaths()
.Distinct(StringComparer.Ordinal)
.Select(dirPath => Path.Combine(dirPath, CliFileName))
.FirstOrDefault(File.Exists);
}
Expand Down

0 comments on commit 0b30001

Please sign in to comment.