2017-10-09 18:04:49 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
using System.IO;
|
2020-08-24 22:25:47 -07:00
|
|
|
|
using System.Linq;
|
2017-10-09 18:04:49 -07:00
|
|
|
|
using System.Text;
|
2018-01-13 22:42:42 -08:00
|
|
|
|
using System.Xml;
|
2020-12-08 00:13:22 -08:00
|
|
|
|
using System.Xml.Schema;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-12-08 13:23:59 -08:00
|
|
|
|
using SabreTools.Core;
|
2020-12-08 16:37:08 -08:00
|
|
|
|
using SabreTools.Core.Tools;
|
2020-12-08 15:15:41 -08:00
|
|
|
|
using SabreTools.DatItems;
|
2021-02-02 10:23:43 -08:00
|
|
|
|
using SabreTools.DatItems.Formats;
|
2020-12-07 15:08:57 -08:00
|
|
|
|
using SabreTools.IO;
|
2017-10-09 18:04:49 -07:00
|
|
|
|
|
2020-09-03 09:57:16 -07:00
|
|
|
|
// TODO: Use softwarelist.dtd and *try* to make this write more correctly
|
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-03 10:03:04 -07:00
|
|
|
|
/// Represents parsing and writing of a SoftwareList
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
internal class SoftwareList : DatFile
|
|
|
|
|
|
{
|
2020-12-09 14:33:47 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// DTD for original MAME Software List DATs
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private const string SoftwareListDTD = @"<!ELEMENT softwarelist (software+)>
|
|
|
|
|
|
<!ATTLIST softwarelist name CDATA #REQUIRED>
|
|
|
|
|
|
<!ATTLIST softwarelist description CDATA #IMPLIED>
|
|
|
|
|
|
<!ELEMENT software (description, year, publisher, info*, sharedfeat*, part*)>
|
|
|
|
|
|
<!ATTLIST software name CDATA #REQUIRED>
|
|
|
|
|
|
<!ATTLIST software cloneof CDATA #IMPLIED>
|
|
|
|
|
|
<!ATTLIST software supported (yes|partial|no) string.Emptyyesstring.Empty>
|
|
|
|
|
|
<!ELEMENT description (#PCDATA)>
|
|
|
|
|
|
<!ELEMENT year (#PCDATA)>
|
|
|
|
|
|
<!ELEMENT publisher (#PCDATA)>
|
|
|
|
|
|
<!ELEMENT info EMPTY>
|
|
|
|
|
|
<!ATTLIST info name CDATA #REQUIRED>
|
|
|
|
|
|
<!ATTLIST info value CDATA #IMPLIED>
|
|
|
|
|
|
<!ELEMENT sharedfeat EMPTY>
|
|
|
|
|
|
<!ATTLIST sharedfeat name CDATA #REQUIRED>
|
|
|
|
|
|
<!ATTLIST sharedfeat value CDATA #IMPLIED>
|
|
|
|
|
|
<!ELEMENT part (feature*, dataarea*, diskarea*, dipswitch*)>
|
|
|
|
|
|
<!ATTLIST part name CDATA #REQUIRED>
|
|
|
|
|
|
<!ATTLIST part interface CDATA #REQUIRED>
|
|
|
|
|
|
<!-- feature is used to store things like pcb-type, mapper type, etc. Specific values depend on the system. -->
|
|
|
|
|
|
<!ELEMENT feature EMPTY>
|
|
|
|
|
|
<!ATTLIST feature name CDATA #REQUIRED>
|
|
|
|
|
|
<!ATTLIST feature value CDATA #IMPLIED>
|
|
|
|
|
|
<!ELEMENT dataarea (rom*)>
|
|
|
|
|
|
<!ATTLIST dataarea name CDATA #REQUIRED>
|
|
|
|
|
|
<!ATTLIST dataarea size CDATA #REQUIRED>
|
|
|
|
|
|
<!ATTLIST dataarea width (8|16|32|64) string.Empty8string.Empty>
|
|
|
|
|
|
<!ATTLIST dataarea endianness (big|little) string.Emptylittlestring.Empty>
|
|
|
|
|
|
<!ELEMENT rom EMPTY>
|
|
|
|
|
|
<!ATTLIST rom name CDATA #IMPLIED>
|
|
|
|
|
|
<!ATTLIST rom size CDATA #IMPLIED>
|
|
|
|
|
|
<!ATTLIST rom crc CDATA #IMPLIED>
|
|
|
|
|
|
<!ATTLIST rom md5 CDATA #IMPLIED>
|
|
|
|
|
|
<!ATTLIST rom sha1 CDATA #IMPLIED>
|
|
|
|
|
|
<!ATTLIST rom sha256 CDATA #IMPLIED>
|
|
|
|
|
|
<!ATTLIST rom sha384 CDATA #IMPLIED>
|
|
|
|
|
|
<!ATTLIST rom sha512 CDATA #IMPLIED>
|
|
|
|
|
|
<!ATTLIST rom offset CDATA #IMPLIED>
|
|
|
|
|
|
<!ATTLIST rom value CDATA #IMPLIED>
|
|
|
|
|
|
<!ATTLIST rom status (baddump|nodump|good) string.Emptygoodstring.Empty>
|
|
|
|
|
|
<!ATTLIST rom loadflag (load16_byte|load16_word|load16_word_swap|load32_byte|load32_word|load32_word_swap|load32_dword|load64_word|load64_word_swap|reload|fill|continue|reload_plain|ignore) #IMPLIED>
|
|
|
|
|
|
<!ELEMENT diskarea (disk*)>
|
|
|
|
|
|
<!ATTLIST diskarea name CDATA #REQUIRED>
|
|
|
|
|
|
<!ELEMENT disk EMPTY>
|
|
|
|
|
|
<!ATTLIST disk name CDATA #REQUIRED>
|
|
|
|
|
|
<!ATTLIST disk md5 CDATA #IMPLIED>
|
|
|
|
|
|
<!ATTLIST disk sha1 CDATA #IMPLIED>
|
|
|
|
|
|
<!ATTLIST disk status (baddump|nodump|good) string.Emptygoodstring.Empty>
|
|
|
|
|
|
<!ATTLIST disk writeable (yes|no) string.Emptynostring.Empty>
|
|
|
|
|
|
<!ELEMENT dipswitch (dipvalue*)>
|
|
|
|
|
|
<!ATTLIST dipswitch name CDATA #REQUIRED>
|
|
|
|
|
|
<!ATTLIST dipswitch tag CDATA #REQUIRED>
|
|
|
|
|
|
<!ATTLIST dipswitch mask CDATA #REQUIRED>
|
|
|
|
|
|
<!ELEMENT dipvalue EMPTY>
|
|
|
|
|
|
<!ATTLIST dipvalue name CDATA #REQUIRED>
|
|
|
|
|
|
<!ATTLIST dipvalue value CDATA #REQUIRED>
|
|
|
|
|
|
<!ATTLIST dipvalue default (yes|no) string.Emptynostring.Empty>
|
|
|
|
|
|
";
|
|
|
|
|
|
|
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>
|
|
|
|
|
|
public SoftwareList(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
|
2020-12-08 00:13:22 -08:00
|
|
|
|
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
|
|
|
|
|
|
{
|
|
|
|
|
|
CheckCharacters = false,
|
|
|
|
|
|
DtdProcessing = DtdProcessing.Ignore,
|
|
|
|
|
|
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 "softwarelist":
|
2020-12-18 12:09:09 -08:00
|
|
|
|
Header.Name ??= xtr.GetAttribute("name") ?? string.Empty;
|
|
|
|
|
|
Header.Description ??= xtr.GetAttribute("description") ?? string.Empty;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
xtr.Read();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
// We want to process the entire subtree of the machine
|
|
|
|
|
|
case "software":
|
2020-12-23 13:55:09 -08:00
|
|
|
|
ReadSoftware(xtr.ReadSubtree(), statsOnly, filename, indexId);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Skip the software now that we've processed it
|
|
|
|
|
|
xtr.Skip();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
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}'");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// For XML errors, just skip the affected node
|
|
|
|
|
|
xtr?.Read();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
xtr.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read software information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader representing a software block</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 ReadSoftware(XmlReader reader, bool statsOnly, string filename, int indexId)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
// If we have an empty software, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// Otherwise, add what is possible
|
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
|
|
bool containsItems = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Create a new machine
|
|
|
|
|
|
Machine machine = new Machine
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
2020-08-24 13:43:37 -07:00
|
|
|
|
CloneOf = reader.GetAttribute("cloneof"),
|
2020-09-03 11:02:06 -07:00
|
|
|
|
Supported = reader.GetAttribute("supported").AsSupported(),
|
2019-01-11 13:43:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
while (!reader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the elements from the software
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "description":
|
|
|
|
|
|
machine.Description = reader.ReadElementContentAsString();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "year":
|
|
|
|
|
|
machine.Year = reader.ReadElementContentAsString();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "publisher":
|
|
|
|
|
|
machine.Publisher = reader.ReadElementContentAsString();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "info":
|
2020-09-02 23:31:35 -07:00
|
|
|
|
ParseAddHelper(new Info
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
2020-09-03 11:48:30 -07:00
|
|
|
|
Value = reader.GetAttribute("value"),
|
2020-08-24 22:25:47 -07:00
|
|
|
|
|
2020-09-02 23:31:35 -07:00
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
2020-12-23 13:55:09 -08:00
|
|
|
|
}, statsOnly);
|
2020-08-23 15:34:42 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "sharedfeat":
|
2020-09-03 00:48:07 -07:00
|
|
|
|
ParseAddHelper(new SharedFeature
|
2020-09-02 23:31:35 -07:00
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
Value = reader.GetAttribute("value"),
|
2020-08-24 22:25:47 -07:00
|
|
|
|
|
2020-09-03 00:48:07 -07:00
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
2020-12-23 13:55:09 -08:00
|
|
|
|
}, statsOnly);
|
2020-08-23 21:10:29 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "part": // Contains all rom and disk information
|
2020-09-03 11:02:06 -07:00
|
|
|
|
var part = new Part()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
Interface = reader.GetAttribute("interface"),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Now read the internal tags
|
2020-12-23 13:55:09 -08:00
|
|
|
|
containsItems = ReadPart(reader.ReadSubtree(), machine, part, statsOnly, filename, indexId);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Skip the part now that we've processed it
|
|
|
|
|
|
reader.Skip();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If no items were found for this machine, add a Blank placeholder
|
|
|
|
|
|
if (!containsItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
Blank blank = new Blank()
|
|
|
|
|
|
{
|
2020-08-20 13:17:14 -07:00
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
2019-01-11 13:43:15 -08:00
|
|
|
|
};
|
2020-08-20 13:17:14 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
blank.CopyMachineInformation(machine);
|
|
|
|
|
|
|
|
|
|
|
|
// Now process and add the rom
|
2020-12-23 13:55:09 -08:00
|
|
|
|
ParseAddHelper(blank, statsOnly);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read part information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader representing a part block</param>
|
|
|
|
|
|
/// <param name="machine">Machine information to pass to contained items</param>
|
2020-09-03 11:02:06 -07:00
|
|
|
|
/// <param name="part">Part information to pass to contained items</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 bool ReadPart(XmlReader reader, Machine machine, Part part, bool statsOnly, string filename, int indexId)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-03 11:02:06 -07:00
|
|
|
|
// If we have an empty port, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Get lists ready
|
|
|
|
|
|
part.Features = new List<PartFeature>();
|
2020-08-24 22:25:47 -07:00
|
|
|
|
List<DatItem> items = new List<DatItem>();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
while (!reader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the elements from the software
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "feature":
|
2020-09-03 11:02:06 -07:00
|
|
|
|
var feature = new PartFeature()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
Value = reader.GetAttribute("value"),
|
|
|
|
|
|
};
|
2020-08-24 22:25:47 -07:00
|
|
|
|
|
2020-09-03 11:02:06 -07:00
|
|
|
|
part.Features.Add(feature);
|
2020-08-23 21:10:29 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "dataarea":
|
2020-09-03 11:02:06 -07:00
|
|
|
|
var dataArea = new DataArea
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-03 11:02:06 -07:00
|
|
|
|
Name = reader.GetAttribute("name"),
|
2020-12-09 22:33:49 -08:00
|
|
|
|
Size = Utilities.CleanLong(reader.GetAttribute("size")),
|
|
|
|
|
|
Width = Utilities.CleanLong(reader.GetAttribute("width")),
|
2020-09-03 21:39:16 -07:00
|
|
|
|
Endianness = reader.GetAttribute("endianness").AsEndianness(),
|
2020-09-03 11:02:06 -07:00
|
|
|
|
};
|
2020-08-21 13:31:22 -07:00
|
|
|
|
|
2020-09-03 11:02:06 -07:00
|
|
|
|
List<DatItem> roms = ReadDataArea(reader.ReadSubtree(), dataArea);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
// If we got valid roms, add them to the list
|
|
|
|
|
|
if (roms != null)
|
|
|
|
|
|
items.AddRange(roms);
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
// Skip the dataarea now that we've processed it
|
|
|
|
|
|
reader.Skip();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "diskarea":
|
2020-09-03 11:02:06 -07:00
|
|
|
|
var diskArea = new DiskArea
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
};
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-03 11:02:06 -07:00
|
|
|
|
List<DatItem> disks = ReadDiskArea(reader.ReadSubtree(), diskArea);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
// If we got valid disks, add them to the list
|
|
|
|
|
|
if (disks != null)
|
|
|
|
|
|
items.AddRange(disks);
|
|
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
// Skip the diskarea now that we've processed it
|
|
|
|
|
|
reader.Skip();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "dipswitch":
|
2020-09-01 13:36:32 -07:00
|
|
|
|
var dipSwitch = new DipSwitch
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
Tag = reader.GetAttribute("tag"),
|
|
|
|
|
|
Mask = reader.GetAttribute("mask"),
|
|
|
|
|
|
};
|
2020-08-22 23:40:00 -07:00
|
|
|
|
|
|
|
|
|
|
// Now read the internal tags
|
2020-08-22 13:31:13 -07:00
|
|
|
|
ReadDipSwitch(reader.ReadSubtree(), dipSwitch);
|
2020-08-21 16:48:56 -07:00
|
|
|
|
|
2020-09-01 13:36:32 -07:00
|
|
|
|
items.Add(dipSwitch);
|
2020-08-24 22:25:47 -07:00
|
|
|
|
|
2020-08-21 16:48:56 -07:00
|
|
|
|
// Skip the dipswitch now that we've processed it
|
2019-01-11 13:43:15 -08:00
|
|
|
|
reader.Skip();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
// Loop over all of the items, if they exist
|
2020-09-30 09:50:54 -07:00
|
|
|
|
string key = string.Empty;
|
2020-08-24 22:25:47 -07:00
|
|
|
|
foreach (DatItem item in items)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Add all missing information
|
2020-09-03 11:19:06 -07:00
|
|
|
|
switch (item.ItemType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case ItemType.DipSwitch:
|
|
|
|
|
|
(item as DipSwitch).Part = part;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ItemType.Disk:
|
|
|
|
|
|
(item as Disk).Part = part;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ItemType.Rom:
|
|
|
|
|
|
(item as Rom).Part = part;
|
2020-09-30 09:50:54 -07:00
|
|
|
|
|
|
|
|
|
|
// If the rom is continue or ignore, add the size to the previous rom
|
|
|
|
|
|
// TODO: Can this be done on write? We technically lose information this way.
|
|
|
|
|
|
// Order is not guaranteed, and since these don't tend to have any way
|
|
|
|
|
|
// of determining what the "previous" item was after this, that info would
|
|
|
|
|
|
// have to be stored *with* the item somehow
|
|
|
|
|
|
if ((item as Rom).LoadFlag == LoadFlag.Continue || (item as Rom).LoadFlag == LoadFlag.Ignore)
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = Items[key].Count - 1;
|
|
|
|
|
|
DatItem lastrom = Items[key][index];
|
|
|
|
|
|
if (lastrom.ItemType == ItemType.Rom)
|
|
|
|
|
|
{
|
|
|
|
|
|
(lastrom as Rom).Size += (item as Rom).Size;
|
|
|
|
|
|
Items[key].RemoveAt(index);
|
|
|
|
|
|
Items[key].Add(lastrom);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-03 11:19:06 -07:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
item.Source = new Source(indexId, filename);
|
|
|
|
|
|
item.CopyMachineInformation(machine);
|
|
|
|
|
|
|
|
|
|
|
|
// Finally add each item
|
2020-12-23 13:55:09 -08:00
|
|
|
|
key = ParseAddHelper(item, statsOnly);
|
2020-08-24 22:25:47 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return items.Any();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read dataarea information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader representing a dataarea block</param>
|
2020-09-03 11:02:06 -07:00
|
|
|
|
/// <param name="dataArea">DataArea representing the enclosing area</param>
|
|
|
|
|
|
private List<DatItem> ReadDataArea(XmlReader reader, DataArea dataArea)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-24 22:25:47 -07:00
|
|
|
|
List<DatItem> items = new List<DatItem>();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
while (!reader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the elements from the software
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "rom":
|
2020-09-04 10:28:25 -07:00
|
|
|
|
var rom = new Rom
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
2020-12-09 22:33:49 -08:00
|
|
|
|
Size = Utilities.CleanLong(reader.GetAttribute("size")),
|
2020-07-15 09:41:59 -07:00
|
|
|
|
CRC = reader.GetAttribute("crc"),
|
|
|
|
|
|
SHA1 = reader.GetAttribute("sha1"),
|
2019-01-11 13:43:15 -08:00
|
|
|
|
Offset = reader.GetAttribute("offset"),
|
2020-08-21 14:20:17 -07:00
|
|
|
|
Value = reader.GetAttribute("value"),
|
2020-09-03 11:02:06 -07:00
|
|
|
|
ItemStatus = reader.GetAttribute("status").AsItemStatus(),
|
2020-09-03 21:32:00 -07:00
|
|
|
|
LoadFlag = reader.GetAttribute("loadflag").AsLoadFlag(),
|
2020-09-03 11:02:06 -07:00
|
|
|
|
|
|
|
|
|
|
DataArea = dataArea,
|
2019-01-11 13:43:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
items.Add(rom);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
return items;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read diskarea information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader representing a diskarea block</param>
|
2020-09-03 11:02:06 -07:00
|
|
|
|
/// <param name="diskArea">DiskArea representing the enclosing area</param>
|
|
|
|
|
|
private List<DatItem> ReadDiskArea(XmlReader reader, DiskArea diskArea)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-24 22:25:47 -07:00
|
|
|
|
List<DatItem> items = new List<DatItem>();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
while (!reader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the elements from the software
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "disk":
|
|
|
|
|
|
DatItem disk = new Disk
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
2020-07-15 09:41:59 -07:00
|
|
|
|
SHA1 = reader.GetAttribute("sha1"),
|
|
|
|
|
|
ItemStatus = reader.GetAttribute("status").AsItemStatus(),
|
|
|
|
|
|
Writable = reader.GetAttribute("writable").AsYesNo(),
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-03 11:02:06 -07:00
|
|
|
|
DiskArea = diskArea,
|
2019-01-11 13:43:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
items.Add(disk);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
return items;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-21 16:48:56 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read DipSwitch DipValues information
|
|
|
|
|
|
/// </summary>
|
2020-08-22 13:31:13 -07:00
|
|
|
|
/// <param name="reader">XmlReader representing a diskarea block</param>
|
2020-09-01 13:36:32 -07:00
|
|
|
|
/// <param name="dipSwitch">DipSwitch to populate</param>
|
|
|
|
|
|
private void ReadDipSwitch(XmlReader reader, DipSwitch dipSwitch)
|
2020-08-21 16:48:56 -07:00
|
|
|
|
{
|
2020-08-23 15:34:42 -07:00
|
|
|
|
// If we have an empty dipswitch, skip it
|
2020-08-21 16:48:56 -07:00
|
|
|
|
if (reader == null)
|
2020-08-22 13:31:13 -07:00
|
|
|
|
return;
|
2020-08-21 16:48:56 -07:00
|
|
|
|
|
|
|
|
|
|
// Get list ready
|
2020-09-01 16:21:55 -07:00
|
|
|
|
dipSwitch.Values = new List<Setting>();
|
2020-08-21 16:48:56 -07:00
|
|
|
|
|
|
|
|
|
|
// Otherwise, add what is possible
|
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
|
|
while (!reader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the information from the dipswitch
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "dipvalue":
|
2020-09-03 11:02:06 -07:00
|
|
|
|
var dipValue = new Setting
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = reader.GetAttribute("name"),
|
|
|
|
|
|
Value = reader.GetAttribute("value"),
|
|
|
|
|
|
Default = reader.GetAttribute("default").AsYesNo(),
|
|
|
|
|
|
};
|
2020-08-22 23:40:00 -07:00
|
|
|
|
|
|
|
|
|
|
dipSwitch.Values.Add(dipValue);
|
|
|
|
|
|
|
2020-08-22 13:31:13 -07:00
|
|
|
|
reader.Read();
|
2020-08-21 16:48:56 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-18 17:12:31 -07:00
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
protected override ItemType[] GetSupportedTypes()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ItemType[]
|
|
|
|
|
|
{
|
|
|
|
|
|
ItemType.DipSwitch,
|
|
|
|
|
|
ItemType.Disk,
|
|
|
|
|
|
ItemType.Info,
|
|
|
|
|
|
ItemType.Rom,
|
|
|
|
|
|
ItemType.SharedFeature,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-15 09:41:59 -07:00
|
|
|
|
XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false))
|
|
|
|
|
|
{
|
|
|
|
|
|
Formatting = Formatting.Indented,
|
|
|
|
|
|
IndentChar = '\t',
|
|
|
|
|
|
Indentation = 1
|
|
|
|
|
|
};
|
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
|
|
|
|
|
|
string lastgame = null;
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2020-08-28 15:06:07 -07:00
|
|
|
|
List<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
|
2020-08-28 15:06:07 -07:00
|
|
|
|
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
|
2020-06-10 22:37:19 -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
|
2020-08-28 15:06:07 -07:00
|
|
|
|
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
|
|
|
|
|
|
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))
|
|
|
|
|
|
WriteDatItem(xtw, datItem);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Set the new data to compare against
|
2020-08-28 15:06:07 -07:00
|
|
|
|
lastgame = datItem.Machine.Name;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Write the file footer out
|
2020-06-10 22:37:19 -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}");
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.Dispose();
|
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();
|
|
|
|
|
|
xtw.WriteDocType("softwarelist", null, "softwarelist.dtd", null);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.WriteStartElement("softwarelist");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", Header.Name);
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("description", Header.Description);
|
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>
|
|
|
|
|
|
/// <param name="datItem">DatItem object to be output</param>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
private 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
|
|
|
|
|
|
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// Build the state
|
|
|
|
|
|
xtw.WriteStartElement("software");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", datItem.Machine.Name);
|
|
|
|
|
|
if (!string.Equals(datItem.Machine.Name, datItem.Machine.CloneOf, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("cloneof", datItem.Machine.CloneOf);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("supported", datItem.Machine.Supported.FromSupported(false));
|
2020-09-15 12:12:13 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.WriteOptionalElementString("description", datItem.Machine.Description);
|
|
|
|
|
|
xtw.WriteOptionalElementString("year", datItem.Machine.Year);
|
|
|
|
|
|
xtw.WriteOptionalElementString("publisher", datItem.Machine.Publisher);
|
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>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
private void WriteEndGame(XmlTextWriter xtw)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// End software
|
|
|
|
|
|
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);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// Build the state
|
|
|
|
|
|
switch (datItem.ItemType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case ItemType.DipSwitch:
|
|
|
|
|
|
var dipSwitch = datItem as DipSwitch;
|
|
|
|
|
|
xtw.WriteStartElement("dipswitch");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", dipSwitch.Name);
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("tag", dipSwitch.Tag);
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("mask", dipSwitch.Mask);
|
2020-09-30 13:25:40 -07:00
|
|
|
|
if (dipSwitch.ValuesSpecified)
|
2020-09-15 14:23:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
foreach (Setting dipValue in dipSwitch.Values)
|
2020-09-01 13:36:32 -07:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.WriteStartElement("dipvalue");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", dipValue.Name);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("value", dipValue.Value);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("default", dipValue.Default.FromYesNo());
|
|
|
|
|
|
xtw.WriteEndElement();
|
2020-09-01 13:36:32 -07:00
|
|
|
|
}
|
2020-09-15 14:23:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
2020-09-01 13:36:32 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
case ItemType.Disk:
|
|
|
|
|
|
var disk = datItem as Disk;
|
|
|
|
|
|
string diskAreaName = disk.DiskArea?.Name;
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(diskAreaName))
|
|
|
|
|
|
diskAreaName = "cdrom";
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.WriteStartElement("part");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", disk.Part?.Name);
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("interface", disk.Part?.Interface);
|
2020-09-03 09:57:16 -07:00
|
|
|
|
|
2020-09-30 13:25:40 -07:00
|
|
|
|
if (disk.Part?.FeaturesSpecified == true)
|
2020-09-15 14:23:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
foreach (PartFeature partFeature in disk.Part.Features)
|
2020-09-03 09:57:16 -07:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.WriteStartElement("feature");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", partFeature.Name);
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("value", partFeature.Value);
|
|
|
|
|
|
xtw.WriteEndElement();
|
2020-09-03 09:57:16 -07:00
|
|
|
|
}
|
2020-09-15 14:23:40 -07:00
|
|
|
|
}
|
2020-09-03 09:57:16 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.WriteStartElement("diskarea");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", diskAreaName);
|
|
|
|
|
|
|
|
|
|
|
|
xtw.WriteStartElement("disk");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", disk.Name);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("md5", disk.MD5?.ToLowerInvariant());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("sha1", disk.SHA1?.ToLowerInvariant());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("status", disk.ItemStatus.FromItemStatus(false));
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("writable", disk.Writable.FromYesNo());
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
|
|
// End diskarea
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
|
|
// End part
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ItemType.Info:
|
|
|
|
|
|
var info = datItem as Info;
|
|
|
|
|
|
xtw.WriteStartElement("info");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", info.Name);
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("value", info.Value);
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ItemType.Rom:
|
|
|
|
|
|
var rom = datItem as Rom;
|
|
|
|
|
|
string dataAreaName = rom.DataArea?.Name;
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(dataAreaName))
|
|
|
|
|
|
dataAreaName = "rom";
|
|
|
|
|
|
|
|
|
|
|
|
xtw.WriteStartElement("part");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", rom.Part?.Name);
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("interface", rom.Part?.Interface);
|
|
|
|
|
|
|
2020-09-30 13:25:40 -07:00
|
|
|
|
if (rom.Part?.FeaturesSpecified == true)
|
2020-09-15 14:23:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
foreach (PartFeature kvp in rom.Part.Features)
|
2020-09-03 09:57:16 -07:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.WriteStartElement("feature");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", kvp.Name);
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("value", kvp.Value);
|
|
|
|
|
|
xtw.WriteEndElement();
|
2020-09-03 09:57:16 -07:00
|
|
|
|
}
|
2020-09-15 14:23:40 -07:00
|
|
|
|
}
|
2020-09-03 09:57:16 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
xtw.WriteStartElement("dataarea");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", dataAreaName);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("size", rom.DataArea?.Size.ToString());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("width", rom.DataArea?.Width?.ToString());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("endianness", rom.DataArea?.Endianness.FromEndianness());
|
|
|
|
|
|
|
|
|
|
|
|
xtw.WriteStartElement("rom");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", rom.Name);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("size", rom.Size?.ToString());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("crc", rom.CRC?.ToLowerInvariant());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("md5", rom.MD5?.ToLowerInvariant());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("sha1", rom.SHA1?.ToLowerInvariant());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("sha256", rom.SHA256?.ToLowerInvariant());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("sha384", rom.SHA384?.ToLowerInvariant());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("sha512", rom.SHA512?.ToLowerInvariant());
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("offset", rom.Offset);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("value", rom.Value);
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("status", rom.ItemStatus.FromItemStatus(false));
|
|
|
|
|
|
xtw.WriteOptionalAttributeString("loadflag", rom.LoadFlag.FromLoadFlag());
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
|
|
// End dataarea
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
|
|
// End part
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ItemType.SharedFeature:
|
|
|
|
|
|
var sharedFeature = datItem as SharedFeature;
|
|
|
|
|
|
xtw.WriteStartElement("sharedfeat");
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("name", sharedFeature.Name);
|
|
|
|
|
|
xtw.WriteRequiredAttributeString("value", sharedFeature.Value);
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
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>
|
2020-09-15 14:23:40 -07:00
|
|
|
|
private void WriteFooter(XmlTextWriter xtw)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// End software
|
|
|
|
|
|
xtw.WriteEndElement();
|
2020-09-15 12:12:13 -07:00
|
|
|
|
|
2020-09-15 14:23:40 -07:00
|
|
|
|
// End softwarelist
|
|
|
|
|
|
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
|
|
|
|
}
|