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 })
};
public static string DefaultIniPath { get; private set; } = Path.Combine(PathUtils.ExeDirectoryPath, "config.ini");
// Shenanigans
public static void SetDefaultIniPath(string newDefaultIniPath)
{
DefaultIniPath = newDefaultIniPath;
}
public Config()
{
if (AllTrollers.Count == 0

View File

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

View File

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

View File

@ -130,16 +130,16 @@ namespace BizHawk.Client.EmuHawk
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;
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();
}
initialConfig = ConfigService.Load<Config>(Config.DefaultIniPath);
initialConfig = ConfigService.Load<Config>(configPath);
}
catch (Exception e)
{
@ -149,8 +149,8 @@ namespace BizHawk.Client.EmuHawk
"The caught exception was:",
e.ToString()
)).ShowDialog();
File.Delete(Config.DefaultIniPath);
initialConfig = ConfigService.Load<Config>(Config.DefaultIniPath);
File.Delete(configPath);
initialConfig = ConfigService.Load<Config>(configPath);
}
initialConfig.ResolveDefaults();
// initialConfig should really be globalConfig as it's mutable
@ -237,6 +237,7 @@ namespace BizHawk.Client.EmuHawk
MainForm mf = new(
cliFlags,
workingGL,
() => configPath,
() => initialConfig,
newSound => globalSound = newSound,
args,