Move `Config.DefaultIniPath` to Program

This commit is contained in:
YoshiRulz 2021-11-16 01:32:15 +10:00
parent fc4da78e73
commit baea2a081b
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
4 changed files with 14 additions and 17 deletions

View File

@ -34,14 +34,6 @@ namespace BizHawk.Client.Common
new[] { CoreNames.TurboNyma, CoreNames.HyperNyma, CoreNames.PceHawk }) new[] { CoreNames.TurboNyma, CoreNames.HyperNyma, CoreNames.PceHawk })
}; };
public static string DefaultIniPath { get; private set; } = Path.Combine(PathUtils.ExeDirectoryPath, "config.ini");
// Shenanigans
public static void SetDefaultIniPath(string newDefaultIniPath)
{
DefaultIniPath = newDefaultIniPath;
}
public Config() public Config()
{ {
if (AllTrollers.Count == 0 if (AllTrollers.Count == 0

View File

@ -1122,7 +1122,7 @@ namespace BizHawk.Client.EmuHawk
private void SaveConfigAsMenuItem_Click(object sender, EventArgs e) private void SaveConfigAsMenuItem_Click(object sender, EventArgs e)
{ {
var path = Config.DefaultIniPath; var path = _getConfigPath();
using var sfd = new SaveFileDialog using var sfd = new SaveFileDialog
{ {
InitialDirectory = Path.GetDirectoryName(path), InitialDirectory = Path.GetDirectoryName(path),
@ -1139,12 +1139,12 @@ namespace BizHawk.Client.EmuHawk
private void LoadConfigMenuItem_Click(object sender, EventArgs e) private void LoadConfigMenuItem_Click(object sender, EventArgs e)
{ {
LoadConfigFile(Config.DefaultIniPath); LoadConfigFile(_getConfigPath());
} }
private void LoadConfigFromMenuItem_Click(object sender, EventArgs e) private void LoadConfigFromMenuItem_Click(object sender, EventArgs e)
{ {
var path = Config.DefaultIniPath; var path = _getConfigPath();
using var ofd = new OpenFileDialog using var ofd = new OpenFileDialog
{ {
InitialDirectory = Path.GetDirectoryName(path), InitialDirectory = Path.GetDirectoryName(path),

View File

@ -284,6 +284,7 @@ namespace BizHawk.Client.EmuHawk
public MainForm( public MainForm(
ParsedCLIFlags cliFlags, ParsedCLIFlags cliFlags,
IGL gl, IGL gl,
Func<string> getConfigPath,
Func<Config> getGlobalConfig, Func<Config> getGlobalConfig,
Action<Sound> updateGlobalSound, Action<Sound> updateGlobalSound,
string[] args, string[] args,
@ -307,6 +308,7 @@ namespace BizHawk.Client.EmuHawk
BootGodDb.Initialize(Path.Combine(PathUtils.ExeDirectoryPath, "gamedb")); BootGodDb.Initialize(Path.Combine(PathUtils.ExeDirectoryPath, "gamedb"));
_argParser = cliFlags; _argParser = cliFlags;
_getConfigPath = getConfigPath;
GL = gl; GL = gl;
_updateGlobalSound = updateGlobalSound; _updateGlobalSound = updateGlobalSound;
@ -910,6 +912,8 @@ namespace BizHawk.Client.EmuHawk
public Action<string> LoadGlobalConfigFromFile { get; set; } public Action<string> LoadGlobalConfigFromFile { get; set; }
private readonly Func<string> _getConfigPath;
private readonly IGL GL; private readonly IGL GL;
private readonly ExternalToolManager ExtToolManager; private readonly ExternalToolManager ExtToolManager;
@ -2465,7 +2469,7 @@ namespace BizHawk.Client.EmuHawk
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
{ {
path = Config.DefaultIniPath; path = _getConfigPath();
} }
ConfigService.Save(path, Config); ConfigService.Save(path, Config);

View File

@ -130,16 +130,16 @@ namespace BizHawk.Client.EmuHawk
new ExceptionBox(e.Message).ShowDialog(); new ExceptionBox(e.Message).ShowDialog();
} }
if (cliFlags.cmdConfigFile != null) Config.SetDefaultIniPath(cliFlags.cmdConfigFile); var configPath = cliFlags.cmdConfigFile ?? Path.Combine(PathUtils.ExeDirectoryPath, "config.json");
Config initialConfig; Config initialConfig;
try try
{ {
if (!VersionInfo.DeveloperBuild && !ConfigService.IsFromSameVersion(Config.DefaultIniPath, out var msg)) if (!VersionInfo.DeveloperBuild && !ConfigService.IsFromSameVersion(configPath, out var msg))
{ {
new MsgBox(msg, "Mismatched version in config file", MessageBoxIcon.Warning).ShowDialog(); new MsgBox(msg, "Mismatched version in config file", MessageBoxIcon.Warning).ShowDialog();
} }
initialConfig = ConfigService.Load<Config>(Config.DefaultIniPath); initialConfig = ConfigService.Load<Config>(configPath);
} }
catch (Exception e) catch (Exception e)
{ {
@ -149,8 +149,8 @@ namespace BizHawk.Client.EmuHawk
"The caught exception was:", "The caught exception was:",
e.ToString() e.ToString()
)).ShowDialog(); )).ShowDialog();
File.Delete(Config.DefaultIniPath); File.Delete(configPath);
initialConfig = ConfigService.Load<Config>(Config.DefaultIniPath); initialConfig = ConfigService.Load<Config>(configPath);
} }
initialConfig.ResolveDefaults(); initialConfig.ResolveDefaults();
// initialConfig should really be globalConfig as it's mutable // initialConfig should really be globalConfig as it's mutable
@ -237,6 +237,7 @@ namespace BizHawk.Client.EmuHawk
MainForm mf = new( MainForm mf = new(
cliFlags, cliFlags,
workingGL, workingGL,
() => configPath,
() => initialConfig, () => initialConfig,
newSound => globalSound = newSound, newSound => globalSound = newSound,
args, args,