mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Finish implementing Listxml internal conversion
This commit is contained in:
@@ -259,8 +259,10 @@ namespace SabreTools.DatFiles
|
|||||||
Header.SetFieldValue<bool?>(Models.Metadata.Header.LockRomModeKey, header.GetFieldValue<bool?>(Models.Metadata.Header.LockRomModeKey));
|
Header.SetFieldValue<bool?>(Models.Metadata.Header.LockRomModeKey, header.GetFieldValue<bool?>(Models.Metadata.Header.LockRomModeKey));
|
||||||
if (Header.GetFieldValue<bool?>(Models.Metadata.Header.LockSampleModeKey) == null)
|
if (Header.GetFieldValue<bool?>(Models.Metadata.Header.LockSampleModeKey) == null)
|
||||||
Header.SetFieldValue<bool?>(Models.Metadata.Header.LockSampleModeKey, header.GetFieldValue<bool?>(Models.Metadata.Header.LockSampleModeKey));
|
Header.SetFieldValue<bool?>(Models.Metadata.Header.LockSampleModeKey, header.GetFieldValue<bool?>(Models.Metadata.Header.LockSampleModeKey));
|
||||||
|
if (Header.GetFieldValue<string?>(Models.Metadata.Header.MameConfigKey) == null)
|
||||||
|
Header.SetFieldValue<string?>(Models.Metadata.Header.MameConfigKey, header.GetFieldValue<string?>(Models.Metadata.Header.NameKey));
|
||||||
if (Header.GetFieldValue<string?>(Models.Metadata.Header.NameKey) == null)
|
if (Header.GetFieldValue<string?>(Models.Metadata.Header.NameKey) == null)
|
||||||
Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, header.GetFieldValue<string?>(Models.Metadata.Header.NameKey));
|
Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, header.GetFieldValue<string?>(Models.Metadata.Header.MameConfigKey));
|
||||||
if (Header.GetFieldValue<string?>(Models.Metadata.Header.PluginKey) == null)
|
if (Header.GetFieldValue<string?>(Models.Metadata.Header.PluginKey) == null)
|
||||||
Header.SetFieldValue<string?>(Models.Metadata.Header.PluginKey, header.GetFieldValue<string?>(Models.Metadata.Header.PluginKey));
|
Header.SetFieldValue<string?>(Models.Metadata.Header.PluginKey, header.GetFieldValue<string?>(Models.Metadata.Header.PluginKey));
|
||||||
if (Header.GetFieldValue<string?>(Models.Metadata.Header.RefNameKey) == null)
|
if (Header.GetFieldValue<string?>(Models.Metadata.Header.RefNameKey) == null)
|
||||||
@@ -446,6 +448,11 @@ namespace SabreTools.DatFiles
|
|||||||
var items = ReadItemArray<Models.Metadata.SharedFeat>(item, Models.Metadata.Machine.SharedFeatKey);
|
var items = ReadItemArray<Models.Metadata.SharedFeat>(item, Models.Metadata.Machine.SharedFeatKey);
|
||||||
ProcessItems(items, machine, filename, indexId, statsOnly);
|
ProcessItems(items, machine, filename, indexId, statsOnly);
|
||||||
}
|
}
|
||||||
|
if (item.ContainsKey(Models.Metadata.Machine.SlotKey))
|
||||||
|
{
|
||||||
|
var items = ReadItemArray<Models.Metadata.Slot>(item, Models.Metadata.Machine.SlotKey);
|
||||||
|
ProcessItems(items, machine, filename, indexId, statsOnly);
|
||||||
|
}
|
||||||
if (item.ContainsKey(Models.Metadata.Machine.SoftwareListKey))
|
if (item.ContainsKey(Models.Metadata.Machine.SoftwareListKey))
|
||||||
{
|
{
|
||||||
var items = ReadItemArray<Models.Metadata.SoftwareList>(item, Models.Metadata.Machine.SoftwareListKey);
|
var items = ReadItemArray<Models.Metadata.SoftwareList>(item, Models.Metadata.Machine.SoftwareListKey);
|
||||||
@@ -487,6 +494,15 @@ namespace SabreTools.DatFiles
|
|||||||
var datItem = new DatItems.Formats.Adjuster(item);
|
var datItem = new DatItems.Formats.Adjuster(item);
|
||||||
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
||||||
datItem.CopyMachineInformation(machine);
|
datItem.CopyMachineInformation(machine);
|
||||||
|
|
||||||
|
// Handle subitems
|
||||||
|
var condition = item.Read<Models.Metadata.Condition>(Models.Metadata.Adjuster.ConditionKey);
|
||||||
|
if (condition != null)
|
||||||
|
{
|
||||||
|
var subItem = new DatItems.Formats.Condition(condition);
|
||||||
|
datItem.SetFieldValue<DatItems.Formats.Condition?>(Models.Metadata.Adjuster.ConditionKey, subItem);
|
||||||
|
}
|
||||||
|
|
||||||
ParseAddHelper(datItem, statsOnly);
|
ParseAddHelper(datItem, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -583,6 +599,49 @@ namespace SabreTools.DatFiles
|
|||||||
var datItem = new DatItems.Formats.Configuration(item);
|
var datItem = new DatItems.Formats.Configuration(item);
|
||||||
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
||||||
datItem.CopyMachineInformation(machine);
|
datItem.CopyMachineInformation(machine);
|
||||||
|
|
||||||
|
// Handle subitems
|
||||||
|
var condition = item.Read<Models.Metadata.Condition>(Models.Metadata.Configuration.ConditionKey);
|
||||||
|
if (condition != null)
|
||||||
|
{
|
||||||
|
var subItem = new DatItems.Formats.Condition(condition);
|
||||||
|
datItem.SetFieldValue<DatItems.Formats.Condition?>(Models.Metadata.Configuration.ConditionKey, subItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
var confLocations = ReadItemArray<Models.Metadata.ConfLocation>(item, Models.Metadata.Configuration.ConfLocationKey);
|
||||||
|
if (confLocations != null)
|
||||||
|
{
|
||||||
|
var subLocations = new List<DatItems.Formats.ConfLocation>();
|
||||||
|
foreach (var location in confLocations)
|
||||||
|
{
|
||||||
|
var subItem = new DatItems.Formats.ConfLocation(location);
|
||||||
|
subLocations.Add(subItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
datItem.SetFieldValue<DatItems.Formats.ConfLocation[]?>(Models.Metadata.Configuration.ConfLocationKey, [.. subLocations]);
|
||||||
|
}
|
||||||
|
|
||||||
|
var confSettings = ReadItemArray<Models.Metadata.ConfSetting>(item, Models.Metadata.Configuration.ConfSettingKey);
|
||||||
|
if (confSettings != null)
|
||||||
|
{
|
||||||
|
var subValues = new List<DatItems.Formats.ConfSetting>();
|
||||||
|
foreach (var setting in confSettings)
|
||||||
|
{
|
||||||
|
var subItem = new DatItems.Formats.ConfSetting(setting);
|
||||||
|
|
||||||
|
var subCondition = item.Read<Models.Metadata.Condition>(Models.Metadata.ConfSetting.ConditionKey);
|
||||||
|
if (subCondition != null)
|
||||||
|
{
|
||||||
|
var subSubItem = new DatItems.Formats.Condition(subCondition);
|
||||||
|
subItem.SetFieldValue<DatItems.Formats.Condition?>(Models.Metadata.ConfSetting.ConditionKey, subSubItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
subValues.Add(subItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
datItem.SetFieldValue<DatItems.Formats.ConfSetting[]?>(Models.Metadata.Configuration.ConfSettingKey, [.. subValues]);
|
||||||
|
}
|
||||||
|
|
||||||
ParseAddHelper(datItem, statsOnly);
|
ParseAddHelper(datItem, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -633,6 +692,28 @@ namespace SabreTools.DatFiles
|
|||||||
var datItem = new DatItems.Formats.Device(item);
|
var datItem = new DatItems.Formats.Device(item);
|
||||||
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
||||||
datItem.CopyMachineInformation(machine);
|
datItem.CopyMachineInformation(machine);
|
||||||
|
|
||||||
|
// Handle subitems
|
||||||
|
var instance = item.Read<Models.Metadata.Instance>(Models.Metadata.Device.InstanceKey);
|
||||||
|
if (instance != null)
|
||||||
|
{
|
||||||
|
var subItem = new DatItems.Formats.Instance(instance);
|
||||||
|
datItem.SetFieldValue<DatItems.Formats.Instance?>(Models.Metadata.Device.InstanceKey, subItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
var extensions = ReadItemArray<Models.Metadata.Extension>(item, Models.Metadata.Device.ExtensionKey);
|
||||||
|
if (extensions != null)
|
||||||
|
{
|
||||||
|
var subExtensions = new List<DatItems.Formats.Extension>();
|
||||||
|
foreach (var extension in extensions)
|
||||||
|
{
|
||||||
|
var subItem = new DatItems.Formats.Extension(extension);
|
||||||
|
subExtensions.Add(subItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
datItem.SetFieldValue<DatItems.Formats.Extension[]?>(Models.Metadata.Device.ExtensionKey, [.. subExtensions]);
|
||||||
|
}
|
||||||
|
|
||||||
ParseAddHelper(datItem, statsOnly);
|
ParseAddHelper(datItem, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -705,6 +786,49 @@ namespace SabreTools.DatFiles
|
|||||||
var datItem = new DatItems.Formats.DipSwitch(item);
|
var datItem = new DatItems.Formats.DipSwitch(item);
|
||||||
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
||||||
datItem.CopyMachineInformation(machine);
|
datItem.CopyMachineInformation(machine);
|
||||||
|
|
||||||
|
// Handle subitems
|
||||||
|
var condition = item.Read<Models.Metadata.Condition>(Models.Metadata.DipSwitch.ConditionKey);
|
||||||
|
if (condition != null)
|
||||||
|
{
|
||||||
|
var subItem = new DatItems.Formats.Condition(condition);
|
||||||
|
datItem.SetFieldValue<DatItems.Formats.Condition?>(Models.Metadata.DipSwitch.ConditionKey, subItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
var dipLocations = ReadItemArray<Models.Metadata.DipLocation>(item, Models.Metadata.DipSwitch.DipLocationKey);
|
||||||
|
if (dipLocations != null)
|
||||||
|
{
|
||||||
|
var subLocations = new List<DatItems.Formats.DipLocation>();
|
||||||
|
foreach (var location in dipLocations)
|
||||||
|
{
|
||||||
|
var subItem = new DatItems.Formats.DipLocation(location);
|
||||||
|
subLocations.Add(subItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
datItem.SetFieldValue<DatItems.Formats.DipLocation[]?>(Models.Metadata.DipSwitch.DipLocationKey, [.. subLocations]);
|
||||||
|
}
|
||||||
|
|
||||||
|
var dipValues = ReadItemArray<Models.Metadata.DipValue>(item, 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);
|
||||||
|
|
||||||
|
var subCondition = item.Read<Models.Metadata.Condition>(Models.Metadata.DipValue.ConditionKey);
|
||||||
|
if (subCondition != null)
|
||||||
|
{
|
||||||
|
var subSubItem = new DatItems.Formats.Condition(subCondition);
|
||||||
|
subItem.SetFieldValue<DatItems.Formats.Condition?>(Models.Metadata.DipValue.ConditionKey, subSubItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
subValues.Add(subItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
datItem.SetFieldValue<DatItems.Formats.DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey, [.. subValues]);
|
||||||
|
}
|
||||||
|
|
||||||
ParseAddHelper(datItem, statsOnly);
|
ParseAddHelper(datItem, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -966,6 +1090,21 @@ namespace SabreTools.DatFiles
|
|||||||
var datItem = new DatItems.Formats.Input(item);
|
var datItem = new DatItems.Formats.Input(item);
|
||||||
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
||||||
datItem.CopyMachineInformation(machine);
|
datItem.CopyMachineInformation(machine);
|
||||||
|
|
||||||
|
// Handle subitems
|
||||||
|
var controls = ReadItemArray<Models.Metadata.Control>(item, Models.Metadata.Input.ControlKey);
|
||||||
|
if (controls != null)
|
||||||
|
{
|
||||||
|
var subControls = new List<DatItems.Formats.Control>();
|
||||||
|
foreach (var control in controls)
|
||||||
|
{
|
||||||
|
var subItem = new DatItems.Formats.Control(control);
|
||||||
|
subControls.Add(subItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
datItem.SetFieldValue<DatItems.Formats.Control[]?>(Models.Metadata.Input.ControlKey, [.. subControls]);
|
||||||
|
}
|
||||||
|
|
||||||
ParseAddHelper(datItem, statsOnly);
|
ParseAddHelper(datItem, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1042,6 +1181,21 @@ namespace SabreTools.DatFiles
|
|||||||
var datItem = new DatItems.Formats.Port(item);
|
var datItem = new DatItems.Formats.Port(item);
|
||||||
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
||||||
datItem.CopyMachineInformation(machine);
|
datItem.CopyMachineInformation(machine);
|
||||||
|
|
||||||
|
// Handle subitems
|
||||||
|
var analogs = ReadItemArray<Models.Metadata.Analog>(item, Models.Metadata.Port.AnalogKey);
|
||||||
|
if (analogs != null)
|
||||||
|
{
|
||||||
|
var subAnalogs = new List<DatItems.Formats.Analog>();
|
||||||
|
foreach (var analog in analogs)
|
||||||
|
{
|
||||||
|
var subItem = new DatItems.Formats.Analog(analog);
|
||||||
|
subAnalogs.Add(subItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
datItem.SetFieldValue<DatItems.Formats.Analog[]?>(Models.Metadata.Port.AnalogKey, [.. subAnalogs]);
|
||||||
|
}
|
||||||
|
|
||||||
ParseAddHelper(datItem, statsOnly);
|
ParseAddHelper(datItem, statsOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1166,6 +1320,45 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert Slot 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.Slot[]? 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.Slot(item);
|
||||||
|
datItem.SetFieldValue<DatItems.Source?>(DatItems.DatItem.SourceKey, new DatItems.Source { Index = indexId, Name = filename });
|
||||||
|
datItem.CopyMachineInformation(machine);
|
||||||
|
|
||||||
|
// Handle subitems
|
||||||
|
var slotOptions = ReadItemArray<Models.Metadata.SlotOption>(item, Models.Metadata.Slot.SlotOptionKey);
|
||||||
|
if (slotOptions != null)
|
||||||
|
{
|
||||||
|
var subOptions = new List<DatItems.Formats.SlotOption>();
|
||||||
|
foreach (var slotOption in slotOptions)
|
||||||
|
{
|
||||||
|
var subItem = new DatItems.Formats.SlotOption(slotOption);
|
||||||
|
subOptions.Add(subItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
datItem.SetFieldValue<DatItems.Formats.SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey, [.. subOptions]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ParseAddHelper(datItem, statsOnly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert SoftwareList information
|
/// Convert SoftwareList information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
{
|
{
|
||||||
var disk = new Disk();
|
var disk = new Disk();
|
||||||
disk.SetName(row.Name);
|
disk.SetName(row.Name);
|
||||||
disk.SetFieldValue<ItemStatus>(Models.Metadata.Disk.StatusKey, value: ItemStatus.BadDump);
|
disk.SetFieldValue<ItemStatus>(Models.Metadata.Disk.StatusKey, ItemStatus.BadDump);
|
||||||
disk.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
disk.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(row.MD5))
|
if (!string.IsNullOrEmpty(row.MD5))
|
||||||
|
|||||||
@@ -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
|
||||||
{
|
{
|
||||||
@@ -21,12 +15,10 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
// Deserialize the input file
|
// Deserialize the input file
|
||||||
// TODO: Support M1 DATs again
|
// TODO: Support M1 DATs again
|
||||||
var mame = new Serialization.Files.Listxml().Deserialize(filename);
|
var mame = new Serialization.Files.Listxml().Deserialize(filename);
|
||||||
|
var metadata = new Serialization.CrossModel.Listxml().Serialize(mame);
|
||||||
|
|
||||||
// Convert the header to the internal format
|
// Convert to the internal format
|
||||||
ConvertHeader(mame, keep);
|
ConvertMetadata(metadata, filename, indexId, keep, statsOnly);
|
||||||
|
|
||||||
// Convert the game data to the internal format
|
|
||||||
ConvertGames(mame?.Game, filename, indexId, statsOnly);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex) when (!throwOnError)
|
catch (Exception ex) when (!throwOnError)
|
||||||
{
|
{
|
||||||
@@ -34,920 +26,5 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
logger.Error(ex, message);
|
logger.Error(ex, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Converters
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert header information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mame">Deserialized model to convert</param>
|
|
||||||
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
|
||||||
private void ConvertHeader(Models.Listxml.Mame? mame, bool keep)
|
|
||||||
{
|
|
||||||
// If the mame is missing, we can't do anything
|
|
||||||
if (mame == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (Header.GetFieldValue<string?>(Models.Metadata.Header.NameKey) == null)
|
|
||||||
Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, mame.Build);
|
|
||||||
if (Header.GetFieldValue<string?>(Models.Metadata.Header.DescriptionKey) == null)
|
|
||||||
Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, mame.Build);
|
|
||||||
if (Header.GetFieldValue<string?>(Models.Metadata.Header.BuildKey) == null)
|
|
||||||
Header.SetFieldValue<string?>(Models.Metadata.Header.BuildKey, mame.Build);
|
|
||||||
if (Header.GetFieldValue<bool?>(Models.Metadata.Header.DebugKey) == null)
|
|
||||||
Header.SetFieldValue<bool?> (Models.Metadata.Header.DebugKey, mame.Debug.AsYesNo());
|
|
||||||
if (Header.GetFieldValue<string?>(Models.Metadata.Header.MameConfigKey) == null)
|
|
||||||
Header.SetFieldValue<string?>(Models.Metadata.Header.MameConfigKey, mame.MameConfig);
|
|
||||||
|
|
||||||
// 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 games information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="games">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 ConvertGames(Models.Listxml.GameBase[]? games, string filename, int indexId, bool statsOnly)
|
|
||||||
{
|
|
||||||
// If the game array is missing, we can't do anything
|
|
||||||
if (games == null || !games.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Loop through the games and add
|
|
||||||
foreach (var game in games)
|
|
||||||
{
|
|
||||||
ConvertGame(game, filename, indexId, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert game information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="game">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 ConvertGame(Models.Listxml.GameBase game, string filename, int indexId, bool statsOnly)
|
|
||||||
{
|
|
||||||
// If the game is missing, we can't do anything
|
|
||||||
if (game == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Create the machine for copying information
|
|
||||||
var machine = new Machine();
|
|
||||||
machine.SetFieldValue<string?>(Models.Metadata.Machine.CloneOfKey, game.CloneOf);
|
|
||||||
machine.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, game.Description);
|
|
||||||
machine.SetFieldValue<string?>(Models.Metadata.Machine.HistoryKey, game.History);
|
|
||||||
machine.SetFieldValue<bool?>(Models.Metadata.Machine.IsBiosKey, game.IsBios.AsYesNo());
|
|
||||||
machine.SetFieldValue<bool?>(Models.Metadata.Machine.IsDeviceKey, game.IsDevice.AsYesNo());
|
|
||||||
machine.SetFieldValue<bool?>(Models.Metadata.Machine.IsMechanicalKey, game.IsMechanical.AsYesNo());
|
|
||||||
machine.SetFieldValue<string?>(Models.Metadata.Machine.ManufacturerKey, game.Manufacturer);
|
|
||||||
machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, game.Name);
|
|
||||||
machine.SetFieldValue<Runnable>(Models.Metadata.Machine.RunnableKey, game.Runnable.AsEnumValue<Runnable>());
|
|
||||||
machine.SetFieldValue<string?>(Models.Metadata.Machine.RomOfKey, game.RomOf);
|
|
||||||
machine.SetFieldValue<string?>(Models.Metadata.Machine.SampleOfKey, game.SampleOf);
|
|
||||||
machine.SetFieldValue<string?>(Models.Metadata.Machine.SourceFileKey, game.SourceFile);
|
|
||||||
machine.SetFieldValue<string?>(Models.Metadata.Machine.YearKey, game.Year);
|
|
||||||
|
|
||||||
// Check if there are any items
|
|
||||||
bool containsItems = false;
|
|
||||||
|
|
||||||
// Loop through each type of item
|
|
||||||
ConvertBiosSets(game.BiosSet, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertRoms(game.Rom, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertDisks(game.Disk, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertDeviceRefs(game.DeviceRef, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertSamples(game.Sample, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertChips(game.Chip, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertDisplays(game.Display, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertVideos(game.Video, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertSound(game.Sound, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertInput(game.Input, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertDipSwitches(game.DipSwitch, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertConfigurations(game.Configuration, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertPorts(game.Port, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertAdjusters(game.Adjuster, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertDriver(game.Driver, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertFeatures(game.Feature, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertDevices(game.Device, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertSlots(game.Slot, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertSoftwareLists(game.SoftwareList, machine, filename, indexId, statsOnly, ref containsItems);
|
|
||||||
ConvertRamOptions(game.RamOption, 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 BiosSet information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="biossets">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 ConvertBiosSets(Models.Listxml.BiosSet[]? biossets, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the BiosSet array is missing, we can't do anything
|
|
||||||
if (biossets == null || !biossets.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var biosset in biossets)
|
|
||||||
{
|
|
||||||
var item = new BiosSet();
|
|
||||||
item.SetName(biosset.Name);
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.BiosSet.DefaultKey, biosset.Default?.AsYesNo());
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.BiosSet.DescriptionKey, biosset.Description);
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Rom information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="roms">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 ConvertRoms(Models.Listxml.Rom[]? roms, 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<long?>(Models.Metadata.Rom.SizeKey, NumberHelper.ConvertToInt64(rom.Size));
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Rom.BiosKey, rom.Bios);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, rom.CRC);
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Rom.DisposeKey, rom.Dispose.AsYesNo());
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Rom.MergeKey, rom.Merge);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Rom.OffsetKey, rom.Offset);
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Rom.OptionalKey, rom.Optional.AsYesNo());
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Rom.RegionKey, rom.Region);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key, rom.SHA1);
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Rom.SoundOnlyKey, rom.SoundOnly.AsYesNo());
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<ItemStatus>(Models.Metadata.Rom.StatusKey, rom.Status.AsEnumValue<ItemStatus>());
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Disk information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disks">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 ConvertDisks(Models.Listxml.Disk[]? disks, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Disk 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<string?>(Models.Metadata.Disk.IndexKey, disk.Index);
|
|
||||||
item.SetFieldValue<ItemStatus>(Models.Metadata.Disk.StatusKey, disk.Status?.AsEnumValue<ItemStatus>() ?? ItemStatus.NULL);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Disk.MD5Key, disk.MD5);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Disk.MergeKey, disk.Merge);
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Disk.OptionalKey, disk.Optional.AsYesNo());
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Disk.RegionKey, disk.Region);
|
|
||||||
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.Writable.AsYesNo());
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert DeviceRef information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="devicerefs">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 ConvertDeviceRefs(Models.Listxml.DeviceRef[]? devicerefs, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the DeviceRef array is missing, we can't do anything
|
|
||||||
if (devicerefs == null || !devicerefs.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var deviceref in devicerefs)
|
|
||||||
{
|
|
||||||
var item = new DeviceRef();
|
|
||||||
item.SetName(deviceref.Name);
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Sample information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="samples">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 ConvertSamples(Models.Listxml.Sample[]? samples, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Sample array is missing, we can't do anything
|
|
||||||
if (samples == null || !samples.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var sample in samples)
|
|
||||||
{
|
|
||||||
var item = new Sample();
|
|
||||||
item.SetName(sample.Name);
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Chip information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="chips">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 ConvertChips(Models.Listxml.Chip[]? chips, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Chip array is missing, we can't do anything
|
|
||||||
if (chips == null || !chips.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var chip in chips)
|
|
||||||
{
|
|
||||||
var item = new Chip();
|
|
||||||
item.SetName(chip.Name);
|
|
||||||
item.SetFieldValue<ChipType?>(Models.Metadata.Chip.ChipTypeKey, chip.Type.AsEnumValue<ChipType>());
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Chip.ClockKey, NumberHelper.ConvertToInt64(chip.Clock));
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Chip.SoundOnlyKey, chip.SoundOnly.AsYesNo());
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Chip.TagKey, chip.Tag);
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Display information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="displays">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 ConvertDisplays(Models.Listxml.Display[]? displays, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Display array is missing, we can't do anything
|
|
||||||
if (displays == null || !displays.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var display in displays)
|
|
||||||
{
|
|
||||||
var item = new Display();
|
|
||||||
item.SetFieldValue<DisplayType>(Models.Metadata.Display.DisplayTypeKey, display.Type.AsEnumValue<DisplayType>());
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Display.FlipXKey, display.FlipX.AsYesNo());
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.HBEndKey, NumberHelper.ConvertToInt64(display.HBEnd));
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.HBStartKey, NumberHelper.ConvertToInt64(display.HBStart));
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.HeightKey, NumberHelper.ConvertToInt64(display.Height));
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.HTotalKey, NumberHelper.ConvertToInt64(display.HTotal));
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.PixClockKey, NumberHelper.ConvertToInt64(display.PixClock));
|
|
||||||
item.SetFieldValue<double?>(Models.Metadata.Display.RefreshKey, NumberHelper.ConvertToDouble(display.Refresh));
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.RotateKey, NumberHelper.ConvertToInt64(display.Rotate));
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Display.TagKey, display.Tag);
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.VBEndKey, NumberHelper.ConvertToInt64(display.VBEnd));
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.VBStartKey, NumberHelper.ConvertToInt64(display.VBStart));
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.VTotalKey, NumberHelper.ConvertToInt64(display.VTotal));
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.WidthKey, NumberHelper.ConvertToInt64(display.Width));
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Video information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="videos">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 ConvertVideos(Models.Listxml.Video[]? videos, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Video array is missing, we can't do anything
|
|
||||||
if (videos == null || !videos.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var video in videos)
|
|
||||||
{
|
|
||||||
var item = new Display();
|
|
||||||
item.SetFieldValue<long?>("ASPECTX", NumberHelper.ConvertToInt64(video.AspectX));
|
|
||||||
item.SetFieldValue<long?>("ASPECTY", NumberHelper.ConvertToInt64(video.AspectY));
|
|
||||||
item.SetFieldValue<DisplayType>(Models.Metadata.Display.DisplayTypeKey, video.Screen?.AsEnumValue<DisplayType>() ?? DisplayType.NULL);
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.HeightKey, NumberHelper.ConvertToInt64(video.Height));
|
|
||||||
item.SetFieldValue<double?>(Models.Metadata.Display.RefreshKey, NumberHelper.ConvertToDouble(video.Refresh));
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.WidthKey, NumberHelper.ConvertToInt64(video.Width));
|
|
||||||
|
|
||||||
switch (video.Orientation)
|
|
||||||
{
|
|
||||||
case "horizontal":
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.RotateKey, 0);
|
|
||||||
break;
|
|
||||||
case "vertical":
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Display.RotateKey, 90);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Sound information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sound">Deserialized model 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 ConvertSound(Models.Listxml.Sound? sound, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Sound is missing, we can't do anything
|
|
||||||
if (sound == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
var item = new Sound();
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Sound.ChannelsKey, NumberHelper.ConvertToInt64(sound.Channels));
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Input information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="input">Deserialized model 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 ConvertInput(Models.Listxml.Input? input, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Input is missing, we can't do anything
|
|
||||||
if (input == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
var item = new Input();
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Input.ButtonsKey, NumberHelper.ConvertToInt64(input.Buttons));
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Input.CoinsKey, NumberHelper.ConvertToInt64(input.Coins));
|
|
||||||
//item.SetFieldValue<string?>(Models.Metadata.Input.ControlKey, input.ControlAttr);
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Input.PlayersKey, NumberHelper.ConvertToInt64(input.Players));
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Input.ServiceKey, input.Service?.AsYesNo());
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Input.TiltKey, input.Tilt?.AsYesNo());
|
|
||||||
|
|
||||||
var controls = new List<Control>();
|
|
||||||
foreach (var control in input.Control ?? [])
|
|
||||||
{
|
|
||||||
var controlItem = new Control();
|
|
||||||
controlItem.SetFieldValue<long?>(Models.Metadata.Control.ButtonsKey, NumberHelper.ConvertToInt64(control.Buttons));
|
|
||||||
controlItem.SetFieldValue<ControlType?>(Models.Metadata.Control.ControlTypeKey, control.Type.AsEnumValue<ControlType>());
|
|
||||||
controlItem.SetFieldValue<long?>(Models.Metadata.Control.KeyDeltaKey, NumberHelper.ConvertToInt64(control.KeyDelta));
|
|
||||||
controlItem.SetFieldValue<long?>(Models.Metadata.Control.MaximumKey, NumberHelper.ConvertToInt64(control.Maximum));
|
|
||||||
controlItem.SetFieldValue<long?>(Models.Metadata.Control.MinimumKey, NumberHelper.ConvertToInt64(control.Minimum));
|
|
||||||
controlItem.SetFieldValue<long?>(Models.Metadata.Control.PlayerKey, NumberHelper.ConvertToInt64(control.Player));
|
|
||||||
controlItem.SetFieldValue<long?>(Models.Metadata.Control.ReqButtonsKey, NumberHelper.ConvertToInt64(control.ReqButtons));
|
|
||||||
controlItem.SetFieldValue<bool?>(Models.Metadata.Control.ReverseKey, control.Reverse.AsYesNo());
|
|
||||||
controlItem.SetFieldValue<long?>(Models.Metadata.Control.SensitivityKey, NumberHelper.ConvertToInt64(control.Sensitivity));
|
|
||||||
controlItem.SetFieldValue<string?>(Models.Metadata.Control.WaysKey, control.Ways);
|
|
||||||
controlItem.SetFieldValue<string?>(Models.Metadata.Control.Ways2Key, control.Ways2);
|
|
||||||
controlItem.SetFieldValue<string?>(Models.Metadata.Control.Ways3Key, control.Ways3);
|
|
||||||
|
|
||||||
controls.Add(controlItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (controls.Any())
|
|
||||||
item.SetFieldValue<Control[]?>(Models.Metadata.Input.ControlKey, [.. controls]);
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert DipSwitch information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dipswitches">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 ConvertDipSwitches(Models.Listxml.DipSwitch[]? dipswitches, 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;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var dipswitch in dipswitches)
|
|
||||||
{
|
|
||||||
var item = new DipSwitch();
|
|
||||||
item.SetName(dipswitch.Name);
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (dipswitch.Condition != null)
|
|
||||||
{
|
|
||||||
var condition = new Condition();
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.MaskKey, dipswitch.Condition.Mask);
|
|
||||||
condition.SetFieldValue<Relation?>(Models.Metadata.Condition.RelationKey, dipswitch.Condition.Relation.AsEnumValue<Relation>());
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.TagKey, dipswitch.Condition.Tag);
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.ValueKey, dipswitch.Condition.Value);
|
|
||||||
|
|
||||||
item.SetFieldValue<Condition[]?>(Models.Metadata.DipSwitch.ConditionKey, [condition]);
|
|
||||||
}
|
|
||||||
|
|
||||||
var locations = new List<DipLocation>();
|
|
||||||
foreach (var diplocation in dipswitch.DipLocation ?? [])
|
|
||||||
{
|
|
||||||
var locationItem = new DipLocation();
|
|
||||||
locationItem.SetName(diplocation.Name);
|
|
||||||
locationItem.SetFieldValue<bool?>(Models.Metadata.DipLocation.InvertedKey, diplocation.Inverted.AsYesNo());
|
|
||||||
locationItem.SetFieldValue<long?>(Models.Metadata.DipLocation.NumberKey, NumberHelper.ConvertToInt64(diplocation.Number));
|
|
||||||
|
|
||||||
locations.Add(locationItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (locations.Any())
|
|
||||||
item.SetFieldValue<DipLocation[]?>(Models.Metadata.DipSwitch.DipLocationKey, [.. locations]);
|
|
||||||
|
|
||||||
var settings = new List<DipValue>();
|
|
||||||
foreach (var dipvalue in dipswitch.DipValue ?? [])
|
|
||||||
{
|
|
||||||
var dipValueItem = new DipValue();
|
|
||||||
dipValueItem.SetName(dipvalue.Name);
|
|
||||||
dipValueItem.SetFieldValue<bool?>(Models.Metadata.DipValue.DefaultKey, dipvalue.Default.AsYesNo());
|
|
||||||
dipValueItem.SetFieldValue<string?>(Models.Metadata.DipValue.ValueKey, dipvalue.Value);
|
|
||||||
|
|
||||||
if (dipvalue.Condition != null)
|
|
||||||
{
|
|
||||||
var condition = new Condition();
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.MaskKey, dipvalue.Condition.Mask);
|
|
||||||
condition.SetFieldValue<Relation?>(Models.Metadata.Condition.RelationKey, dipvalue.Condition.Relation.AsEnumValue<Relation>());
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.TagKey, dipvalue.Condition.Tag);
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.ValueKey, dipvalue.Condition.Value);
|
|
||||||
|
|
||||||
dipValueItem.SetFieldValue<Condition[]?>(Models.Metadata.DipValue.ConditionKey, [condition]);
|
|
||||||
}
|
|
||||||
|
|
||||||
settings.Add(dipValueItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.Any())
|
|
||||||
item.SetFieldValue<DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey, [.. settings]);
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Configuration information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="configurations">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 ConvertConfigurations(Models.Listxml.Configuration[]? configurations, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Configuration array is missing, we can't do anything
|
|
||||||
if (configurations == null || !configurations.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var configuration in configurations)
|
|
||||||
{
|
|
||||||
var item = new Configuration();
|
|
||||||
item.SetName(configuration.Name);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Configuration.MaskKey, configuration.Mask);
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Configuration.TagKey, configuration.Tag);
|
|
||||||
|
|
||||||
if (configuration.Condition != null)
|
|
||||||
{
|
|
||||||
var condition = new DatItems.Formats.Condition();
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.MaskKey, configuration.Condition.Mask);
|
|
||||||
condition.SetFieldValue<Relation?>(Models.Metadata.Condition.RelationKey, configuration.Condition.Relation.AsEnumValue<Relation>());
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.TagKey, configuration.Condition.Tag);
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.ValueKey, configuration.Condition.Value);
|
|
||||||
|
|
||||||
item.SetFieldValue<Condition[]?>(Models.Metadata.Configuration.ConditionKey, [condition]);
|
|
||||||
}
|
|
||||||
|
|
||||||
var locations = new List<ConfLocation>();
|
|
||||||
foreach (var confLocation in configuration.ConfLocation ?? [])
|
|
||||||
{
|
|
||||||
var locationItem = new ConfLocation();
|
|
||||||
locationItem.SetName(confLocation.Name);
|
|
||||||
locationItem.SetFieldValue<bool?>(Models.Metadata.ConfLocation.InvertedKey, confLocation.Inverted.AsYesNo());
|
|
||||||
locationItem.SetFieldValue<long?>(Models.Metadata.ConfLocation.NumberKey, NumberHelper.ConvertToInt64(confLocation.Number));
|
|
||||||
|
|
||||||
locations.Add(locationItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (locations.Any())
|
|
||||||
item.SetFieldValue<ConfLocation[]?>(Models.Metadata.Configuration.ConfLocationKey, [.. locations]);
|
|
||||||
|
|
||||||
var settings = new List<ConfSetting>();
|
|
||||||
foreach (var dipvalue in configuration.ConfSetting ?? [])
|
|
||||||
{
|
|
||||||
var settingItem = new ConfSetting();
|
|
||||||
settingItem.SetName(dipvalue.Name);
|
|
||||||
settingItem.SetFieldValue<bool?>(Models.Metadata.ConfSetting.DefaultKey, dipvalue.Default.AsYesNo());
|
|
||||||
settingItem.SetFieldValue<string?>(Models.Metadata.ConfSetting.ValueKey, dipvalue.Value);
|
|
||||||
|
|
||||||
if (dipvalue.Condition != null)
|
|
||||||
{
|
|
||||||
var condition = new Condition();
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.MaskKey, dipvalue.Condition.Mask);
|
|
||||||
condition.SetFieldValue<Relation?>(Models.Metadata.Condition.RelationKey, dipvalue.Condition.Relation.AsEnumValue<Relation>());
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.TagKey, dipvalue.Condition.Tag);
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.ValueKey, dipvalue.Condition.Value);
|
|
||||||
|
|
||||||
settingItem.SetFieldValue<Condition[]?>(Models.Metadata.ConfSetting.ConditionKey, [condition]);
|
|
||||||
}
|
|
||||||
|
|
||||||
settings.Add(settingItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.Any())
|
|
||||||
item.SetFieldValue<ConfSetting[]?>(Models.Metadata.Configuration.ConfSettingKey, [.. settings]);
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Port information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ports">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 ConvertPorts(Models.Listxml.Port[]? ports, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Port array is missing, we can't do anything
|
|
||||||
if (ports == null || !ports.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var port in ports)
|
|
||||||
{
|
|
||||||
var item = new Port();
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<string>(Models.Metadata.Port.TagKey, port.Tag);
|
|
||||||
|
|
||||||
var analogs = new List<Analog>();
|
|
||||||
foreach (var analog in port.Analog ?? [])
|
|
||||||
{
|
|
||||||
var analogItem = new Analog();
|
|
||||||
analogItem.SetFieldValue<string?>(Models.Metadata.Analog.MaskKey, analog.Mask);
|
|
||||||
|
|
||||||
analogs.Add(analogItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (analogs.Any())
|
|
||||||
item.SetFieldValue<Analog[]?>(Models.Metadata.Port.AnalogKey, [.. analogs]);
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Adjuster information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="adjusters">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 ConvertAdjusters(Models.Listxml.Adjuster[]? adjusters, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Adjuster array is missing, we can't do anything
|
|
||||||
if (adjusters == null || !adjusters.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var adjuster in adjusters)
|
|
||||||
{
|
|
||||||
var item = new Adjuster();
|
|
||||||
item.SetName(adjuster.Name);
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Adjuster.DefaultKey, adjuster.Default.AsYesNo());
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
|
|
||||||
if (adjuster.Condition != null)
|
|
||||||
{
|
|
||||||
var condition = new Condition();
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.MaskKey, adjuster.Condition.Mask);
|
|
||||||
condition.SetFieldValue<Relation?>(Models.Metadata.Condition.RelationKey, adjuster.Condition.Relation.AsEnumValue<Relation>());
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.TagKey, adjuster.Condition.Tag);
|
|
||||||
condition.SetFieldValue<string?>(Models.Metadata.Condition.ValueKey, adjuster.Condition.Value);
|
|
||||||
|
|
||||||
item.SetFieldValue<Condition[]?>(Models.Metadata.Adjuster.ConditionKey, [condition]);
|
|
||||||
}
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Driver information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="driver">Deserialized model 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 ConvertDriver(Models.Listxml.Driver? driver, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Driver is missing, we can't do anything
|
|
||||||
if (driver == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
var item = new Driver();
|
|
||||||
item.SetFieldValue<SupportStatus>(Models.Metadata.Driver.CocktailKey, driver.Cocktail?.AsEnumValue<SupportStatus>() ?? SupportStatus.NULL);
|
|
||||||
item.SetFieldValue<SupportStatus>(Models.Metadata.Driver.ColorKey, driver.Color?.AsEnumValue<SupportStatus>() ?? SupportStatus.NULL);
|
|
||||||
item.SetFieldValue<SupportStatus>(Models.Metadata.Driver.EmulationKey, driver.Emulation?.AsEnumValue<SupportStatus>() ?? SupportStatus.NULL);
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Driver.IncompleteKey, driver.Incomplete.AsYesNo());
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Driver.NoSoundHardwareKey, driver.NoSoundHardware.AsYesNo());
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Driver.PaletteSizeKey, NumberHelper.ConvertToInt64(driver.PaletteSize));
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Driver.RequiresArtworkKey, driver.RequiresArtwork.AsYesNo());
|
|
||||||
item.SetFieldValue<Supported>(Models.Metadata.Driver.SaveStateKey, driver.SaveState?.AsEnumValue<Supported>() ?? Supported.NULL);
|
|
||||||
item.SetFieldValue<SupportStatus>(Models.Metadata.Driver.SoundKey, driver.Sound?.AsEnumValue<SupportStatus>() ?? SupportStatus.NULL);
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<SupportStatus>(Models.Metadata.Driver.StatusKey, driver.Status?.AsEnumValue<SupportStatus>() ?? SupportStatus.NULL);
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.Driver.UnofficialKey, driver.Unofficial.AsYesNo());
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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>
|
|
||||||
/// <param name="containsItems">True if there were any items in the array, false otherwise</param>
|
|
||||||
private void ConvertFeatures(Models.Listxml.Feature[]? features, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Feature array is missing, we can't do anything
|
|
||||||
if (features == null || !features.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var feature in features)
|
|
||||||
{
|
|
||||||
var item = new Feature();
|
|
||||||
item.SetFieldValue<FeatureType>(Models.Metadata.Feature.FeatureTypeKey, feature.Type.AsEnumValue<FeatureType>());
|
|
||||||
item.SetFieldValue<FeatureStatus>(Models.Metadata.Feature.OverallKey, feature.Overall.AsEnumValue<FeatureStatus>());
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<FeatureStatus>(Models.Metadata.Feature.StatusKey, feature.Status.AsEnumValue<FeatureStatus>());
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Device information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="devices">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 ConvertDevices(Models.Listxml.Device[]? devices, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Device array is missing, we can't do anything
|
|
||||||
if (devices == null || !devices.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var device in devices)
|
|
||||||
{
|
|
||||||
var item = new Device();
|
|
||||||
item.SetFieldValue<DeviceType>(Models.Metadata.Device.DeviceTypeKey, device.Type.AsEnumValue<DeviceType>());
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Device.FixedImageKey, device.FixedImage);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Device.InterfaceKey, device.Interface);
|
|
||||||
item.SetFieldValue<long?>(Models.Metadata.Device.MandatoryKey, NumberHelper.ConvertToInt64(device.Mandatory));
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.Device.TagKey, device.Tag);
|
|
||||||
|
|
||||||
if (device.Instance != null)
|
|
||||||
{
|
|
||||||
var instance = new Instance();
|
|
||||||
instance.SetName(device.Instance.Name);
|
|
||||||
instance.SetFieldValue<string?>(Models.Metadata.Instance.BriefNameKey, device.Instance.BriefName);
|
|
||||||
|
|
||||||
item.SetFieldValue<Instance[]?>(Models.Metadata.Device.InstanceKey, [instance]);
|
|
||||||
}
|
|
||||||
|
|
||||||
var extensions = new List<Extension>();
|
|
||||||
foreach (var extension in device.Extension ?? [])
|
|
||||||
{
|
|
||||||
var extensionItem = new Extension();
|
|
||||||
extensionItem.SetName(extension.Name);
|
|
||||||
|
|
||||||
extensions.Add(extensionItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extensions.Any())
|
|
||||||
item.SetFieldValue<Extension[]?>(Models.Metadata.Device.ExtensionKey, extensions.ToArray());
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert Slot information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="slots">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 ConvertSlots(Models.Listxml.Slot[]? slots, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the Slot array is missing, we can't do anything
|
|
||||||
if (slots == null || !slots.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var slot in slots)
|
|
||||||
{
|
|
||||||
var item = new Slot();
|
|
||||||
item.SetName(slot.Name);
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
|
|
||||||
var slotoptions = new List<SlotOption>();
|
|
||||||
foreach (var slotoption in slot.SlotOption ?? [])
|
|
||||||
{
|
|
||||||
var slotoptionItem = new SlotOption();
|
|
||||||
slotoptionItem.SetName(slotoption.Name);
|
|
||||||
slotoptionItem.SetFieldValue<bool?>(Models.Metadata.SlotOption.DefaultKey, slotoption.Default.AsYesNo());
|
|
||||||
slotoptionItem.SetFieldValue<string?>(Models.Metadata.SlotOption.DevNameKey, slotoption.DevName);
|
|
||||||
|
|
||||||
slotoptions.Add(slotoptionItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slotoptions.Any())
|
|
||||||
item.SetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey, [.. slotoptions]);
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert SoftwareList information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="softwarelists">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 ConvertSoftwareLists(Models.Listxml.SoftwareList[]? softwarelists, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the SoftwareList array is missing, we can't do anything
|
|
||||||
if (softwarelists == null || !softwarelists.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var softwarelist in softwarelists)
|
|
||||||
{
|
|
||||||
var item = new DatItems.Formats.SoftwareList();
|
|
||||||
item.SetName(softwarelist.Name);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.SoftwareList.FilterKey, softwarelist.Filter);
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
item.SetFieldValue<SoftwareListStatus>(Models.Metadata.SoftwareList.StatusKey, softwarelist.Status.AsEnumValue<SoftwareListStatus>());
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.SoftwareList.TagKey, softwarelist.Tag);
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert RamOption information
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ramoptions">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 ConvertRamOptions(Models.Listxml.RamOption[]? ramoptions, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
|
|
||||||
{
|
|
||||||
// If the RamOption array is missing, we can't do anything
|
|
||||||
if (ramoptions == null || !ramoptions.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
containsItems = true;
|
|
||||||
foreach (var ramoption in ramoptions)
|
|
||||||
{
|
|
||||||
var item = new RamOption();
|
|
||||||
item.SetName(ramoption.Name);
|
|
||||||
item.SetFieldValue<string?>(Models.Metadata.RamOption.ContentKey, ramoption.Content);
|
|
||||||
item.SetFieldValue<bool?>(Models.Metadata.RamOption.DefaultKey, ramoption.Default.AsYesNo());
|
|
||||||
item.SetFieldValue<Source?>(DatItem.SourceKey, new Source { Index = indexId, Name = filename });
|
|
||||||
|
|
||||||
item.CopyMachineInformation(machine);
|
|
||||||
ParseAddHelper(item, statsOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using SabreTools.Core;
|
using SabreTools.Core;
|
||||||
|
using SabreTools.Core.Tools;
|
||||||
|
|
||||||
namespace SabreTools.DatItems.Formats
|
namespace SabreTools.DatItems.Formats
|
||||||
{
|
{
|
||||||
@@ -27,8 +28,22 @@ namespace SabreTools.DatItems.Formats
|
|||||||
|
|
||||||
public Display(Models.Metadata.Video item) : base()
|
public Display(Models.Metadata.Video item) : base()
|
||||||
{
|
{
|
||||||
// TODO: Determine what transformation is needed here
|
SetFieldValue<long?>("ASPECTX", NumberHelper.ConvertToInt64(item.ReadString(Models.Metadata.Video.AspectXKey)));
|
||||||
_internal = item;
|
SetFieldValue<long?>("ASPECTY", NumberHelper.ConvertToInt64(item.ReadString(Models.Metadata.Video.AspectYKey)));
|
||||||
|
SetFieldValue<DisplayType>(Models.Metadata.Display.DisplayTypeKey, item.ReadString(Models.Metadata.Video.ScreenKey)?.AsEnumValue<DisplayType>() ?? DisplayType.NULL);
|
||||||
|
SetFieldValue<long?>(Models.Metadata.Display.HeightKey, NumberHelper.ConvertToInt64(item.ReadString(Models.Metadata.Video.HeightKey)));
|
||||||
|
SetFieldValue<double?>(Models.Metadata.Display.RefreshKey, NumberHelper.ConvertToDouble(item.ReadString(Models.Metadata.Video.RefreshKey)));
|
||||||
|
SetFieldValue<long?>(Models.Metadata.Display.WidthKey, NumberHelper.ConvertToInt64(item.ReadString(Models.Metadata.Video.WidthKey)));
|
||||||
|
|
||||||
|
switch (item.ReadString(Models.Metadata.Video.OrientationKey))
|
||||||
|
{
|
||||||
|
case "horizontal":
|
||||||
|
SetFieldValue<long?>(Models.Metadata.Display.RotateKey, 0);
|
||||||
|
break;
|
||||||
|
case "vertical":
|
||||||
|
SetFieldValue<long?>(Models.Metadata.Display.RotateKey, 90);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -294,7 +294,7 @@ namespace SabreTools.Filtering
|
|||||||
{
|
{
|
||||||
// Update machine name
|
// Update machine name
|
||||||
if (!string.IsNullOrEmpty(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)) && mapping.ContainsKey(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)!))
|
if (!string.IsNullOrEmpty(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)) && mapping.ContainsKey(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)!))
|
||||||
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, value: mapping[item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)!]);
|
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, mapping[item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)!]);
|
||||||
|
|
||||||
// Update cloneof
|
// Update cloneof
|
||||||
if (!string.IsNullOrEmpty(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.CloneOfKey)) && mapping.ContainsKey(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.CloneOfKey)!))
|
if (!string.IsNullOrEmpty(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.CloneOfKey)) && mapping.ContainsKey(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetFieldValue<string?>(Models.Metadata.Machine.CloneOfKey)!))
|
||||||
|
|||||||
Reference in New Issue
Block a user