diff --git a/SabreTools.DatFiles/Formats/SabreJSON.cs b/SabreTools.DatFiles/Formats/SabreJSON.cs index aad17174..6b00947e 100644 --- a/SabreTools.DatFiles/Formats/SabreJSON.cs +++ b/SabreTools.DatFiles/Formats/SabreJSON.cs @@ -503,7 +503,7 @@ namespace SabreTools.DatFiles.Formats // Write out the item if we're not ignoring if (!ShouldIgnore(datItem.Value, ignoreblanks)) - WriteDatItem(jtw, datItem.Value); + WriteDatItemDB(jtw, datItem); // Set the new data to compare against lastgame = machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey); @@ -609,6 +609,30 @@ namespace SabreTools.DatFiles.Formats jtw.Flush(); } + /// + /// Write out DatItem using the supplied JsonTextWriter + /// + /// JsonTextWriter to output to + /// DatItem object to be output + private void WriteDatItemDB(JsonTextWriter jtw, KeyValuePair datItem) + { + // Pre-process the item name + ProcessItemNameDB(datItem, true); + + // Build the state + jtw.WriteStartObject(); + + // Write the DatItem + jtw.WritePropertyName("datitem"); + JsonSerializer js = new() { ContractResolver = new BaseFirstContractResolver(), Formatting = Formatting.Indented }; + js.Serialize(jtw, datItem); + + // End item + jtw.WriteEndObject(); + + jtw.Flush(); + } + /// /// Write out DAT footer using the supplied JsonTextWriter /// diff --git a/SabreTools.DatFiles/Formats/SabreXML.cs b/SabreTools.DatFiles/Formats/SabreXML.cs index cf7672df..d49d5487 100644 --- a/SabreTools.DatFiles/Formats/SabreXML.cs +++ b/SabreTools.DatFiles/Formats/SabreXML.cs @@ -332,7 +332,7 @@ namespace SabreTools.DatFiles.Formats // Write out the item if we're not ignoring if (!ShouldIgnore(datItem.Value, ignoreblanks)) - WriteDatItem(xtw, datItem.Value); + WriteDatItemDB(xtw, datItem); // Set the new data to compare against lastgame = machine.Value!.GetStringFieldValue(Models.Metadata.Machine.NameKey); @@ -433,6 +433,25 @@ namespace SabreTools.DatFiles.Formats xtw.Flush(); } + /// + /// Write out DatItem using the supplied StreamWriter + /// + /// XmlTextWriter to output to + /// DatItem object to be output + private void WriteDatItemDB(XmlTextWriter xtw, KeyValuePair datItem) + { + // Pre-process the item name + ProcessItemNameDB(datItem, true); + + // Write the DatItem + XmlSerializer xs = new(typeof(DatItem)); + XmlSerializerNamespaces ns = new(); + ns.Add("", ""); + xs.Serialize(xtw, datItem, ns); + + xtw.Flush(); + } + /// /// Write out DAT footer using the supplied StreamWriter ///