Patches: Allow patches in the same folder as a single rom to automatically load the rom when the patch is loaded

This commit is contained in:
Souryo 2017-09-08 14:03:10 -04:00
parent e64e4731f2
commit f26601f802

View file

@ -168,23 +168,39 @@ namespace Mesen.GUI.Forms
private void LoadPatchFile(string patchFile) private void LoadPatchFile(string patchFile)
{ {
string patchFolder = Path.GetDirectoryName(patchFile);
HashSet<string> romExtensions = new HashSet<string>() { ".nes", ".fds", ".unf" };
List<string> romsInFolder = new List<string>();
foreach(string filepath in Directory.EnumerateFiles(patchFolder)) {
if(romExtensions.Contains(Path.GetExtension(filepath).ToLowerInvariant())) {
romsInFolder.Add(filepath);
}
}
if(romsInFolder.Count == 1) {
//There is a single rom in the same folder as the IPS/BPS patch, use it automatically
LoadROM(romsInFolder[0], true, patchFile);
} else {
if(_emuThread == null) { if(_emuThread == null) {
if(MesenMsgBox.Show("SelectRomIps", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { //Prompt the user for a rom to load
if(MesenMsgBox.Show("SelectRomIps", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) {
using(OpenFileDialog ofd = new OpenFileDialog()) { using(OpenFileDialog ofd = new OpenFileDialog()) {
ofd.SetFilter(ResourceHelper.GetMessage("FilterRom")); ofd.SetFilter(ResourceHelper.GetMessage("FilterRom"));
if(ConfigManager.Config.RecentFiles.Count > 0) { if(ConfigManager.Config.RecentFiles.Count > 0) {
ofd.InitialDirectory = ConfigManager.Config.RecentFiles[0].RomFile.Folder; ofd.InitialDirectory = ConfigManager.Config.RecentFiles[0].RomFile.Folder;
} }
if(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if(ofd.ShowDialog() == DialogResult.OK) {
LoadROM(ofd.FileName, true, patchFile); LoadROM(ofd.FileName, true, patchFile);
} }
} }
} }
} else if(MesenMsgBox.Show("PatchAndReset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { } else if(MesenMsgBox.Show("PatchAndReset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) {
//Confirm that the user wants to patch the current rom and reset
LoadROM(_currentRomPath.Value, true, patchFile); LoadROM(_currentRomPath.Value, true, patchFile);
} }
} }
}
private void LoadROM(ResourcePath romFile, bool autoLoadPatches = false, ResourcePath? patchFileToApply = null) private void LoadROM(ResourcePath romFile, bool autoLoadPatches = false, ResourcePath? patchFileToApply = null)
{ {