From 0b3000189f60dc69d20d316e436dc422d28d09f9 Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:49:25 +0300 Subject: [PATCH] Clean up previous PR --- YoutubeDownloader.Core/Downloading/FFmpeg.cs | 39 ++++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/YoutubeDownloader.Core/Downloading/FFmpeg.cs b/YoutubeDownloader.Core/Downloading/FFmpeg.cs index 1ae4828d0..759666f31 100644 --- a/YoutubeDownloader.Core/Downloading/FFmpeg.cs +++ b/YoutubeDownloader.Core/Downloading/FFmpeg.cs @@ -17,22 +17,47 @@ static IEnumerable 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); }