2023-08-01 00:07:36 -04:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2024-03-05 15:24:11 -05:00
|
|
|
using SabreTools.Core;
|
2023-08-01 00:07:36 -04:00
|
|
|
using SabreTools.Core.Tools;
|
|
|
|
|
using SabreTools.DatItems;
|
|
|
|
|
using SabreTools.DatItems.Formats;
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.DatFiles.Formats
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents parsing a SoftwareList
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal partial class SoftwareList : DatFile
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
// Deserialize the input file
|
2023-09-11 01:20:21 -04:00
|
|
|
var softwarelist = new Serialization.Files.SoftwareList().Deserialize(filename);
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
// Convert the header to the internal format
|
|
|
|
|
ConvertHeader(softwarelist, keep);
|
|
|
|
|
|
|
|
|
|
// Convert the software data to the internal format
|
|
|
|
|
ConvertSoftware(softwarelist?.Software, filename, indexId, statsOnly);
|
2023-08-01 00:07:36 -04:00
|
|
|
}
|
|
|
|
|
catch (Exception ex) when (!throwOnError)
|
|
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
string message = $"'{filename}' - An error occurred during parsing";
|
|
|
|
|
logger.Error(ex, message);
|
2023-08-01 00:07:36 -04:00
|
|
|
}
|
2023-08-01 01:04:21 -04:00
|
|
|
}
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
#region Converters
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert header information
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="softwarelist">Deserialized model to convert</param>
|
|
|
|
|
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
|
|
|
|
private void ConvertHeader(Models.SoftwareList.SoftwareList? softwarelist, bool keep)
|
|
|
|
|
{
|
|
|
|
|
// If the datafile is missing, we can't do anything
|
|
|
|
|
if (softwarelist == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-03-10 04:10:37 -04:00
|
|
|
if (Header.GetFieldValue<string?>(Models.Metadata.Header.NameKey) == null)
|
|
|
|
|
Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, softwarelist.Name);
|
|
|
|
|
if (Header.GetFieldValue<string?>(Models.Metadata.Header.DescriptionKey) == null)
|
|
|
|
|
Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, softwarelist.Description);
|
|
|
|
|
if (Header.GetFieldValue<string?>(Models.Metadata.Header.CommentKey) == null)
|
|
|
|
|
Header.SetFieldValue<string?>(Models.Metadata.Header.CommentKey, softwarelist.Notes);
|
2023-08-01 01:04:21 -04:00
|
|
|
|
|
|
|
|
// Handle implied SuperDAT
|
2024-03-10 04:10:37 -04:00
|
|
|
if (Header.GetFieldValue<string?>(Models.Metadata.Header.NameKey)?.Contains(" - SuperDAT") == true && keep)
|
|
|
|
|
{
|
|
|
|
|
if (Header.GetFieldValue<string?>(Models.Metadata.Header.TypeKey) == null)
|
|
|
|
|
Header.SetFieldValue<string?>(Models.Metadata.Header.TypeKey, "SuperDAT");
|
|
|
|
|
}
|
2023-08-01 00:07:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-08-01 01:04:21 -04:00
|
|
|
/// Convert software information
|
2023-08-01 00:07:36 -04:00
|
|
|
/// </summary>
|
2023-08-01 01:04:21 -04:00
|
|
|
/// <param name="software">Array of deserialized models to convert</param>
|
2023-08-01 00:07:36 -04:00
|
|
|
/// <param name="filename">Name of the file to be parsed</param>
|
|
|
|
|
/// <param name="indexId">Index ID for the DAT</param>
|
2023-08-01 01:04:21 -04:00
|
|
|
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
|
|
|
|
|
private void ConvertSoftware(Models.SoftwareList.Software[]? software, string filename, int indexId, bool statsOnly)
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
// If the game array is missing, we can't do anything
|
|
|
|
|
if (software == null || !software.Any())
|
2023-08-01 00:07:36 -04:00
|
|
|
return;
|
|
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
// Loop through the software and add
|
|
|
|
|
foreach (var sw in software)
|
|
|
|
|
{
|
|
|
|
|
ConvertSoftware(sw, filename, indexId, statsOnly);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
/// <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.SoftwareList.Software software, string filename, int indexId, bool statsOnly)
|
|
|
|
|
{
|
|
|
|
|
// If the game is missing, we can't do anything
|
|
|
|
|
if (software == null)
|
|
|
|
|
return;
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
// Create the machine for copying information
|
2024-03-09 23:43:43 -05:00
|
|
|
var machine = new Machine();
|
|
|
|
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.CloneOfKey, software.CloneOf);
|
|
|
|
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.CommentKey, software.Notes);
|
|
|
|
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, software.Description);
|
|
|
|
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, software.Name);
|
|
|
|
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.PublisherKey, software.Publisher);
|
|
|
|
|
machine.SetFieldValue<Supported>(Models.Metadata.Machine.SupportedKey, software.Supported.AsEnumValue<Supported>());
|
|
|
|
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.YearKey, software.Year);
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
// Add all Info objects
|
2024-02-28 19:19:50 -05:00
|
|
|
foreach (var info in software.Info ?? [])
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2024-03-10 16:49:07 -04:00
|
|
|
var infoItem = new Info();
|
2024-03-08 20:42:24 -05:00
|
|
|
infoItem.SetName(info.Name);
|
2024-03-10 16:49:07 -04:00
|
|
|
infoItem.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
2024-03-09 21:34:26 -05:00
|
|
|
infoItem.SetFieldValue<string?>(Models.Metadata.Info.ValueKey, info.Value);
|
2023-08-01 01:04:21 -04:00
|
|
|
|
|
|
|
|
infoItem.CopyMachineInformation(machine);
|
|
|
|
|
ParseAddHelper(infoItem, statsOnly);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add all SharedFeat objects
|
2024-02-28 19:19:50 -05:00
|
|
|
foreach (var sharedfeat in software.SharedFeat ?? [])
|
2023-08-01 01:04:21 -04:00
|
|
|
{
|
2024-03-10 20:39:54 -04:00
|
|
|
var sharedfeatItem = new SharedFeat();
|
2024-03-08 20:42:24 -05:00
|
|
|
sharedfeatItem.SetName(sharedfeat.Name);
|
2024-03-10 16:49:07 -04:00
|
|
|
sharedfeatItem.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
2024-03-09 21:34:26 -05:00
|
|
|
sharedfeatItem.SetFieldValue<string?>(Models.Metadata.SharedFeat.ValueKey, sharedfeat.Value);
|
2023-08-01 01:04:21 -04:00
|
|
|
|
|
|
|
|
sharedfeatItem.CopyMachineInformation(machine);
|
|
|
|
|
ParseAddHelper(sharedfeatItem, statsOnly);
|
2023-08-01 00:07:36 -04:00
|
|
|
}
|
|
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
// Check if there are any items
|
|
|
|
|
bool containsItems = false;
|
|
|
|
|
|
|
|
|
|
// Loop through each type of item
|
|
|
|
|
ConvertPart(software.Part, machine, filename, indexId, statsOnly, ref containsItems);
|
|
|
|
|
|
|
|
|
|
// If we had no items, create a Blank placeholder
|
2023-08-01 00:07:36 -04:00
|
|
|
if (!containsItems)
|
|
|
|
|
{
|
2024-03-10 16:49:07 -04:00
|
|
|
var blank = new Blank();
|
|
|
|
|
blank.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
2023-08-01 00:07:36 -04:00
|
|
|
|
|
|
|
|
blank.CopyMachineInformation(machine);
|
|
|
|
|
ParseAddHelper(blank, statsOnly);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-08-01 01:04:21 -04:00
|
|
|
/// Convert Part information
|
2023-08-01 00:07:36 -04:00
|
|
|
/// </summary>
|
2023-08-01 01:04:21 -04:00
|
|
|
/// <param name="parts">Array of deserialized models to convert</param>
|
|
|
|
|
/// <param name="machine">Prefilled machine to use</param>
|
2023-08-01 00:07:36 -04:00
|
|
|
/// <param name="filename">Name of the file to be parsed</param>
|
|
|
|
|
/// <param name="indexId">Index ID for the DAT</param>
|
2023-08-01 01:04:21 -04:00
|
|
|
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
|
|
|
|
|
/// <param name="containsItems">True if there were any items in the array, false otherwise</param>
|
|
|
|
|
private void ConvertPart(Models.SoftwareList.Part[]? parts, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
// If the parts array is missing, we can't do anything
|
|
|
|
|
if (parts == null || !parts.Any())
|
|
|
|
|
return;
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
foreach (var part in parts)
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2024-03-10 16:49:07 -04:00
|
|
|
var item = new Part();
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(part.Name);
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<string?>(Models.Metadata.Part.InterfaceKey, part.Interface);
|
|
|
|
|
item.SetFieldValue<PartFeature[]?>(Models.Metadata.Part.FeatureKey, CreateFeatures(part.Feature, machine, filename, indexId, statsOnly));
|
2024-03-10 16:49:07 -04:00
|
|
|
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
2023-08-01 01:04:21 -04:00
|
|
|
|
|
|
|
|
item.CopyMachineInformation(machine);
|
|
|
|
|
|
|
|
|
|
ConvertDataArea(part.DataArea, item, machine, filename, indexId, statsOnly, ref containsItems);
|
|
|
|
|
ConvertDiskArea(part.DiskArea, item, machine, filename, indexId, statsOnly, ref containsItems);
|
|
|
|
|
ConvertDipSwitch(part.DipSwitch, item, machine, filename, indexId, statsOnly, ref containsItems);
|
2023-08-01 00:07:36 -04:00
|
|
|
}
|
2023-08-01 01:04:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert Feature information
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="features">Array of deserialized models to convert</param>
|
|
|
|
|
/// <param name="machine">Prefilled machine to use</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>
|
2024-03-09 21:34:26 -05:00
|
|
|
private static PartFeature[]? CreateFeatures(Models.SoftwareList.Feature[]? features, Machine machine, string filename, int indexId, bool statsOnly)
|
2023-08-01 01:04:21 -04:00
|
|
|
{
|
|
|
|
|
// If the feature array is missing, we can't do anything
|
|
|
|
|
if (features == null || !features.Any())
|
|
|
|
|
return null;
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
var partFeatures = new List<PartFeature>();
|
|
|
|
|
foreach (var feature in features)
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2024-03-10 16:49:07 -04:00
|
|
|
var item = new PartFeature();
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(feature.Name);
|
2024-03-10 16:49:07 -04:00
|
|
|
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<string?>(Models.Metadata.Feature.ValueKey, feature.Value);
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
item.CopyMachineInformation(machine);
|
|
|
|
|
partFeatures.Add(item);
|
2023-08-01 00:07:36 -04:00
|
|
|
}
|
|
|
|
|
|
2024-03-09 21:34:26 -05:00
|
|
|
return [.. partFeatures];
|
2023-08-01 00:07:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-08-01 01:04:21 -04:00
|
|
|
/// Convert DataArea information
|
2023-08-01 00:07:36 -04:00
|
|
|
/// </summary>
|
2023-08-01 01:04:21 -04:00
|
|
|
/// <param name="dataareas">Array of deserialized models to convert</param>
|
|
|
|
|
/// <param name="part">Parent Part to use</param>
|
|
|
|
|
/// <param name="machine">Prefilled machine to use</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="containsItems">True if there were any items in the array, false otherwise</param>
|
|
|
|
|
private void ConvertDataArea(Models.SoftwareList.DataArea[]? dataareas, Part part, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
// If the dataarea array is missing, we can't do anything
|
|
|
|
|
if (dataareas == null || !dataareas.Any())
|
|
|
|
|
return;
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
foreach (var dataarea in dataareas)
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2024-03-10 16:49:07 -04:00
|
|
|
var item = new DataArea();
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(dataarea.Name);
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<Endianness?>(Models.Metadata.DataArea.EndiannessKey, dataarea.Endianness.AsEnumValue<Endianness>());
|
|
|
|
|
item.SetFieldValue<long?>(Models.Metadata.DataArea.SizeKey, NumberHelper.ConvertToInt64(dataarea.Size));
|
2024-03-10 16:49:07 -04:00
|
|
|
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<long?>(Models.Metadata.DataArea.WidthKey, NumberHelper.ConvertToInt64(dataarea.Width));
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
item.CopyMachineInformation(machine);
|
|
|
|
|
ConvertRoms(dataarea.Rom, part, item, machine, filename, indexId, statsOnly, ref containsItems);
|
|
|
|
|
}
|
2023-08-01 00:07:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-08-01 01:04:21 -04:00
|
|
|
/// Convert Rom information
|
2023-08-01 00:07:36 -04:00
|
|
|
/// </summary>
|
2023-08-01 01:04:21 -04:00
|
|
|
/// <param name="roms">Array of deserialized models to convert</param>
|
|
|
|
|
/// <param name="part">Parent Part to use</param>
|
|
|
|
|
/// <param name="dataarea">Parent DataArea to use</param>
|
|
|
|
|
/// <param name="machine">Prefilled machine to use</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="containsItems">True if there were any items in the array, false otherwise</param>
|
|
|
|
|
private void ConvertRoms(Models.SoftwareList.Rom[]? roms, Part part, DataArea dataarea, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
// If the rom array is missing, we can't do anything
|
|
|
|
|
if (roms == null || !roms.Any())
|
|
|
|
|
return;
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
containsItems = true;
|
|
|
|
|
foreach (var rom in roms)
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2024-03-10 16:49:07 -04:00
|
|
|
var item = new Rom();
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(rom.Name);
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, rom.CRC);
|
2024-03-10 16:49:07 -04:00
|
|
|
item.SetFieldValue<DataArea?>(Rom.DataAreaKey, dataarea);
|
|
|
|
|
item.SetFieldValue<LoadFlag>(Models.Metadata.Rom.LoadFlagKey, rom.LoadFlag.AsEnumValue<LoadFlag>());
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<string?>(Models.Metadata.Rom.OffsetKey, rom.Offset);
|
2024-03-10 16:49:07 -04:00
|
|
|
item.SetFieldValue<Part?>(Rom.PartKey, part);
|
|
|
|
|
item.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key, rom.SHA1);
|
|
|
|
|
item.SetFieldValue<long?>(Models.Metadata.Rom.SizeKey, NumberHelper.ConvertToInt64(rom.Size ?? rom.Length));
|
|
|
|
|
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<ItemStatus>(Models.Metadata.Rom.StatusKey, rom.Status.AsEnumValue<ItemStatus>());
|
2024-03-10 16:49:07 -04:00
|
|
|
item.SetFieldValue<string?>(Models.Metadata.Rom.ValueKey, rom.Value);
|
2023-08-01 01:04:21 -04:00
|
|
|
|
|
|
|
|
item.CopyMachineInformation(machine);
|
|
|
|
|
ParseAddHelper(item, statsOnly);
|
2023-08-01 00:07:36 -04:00
|
|
|
}
|
2023-08-01 01:04:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert DiskArea information
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="diskareas">Array of deserialized models to convert</param>
|
|
|
|
|
/// <param name="part">Parent Part to use</param>
|
|
|
|
|
/// <param name="machine">Prefilled machine to use</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="containsItems">True if there were any items in the array, false otherwise</param>
|
|
|
|
|
private void ConvertDiskArea(Models.SoftwareList.DiskArea[]? diskareas, Part part, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
|
|
|
{
|
|
|
|
|
// If the diskarea array is missing, we can't do anything
|
|
|
|
|
if (diskareas == null || !diskareas.Any())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (var diskarea in diskareas)
|
|
|
|
|
{
|
2024-03-10 16:49:07 -04:00
|
|
|
var item = new DiskArea();
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(diskarea.Name);
|
2024-03-10 16:49:07 -04:00
|
|
|
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
2023-08-01 01:04:21 -04:00
|
|
|
|
|
|
|
|
item.CopyMachineInformation(machine);
|
|
|
|
|
ConvertDisks(diskarea.Disk, part, item, machine, filename, indexId, statsOnly, ref containsItems);
|
|
|
|
|
}
|
2023-08-01 00:07:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-08-01 01:04:21 -04:00
|
|
|
/// Convert Disk information
|
2023-08-01 00:07:36 -04:00
|
|
|
/// </summary>
|
2023-08-01 01:04:21 -04:00
|
|
|
/// <param name="disks">Array of deserialized models to convert</param>
|
|
|
|
|
/// <param name="part">Parent Part to use</param>
|
|
|
|
|
/// <param name="diskarea">Parent DiskArea to use</param>
|
|
|
|
|
/// <param name="machine">Prefilled machine to use</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="containsItems">True if there were any items in the array, false otherwise</param>
|
|
|
|
|
private void ConvertDisks(Models.SoftwareList.Disk[]? disks, Part part, DiskArea diskarea, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
// If the rom array is missing, we can't do anything
|
|
|
|
|
if (disks == null || !disks.Any())
|
2023-08-01 00:07:36 -04:00
|
|
|
return;
|
|
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
containsItems = true;
|
2024-03-08 20:42:24 -05:00
|
|
|
foreach (var disk in disks)
|
2023-08-01 01:04:21 -04:00
|
|
|
{
|
2024-03-10 16:49:07 -04:00
|
|
|
var item = new Disk();
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(disk.Name);
|
2024-03-10 16:49:07 -04:00
|
|
|
item.SetFieldValue<DiskArea?>(Disk.DiskAreaKey, diskarea);
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<ItemStatus>(Models.Metadata.Disk.StatusKey, disk.Status?.AsEnumValue<ItemStatus>() ?? ItemStatus.NULL);
|
|
|
|
|
item.SetFieldValue<string?>(Models.Metadata.Disk.MD5Key, disk.MD5);
|
2024-03-10 16:49:07 -04:00
|
|
|
item.SetFieldValue<Part?>(Disk.PartKey, part);
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<string?>(Models.Metadata.Disk.SHA1Key, disk.SHA1);
|
2024-03-10 16:49:07 -04:00
|
|
|
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<bool?>(Models.Metadata.Disk.WritableKey, disk.Writeable.AsYesNo());
|
2023-08-01 01:04:21 -04:00
|
|
|
|
|
|
|
|
item.CopyMachineInformation(machine);
|
|
|
|
|
ParseAddHelper(item, statsOnly);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert DipSwitch information
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dipswitches">Array of deserialized models to convert</param>
|
|
|
|
|
/// <param name="part">Parent Part to use</param>
|
|
|
|
|
/// <param name="machine">Prefilled machine to use</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="containsItems">True if there were any items in the array, false otherwise</param>
|
|
|
|
|
private void ConvertDipSwitch(Models.SoftwareList.DipSwitch[]? dipswitches, Part part, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
|
|
|
{
|
|
|
|
|
// If the dipswitch array is missing, we can't do anything
|
|
|
|
|
if (dipswitches == null || !dipswitches.Any())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (var dipswitch in dipswitches)
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2024-03-10 16:49:07 -04:00
|
|
|
var item = new DipSwitch();
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(dipswitch.Name);
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey, CreateDipValues(dipswitch.DipValue, machine, filename, indexId)?.ToArray());
|
2024-03-10 16:49:07 -04:00
|
|
|
item.SetFieldValue<Part?>(DipSwitch.PartKey, part);
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<string?>(Models.Metadata.DipSwitch.MaskKey, dipswitch.Mask);
|
2024-03-10 16:49:07 -04:00
|
|
|
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<string?>(Models.Metadata.DipSwitch.TagKey, dipswitch.Tag);
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
item.CopyMachineInformation(machine);
|
|
|
|
|
ParseAddHelper(item, statsOnly);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert DipValue information
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dipvalues">Array of deserialized models to convert</param>
|
|
|
|
|
/// <param name="machine">Prefilled machine to use</param>
|
|
|
|
|
/// <param name="filename">Name of the file to be parsed</param>
|
|
|
|
|
/// <param name="indexId">Index ID for the DAT</param>
|
2023-08-14 13:17:51 -04:00
|
|
|
private static List<DipValue>? CreateDipValues(Models.SoftwareList.DipValue[]? dipvalues, Machine machine, string filename, int indexId)
|
2023-08-01 01:04:21 -04:00
|
|
|
{
|
|
|
|
|
// If the feature array is missing, we can't do anything
|
|
|
|
|
if (dipvalues == null || !dipvalues.Any())
|
|
|
|
|
return null;
|
|
|
|
|
|
2023-08-14 13:17:51 -04:00
|
|
|
var settings = new List<DipValue>();
|
2023-08-01 01:04:21 -04:00
|
|
|
foreach (var dipvalue in dipvalues)
|
|
|
|
|
{
|
2024-03-10 16:49:07 -04:00
|
|
|
var item = new DipValue();
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(dipvalue.Name);
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<bool?>(Models.Metadata.DipValue.DefaultKey, dipvalue.Default.AsYesNo());
|
2024-03-10 16:49:07 -04:00
|
|
|
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
2024-03-09 21:34:26 -05:00
|
|
|
item.SetFieldValue<string?>(Models.Metadata.DipValue.ValueKey, dipvalue.Value);
|
2023-08-01 01:04:21 -04:00
|
|
|
|
|
|
|
|
item.CopyMachineInformation(machine);
|
|
|
|
|
settings.Add(item);
|
2023-08-01 00:07:36 -04:00
|
|
|
}
|
2023-08-01 01:04:21 -04:00
|
|
|
|
|
|
|
|
return settings;
|
2023-08-01 00:07:36 -04:00
|
|
|
}
|
2023-08-01 01:04:21 -04:00
|
|
|
|
|
|
|
|
#endregion
|
2023-08-01 00:07:36 -04:00
|
|
|
}
|
|
|
|
|
}
|