Fix of-tags, more CMP writing

This commit is contained in:
Matt Nadareski
2020-08-24 13:43:37 -07:00
parent 769bc077e7
commit 38f69f9dcc
7 changed files with 56 additions and 57 deletions

View File

@@ -548,28 +548,18 @@ namespace SabreTools.Library.DatFiles
{ {
cmpw.WriteStartElement("clrmamepro"); cmpw.WriteStartElement("clrmamepro");
cmpw.WriteStandalone("name", Header.Name); cmpw.WriteRequiredStandalone("name", Header.Name);
cmpw.WriteStandalone("description", Header.Description); cmpw.WriteRequiredStandalone("description", Header.Description);
if (!string.IsNullOrWhiteSpace(Header.Category)) cmpw.WriteOptionalStandalone("category", Header.Category);
cmpw.WriteStandalone("category", Header.Category); cmpw.WriteRequiredStandalone("version", Header.Version);
cmpw.WriteStandalone("version", Header.Version); cmpw.WriteOptionalStandalone("date", Header.Date);
if (!string.IsNullOrWhiteSpace(Header.Date)) cmpw.WriteRequiredStandalone("author", Header.Author);
cmpw.WriteStandalone("date", Header.Date); cmpw.WriteOptionalStandalone("email", Header.Email);
cmpw.WriteStandalone("author", Header.Author); cmpw.WriteOptionalStandalone("homepage", Header.Homepage);
if (!string.IsNullOrWhiteSpace(Header.Email)) cmpw.WriteOptionalStandalone("url", Header.Url);
cmpw.WriteStandalone("email", Header.Email); cmpw.WriteOptionalStandalone("comment", Header.Comment);
if (!string.IsNullOrWhiteSpace(Header.Homepage)) cmpw.WriteOptionalStandalone("forcezipping", Header.ForcePacking.FromPackingFlag(true), false);
cmpw.WriteStandalone("homepage", Header.Homepage); cmpw.WriteOptionalStandalone("forcemerging", Header.ForceMerging.FromMergingFlag(false), false);
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);
// End clrmamepro // End clrmamepro
cmpw.WriteEndElement(); cmpw.WriteEndElement();
@@ -600,23 +590,14 @@ namespace SabreTools.Library.DatFiles
// Build the state // Build the state
cmpw.WriteStartElement(datItem.Machine.MachineType == MachineType.Bios ? "resource" : "game"); cmpw.WriteStartElement(datItem.Machine.MachineType == MachineType.Bios ? "resource" : "game");
cmpw.WriteStandalone("name", datItem.Machine.Name);
if (!string.IsNullOrWhiteSpace(datItem.Machine.RomOf)) cmpw.WriteRequiredStandalone("name", datItem.Machine.Name);
cmpw.WriteStandalone("romof", datItem.Machine.RomOf); cmpw.WriteOptionalStandalone("romof", datItem.Machine.RomOf);
if (!string.IsNullOrWhiteSpace(datItem.Machine.CloneOf)) cmpw.WriteOptionalStandalone("cloneof", datItem.Machine.CloneOf);
cmpw.WriteStandalone("cloneof", datItem.Machine.CloneOf); cmpw.WriteOptionalStandalone("description", datItem.Machine.Description ?? datItem.Machine.Name);
if (!string.IsNullOrWhiteSpace(datItem.Machine.SampleOf)) cmpw.WriteOptionalStandalone("year", datItem.Machine.Year);
cmpw.WriteStandalone("sampleof", datItem.Machine.SampleOf); cmpw.WriteOptionalStandalone("manufacturer", datItem.Machine.Manufacturer);
if (!string.IsNullOrWhiteSpace(datItem.Machine.Description)) cmpw.WriteOptionalStandalone("category", datItem.Machine.Category);
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.Flush(); cmpw.Flush();
} }
@@ -640,8 +621,7 @@ namespace SabreTools.Library.DatFiles
try try
{ {
// Build the state // Build the state
if (!string.IsNullOrWhiteSpace(datItem.Machine.SampleOf)) cmpw.WriteOptionalStandalone("sampleof", datItem.Machine.SampleOf);
cmpw.WriteStandalone("sampleof", datItem.Machine.SampleOf);
// End game // End game
cmpw.WriteEndElement(); cmpw.WriteEndElement();

View File

@@ -375,14 +375,17 @@ namespace SabreTools.Library.DatFiles
{ {
try try
{ {
// Build the state
cmpw.WriteStartElement("DOSCenter"); cmpw.WriteStartElement("DOSCenter");
cmpw.WriteStandalone("Name:", Header.Name, false);
cmpw.WriteStandalone("Description:", Header.Description, false); cmpw.WriteRequiredStandalone("Name:", Header.Name, false);
cmpw.WriteStandalone("Version:", Header.Version, false); cmpw.WriteRequiredStandalone("Description:", Header.Description, false);
cmpw.WriteStandalone("Date:", Header.Date, false); cmpw.WriteRequiredStandalone("Version:", Header.Version, false);
cmpw.WriteStandalone("Author:", Header.Author, false); cmpw.WriteRequiredStandalone("Date:", Header.Date, false);
cmpw.WriteStandalone("Homepage:", Header.Homepage, false); cmpw.WriteRequiredStandalone("Author:", Header.Author, false);
cmpw.WriteStandalone("Comment:", Header.Comment, false); cmpw.WriteRequiredStandalone("Homepage:", Header.Homepage, false);
cmpw.WriteRequiredStandalone("Comment:", Header.Comment, false);
cmpw.WriteEndElement(); cmpw.WriteEndElement();
cmpw.Flush(); cmpw.Flush();
@@ -411,7 +414,7 @@ namespace SabreTools.Library.DatFiles
// Build the state // Build the state
cmpw.WriteStartElement("game"); cmpw.WriteStartElement("game");
cmpw.WriteStandalone("name", $"{datItem.Machine.Name}.zip", true); cmpw.WriteRequiredStandalone("name", $"{datItem.Machine.Name}.zip", true);
cmpw.Flush(); cmpw.Flush();
} }

View File

@@ -6,7 +6,6 @@ using System.Text;
using SabreTools.Library.Data; using SabreTools.Library.Data;
using SabreTools.Library.DatItems; using SabreTools.Library.DatItems;
using SabreTools.Library.IO; using SabreTools.Library.IO;
using SabreTools.Library.Tools;
namespace SabreTools.Library.DatFiles namespace SabreTools.Library.DatFiles
{ {

View File

@@ -142,9 +142,9 @@ namespace SabreTools.Library.DatFiles
Name = reader.GetAttribute("name"), Name = reader.GetAttribute("name"),
Comment = string.Empty, Comment = string.Empty,
Description = reader.GetAttribute("name"), Description = reader.GetAttribute("name"),
CloneOf = reader.GetAttribute("cloneof") ?? string.Empty, CloneOf = reader.GetAttribute("cloneof"),
RomOf = reader.GetAttribute("romof") ?? string.Empty, RomOf = reader.GetAttribute("romof"),
SampleOf = reader.GetAttribute("sampleof") ?? string.Empty, SampleOf = reader.GetAttribute("sampleof"),
MachineType = (machineType == MachineType.NULL ? MachineType.None : machineType), MachineType = (machineType == MachineType.NULL ? MachineType.None : machineType),
SourceFile = reader.GetAttribute("sourcefile"), SourceFile = reader.GetAttribute("sourcefile"),

View File

@@ -317,9 +317,9 @@ namespace SabreTools.Library.DatFiles
Comment = string.Empty, Comment = string.Empty,
CloneOf = reader.GetAttribute("cloneof") ?? string.Empty, CloneOf = reader.GetAttribute("cloneof"),
RomOf = reader.GetAttribute("romof") ?? string.Empty, RomOf = reader.GetAttribute("romof"),
SampleOf = reader.GetAttribute("sampleof") ?? string.Empty, SampleOf = reader.GetAttribute("sampleof"),
MachineType = (machineType == MachineType.NULL ? MachineType.None : machineType), MachineType = (machineType == MachineType.NULL ? MachineType.None : machineType),
}; };

View File

@@ -144,7 +144,7 @@ namespace SabreTools.Library.DatFiles
Description = reader.GetAttribute("name"), Description = reader.GetAttribute("name"),
Supported = reader.GetAttribute("supported").AsSupported(), Supported = reader.GetAttribute("supported").AsSupported(),
CloneOf = reader.GetAttribute("cloneof") ?? string.Empty, CloneOf = reader.GetAttribute("cloneof"),
Infos = new List<ListXmlInfo>(), Infos = new List<ListXmlInfo>(),
SharedFeatures = new List<SoftwareListSharedFeature>(), SharedFeatures = new List<SoftwareListSharedFeature>(),
DipSwitches = new List<ListXmlDipSwitch>(), DipSwitches = new List<ListXmlDipSwitch>(),

View File

@@ -288,6 +288,23 @@ namespace SabreTools.Library.IO
} }
} }
/// <summary>
/// Ensure writing writing null values as empty strings
/// </summary>
public void WriteRequiredStandalone(string name, string value, bool? quoteOverride = null)
{
WriteStandalone(name, value ?? string.Empty, quoteOverride);
}
/// <summary>
/// Write an standalone, if the value is not null or empty
/// </summary>
public void WriteOptionalStandalone(string name, string value, bool? quoteOverride = null)
{
if (!string.IsNullOrEmpty(value))
WriteStandalone(name, value, quoteOverride);
}
/// <summary> /// <summary>
/// Write a string content value /// Write a string content value
/// </summary> /// </summary>