From 7ff1591674194e887407226c6405979c9e1ddfdc Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Fri, 10 Jan 2025 04:13:56 -0500 Subject: [PATCH] Add ability to wait for a debugger to attach before executing. Uses preprocessor `#define WAIT_FOR_DEBUGGER` --- ReCodeItCLI/Commands/AutoMatcher.cs | 14 +++++++++++++- ReCodeItCLI/Commands/ReMap.cs | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ReCodeItCLI/Commands/AutoMatcher.cs b/ReCodeItCLI/Commands/AutoMatcher.cs index 40cc589..e192e95 100644 --- a/ReCodeItCLI/Commands/AutoMatcher.cs +++ b/ReCodeItCLI/Commands/AutoMatcher.cs @@ -1,4 +1,8 @@ -using CliFx; +// Uncomment this to have the application wait for a debugger to attach before running. +#define WAIT_FOR_DEBUGGER + +using System.Diagnostics; +using CliFx; using CliFx.Attributes; using CliFx.Infrastructure; using ReCodeItLib.Models; @@ -28,6 +32,14 @@ public class AutoMatchCommand : ICommand Logger.LogSync("Finding match..."); var remaps = new List(); + +#if WAIT_FOR_DEBUGGER + Logger.LogSync("Waiting for debugger..."); + while (!Debugger.IsAttached) + { + Thread.Sleep(100); + } +#endif if (!string.IsNullOrEmpty(MappingsPath)) { diff --git a/ReCodeItCLI/Commands/ReMap.cs b/ReCodeItCLI/Commands/ReMap.cs index f3e90c3..0fafbb9 100644 --- a/ReCodeItCLI/Commands/ReMap.cs +++ b/ReCodeItCLI/Commands/ReMap.cs @@ -1,4 +1,8 @@ -using CliFx; +// Uncomment this to have the application wait for a debugger to attach before running. +//#define WAIT_FOR_DEBUGGER + +using System.Diagnostics; +using CliFx; using CliFx.Attributes; using CliFx.Infrastructure; using ReCodeItLib.Utils; @@ -19,6 +23,14 @@ public class ReMap : ICommand public ValueTask ExecuteAsync(IConsole console) { +#if WAIT_FOR_DEBUGGER + Logger.LogSync("Waiting for debugger..."); + while (!Debugger.IsAttached) + { + Thread.Sleep(100); + } +#endif + DataProvider.Settings.MappingPath = MappingJsonPath; var remaps = DataProvider.LoadMappingFile(MappingJsonPath);