From 8859f8f859205dadde40cf262042d34537b87cf9 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Tue, 16 Nov 2021 00:34:10 +1000 Subject: [PATCH] Move `ArgParser.ParseArguments` call to Program, replacing config hack --- src/BizHawk.Client.Common/ArgParser.cs | 7 ------- src/BizHawk.Client.Common/ParsedCLIFlags.cs | 4 ---- src/BizHawk.Client.EmuHawk/MainForm.cs | 18 ++++++++---------- src/BizHawk.Client.EmuHawk/Program.cs | 21 ++++++++++++++++++--- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/BizHawk.Client.Common/ArgParser.cs b/src/BizHawk.Client.Common/ArgParser.cs index 99d4ac9a1a..749b6cd525 100644 --- a/src/BizHawk.Client.Common/ArgParser.cs +++ b/src/BizHawk.Client.Common/ArgParser.cs @@ -21,7 +21,6 @@ namespace BizHawk.Client.Common { string? cmdLoadSlot = null; string? cmdLoadState = null; - string? cmdConfigPath = null; string? cmdConfigFile = null; string? cmdMovie = null; string? cmdDumpType = null; @@ -182,7 +181,6 @@ namespace BizHawk.Client.Common parsed = new ParsedCLIFlags( cmdLoadSlot: cmdLoadSlot, cmdLoadState: cmdLoadState, - cmdConfigPath: cmdConfigPath, cmdConfigFile: cmdConfigFile, cmdMovie: cmdMovie, cmdDumpType: cmdDumpType, @@ -204,11 +202,6 @@ namespace BizHawk.Client.Common ); } - public static string? GetCmdConfigFile(string[] args) - { - return args.FirstOrDefault(arg => arg.StartsWith("--config=", StringComparison.InvariantCultureIgnoreCase))?.Substring(9); - } - public sealed class ArgParserException : Exception { public ArgParserException(string message) : base(message) {} diff --git a/src/BizHawk.Client.Common/ParsedCLIFlags.cs b/src/BizHawk.Client.Common/ParsedCLIFlags.cs index 3e98e2b9af..93a31febb3 100644 --- a/src/BizHawk.Client.Common/ParsedCLIFlags.cs +++ b/src/BizHawk.Client.Common/ParsedCLIFlags.cs @@ -10,8 +10,6 @@ namespace BizHawk.Client.Common public readonly string? cmdLoadState; - public readonly string? cmdConfigPath; - public readonly string? cmdConfigFile; public readonly string? cmdMovie; @@ -50,7 +48,6 @@ namespace BizHawk.Client.Common public ParsedCLIFlags(string? cmdLoadSlot, string? cmdLoadState, - string? cmdConfigPath, string? cmdConfigFile, string? cmdMovie, string? cmdDumpType, @@ -72,7 +69,6 @@ namespace BizHawk.Client.Common { this.cmdLoadSlot = cmdLoadSlot; this.cmdLoadState = cmdLoadState; - this.cmdConfigPath = cmdConfigPath; this.cmdConfigFile = cmdConfigFile; this.cmdMovie = cmdMovie; this.cmdDumpType = cmdDumpType; diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 68c7e0d031..4a7dd3f9bd 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -281,7 +281,13 @@ namespace BizHawk.Client.EmuHawk CloseRomContextMenuItem.Image = Properties.Resources.Close; } - public MainForm(Config config, IGL gl, Action updateGlobalSound, string[] args, out IMovieSession movieSession) + public MainForm( + ParsedCLIFlags cliFlags, + Config config, + IGL gl, + Action updateGlobalSound, + string[] args, + out IMovieSession movieSession) { movieSession = null; @@ -298,6 +304,7 @@ namespace BizHawk.Client.EmuHawk Database.InitializeDatabase(Path.Combine(PathUtils.ExeDirectoryPath, "gamedb", "gamedb.txt"), silent: true); BootGodDb.Initialize(Path.Combine(PathUtils.ExeDirectoryPath, "gamedb")); + _argParser = cliFlags; Config = config; GL = gl; _updateGlobalSound = updateGlobalSound; @@ -361,15 +368,6 @@ namespace BizHawk.Client.EmuHawk UpdateStatusSlots(); UpdateKeyPriorityIcon(); - try - { - ArgParser.ParseArguments(out _argParser, args); - } - catch (ArgParser.ArgParserException e) - { - ShowMessageBox(owner: null, e.Message); - } - // TODO GL - a lot of disorganized wiring-up here // installed separately on Unix (via package manager or from https://developer.nvidia.com/cg-toolkit-download), look in $PATH _presentationPanel = new PresentationPanel( diff --git a/src/BizHawk.Client.EmuHawk/Program.cs b/src/BizHawk.Client.EmuHawk/Program.cs index b828c1acae..dead00ab5b 100644 --- a/src/BizHawk.Client.EmuHawk/Program.cs +++ b/src/BizHawk.Client.EmuHawk/Program.cs @@ -120,8 +120,17 @@ namespace BizHawk.Client.EmuHawk HawkFile.DearchivalMethod = SharpCompressDearchivalMethod.Instance; - string cmdConfigFile = ArgParser.GetCmdConfigFile(args); - if (cmdConfigFile != null) Config.SetDefaultIniPath(cmdConfigFile); + ParsedCLIFlags cliFlags = default; + try + { + ArgParser.ParseArguments(out cliFlags, args); + } + catch (ArgParser.ArgParserException e) + { + new ExceptionBox(e.Message).ShowDialog(); + } + + if (cliFlags.cmdConfigFile != null) Config.SetDefaultIniPath(cliFlags.cmdConfigFile); Config initialConfig; try @@ -224,7 +233,13 @@ namespace BizHawk.Client.EmuHawk var exitCode = 0; try { - var mf = new MainForm(initialConfig, workingGL, newSound => globalSound = newSound, args, out var movieSession); + MainForm mf = new( + cliFlags, + initialConfig, + workingGL, + newSound => globalSound = newSound, + args, + out var movieSession); // var title = mf.Text; mf.Show(); // mf.Text = title;