2017-10-09 18:04:49 -07:00
|
|
|
|
using System;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
using System.IO;
|
2017-10-09 18:04:49 -07:00
|
|
|
|
using System.Text;
|
2018-01-15 10:47:19 -08:00
|
|
|
|
using System.Xml;
|
2020-12-08 00:13:22 -08:00
|
|
|
|
using System.Xml.Schema;
|
2020-09-07 22:21:02 -07:00
|
|
|
|
using System.Xml.Serialization;
|
2021-07-18 21:00:01 -07:00
|
|
|
|
using SabreTools.Core;
|
2020-12-08 15:15:41 -08:00
|
|
|
|
using SabreTools.DatItems;
|
2017-10-09 18:04:49 -07:00
|
|
|
|
|
2020-12-09 22:11:35 -08:00
|
|
|
|
namespace SabreTools.DatFiles.Formats
|
2017-10-09 18:04:49 -07:00
|
|
|
|
{
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <summary>
|
2020-09-07 22:57:44 -07:00
|
|
|
|
/// Represents parsing and writing of a SabreDAT XML
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// </summary>
|
2020-09-07 22:57:44 -07:00
|
|
|
|
internal class SabreXML : DatFile
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor designed for casting a base DatFile
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public SabreXML(DatFile? datFile)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
: base(datFile)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-18 12:09:09 -08:00
|
|
|
|
/// <inheritdoc/>
|
2020-12-23 13:55:09 -08:00
|
|
|
|
public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
// Prepare all internal variables
|
2023-08-10 23:22:14 -04:00
|
|
|
|
XmlReader? xtr = XmlReader.Create(filename, new XmlReaderSettings
|
2020-12-08 00:13:22 -08:00
|
|
|
|
{
|
|
|
|
|
|
CheckCharacters = false,
|
2024-02-28 22:54:56 -05:00
|
|
|
|
#if NET40_OR_GREATER
|
2020-12-08 00:13:22 -08:00
|
|
|
|
DtdProcessing = DtdProcessing.Ignore,
|
2024-02-28 22:54:56 -05:00
|
|
|
|
#endif
|
2020-12-08 00:13:22 -08:00
|
|
|
|
IgnoreComments = true,
|
|
|
|
|
|
IgnoreWhitespace = true,
|
|
|
|
|
|
ValidationFlags = XmlSchemaValidationFlags.None,
|
|
|
|
|
|
ValidationType = ValidationType.None,
|
|
|
|
|
|
});
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// If we got a null reader, just return
|
|
|
|
|
|
if (xtr == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// Otherwise, read the file to the end
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
xtr.MoveToContent();
|
|
|
|
|
|
while (!xtr.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (xtr.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
xtr.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (xtr.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "header":
|
2023-04-19 16:39:58 -04:00
|
|
|
|
XmlSerializer xs = new(typeof(DatHeader));
|
2023-08-10 23:22:14 -04:00
|
|
|
|
DatHeader? header = xs.Deserialize(xtr.ReadSubtree()) as DatHeader;
|
2020-09-07 22:21:02 -07:00
|
|
|
|
Header.ConditionalCopy(header);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
xtr.Skip();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "directory":
|
2020-12-23 13:55:09 -08:00
|
|
|
|
ReadDirectory(xtr.ReadSubtree(), statsOnly, filename, indexId);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Skip the directory node now that we've processed it
|
|
|
|
|
|
xtr.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
xtr.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-01-12 15:54:14 -08:00
|
|
|
|
catch (Exception ex) when (!throwOnError)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Warning(ex, $"Exception found while parsing '{filename}'");
|
2023-08-10 23:22:14 -04:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
// For XML errors, just skip the affected node
|
|
|
|
|
|
xtr?.Read();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-28 22:54:56 -05:00
|
|
|
|
#if NET452_OR_GREATER
|
2023-08-10 23:22:14 -04:00
|
|
|
|
xtr?.Dispose();
|
2024-02-28 22:54:56 -05:00
|
|
|
|
#endif
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read directory information
|
|
|
|
|
|
/// </summary>
|
2020-09-07 22:21:02 -07:00
|
|
|
|
/// <param name="xtr">XmlReader to use to parse the header</param>
|
2020-12-23 13:55:09 -08:00
|
|
|
|
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <param name="filename">Name of the file to be parsed</param>
|
2020-07-15 09:41:59 -07:00
|
|
|
|
/// <param name="indexId">Index ID for the DAT</param>
|
2020-12-23 13:55:09 -08:00
|
|
|
|
private void ReadDirectory(XmlReader xtr, bool statsOnly, string filename, int indexId)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-07 22:21:02 -07:00
|
|
|
|
// If the reader is invalid, skip
|
|
|
|
|
|
if (xtr == null)
|
|
|
|
|
|
return;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-07 22:21:02 -07:00
|
|
|
|
// Prepare internal variables
|
2023-08-10 23:22:14 -04:00
|
|
|
|
Machine? machine = null;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-07 22:21:02 -07:00
|
|
|
|
// Otherwise, read the directory
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtr.MoveToContent();
|
|
|
|
|
|
while (!xtr.EOF)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (xtr.NodeType != XmlNodeType.Element)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtr.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
switch (xtr.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "machine":
|
2023-04-19 16:39:58 -04:00
|
|
|
|
XmlSerializer xs = new(typeof(Machine));
|
2023-08-10 23:22:14 -04:00
|
|
|
|
machine = xs?.Deserialize(xtr.ReadSubtree()) as Machine;
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtr.Skip();
|
|
|
|
|
|
break;
|
2020-09-01 13:36:32 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
case "files":
|
2020-12-23 13:55:09 -08:00
|
|
|
|
ReadFiles(xtr.ReadSubtree(), machine, statsOnly, filename, indexId);
|
2020-09-01 13:36:32 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// Skip the directory node now that we've processed it
|
|
|
|
|
|
xtr.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
xtr.Read();
|
|
|
|
|
|
break;
|
2020-09-01 13:36:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-09-07 22:21:02 -07:00
|
|
|
|
/// Read Files information
|
2020-09-01 13:36:32 -07:00
|
|
|
|
/// </summary>
|
2020-09-07 22:21:02 -07:00
|
|
|
|
/// <param name="xtr">XmlReader to use to parse the header</param>
|
|
|
|
|
|
/// <param name="machine">Machine to copy information from</param>
|
2020-12-23 13:55:09 -08:00
|
|
|
|
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
|
2020-09-07 22:21:02 -07:00
|
|
|
|
/// <param name="filename">Name of the file to be parsed</param>
|
|
|
|
|
|
/// <param name="indexId">Index ID for the DAT</param>
|
2023-08-10 23:22:14 -04:00
|
|
|
|
private void ReadFiles(XmlReader xtr, Machine? machine, bool statsOnly, string filename, int indexId)
|
2020-09-01 13:36:32 -07:00
|
|
|
|
{
|
2020-09-07 22:21:02 -07:00
|
|
|
|
// If the reader is invalid, skip
|
|
|
|
|
|
if (xtr == null)
|
2020-09-01 13:36:32 -07:00
|
|
|
|
return;
|
|
|
|
|
|
|
2020-09-07 22:21:02 -07:00
|
|
|
|
// Otherwise, read the items
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtr.MoveToContent();
|
|
|
|
|
|
while (!xtr.EOF)
|
2020-09-01 13:36:32 -07:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (xtr.NodeType != XmlNodeType.Element)
|
2020-09-01 13:36:32 -07:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtr.Read();
|
|
|
|
|
|
continue;
|
2020-09-01 13:36:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
switch (xtr.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "datitem":
|
2023-04-19 16:39:58 -04:00
|
|
|
|
XmlSerializer xs = new(typeof(DatItem));
|
2023-08-10 23:22:14 -04:00
|
|
|
|
if (xs.Deserialize(xtr.ReadSubtree()) is DatItem item)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.CopyMachineInformation(machine);
|
2024-03-10 16:49:07 -04:00
|
|
|
|
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
2023-08-10 23:22:14 -04:00
|
|
|
|
ParseAddHelper(item, statsOnly);
|
|
|
|
|
|
}
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtr.Skip();
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
xtr.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2020-09-01 13:36:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-18 12:09:09 -08:00
|
|
|
|
/// <inheritdoc/>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2021-02-03 11:22:09 -08:00
|
|
|
|
logger.User($"Writing to '{outfile}'...");
|
2020-12-08 00:13:22 -08:00
|
|
|
|
FileStream fs = File.Create(outfile);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// If we get back null for some reason, just log and return
|
|
|
|
|
|
if (fs == null)
|
|
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Warning($"File '{outfile}' could not be created for writing! Please check to see if the file is writable");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-19 16:39:58 -04:00
|
|
|
|
XmlTextWriter xtw = new(fs, new UTF8Encoding(false))
|
2020-07-15 09:41:59 -07:00
|
|
|
|
{
|
|
|
|
|
|
Formatting = Formatting.Indented,
|
|
|
|
|
|
IndentChar = '\t',
|
2020-09-07 22:21:02 -07:00
|
|
|
|
Indentation = 1,
|
2020-07-15 09:41:59 -07:00
|
|
|
|
};
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Write out the header
|
2020-06-10 22:37:19 -07:00
|
|
|
|
WriteHeader(xtw);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Write out each of the machines and roms
|
2023-08-10 23:22:14 -04:00
|
|
|
|
string? lastgame = null;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-07-26 21:00:30 -07:00
|
|
|
|
// Use a sorted list of games to output
|
2020-07-26 22:34:45 -07:00
|
|
|
|
foreach (string key in Items.SortedKeys)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2021-07-18 21:00:01 -07:00
|
|
|
|
ConcurrentList<DatItem> datItems = Items.FilteredItems(key);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-25 20:25:29 -07:00
|
|
|
|
// If this machine doesn't contain any writable items, skip
|
|
|
|
|
|
if (!ContainsWritable(datItems))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
// Resolve the names in the block
|
2020-08-28 15:06:07 -07:00
|
|
|
|
datItems = DatItem.ResolveNames(datItems);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-28 15:06:07 -07:00
|
|
|
|
for (int index = 0; index < datItems.Count; index++)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-28 15:06:07 -07:00
|
|
|
|
DatItem datItem = datItems[index];
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// If we have a different game and we're not at the start of the list, output the end of last item
|
2024-03-10 16:49:07 -04:00
|
|
|
|
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)?.ToLowerInvariant())
|
2020-09-07 22:21:02 -07:00
|
|
|
|
WriteEndGame(xtw);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// If we have a new game, output the beginning of the new item
|
2024-03-10 16:49:07 -04:00
|
|
|
|
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)?.ToLowerInvariant())
|
2020-09-07 22:21:02 -07:00
|
|
|
|
WriteStartGame(xtw, datItem);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-28 15:06:07 -07:00
|
|
|
|
// Check for a "null" item
|
|
|
|
|
|
datItem = ProcessNullifiedItem(datItem);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-28 15:06:07 -07:00
|
|
|
|
// Write out the item if we're not ignoring
|
|
|
|
|
|
if (!ShouldIgnore(datItem, ignoreblanks))
|
2020-09-07 22:21:02 -07:00
|
|
|
|
WriteDatItem(xtw, datItem);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Set the new data to compare against
|
2024-03-10 16:49:07 -04:00
|
|
|
|
lastgame = datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.NameKey);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Write the file footer out
|
2020-09-07 22:21:02 -07:00
|
|
|
|
WriteFooter(xtw);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2021-02-03 11:22:09 -08:00
|
|
|
|
logger.User($"'{outfile}' written!{Environment.NewLine}");
|
2024-02-28 22:54:56 -05:00
|
|
|
|
#if NET452_OR_GREATER
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.Dispose();
|
2024-02-28 22:54:56 -05:00
|
|
|
|
#endif
|
2019-01-11 13:43:15 -08:00
|
|
|
|
fs.Dispose();
|
|
|
|
|
|
}
|
2021-01-12 15:54:14 -08:00
|
|
|
|
catch (Exception ex) when (!throwOnError)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Error(ex);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out DAT header using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
private void WriteHeader(XmlTextWriter xtw)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.WriteStartDocument();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.WriteStartElement("datafile");
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2023-04-19 16:39:58 -04:00
|
|
|
|
XmlSerializer xs = new(typeof(DatHeader));
|
|
|
|
|
|
XmlSerializerNamespaces ns = new();
|
2020-09-15 14:23:40 -07:00
|
|
|
|
ns.Add("", "");
|
|
|
|
|
|
xs.Serialize(xtw, Header, ns);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.WriteStartElement("data");
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out Game start using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
|
|
|
|
|
/// <param name="datItem">DatItem object to be output</param>
|
2024-02-28 19:19:50 -05:00
|
|
|
|
private static void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// No game should start with a path separator
|
2024-03-10 16:49:07 -04:00
|
|
|
|
datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)?.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// Write the machine
|
|
|
|
|
|
xtw.WriteStartElement("directory");
|
2023-04-19 16:39:58 -04:00
|
|
|
|
XmlSerializer xs = new(typeof(Machine));
|
|
|
|
|
|
XmlSerializerNamespaces ns = new();
|
2020-09-15 14:23:40 -07:00
|
|
|
|
ns.Add("", "");
|
2024-03-10 16:49:07 -04:00
|
|
|
|
xs.Serialize(xtw, datItem.GetFieldValue<Machine>(DatItem.MachineKey), ns);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.WriteStartElement("files");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out Game start using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
2024-02-28 19:19:50 -05:00
|
|
|
|
private static void WriteEndGame(XmlTextWriter xtw)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// End files
|
|
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// End directory
|
|
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out DatItem using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
|
|
|
|
|
/// <param name="datItem">DatItem object to be output</param>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// Pre-process the item name
|
|
|
|
|
|
ProcessItemName(datItem, true);
|
2020-09-15 12:12:13 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// Write the DatItem
|
2023-04-19 16:39:58 -04:00
|
|
|
|
XmlSerializer xs = new(typeof(DatItem));
|
|
|
|
|
|
XmlSerializerNamespaces ns = new();
|
2020-09-15 14:23:40 -07:00
|
|
|
|
ns.Add("", "");
|
|
|
|
|
|
xs.Serialize(xtw, datItem, ns);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write out DAT footer using the supplied StreamWriter
|
|
|
|
|
|
/// </summary>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
2024-02-28 19:19:50 -05:00
|
|
|
|
private static void WriteFooter(XmlTextWriter xtw)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// End files
|
|
|
|
|
|
xtw.WriteEndElement();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// End directory
|
|
|
|
|
|
xtw.WriteEndElement();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// End data
|
|
|
|
|
|
xtw.WriteEndElement();
|
2020-09-15 12:12:13 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// End datafile
|
|
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-09 18:04:49 -07:00
|
|
|
|
}
|