From f26601f80295101e87f1017c4445d5717a468d9d Mon Sep 17 00:00:00 2001 From: Souryo Date: Fri, 8 Sep 2017 14:03:10 -0400 Subject: [PATCH] Patches: Allow patches in the same folder as a single rom to automatically load the rom when the patch is loaded --- GUI.NET/Forms/frmMain.File.cs | 38 +++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/GUI.NET/Forms/frmMain.File.cs b/GUI.NET/Forms/frmMain.File.cs index 3e1e9c31..7912346e 100644 --- a/GUI.NET/Forms/frmMain.File.cs +++ b/GUI.NET/Forms/frmMain.File.cs @@ -168,21 +168,37 @@ namespace Mesen.GUI.Forms private void LoadPatchFile(string patchFile) { - if(_emuThread == null) { - if(MesenMsgBox.Show("SelectRomIps", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { - using(OpenFileDialog ofd = new OpenFileDialog()) { - ofd.SetFilter(ResourceHelper.GetMessage("FilterRom")); - if(ConfigManager.Config.RecentFiles.Count > 0) { - ofd.InitialDirectory = ConfigManager.Config.RecentFiles[0].RomFile.Folder; - } + string patchFolder = Path.GetDirectoryName(patchFile); + HashSet romExtensions = new HashSet() { ".nes", ".fds", ".unf" }; + List romsInFolder = new List(); + foreach(string filepath in Directory.EnumerateFiles(patchFolder)) { + if(romExtensions.Contains(Path.GetExtension(filepath).ToLowerInvariant())) { + romsInFolder.Add(filepath); + } + } - if(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { - LoadROM(ofd.FileName, true, patchFile); + 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) { + //Prompt the user for a rom to load + if(MesenMsgBox.Show("SelectRomIps", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { + using(OpenFileDialog ofd = new OpenFileDialog()) { + ofd.SetFilter(ResourceHelper.GetMessage("FilterRom")); + if(ConfigManager.Config.RecentFiles.Count > 0) { + ofd.InitialDirectory = ConfigManager.Config.RecentFiles[0].RomFile.Folder; + } + + if(ofd.ShowDialog() == DialogResult.OK) { + LoadROM(ofd.FileName, true, patchFile); + } } } + } 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); } - } else if(MesenMsgBox.Show("PatchAndReset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { - LoadROM(_currentRomPath.Value, true, patchFile); } }