mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Use OpenMSX serializer for reading only
This commit is contained in:
@@ -54,7 +54,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
Header.Comment ??= doscenter.Comment;
|
Header.Comment ??= doscenter.Comment;
|
||||||
|
|
||||||
// Handle implied SuperDAT
|
// Handle implied SuperDAT
|
||||||
if (doscenter.Name.Contains(" - SuperDAT") && keep)
|
if (doscenter.Name?.Contains(" - SuperDAT") == true && keep)
|
||||||
Header.Type ??= "SuperDAT";
|
Header.Type ??= "SuperDAT";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Linq;
|
||||||
using System.Xml;
|
|
||||||
using System.Xml.Schema;
|
|
||||||
using SabreTools.Core;
|
using SabreTools.Core;
|
||||||
using SabreTools.Core.Tools;
|
|
||||||
using SabreTools.DatItems;
|
using SabreTools.DatItems;
|
||||||
using SabreTools.DatItems.Formats;
|
using SabreTools.DatItems.Formats;
|
||||||
|
|
||||||
@@ -17,144 +14,93 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
|
public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Prepare all internal variables
|
|
||||||
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
|
|
||||||
{
|
|
||||||
CheckCharacters = false,
|
|
||||||
DtdProcessing = DtdProcessing.Ignore,
|
|
||||||
IgnoreComments = true,
|
|
||||||
IgnoreWhitespace = true,
|
|
||||||
ValidationFlags = XmlSchemaValidationFlags.None,
|
|
||||||
ValidationType = ValidationType.None,
|
|
||||||
});
|
|
||||||
|
|
||||||
// If we got a null reader, just return
|
|
||||||
if (xtr == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Otherwise, read the file to the end
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
xtr.MoveToContent();
|
// Deserialize the input file
|
||||||
while (!xtr.EOF)
|
var softwareDb = Serialization.OpenMSX.Deserialize(filename);
|
||||||
{
|
|
||||||
// We only want elements
|
|
||||||
if (xtr.NodeType != XmlNodeType.Element)
|
|
||||||
{
|
|
||||||
xtr.Read();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (xtr.Name)
|
// Convert the header to the internal format
|
||||||
{
|
ConvertHeader(softwareDb);
|
||||||
case "softwaredb":
|
|
||||||
Header.Name ??= "openMSX Software List";
|
|
||||||
Header.Description ??= Header.Name;
|
|
||||||
Header.Date ??= xtr.GetAttribute("timestamp");
|
|
||||||
xtr.Read();
|
|
||||||
break;
|
|
||||||
|
|
||||||
// We want to process the entire subtree of the software
|
// Convert the software data to the internal format
|
||||||
case "software":
|
ConvertSoftwares(softwareDb?.Software, filename, indexId, statsOnly);
|
||||||
ReadSoftware(xtr.ReadSubtree(), statsOnly, filename, indexId);
|
|
||||||
|
|
||||||
// Skip the software now that we've processed it
|
|
||||||
xtr.Skip();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
xtr.Read();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex) when (!throwOnError)
|
catch (Exception ex) when (!throwOnError)
|
||||||
{
|
{
|
||||||
logger.Warning(ex, $"Exception found while parsing '{filename}'");
|
string message = $"'{filename}' - An error occurred during parsing";
|
||||||
|
logger.Error(ex, message);
|
||||||
// For XML errors, just skip the affected node
|
}
|
||||||
xtr?.Read();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xtr.Dispose();
|
#region Converters
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert header information
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datafile">Deserialized model to convert</param>
|
||||||
|
private void ConvertHeader(Models.OpenMSX.SoftwareDb? datafile)
|
||||||
|
{
|
||||||
|
// If the datafile is missing, we can't do anything
|
||||||
|
if (datafile == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Header.Name ??= "openMSX Software List";
|
||||||
|
Header.Description ??= Header.Name;
|
||||||
|
Header.Date ??= datafile.Timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read software information
|
/// Convert softwares information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">XmlReader representing a machine block</param>
|
/// <param name="softwares">Array of deserialized models to convert</param>
|
||||||
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
|
|
||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index ID for the DAT</param>
|
||||||
private void ReadSoftware(XmlReader reader, bool statsOnly, string filename, int indexId)
|
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
|
||||||
|
private void ConvertSoftwares(Models.OpenMSX.Software[]? softwares, string filename, int indexId, bool statsOnly)
|
||||||
{
|
{
|
||||||
// If we have an empty machine, skip it
|
// If the software array is missing, we can't do anything
|
||||||
if (reader == null)
|
if (softwares == null || !softwares.Any())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Otherwise, add what is possible
|
// Loop through the software and add
|
||||||
reader.MoveToContent();
|
foreach (var software in softwares)
|
||||||
|
{
|
||||||
|
ConvertSoftware(software, filename, indexId, statsOnly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int diskno = 0;
|
/// <summary>
|
||||||
|
/// Convert software information
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="software">Deserialized model to convert</param>
|
||||||
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
|
/// <param name="indexId">Index ID for the DAT</param>
|
||||||
|
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
|
||||||
|
private void ConvertSoftware(Models.OpenMSX.Software software, string filename, int indexId, bool statsOnly, string dirname = null)
|
||||||
|
{
|
||||||
|
// If the software is missing, we can't do anything
|
||||||
|
if (software == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Create the machine for copying information
|
||||||
|
var machine = new Machine
|
||||||
|
{
|
||||||
|
Name = software.Title,
|
||||||
|
GenMSXID = software.GenMSXID,
|
||||||
|
System = software.System,
|
||||||
|
Manufacturer = software.Company,
|
||||||
|
Year = software.Year,
|
||||||
|
Country = software.Country,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if there are any items
|
||||||
bool containsItems = false;
|
bool containsItems = false;
|
||||||
|
ConvertDumps(software.Dump, machine, filename, indexId, statsOnly, ref containsItems);
|
||||||
|
|
||||||
// Create a new machine
|
// If we had no items, create a Blank placeholder
|
||||||
Machine machine = new();
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
case "genmsxid":
|
|
||||||
machine.GenMSXID = reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "system":
|
|
||||||
machine.System = reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "company":
|
|
||||||
machine.Manufacturer = reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "year":
|
|
||||||
machine.Year = reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "country":
|
|
||||||
machine.Country = reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "dump":
|
|
||||||
containsItems = ReadDump(reader.ReadSubtree(), machine, diskno, statsOnly, filename, indexId);
|
|
||||||
diskno++;
|
|
||||||
|
|
||||||
// Skip the dump now that we've processed it
|
|
||||||
reader.Skip();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
reader.Read();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no items were found for this machine, add a Blank placeholder
|
|
||||||
if (!containsItems)
|
if (!containsItems)
|
||||||
{
|
{
|
||||||
Blank blank = new()
|
var blank = new Blank
|
||||||
{
|
{
|
||||||
Source = new Source
|
Source = new Source
|
||||||
{
|
{
|
||||||
@@ -164,342 +110,78 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
};
|
};
|
||||||
|
|
||||||
blank.CopyMachineInformation(machine);
|
blank.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
|
||||||
ParseAddHelper(blank, statsOnly);
|
ParseAddHelper(blank, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read dump information
|
/// Convert Dump information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reader">XmlReader representing a part block</param>
|
/// <param name="dumps">Array of deserialized models to convert</param>
|
||||||
/// <param name="machine">Machine information to pass to contained items</param>
|
/// <param name="machine">Prefilled machine to use</param>
|
||||||
/// <param name="diskno">Disk number to use when outputting to other DAT formats</param>
|
|
||||||
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
|
|
||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index ID for the DAT</param>
|
||||||
private bool ReadDump(
|
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
|
||||||
XmlReader reader,
|
/// <param name="containsItems">True if there were any items in the array, false otherwise</param>
|
||||||
Machine machine,
|
private void ConvertDumps(Models.OpenMSX.Dump[]? dumps, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
||||||
int diskno,
|
{
|
||||||
bool statsOnly,
|
// If the dumps array is missing, we can't do anything
|
||||||
|
if (dumps == null || !dumps.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
// Standard Dat parsing
|
containsItems = true;
|
||||||
string filename,
|
int index = 0;
|
||||||
int indexId)
|
foreach (var dump in dumps)
|
||||||
{
|
{
|
||||||
List<DatItem> items = new();
|
// If we don't have rom data, we can't do anything
|
||||||
Original original = null;
|
if (dump?.Rom == null)
|
||||||
|
|
||||||
while (!reader.EOF)
|
|
||||||
{
|
|
||||||
// We only want elements
|
|
||||||
if (reader.NodeType != XmlNodeType.Element)
|
|
||||||
{
|
|
||||||
reader.Read();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
// Get the elements from the dump
|
var rom = dump.Rom;
|
||||||
switch (reader.Name)
|
|
||||||
|
string name = $"{machine.Name}_{index++}{(!string.IsNullOrWhiteSpace(rom.Remark) ? $" {rom.Remark}" : string.Empty)}";
|
||||||
|
var item = new Rom
|
||||||
{
|
{
|
||||||
case "rom":
|
Name = name,
|
||||||
DatItem rom = ReadRom(reader.ReadSubtree(), machine, diskno, filename, indexId);
|
Offset = dump.Rom?.Start,
|
||||||
if (rom != null)
|
OpenMSXType = rom.Type,
|
||||||
items.Add(rom);
|
SHA1 = rom.Hash,
|
||||||
|
Remark = rom.Remark,
|
||||||
|
|
||||||
// Skip the rom now that we've processed it
|
Source = new Source
|
||||||
reader.Skip();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "megarom":
|
|
||||||
DatItem megarom = ReadMegaRom(reader.ReadSubtree(), machine, diskno, filename, indexId);
|
|
||||||
if (megarom != null)
|
|
||||||
items.Add(megarom);
|
|
||||||
|
|
||||||
// Skip the megarom now that we've processed it
|
|
||||||
reader.Skip();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "sccpluscart":
|
|
||||||
DatItem sccpluscart = ReadSccPlusCart(reader.ReadSubtree(), machine, diskno, filename, indexId);
|
|
||||||
if (sccpluscart != null)
|
|
||||||
items.Add(sccpluscart);
|
|
||||||
|
|
||||||
// Skip the sccpluscart now that we've processed it
|
|
||||||
reader.Skip();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "original":
|
|
||||||
original = new Original
|
|
||||||
{
|
{
|
||||||
Value = reader.GetAttribute("value").AsYesNo(),
|
Index = indexId,
|
||||||
Content = reader.ReadElementContentAsString()
|
Name = filename,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
if (dump.Original != null)
|
||||||
reader.Read();
|
{
|
||||||
break;
|
item.Original = new Original
|
||||||
}
|
{
|
||||||
|
Value = dump.Original.Value,
|
||||||
|
Content = dump.Original.Content,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have any items, loop through and add them
|
switch (dump.Rom)
|
||||||
foreach (DatItem item in items)
|
|
||||||
{
|
{
|
||||||
switch (item.ItemType)
|
case Models.OpenMSX.Rom:
|
||||||
{
|
item.OpenMSXSubType = OpenMSXSubType.Rom;
|
||||||
case ItemType.Rom:
|
break;
|
||||||
(item as Rom).Original = original;
|
case Models.OpenMSX.MegaRom:
|
||||||
|
item.OpenMSXSubType = OpenMSXSubType.MegaRom;
|
||||||
|
break;
|
||||||
|
case Models.OpenMSX.SCCPlusCart:
|
||||||
|
item.OpenMSXSubType = OpenMSXSubType.SCCPlusCart;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
item.CopyMachineInformation(machine);
|
||||||
ParseAddHelper(item, statsOnly);
|
ParseAddHelper(item, statsOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
return items.Count > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
#endregion
|
||||||
/// 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>
|
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
|
||||||
private DatItem ReadRom(
|
|
||||||
XmlReader reader,
|
|
||||||
Machine machine,
|
|
||||||
int diskno,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
|
||||||
string filename,
|
|
||||||
int indexId)
|
|
||||||
{
|
|
||||||
string hash = string.Empty,
|
|
||||||
offset = string.Empty,
|
|
||||||
type = string.Empty,
|
|
||||||
remark = string.Empty;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
case "start":
|
|
||||||
offset = reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "type":
|
|
||||||
type = reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "remark":
|
|
||||||
remark = reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
reader.Read();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we got a hash, then create and return the item
|
|
||||||
if (!string.IsNullOrWhiteSpace(hash))
|
|
||||||
{
|
|
||||||
return new Rom
|
|
||||||
{
|
|
||||||
Name = machine.Name + "_" + diskno + (!string.IsNullOrWhiteSpace(remark) ? " " + remark : string.Empty),
|
|
||||||
Offset = offset,
|
|
||||||
Size = null,
|
|
||||||
SHA1 = hash,
|
|
||||||
|
|
||||||
Source = new Source
|
|
||||||
{
|
|
||||||
Index = indexId,
|
|
||||||
Name = filename,
|
|
||||||
},
|
|
||||||
|
|
||||||
OpenMSXSubType = OpenMSXSubType.Rom,
|
|
||||||
OpenMSXType = type,
|
|
||||||
Remark = remark,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// No valid item means returning null
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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>
|
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
|
||||||
private DatItem ReadMegaRom(
|
|
||||||
XmlReader reader,
|
|
||||||
Machine machine,
|
|
||||||
int diskno,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
|
||||||
string filename,
|
|
||||||
int indexId)
|
|
||||||
{
|
|
||||||
string hash = string.Empty,
|
|
||||||
offset = string.Empty,
|
|
||||||
type = string.Empty,
|
|
||||||
remark = string.Empty;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
case "start":
|
|
||||||
offset = reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "type":
|
|
||||||
reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "remark":
|
|
||||||
remark = reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
reader.Read();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we got a hash, then create and return the item
|
|
||||||
if (!string.IsNullOrWhiteSpace(hash))
|
|
||||||
{
|
|
||||||
return new Rom
|
|
||||||
{
|
|
||||||
Name = machine.Name + "_" + diskno + (!string.IsNullOrWhiteSpace(remark) ? " " + remark : string.Empty),
|
|
||||||
Offset = offset,
|
|
||||||
Size = null,
|
|
||||||
SHA1 = hash,
|
|
||||||
|
|
||||||
Source = new Source
|
|
||||||
{
|
|
||||||
Index = indexId,
|
|
||||||
Name = filename,
|
|
||||||
},
|
|
||||||
|
|
||||||
OpenMSXSubType = OpenMSXSubType.MegaRom,
|
|
||||||
OpenMSXType = type,
|
|
||||||
Remark = remark,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// No valid item means returning null
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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>
|
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
|
||||||
private DatItem ReadSccPlusCart(
|
|
||||||
XmlReader reader,
|
|
||||||
Machine machine,
|
|
||||||
int diskno,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
|
||||||
string filename,
|
|
||||||
int indexId)
|
|
||||||
{
|
|
||||||
string boot = string.Empty,
|
|
||||||
hash = string.Empty,
|
|
||||||
remark = string.Empty;
|
|
||||||
|
|
||||||
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":
|
|
||||||
boot = reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "hash":
|
|
||||||
hash = reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "remark":
|
|
||||||
remark = reader.ReadElementContentAsString();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
reader.Read();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we got a hash, then create and return the item
|
|
||||||
if (!string.IsNullOrWhiteSpace(hash))
|
|
||||||
{
|
|
||||||
return new Rom
|
|
||||||
{
|
|
||||||
Name = machine.Name + "_" + diskno + (!string.IsNullOrWhiteSpace(remark) ? " " + remark : string.Empty),
|
|
||||||
Size = null,
|
|
||||||
SHA1 = hash,
|
|
||||||
|
|
||||||
Source = new Source
|
|
||||||
{
|
|
||||||
Index = indexId,
|
|
||||||
Name = filename,
|
|
||||||
},
|
|
||||||
|
|
||||||
OpenMSXSubType = OpenMSXSubType.SCCPlusCart,
|
|
||||||
Boot = boot,
|
|
||||||
Remark = remark,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// No valid item means returning null
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace SabreTools.Test.Parser
|
|||||||
Assert.NotNull(stream);
|
Assert.NotNull(stream);
|
||||||
byte[] hash = System.Security.Cryptography.SHA1.Create().ComputeHash(stream.GetBuffer());
|
byte[] hash = System.Security.Cryptography.SHA1.Create().ComputeHash(stream.GetBuffer());
|
||||||
string hashstr = BitConverter.ToString(hash).Replace("-", string.Empty);
|
string hashstr = BitConverter.ToString(hash).Replace("-", string.Empty);
|
||||||
Assert.Equal("195D11C8A93D73F9FBF1ECD8166D80D7BB1B0974", hashstr);
|
Assert.Equal("268940391C107ABE67E804BC5479E40B5FF68B34", hashstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Payload Generators
|
#region Payload Generators
|
||||||
|
|||||||
Reference in New Issue
Block a user