2018-03-15 16:59:48 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
using System.IO;
|
2018-03-15 16:59:48 -07:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Xml;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2018-03-15 16:59:48 -07:00
|
|
|
|
using SabreTools.Library.Data;
|
|
|
|
|
|
using SabreTools.Library.DatItems;
|
2020-08-01 23:04:11 -07:00
|
|
|
|
using SabreTools.Library.IO;
|
2020-08-21 23:48:35 -07:00
|
|
|
|
using SabreTools.Library.Tools;
|
2018-03-15 16:59:48 -07:00
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.Library.DatFiles
|
|
|
|
|
|
{
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents parsing and writing of a openMSX softawre list XML DAT
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
internal class OpenMSX : DatFile
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor designed for casting a base DatFile
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="datFile">Parent DatFile to copy from</param>
|
|
|
|
|
|
public OpenMSX(DatFile datFile)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
: base(datFile)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Parse a openMSX softawre list XML DAT and return all found games and roms within
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <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>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
2020-07-15 09:41:59 -07:00
|
|
|
|
protected override void ParseFile(
|
2019-01-11 13:43:15 -08:00
|
|
|
|
// Standard Dat parsing
|
|
|
|
|
|
string filename,
|
2020-07-15 09:41:59 -07:00
|
|
|
|
int indexId,
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Miscellaneous
|
2020-07-15 09:41:59 -07:00
|
|
|
|
bool keep)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
// Prepare all internal variables
|
2020-07-15 09:41:59 -07:00
|
|
|
|
XmlReader xtr = filename.GetXmlTextReader();
|
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 "softwaredb":
|
2020-08-08 14:06:05 -07:00
|
|
|
|
Header.Name = (Header.Name == null ? "openMSX Software List" : Header.Name);
|
|
|
|
|
|
Header.Description = (Header.Description == null ? Header.Name : Header.Description);
|
2020-08-20 15:53:56 -07:00
|
|
|
|
Header.Date = (Header.Date == null ? xtr.GetAttribute("timestamp") : Header.Date);
|
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 software
|
|
|
|
|
|
case "software":
|
2020-07-15 09:41:59 -07:00
|
|
|
|
ReadSoftware(xtr.ReadSubtree(), 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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
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 machine block</param>
|
|
|
|
|
|
/// <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>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
private void ReadSoftware(
|
|
|
|
|
|
XmlReader reader,
|
|
|
|
|
|
|
|
|
|
|
|
// Standard Dat parsing
|
|
|
|
|
|
string filename,
|
2020-07-15 09:41:59 -07:00
|
|
|
|
int indexId)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
// If we have an empty machine, skip it
|
|
|
|
|
|
if (reader == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// Otherwise, add what is possible
|
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
|
|
int diskno = 0;
|
|
|
|
|
|
bool containsItems = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Create a new machine
|
|
|
|
|
|
Machine machine = new Machine();
|
|
|
|
|
|
|
|
|
|
|
|
while (!reader.EOF)
|
|
|
|
|
|
{
|
|
|
|
|
|
// We only want elements
|
|
|
|
|
|
if (reader.NodeType != XmlNodeType.Element)
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the roms from the machine
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "title":
|
|
|
|
|
|
machine.Name = reader.ReadElementContentAsString();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "genmsxid":
|
2020-08-21 17:27:11 -07:00
|
|
|
|
machine.GenMSXID = reader.ReadElementContentAsString();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "system":
|
2020-08-21 17:27:11 -07:00
|
|
|
|
machine.System = reader.ReadElementContentAsString();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "company":
|
|
|
|
|
|
machine.Manufacturer = 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 "country":
|
2020-08-21 17:27:11 -07:00
|
|
|
|
machine.Country = reader.ReadElementContentAsString();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "dump":
|
2020-07-15 09:41:59 -07:00
|
|
|
|
containsItems = ReadDump(reader.ReadSubtree(), machine, diskno, filename, indexId);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
diskno++;
|
|
|
|
|
|
|
|
|
|
|
|
// Skip the dump 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-07-15 09:41:59 -07:00
|
|
|
|
ParseAddHelper(blank);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read dump information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader representing a part block</param>
|
|
|
|
|
|
/// <param name="machine">Machine information to pass to contained items</param>
|
|
|
|
|
|
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
|
|
|
|
|
|
/// <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>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
private bool ReadDump(
|
|
|
|
|
|
XmlReader reader,
|
|
|
|
|
|
Machine machine,
|
|
|
|
|
|
int diskno,
|
|
|
|
|
|
|
|
|
|
|
|
// Standard Dat parsing
|
|
|
|
|
|
string filename,
|
2020-07-15 09:41:59 -07:00
|
|
|
|
int indexId)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-21 23:48:35 -07:00
|
|
|
|
List<DatItem> items = new List<DatItem>();
|
|
|
|
|
|
OpenMSXOriginal original = null;
|
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 dump
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "rom":
|
2020-08-21 23:48:35 -07:00
|
|
|
|
DatItem rom = ReadRom(reader.ReadSubtree(), machine, diskno, filename, indexId);
|
|
|
|
|
|
if (rom != null)
|
|
|
|
|
|
items.Add(rom);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Skip the rom 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 "megarom":
|
2020-08-21 23:48:35 -07:00
|
|
|
|
DatItem megarom = ReadMegaRom(reader.ReadSubtree(), machine, diskno, filename, indexId);
|
|
|
|
|
|
if (megarom != null)
|
|
|
|
|
|
items.Add(megarom);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Skip the megarom 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 "sccpluscart":
|
2020-08-21 23:48:35 -07:00
|
|
|
|
DatItem sccpluscart = ReadSccPlusCart(reader.ReadSubtree(), machine, diskno, filename, indexId);
|
|
|
|
|
|
if (sccpluscart != null)
|
|
|
|
|
|
items.Add(sccpluscart);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Skip the sccpluscart 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 "original":
|
2020-08-22 23:40:00 -07:00
|
|
|
|
original = new OpenMSXOriginal();
|
|
|
|
|
|
original.Value = reader.GetAttribute("value").AsYesNo();
|
2020-08-23 21:10:29 -07:00
|
|
|
|
original.Content = reader.ReadElementContentAsString();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
// If we have any items, loop through and add them
|
|
|
|
|
|
foreach (DatItem item in items)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.CopyMachineInformation(machine);
|
|
|
|
|
|
item.Original = original;
|
|
|
|
|
|
ParseAddHelper(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return items.Count > 0;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read rom information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader representing a rom block</param>
|
|
|
|
|
|
/// <param name="machine">Machine information to pass to contained items</param>
|
|
|
|
|
|
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
|
|
|
|
|
|
/// <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-08-21 23:48:35 -07:00
|
|
|
|
private DatItem ReadRom(
|
2019-01-11 13:43:15 -08:00
|
|
|
|
XmlReader reader,
|
|
|
|
|
|
Machine machine,
|
|
|
|
|
|
int diskno,
|
|
|
|
|
|
|
|
|
|
|
|
// Standard Dat parsing
|
|
|
|
|
|
string filename,
|
2020-07-15 09:41:59 -07:00
|
|
|
|
int indexId)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-21 23:48:35 -07:00
|
|
|
|
string hash = string.Empty,
|
|
|
|
|
|
offset = string.Empty,
|
|
|
|
|
|
type = string.Empty,
|
|
|
|
|
|
remark = string.Empty;
|
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 rom
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "hash":
|
|
|
|
|
|
hash = reader.ReadElementContentAsString();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "start":
|
|
|
|
|
|
offset = reader.ReadElementContentAsString();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "type":
|
2020-08-21 23:48:35 -07:00
|
|
|
|
type = reader.ReadElementContentAsString();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "remark":
|
|
|
|
|
|
remark = reader.ReadElementContentAsString();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
// If we got a hash, then create and return the item
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(hash))
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-21 23:48:35 -07:00
|
|
|
|
return new Rom
|
2020-08-20 13:17:14 -07:00
|
|
|
|
{
|
2020-08-21 23:48:35 -07:00
|
|
|
|
Name = machine.Name + "_" + diskno + (!string.IsNullOrWhiteSpace(remark) ? " " + remark : string.Empty),
|
|
|
|
|
|
Offset = offset,
|
|
|
|
|
|
Size = -1,
|
|
|
|
|
|
SHA1 = hash,
|
|
|
|
|
|
|
|
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
OpenMSXSubType = OpenMSXSubType.Rom,
|
|
|
|
|
|
OpenMSXType = type,
|
|
|
|
|
|
Remark = remark,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
// No valid item means returning null
|
|
|
|
|
|
return null;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read megarom information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader representing a megarom block</param>
|
|
|
|
|
|
/// <param name="machine">Machine information to pass to contained items</param>
|
|
|
|
|
|
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
|
|
|
|
|
|
/// <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-08-21 23:48:35 -07:00
|
|
|
|
private DatItem ReadMegaRom(
|
2019-01-11 13:43:15 -08:00
|
|
|
|
XmlReader reader,
|
|
|
|
|
|
Machine machine,
|
|
|
|
|
|
int diskno,
|
|
|
|
|
|
|
|
|
|
|
|
// Standard Dat parsing
|
|
|
|
|
|
string filename,
|
2020-07-15 09:41:59 -07:00
|
|
|
|
int indexId)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-21 23:48:35 -07:00
|
|
|
|
string hash = string.Empty,
|
|
|
|
|
|
offset = string.Empty,
|
|
|
|
|
|
type = string.Empty,
|
|
|
|
|
|
remark = string.Empty;
|
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 dump
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "hash":
|
|
|
|
|
|
hash = reader.ReadElementContentAsString();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "start":
|
|
|
|
|
|
offset = reader.ReadElementContentAsString();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "type":
|
2020-07-15 09:41:59 -07:00
|
|
|
|
reader.ReadElementContentAsString();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "remark":
|
|
|
|
|
|
remark = reader.ReadElementContentAsString();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
// If we got a hash, then create and return the item
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(hash))
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-21 23:48:35 -07:00
|
|
|
|
return new Rom
|
2020-08-20 13:17:14 -07:00
|
|
|
|
{
|
2020-08-21 23:48:35 -07:00
|
|
|
|
Name = machine.Name + "_" + diskno + (!string.IsNullOrWhiteSpace(remark) ? " " + remark : string.Empty),
|
|
|
|
|
|
Offset = offset,
|
|
|
|
|
|
Size = -1,
|
|
|
|
|
|
SHA1 = hash,
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
OpenMSXSubType = OpenMSXSubType.MegaRom,
|
|
|
|
|
|
OpenMSXType = type,
|
|
|
|
|
|
Remark = remark,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
// No valid item means returning null
|
|
|
|
|
|
return null;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read sccpluscart information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="reader">XmlReader representing a sccpluscart block</param>
|
|
|
|
|
|
/// <param name="machine">Machine information to pass to contained items</param>
|
|
|
|
|
|
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
|
|
|
|
|
|
/// <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-08-21 23:48:35 -07:00
|
|
|
|
private DatItem ReadSccPlusCart(
|
2019-01-11 13:43:15 -08:00
|
|
|
|
XmlReader reader,
|
|
|
|
|
|
Machine machine,
|
|
|
|
|
|
int diskno,
|
|
|
|
|
|
|
|
|
|
|
|
// Standard Dat parsing
|
|
|
|
|
|
string filename,
|
2020-07-15 09:41:59 -07:00
|
|
|
|
int indexId)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-21 23:48:35 -07:00
|
|
|
|
string boot = string.Empty,
|
|
|
|
|
|
hash = string.Empty,
|
|
|
|
|
|
remark = string.Empty;
|
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 dump
|
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "boot":
|
2020-08-21 23:48:35 -07:00
|
|
|
|
boot = reader.ReadElementContentAsString();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "hash":
|
|
|
|
|
|
hash = reader.ReadElementContentAsString();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
case "remark":
|
|
|
|
|
|
remark = reader.ReadElementContentAsString();
|
|
|
|
|
|
break;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2019-01-11 13:43:15 -08:00
|
|
|
|
default:
|
|
|
|
|
|
reader.Read();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
// If we got a hash, then create and return the item
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(hash))
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-21 23:48:35 -07:00
|
|
|
|
return new Rom
|
2020-08-20 13:17:14 -07:00
|
|
|
|
{
|
2020-08-21 23:48:35 -07:00
|
|
|
|
Name = machine.Name + "_" + diskno + (!string.IsNullOrWhiteSpace(remark) ? " " + remark : string.Empty),
|
|
|
|
|
|
Size = -1,
|
|
|
|
|
|
SHA1 = hash,
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
Source = new Source
|
|
|
|
|
|
{
|
|
|
|
|
|
Index = indexId,
|
|
|
|
|
|
Name = filename,
|
|
|
|
|
|
},
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
OpenMSXSubType = OpenMSXSubType.SCCPlusCart,
|
|
|
|
|
|
Boot = boot,
|
|
|
|
|
|
Remark = remark,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// No valid item means returning null
|
|
|
|
|
|
return null;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create and open an output file for writing direct from a dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="outfile">Name of the file to write to</param>
|
|
|
|
|
|
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
|
|
|
|
|
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
|
|
|
|
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
Globals.Logger.User($"Opening file for writing: {outfile}");
|
2020-07-15 09:41:59 -07:00
|
|
|
|
FileStream fs = FileExtensions.TryCreate(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-06-10 22:37:19 -07:00
|
|
|
|
Globals.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-07-26 22:34:45 -07:00
|
|
|
|
List<DatItem> roms = Items[key];
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Resolve the names in the block
|
|
|
|
|
|
roms = DatItem.ResolveNames(roms);
|
|
|
|
|
|
|
|
|
|
|
|
for (int index = 0; index < roms.Count; index++)
|
|
|
|
|
|
{
|
|
|
|
|
|
DatItem rom = roms[index];
|
|
|
|
|
|
|
|
|
|
|
|
// There are apparently times when a null rom can skip by, skip them
|
2020-08-20 13:17:14 -07:00
|
|
|
|
if (rom.Name == null || rom.Machine.Name == null)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
Globals.Logger.Warning("Null rom found!");
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If we have a different game and we're not at the start of the list, output the end of last item
|
2020-08-20 13:17:14 -07:00
|
|
|
|
if (lastgame != null && lastgame.ToLowerInvariant() != rom.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-20 13:17:14 -07:00
|
|
|
|
if (lastgame == null || lastgame.ToLowerInvariant() != rom.Machine.Name.ToLowerInvariant())
|
2020-06-10 22:37:19 -07:00
|
|
|
|
WriteStartGame(xtw, rom);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// If we have a "null" game (created by DATFromDir or something similar), log it to file
|
|
|
|
|
|
if (rom.ItemType == ItemType.Rom
|
|
|
|
|
|
&& ((Rom)rom).Size == -1
|
|
|
|
|
|
&& ((Rom)rom).CRC == "null")
|
|
|
|
|
|
{
|
2020-08-20 13:17:14 -07:00
|
|
|
|
Globals.Logger.Verbose($"Empty folder found: {rom.Machine.Name}");
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-20 13:17:14 -07:00
|
|
|
|
lastgame = rom.Machine.Name;
|
2019-01-11 13:43:15 -08:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Now, output the rom data
|
2020-06-10 22:37:19 -07:00
|
|
|
|
WriteDatItem(xtw, rom, ignoreblanks);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
|
|
|
|
|
// Set the new data to compare against
|
2020-08-20 13:17:14 -07:00
|
|
|
|
lastgame = rom.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
|
|
|
|
|
|
|
|
|
|
Globals.Logger.Verbose("File written!" + Environment.NewLine);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.Dispose();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
fs.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Globals.Logger.Error(ex.ToString());
|
|
|
|
|
|
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>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <returns>True if the data was written, false on error</returns>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
private bool WriteHeader(XmlTextWriter xtw)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.WriteStartDocument();
|
|
|
|
|
|
xtw.WriteDocType("softwaredb", null, "softwaredb1.dtd", null);
|
|
|
|
|
|
|
|
|
|
|
|
xtw.WriteStartElement("softwaredb");
|
2020-08-24 00:48:27 -07:00
|
|
|
|
xtw.WriteRequiredAttributeString("timestamp", Header.Date);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-06-11 11:44:46 -07:00
|
|
|
|
//TODO: Figure out how to fix the issue with removed formatting after this point
|
|
|
|
|
|
// xtw.WriteComment("Credits");
|
|
|
|
|
|
// xtw.WriteCData(@"The softwaredb.xml file contains information about rom mapper types
|
|
|
|
|
|
|
|
|
|
|
|
//-Copyright 2003 Nicolas Beyaert(Initial Database)
|
|
|
|
|
|
//-Copyright 2004 - 2013 BlueMSX Team
|
|
|
|
|
|
//-Copyright 2005 - 2020 openMSX Team
|
|
|
|
|
|
//-Generation MSXIDs by www.generation - msx.nl
|
|
|
|
|
|
|
|
|
|
|
|
//- Thanks go out to:
|
|
|
|
|
|
//-Generation MSX / Sylvester for the incredible source of information
|
|
|
|
|
|
//- p_gimeno and diedel for their help adding and valdiating ROM additions
|
|
|
|
|
|
//- GDX for additional ROM info and validations and corrections");
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
|
|
|
|
|
xtw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Globals.Logger.Error(ex.ToString());
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <returns>True if the data was written, false on error</returns>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
private bool WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// No game should start with a path separator
|
2020-08-20 13:17:14 -07:00
|
|
|
|
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-08-23 22:23:55 -07:00
|
|
|
|
// Build the state
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.WriteStartElement("software");
|
2020-08-24 00:48:27 -07:00
|
|
|
|
xtw.WriteRequiredElementString("title", datItem.Machine.Name);
|
|
|
|
|
|
xtw.WriteRequiredElementString("genmsxid", datItem.Machine.GenMSXID);
|
|
|
|
|
|
xtw.WriteRequiredElementString("system", datItem.Machine.System);
|
|
|
|
|
|
xtw.WriteRequiredElementString("company", datItem.Machine.Manufacturer);
|
|
|
|
|
|
xtw.WriteRequiredElementString("year", datItem.Machine.Year);
|
|
|
|
|
|
xtw.WriteRequiredElementString("country", datItem.Machine.Country);
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
|
|
|
|
|
xtw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Globals.Logger.Error(ex.ToString());
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <returns>True if the data was written, false on error</returns>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
private bool WriteEndGame(XmlTextWriter xtw)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
// End software
|
|
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Globals.Logger.Error(ex.ToString());
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
|
|
|
|
|
|
/// <returns>True if the data was written, false on error</returns>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem, bool ignoreblanks = false)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
// If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
2020-06-10 22:37:19 -07:00
|
|
|
|
if (ignoreblanks && (datItem.ItemType == ItemType.Rom && ((datItem as Rom).Size == 0 || (datItem as Rom).Size == -1)))
|
2019-01-11 13:43:15 -08:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// Pre-process the item name
|
2020-06-10 22:37:19 -07:00
|
|
|
|
ProcessItemName(datItem, true);
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-08-23 22:23:55 -07:00
|
|
|
|
// Build the state
|
2020-06-10 22:37:19 -07:00
|
|
|
|
switch (datItem.ItemType)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
2020-08-21 23:48:35 -07:00
|
|
|
|
case ItemType.Rom:
|
2020-06-10 22:37:19 -07:00
|
|
|
|
var rom = datItem as Rom;
|
|
|
|
|
|
xtw.WriteStartElement("dump");
|
|
|
|
|
|
|
2020-08-23 22:23:55 -07:00
|
|
|
|
if (rom.Original != null)
|
2020-08-21 23:48:35 -07:00
|
|
|
|
{
|
|
|
|
|
|
xtw.WriteStartElement("original");
|
|
|
|
|
|
xtw.WriteAttributeString("value", rom.Original.Value == true ? "true" : "false");
|
2020-08-23 21:10:29 -07:00
|
|
|
|
xtw.WriteString(rom.Original.Content);
|
2020-08-21 23:48:35 -07:00
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
}
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
switch (datItem.OpenMSXSubType)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Default to Rom for converting from other formats
|
|
|
|
|
|
case OpenMSXSubType.Rom:
|
|
|
|
|
|
case OpenMSXSubType.NULL:
|
2020-08-24 13:21:59 -07:00
|
|
|
|
xtw.WriteStartElement(datItem.OpenMSXSubType.FromOpenMSXSubType());
|
2020-08-24 11:56:49 -07:00
|
|
|
|
xtw.WriteRequiredElementString("hash", rom.SHA1?.ToLowerInvariant());
|
2020-08-24 00:25:23 -07:00
|
|
|
|
xtw.WriteOptionalElementString("start", rom.Offset);
|
|
|
|
|
|
xtw.WriteOptionalElementString("type", rom.OpenMSXType);
|
|
|
|
|
|
xtw.WriteOptionalElementString("remark", rom.Remark);
|
2020-08-21 23:48:35 -07:00
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case OpenMSXSubType.MegaRom:
|
2020-08-24 13:21:59 -07:00
|
|
|
|
xtw.WriteStartElement(datItem.OpenMSXSubType.FromOpenMSXSubType());
|
2020-08-24 11:56:49 -07:00
|
|
|
|
xtw.WriteRequiredElementString("hash", rom.SHA1?.ToLowerInvariant());
|
2020-08-24 00:25:23 -07:00
|
|
|
|
xtw.WriteOptionalElementString("start", rom.Offset);
|
|
|
|
|
|
xtw.WriteOptionalElementString("type", rom.OpenMSXType);
|
|
|
|
|
|
xtw.WriteOptionalElementString("remark", rom.Remark);
|
2020-08-21 23:48:35 -07:00
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case OpenMSXSubType.SCCPlusCart:
|
2020-08-24 13:21:59 -07:00
|
|
|
|
xtw.WriteStartElement(datItem.OpenMSXSubType.FromOpenMSXSubType());
|
2020-08-24 00:25:23 -07:00
|
|
|
|
xtw.WriteOptionalElementString("boot", rom.Boot);
|
2020-08-24 11:56:49 -07:00
|
|
|
|
xtw.WriteRequiredElementString("hash", rom.SHA1?.ToLowerInvariant());
|
2020-08-24 00:25:23 -07:00
|
|
|
|
xtw.WriteOptionalElementString("remark", rom.Remark);
|
2020-08-21 23:48:35 -07:00
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
|
|
|
|
|
// End dump
|
|
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Globals.Logger.Error(ex.ToString());
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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>
|
2019-01-11 13:43:15 -08:00
|
|
|
|
/// <returns>True if the data was written, false on error</returns>
|
2020-06-10 22:37:19 -07:00
|
|
|
|
private bool WriteFooter(XmlTextWriter xtw)
|
2019-01-11 13:43:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
// End software
|
|
|
|
|
|
xtw.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
|
|
// End softwaredb
|
|
|
|
|
|
xtw.WriteEndElement();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
xtw.Flush();
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Globals.Logger.Error(ex.ToString());
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-03-15 16:59:48 -07:00
|
|
|
|
}
|