Files
SabreTools/SabreTools.DatFiles/Formats/ClrMamePro.Reader.cs

572 lines
28 KiB
C#
Raw Normal View History

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
{
/// <summary>
/// Represents parsing of a ClrMamePro DAT
/// </summary>
internal partial class ClrMamePro : DatFile
{
/// <inheritdoc/>
public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
try
{
// Deserialize the input file
2023-09-11 01:20:21 -04:00
var metadataFile = new Serialization.Files.ClrMamePro().Deserialize(filename, this.Quotes);
// Convert the header to the internal format
ConvertHeader(metadataFile?.ClrMamePro, keep);
// Convert the game data to the internal format
ConvertGames(metadataFile?.Game, filename, indexId, statsOnly);
}
catch (Exception ex) when (!throwOnError)
{
string message = $"'{filename}' - An error occurred during parsing";
logger.Error(ex, message);
}
}
#region Converters
/// <summary>
/// Convert header information
/// </summary>
/// <param name="cmp">Deserialized model to convert</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
private void ConvertHeader(Models.ClrMamePro.ClrMamePro? cmp, bool keep)
{
// If the header is missing, we can't do anything
if (cmp == null)
return;
Header.Name ??= cmp.Name;
Header.Description ??= cmp.Description;
Header.RootDir ??= cmp.RootDir;
Header.Category ??= cmp.Category;
Header.Version ??= cmp.Version;
Header.Date ??= cmp.Date;
Header.Author ??= cmp.Author;
Header.Homepage ??= cmp.Homepage;
Header.Url ??= cmp.Url;
Header.Comment ??= cmp.Comment;
Header.HeaderSkipper ??= cmp.Header;
Header.Type ??= cmp.Type;
if (Header.ForceMerging == MergingFlag.None)
2024-03-05 15:24:11 -05:00
Header.ForceMerging = cmp.ForceMerging?.AsEnumValue<MergingFlag>() ?? MergingFlag.None;
if (Header.ForcePacking == PackingFlag.None)
2024-03-05 15:24:11 -05:00
Header.ForcePacking = cmp.ForceZipping?.AsEnumValue<PackingFlag>() ?? PackingFlag.None;
if (Header.ForcePacking == PackingFlag.None)
2024-03-05 15:24:11 -05:00
Header.ForcePacking = cmp.ForcePacking?.AsEnumValue<PackingFlag>() ?? PackingFlag.None;
// Handle implied SuperDAT
if (cmp.Name?.Contains(" - SuperDAT") == true && keep)
Header.Type ??= "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>
2023-09-11 10:27:17 -04:00
private void ConvertGames(Models.ClrMamePro.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>
2023-09-11 10:27:17 -04:00
private void ConvertGame(Models.ClrMamePro.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
{
Name = game.Name,
Description = game.Description,
Year = game.Year,
Manufacturer = game.Manufacturer,
Category = game.Category,
CloneOf = game.CloneOf,
RomOf = game.RomOf,
SampleOf = game.SampleOf,
MachineType = (game is Models.ClrMamePro.Resource ? MachineType.Bios : MachineType.None),
};
// Check if there are any items
bool containsItems = false;
// Loop through each type of item
ConvertReleases(game.Release, machine, filename, indexId, statsOnly, ref containsItems);
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);
ConvertMedia(game.Media, machine, filename, indexId, statsOnly, ref containsItems);
ConvertArchives(game.Archive, machine, filename, indexId, statsOnly, ref containsItems);
ConvertChips(game.Chip, machine, filename, indexId, statsOnly, ref containsItems);
2023-08-10 15:02:40 -04:00
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);
ConvertDriver(game.Driver, machine, filename, indexId, statsOnly, ref containsItems);
// If we had no items, create a Blank placeholder
if (!containsItems)
{
var blank = new Blank
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
};
blank.CopyMachineInformation(machine);
ParseAddHelper(blank, statsOnly);
}
}
/// <summary>
/// Convert Release information
/// </summary>
/// <param name="releases">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 ConvertReleases(Models.ClrMamePro.Release[]? releases, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
{
// If the release array is missing, we can't do anything
if (releases == null || !releases.Any())
return;
containsItems = true;
foreach (var release in releases)
{
var item = new Release
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
};
2024-03-08 20:42:24 -05:00
item.SetName(release.Name);
2024-03-09 21:34:26 -05:00
item.SetFieldValue<string?>(Models.Metadata.Release.DateKey, release.Date);
item.SetFieldValue<bool?>(Models.Metadata.Release.DefaultKey, release.Default?.AsYesNo());
item.SetFieldValue<string?>(Models.Metadata.Release.LanguageKey, release.Language);
item.SetFieldValue<string?>(Models.Metadata.Release.RegionKey, release.Region);
item.CopyMachineInformation(machine);
ParseAddHelper(item, 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.ClrMamePro.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
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
};
2024-03-08 20:42:24 -05:00
item.SetName(biosset.Name);
2024-03-09 21:34:26 -05:00
item.SetFieldValue<bool?>(Models.Metadata.BiosSet.DefaultKey, biosset.Default?.AsYesNo());
item.SetFieldValue<string?>(Models.Metadata.BiosSet.DescriptionKey, biosset.Description);
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.ClrMamePro.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
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
};
2024-03-08 20:42:24 -05:00
item.SetName(rom.Name);
2024-03-09 21:34:26 -05:00
item.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, rom.CRC);
item.SetFieldValue<string?>(Models.Metadata.Rom.DateKey, rom.Date);
item.SetFieldValue<string?>(Models.Metadata.Rom.FlagsKey, rom.Flags);
item.SetFieldValue<string?>(Models.Metadata.Rom.HeaderKey, rom.Header);
item.SetFieldValue<bool?>(Models.Metadata.Rom.InvertedKey, rom.Inverted?.AsYesNo());
item.SetFieldValue<bool?>(Models.Metadata.Rom.MIAKey, rom.MIA?.AsYesNo());
item.SetFieldValue<string?>(Models.Metadata.Rom.MD5Key, rom.MD5);
item.SetFieldValue<string?>(Models.Metadata.Rom.MergeKey, rom.Merge);
item.SetFieldValue<string?>(Models.Metadata.Rom.OffsetKey, rom.Offs);
item.SetFieldValue<string?>(Models.Metadata.Rom.RegionKey, rom.Region);
item.SetFieldValue<string?>(Models.Metadata.Rom.SerialKey, rom.Serial);
item.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key, rom.SHA1);
item.SetFieldValue<string?>(Models.Metadata.Rom.SHA256Key, rom.SHA256);
item.SetFieldValue<string?>(Models.Metadata.Rom.SHA384Key, rom.SHA384);
item.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key, rom.SHA512);
item.SetFieldValue<long?>(Models.Metadata.Rom.SizeKey, NumberHelper.ConvertToInt64(rom.Size));
item.SetFieldValue<string?>(Models.Metadata.Rom.SpamSumKey, rom.SpamSum);
item.SetFieldValue<ItemStatus?>(Models.Metadata.Rom.StatusKey, rom.Status?.AsEnumValue<ItemStatus>() ?? ItemStatus.NULL);
item.SetFieldValue<string?>(Models.Metadata.Rom.xxHash364Key, rom.xxHash364);
item.SetFieldValue<string?>(Models.Metadata.Rom.xxHash3128Key, rom.xxHash3128);
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.ClrMamePro.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
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
};
2024-03-08 20:42:24 -05:00
item.SetName(disk.Name);
2024-03-09 21:34:26 -05:00
item.SetFieldValue<string?>(Models.Metadata.Disk.FlagsKey, disk.Flags);
item.SetFieldValue<string?>(Models.Metadata.Disk.MD5Key, disk.MD5);
item.SetFieldValue<string?>(Models.Metadata.Disk.MergeKey, disk.Merge);
item.SetFieldValue<string?>(Models.Metadata.Disk.SHA1Key, disk.SHA1);
item.SetFieldValue<ItemStatus>(Models.Metadata.Disk.StatusKey, disk.Status?.AsEnumValue<ItemStatus>() ?? ItemStatus.NULL);
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
}
}
/// <summary>
/// Convert Media information
/// </summary>
/// <param name="media">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 ConvertMedia(Models.ClrMamePro.Media[]? media, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
{
// If the media array is missing, we can't do anything
if (media == null || !media.Any())
return;
containsItems = true;
foreach (var medium in media)
{
var item = new Media
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
};
2024-03-08 20:42:24 -05:00
item.SetName(medium.Name);
2024-03-09 21:34:26 -05:00
item.SetFieldValue<string?>(Models.Metadata.Media.MD5Key, medium.MD5);
item.SetFieldValue<string?>(Models.Metadata.Media.SHA1Key, medium.SHA1);
item.SetFieldValue<string?>(Models.Metadata.Media.SHA256Key, medium.SHA256);
item.SetFieldValue<string?>(Models.Metadata.Media.SpamSumKey, medium.SpamSum);
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
}
}
/// <summary>
/// Convert Archive information
/// </summary>
/// <param name="archives">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 ConvertArchives(Models.ClrMamePro.Archive[]? archives, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
{
// If the archive array is missing, we can't do anything
if (archives == null || !archives.Any())
return;
containsItems = true;
foreach (var archive in archives)
{
var item = new Archive
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
};
2024-03-08 20:42:24 -05:00
item.SetName(archive.Name);
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.ClrMamePro.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
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
};
2024-03-08 20:42:24 -05:00
item.SetName(chip.Name);
2024-03-09 21:34:26 -05:00
item.SetFieldValue<ChipType>(Models.Metadata.Chip.ChipTypeKey, chip.Type?.AsEnumValue<ChipType>() ?? ChipType.NULL);
item.SetFieldValue<long?>(Models.Metadata.Chip.ClockKey, NumberHelper.ConvertToInt64(chip.Clock));
item.SetFieldValue<string?>(Models.Metadata.Chip.FlagsKey, chip.Flags);
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
}
}
/// <summary>
/// Convert Video information
/// </summary>
2023-08-10 15:02:40 -04:00
/// <param name="video">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>
2023-08-10 15:02:40 -04:00
private void ConvertVideos(Models.ClrMamePro.Video[]? videos, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
{
2023-08-10 15:02:40 -04:00
// If the video array is missing, we can't do anything
if (videos == null || !videos.Any())
return;
containsItems = true;
2023-08-10 15:02:40 -04:00
foreach (var video in videos)
{
2023-08-10 15:02:40 -04:00
var item = new Display
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
2023-08-10 15:02:40 -04:00
};
2024-03-09 21:34:26 -05:00
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.Y));
item.SetFieldValue<double?>(Models.Metadata.Display.RefreshKey, NumberHelper.ConvertToDouble(video.Freq));
item.SetFieldValue<long?>(Models.Metadata.Display.WidthKey, NumberHelper.ConvertToInt64(video.X));
2023-08-10 15:02:40 -04:00
switch (video.Orientation)
{
case "horizontal":
2024-03-09 21:34:26 -05:00
item.SetFieldValue<long?>(Models.Metadata.Display.RotateKey, 0);
2023-08-10 15:02:40 -04:00
break;
case "vertical":
2024-03-09 21:34:26 -05:00
item.SetFieldValue<long?>(Models.Metadata.Display.RotateKey, 90);
2023-08-10 15:02:40 -04:00
break;
}
2023-08-10 15:02:40 -04:00
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.ClrMamePro.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
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
};
2024-03-09 21:34:26 -05:00
item.SetFieldValue<long?>(Models.Metadata.Sound.ChannelsKey, NumberHelper.ConvertToInt64(sound.Channels));
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.ClrMamePro.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
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
};
2024-03-09 21:34:26 -05:00
item.SetFieldValue<long?>(Models.Metadata.Input.CoinsKey, NumberHelper.ConvertToInt64(input.Coins));
//item.SetFieldValue<string?>(Models.Metadata.Input.ControlKey, input.Control);
item.SetFieldValue<long?>(Models.Metadata.Input.PlayersKey, NumberHelper.ConvertToInt64(input.Players));
item.SetFieldValue<bool?>(Models.Metadata.Input.ServiceKey, input.Service?.AsYesNo());
item.SetFieldValue<bool?>(Models.Metadata.Input.TiltKey, input.Tilt?.AsYesNo());
var control = new Control();
control.SetFieldValue<long?>(Models.Metadata.Control.ButtonsKey, NumberHelper.ConvertToInt64(input.Buttons));
item.SetFieldValue<Control[]?>(Models.Metadata.Input.ControlKey, [control]);
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.ClrMamePro.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
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
};
2024-03-08 20:42:24 -05:00
item.SetName(dipswitch.Name);
2024-03-09 21:34:26 -05:00
var values = new List<DipValue>();
2024-02-28 19:19:50 -05:00
foreach (string entry in dipswitch.Entry ?? [])
{
2024-03-09 21:34:26 -05:00
var dipValue = new DipValue();
2024-03-08 20:42:24 -05:00
dipValue.SetName(dipswitch.Name);
2024-03-09 21:34:26 -05:00
dipValue.SetFieldValue<bool?>(Models.Metadata.DipValue.DefaultKey, entry == dipswitch.Default);
dipValue.SetFieldValue<string?>(Models.Metadata.DipValue.ValueKey, entry);
2024-03-08 20:42:24 -05:00
2024-03-09 21:34:26 -05:00
values.Add(dipValue);
}
2024-03-09 21:34:26 -05:00
item.SetFieldValue<DipValue[]?>(Models.Metadata.DipSwitch.DipValueKey, [.. values]);
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.ClrMamePro.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
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
};
2024-03-09 21:34:26 -05:00
item.SetFieldValue<string?>(Models.Metadata.Driver.BlitKey, driver.Blit);
item.SetFieldValue<SupportStatus>(Models.Metadata.Driver.ColorKey, driver.Color?.AsEnumValue<SupportStatus>() ?? SupportStatus.NULL);
item.SetFieldValue<long?>(Models.Metadata.Driver.PaletteSizeKey, NumberHelper.ConvertToInt64(driver.PaletteSize));
item.SetFieldValue<SupportStatus>(Models.Metadata.Driver.SoundKey, driver.Sound?.AsEnumValue<SupportStatus>() ?? SupportStatus.NULL);
item.SetFieldValue<SupportStatus>(Models.Metadata.Driver.StatusKey, driver.Status?.AsEnumValue<SupportStatus>() ?? SupportStatus.NULL);
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
}
#endregion
}
}