From fc4da78e739739d3fc962f843fab5c4eefca0ea0 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Tue, 16 Nov 2021 01:01:56 +1000 Subject: [PATCH] Move global Config to Program --- src/BizHawk.Client.EmuHawk/MainForm.cs | 24 +++++++++--------------- src/BizHawk.Client.EmuHawk/Program.cs | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 4a7dd3f9bd..7a33676678 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -283,15 +283,17 @@ namespace BizHawk.Client.EmuHawk public MainForm( ParsedCLIFlags cliFlags, - Config config, IGL gl, + Func getGlobalConfig, Action updateGlobalSound, string[] args, out IMovieSession movieSession) { movieSession = null; - if (config.SingleInstanceMode) + _getGlobalConfig = getGlobalConfig; + + if (Config.SingleInstanceMode) { if (SingleInstanceInit(args)) { @@ -305,7 +307,6 @@ namespace BizHawk.Client.EmuHawk BootGodDb.Initialize(Path.Combine(PathUtils.ExeDirectoryPath, "gamedb")); _argParser = cliFlags; - Config = config; GL = gl; _updateGlobalSound = updateGlobalSound; @@ -903,13 +904,11 @@ namespace BizHawk.Client.EmuHawk private ISoundProvider _currentSoundProvider = new NullSound(44100 / 60); // Reasonable default until we have a core instance /// don't use this, use - private Config _config; + private readonly Func _getGlobalConfig; - private new Config Config - { - get => _config; - set => base.Config = _config = value; - } + private new Config Config => _getGlobalConfig(); + + public Action LoadGlobalConfigFromFile { get; set; } private readonly IGL GL; @@ -2910,12 +2909,7 @@ namespace BizHawk.Client.EmuHawk private void LoadConfigFile(string iniPath) { - if (!VersionInfo.DeveloperBuild && !ConfigService.IsFromSameVersion(iniPath, out var msg)) - { - new MsgBox(msg, "Mismatched version in config file", MessageBoxIcon.Warning).ShowDialog(); - } - Config = ConfigService.Load(iniPath); - Config.ResolveDefaults(); + LoadGlobalConfigFromFile(iniPath); InitControls(); // rebind hotkeys InputManager.SyncControls(Emulator, MovieSession, Config); Tools.Restart(Config, Emulator, Game); diff --git a/src/BizHawk.Client.EmuHawk/Program.cs b/src/BizHawk.Client.EmuHawk/Program.cs index dead00ab5b..567c107ad1 100644 --- a/src/BizHawk.Client.EmuHawk/Program.cs +++ b/src/BizHawk.Client.EmuHawk/Program.cs @@ -152,8 +152,9 @@ namespace BizHawk.Client.EmuHawk File.Delete(Config.DefaultIniPath); initialConfig = ConfigService.Load(Config.DefaultIniPath); } - initialConfig.ResolveDefaults(); + // initialConfig should really be globalConfig as it's mutable + FFmpegService.FFmpegPath = Path.Combine(PathUtils.DllDirectoryPath, OSTC.IsUnixHost ? "ffmpeg" : "ffmpeg.exe"); StringLogUtil.DefaultToDisk = initialConfig.Movies.MoviesOnDisk; @@ -235,11 +236,21 @@ namespace BizHawk.Client.EmuHawk { MainForm mf = new( cliFlags, - initialConfig, workingGL, + () => initialConfig, newSound => globalSound = newSound, args, out var movieSession); + mf.LoadGlobalConfigFromFile = iniPath => + { + if (!VersionInfo.DeveloperBuild && !ConfigService.IsFromSameVersion(iniPath, out var msg)) + { + new MsgBox(msg, "Mismatched version in config file", MessageBoxIcon.Warning).ShowDialog(); + } + initialConfig = ConfigService.Load(iniPath); + initialConfig.ResolveDefaults(); + mf.Config = initialConfig; + }; // var title = mf.Text; mf.Show(); // mf.Text = title;