FirmwaresConfig: set customization file chooser now incorporates ArchiveChooser - if an insidefile is selected this is copied to the global firmwares folder

This commit is contained in:
Asnivor 2018-09-14 09:46:39 +01:00
parent 163a370be0
commit 35afeb2b3d
1 changed files with 59 additions and 21 deletions

View File

@ -380,12 +380,42 @@ namespace BizHawk.Client.EmuHawk
// remember the location we selected this firmware from, maybe there are others // remember the location we selected this firmware from, maybe there are others
currSelectorDir = Path.GetDirectoryName(ofd.FileName); currSelectorDir = Path.GetDirectoryName(ofd.FileName);
try
{
using (var hf = new HawkFile(ofd.FileName))
{
// for each selected item, set the user choice (even though multiple selection for this operation is no longer allowed) // for each selected item, set the user choice (even though multiple selection for this operation is no longer allowed)
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;
string filePath = ofd.FileName; string filePath = ofd.FileName;
// if the selected file is an archive, allow the user to pick the inside file
// to always be copied to the global firmwares directory
if (hf.IsArchive)
{
var ac = new ArchiveChooser(new HawkFile(filePath));
int memIdx = -1;
if (ac.ShowDialog(this) == DialogResult.OK)
{
memIdx = ac.SelectedMemberIndex;
}
else
{
return;
}
var insideFile = hf.BindArchiveMember(memIdx);
var fileData = insideFile.ReadAllBytes();
// write to file in the firmwares folder
File.WriteAllBytes(Path.Combine(frmwarePath, insideFile.Name), fileData);
filePath = Path.Combine(frmwarePath, insideFile.Name);
}
else
{
// selected file is not an archive
// check whether this file is currently outside of the global firmware directory // check whether this file is currently outside of the global firmware directory
if (currSelectorDir != frmwarePath) if (currSelectorDir != frmwarePath)
{ {
@ -405,9 +435,17 @@ namespace BizHawk.Client.EmuHawk
} }
} }
} }
}
Global.Config.FirmwareUserSpecifications[fr.ConfigKey] = filePath; Global.Config.FirmwareUserSpecifications[fr.ConfigKey] = filePath;
} }
}
}
catch (Exception ex)
{
MessageBox.Show(this, "There was an issue during the process. The customization has NOT been set.\n\n" + ex.StackTrace);
return;
}
DoScan(); DoScan();
} }