Skip to content

Commit 791ece9

Browse files
committed
处理 #587 ; 处理用户按下Ctrl+C事件
1 parent 576a81a commit 791ece9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

BBDown/Program.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,23 @@ private static int Compare(Audio r1, Audio r2)
4141
[JsonSerializable(typeof(MyOption))]
4242
partial class MyOptionJsonContext : JsonSerializerContext { }
4343

44+
private static void Console_CancelKeyPress(object? sender, ConsoleCancelEventArgs e)
45+
{
46+
LogWarn("Force Exit...");
47+
try
48+
{
49+
Console.ResetColor();
50+
Console.CursorVisible = true;
51+
if (!OperatingSystem.IsWindows())
52+
System.Diagnostics.Process.Start("stty", "echo");
53+
}
54+
catch { }
55+
Environment.Exit(0);
56+
}
4457

4558
public static async Task<int> Main(params string[] args)
4659
{
60+
Console.CancelKeyPress += Console_CancelKeyPress;
4761
ServicePointManager.DefaultConnectionLimit = 2048;
4862

4963
var rootCommand = CommandLineInvoker.GetRootCommand(DoWorkAsync);
@@ -211,6 +225,8 @@ private static async Task DoWorkAsync(MyOption myOption)
211225
Config.COOKIE = myOption.Cookie;
212226
Config.TOKEN = myOption.AccessToken.Replace("access_token=", "");
213227

228+
if (interactMode) hideStreams = false; //手动选择时不能隐藏流
229+
214230
if (!string.IsNullOrEmpty(myOption.WorkDir))
215231
{
216232
//解释环境变量

0 commit comments

Comments
 (0)