mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Finish implementing software list internal conversion
This commit is contained in:
@@ -5,7 +5,6 @@ using SabreTools.Core.Tools;
|
|||||||
|
|
||||||
namespace SabreTools.DatFiles
|
namespace SabreTools.DatFiles
|
||||||
{
|
{
|
||||||
// TODO: Convert nested items (e.g. Configuration, DipLocation)
|
|
||||||
public partial class DatFile
|
public partial class DatFile
|
||||||
{
|
{
|
||||||
#region Converters
|
#region Converters
|
||||||
@@ -646,32 +645,6 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert DataArea information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="items">Array of internal items to convert</param>
|
|
||||||
/// <param name="machine">Machine to use with the converted items</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 ProcessItems(Models.Metadata.DataArea[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly)
|
|
||||||
{
|
|
||||||
// If the array is null or empty, return without processing
|
|
||||||
if (items == null || items.Length == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// TODO: Extract Roms
|
|
||||||
|
|
||||||
// Loop through the items and add
|
|
||||||
foreach (var item in items)
|
|
||||||
{
|
|
||||||
var datItem = new DatItems.Formats.DataArea(item);
|
|
||||||
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
|
||||||
datItem.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(datItem, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert Device information
|
/// Convert Device information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -742,30 +715,6 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert DipLocation information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="items">Array of internal items to convert</param>
|
|
||||||
/// <param name="machine">Machine to use with the converted items</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 ProcessItems(Models.Metadata.DipLocation[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly)
|
|
||||||
{
|
|
||||||
// If the array is null or empty, return without processing
|
|
||||||
if (items == null || items.Length == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Loop through the items and add
|
|
||||||
foreach (var item in items)
|
|
||||||
{
|
|
||||||
var datItem = new DatItems.Formats.DipLocation(item);
|
|
||||||
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
|
||||||
datItem.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(datItem, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert DipSwitch information
|
/// Convert DipSwitch information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -833,30 +782,6 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert DipValue information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="items">Array of internal items to convert</param>
|
|
||||||
/// <param name="machine">Machine to use with the converted items</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 ProcessItems(Models.Metadata.DipValue[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly)
|
|
||||||
{
|
|
||||||
// If the array is null or empty, return without processing
|
|
||||||
if (items == null || items.Length == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Loop through the items and add
|
|
||||||
foreach (var item in items)
|
|
||||||
{
|
|
||||||
var datItem = new DatItems.Formats.DipValue(item);
|
|
||||||
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
|
||||||
datItem.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(datItem, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert Disk information
|
/// Convert Disk information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -881,32 +806,6 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert DiskArea information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="items">Array of internal items to convert</param>
|
|
||||||
/// <param name="machine">Machine to use with the converted items</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 ProcessItems(Models.Metadata.DiskArea[]? items, DatItems.Machine machine, string filename, int indexId, bool statsOnly)
|
|
||||||
{
|
|
||||||
// If the array is null or empty, return without processing
|
|
||||||
if (items == null || items.Length == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// TODO: Extract Disks
|
|
||||||
|
|
||||||
// Loop through the items and add
|
|
||||||
foreach (var item in items)
|
|
||||||
{
|
|
||||||
var datItem = new DatItems.Formats.DiskArea(item);
|
|
||||||
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
|
||||||
datItem.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(datItem, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert Display information
|
/// Convert Display information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1147,17 +1046,81 @@ namespace SabreTools.DatFiles
|
|||||||
if (items == null || items.Length == 0)
|
if (items == null || items.Length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: Extract DataAreas
|
|
||||||
// TODO: Extract DiskAreas
|
|
||||||
// TODO: Extract DipSwitches
|
|
||||||
|
|
||||||
// Loop through the items and add
|
// Loop through the items and add
|
||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
var datItem = new DatItems.Formats.Part(item);
|
var partItem = new DatItems.Formats.Part(item);
|
||||||
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
|
||||||
datItem.CopyMachineInformation(machine);
|
// Handle subitems
|
||||||
ParseAddHelper(datItem, statsOnly);
|
var dataAreas = ReadItemArray<Models.Metadata.DataArea>(item, Models.Metadata.Part.DataAreaKey);
|
||||||
|
if (dataAreas != null)
|
||||||
|
{
|
||||||
|
foreach (var dataArea in dataAreas)
|
||||||
|
{
|
||||||
|
var dataAreaItem = new DatItems.Formats.DataArea(dataArea);
|
||||||
|
var roms = ReadItemArray<Models.Metadata.Rom>(dataArea, Models.Metadata.DataArea.RomKey);
|
||||||
|
if (roms == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var rom in roms)
|
||||||
|
{
|
||||||
|
var romItem = new DatItems.Formats.Rom(rom);
|
||||||
|
romItem.SetFieldValue<DatItems.Formats.DataArea?>(DatItems.Formats.Rom.DataAreaKey, dataAreaItem);
|
||||||
|
romItem.SetFieldValue<DatItems.Formats.Part?>(DatItems.Formats.Rom.PartKey, partItem);
|
||||||
|
romItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
||||||
|
romItem.CopyMachineInformation(machine);
|
||||||
|
ParseAddHelper(romItem, statsOnly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var diskAreas = ReadItemArray<Models.Metadata.DiskArea>(item, Models.Metadata.Part.DiskAreaKey);
|
||||||
|
if (diskAreas != null)
|
||||||
|
{
|
||||||
|
foreach (var diskArea in diskAreas)
|
||||||
|
{
|
||||||
|
var diskAreaitem = new DatItems.Formats.DiskArea(diskArea);
|
||||||
|
var disks = ReadItemArray<Models.Metadata.Disk>(diskArea, Models.Metadata.DiskArea.DiskKey);
|
||||||
|
if (disks == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var disk in disks)
|
||||||
|
{
|
||||||
|
var diskItem = new DatItems.Formats.Disk(disk);
|
||||||
|
diskItem.SetFieldValue<DatItems.Formats.DiskArea?>(DatItems.Formats.Disk.DiskAreaKey, diskAreaitem);
|
||||||
|
diskItem.SetFieldValue<DatItems.Formats.Part?>(DatItems.Formats.Disk.PartKey, partItem);
|
||||||
|
diskItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
||||||
|
diskItem.CopyMachineInformation(machine);
|
||||||
|
ParseAddHelper(diskItem, statsOnly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var dipSwitches = ReadItemArray<Models.Metadata.DipSwitch>(item, Models.Metadata.Part.DipSwitchKey);
|
||||||
|
if (dipSwitches != null)
|
||||||
|
{
|
||||||
|
foreach (var dipSwitch in dipSwitches)
|
||||||
|
{
|
||||||
|
var dipSwitchItem = new DatItems.Formats.DipSwitch(dipSwitch);
|
||||||
|
dipSwitchItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
||||||
|
dipSwitchItem.CopyMachineInformation(machine);
|
||||||
|
|
||||||
|
var dipValues = ReadItemArray<Models.Metadata.DipValue>(dipSwitch, Models.Metadata.DipSwitch.DipValueKey);
|
||||||
|
if (dipValues != null)
|
||||||
|
{
|
||||||
|
var subValues = new List<DatItems.Formats.DipValue>();
|
||||||
|
foreach (var value in dipValues)
|
||||||
|
{
|
||||||
|
var subItem = new DatItems.Formats.DipValue(value);
|
||||||
|
subValues.Add(subItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
dipSwitchItem.SetFieldValue<DatItems.Formats.DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey, [.. subValues]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ParseAddHelper(dipSwitchItem, statsOnly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using SabreTools.Core;
|
|
||||||
using SabreTools.Core.Tools;
|
|
||||||
using SabreTools.DatItems;
|
|
||||||
using SabreTools.DatItems.Formats;
|
|
||||||
|
|
||||||
namespace SabreTools.DatFiles.Formats
|
namespace SabreTools.DatFiles.Formats
|
||||||
{
|
{
|
||||||
@@ -20,12 +14,10 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
{
|
{
|
||||||
// Deserialize the input file
|
// Deserialize the input file
|
||||||
var softwarelist = new Serialization.Files.SoftwareList().Deserialize(filename);
|
var softwarelist = new Serialization.Files.SoftwareList().Deserialize(filename);
|
||||||
|
var metadata = new Serialization.CrossModel.SoftwareList().Serialize(softwarelist);
|
||||||
|
|
||||||
// Convert the header to the internal format
|
// Convert to the internal format
|
||||||
ConvertHeader(softwarelist, keep);
|
ConvertMetadata(metadata, filename, indexId, keep, statsOnly);
|
||||||
|
|
||||||
// Convert the software data to the internal format
|
|
||||||
ConvertSoftware(softwarelist?.Software, filename, indexId, statsOnly);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex) when (!throwOnError)
|
catch (Exception ex) when (!throwOnError)
|
||||||
{
|
{
|
||||||
@@ -33,369 +25,5 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
logger.Error(ex, message);
|
logger.Error(ex, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#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;
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Handle implied SuperDAT
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert software information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="software">Array of deserialized models 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 array is missing, we can't do anything
|
|
||||||
if (software == null || !software.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Loop through the software and add
|
|
||||||
foreach (var sw in software)
|
|
||||||
{
|
|
||||||
ConvertSoftware(sw, filename, indexId, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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;
|
|
||||||
|
|
||||||
// Create the machine for copying information
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Add all Info objects
|
|
||||||
foreach (var info in software.Info ?? [])
|
|
||||||
{
|
|
||||||
var infoItem = new Info();
|
|
||||||
infoItem.SetName(info.Name);
|
|
||||||
infoItem.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
infoItem.SetFieldValue<string?>(Models.Metadata.Info.ValueKey, info.Value);
|
|
||||||
|
|
||||||
infoItem.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(infoItem, statsOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add all SharedFeat objects
|
|
||||||
foreach (var sharedfeat in software.SharedFeat ?? [])
|
|
||||||
{
|
|
||||||
var sharedfeatItem = new SharedFeat();
|
|
||||||
sharedfeatItem.SetName(sharedfeat.Name);
|
|
||||||
sharedfeatItem.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
sharedfeatItem.SetFieldValue<string?>(Models.Metadata.SharedFeat.ValueKey, sharedfeat.Value);
|
|
||||||
|
|
||||||
sharedfeatItem.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(sharedfeatItem, statsOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
|
||||||
if (!containsItems)
|
|
||||||
{
|
|
||||||
var blank = new Blank();
|
|
||||||
blank.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
|
|
||||||
blank.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(blank, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Part information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="parts">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>
|
|
||||||
/// <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)
|
|
||||||
{
|
|
||||||
// If the parts array is missing, we can't do anything
|
|
||||||
if (parts == null || !parts.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (var part in parts)
|
|
||||||
{
|
|
||||||
var item = new Part();
|
|
||||||
item.SetName(part.Name);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Part.InterfaceKey, part.Interface);
|
|
||||||
item.SetFieldValue<PartFeature[]?>(Models.Metadata.Part.FeatureKey, CreateFeatures(part.Feature, machine, filename, indexId, statsOnly));
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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>
|
|
||||||
private static PartFeature[]? CreateFeatures(Models.SoftwareList.Feature[]? features, Machine machine, string filename, int indexId, bool statsOnly)
|
|
||||||
{
|
|
||||||
// If the feature array is missing, we can't do anything
|
|
||||||
if (features == null || !features.Any())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var partFeatures = new List<PartFeature>();
|
|
||||||
foreach (var feature in features)
|
|
||||||
{
|
|
||||||
var item = new PartFeature();
|
|
||||||
item.SetName(feature.Name);
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Feature.ValueKey, feature.Value);
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
partFeatures.Add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [.. partFeatures];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert DataArea information
|
|
||||||
/// </summary>
|
|
||||||
/// <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)
|
|
||||||
{
|
|
||||||
// If the dataarea array is missing, we can't do anything
|
|
||||||
if (dataareas == null || !dataareas.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (var dataarea in dataareas)
|
|
||||||
{
|
|
||||||
var item = new DataArea();
|
|
||||||
item.SetName(dataarea.Name);
|
|
||||||
item.SetFieldValue<Endianness?>(Models.Metadata.DataArea.EndiannessKey, dataarea.Endianness.AsEnumValue<Endianness>());
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.DataArea.SizeKey, NumberHelper.ConvertToInt64(dataarea.Size));
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.DataArea.WidthKey, NumberHelper.ConvertToInt64(dataarea.Width));
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ConvertRoms(dataarea.Rom, part, item, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Rom information
|
|
||||||
/// </summary>
|
|
||||||
/// <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)
|
|
||||||
{
|
|
||||||
// If the rom array is missing, we can't do anything
|
|
||||||
if (roms == null || !roms.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var rom in roms)
|
|
||||||
{
|
|
||||||
var item = new Rom();
|
|
||||||
item.SetName(rom.Name);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, rom.CRC);
|
|
||||||
item.SetFieldValue<DataArea?>(Rom.DataAreaKey, dataarea);
|
|
||||||
item.SetFieldValue<LoadFlag>(Models.Metadata.Rom.LoadFlagKey, rom.LoadFlag.AsEnumValue<LoadFlag>());
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Rom.OffsetKey, rom.Offset);
|
|
||||||
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 });
|
|
||||||
item.SetFieldValue<ItemStatus>(Models.Metadata.Rom.StatusKey, rom.Status.AsEnumValue<ItemStatus>());
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Rom.ValueKey, rom.Value);
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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)
|
|
||||||
{
|
|
||||||
var item = new DiskArea();
|
|
||||||
item.SetName(diskarea.Name);
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ConvertDisks(diskarea.Disk, part, item, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Disk information
|
|
||||||
/// </summary>
|
|
||||||
/// <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)
|
|
||||||
{
|
|
||||||
// If the rom array is missing, we can't do anything
|
|
||||||
if (disks == null || !disks.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var disk in disks)
|
|
||||||
{
|
|
||||||
var item = new Disk();
|
|
||||||
item.SetName(disk.Name);
|
|
||||||
item.SetFieldValue<DiskArea?>(Disk.DiskAreaKey, diskarea);
|
|
||||||
item.SetFieldValue<ItemStatus>(Models.Metadata.Disk.StatusKey, disk.Status?.AsEnumValue<ItemStatus>() ?? ItemStatus.NULL);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Disk.MD5Key, disk.MD5);
|
|
||||||
item.SetFieldValue<Part?>(Disk.PartKey, part);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Disk.SHA1Key, disk.SHA1);
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Disk.WritableKey, disk.Writeable.AsYesNo());
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
var item = new DipSwitch();
|
|
||||||
item.SetName(dipswitch.Name);
|
|
||||||
item.SetFieldValue<DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey, CreateDipValues(dipswitch.DipValue, machine, filename, indexId)?.ToArray());
|
|
||||||
item.SetFieldValue<Part?>(DipSwitch.PartKey, part);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.DipSwitch.MaskKey, dipswitch.Mask);
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.DipSwitch.TagKey, dipswitch.Tag);
|
|
||||||
|
|
||||||
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>
|
|
||||||
private static List<DipValue>? CreateDipValues(Models.SoftwareList.DipValue[]? dipvalues, Machine machine, string filename, int indexId)
|
|
||||||
{
|
|
||||||
// If the feature array is missing, we can't do anything
|
|
||||||
if (dipvalues == null || !dipvalues.Any())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var settings = new List<DipValue>();
|
|
||||||
foreach (var dipvalue in dipvalues)
|
|
||||||
{
|
|
||||||
var item = new DipValue();
|
|
||||||
item.SetName(dipvalue.Name);
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.DipValue.DefaultKey, dipvalue.Default.AsYesNo());
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.DipValue.ValueKey, dipvalue.Value);
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
settings.Add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user