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>
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))
{
path = null;

View File

@ -41,7 +41,7 @@ namespace BizHawk.Client.Common
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.
bool first = true;
@ -55,7 +55,7 @@ namespace BizHawk.Client.Common
{
if (!forbidScan)
{
DoScanAndResolve();
DoScanAndResolve(firmwaresPath);
}
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 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)
{
return null;
@ -138,7 +138,7 @@ namespace BizHawk.Client.Common
return false;
}
public void DoScanAndResolve()
public void DoScanAndResolve(string firmwaresPath)
{
// build a list of file sizes. Only those will be checked during scanning
var sizes = new HashSet<long>();
@ -150,7 +150,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(Global.Config.PathEntries.FirmwaresPathFragment, null)));
todo.Enqueue(new DirectoryInfo(PathManager.MakeAbsolutePath(firmwaresPath, null)));
while (todo.Count != 0)
{

View File

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