FirmwaresConfig: Stop indescriminate importing (and some other things) - #314

This commit is contained in:
Asnivor 2018-09-13 15:07:52 +01:00
parent afc5d516b8
commit a04ad91b2c
4 changed files with 427 additions and 332 deletions

View File

@ -126,6 +126,37 @@ namespace BizHawk.Client.Common
public Dictionary<string, RealFirmwareFile> Dict { get; } = new Dictionary<string, RealFirmwareFile>();
}
/// <summary>
/// Test to determine whether the supplied firmware file matches something in the firmware database
/// For customization overrides then perhaps the user can copy into the firmware directory manually?
/// </summary>
/// <param name="f"></param>
/// <returns></returns>
public bool CanFileBeImported(string f)
{
try
{
var fi = new FileInfo(f);
if (!fi.Exists)
return false;
// weed out filesizes first to reduce the unnecessary overhead of a hashing operation
if (FirmwareDatabase.FirmwareFiles.Where(a => a.Size == fi.Length).FirstOrDefault() == null)
return false;
// check the hash
using (var reader = new RealFirmwareReader())
{
reader.Read(fi);
if (FirmwareDatabase.FirmwareFiles.Where(a => a.Hash == reader.Dict.FirstOrDefault().Value.Hash).FirstOrDefault() != null)
return true;
}
}
catch { }
return false;
}
public void DoScanAndResolve()
{
// build a list of file sizes. Only those will be checked during scanning

View File

@ -61,6 +61,7 @@
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.tbbOpenFolder = new System.Windows.Forms.ToolStripButton();
this.lvFirmwaresContextMenuStrip.SuspendLayout();
this.panel1.SuspendLayout();
this.toolStrip1.SuspendLayout();
@ -201,7 +202,8 @@
this.tbbImport,
this.tbbClose,
this.toolStripSeparator1,
this.tbbCloseReload});
this.tbbCloseReload,
this.tbbOpenFolder});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(824, 25);
@ -345,10 +347,20 @@
this.label2.Location = new System.Drawing.Point(5, 5);
this.label2.Margin = new System.Windows.Forms.Padding(5, 5, 3, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(383, 13);
this.label2.Size = new System.Drawing.Size(395, 13);
this.label2.TabIndex = 27;
this.label2.Text = "Firmware such as BIOS files are copyrighted material and not provided by BizHawk";
//
// tbbOpenFolder
//
this.tbbOpenFolder.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tbbOpenFolder.Image = ((System.Drawing.Image)(resources.GetObject("tbbOpenFolder.Image")));
this.tbbOpenFolder.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tbbOpenFolder.Name = "tbbOpenFolder";
this.tbbOpenFolder.Size = new System.Drawing.Size(128, 22);
this.tbbOpenFolder.Text = "Open Firmware Folder";
this.tbbOpenFolder.Click += new System.EventHandler(this.tbbOpenFolder_Click);
//
// FirmwaresConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -407,5 +419,6 @@
private System.Windows.Forms.ToolStripButton tbbCloseReload;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ToolStripButton tbbOpenFolder;
}
}

View File

@ -341,6 +341,12 @@ namespace BizHawk.Client.EmuHawk
DoScan();
}
private void tbbOpenFolder_Click(object sender, EventArgs e)
{
var frmWares = PathManager.MakeAbsolutePath(Global.Config.PathEntries.FirmwaresPathFragment, null);
System.Diagnostics.Process.Start(frmWares);
}
private void lvFirmwares_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift)
@ -367,6 +373,7 @@ namespace BizHawk.Client.EmuHawk
{
ofd.InitialDirectory = currSelectorDir;
ofd.RestoreDirectory = true;
string frmwarePath = PathManager.MakeAbsolutePath(Global.Config.PathEntries.FirmwaresPathFragment, null);
if (ofd.ShowDialog() == DialogResult.OK)
{
@ -377,7 +384,29 @@ namespace BizHawk.Client.EmuHawk
foreach (ListViewItem lvi in lvFirmwares.SelectedItems)
{
var fr = lvi.Tag as FirmwareDatabase.FirmwareRecord;
Global.Config.FirmwareUserSpecifications[fr.ConfigKey] = ofd.FileName;
string filePath = ofd.FileName;
// check whether this file is currently outside of the global firmware directory
if (currSelectorDir != frmwarePath)
{
var askMoveResult = MessageBox.Show(this, "The selected custom firmware does not reside in the root of the global firmware directory.\nDo you want to copy it there?", "Import Custom Firmware", MessageBoxButtons.YesNo);
if (askMoveResult == DialogResult.Yes)
{
try
{
FileInfo fi = new FileInfo(filePath);
filePath = Path.Combine(frmwarePath, fi.Name);
File.Copy(ofd.FileName, filePath);
}
catch (Exception ex)
{
MessageBox.Show(this, "There was an issue copying the file. The customization has NOT been set.\n\n" + ex.StackTrace);
continue;
}
}
}
Global.Config.FirmwareUserSpecifications[fr.ConfigKey] = filePath;
}
DoScan();
@ -584,7 +613,11 @@ namespace BizHawk.Client.EmuHawk
outfile = Path.Combine(extractpath, myname);
File.WriteAllBytes(outfile, ms.ToArray());
hf.Unbind();
if (Manager.CanFileBeImported(outfile))
{
didSomething |= RunImportJobSingle(basepath, outfile, ref errors);
}
}
}
finally
@ -594,10 +627,13 @@ namespace BizHawk.Client.EmuHawk
}
else
{
if (Manager.CanFileBeImported(hf.CanonicalFullPath))
{
didSomething |= RunImportJobSingle(basepath, f, ref errors);
}
}
}
}
if (!string.IsNullOrEmpty(errors))
{

View File

@ -215,6 +215,21 @@
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
</value>
</data>
<data name="tbbOpenFolder.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">