FirmwareManager - don't depend on Global.Config
This commit is contained in:
parent
d1623c32b7
commit
16781fa212
|
@ -62,7 +62,7 @@ namespace BizHawk.Client.Common
|
|||
/// <exception cref="MissingFirmwareException">not found and <paramref name="required"/> is true</exception>
|
||||
public string GetFirmwarePath(string sysId, string firmwareId, bool required, string msg = null)
|
||||
{
|
||||
var path = FirmwareManager.Request(Global.Config.PathEntries.FirmwaresPathFragment, sysId, firmwareId);
|
||||
var path = FirmwareManager.Request(Global.Config.PathEntries.FirmwaresPathFragment, Global.Config.FirmwareUserSpecifications, sysId, firmwareId);
|
||||
if (path != null && !File.Exists(path))
|
||||
{
|
||||
path = null;
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace BizHawk.Client.Common
|
|||
public string FirmwareId { get; set; }
|
||||
}
|
||||
|
||||
public ResolutionInfo Resolve(string firmwaresPath, FirmwareDatabase.FirmwareRecord record, bool forbidScan = false)
|
||||
public ResolutionInfo Resolve(string firmwaresPath, IDictionary<string, string> userSpecifications, FirmwareDatabase.FirmwareRecord record, bool forbidScan = false)
|
||||
{
|
||||
// purpose of forbidScan: sometimes this is called from a loop in Scan(). we don't want to repeatedly DoScanAndResolve in that case, its already been done.
|
||||
bool first = true;
|
||||
|
@ -55,7 +55,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (!forbidScan)
|
||||
{
|
||||
DoScanAndResolve(firmwaresPath);
|
||||
DoScanAndResolve(firmwaresPath, userSpecifications);
|
||||
}
|
||||
|
||||
first = false;
|
||||
|
@ -66,9 +66,9 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
// Requests the specified firmware. tries really hard to scan and resolve as necessary
|
||||
public string Request(string firmwaresPath, string sysId, string firmwareId)
|
||||
public string Request(string firmwaresPath, IDictionary<string, string> userSpecifications, string sysId, string firmwareId)
|
||||
{
|
||||
var resolved = Resolve(firmwaresPath, FirmwareDatabase.LookupFirmwareRecord(sysId, firmwareId));
|
||||
var resolved = Resolve(firmwaresPath, userSpecifications, FirmwareDatabase.LookupFirmwareRecord(sysId, firmwareId));
|
||||
if (resolved == null)
|
||||
{
|
||||
return null;
|
||||
|
@ -138,7 +138,7 @@ namespace BizHawk.Client.Common
|
|||
return false;
|
||||
}
|
||||
|
||||
public void DoScanAndResolve(string firmwaresPath)
|
||||
public void DoScanAndResolve(string firmwaresPath, IDictionary<string, string> userSpecifications)
|
||||
{
|
||||
// build a list of file sizes. Only those will be checked during scanning
|
||||
var sizes = new HashSet<long>();
|
||||
|
@ -148,6 +148,7 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
using var reader = new RealFirmwareReader();
|
||||
|
||||
// build a list of files under the global firmwares path, and build a hash for each of them while we're at it
|
||||
var todo = new Queue<DirectoryInfo>();
|
||||
todo.Enqueue(new DirectoryInfo(PathManager.MakeAbsolutePath(firmwaresPath, null)));
|
||||
|
@ -162,9 +163,9 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
// we're going to allow recursing into subdirectories, now. its been verified to work OK
|
||||
foreach (var disub in di.GetDirectories())
|
||||
foreach (var subDir in di.GetDirectories())
|
||||
{
|
||||
todo.Enqueue(disub);
|
||||
todo.Enqueue(subDir);
|
||||
}
|
||||
|
||||
foreach (var fi in di.GetFiles())
|
||||
|
@ -217,7 +218,7 @@ namespace BizHawk.Client.Common
|
|||
foreach (var fr in FirmwareDatabase.FirmwareRecords)
|
||||
{
|
||||
// do we have a user specification for this firmware record?
|
||||
if (Global.Config.FirmwareUserSpecifications.TryGetValue(fr.ConfigKey, out var userSpec))
|
||||
if (userSpecifications.TryGetValue(fr.ConfigKey, out var userSpec))
|
||||
{
|
||||
// flag it as user specified
|
||||
if (!_resolutionDictionary.TryGetValue(fr, out ResolutionInfo ri))
|
||||
|
|
|
@ -965,13 +965,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
if (e is RomLoader.RomErrorArgs args)
|
||||
{
|
||||
using var configForm = new FirmwaresConfig(this, true, args.RomPath);
|
||||
using var configForm = new FirmwaresConfig(this, Config, true, args.RomPath);
|
||||
var result = configForm.ShowDialog();
|
||||
args.Retry = result == DialogResult.Retry;
|
||||
}
|
||||
else
|
||||
{
|
||||
using var configForm = new FirmwaresConfig(this);
|
||||
using var configForm = new FirmwaresConfig(this, Config);
|
||||
configForm.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
public partial class FirmwaresConfig : Form
|
||||
{
|
||||
private readonly MainForm _mainForm;
|
||||
private readonly Config _config;
|
||||
|
||||
// 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.
|
||||
|
@ -91,11 +92,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
private string _currSelectorDir;
|
||||
private readonly ListViewSorter _listViewSorter;
|
||||
|
||||
private string FirmwaresPath => Global.Config.PathEntries.FirmwaresPathFragment;
|
||||
|
||||
public FirmwaresConfig(MainForm mainForm, bool retryLoadRom = false, string reloadRomPath = null)
|
||||
public FirmwaresConfig(MainForm mainForm, Config config, bool retryLoadRom = false, string reloadRomPath = null)
|
||||
{
|
||||
_mainForm = mainForm;
|
||||
_config = config;
|
||||
InitializeComponent();
|
||||
|
||||
// prep ImageList for ListView with 3 item states for {idUnsure, idMissing, idOk}
|
||||
|
@ -247,15 +247,24 @@ namespace BizHawk.Client.EmuHawk
|
|||
private void DoScan()
|
||||
{
|
||||
lvFirmwares.BeginUpdate();
|
||||
Manager.DoScanAndResolve(FirmwaresPath);
|
||||
Manager.DoScanAndResolve(
|
||||
_config.PathEntries.FirmwaresPathFragment,
|
||||
_config.FirmwareUserSpecifications);
|
||||
|
||||
// for each type of firmware, try resolving and record the result
|
||||
foreach (ListViewItem lvi in lvFirmwares.Items)
|
||||
{
|
||||
var fr = lvi.Tag as FirmwareDatabase.FirmwareRecord;
|
||||
var ri = Manager.Resolve(FirmwaresPath, fr, true);
|
||||
for(int i=4;i<=7;i++)
|
||||
var ri = Manager.Resolve(
|
||||
_config.PathEntries.FirmwaresPathFragment,
|
||||
_config.FirmwareUserSpecifications,
|
||||
fr,
|
||||
true);
|
||||
|
||||
for (int i = 4; i <= 7; i++)
|
||||
{
|
||||
lvi.SubItems[i].Text = "";
|
||||
}
|
||||
|
||||
if (ri == null)
|
||||
{
|
||||
|
@ -333,11 +342,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
return;
|
||||
}
|
||||
|
||||
Manager.DoScanAndResolve(FirmwaresPath);
|
||||
Manager.DoScanAndResolve(_config.PathEntries.FirmwaresPathFragment, _config.FirmwareUserSpecifications);
|
||||
|
||||
foreach (var fr in FirmwareDatabase.FirmwareRecords)
|
||||
{
|
||||
var ri = Manager.Resolve(FirmwaresPath, fr);
|
||||
var ri = Manager.Resolve(_config.PathEntries.FirmwaresPathFragment, _config.FirmwareUserSpecifications, fr);
|
||||
if (ri?.KnownFirmwareFile == null) continue;
|
||||
if (ri.UserSpecified) continue;
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return;
|
||||
}
|
||||
|
||||
using var f = new FirmwaresConfig(_mainForm) { TargetSystem = "Global" };
|
||||
using var f = new FirmwaresConfig(_mainForm, _config) { TargetSystem = "Global" };
|
||||
f.ShowDialog(this);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue