Use OfflineList serializer for reading only

This commit is contained in:
Matt Nadareski
2023-07-31 16:11:27 -04:00
parent b5011c31cd
commit a3f273db98
4 changed files with 310 additions and 534 deletions

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Xml; using System.Linq;
using System.Xml.Schema;
using SabreTools.Core; using SabreTools.Core;
using SabreTools.Core.Tools; using SabreTools.Core.Tools;
using SabreTools.DatItems; using SabreTools.DatItems;
@@ -17,619 +16,362 @@ 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)
{ {
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 dat = Serialization.OfflineList.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(dat);
case "configuration":
ReadConfiguration(xtr.ReadSubtree(), keep);
// Skip the configuration node now that we've processed it // Convert the configuration to the internal format
xtr.Skip(); ConvertConfiguration(dat.Configuration, keep);
break;
case "games": // Convert the games to the internal format
ReadGames(xtr.ReadSubtree(), statsOnly, filename, indexId); ConvertGames(dat?.Games, filename, indexId, statsOnly);
// Skip the games node now that we've processed it // Convert the GUI to the internal format
xtr.Skip(); ConvertGUI(dat?.GUI);
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();
} }
/// <summary> #region Converters
/// Read configuration information
/// </summary>
/// <param name="reader">XmlReader to use to parse the header</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
private void ReadConfiguration(XmlReader reader, bool keep)
{
bool superdat = false;
// If there's no subtree to the configuration, skip it /// <summary>
if (reader == null) /// Convert header information
/// </summary>
/// <param name="dat">Deserialized model to convert</param>
private void ConvertHeader(Models.OfflineList.Dat? dat)
{
// If the datafile is missing, we can't do anything
if (dat == null)
return; return;
// Otherwise, add what is possible //Header.NoNamespaceSchemaLocation = dat.NoNamespaceSchemaLocation; // TODO: Add to internal model
reader.MoveToContent();
// Otherwise, read what we can from the header
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get all configuration items (ONLY OVERWRITE IF THERE'S NO DATA)
string content;
switch (reader.Name.ToLowerInvariant())
{
case "datname":
content = reader.ReadElementContentAsString();
Header.Name ??= content;
superdat |= content.Contains(" - SuperDAT");
if (keep && superdat)
{
Header.Type ??= "SuperDAT";
}
break;
case "datversion":
content = reader.ReadElementContentAsString();
Header.Version ??= content;
break;
case "system":
content = reader.ReadElementContentAsString();
Header.System ??= content;
break;
// TODO: Int32?
case "screenshotswidth":
content = reader.ReadElementContentAsString();
Header.ScreenshotsWidth ??= content;
break;
// TODO: Int32?
case "screenshotsheight":
content = reader.ReadElementContentAsString();
Header.ScreenshotsHeight ??= content;
break;
case "infos":
ReadInfos(reader.ReadSubtree());
// Skip the infos node now that we've processed it
reader.Skip();
break;
case "canopen":
ReadCanOpen(reader.ReadSubtree());
// Skip the canopen node now that we've processed it
reader.Skip();
break;
// TODO: Use all header values
case "newdat":
ReadNewDat(reader.ReadSubtree());
// Skip the newdat node now that we've processed it
reader.Skip();
break;
// TODO: Use header values
case "search":
ReadSearch(reader.ReadSubtree());
// Skip the search node now that we've processed it
reader.Skip();
break;
case "romtitle":
content = reader.ReadElementContentAsString();
Header.RomTitle ??= content;
break;
default:
reader.Read();
break;
}
}
} }
/// <summary> /// <summary>
/// Read infos information /// Convert configuration information
/// </summary> /// </summary>
/// <param name="reader">XmlReader to use to parse the header</param> /// <param name="config">Deserialized model to convert</param>
private void ReadInfos(XmlReader reader) private void ConvertConfiguration(Models.OfflineList.Configuration? config, bool keep)
{ {
// If there's no subtree to the configuration, skip it // If the config is missing, we can't do anything
if (reader == null) if (config == null)
return; return;
// Setup the infos object Header.Name ??= config.DatName;
Header.Infos = new List<OfflineListInfo>(); //Header.ImFolder ??= config.ImFolder; // TODO: Add to internal model
Header.Version = config.DatVersion;
Header.System = config.System;
Header.ScreenshotsWidth = config.ScreenshotsWidth;
Header.ScreenshotsHeight = config.ScreenshotsHeight;
ConvertInfos(config.Infos);
ConvertCanOpen(config.CanOpen);
ConvertNewDat(config.NewDat);
ConvertSearch(config.Search);
Header.RomTitle = config.RomTitle;
// Otherwise, add what is possible // Handle implied SuperDAT
reader.MoveToContent(); if (config.DatName.Contains(" - SuperDAT") && keep)
Header.Type ??= "SuperDAT";
// Otherwise, read what we can from the header
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Add all infos to the info list
switch (reader.Name.ToLowerInvariant())
{
default:
var info = new OfflineListInfo
{
Name = reader.Name.ToLowerInvariant(),
Visible = reader.GetAttribute("visible").AsYesNo(),
InNamingOption = reader.GetAttribute("inNamingOption").AsYesNo(),
Default = reader.GetAttribute("default").AsYesNo()
};
Header.Infos.Add(info);
reader.Read();
break;
}
}
} }
/// <summary> /// <summary>
/// Read canopen information /// Convert infos information
/// </summary> /// </summary>
/// <param name="reader">XmlReader to use to parse the header</param> /// <param name="infos">Deserialized model to convert</param>
private void ReadCanOpen(XmlReader reader) private void ConvertInfos(Models.OfflineList.Infos? infos)
{ {
// Prepare all internal variables // If the infos is missing, we can't do anything
Header.CanOpen = new List<string>(); if (infos == null)
// If there's no subtree to the configuration, skip it
if (reader == null)
return; return;
// Otherwise, add what is possible var offlineListInfos = new List<OfflineListInfo>();
reader.MoveToContent();
// Otherwise, read what we can from the header if (infos.Title != null)
while (!reader.EOF)
{ {
// We only want elements offlineListInfos.Add(new OfflineListInfo
if (reader.NodeType != XmlNodeType.Element)
{ {
reader.Read(); Name = "title",
continue; Visible = infos.Title.Visible.AsYesNo(),
} InNamingOption = infos.Title.InNamingOption.AsYesNo(),
Default = infos.Title.Default.AsYesNo(),
// Get all canopen items });
switch (reader.Name.ToLowerInvariant())
{
case "extension":
Header.CanOpen.Add(reader.ReadElementContentAsString());
break;
default:
reader.Read();
break;
}
} }
if (infos.Location != null)
{
offlineListInfos.Add(new OfflineListInfo
{
Name = "location",
Visible = infos.Location.Visible.AsYesNo(),
InNamingOption = infos.Location.InNamingOption.AsYesNo(),
Default = infos.Location.Default.AsYesNo(),
});
}
if (infos.Publisher != null)
{
offlineListInfos.Add(new OfflineListInfo
{
Name = "publisher",
Visible = infos.Publisher.Visible.AsYesNo(),
InNamingOption = infos.Publisher.InNamingOption.AsYesNo(),
Default = infos.Publisher.Default.AsYesNo(),
});
}
if (infos.SourceRom != null)
{
offlineListInfos.Add(new OfflineListInfo
{
Name = "sourceRom",
Visible = infos.SourceRom.Visible.AsYesNo(),
InNamingOption = infos.SourceRom.InNamingOption.AsYesNo(),
Default = infos.SourceRom.Default.AsYesNo(),
});
}
if (infos.SaveType != null)
{
offlineListInfos.Add(new OfflineListInfo
{
Name = "saveType",
Visible = infos.SaveType.Visible.AsYesNo(),
InNamingOption = infos.SaveType.InNamingOption.AsYesNo(),
Default = infos.SaveType.Default.AsYesNo(),
});
}
if (infos.RomSize != null)
{
offlineListInfos.Add(new OfflineListInfo
{
Name = "romSize",
Visible = infos.RomSize.Visible.AsYesNo(),
InNamingOption = infos.RomSize.InNamingOption.AsYesNo(),
Default = infos.RomSize.Default.AsYesNo(),
});
}
if (infos.ReleaseNumber != null)
{
offlineListInfos.Add(new OfflineListInfo
{
Name = "releaseNumber",
Visible = infos.ReleaseNumber.Visible.AsYesNo(),
InNamingOption = infos.ReleaseNumber.InNamingOption.AsYesNo(),
Default = infos.ReleaseNumber.Default.AsYesNo(),
});
}
if (infos.LanguageNumber != null)
{
offlineListInfos.Add(new OfflineListInfo
{
Name = "languageNumber",
Visible = infos.LanguageNumber.Visible.AsYesNo(),
InNamingOption = infos.LanguageNumber.InNamingOption.AsYesNo(),
Default = infos.LanguageNumber.Default.AsYesNo(),
});
}
if (infos.Comment != null)
{
offlineListInfos.Add(new OfflineListInfo
{
Name = "comment",
Visible = infos.Comment.Visible.AsYesNo(),
InNamingOption = infos.Comment.InNamingOption.AsYesNo(),
Default = infos.Comment.Default.AsYesNo(),
});
}
if (infos.RomCRC != null)
{
offlineListInfos.Add(new OfflineListInfo
{
Name = "romCRC",
Visible = infos.RomCRC.Visible.AsYesNo(),
InNamingOption = infos.RomCRC.InNamingOption.AsYesNo(),
Default = infos.RomCRC.Default.AsYesNo(),
});
}
if (infos.Im1CRC != null)
{
offlineListInfos.Add(new OfflineListInfo
{
Name = "im1CRC",
Visible = infos.Im1CRC.Visible.AsYesNo(),
InNamingOption = infos.Im1CRC.InNamingOption.AsYesNo(),
Default = infos.Im1CRC.Default.AsYesNo(),
});
}
if (infos.Im2CRC != null)
{
offlineListInfos.Add(new OfflineListInfo
{
Name = "im2CRC",
Visible = infos.Im2CRC.Visible.AsYesNo(),
InNamingOption = infos.Im2CRC.InNamingOption.AsYesNo(),
Default = infos.Im2CRC.Default.AsYesNo(),
});
}
if (infos.Languages != null)
{
offlineListInfos.Add(new OfflineListInfo
{
Name = "languages",
Visible = infos.Languages.Visible.AsYesNo(),
InNamingOption = infos.Languages.InNamingOption.AsYesNo(),
Default = infos.Languages.Default.AsYesNo(),
});
}
Header.Infos = offlineListInfos;
} }
/// <summary> /// <summary>
/// Read newdat information /// Convert canopen information
/// </summary> /// </summary>
/// <param name="reader">XmlReader to use to parse the header</param> /// <param name="canOpen">Deserialized model to convert</param>
private void ReadNewDat(XmlReader reader) private void ConvertCanOpen(Models.OfflineList.CanOpen? canOpen)
{ {
// If there's no subtree to the configuration, skip it // If the canOpen is missing, we can't do anything
if (reader == null) if (canOpen == null)
return; return;
// Otherwise, add what is possible Header.CanOpen = new List<string>(canOpen.Extension);
reader.MoveToContent();
// Otherwise, read what we can from the header
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get all newdat items
string content;
switch (reader.Name.ToLowerInvariant())
{
case "datversionurl":
// TODO: Read this into an appropriate field
content = reader.ReadElementContentAsString();
Header.Url ??= content;
break;
case "daturl":
// TODO: Read this into an appropriate structure
reader.GetAttribute("fileName");
reader.ReadElementContentAsString();
break;
case "imurl":
// TODO: Read this into an appropriate field
reader.ReadElementContentAsString();
break;
default:
reader.Read();
break;
}
}
} }
/// <summary> /// <summary>
/// Read search information /// Convert newdat information
/// </summary> /// </summary>
/// <param name="reader">XmlReader to use to parse the header</param> /// <param name="newDat">Deserialized model to convert</param>
private void ReadSearch(XmlReader reader) private void ConvertNewDat(Models.OfflineList.NewDat? newDat)
{ {
// If there's no subtree to the configuration, skip it // If the canOpen is missing, we can't do anything
if (reader == null) if (newDat == null)
return; return;
// Otherwise, add what is possible Header.Url = newDat.DatVersionUrl;
reader.MoveToContent(); //Header.DatUrl = newDat.DatUrl; // TODO: Add to internal model
//Header.ImUrl = newDat.ImUrl; // TODO: Add to internal model
// Otherwise, read what we can from the header
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get all search items
switch (reader.Name.ToLowerInvariant())
{
case "to":
// TODO: Read this into an appropriate structure
reader.GetAttribute("value");
reader.GetAttribute("default"); // (true|false)
reader.GetAttribute("auto"); // (true|false)
ReadTo(reader.ReadSubtree());
// Skip the to node now that we've processed it
reader.Skip();
break;
default:
reader.Read();
break;
}
}
} }
/// <summary> /// <summary>
/// Read to information /// Convert search information
/// </summary> /// </summary>
/// <param name="reader">XmlReader to use to parse the header</param> /// <param name="search">Deserialized model to convert</param>
private void ReadTo(XmlReader reader) private void ConvertSearch(Models.OfflineList.Search? search)
{ {
// If there's no subtree to the configuration, skip it // If the search or to array is missing, we can't do anything
if (reader == null) if (search?.To == null)
return; return;
// Otherwise, add what is possible // TODO: Add to internal model
reader.MoveToContent();
// Otherwise, read what we can from the header
while (!reader.EOF)
{
// We only want elements
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get all search items
switch (reader.Name.ToLowerInvariant())
{
case "find":
// TODO: Read this into an appropriate structure
reader.GetAttribute("operation");
reader.GetAttribute("value"); // Int32?
reader.ReadElementContentAsString();
break;
default:
reader.Read();
break;
}
}
} }
/// <summary> /// <summary>
/// Read games information /// Convert games information
/// </summary> /// </summary>
/// <param name="reader">XmlReader to use to parse the header</param> /// <param name="search">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> /// <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> private void ConvertGames(Models.OfflineList.Games? games, string filename, int indexId, bool statsOnly)
/// <param name="indexId">Index ID for the DAT</param>
private void ReadGames(XmlReader reader, bool statsOnly, string filename, int indexId)
{ {
// If there's no subtree to the configuration, skip it // If the games array is missing, we can't do anything
if (reader == null) if (games?.Game == null || !games.Game.Any())
return; return;
// Otherwise, add what is possible foreach (var game in games.Game)
reader.MoveToContent();
// Otherwise, read what we can from the header
while (!reader.EOF)
{ {
// We only want elements ConvertGame(game, filename, indexId, statsOnly);
if (reader.NodeType != XmlNodeType.Element)
{
reader.Read();
continue;
}
// Get all games items (ONLY OVERWRITE IF THERE'S NO DATA)
switch (reader.Name.ToLowerInvariant())
{
case "game":
ReadGame(reader.ReadSubtree(), statsOnly, filename, indexId);
// Skip the game node now that we've processed it
reader.Skip();
break;
default:
reader.Read();
break;
}
} }
} }
/// <summary> /// <summary>
/// Read game information /// Convert game information
/// </summary> /// </summary>
/// <param name="reader">XmlReader to use to parse the header</param> /// <param name="search">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> /// <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> private void ConvertGame(Models.OfflineList.Game? game, string filename, int indexId, bool statsOnly)
/// <param name="indexId">Index ID for the DAT</param>
private void ReadGame(XmlReader reader, bool statsOnly, string filename, int indexId)
{ {
// Prepare all internal variables // If the game is missing, we can't do anything
string releaseNumber = string.Empty, duplicateid; if (game == null)
long? size = null;
List<Rom> datItems = new();
Machine machine = new();
// If there's no subtree to the configuration, skip it
if (reader == null)
return; return;
// Otherwise, add what is possible var machine = new Machine
reader.MoveToContent();
// Otherwise, read what we can from the header
while (!reader.EOF)
{ {
// We only want elements //ImageNumber = game.ImageNumber, // TODO: Add to internal model
if (reader.NodeType != XmlNodeType.Element) //ReleaseNumber = game.ReleaseNumber, // TODO: Add to internal model
{ Name = game.Title,
reader.Read(); //SaveType = game.SaveType, // TODO: Add to internal model
continue; Publisher = game.Publisher,
} //Location = game.Location, // TODO: Add to internal model
//SourceRom = game.SourceRom, // TODO: Add to internal model
//Language = game.Language, // TODO: Add to internal model
//Im1CRC = game.Im1CRC, // TODO: Add to internal model
//Im2CRC = game.Im2CRC, // TODO: Add to internal model
Comment = game.Comment,
};
// Get all games items long? size = Utilities.CleanLong(game.RomSize);
switch (reader.Name.ToLowerInvariant()) if (game.DuplicateID != "0")
{ machine.CloneOf = game.DuplicateID;
case "imagenumber":
// TODO: Read this into a field
reader.ReadElementContentAsString();
break;
case "releasenumber": // Check if there are any items
// TODO: Read this into a field bool containsItems = false;
releaseNumber = reader.ReadElementContentAsString();
break;
case "title": // Loop through each file
machine.Name = reader.ReadElementContentAsString(); ConvertFiles(game.Files, machine, size, game.ReleaseNumber, filename, indexId, statsOnly, ref containsItems);
break;
case "savetype": // If we had no items, create a Blank placeholder
// TODO: Read this into a field if (!containsItems)
reader.ReadElementContentAsString();
break;
case "romsize":
size = Utilities.CleanLong(reader.ReadElementContentAsString());
break;
case "publisher":
machine.Publisher = reader.ReadElementContentAsString();
break;
case "location":
// TODO: Read this into a field
reader.ReadElementContentAsString();
break;
case "sourcerom":
// TODO: Read this into a field
reader.ReadElementContentAsString();
break;
case "language":
// TODO: Read this into a field
reader.ReadElementContentAsString();
break;
case "files":
datItems = ReadFiles(reader.ReadSubtree(), releaseNumber, machine.Name, filename, indexId);
// Skip the files node now that we've processed it
reader.Skip();
break;
case "im1crc":
// TODO: Read this into a field
reader.ReadElementContentAsString();
break;
case "im2crc":
// TODO: Read this into a field
reader.ReadElementContentAsString();
break;
case "comment":
machine.Comment = reader.ReadElementContentAsString();
break;
case "duplicateid":
duplicateid = reader.ReadElementContentAsString();
if (duplicateid != "0")
machine.CloneOf = duplicateid;
break;
default:
reader.Read();
break;
}
}
// Add information accordingly for each rom
for (int i = 0; i < datItems.Count; i++)
{ {
datItems[i].Size = size; var blank = new Blank
datItems[i].CopyMachineInformation(machine); {
Source = new Source
{
Index = indexId,
Name = filename,
},
};
// Now process and add the rom blank.CopyMachineInformation(machine);
ParseAddHelper(datItems[i], statsOnly); ParseAddHelper(blank, statsOnly);
} }
} }
/// <summary> /// <summary>
/// Read files information /// Convert Files information
/// </summary> /// </summary>
/// <param name="reader">XmlReader to use to parse the header</param> /// <param name="files">Array of deserialized models to convert</param>
/// <param name="releaseNumber">Release number from the parent game</param> /// <param name="machine">Prefilled machine to use</param>
/// <param name="machineName">Name of the parent game to use</param> /// <param name="size">Item size to use</param>
/// <param name="releaseNumber">Release number to use</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 List<Rom> ReadFiles( /// <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>
string releaseNumber, private void ConvertFiles(Models.OfflineList.Files? files, Machine machine, long? size, string releaseNumber, string filename, int indexId, bool statsOnly, ref bool containsItems)
string machineName,
// Standard Dat parsing
string filename,
int indexId)
{ {
// Prepare all internal variables // If the files array is missing, we can't do anything
var extensionToCrc = new List<KeyValuePair<string, string>>(); if (files?.RomCRC == null || !files.RomCRC.Any())
var roms = new List<Rom>(); return;
// If there's no subtree to the configuration, skip it containsItems = true;
if (reader == null) foreach (var crc in files.RomCRC)
return roms;
// Otherwise, add what is possible
reader.MoveToContent();
// Otherwise, read what we can from the header
while (!reader.EOF)
{ {
// We only want elements string name = string.Empty;
if (reader.NodeType != XmlNodeType.Element) if (!string.IsNullOrWhiteSpace(releaseNumber) && releaseNumber != "0")
name += $"{releaseNumber} - ";
name += $"{machine.Name}{crc.Extension}";
var item = new Rom
{ {
reader.Read(); Name = name,
continue; CRC = crc.Content,
}
// Get all romCRC items
switch (reader.Name.ToLowerInvariant())
{
case "romcrc":
extensionToCrc.Add(
new KeyValuePair<string, string>(
reader.GetAttribute("extension") ?? string.Empty,
reader.ReadElementContentAsString().ToLowerInvariant()));
break;
default:
reader.Read();
break;
}
}
// Now process the roms with the proper information
foreach (KeyValuePair<string, string> pair in extensionToCrc)
{
roms.Add(new Rom()
{
Name = (releaseNumber != "0" ? releaseNumber + " - " : string.Empty) + machineName + pair.Key,
CRC = pair.Value,
ItemStatus = ItemStatus.None, ItemStatus = ItemStatus.None,
Source = new Source Source = new Source
@@ -637,10 +379,27 @@ namespace SabreTools.DatFiles.Formats
Index = indexId, Index = indexId,
Name = filename, Name = filename,
}, },
}); };
}
return roms; item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
}
} }
/// <summary>
/// Convert GUI information
/// </summary>
/// <param name="gui">Deserialized model to convert</param>
private void ConvertGUI(Models.OfflineList.GUI? gui)
{
// If the gui or Images are missing, we can't do anything
if (gui?.Images?.Image == null || !gui.Images.Image.Any())
return;
// TODO: Add to internal model
}
#endregion
} }
} }

