From bbd21eb775acda319d1b78160cd6638297ebeb49 Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Mon, 17 Jun 2024 01:11:52 +0200 Subject: [PATCH] Prefill values in the MultiDiskBundler from currently loaded xml If the currently loaded "rom" is an xml, the MultiDiskBundler will now prefill its text boxes with the information from that xml instead of leaving everything empty. - closes #3947 --- .../MultiDiskBundler/MultiDiskBundler.cs | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs index fe1c288fca..c1fb48e989 100644 --- a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs +++ b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs @@ -8,6 +8,7 @@ using System.Xml.Linq; using BizHawk.Emulation.Common; using BizHawk.Client.Common; +using BizHawk.Common; using BizHawk.Common.PathExtensions; using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Cores.Sega.MasterSystem; @@ -59,7 +60,7 @@ namespace BizHawk.Client.EmuHawk AddButton_Click(null, null); AddButton_Click(null, null); - if (!Game.IsNullInstance() && !MainForm.CurrentlyOpenRom.EndsWithOrdinal(".xml")) + if (!Game.IsNullInstance()) { if (MainForm.CurrentlyOpenRom.Contains("|")) { @@ -69,10 +70,19 @@ namespace BizHawk.Client.EmuHawk var filename = Path.ChangeExtension(pieces[1], ".xml"); NameBox.Text = Path.Combine(directory, filename); + FileSelectors.First().Path = MainForm.CurrentlyOpenRom; } else { NameBox.Text = Path.ChangeExtension(MainForm.CurrentlyOpenRom, ".xml"); + if (MainForm.CurrentlyOpenRom.EndsWithOrdinal(".xml")) + { + PopulateFromXmlFile(MainForm.CurrentlyOpenRom); + } + else + { + FileSelectors.First().Path = MainForm.CurrentlyOpenRom; + } } if (SystemDropDown.Items.Contains(Emulator.SystemId)) @@ -83,8 +93,28 @@ namespace BizHawk.Client.EmuHawk { SystemDropDown.SelectedItem = VSystemID.Raw.GGL; } + } + } - FileSelectors.First().Path = MainForm.CurrentlyOpenRom; + private void PopulateFromXmlFile(string xmlPath) + { + try + { + var xmlGame = XmlGame.Create(new HawkFile(xmlPath)); + for (int i = FileSelectorPanel.Controls.Count; i < xmlGame.AssetFullPaths.Count; i++) + { + AddButton_Click(null, null); + } + + var fileSelectors = FileSelectors.ToArray(); + for (int i = 0; i < xmlGame.AssetFullPaths.Count; i++) + { + fileSelectors[i].Path = xmlGame.AssetFullPaths[i]; + } + } + catch + { + // something went wrong while parsing the given xml path... just don't populate anything then } }