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

631 lines
29 KiB
C#
Raw Normal View History

2023-07-30 22:06:48 -04:00
using System;
2023-07-30 22:59:04 -04:00
using System.Linq;
2023-07-30 22:06:48 -04:00
using SabreTools.Core;
using SabreTools.Core.Tools;
using SabreTools.DatItems;
using SabreTools.DatItems.Formats;
namespace SabreTools.DatFiles.Formats
{
/// <summary>
/// Represents parsing a Logiqx-derived DAT
/// </summary>
internal partial class Logiqx : DatFile
{
/// <inheritdoc/>
public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
try
{
2023-07-30 22:59:04 -04:00
// Deserialize the input file
2023-09-11 01:20:21 -04:00
var metadataFile = new Serialization.Files.Logiqx().Deserialize(filename);
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
// Convert the header to the internal format
ConvertHeader(metadataFile, keep);
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
// Convert the game data to the internal format
ConvertGames(metadataFile?.Game, filename, indexId, statsOnly);
// Convert the dir data to the internal format
ConvertDirs(metadataFile?.Dir, filename, indexId, statsOnly);
2023-07-30 22:06:48 -04:00
}
catch (Exception ex) when (!throwOnError)
{
2023-07-30 22:59:04 -04:00
string message = $"'{filename}' - An error occurred during parsing";
logger.Error(ex, message);
2023-07-30 22:06:48 -04:00
}
2023-07-30 22:59:04 -04:00
}
#region Converters
/// <summary>
/// Convert header information
/// </summary>
/// <param name="datafile">Deserialized model to convert</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
private void ConvertHeader(Models.Logiqx.Datafile? datafile, bool keep)
{
// If the datafile is missing, we can't do anything
if (datafile == null)
return;
Header.Build ??= datafile.Build;
Header.Debug ??= datafile.Debug.AsYesNo();
// SchemaLocation is specifically skipped
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
ConvertHeader(datafile.Header, keep);
2023-07-30 22:06:48 -04:00
}
/// <summary>
2023-07-30 22:59:04 -04:00
/// Convert header information
2023-07-30 22:06:48 -04:00
/// </summary>
2023-07-30 22:59:04 -04:00
/// <param name="header">Deserialized model to convert</param>
2023-07-30 22:06:48 -04:00
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
2023-07-30 22:59:04 -04:00
private void ConvertHeader(Models.Logiqx.Header? header, bool keep)
2023-07-30 22:06:48 -04:00
{
2023-07-30 22:59:04 -04:00
// If the header is missing, we can't do anything
if (header == null)
return;
Header.NoIntroID ??= header.Id;
Header.Name ??= header.Name;
Header.Description ??= header.Description;
Header.RootDir ??= header.RootDir;
Header.Category ??= header.Category;
Header.Version ??= header.Version;
Header.Date ??= header.Date;
Header.Author ??= header.Author;
Header.Email ??= header.Email;
Header.Homepage ??= header.Homepage;
Header.Url ??= header.Url;
Header.Comment ??= header.Comment;
Header.Type ??= header.Type;
ConvertSubheader(header.ClrMamePro);
ConvertSubheader(header.RomCenter);
// Handle implied SuperDAT
if (header.Name?.Contains(" - SuperDAT") == true && keep)
2023-07-30 22:59:04 -04:00
Header.Type ??= "SuperDAT";
}
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
/// <summary>
/// Convert subheader information
/// </summary>
/// <param name="clrMamePro">Deserialized model to convert</param>
private void ConvertSubheader(Models.Logiqx.ClrMamePro? clrMamePro)
{
// If the subheader is missing, we can't do anything
if (clrMamePro == null)
2023-07-30 22:06:48 -04:00
return;
2023-07-30 22:59:04 -04:00
Header.HeaderSkipper ??= clrMamePro.Header;
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
if (Header.ForceMerging == MergingFlag.None)
2024-03-05 15:24:11 -05:00
Header.ForceMerging = clrMamePro.ForceMerging.AsEnumValue<MergingFlag>();
2023-07-30 22:59:04 -04:00
if (Header.ForceNodump == NodumpFlag.None)
2024-03-05 15:24:11 -05:00
Header.ForceNodump = clrMamePro.ForceNodump.AsEnumValue<NodumpFlag>();
2023-07-30 22:59:04 -04:00
if (Header.ForcePacking == PackingFlag.None)
2024-03-05 15:24:11 -05:00
Header.ForcePacking = clrMamePro.ForcePacking.AsEnumValue<PackingFlag>();
2023-07-30 22:59:04 -04:00
}
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
/// <summary>
/// Convert subheader information
/// </summary>
/// <param name="romCenter">Deserialized model to convert</param>
private void ConvertSubheader(Models.Logiqx.RomCenter? romCenter)
{
// If the subheader is missing, we can't do anything
if (romCenter == null)
return;
Header.System ??= romCenter.Plugin;
if (Header.RomMode == MergingFlag.None)
2024-03-05 15:24:11 -05:00
Header.RomMode = romCenter.RomMode.AsEnumValue<MergingFlag>();
2023-07-30 22:59:04 -04:00
if (Header.BiosMode == MergingFlag.None)
2024-03-05 15:24:11 -05:00
Header.BiosMode = romCenter.BiosMode.AsEnumValue<MergingFlag>();
2023-07-30 22:59:04 -04:00
if (Header.SampleMode == MergingFlag.None)
2024-03-05 15:24:11 -05:00
Header.SampleMode = romCenter.SampleMode.AsEnumValue<MergingFlag>();
2023-07-30 22:59:04 -04:00
Header.LockRomMode ??= romCenter.LockRomMode.AsYesNo();
Header.LockBiosMode ??= romCenter.LockBiosMode.AsYesNo();
Header.LockSampleMode ??= romCenter.LockSampleMode.AsYesNo();
}
/// <summary>
/// Convert dirs information
/// </summary>
/// <param name="dirs">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 ConvertDirs(Models.Logiqx.Dir[]? dirs, string filename, int indexId, bool statsOnly)
{
// If the dir array is missing, we can't do anything
if (dirs == null || !dirs.Any())
return;
// Loop through the dirs and add
foreach (var dir in dirs)
{
ConvertDir(dir, filename, indexId, statsOnly);
2023-07-30 22:06:48 -04:00
}
}
/// <summary>
2023-07-30 22:59:04 -04:00
/// Convert dir information
2023-07-30 22:06:48 -04:00
/// </summary>
2023-07-30 22:59:04 -04:00
/// <param name="dir">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>
2023-07-30 22:06:48 -04:00
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
2023-07-30 22:59:04 -04:00
private void ConvertDir(Models.Logiqx.Dir dir, string filename, int indexId, bool statsOnly)
{
// If the game array is missing, we can't do anything
if (dir.Game == null || !dir.Game.Any())
return;
// Loop through the games and add
foreach (var game in dir.Game)
{
ConvertGame(game, filename, indexId, statsOnly, dir.Name);
}
}
/// <summary>
/// Convert games information
/// </summary>
/// <param name="games">Array of deserialized models to convert</param>
2023-07-30 22:06:48 -04:00
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
2023-07-30 22:59:04 -04:00
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
private void ConvertGames(Models.Logiqx.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;
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
// Loop through the games and add
foreach (var game in games)
{
ConvertGame(game, filename, indexId, statsOnly);
}
}
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
/// <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.Logiqx.GameBase game, string filename, int indexId, bool statsOnly, string? dirname = null)
2023-07-30 22:06:48 -04:00
{
2023-07-30 22:59:04 -04:00
// If the game is missing, we can't do anything
if (game == null)
2023-07-30 22:06:48 -04:00
return;
2023-07-30 22:59:04 -04:00
// Create the machine for copying information
var machine = new Machine
{
Name = game.Name,
SourceFile = game.SourceFile,
CloneOf = game.CloneOf,
RomOf = game.RomOf,
SampleOf = game.SampleOf,
Board = game.Board,
RebuildTo = game.RebuildTo,
NoIntroId = game.Id,
NoIntroCloneOfId = game.CloneOfId,
2024-03-05 15:24:11 -05:00
Runnable = game.Runnable.AsEnumValue<Runnable>(),
2023-07-30 22:59:04 -04:00
Description = game.Description,
Year = game.Year,
Manufacturer = game.Manufacturer,
Publisher = game.Publisher,
};
2023-07-30 22:06:48 -04:00
2024-02-28 22:54:56 -05:00
if (!string.IsNullOrEmpty(dirname))
2023-07-30 22:59:04 -04:00
machine.Name = $"{dirname}/{machine.Name}";
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
if (game.IsBios.AsYesNo() == true)
machine.MachineType |= MachineType.Bios;
if (game.IsDevice.AsYesNo() == true)
machine.MachineType |= MachineType.Device;
if (game.IsMechanical.AsYesNo() == true)
machine.MachineType |= MachineType.Mechanical;
2023-07-30 22:06:48 -04:00
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
if (game.Comment != null && game.Comment.Any())
machine.Comment = string.Join(";", game.Comment);
if (game.Category != null && game.Category.Any())
machine.Category = string.Join(";", game.Category);
#else
if (game.Comment != null && game.Comment.Any())
machine.Comment = string.Join(';', game.Comment);
if (game.Category != null && game.Category.Any())
machine.Category = string.Join(';', game.Category);
2024-02-28 22:54:56 -05:00
#endif
2023-07-30 22:59:04 -04:00
if (game.Trurip != null)
2023-07-30 22:06:48 -04:00
{
2023-07-30 22:59:04 -04:00
var trurip = game.Trurip;
machine.TitleID = trurip.TitleID;
machine.Publisher = trurip.Publisher;
machine.Developer = trurip.Developer;
machine.Year = trurip.Year;
machine.Genre = trurip.Genre;
machine.Subgenre = trurip.Subgenre;
machine.Ratings = trurip.Ratings;
machine.Score = trurip.Score;
machine.Players = trurip.Players;
machine.Enabled = trurip.Enabled;
machine.Crc = trurip.CRC.AsYesNo();
machine.SourceFile = trurip.Source;
machine.CloneOf = trurip.CloneOf;
machine.RelatedTo = trurip.RelatedTo;
}
// Check if there are any items
bool containsItems = false;
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
// 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);
ConvertDeviceRefs(game.DeviceRef, machine, filename, indexId, statsOnly, ref containsItems);
ConvertSamples(game.Sample, machine, filename, indexId, statsOnly, ref containsItems);
2023-07-30 22:59:04 -04:00
ConvertArchives(game.Archive, machine, filename, indexId, statsOnly, ref containsItems);
2023-08-10 11:35:32 -04:00
ConvertDriver(game.Driver, machine, filename, indexId, statsOnly, ref containsItems);
2023-07-30 22:59:04 -04:00
ConvertSoftwareLists(game.SoftwareList, machine, filename, indexId, statsOnly, ref containsItems);
// If we had no items, create a Blank placeholder
if (!containsItems)
2023-07-30 22:06:48 -04:00
{
2023-07-30 22:59:04 -04:00
var blank = new Blank
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
2023-07-30 22:59:04 -04:00
};
blank.CopyMachineInformation(machine);
ParseAddHelper(blank, statsOnly);
2023-07-30 22:06:48 -04:00
}
2023-07-30 22:59:04 -04:00
}
/// <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.Logiqx.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;
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
containsItems = true;
foreach (var release in releases)
2023-07-30 22:06:48 -04:00
{
2023-07-30 22:59:04 -04:00
var item = new Release
2023-07-30 22:06:48 -04:00
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
2023-07-30 22:59:04 -04:00
};
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);
2023-07-30 22:59:04 -04:00
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.Logiqx.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
2023-07-30 22:06:48 -04:00
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
2023-07-30 22:59:04 -04:00
};
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);
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
}
}
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
/// <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.Logiqx.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;
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
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 },
2023-07-30 22:59:04 -04:00
};
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.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.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);
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
}
}
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
/// <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.Logiqx.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;
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
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 },
2023-07-30 22:59:04 -04:00
};
2024-03-08 20:42:24 -05:00
item.SetName(disk.Name);
2024-03-09 21:34:26 -05:00
item.SetFieldValue<ItemStatus>(Models.Metadata.Disk.StatusKey, disk.Status?.AsEnumValue<ItemStatus>() ?? ItemStatus.NULL);
item.SetFieldValue<string?>(Models.Metadata.Disk.MD5Key, disk.MD5);
item.SetFieldValue<string?>(Models.Metadata.Disk.MergeKey, disk.Merge);
item.SetFieldValue<string?>(Models.Metadata.Disk.RegionKey, disk.Region);
item.SetFieldValue<string?>(Models.Metadata.Disk.SHA1Key, disk.SHA1);
2023-07-30 22:59:04 -04:00
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
2023-07-30 22:06:48 -04:00
}
2023-07-30 22:59:04 -04:00
}
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
/// <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.Logiqx.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)
2023-07-30 22:06:48 -04:00
{
2023-07-30 22:59:04 -04:00
var item = new Media
2023-07-30 22:06:48 -04:00
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
2023-07-30 22:06:48 -04:00
};
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);
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
}
}
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
/// <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.Logiqx.DeviceRef[]? devicerefs, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
{
// If the devicerefs array is missing, we can't do anything
if (devicerefs == null || !devicerefs.Any())
return;
containsItems = true;
foreach (var deviceref in devicerefs)
{
var item = new DeviceReference
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
2023-07-30 22:59:04 -04:00
};
2024-03-08 20:42:24 -05:00
item.SetName(deviceref.Name);
2023-07-30 22:59:04 -04:00
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
2023-07-30 22:06:48 -04:00
}
}
/// <summary>
2023-07-30 22:59:04 -04:00
/// Convert DeviceRef information
2023-07-30 22:06:48 -04:00
/// </summary>
2023-07-30 22:59:04 -04:00
/// <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.Logiqx.Sample[]? samples, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
{
// If the samples 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
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
2023-07-30 22:59:04 -04:00
};
2024-03-08 20:42:24 -05:00
item.SetName(sample.Name);
2023-07-30 22:59:04 -04:00
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.Logiqx.Archive[]? archives, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
2023-07-30 22:06:48 -04:00
{
2023-07-30 22:59:04 -04:00
// If the archive array is missing, we can't do anything
if (archives == null || !archives.Any())
2023-07-30 22:06:48 -04:00
return;
2023-07-30 22:59:04 -04:00
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 },
2023-07-30 22:59:04 -04:00
};
2024-03-08 20:42:24 -05:00
item.SetName(archive.Name);
2023-07-30 22:59:04 -04:00
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
}
}
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
/// <summary>
/// Convert Driver information
/// </summary>
2023-08-10 11:35:32 -04:00
/// <param name="driver">Deserialized model to convert</param>
2023-07-30 22:59:04 -04:00
/// <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 11:35:32 -04:00
private void ConvertDriver(Models.Logiqx.Driver? driver, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
2023-07-30 22:59:04 -04:00
{
2023-08-10 11:35:32 -04:00
// If the driver is missing, we can't do anything
if (driver == null)
2023-07-30 22:59:04 -04:00
return;
containsItems = true;
2023-08-10 11:35:32 -04:00
var item = new Driver
2023-07-30 22:06:48 -04:00
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
2023-08-10 11:35:32 -04:00
};
2024-03-09 21:34:26 -05:00
item.SetFieldValue<SupportStatus>(Models.Metadata.Driver.CocktailKey, driver.Cocktail?.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<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.StatusKey, driver.Status?.AsEnumValue<SupportStatus>() ?? SupportStatus.NULL);
item.SetFieldValue<bool?>(Models.Metadata.Driver.UnofficialKey, driver.Unofficial.AsYesNo());
2023-07-30 22:59:04 -04:00
2023-08-10 11:35:32 -04:00
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
2023-07-30 22:59:04 -04:00
}
/// <summary>
2023-07-30 22:59:04 -04:00
/// 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.Logiqx.SoftwareList[]? softwarelists, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
{
// If the softwarelists array is missing, we can't do anything
if (softwarelists == null || !softwarelists.Any())
return;
2023-07-30 22:06:48 -04:00
2023-07-30 22:59:04 -04:00
containsItems = true;
foreach (var softwarelist in softwarelists)
{
var item = new DatItems.Formats.SoftwareList
2023-07-30 22:06:48 -04:00
{
2024-03-08 21:12:13 -05:00
Source = new Source { Index = indexId, Name = filename },
2023-07-30 22:59:04 -04:00
};
2024-03-08 20:42:24 -05:00
item.SetName(softwarelist.Name);
2024-03-09 21:34:26 -05:00
item.SetFieldValue<string?>(Models.Metadata.SoftwareList.FilterKey, softwarelist.Filter);
item.SetFieldValue<SoftwareListStatus>(Models.Metadata.SoftwareList.StatusKey, softwarelist.Status.AsEnumValue<SoftwareListStatus>());
item.SetFieldValue<string?>(Models.Metadata.SoftwareList.TagKey, softwarelist.Tag);
2023-07-30 22:59:04 -04:00
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
2023-07-30 22:06:48 -04:00
}
}
2023-07-30 22:59:04 -04:00
#endregion
2023-07-30 22:06:48 -04:00
}
}