From 38f69f9dcc081d079ec016e18be98ad88959151f Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 24 Aug 2020 13:43:37 -0700 Subject: [PATCH] Fix of-tags, more CMP writing --- SabreTools.Library/DatFiles/ClrMamePro.cs | 62 +++++++------------- SabreTools.Library/DatFiles/DosCenter.cs | 19 +++--- SabreTools.Library/DatFiles/EverdriveSmdb.cs | 1 - SabreTools.Library/DatFiles/Listxml.cs | 6 +- SabreTools.Library/DatFiles/Logiqx.cs | 6 +- SabreTools.Library/DatFiles/SoftwareList.cs | 2 +- SabreTools.Library/IO/ClrMameProWriter.cs | 17 ++++++ 7 files changed, 56 insertions(+), 57 deletions(-) diff --git a/SabreTools.Library/DatFiles/ClrMamePro.cs b/SabreTools.Library/DatFiles/ClrMamePro.cs index b8610b94..56688a6a 100644 --- a/SabreTools.Library/DatFiles/ClrMamePro.cs +++ b/SabreTools.Library/DatFiles/ClrMamePro.cs @@ -548,28 +548,18 @@ namespace SabreTools.Library.DatFiles { cmpw.WriteStartElement("clrmamepro"); - cmpw.WriteStandalone("name", Header.Name); - cmpw.WriteStandalone("description", Header.Description); - if (!string.IsNullOrWhiteSpace(Header.Category)) - cmpw.WriteStandalone("category", Header.Category); - cmpw.WriteStandalone("version", Header.Version); - if (!string.IsNullOrWhiteSpace(Header.Date)) - cmpw.WriteStandalone("date", Header.Date); - cmpw.WriteStandalone("author", Header.Author); - if (!string.IsNullOrWhiteSpace(Header.Email)) - cmpw.WriteStandalone("email", Header.Email); - if (!string.IsNullOrWhiteSpace(Header.Homepage)) - cmpw.WriteStandalone("homepage", Header.Homepage); - if (!string.IsNullOrWhiteSpace(Header.Url)) - cmpw.WriteStandalone("url", Header.Url); - if (!string.IsNullOrWhiteSpace(Header.Comment)) - cmpw.WriteStandalone("comment", Header.Comment); - - if (Header.ForcePacking != PackingFlag.None) - cmpw.WriteStandalone("forcezipping", Header.ForcePacking.FromPackingFlag(true), false); - - if (Header.ForceMerging != MergingFlag.None) - cmpw.WriteStandalone("forcemerging", Header.ForceMerging.FromMergingFlag(false), false); + cmpw.WriteRequiredStandalone("name", Header.Name); + cmpw.WriteRequiredStandalone("description", Header.Description); + cmpw.WriteOptionalStandalone("category", Header.Category); + cmpw.WriteRequiredStandalone("version", Header.Version); + cmpw.WriteOptionalStandalone("date", Header.Date); + cmpw.WriteRequiredStandalone("author", Header.Author); + cmpw.WriteOptionalStandalone("email", Header.Email); + cmpw.WriteOptionalStandalone("homepage", Header.Homepage); + cmpw.WriteOptionalStandalone("url", Header.Url); + cmpw.WriteOptionalStandalone("comment", Header.Comment); + cmpw.WriteOptionalStandalone("forcezipping", Header.ForcePacking.FromPackingFlag(true), false); + cmpw.WriteOptionalStandalone("forcemerging", Header.ForceMerging.FromMergingFlag(false), false); // End clrmamepro cmpw.WriteEndElement(); @@ -600,23 +590,14 @@ namespace SabreTools.Library.DatFiles // Build the state cmpw.WriteStartElement(datItem.Machine.MachineType == MachineType.Bios ? "resource" : "game"); - cmpw.WriteStandalone("name", datItem.Machine.Name); - if (!string.IsNullOrWhiteSpace(datItem.Machine.RomOf)) - cmpw.WriteStandalone("romof", datItem.Machine.RomOf); - if (!string.IsNullOrWhiteSpace(datItem.Machine.CloneOf)) - cmpw.WriteStandalone("cloneof", datItem.Machine.CloneOf); - if (!string.IsNullOrWhiteSpace(datItem.Machine.SampleOf)) - cmpw.WriteStandalone("sampleof", datItem.Machine.SampleOf); - if (!string.IsNullOrWhiteSpace(datItem.Machine.Description)) - cmpw.WriteStandalone("description", datItem.Machine.Description); - else if (!string.IsNullOrWhiteSpace(datItem.Machine.Description)) - cmpw.WriteStandalone("description", datItem.Machine.Name); - if (!string.IsNullOrWhiteSpace(datItem.Machine.Year)) - cmpw.WriteStandalone("year", datItem.Machine.Year); - if (!string.IsNullOrWhiteSpace(datItem.Machine.Manufacturer)) - cmpw.WriteStandalone("manufacturer", datItem.Machine.Manufacturer); - if (!string.IsNullOrWhiteSpace(datItem.Machine.Category)) - cmpw.WriteStandalone("category", datItem.Machine.Category); + + cmpw.WriteRequiredStandalone("name", datItem.Machine.Name); + cmpw.WriteOptionalStandalone("romof", datItem.Machine.RomOf); + cmpw.WriteOptionalStandalone("cloneof", datItem.Machine.CloneOf); + cmpw.WriteOptionalStandalone("description", datItem.Machine.Description ?? datItem.Machine.Name); + cmpw.WriteOptionalStandalone("year", datItem.Machine.Year); + cmpw.WriteOptionalStandalone("manufacturer", datItem.Machine.Manufacturer); + cmpw.WriteOptionalStandalone("category", datItem.Machine.Category); cmpw.Flush(); } @@ -640,8 +621,7 @@ namespace SabreTools.Library.DatFiles try { // Build the state - if (!string.IsNullOrWhiteSpace(datItem.Machine.SampleOf)) - cmpw.WriteStandalone("sampleof", datItem.Machine.SampleOf); + cmpw.WriteOptionalStandalone("sampleof", datItem.Machine.SampleOf); // End game cmpw.WriteEndElement(); diff --git a/SabreTools.Library/DatFiles/DosCenter.cs b/SabreTools.Library/DatFiles/DosCenter.cs index 0736bf66..f12e890f 100644 --- a/SabreTools.Library/DatFiles/DosCenter.cs +++ b/SabreTools.Library/DatFiles/DosCenter.cs @@ -375,14 +375,17 @@ namespace SabreTools.Library.DatFiles { try { + // Build the state cmpw.WriteStartElement("DOSCenter"); - cmpw.WriteStandalone("Name:", Header.Name, false); - cmpw.WriteStandalone("Description:", Header.Description, false); - cmpw.WriteStandalone("Version:", Header.Version, false); - cmpw.WriteStandalone("Date:", Header.Date, false); - cmpw.WriteStandalone("Author:", Header.Author, false); - cmpw.WriteStandalone("Homepage:", Header.Homepage, false); - cmpw.WriteStandalone("Comment:", Header.Comment, false); + + cmpw.WriteRequiredStandalone("Name:", Header.Name, false); + cmpw.WriteRequiredStandalone("Description:", Header.Description, false); + cmpw.WriteRequiredStandalone("Version:", Header.Version, false); + cmpw.WriteRequiredStandalone("Date:", Header.Date, false); + cmpw.WriteRequiredStandalone("Author:", Header.Author, false); + cmpw.WriteRequiredStandalone("Homepage:", Header.Homepage, false); + cmpw.WriteRequiredStandalone("Comment:", Header.Comment, false); + cmpw.WriteEndElement(); cmpw.Flush(); @@ -411,7 +414,7 @@ namespace SabreTools.Library.DatFiles // Build the state cmpw.WriteStartElement("game"); - cmpw.WriteStandalone("name", $"{datItem.Machine.Name}.zip", true); + cmpw.WriteRequiredStandalone("name", $"{datItem.Machine.Name}.zip", true); cmpw.Flush(); } diff --git a/SabreTools.Library/DatFiles/EverdriveSmdb.cs b/SabreTools.Library/DatFiles/EverdriveSmdb.cs index 2ac594d1..e6737502 100644 --- a/SabreTools.Library/DatFiles/EverdriveSmdb.cs +++ b/SabreTools.Library/DatFiles/EverdriveSmdb.cs @@ -6,7 +6,6 @@ using System.Text; using SabreTools.Library.Data; using SabreTools.Library.DatItems; using SabreTools.Library.IO; -using SabreTools.Library.Tools; namespace SabreTools.Library.DatFiles { diff --git a/SabreTools.Library/DatFiles/Listxml.cs b/SabreTools.Library/DatFiles/Listxml.cs index 52b585f7..f938df2d 100644 --- a/SabreTools.Library/DatFiles/Listxml.cs +++ b/SabreTools.Library/DatFiles/Listxml.cs @@ -142,9 +142,9 @@ namespace SabreTools.Library.DatFiles Name = reader.GetAttribute("name"), Comment = string.Empty, Description = reader.GetAttribute("name"), - CloneOf = reader.GetAttribute("cloneof") ?? string.Empty, - RomOf = reader.GetAttribute("romof") ?? string.Empty, - SampleOf = reader.GetAttribute("sampleof") ?? string.Empty, + CloneOf = reader.GetAttribute("cloneof"), + RomOf = reader.GetAttribute("romof"), + SampleOf = reader.GetAttribute("sampleof"), MachineType = (machineType == MachineType.NULL ? MachineType.None : machineType), SourceFile = reader.GetAttribute("sourcefile"), diff --git a/SabreTools.Library/DatFiles/Logiqx.cs b/SabreTools.Library/DatFiles/Logiqx.cs index 9ace3bc1..4a06fa8a 100644 --- a/SabreTools.Library/DatFiles/Logiqx.cs +++ b/SabreTools.Library/DatFiles/Logiqx.cs @@ -317,9 +317,9 @@ namespace SabreTools.Library.DatFiles Comment = string.Empty, - CloneOf = reader.GetAttribute("cloneof") ?? string.Empty, - RomOf = reader.GetAttribute("romof") ?? string.Empty, - SampleOf = reader.GetAttribute("sampleof") ?? string.Empty, + CloneOf = reader.GetAttribute("cloneof"), + RomOf = reader.GetAttribute("romof"), + SampleOf = reader.GetAttribute("sampleof"), MachineType = (machineType == MachineType.NULL ? MachineType.None : machineType), }; diff --git a/SabreTools.Library/DatFiles/SoftwareList.cs b/SabreTools.Library/DatFiles/SoftwareList.cs index 8b020b57..ae9865d5 100644 --- a/SabreTools.Library/DatFiles/SoftwareList.cs +++ b/SabreTools.Library/DatFiles/SoftwareList.cs @@ -144,7 +144,7 @@ namespace SabreTools.Library.DatFiles Description = reader.GetAttribute("name"), Supported = reader.GetAttribute("supported").AsSupported(), - CloneOf = reader.GetAttribute("cloneof") ?? string.Empty, + CloneOf = reader.GetAttribute("cloneof"), Infos = new List(), SharedFeatures = new List(), DipSwitches = new List(), diff --git a/SabreTools.Library/IO/ClrMameProWriter.cs b/SabreTools.Library/IO/ClrMameProWriter.cs index 6efc9416..2cc628b0 100644 --- a/SabreTools.Library/IO/ClrMameProWriter.cs +++ b/SabreTools.Library/IO/ClrMameProWriter.cs @@ -288,6 +288,23 @@ namespace SabreTools.Library.IO } } + /// + /// Ensure writing writing null values as empty strings + /// + public void WriteRequiredStandalone(string name, string value, bool? quoteOverride = null) + { + WriteStandalone(name, value ?? string.Empty, quoteOverride); + } + + /// + /// Write an standalone, if the value is not null or empty + /// + public void WriteOptionalStandalone(string name, string value, bool? quoteOverride = null) + { + if (!string.IsNullOrEmpty(value)) + WriteStandalone(name, value, quoteOverride); + } + /// /// Write a string content value ///