Move `ArgParser.ParseArguments` call to Program, replacing config hack

This commit is contained in:
YoshiRulz 2021-11-16 00:34:10 +10:00
parent 69a4d64671
commit 8859f8f859
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
4 changed files with 26 additions and 24 deletions

View File

@ -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) {}

View File

@ -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;

View File

@ -281,7 +281,13 @@ namespace BizHawk.Client.EmuHawk
CloseRomContextMenuItem.Image = Properties.Resources.Close;
}
public MainForm(Config config, IGL gl, Action<Sound> updateGlobalSound, string[] args, out IMovieSession movieSession)
public MainForm(
ParsedCLIFlags cliFlags,
Config config,
IGL gl,
Action<Sound> 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(

View File

@ -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;