Firmwares manager - depend on Global.Config less

This commit is contained in:
adelikat 2020-03-14 12:10:53 -05:00
parent 51539ebebd
commit d1623c32b7
3 changed files with 17 additions and 14 deletions

View File

@ -62,7 +62,7 @@ namespace BizHawk.Client.Common
/// <exception cref="MissingFirmwareException">not found and <paramref name="required"/> is true</exception> /// <exception cref="MissingFirmwareException">not found and <paramref name="required"/> is true</exception>
public string GetFirmwarePath(string sysId, string firmwareId, bool required, string msg = null) public string GetFirmwarePath(string sysId, string firmwareId, bool required, string msg = null)
{ {
var path = FirmwareManager.Request(sysId, firmwareId); var path = FirmwareManager.Request(Global.Config.PathEntries.FirmwaresPathFragment, sysId, firmwareId);
if (path != null && !File.Exists(path)) if (path != null && !File.Exists(path))
{ {
path = null; path = null;

View File

@ -41,7 +41,7 @@ namespace BizHawk.Client.Common
public string FirmwareId { get; set; } public string FirmwareId { get; set; }
} }
public ResolutionInfo Resolve(FirmwareDatabase.FirmwareRecord record, bool forbidScan = false) public ResolutionInfo Resolve(string firmwaresPath, 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. // 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; bool first = true;
@ -55,7 +55,7 @@ namespace BizHawk.Client.Common
{ {
if (!forbidScan) if (!forbidScan)
{ {
DoScanAndResolve(); DoScanAndResolve(firmwaresPath);
} }
first = false; first = false;
@ -66,9 +66,9 @@ namespace BizHawk.Client.Common
} }
// Requests the specified firmware. tries really hard to scan and resolve as necessary // Requests the specified firmware. tries really hard to scan and resolve as necessary
public string Request(string sysId, string firmwareId) public string Request(string firmwaresPath, string sysId, string firmwareId)
{ {
var resolved = Resolve(FirmwareDatabase.LookupFirmwareRecord(sysId, firmwareId)); var resolved = Resolve(firmwaresPath, FirmwareDatabase.LookupFirmwareRecord(sysId, firmwareId));
if (resolved == null) if (resolved == null)
{ {
return null; return null;
@ -138,7 +138,7 @@ namespace BizHawk.Client.Common
return false; return false;
} }
public void DoScanAndResolve() public void DoScanAndResolve(string firmwaresPath)
{ {
// build a list of file sizes. Only those will be checked during scanning // build a list of file sizes. Only those will be checked during scanning
var sizes = new HashSet<long>(); var sizes = new HashSet<long>();
@ -150,7 +150,7 @@ namespace BizHawk.Client.Common
using var reader = new RealFirmwareReader(); 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 // 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>(); var todo = new Queue<DirectoryInfo>();
todo.Enqueue(new DirectoryInfo(PathManager.MakeAbsolutePath(Global.Config.PathEntries.FirmwaresPathFragment, null))); todo.Enqueue(new DirectoryInfo(PathManager.MakeAbsolutePath(firmwaresPath, null)));
while (todo.Count != 0) while (todo.Count != 0)
{ {

View File

@ -91,6 +91,8 @@ namespace BizHawk.Client.EmuHawk
private string _currSelectorDir; private string _currSelectorDir;
private readonly ListViewSorter _listViewSorter; 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, bool retryLoadRom = false, string reloadRomPath = null)
{ {
_mainForm = mainForm; _mainForm = mainForm;
@ -245,13 +247,13 @@ namespace BizHawk.Client.EmuHawk
private void DoScan() private void DoScan()
{ {
lvFirmwares.BeginUpdate(); lvFirmwares.BeginUpdate();
Manager.DoScanAndResolve(); Manager.DoScanAndResolve(FirmwaresPath);
// 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(fr, true); var ri = Manager.Resolve(FirmwaresPath, fr, true);
for(int i=4;i<=7;i++) for(int i=4;i<=7;i++)
lvi.SubItems[i].Text = ""; lvi.SubItems[i].Text = "";
@ -315,8 +317,9 @@ namespace BizHawk.Client.EmuHawk
lvi.SubItems[6].Text = ri.Size.ToString(); lvi.SubItems[6].Text = ri.Size.ToString();
if (ri.Hash != null) lvi.SubItems[7].Text = $"sha1:{ri.Hash}"; lvi.SubItems[7].Text = ri.Hash != null
else lvi.SubItems[7].Text = ""; ? $"sha1:{ri.Hash}"
: "";
} }
} }
@ -330,11 +333,11 @@ namespace BizHawk.Client.EmuHawk
return; return;
} }
Manager.DoScanAndResolve(); Manager.DoScanAndResolve(FirmwaresPath);
foreach (var fr in FirmwareDatabase.FirmwareRecords) foreach (var fr in FirmwareDatabase.FirmwareRecords)
{ {
var ri = Manager.Resolve(fr); var ri = Manager.Resolve(FirmwaresPath, fr);
if (ri?.KnownFirmwareFile == null) continue; if (ri?.KnownFirmwareFile == null) continue;
if (ri.UserSpecified) continue; if (ri.UserSpecified) continue;
@ -650,7 +653,7 @@ namespace BizHawk.Client.EmuHawk
{ {
// blech. the worst extraction code in the universe. // blech. the worst extraction code in the universe.
string extractPath = $"{Path.GetTempFileName()}.dir"; string extractPath = $"{Path.GetTempFileName()}.dir";
DirectoryInfo di = Directory.CreateDirectory(extractPath); var di = Directory.CreateDirectory(extractPath);
try try
{ {