From facfc791c251106392df358ddc6fd7c454d11467 Mon Sep 17 00:00:00 2001 From: Alek-ban Date: Thu, 26 Feb 2026 11:15:50 +0300 Subject: [PATCH] feat: command line debug option --- GSS2.Test/Program.cs | 27 ++++++++++++++++----------- GSS2.Test/PropgramUi.cs | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/GSS2.Test/Program.cs b/GSS2.Test/Program.cs index fcd11dd..9a659dd 100644 --- a/GSS2.Test/Program.cs +++ b/GSS2.Test/Program.cs @@ -19,6 +19,21 @@ public partial class Program { 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", + DefaultValueFactory = (_) => RenderingMode.X11 + }; + private static readonly Option _hideConsole = new("--hide-console") + { + Description = "Suppress console output", + DefaultValueFactory = (result) => result.GetRequiredValue(_renderingMode) == RenderingMode.DRM + }; private static readonly Command _cameraTuningCommand = new("camera-tuning") { @@ -80,17 +95,6 @@ public partial class Program DefaultValueFactory = (_) => 0 }; - private static readonly Option _renderingMode = new("--rendering-mode") - { - Description = "Rendering mode to use", - DefaultValueFactory = (_) => RenderingMode.X11 - }; - private static readonly Option _hideConsole = new("--hide-console") - { - Description = "Suppress console output", - DefaultValueFactory = (result) => result.GetRequiredValue(_renderingMode) == RenderingMode.DRM - }; - public static event ConsoleCancelEventHandler? ShutdownRequested; [STAThread] @@ -100,6 +104,7 @@ public partial class Program _rootCommand.SetAction(Ui); _rootCommand.Add(_fullscreen); + _rootCommand.Add(_debug); _rootCommand.Add(_renderingMode); _rootCommand.Add(_hideConsole); diff --git a/GSS2.Test/PropgramUi.cs b/GSS2.Test/PropgramUi.cs index d5739c1..53d9e9a 100644 --- a/GSS2.Test/PropgramUi.cs +++ b/GSS2.Test/PropgramUi.cs @@ -22,11 +22,25 @@ public partial class Program private static void Ui(ParseResult parseResult) { var builder = BuildAvaloniaApp(); + var fullscreen = parseResult.GetValue(_fullscreen); + var debug = parseResult.GetValue(_debug); var renderingMode = parseResult.GetValue(_renderingMode); var hideConsole = parseResult.GetValue(_hideConsole); - var fullscreen = parseResult.GetValue(_fullscreen); + IsFullscreen = fullscreen; +#if DEBUG + if (debug && !System.Diagnostics.Debugger.IsAttached) + { + Console.WriteLine("Waiting debugger attach"); + Console.WriteLine($"ProcessId: {Environment.ProcessPath} [{Environment.ProcessId}]"); + Console.WriteLine($"Thread: {Thread.CurrentThread.Name} [{Thread.CurrentThread.ManagedThreadId}]"); + while (!System.Diagnostics.Debugger.IsAttached) + Thread.Sleep(100); + System.Diagnostics.Debugger.Break(); + } +#endif + if (hideConsole) SilenceConsole();