Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

寻找工具时需要包含工作目录. #357

Merged
merged 3 commits into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions BBDown/BBDownUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -812,33 +812,11 @@ public static string GetMp4boxMetaString(List<ViewPoint> points)

public static string FindExecutable(string name)
{
if (OperatingSystem.IsWindows())
{
var file = Path.Combine(Program.APP_DIR, name + ".exe");
if (File.Exists(file))
return file;
var path = Environment.GetEnvironmentVariable("PATH");
foreach (var item in path.Split(';'))
{
file = Path.Combine(item, name + ".exe");
if (File.Exists(file))
return file;
}
}
else
{
var file = Path.Combine(Program.APP_DIR, name);
if (File.Exists(file))
return file;
var path = Environment.GetEnvironmentVariable("PATH");
foreach (var item in path.Split(':'))
{
file = Path.Combine(item, name);
if (File.Exists(file))
return file;
}
}
return null;
var fileExt = OperatingSystem.IsWindows() ? ".exe" : "";
var searchPath = new [] { Environment.CurrentDirectory, Program.APP_DIR };
var envPath = Environment.GetEnvironmentVariable("PATH")?.Split(Path.PathSeparator) ??
Array.Empty<string>();
return searchPath.Concat(envPath).Select(p => Path.Combine(p, name + fileExt)).FirstOrDefault(File.Exists);
}

public static async Task<bool> CheckLogin(string cookie)
Expand Down
53 changes: 30 additions & 23 deletions BBDown/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,17 +471,34 @@ private static async Task DoWorkAsync(MyOption myOption)
LogDebug("切换工作目录至:{0}", dir);
}

if (!string.IsNullOrEmpty(myOption.FFmpegPath) && File.Exists(myOption.FFmpegPath))
{
BBDownMuxer.FFMPEG = myOption.FFmpegPath;
}

if (!string.IsNullOrEmpty(myOption.Mp4boxPath) && File.Exists(myOption.Mp4boxPath))
{
BBDownMuxer.MP4BOX = myOption.Mp4boxPath;
}

if (!string.IsNullOrEmpty(myOption.Aria2cPath) && File.Exists(myOption.Aria2cPath))
{
BBDownAria2c.ARIA2C = myOption.Aria2cPath;
}
//寻找ffmpeg或mp4box
if (!skipMux)
{
if (useMp4box)
{
var binPath = FindExecutable("mp4box");
if (string.IsNullOrEmpty(binPath))
throw new Exception("找不到可执行的mp4box文件");
BBDownMuxer.MP4BOX = binPath;
if (string.IsNullOrEmpty(BBDownMuxer.MP4BOX))
{
var binPath = FindExecutable("mp4box");
if (string.IsNullOrEmpty(binPath))
throw new Exception("找不到可执行的mp4box文件");
BBDownMuxer.MP4BOX = binPath;
}
}
else
else if (string.IsNullOrEmpty(BBDownMuxer.FFMPEG))
{
var binPath = FindExecutable("ffmpeg");
if (string.IsNullOrEmpty(binPath))
Expand All @@ -493,26 +510,16 @@ private static async Task DoWorkAsync(MyOption myOption)
//寻找aria2c
if (useAria2c)
{
var binPath = FindExecutable("aria2c");
if (string.IsNullOrEmpty(binPath))
throw new Exception("找不到可执行的aria2c文件");
BBDownAria2c.ARIA2C = binPath;
}

if (!string.IsNullOrEmpty(myOption.FFmpegPath) && File.Exists(myOption.FFmpegPath))
{
BBDownMuxer.FFMPEG = myOption.FFmpegPath;
}

if (!string.IsNullOrEmpty(myOption.Mp4boxPath) && File.Exists(myOption.Mp4boxPath))
{
BBDownMuxer.MP4BOX = myOption.Mp4boxPath;
if (string.IsNullOrEmpty(BBDownAria2c.ARIA2C))
{
var binPath = FindExecutable("aria2c");
if (string.IsNullOrEmpty(binPath))
throw new Exception("找不到可执行的aria2c文件");
BBDownAria2c.ARIA2C = binPath;
}

}

if (!string.IsNullOrEmpty(myOption.Aria2cPath) && File.Exists(myOption.Aria2cPath))
{
BBDownAria2c.ARIA2C = myOption.Aria2cPath;
}

//audioOnly和videoOnly同时开启则全部忽视
if (audioOnly && videoOnly)
Expand Down