View File

@@ -27,8 +27,24 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/> /// <inheritdoc/>
protected override List<DatItemField> GetMissingRequiredFields(DatItem datItem) protected override List<DatItemField> GetMissingRequiredFields(DatItem datItem)
{ {
// TODO: Check required fields var missingFields = new List<DatItemField>();
return null;
if (string.IsNullOrWhiteSpace(datItem.GetName()))
missingFields.Add(DatItemField.Name);
switch (datItem)
{
case Rom rom:
if (rom.Size == null || rom.Size < 0)
missingFields.Add(DatItemField.Size);
if (string.IsNullOrWhiteSpace(rom.CRC))
{
missingFields.Add(DatItemField.SHA1);
}
break;
}
return missingFields;
} }
/// <inheritdoc/> /// <inheritdoc/>

View File

@@ -38,16 +38,16 @@ namespace SabreTools.DatFiles.Formats
/// <summary> /// <summary>
/// Convert header information /// Convert header information
/// </summary> /// </summary>
/// <param name="datafile">Deserialized model to convert</param> /// <param name="softwaredb">Deserialized model to convert</param>
private void ConvertHeader(Models.OpenMSX.SoftwareDb? datafile) private void ConvertHeader(Models.OpenMSX.SoftwareDb? softwaredb)
{ {
// If the datafile is missing, we can't do anything // If the datafile is missing, we can't do anything
if (datafile == null) if (softwaredb == null)
return; return;
Header.Name ??= "openMSX Software List"; Header.Name ??= "openMSX Software List";
Header.Description ??= Header.Name; Header.Description ??= Header.Name;
Header.Date ??= datafile.Timestamp; Header.Date ??= softwaredb.Timestamp;
} }
/// <summary> /// <summary>

View File

@@ -18,8 +18,9 @@ namespace SabreTools.Models.OfflineList
[XmlElement("saveType")] [XmlElement("saveType")]
public string? SaveType { get; set; } public string? SaveType { get; set; }
/// <remarks>Numeric</remarks>
[XmlElement("romSize")] [XmlElement("romSize")]
public long? RomSize { get; set; } public string? RomSize { get; set; }
[XmlElement("publisher")] [XmlElement("publisher")]
public string? Publisher { get; set; } public string? Publisher { get; set; }