Cleanup instantiation of FirmwaresManager and PathConfig
and remove unused MainForm interface prop
This commit is contained in:
parent
18ebfecc97
commit
206a3e30c8
|
@ -8,9 +8,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
/// <remarks>only referenced from <see cref="GenericCoreConfig"/></remarks>
|
/// <remarks>only referenced from <see cref="GenericCoreConfig"/></remarks>
|
||||||
IEmulator Emulator { get; }
|
IEmulator Emulator { get; }
|
||||||
|
|
||||||
/// <remarks>only referenced from <see cref="FirmwaresConfig"/></remarks>
|
|
||||||
FirmwareManager FirmwareManager { get; }
|
|
||||||
|
|
||||||
IMovieSession MovieSession { get; }
|
IMovieSession MovieSession { get; }
|
||||||
|
|
||||||
void AddOnScreenMessage(string message);
|
void AddOnScreenMessage(string message);
|
||||||
|
|
|
@ -866,13 +866,13 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
if (e is RomLoader.RomErrorArgs args)
|
if (e is RomLoader.RomErrorArgs args)
|
||||||
{
|
{
|
||||||
using var configForm = new FirmwaresConfig(this, Config, Game, true, args.RomPath);
|
using var configForm = new FirmwaresConfig(FirmwareManager, Config.FirmwareUserSpecifications, Game, this, Config.PathEntries, retryLoadRom: true, reloadRomPath: args.RomPath);
|
||||||
var result = configForm.ShowDialog();
|
var result = configForm.ShowDialog();
|
||||||
args.Retry = result == DialogResult.Retry;
|
args.Retry = result == DialogResult.Retry;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
using var configForm = new FirmwaresConfig(this, Config, Game);
|
using var configForm = new FirmwaresConfig(FirmwareManager, Config.FirmwareUserSpecifications, Game, this, Config.PathEntries);
|
||||||
configForm.ShowDialog();
|
configForm.ShowDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -888,7 +888,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private void PathsMenuItem_Click(object sender, EventArgs e)
|
private void PathsMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
using var form = new PathConfig(this, Config, Game);
|
using var form = new PathConfig(FirmwareManager, Config.FirmwareUserSpecifications, Game, this, Config.PathEntries);
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,16 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
public partial class FirmwaresConfig : Form
|
public partial class FirmwaresConfig : Form
|
||||||
{
|
{
|
||||||
private readonly IMainFormForConfig _mainForm;
|
private readonly IDictionary<string, string> _firmwareUserSpecifications;
|
||||||
private readonly Config _config;
|
|
||||||
private readonly IGameInfo _game;
|
private readonly IGameInfo _game;
|
||||||
|
|
||||||
|
private readonly IMainFormForConfig _mainForm;
|
||||||
|
|
||||||
|
private readonly PathEntryCollection _pathEntries;
|
||||||
|
|
||||||
|
private readonly FirmwareManager Manager;
|
||||||
|
|
||||||
// friendlier names than the system Ids
|
// friendlier names than the system Ids
|
||||||
// Redundant with SystemLookup? Not so fast. That data drives things. This is one step abstracted. Don't be such a smart guy. Keep this redundant list up to date.
|
// Redundant with SystemLookup? Not so fast. That data drives things. This is one step abstracted. Don't be such a smart guy. Keep this redundant list up to date.
|
||||||
private static readonly Dictionary<string, string> SystemGroupNames = new Dictionary<string, string>
|
private static readonly Dictionary<string, string> SystemGroupNames = new Dictionary<string, string>
|
||||||
|
@ -95,11 +101,21 @@ namespace BizHawk.Client.EmuHawk
|
||||||
private string _currSelectorDir;
|
private string _currSelectorDir;
|
||||||
private readonly ListViewSorter _listViewSorter;
|
private readonly ListViewSorter _listViewSorter;
|
||||||
|
|
||||||
public FirmwaresConfig(IMainFormForConfig mainForm, Config config, IGameInfo game, bool retryLoadRom = false, string reloadRomPath = null)
|
public FirmwaresConfig(
|
||||||
|
FirmwareManager firmwareManager,
|
||||||
|
IDictionary<string, string> firmwareUserSpecifications,
|
||||||
|
IGameInfo game,
|
||||||
|
IMainFormForConfig mainForm,
|
||||||
|
PathEntryCollection pathEntries,
|
||||||
|
bool retryLoadRom = false,
|
||||||
|
string reloadRomPath = null)
|
||||||
{
|
{
|
||||||
_mainForm = mainForm;
|
_firmwareUserSpecifications = firmwareUserSpecifications;
|
||||||
_config = config;
|
|
||||||
_game = game;
|
_game = game;
|
||||||
|
_mainForm = mainForm;
|
||||||
|
_pathEntries = pathEntries;
|
||||||
|
Manager = firmwareManager;
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
tbbGroup.Image
|
tbbGroup.Image
|
||||||
|
@ -253,22 +269,20 @@ namespace BizHawk.Client.EmuHawk
|
||||||
DoScan();
|
DoScan();
|
||||||
}
|
}
|
||||||
|
|
||||||
private FirmwareManager Manager => _mainForm.FirmwareManager;
|
|
||||||
|
|
||||||
private void DoScan()
|
private void DoScan()
|
||||||
{
|
{
|
||||||
lvFirmwares.BeginUpdate();
|
lvFirmwares.BeginUpdate();
|
||||||
Manager.DoScanAndResolve(
|
Manager.DoScanAndResolve(
|
||||||
_config.PathEntries,
|
_pathEntries,
|
||||||
_config.FirmwareUserSpecifications);
|
_firmwareUserSpecifications);
|
||||||
|
|
||||||
// for each type of firmware, try resolving and record the result
|
// for each type of firmware, try resolving and record the result
|
||||||
foreach (ListViewItem lvi in lvFirmwares.Items)
|
foreach (ListViewItem lvi in lvFirmwares.Items)
|
||||||
{
|
{
|
||||||
var fr = lvi.Tag as FirmwareDatabase.FirmwareRecord;
|
var fr = lvi.Tag as FirmwareDatabase.FirmwareRecord;
|
||||||
var ri = Manager.Resolve(
|
var ri = Manager.Resolve(
|
||||||
_config.PathEntries,
|
_pathEntries,
|
||||||
_config.FirmwareUserSpecifications,
|
_firmwareUserSpecifications,
|
||||||
fr,
|
fr,
|
||||||
true);
|
true);
|
||||||
|
|
||||||
|
@ -285,7 +299,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// lazy substring extraction. really should do a better job
|
// lazy substring extraction. really should do a better job
|
||||||
var basePath = _config.PathEntries.FirmwareAbsolutePath() + Path.DirectorySeparatorChar;
|
var basePath = _pathEntries.FirmwareAbsolutePath() + Path.DirectorySeparatorChar;
|
||||||
|
|
||||||
var path = ri.FilePath.Replace(basePath, "");
|
var path = ri.FilePath.Replace(basePath, "");
|
||||||
|
|
||||||
|
@ -353,16 +367,16 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Manager.DoScanAndResolve(_config.PathEntries, _config.FirmwareUserSpecifications);
|
Manager.DoScanAndResolve(_pathEntries, _firmwareUserSpecifications);
|
||||||
|
|
||||||
foreach (var fr in FirmwareDatabase.FirmwareRecords)
|
foreach (var fr in FirmwareDatabase.FirmwareRecords)
|
||||||
{
|
{
|
||||||
var ri = Manager.Resolve(_config.PathEntries, _config.FirmwareUserSpecifications, fr);
|
var ri = Manager.Resolve(_pathEntries, _firmwareUserSpecifications, fr);
|
||||||
if (ri?.KnownFirmwareFile == null) continue;
|
if (ri?.KnownFirmwareFile == null) continue;
|
||||||
if (ri.UserSpecified) continue;
|
if (ri.UserSpecified) continue;
|
||||||
|
|
||||||
var fpTarget = Path.Combine(
|
var fpTarget = Path.Combine(
|
||||||
_config.PathEntries.FirmwareAbsolutePath(),
|
_pathEntries.FirmwareAbsolutePath(),
|
||||||
ri.KnownFirmwareFile.RecommendedName);
|
ri.KnownFirmwareFile.RecommendedName);
|
||||||
string fpSource = ri.FilePath;
|
string fpSource = ri.FilePath;
|
||||||
|
|
||||||
|
@ -382,7 +396,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private void TbbOpenFolder_Click(object sender, EventArgs e)
|
private void TbbOpenFolder_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var frmWares = _config.PathEntries.FirmwareAbsolutePath();
|
var frmWares = _pathEntries.FirmwareAbsolutePath();
|
||||||
if (!Directory.Exists(frmWares))
|
if (!Directory.Exists(frmWares))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(frmWares);
|
Directory.CreateDirectory(frmWares);
|
||||||
|
@ -418,7 +432,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
InitialDirectory = _currSelectorDir,
|
InitialDirectory = _currSelectorDir,
|
||||||
RestoreDirectory = true
|
RestoreDirectory = true
|
||||||
};
|
};
|
||||||
string firmwarePath = _config.PathEntries.FirmwareAbsolutePath();
|
string firmwarePath = _pathEntries.FirmwareAbsolutePath();
|
||||||
|
|
||||||
if (ofd.ShowDialog() == DialogResult.OK)
|
if (ofd.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
|
@ -481,7 +495,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_config.FirmwareUserSpecifications[fr.ConfigKey] = filePath;
|
_firmwareUserSpecifications[fr.ConfigKey] = filePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -500,7 +514,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
foreach (ListViewItem lvi in lvFirmwares.SelectedItems)
|
foreach (ListViewItem lvi in lvFirmwares.SelectedItems)
|
||||||
{
|
{
|
||||||
var fr = lvi.Tag as FirmwareDatabase.FirmwareRecord;
|
var fr = lvi.Tag as FirmwareDatabase.FirmwareRecord;
|
||||||
_config.FirmwareUserSpecifications.Remove(fr.ConfigKey);
|
_firmwareUserSpecifications.Remove(fr.ConfigKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
DoScan();
|
DoScan();
|
||||||
|
@ -594,7 +608,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var pathConfig = new PathConfig(_mainForm, _config, _game);
|
using var pathConfig = new PathConfig(Manager, _firmwareUserSpecifications, _game, _mainForm, _pathEntries);
|
||||||
pathConfig.ShowDialog(this);
|
pathConfig.ShowDialog(this);
|
||||||
RefreshBasePath();
|
RefreshBasePath();
|
||||||
}
|
}
|
||||||
|
@ -602,7 +616,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
private void RefreshBasePath()
|
private void RefreshBasePath()
|
||||||
{
|
{
|
||||||
string oldBasePath = _currSelectorDir;
|
string oldBasePath = _currSelectorDir;
|
||||||
linkBasePath.Text = _currSelectorDir = _config.PathEntries.FirmwareAbsolutePath();
|
linkBasePath.Text = _currSelectorDir = _pathEntries.FirmwareAbsolutePath();
|
||||||
if (oldBasePath != _currSelectorDir)
|
if (oldBasePath != _currSelectorDir)
|
||||||
{
|
{
|
||||||
DoScan();
|
DoScan();
|
||||||
|
@ -666,7 +680,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
private void RunImportJob(IEnumerable<string> files)
|
private void RunImportJob(IEnumerable<string> files)
|
||||||
{
|
{
|
||||||
bool didSomething = false;
|
bool didSomething = false;
|
||||||
var basePath = _config.PathEntries.FirmwareAbsolutePath();
|
var basePath = _pathEntries.FirmwareAbsolutePath();
|
||||||
string errors = "";
|
string errors = "";
|
||||||
foreach(var f in files)
|
foreach(var f in files)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,10 +12,16 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
public partial class PathConfig : Form
|
public partial class PathConfig : Form
|
||||||
{
|
{
|
||||||
private readonly Config _config;
|
private readonly FirmwareManager _firmwareManager;
|
||||||
|
|
||||||
|
private readonly IDictionary<string, string> _firmwareUserSpecifications;
|
||||||
|
|
||||||
private readonly IGameInfo _game;
|
private readonly IGameInfo _game;
|
||||||
|
|
||||||
private readonly IMainFormForConfig _mainForm;
|
private readonly IMainFormForConfig _mainForm;
|
||||||
|
|
||||||
|
private readonly PathEntryCollection _pathEntries;
|
||||||
|
|
||||||
// All path text boxes should do some kind of error checking
|
// All path text boxes should do some kind of error checking
|
||||||
// Config path under base, config will default to %exe%
|
// Config path under base, config will default to %exe%
|
||||||
private void LockDownCores()
|
private void LockDownCores()
|
||||||
|
@ -43,20 +49,27 @@ namespace BizHawk.Client.EmuHawk
|
||||||
"..\\"
|
"..\\"
|
||||||
};
|
};
|
||||||
|
|
||||||
public PathConfig(IMainFormForConfig mainForm, Config config, IGameInfo game)
|
public PathConfig(
|
||||||
|
FirmwareManager firmwareManager,
|
||||||
|
IDictionary<string, string> firmwareUserSpecifications,
|
||||||
|
IGameInfo game,
|
||||||
|
IMainFormForConfig mainForm,
|
||||||
|
PathEntryCollection pathEntries)
|
||||||
{
|
{
|
||||||
_mainForm = mainForm;
|
_firmwareManager = firmwareManager;
|
||||||
_config = config;
|
_firmwareUserSpecifications = firmwareUserSpecifications;
|
||||||
_game = game;
|
_game = game;
|
||||||
|
_mainForm = mainForm;
|
||||||
|
_pathEntries = pathEntries;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
SpecialCommandsBtn.Image = Properties.Resources.Help;
|
SpecialCommandsBtn.Image = Properties.Resources.Help;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadSettings()
|
private void LoadSettings()
|
||||||
{
|
{
|
||||||
RecentForROMs.Checked = _config.PathEntries.UseRecentForRoms;
|
RecentForROMs.Checked = _pathEntries.UseRecentForRoms;
|
||||||
|
|
||||||
DoTabs(_config.PathEntries.ToList());
|
DoTabs(_pathEntries.ToList());
|
||||||
SetDefaultFocusedTab();
|
SetDefaultFocusedTab();
|
||||||
DoRomToggle();
|
DoRomToggle();
|
||||||
}
|
}
|
||||||
|
@ -88,7 +101,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
PathTabControl.TabPages.Clear();
|
PathTabControl.TabPages.Clear();
|
||||||
|
|
||||||
// Separate by system
|
// Separate by system
|
||||||
var systems = _config.PathEntries
|
var systems = _pathEntries
|
||||||
.Select(s => s.SystemDisplayName)
|
.Select(s => s.SystemDisplayName)
|
||||||
.Distinct()
|
.Distinct()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
@ -112,7 +125,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
foreach (var systemDisplayName in systems)
|
foreach (var systemDisplayName in systems)
|
||||||
{
|
{
|
||||||
var systemId = _config.PathEntries.First(p => p.SystemDisplayName == systemDisplayName).System;
|
var systemId = _pathEntries.First(p => p.SystemDisplayName == systemDisplayName).System;
|
||||||
var t = new TabPage
|
var t = new TabPage
|
||||||
{
|
{
|
||||||
Text = systemDisplayName,
|
Text = systemDisplayName,
|
||||||
|
@ -179,7 +192,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var f = new FirmwaresConfig(_mainForm, _config, _game) { TargetSystem = "Global" };
|
using var f = new FirmwaresConfig(_firmwareManager, _firmwareUserSpecifications, _game, _mainForm, _pathEntries) { TargetSystem = "Global" };
|
||||||
f.ShowDialog(this);
|
f.ShowDialog(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -225,7 +238,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
using var f = new FolderBrowserDialog
|
using var f = new FolderBrowserDialog
|
||||||
{
|
{
|
||||||
Description = $"Set the directory for {name}",
|
Description = $"Set the directory for {name}",
|
||||||
SelectedPath = _config.PathEntries.AbsolutePathFor(box.Text, system)
|
SelectedPath = _pathEntries.AbsolutePathFor(box.Text, system)
|
||||||
};
|
};
|
||||||
result = f.ShowDialog();
|
result = f.ShowDialog();
|
||||||
selectedPath = f.SelectedPath;
|
selectedPath = f.SelectedPath;
|
||||||
|
@ -235,28 +248,28 @@ namespace BizHawk.Client.EmuHawk
|
||||||
using var f = new FolderBrowserEx
|
using var f = new FolderBrowserEx
|
||||||
{
|
{
|
||||||
Description = $"Set the directory for {name}",
|
Description = $"Set the directory for {name}",
|
||||||
SelectedPath = _config.PathEntries.AbsolutePathFor(box.Text, system)
|
SelectedPath = _pathEntries.AbsolutePathFor(box.Text, system)
|
||||||
};
|
};
|
||||||
result = f.ShowDialog();
|
result = f.ShowDialog();
|
||||||
selectedPath = f.SelectedPath;
|
selectedPath = f.SelectedPath;
|
||||||
}
|
}
|
||||||
if (result.IsOk())
|
if (result.IsOk())
|
||||||
{
|
{
|
||||||
box.Text = _config.PathEntries.TryMakeRelative(selectedPath, system);
|
box.Text = _pathEntries.TryMakeRelative(selectedPath, system);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveSettings()
|
private void SaveSettings()
|
||||||
{
|
{
|
||||||
_config.PathEntries.UseRecentForRoms = RecentForROMs.Checked;
|
_pathEntries.UseRecentForRoms = RecentForROMs.Checked;
|
||||||
|
|
||||||
foreach (var t in AllPathBoxes)
|
foreach (var t in AllPathBoxes)
|
||||||
{
|
{
|
||||||
var pathEntry = _config.PathEntries.First(p => p.System == t.Parent.Name && p.Type == t.Name);
|
var pathEntry = _pathEntries.First(p => p.System == t.Parent.Name && p.Type == t.Name);
|
||||||
pathEntry.Path = t.Text;
|
pathEntry.Path = t.Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
_mainForm.MovieSession.BackupDirectory = _config.PathEntries.MovieBackupsAbsolutePath();
|
_mainForm.MovieSession.BackupDirectory = _pathEntries.MovieBackupsAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoRomToggle()
|
private void DoRomToggle()
|
||||||
|
@ -326,7 +339,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
|
|
||||||
_config.PathEntries.RefreshTempPath();
|
_pathEntries.RefreshTempPath();
|
||||||
_mainForm.AddOnScreenMessage("Path settings saved");
|
_mainForm.AddOnScreenMessage("Path settings saved");
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue