From 498a8619ab018f600bdd4cd2007ef736e95bc0a5 Mon Sep 17 00:00:00 2001 From: Alek-ban Date: Wed, 1 Apr 2026 10:16:41 +0300 Subject: [PATCH] feat: move the "--debug" option from ui to global and process it manualy --- GSS2.Test/Program.cs | 50 ++++++++++++++++++++++++++++++++++------- GSS2.Test/PropgramUi.cs | 35 ++--------------------------- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/GSS2.Test/Program.cs b/GSS2.Test/Program.cs index 79378b7..bc1bc11 100644 --- a/GSS2.Test/Program.cs +++ b/GSS2.Test/Program.cs @@ -13,17 +13,12 @@ public partial class Program DRM } - private static string[]? _args = null; + private static List? _args = null; private static readonly RootCommand _rootCommand = new("Run UI application"); private static readonly Option _fullscreen = new("--fullscreen") { Description = "Run in fullscreen mode" }; - private static readonly Option _debug = new Option("--debug") - { - Description = "Wait debugger attach on launch", - Hidden = true - }; private static readonly Option _renderingMode = new("--rendering-mode") { Description = "Rendering mode to use", @@ -106,11 +101,14 @@ public partial class Program [STAThread] public static int Main(string[] args) { - _args = args; + _args = args.ToList(); + +#if DEBUG + WaitDebuggerIfNeeded(); +#endif _rootCommand.SetAction(Ui); _rootCommand.Add(_fullscreen); - _rootCommand.Add(_debug); _rootCommand.Add(_renderingMode); _rootCommand.Add(_hideConsole); @@ -152,4 +150,40 @@ public partial class Program ShutdownRequested?.Invoke(sender, ea); ea.Cancel = true; } + + private static void WaitDebuggerIfNeeded() + { + if (System.Diagnostics.Debugger.IsAttached) + return; + + if (_args is null || !_args.Contains("--debug")) + return; + + _args.Remove("--debug"); + + bool keepWaiting = true; + + void CancelHandle(object? sender, ConsoleCancelEventArgs e) + { + e.Cancel = true; + keepWaiting = false; + Console.WriteLine("\nWait cancelled by user."); + Environment.Exit(0); + } + Console.CancelKeyPress += CancelHandle; + + Console.WriteLine("Waiting debugger attach (Press Ctrl+C to cancel)"); + Console.WriteLine($"Process Id: {Environment.ProcessId}"); + Console.WriteLine($"Process Name: {Environment.ProcessPath}"); + Console.WriteLine($"Thread Id: {Thread.CurrentThread.ManagedThreadId}"); + Console.WriteLine($"Thread Name: {Thread.CurrentThread.Name}"); + + while (!System.Diagnostics.Debugger.IsAttached && keepWaiting) + Thread.Sleep(100); + + if (System.Diagnostics.Debugger.IsAttached) + System.Diagnostics.Debugger.Break(); + + Console.CancelKeyPress -= CancelHandle; + } } diff --git a/GSS2.Test/PropgramUi.cs b/GSS2.Test/PropgramUi.cs index f13dbfa..b8d01eb 100644 --- a/GSS2.Test/PropgramUi.cs +++ b/GSS2.Test/PropgramUi.cs @@ -24,52 +24,21 @@ public partial class Program { var builder = BuildAvaloniaApp(); var fullscreen = parseResult.GetValue(_fullscreen); - var debug = parseResult.GetValue(_debug); var renderingMode = parseResult.GetValue(_renderingMode); var hideConsole = parseResult.GetValue(_hideConsole); IsFullscreen = fullscreen; -#if DEBUG - if (debug && !System.Diagnostics.Debugger.IsAttached) - { - bool keepWaiting = true; - - void CancelHandle(object? sender, ConsoleCancelEventArgs e) - { - e.Cancel = true; - keepWaiting = false; - Console.WriteLine("\nWait cancelled by user."); - Environment.Exit(0); - } - Console.CancelKeyPress += CancelHandle; - - Console.WriteLine("Waiting debugger attach (Press Ctrl+C to cancel)"); - Console.WriteLine($"Process Id: {Environment.ProcessId}"); - Console.WriteLine($"Process Name: {Environment.ProcessPath}"); - Console.WriteLine($"Thread Id: {Thread.CurrentThread.ManagedThreadId}"); - Console.WriteLine($"Thread Name: {Thread.CurrentThread.Name}"); - - while (!System.Diagnostics.Debugger.IsAttached && keepWaiting) - Thread.Sleep(100); - - if (System.Diagnostics.Debugger.IsAttached) - System.Diagnostics.Debugger.Break(); - - Console.CancelKeyPress -= CancelHandle; - } -#endif - if (hideConsole) SilenceConsole(); switch (renderingMode) { case RenderingMode.X11: - builder.StartWithClassicDesktopLifetime(_args ?? []); + builder.StartWithClassicDesktopLifetime(_args?.ToArray() ?? []); break; case RenderingMode.DRM: - builder.StartLinuxDrm(_args ?? [], "/dev/dri/card1", 1.0); + builder.StartLinuxDrm(_args?.ToArray() ?? [], "/dev/dri/card1", 1.0); break; } }