Working version
This commit is contained in:
@@ -22,6 +22,18 @@ public static class ToolExtractor
|
||||
return await ExtractAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public static bool TryResolveFromSystemPath(out ToolPaths? tools)
|
||||
{
|
||||
tools = null;
|
||||
string? ffmpeg = FindOnPath("ffmpeg.exe");
|
||||
string? ffprobe = FindOnPath("ffprobe.exe");
|
||||
if (ffmpeg is null || ffprobe is null)
|
||||
return false;
|
||||
|
||||
tools = new ToolPaths(ffmpeg, ffprobe);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static async Task<ToolPaths> ExtractAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
string toolDir = Path.Combine(
|
||||
@@ -66,4 +78,26 @@ public static class ToolExtractor
|
||||
byte[] bHash = sha.ComputeHash(b);
|
||||
return aHash.AsSpan().SequenceEqual(bHash);
|
||||
}
|
||||
|
||||
private static string? FindOnPath(string fileName)
|
||||
{
|
||||
string? path = Environment.GetEnvironmentVariable("PATH");
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
return null;
|
||||
|
||||
foreach (string directory in path.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
|
||||
{
|
||||
try
|
||||
{
|
||||
string candidate = Path.Combine(directory, fileName);
|
||||
if (File.Exists(candidate))
|
||||
return candidate;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user