From ccc7353bb1edbeb145e5bf40e7b27becc5ffdd50 Mon Sep 17 00:00:00 2001 From: Casper Sparre Date: Mon, 15 Dec 2025 17:39:20 +0100 Subject: [PATCH] Attempt to fix logging not flushing correctly before exiting --- OF DL/Program.cs | 66 ++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 2f764dc..ac0665f 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -83,8 +83,7 @@ public class Program AnsiConsole.MarkupLine($"[red]Press any key to exit.[/]"); Log.Error(e, "auth invalid after attempt to get auth from browser"); - Log.CloseAndFlush(); - Environment.Exit(2); + ExitWithCode(2); } if (auth == null) @@ -96,8 +95,7 @@ public class Program AnsiConsole.MarkupLine($"[red]Press any key to exit.[/]"); Log.Error("auth invalid after attempt to get auth from browser"); - Log.CloseAndFlush(); - Environment.Exit(2); + ExitWithCode(2); } else { @@ -253,8 +251,7 @@ public class Program Console.ReadKey(); } - Log.CloseAndFlush(); - Environment.Exit(3); + ExitWithCode(3); } } @@ -384,8 +381,7 @@ public class Program Console.ReadKey(); } - Log.CloseAndFlush(); - Environment.Exit(3); + ExitWithCode(3); } } else @@ -497,8 +493,7 @@ public class Program Console.ReadKey(); } - Log.CloseAndFlush(); - Environment.Exit(3); + ExitWithCode(3); } @@ -593,8 +588,7 @@ public class Program Console.ReadKey(); } - Log.CloseAndFlush(); - Environment.Exit(1); + ExitWithCode(1); } else { @@ -691,8 +685,7 @@ public class Program AnsiConsole.MarkupLine($"[red]Press any key to exit.[/]"); Console.ReadKey(); - Log.CloseAndFlush(); - Environment.Exit(2); + ExitWithCode(2); } @@ -708,8 +701,7 @@ public class Program AnsiConsole.MarkupLine($"[red]Press any key to exit.[/]"); Console.ReadKey(); - Log.CloseAndFlush(); - Environment.Exit(2); + ExitWithCode(2); } } } @@ -723,8 +715,7 @@ public class Program AnsiConsole.MarkupLine($"[red]Press any key to exit.[/]"); Console.ReadKey(); - Log.CloseAndFlush(); - Environment.Exit(2); + ExitWithCode(2); } if (!config!.DisableBrowserAuth) @@ -739,8 +730,7 @@ public class Program AnsiConsole.MarkupLine($"[red]Press any key to exit.[/]"); Console.ReadKey(); - Log.CloseAndFlush(); - Environment.Exit(2); + ExitWithCode(2); } } @@ -770,8 +760,7 @@ public class Program Console.ReadKey(); } - Log.CloseAndFlush(); - Environment.Exit(2); + ExitWithCode(2); } } @@ -915,8 +904,7 @@ public class Program Console.ReadKey(); } - Log.CloseAndFlush(); - Environment.Exit(4); + ExitWithCode(4); } if (!File.Exists(Path.Join(WidevineClient.Widevine.Constants.DEVICES_FOLDER, WidevineClient.Widevine.Constants.DEVICE_NAME, "device_client_id_blob"))) @@ -975,8 +963,7 @@ public class Program Console.ReadKey(); - Log.CloseAndFlush(); - Environment.Exit(2); + ExitWithCode(2); } } @@ -1019,11 +1006,15 @@ public class Program Console.ReadKey(); } - Log.CloseAndFlush(); - Environment.Exit(5); + ExitWithCode(5); } finally { + Console.WriteLine(); + + AnsiConsole.Markup($"Exiting after successful run..\n"); + await Task.Delay(2000); + Log.CloseAndFlush(); } } @@ -1629,6 +1620,8 @@ public class Program .ForContext("Paid Messages", totalNewPaidMessagesCount) .Information("Scrape Completed in {TotalMinutes:0.00} minutes", totalTime.TotalMinutes); AnsiConsole.Markup($"[green]Scrape Completed in {totalTime.TotalMinutes:0.00} minutes\n[/]"); + + await Task.Delay(2000); } else if (hasSelectedUsersKVP.Key && hasSelectedUsersKVP.Value != null && hasSelectedUsersKVP.Value.ContainsKey("ConfigChanged")) { @@ -3690,7 +3683,7 @@ public class Program AnsiConsole.Markup($"[red]{settingName} is not unique enough, please make sure you include either '{{mediaId}}' or '{{filename}}' to ensure that files are not overwritten with the same filename.[/]\n"); AnsiConsole.Markup("[red]Press any key to continue.[/]\n"); Console.ReadKey(); - Environment.Exit(2); + ExitWithCode(2); } } @@ -3719,8 +3712,21 @@ public class Program AnsiConsole.Markup($"[green]Other OF DL process detected, exiting..\n[/]"); Log.Warning("Other OF DL process detected, exiting.."); + ExitWithCode(0); + } + + static void ExitWithCode(int exitCode) + { + Console.WriteLine(); + + (string colorStart, string colorEnd) = exitCode != 0 ? ("[red]", "[]") : ("", ""); + AnsiConsole.Markup($"{colorStart}Exiting run with Code '{exitCode}'..{colorEnd}\n"); + Log.CloseAndFlush(); - Environment.Exit(0); + Log.CloseAndFlush(); + Task.Delay(5000).GetAwaiter().GetResult(); + + Environment.Exit(exitCode); } static ILogger LoggerWithConfigContext(Entities.Config config)