Fix ListXML write

This commit is contained in:
Matt Nadareski
2020-08-25 22:13:49 -07:00
parent d8b8f53821
commit 0fa843a587
4 changed files with 43 additions and 24 deletions

View File

@@ -1003,7 +1003,7 @@ namespace SabreTools.Library.DatFiles
// If we have a different game and we're not at the start of the list, output the end of last item // If we have a different game and we're not at the start of the list, output the end of last item
if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) if (lastgame != null && lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
WriteEndGame(xtw); WriteEndGame(xtw, rom);
// If we have a new game, output the beginning of the new item // If we have a new game, output the beginning of the new item
if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant()) if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
@@ -1107,9 +1107,9 @@ namespace SabreTools.Library.DatFiles
xtw.WriteOptionalElementString("description", datItem.Machine.Description); xtw.WriteOptionalElementString("description", datItem.Machine.Description);
xtw.WriteOptionalElementString("year", datItem.Machine.Year); xtw.WriteOptionalElementString("year", datItem.Machine.Year);
xtw.WriteOptionalElementString("publisher", datItem.Machine.Publisher); xtw.WriteOptionalElementString("manufacturer", datItem.Machine.Manufacturer);
xtw.WriteOptionalElementString("category", datItem.Machine.Category);
// TODO: These should go *after* the datitems
if (datItem.Machine.DeviceReferences != null) if (datItem.Machine.DeviceReferences != null)
{ {
foreach (var deviceReference in datItem.Machine.DeviceReferences) foreach (var deviceReference in datItem.Machine.DeviceReferences)
@@ -1230,17 +1230,17 @@ namespace SabreTools.Library.DatFiles
} }
if (datItem.Machine.DipSwitches != null) if (datItem.Machine.DipSwitches != null)
{ {
foreach (var dipSwitches in datItem.Machine.DipSwitches) foreach (var dipSwitch in datItem.Machine.DipSwitches)
{ {
xtw.WriteStartElement("dipswitch"); xtw.WriteStartElement("dipswitch");
xtw.WriteOptionalAttributeString("name", dipSwitches.Name); xtw.WriteOptionalAttributeString("name", dipSwitch.Name);
xtw.WriteOptionalAttributeString("tag", dipSwitches.Tag); xtw.WriteOptionalAttributeString("tag", dipSwitch.Tag);
xtw.WriteOptionalAttributeString("mask", dipSwitches.Mask); xtw.WriteOptionalAttributeString("mask", dipSwitch.Mask);
if (dipSwitches.Locations != null) if (dipSwitch.Locations != null)
{ {
foreach (var location in dipSwitches.Locations) foreach (var location in dipSwitch.Locations)
{ {
xtw.WriteStartElement("diplocation"); xtw.WriteStartElement("diplocation");
@@ -1252,9 +1252,9 @@ namespace SabreTools.Library.DatFiles
xtw.WriteEndElement(); xtw.WriteEndElement();
} }
} }
if (dipSwitches.Values != null) if (dipSwitch.Values != null)
{ {
foreach (var value in dipSwitches.Values) foreach (var value in dipSwitch.Values)
{ {
xtw.WriteStartElement("dipvalue"); xtw.WriteStartElement("dipvalue");
@@ -1508,8 +1508,9 @@ namespace SabreTools.Library.DatFiles
/// Write out Game start using the supplied StreamWriter /// Write out Game start using the supplied StreamWriter
/// </summary> /// </summary>
/// <param name="xtw">XmlTextWriter to output to</param> /// <param name="xtw">XmlTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns> /// <returns>True if the data was written, false on error</returns>
private bool WriteEndGame(XmlTextWriter xtw) private bool WriteEndGame(XmlTextWriter xtw, DatItem datItem)
{ {
try try
{ {

View File

@@ -620,7 +620,7 @@ namespace SabreTools.Library.DatFiles
break; break;
case "crc": case "crc":
machine.HasCrc = reader.ReadElementContentAsString().AsYesNo(); machine.Crc = reader.ReadElementContentAsString().AsYesNo();
break; break;
case "source": case "source":
@@ -873,7 +873,7 @@ namespace SabreTools.Library.DatFiles
|| datItem.Machine.Ratings != null || datItem.Machine.Ratings != null
|| datItem.Machine.Score != null || datItem.Machine.Score != null
|| datItem.Machine.Enabled != null || datItem.Machine.Enabled != null
|| datItem.Machine.HasCrc != null || datItem.Machine.Crc != null
|| datItem.Machine.RelatedTo != null) || datItem.Machine.RelatedTo != null)
{ {
xtw.WriteStartElement("trurip"); xtw.WriteStartElement("trurip");
@@ -889,7 +889,7 @@ namespace SabreTools.Library.DatFiles
xtw.WriteOptionalElementString("players", datItem.Machine.Players); xtw.WriteOptionalElementString("players", datItem.Machine.Players);
xtw.WriteOptionalElementString("enabled", datItem.Machine.Enabled); xtw.WriteOptionalElementString("enabled", datItem.Machine.Enabled);
xtw.WriteOptionalElementString("titleid", datItem.Machine.TitleID); xtw.WriteOptionalElementString("titleid", datItem.Machine.TitleID);
xtw.WriteOptionalElementString("crc", datItem.Machine.HasCrc.FromYesNo()); xtw.WriteOptionalElementString("crc", datItem.Machine.Crc.FromYesNo());
xtw.WriteOptionalElementString("source", datItem.Machine.SourceFile); xtw.WriteOptionalElementString("source", datItem.Machine.SourceFile);
xtw.WriteOptionalElementString("cloneof", datItem.Machine.CloneOf); xtw.WriteOptionalElementString("cloneof", datItem.Machine.CloneOf);
xtw.WriteOptionalElementString("relatedto", datItem.Machine.RelatedTo); xtw.WriteOptionalElementString("relatedto", datItem.Machine.RelatedTo);

View File

@@ -40,6 +40,7 @@ namespace SabreTools.Library.DatItems
/// <summary> /// <summary>
/// Represents one ListXML chip /// Represents one ListXML chip
/// </summary> /// </summary>
/// TODO: Promote this to the same level as Sample
[JsonObject("chip")] [JsonObject("chip")]
public class ListXmlChip public class ListXmlChip
{ {
@@ -203,6 +204,7 @@ namespace SabreTools.Library.DatItems
/// <summary> /// <summary>
/// Represents one ListXML deviceref /// Represents one ListXML deviceref
/// </summary> /// </summary>
/// TODO: Promote this to the same level as Sample
[JsonObject("deviceref")] [JsonObject("deviceref")]
public class ListXmlDeviceReference public class ListXmlDeviceReference
{ {
@@ -450,6 +452,7 @@ namespace SabreTools.Library.DatItems
/// <summary> /// <summary>
/// Represents one ListXML softwarelist /// Represents one ListXML softwarelist
/// </summary> /// </summary>
/// TODO: Promote this to the same level as Sample?
[JsonObject("softwarelist")] [JsonObject("softwarelist")]
public class ListXmlSoftwareList public class ListXmlSoftwareList
{ {

View File

@@ -317,7 +317,7 @@ namespace SabreTools.Library.DatItems
/// Does the game have a CRC check /// Does the game have a CRC check
/// </summary> /// </summary>
[JsonProperty("hascrc", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonProperty("hascrc", DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool? HasCrc { get; set; } = null; public bool? Crc { get; set; } = null;
/// <summary> /// <summary>
/// Machine relations /// Machine relations
@@ -505,7 +505,7 @@ namespace SabreTools.Library.DatItems
Enabled = mappings[Field.Machine_Enabled]; Enabled = mappings[Field.Machine_Enabled];
if (mappings.Keys.Contains(Field.Machine_CRC)) if (mappings.Keys.Contains(Field.Machine_CRC))
HasCrc = mappings[Field.Machine_CRC].AsYesNo(); Crc = mappings[Field.Machine_CRC].AsYesNo();
if (mappings.Keys.Contains(Field.Machine_RelatedTo)) if (mappings.Keys.Contains(Field.Machine_RelatedTo))
RelatedTo = mappings[Field.Machine_RelatedTo]; RelatedTo = mappings[Field.Machine_RelatedTo];
@@ -582,6 +582,7 @@ namespace SabreTools.Library.DatItems
RomOf = this.RomOf, RomOf = this.RomOf,
CloneOf = this.CloneOf, CloneOf = this.CloneOf,
SampleOf = this.SampleOf, SampleOf = this.SampleOf,
MachineType = this.MachineType,
#endregion #endregion
@@ -602,9 +603,21 @@ namespace SabreTools.Library.DatItems
SourceFile = this.SourceFile, SourceFile = this.SourceFile,
Runnable = this.Runnable, Runnable = this.Runnable,
DeviceReferences = this.DeviceReferences, DeviceReferences = this.DeviceReferences,
Chips = this.Chips,
Displays = this.Displays,
Sounds = this.Sounds,
Conditions = this.Conditions,
Inputs = this.Inputs,
DipSwitches = this.DipSwitches,
Configurations = this.Configurations,
Ports = this.Ports,
Adjusters = this.Adjusters,
Drivers = this.Drivers,
Features = this.Features,
Devices = this.Devices,
Slots = this.Slots, Slots = this.Slots,
Infos = this.Infos, SoftwareLists = this.SoftwareLists,
MachineType = this.MachineType, RamOptions = this.RamOptions,
#endregion #endregion
@@ -624,7 +637,7 @@ namespace SabreTools.Library.DatItems
Ratings = this.Ratings, Ratings = this.Ratings,
Score = this.Score, Score = this.Score,
Enabled = this.Enabled, Enabled = this.Enabled,
HasCrc = this.HasCrc, Crc = this.Crc,
RelatedTo = this.RelatedTo, RelatedTo = this.RelatedTo,
#endregion #endregion
@@ -640,8 +653,8 @@ namespace SabreTools.Library.DatItems
#region SoftwareList #region SoftwareList
Supported = this.Supported, Supported = this.Supported,
Infos = this.Infos,
SharedFeatures = this.SharedFeatures, SharedFeatures = this.SharedFeatures,
DipSwitches = this.DipSwitches,
#endregion #endregion
}; };
@@ -1401,7 +1414,7 @@ namespace SabreTools.Library.DatItems
return false; return false;
// Machine_CRC // Machine_CRC
if (filter.Machine_CRC.MatchesNeutral(null, HasCrc) == false) if (filter.Machine_CRC.MatchesNeutral(null, Crc) == false)
return false; return false;
// Machine_RelatedTo // Machine_RelatedTo
@@ -1547,6 +1560,7 @@ namespace SabreTools.Library.DatItems
/// Remove fields from the Machine /// Remove fields from the Machine
/// </summary> /// </summary>
/// <param name="fields">List of Fields to remove</param> /// <param name="fields">List of Fields to remove</param>
/// TODO: Add new ListXML and SoftwareList fields
public void RemoveFields(List<Field> fields) public void RemoveFields(List<Field> fields)
{ {
#region Common #region Common
@@ -1664,7 +1678,7 @@ namespace SabreTools.Library.DatItems
Enabled = null; Enabled = null;
if (fields.Contains(Field.Machine_CRC)) if (fields.Contains(Field.Machine_CRC))
HasCrc = null; Crc = null;
if (fields.Contains(Field.Machine_RelatedTo)) if (fields.Contains(Field.Machine_RelatedTo))
RelatedTo = null; RelatedTo = null;
@@ -1708,6 +1722,7 @@ namespace SabreTools.Library.DatItems
/// <param name="item">DatItem to pull new information from</param> /// <param name="item">DatItem to pull new information from</param>
/// <param name="fields">List of Fields representing what should be updated</param> /// <param name="fields">List of Fields representing what should be updated</param>
/// <param name="onlySame">True if descriptions should only be replaced if the game name is the same, false otherwise</param> /// <param name="onlySame">True if descriptions should only be replaced if the game name is the same, false otherwise</param>
/// TODO: Add new ListXML and SoftwareList fields
public void ReplaceFields(Machine machine, List<Field> fields, bool onlySame) public void ReplaceFields(Machine machine, List<Field> fields, bool onlySame)
{ {
#region Common #region Common
@@ -1828,7 +1843,7 @@ namespace SabreTools.Library.DatItems
Enabled = machine.Enabled; Enabled = machine.Enabled;
if (fields.Contains(Field.Machine_CRC)) if (fields.Contains(Field.Machine_CRC))
HasCrc = machine.HasCrc; Crc = machine.Crc;
if (fields.Contains(Field.Machine_RelatedTo)) if (fields.Contains(Field.Machine_RelatedTo))
RelatedTo = machine.RelatedTo; RelatedTo = machine.RelatedTo;