From ea72da9f89b3cab0bbbfd4c8c873838ae575e371 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 10 May 2015 18:58:00 +0000 Subject: [PATCH] Refector xml game, it now has a List of keyvalue pairs instead of dictionary, and the schema is now LoadAssets with an array of Asset tags. MultiDiskBundler changes to account for this, also remove restriction of using current rom based on system type, isntead it will assume any system is ok --- BizHawk.Client.Common/RomLoader.cs | 13 +++++++++---- BizHawk.Client.Common/XmlGame.cs | 17 +++++++++++------ .../tools/MultiDiskBundler/MultiDiskBundler.cs | 12 ++++++------ .../MultiDiskBundler/MultiDiskFileSelector.cs | 3 +-- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/BizHawk.Client.Common/RomLoader.cs b/BizHawk.Client.Common/RomLoader.cs index d6afe9aa0d..b18c9ebf63 100644 --- a/BizHawk.Client.Common/RomLoader.cs +++ b/BizHawk.Client.Common/RomLoader.cs @@ -323,15 +323,20 @@ namespace BizHawk.Client.Common switch (game.System) { + case "GB": case "DGB": - var left = Database.GetGameInfo(xmlGame.Assets["LeftRom"], "left.gb"); - var right = Database.GetGameInfo(xmlGame.Assets["RightRom"], "right.gb"); + // adelikat: remove need for tags to be hardcoded to left and right, we should clean this up, also maybe the DGB core should just take the xml file and handle it itself + var leftBytes = xmlGame.Assets.First().Value; + var rightBytes = xmlGame.Assets.Skip(1).First().Value; + + var left = Database.GetGameInfo(leftBytes, "left.gb"); + var right = Database.GetGameInfo(rightBytes, "right.gb"); nextEmulator = new GambatteLink( nextComm, left, - xmlGame.Assets["LeftRom"], + leftBytes, right, - xmlGame.Assets["RightRom"], + rightBytes, GetCoreSettings(), GetCoreSyncSettings(), Deterministic); diff --git a/BizHawk.Client.Common/XmlGame.cs b/BizHawk.Client.Common/XmlGame.cs index d99ece5dd2..8d7f7bfab6 100644 --- a/BizHawk.Client.Common/XmlGame.cs +++ b/BizHawk.Client.Common/XmlGame.cs @@ -13,9 +13,15 @@ namespace BizHawk.Client.Common { public class XmlGame { + public XmlGame() + { + Assets = new List>(); + GI = new GameInfo(); + } + public XmlDocument Xml { get; set; } - public GameInfo GI = new GameInfo(); - public Dictionary Assets = new Dictionary(); + public GameInfo GI { get; set; } + public IList> Assets { get; set; } public static XmlGame Create(HawkFile f) { @@ -48,7 +54,6 @@ namespace BizHawk.Client.Common foreach (XmlNode a in n.ChildNodes) { - string name = a.Name; string filename = a.Attributes["FileName"].Value; byte[] data; if (filename[0] == '|') @@ -68,7 +73,7 @@ namespace BizHawk.Client.Common } else { - throw new Exception("Couldn't load XMLGame LoadAsset \"" + name + "\""); + throw new Exception("Couldn't load XMLGame Asset \"" + filename + "\""); } } else @@ -82,11 +87,11 @@ namespace BizHawk.Client.Common } catch { - throw new Exception("Couldn't load XMLGame LoadAsset \"" + name + "\""); + throw new Exception("Couldn't load XMLGame LoadAsset \"" + filename + "\""); } } - ret.Assets[name] = data; + ret.Assets.Add(new KeyValuePair(filename, data)); using (var sha1 = System.Security.Cryptography.SHA1.Create()) { diff --git a/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs b/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs index 0af1786c56..257cb4c868 100644 --- a/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs +++ b/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs @@ -27,7 +27,7 @@ namespace BizHawk.Client.EmuHawk { if (!Global.Game.IsNullInstance) { - NameBox.Text = Path.ChangeExtension(PathManager.FilesystemSafeName(Global.Game), ".xml"); + NameBox.Text = Path.ChangeExtension(GlobalWin.MainForm.CurrentlyOpenRom, ".xml"); } AddButton_Click(null, null); @@ -92,6 +92,8 @@ namespace BizHawk.Client.EmuHawk DialogResult = DialogResult.OK; Close(); + + GlobalWin.MainForm.LoadRom(fileInfo.FullName); } } @@ -158,15 +160,13 @@ namespace BizHawk.Client.EmuHawk string system = Global.Emulator.SystemId; // TODO: have the user pick this? - var tagNames = names.Select(n => Path.GetFileNameWithoutExtension(n)); - _currentXml = new XElement("BizHawk-XMLGame", new XAttribute("System", system), - new XAttribute("Name", Path.GetFileNameWithoutExtension(name)), + new XAttribute("Name", name), new XElement("LoadAssets", names.Select(n => new XElement( - ConvertToTag(Path.GetFileNameWithoutExtension(n)), - new XAttribute("FileName", n) + "Asset", + new XAttribute("FileName", n) )) ) ); diff --git a/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskFileSelector.cs b/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskFileSelector.cs index 92aa9bc601..26fa36ce65 100644 --- a/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskFileSelector.cs +++ b/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskFileSelector.cs @@ -104,8 +104,7 @@ namespace BizHawk.Client.EmuHawk { UseCurrentRomButton.Enabled = Global.Emulator != null // For the designer && !string.IsNullOrEmpty(GlobalWin.MainForm.CurrentlyOpenRom) - && !GlobalWin.MainForm.CurrentlyOpenRom.Contains('|') && // Can't be archive - !GlobalWin.MainForm.CurrentlyOpenRom.Contains(".xml"); // Can't already be an xml + && !GlobalWin.MainForm.CurrentlyOpenRom.Contains(".xml"); // Can't already be an xml } private void PathBox_TextChanged(object sender, EventArgs e)