Skip to content

Commit

Permalink
Merge pull request #357 from copyliu/path_fix
Browse files Browse the repository at this point in the history
寻找工具时需要包含工作目录.
  • Loading branch information
nilaoda authored May 22, 2022
2 parents 5b7b7ce + 40fd2cb commit 98ee00e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 50 deletions.
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

0 comments on commit 98ee00e

Please sign in to comment.