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;
|
|
|
|
|
|
|
|
|
|
Header.Name ??= softwarelist.Name;
|
|
|
|
|
Header.Description ??= softwarelist.Description;
|
|
|
|
|
Header.Comment ??= softwarelist.Notes;
|
|
|
|
|
|
|
|
|
|
// Handle implied SuperDAT
|
2023-08-10 23:22:14 -04:00
|
|
|
if (Header.Name?.Contains(" - SuperDAT") == true && keep)
|
2023-08-01 01:04:21 -04:00
|
|
|
Header.Type ??= "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
|
|
|
|
|
var machine = new Machine
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
Name = software.Name,
|
|
|
|
|
CloneOf = software.CloneOf,
|
2024-03-05 15:24:11 -05:00
|
|
|
Supported = software.Supported.AsEnumValue<Supported>(),
|
2023-08-01 01:04:21 -04:00
|
|
|
Description = software.Description,
|
|
|
|
|
Year = software.Year,
|
|
|
|
|
Publisher = software.Publisher,
|
|
|
|
|
Comment = software.Notes,
|
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
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
var infoItem = new Info
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
Value = info.Value,
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2024-03-08 21:12:13 -05:00
|
|
|
Source = new Source { Index = indexId, Name = filename },
|
2023-08-01 01:04:21 -04:00
|
|
|
};
|
2024-03-08 20:42:24 -05:00
|
|
|
infoItem.SetName(info.Name);
|
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
|
|
|
{
|
|
|
|
|
var sharedfeatItem = new SharedFeature
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
Value = sharedfeat.Value,
|
|
|
|
|
|
2024-03-08 21:12:13 -05:00
|
|
|
Source = new Source { Index = indexId, Name = filename },
|
2023-08-01 01:04:21 -04:00
|
|
|
};
|
2024-03-08 20:42:24 -05:00
|
|
|
sharedfeatItem.SetName(sharedfeat.Name);
|
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)
|
|
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
var blank = new Blank
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2024-03-08 21:12:13 -05:00
|
|
|
Source = 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
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
var item = new Part
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
Interface = part.Interface,
|
|
|
|
|
Features = CreateFeatures(part.Feature, machine, filename, indexId, statsOnly),
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2024-03-08 21:12:13 -05:00
|
|
|
Source = new Source { Index = indexId, Name = filename },
|
2023-08-01 01:04:21 -04:00
|
|
|
};
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(part.Name);
|
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>
|
|
|
|
|
private static List<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;
|
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
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
var item = new PartFeature
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
Value = feature.Value,
|
|
|
|
|
|
2024-03-08 21:12:13 -05:00
|
|
|
Source = new Source { Index = indexId, Name = filename },
|
2023-08-01 01:04:21 -04:00
|
|
|
};
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(feature.Name);
|
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
|
|
|
}
|
|
|
|
|
|
2023-08-01 01:04:21 -04: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
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
var item = new DataArea
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-11 14:30:31 -04:00
|
|
|
Size = NumberHelper.ConvertToInt64(dataarea.Size),
|
|
|
|
|
Width = NumberHelper.ConvertToInt64(dataarea.Width),
|
2024-03-05 15:24:11 -05:00
|
|
|
Endianness = dataarea.Endianness.AsEnumValue<Endianness>(),
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2024-03-08 21:12:13 -05:00
|
|
|
Source = new Source { Index = indexId, Name = filename },
|
2023-08-01 01:04:21 -04:00
|
|
|
};
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(dataarea.Name);
|
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
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
var item = new Rom
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-11 14:30:31 -04:00
|
|
|
Size = NumberHelper.ConvertToInt64(rom.Size ?? rom.Length),
|
2023-08-01 01:04:21 -04:00
|
|
|
CRC = rom.CRC,
|
|
|
|
|
SHA1 = rom.SHA1,
|
|
|
|
|
Offset = rom.Offset,
|
|
|
|
|
Value = rom.Value,
|
2024-03-05 15:24:11 -05:00
|
|
|
ItemStatus = rom.Status.AsEnumValue<ItemStatus>(),
|
|
|
|
|
LoadFlag = rom.LoadFlag.AsEnumValue<LoadFlag>(),
|
2023-08-01 01:04:21 -04:00
|
|
|
|
|
|
|
|
Part = part,
|
|
|
|
|
DataArea = dataarea,
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2024-03-08 21:12:13 -05:00
|
|
|
Source = new Source { Index = indexId, Name = filename },
|
2023-08-01 01:04:21 -04:00
|
|
|
};
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(rom.Name);
|
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)
|
|
|
|
|
{
|
|
|
|
|
var item = new DiskArea
|
|
|
|
|
{
|
2024-03-08 21:12:13 -05:00
|
|
|
Source = new Source { Index = indexId, Name = filename },
|
2023-08-01 01:04:21 -04:00
|
|
|
};
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(diskarea.Name);
|
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
|
|
|
{
|
|
|
|
|
var item = new Disk
|
|
|
|
|
{
|
2024-03-08 20:42:24 -05:00
|
|
|
MD5 = disk.MD5,
|
|
|
|
|
SHA1 = disk.SHA1,
|
|
|
|
|
ItemStatus = disk.Status.AsEnumValue<ItemStatus>(),
|
|
|
|
|
Writable = disk.Writeable.AsYesNo(),
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
Part = part,
|
|
|
|
|
DiskArea = diskarea,
|
2023-08-01 00:07:36 -04:00
|
|
|
|
2024-03-08 21:12:13 -05:00
|
|
|
Source = new Source { Index = indexId, Name = filename },
|
2023-08-01 01:04:21 -04:00
|
|
|
};
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(disk.Name);
|
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
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
var item = new DipSwitch
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
Tag = dipswitch.Tag,
|
|
|
|
|
Mask = dipswitch.Mask,
|
2023-08-14 13:17:51 -04:00
|
|
|
Values = CreateDipValues(dipswitch.DipValue, machine, filename, indexId),
|
2024-03-08 20:42:24 -05:00
|
|
|
|
2023-08-01 01:04:21 -04:00
|
|
|
Part = part,
|
|
|
|
|
|
2024-03-08 21:12:13 -05:00
|
|
|
Source = new Source { Index = indexId, Name = filename },
|
2023-08-01 01:04:21 -04:00
|
|
|
};
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(dipswitch.Name);
|
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)
|
|
|
|
|
{
|
2023-08-14 13:17:51 -04:00
|
|
|
var item = new DipValue
|
2023-08-01 00:07:36 -04:00
|
|
|
{
|
2023-08-01 01:04:21 -04:00
|
|
|
Value = dipvalue.Value,
|
|
|
|
|
Default = dipvalue.Default.AsYesNo(),
|
|
|
|
|
|
2024-03-08 21:12:13 -05:00
|
|
|
Source = new Source { Index = indexId, Name = filename },
|
2023-08-01 01:04:21 -04:00
|
|
|
};
|
2024-03-08 20:42:24 -05:00
|
|
|
item.SetName(dipvalue.Name);
|
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
|
|
|
}
|
|
|
|
|
}
|