2023-07-30 22:06:48 -04:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2023-07-31 12:51:41 -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 and writing of a Logiqx-derived DAT
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal partial class Logiqx : DatFile
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
protected override ItemType[] GetSupportedTypes()
|
|
|
|
|
{
|
2024-02-28 19:19:50 -05:00
|
|
|
return
|
|
|
|
|
[
|
2023-07-30 22:06:48 -04:00
|
|
|
ItemType.Archive,
|
|
|
|
|
ItemType.BiosSet,
|
|
|
|
|
ItemType.Disk,
|
|
|
|
|
ItemType.Media,
|
|
|
|
|
ItemType.Release,
|
|
|
|
|
ItemType.Rom,
|
|
|
|
|
ItemType.Sample,
|
2024-02-28 19:19:50 -05:00
|
|
|
];
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2023-08-10 23:22:14 -04:00
|
|
|
protected override List<DatItemField>? GetMissingRequiredFields(DatItem datItem)
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
var missingFields = new List<DatItemField>();
|
2023-07-31 11:05:22 -04:00
|
|
|
switch (datItem)
|
|
|
|
|
{
|
|
|
|
|
case Release release:
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(release.Name))
|
2023-07-31 11:05:22 -04:00
|
|
|
missingFields.Add(DatItemField.Name);
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(release.Region))
|
2023-07-31 11:05:22 -04:00
|
|
|
missingFields.Add(DatItemField.Region);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BiosSet biosset:
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(biosset.Name))
|
2023-07-31 11:05:22 -04:00
|
|
|
missingFields.Add(DatItemField.Name);
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(biosset.Description))
|
2023-07-31 11:05:22 -04:00
|
|
|
missingFields.Add(DatItemField.Description);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Rom rom:
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(rom.Name))
|
2023-07-31 11:05:22 -04:00
|
|
|
missingFields.Add(DatItemField.Name);
|
|
|
|
|
if (rom.Size == null || rom.Size < 0)
|
|
|
|
|
missingFields.Add(DatItemField.Size);
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(rom.CRC)
|
|
|
|
|
&& string.IsNullOrEmpty(rom.MD5)
|
|
|
|
|
&& string.IsNullOrEmpty(rom.SHA1)
|
|
|
|
|
&& string.IsNullOrEmpty(rom.SHA256)
|
|
|
|
|
&& string.IsNullOrEmpty(rom.SHA384)
|
|
|
|
|
&& string.IsNullOrEmpty(rom.SHA512)
|
|
|
|
|
&& string.IsNullOrEmpty(rom.SpamSum))
|
2023-07-31 11:05:22 -04:00
|
|
|
{
|
|
|
|
|
missingFields.Add(DatItemField.SHA1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Disk disk:
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(disk.Name))
|
2023-07-31 11:05:22 -04:00
|
|
|
missingFields.Add(DatItemField.Name);
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(disk.MD5)
|
|
|
|
|
&& string.IsNullOrEmpty(disk.SHA1))
|
2023-07-31 11:05:22 -04:00
|
|
|
{
|
|
|
|
|
missingFields.Add(DatItemField.SHA1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Media media:
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(media.Name))
|
2023-07-31 11:05:22 -04:00
|
|
|
missingFields.Add(DatItemField.Name);
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(media.MD5)
|
|
|
|
|
&& string.IsNullOrEmpty(media.SHA1)
|
|
|
|
|
&& string.IsNullOrEmpty(media.SHA256)
|
|
|
|
|
&& string.IsNullOrEmpty(media.SpamSum))
|
2023-07-31 11:05:22 -04:00
|
|
|
{
|
|
|
|
|
missingFields.Add(DatItemField.SHA1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DeviceReference deviceref:
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(deviceref.Name))
|
2023-07-31 11:05:22 -04:00
|
|
|
missingFields.Add(DatItemField.Name);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Sample sample:
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(sample.Name))
|
2023-07-31 11:05:22 -04:00
|
|
|
missingFields.Add(DatItemField.Name);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Archive archive:
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(archive.Name))
|
2023-07-31 11:05:22 -04:00
|
|
|
missingFields.Add(DatItemField.Name);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Driver driver:
|
|
|
|
|
if (!driver.StatusSpecified)
|
|
|
|
|
missingFields.Add(DatItemField.SupportStatus);
|
|
|
|
|
if (!driver.EmulationSpecified)
|
|
|
|
|
missingFields.Add(DatItemField.EmulationStatus);
|
|
|
|
|
if (!driver.CocktailSpecified)
|
|
|
|
|
missingFields.Add(DatItemField.CocktailStatus);
|
|
|
|
|
if (!driver.SaveStateSpecified)
|
|
|
|
|
missingFields.Add(DatItemField.SaveStateStatus);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DatItems.Formats.SoftwareList softwarelist:
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(softwarelist.Tag))
|
2023-07-31 11:05:22 -04:00
|
|
|
missingFields.Add(DatItemField.Tag);
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(softwarelist.Name))
|
2023-07-31 11:05:22 -04:00
|
|
|
missingFields.Add(DatItemField.Name);
|
|
|
|
|
if (!softwarelist.StatusSpecified)
|
|
|
|
|
missingFields.Add(DatItemField.SoftwareListStatus);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return missingFields;
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
logger.User($"Writing to '{outfile}'...");
|
|
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
var datafile = CreateDatafile(ignoreblanks);
|
|
|
|
|
|
|
|
|
|
// Only write the doctype if we don't have No-Intro data
|
|
|
|
|
bool success;
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(Header.NoIntroID))
|
2023-09-11 01:20:21 -04:00
|
|
|
success = new Serialization.Files.Logiqx().SerializeToFileWithDocType(datafile, outfile);
|
2023-07-31 12:51:41 -04:00
|
|
|
else
|
2023-09-11 01:20:21 -04:00
|
|
|
success = new Serialization.Files.Logiqx().Serialize(datafile, outfile);
|
2023-07-31 12:51:41 -04:00
|
|
|
|
|
|
|
|
if (!success)
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
logger.Warning($"File '{outfile}' could not be written! See the log for more details.");
|
2023-07-30 22:06:48 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
2023-07-31 12:51:41 -04:00
|
|
|
}
|
|
|
|
|
catch (Exception ex) when (!throwOnError)
|
|
|
|
|
{
|
|
|
|
|
logger.Error(ex);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
logger.User($"'{outfile}' written!{Environment.NewLine}");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
#region Converters
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Create a Datafile from the current internal information
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise</param>
|
|
|
|
|
private Models.Logiqx.Datafile CreateDatafile(bool ignoreblanks)
|
|
|
|
|
{
|
|
|
|
|
var datafile = new Models.Logiqx.Datafile
|
|
|
|
|
{
|
|
|
|
|
Build = Header.Build,
|
|
|
|
|
Debug = Header.Debug.FromYesNo(),
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
Header = CreateHeader(),
|
|
|
|
|
Game = CreateGames(ignoreblanks)
|
|
|
|
|
};
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
if (!string.IsNullOrEmpty(Header.NoIntroID))
|
|
|
|
|
datafile.SchemaLocation = "https://datomatic.no-intro.org/stuff https://datomatic.no-intro.org/stuff/schema_nointro_datfile_v3.xsd";
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
return datafile;
|
|
|
|
|
}
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Create a Header from the current internal information
|
|
|
|
|
/// <summary>
|
|
|
|
|
private Models.Logiqx.Header? CreateHeader()
|
|
|
|
|
{
|
|
|
|
|
// If we don't have a header, we can't do anything
|
|
|
|
|
if (this.Header == null)
|
|
|
|
|
return null;
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
var header = new Models.Logiqx.Header
|
|
|
|
|
{
|
|
|
|
|
Id = Header.NoIntroID,
|
|
|
|
|
Name = Header.Name,
|
|
|
|
|
Description = Header.Description,
|
|
|
|
|
RootDir = Header.RootDir,
|
|
|
|
|
Category = Header.Category,
|
|
|
|
|
Version = Header.Version,
|
|
|
|
|
Date = Header.Date,
|
|
|
|
|
Author = Header.Author,
|
|
|
|
|
Email = Header.Email,
|
|
|
|
|
Homepage = Header.Homepage,
|
|
|
|
|
Url = Header.Url,
|
|
|
|
|
Comment = Header.Comment,
|
|
|
|
|
Type = Header.Type,
|
|
|
|
|
|
|
|
|
|
ClrMamePro = CreateClrMamePro(),
|
|
|
|
|
RomCenter = CreateRomCenter(),
|
|
|
|
|
};
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
return header;
|
|
|
|
|
}
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Create a ClrMamePro from the current internal information
|
|
|
|
|
/// <summary>
|
|
|
|
|
private Models.Logiqx.ClrMamePro? CreateClrMamePro()
|
|
|
|
|
{
|
|
|
|
|
// If we don't have subheader values, we can't do anything
|
|
|
|
|
if (!Header.ForceMergingSpecified
|
|
|
|
|
&& !Header.ForceNodumpSpecified
|
|
|
|
|
&& !Header.ForcePackingSpecified
|
2024-02-28 22:54:56 -05:00
|
|
|
&& string.IsNullOrEmpty(Header.HeaderSkipper))
|
2023-07-31 12:51:41 -04:00
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
var subheader = new Models.Logiqx.ClrMamePro
|
|
|
|
|
{
|
|
|
|
|
Header = Header.HeaderSkipper,
|
|
|
|
|
};
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
if (Header.ForceMergingSpecified)
|
2024-03-05 15:24:11 -05:00
|
|
|
subheader.ForceMerging = Header.ForceMerging.AsStringValue<MergingFlag>(useSecond: false);
|
2023-07-31 12:51:41 -04:00
|
|
|
if (Header.ForceNodumpSpecified)
|
2024-03-05 15:24:11 -05:00
|
|
|
subheader.ForceNodump = Header.ForceNodump.AsStringValue<NodumpFlag>();
|
2023-07-31 12:51:41 -04:00
|
|
|
if (Header.ForcePackingSpecified)
|
2024-03-05 15:24:11 -05:00
|
|
|
subheader.ForcePacking = Header.ForcePacking.AsStringValue<PackingFlag>(useSecond: false);
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
return subheader;
|
|
|
|
|
}
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Create a RomCenter from the current internal information
|
|
|
|
|
/// <summary>
|
|
|
|
|
private Models.Logiqx.RomCenter? CreateRomCenter()
|
|
|
|
|
{
|
|
|
|
|
// If we don't have subheader values, we can't do anything
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(Header.System)
|
2023-07-31 12:51:41 -04:00
|
|
|
&& !Header.RomModeSpecified
|
|
|
|
|
&& !Header.BiosModeSpecified
|
|
|
|
|
&& !Header.SampleModeSpecified
|
|
|
|
|
&& !Header.LockRomModeSpecified
|
|
|
|
|
&& !Header.LockBiosModeSpecified
|
|
|
|
|
&& !Header.LockSampleModeSpecified)
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
return null;
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
|
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
var subheader = new Models.Logiqx.RomCenter
|
|
|
|
|
{
|
|
|
|
|
Plugin = Header.System,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (Header.RomModeSpecified)
|
2024-03-05 15:24:11 -05:00
|
|
|
subheader.RomMode = Header.RomMode.AsStringValue<MergingFlag>(useSecond: true);
|
2023-07-31 12:51:41 -04:00
|
|
|
if (Header.BiosModeSpecified)
|
2024-03-05 15:24:11 -05:00
|
|
|
subheader.BiosMode = Header.BiosMode.AsStringValue<MergingFlag>(useSecond: true);
|
2023-07-31 12:51:41 -04:00
|
|
|
if (Header.SampleModeSpecified)
|
2024-03-05 15:24:11 -05:00
|
|
|
subheader.SampleMode = Header.SampleMode.AsStringValue<MergingFlag>(useSecond: true);
|
2023-07-31 12:51:41 -04:00
|
|
|
|
|
|
|
|
if (Header.LockRomModeSpecified)
|
|
|
|
|
subheader.LockRomMode = Header.LockRomMode.FromYesNo();
|
|
|
|
|
if (Header.LockBiosModeSpecified)
|
|
|
|
|
subheader.LockBiosMode = Header.LockBiosMode.FromYesNo();
|
|
|
|
|
if (Header.LockSampleModeSpecified)
|
|
|
|
|
subheader.LockSampleMode = Header.LockSampleMode.FromYesNo();
|
|
|
|
|
|
|
|
|
|
return subheader;
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-07-31 12:51:41 -04:00
|
|
|
/// Create an array of GameBase from the current internal information
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise</param>
|
|
|
|
|
private Models.Logiqx.GameBase[]? CreateGames(bool ignoreblanks)
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
// If we don't have items, we can't do anything
|
|
|
|
|
if (this.Items == null || !this.Items.Any())
|
|
|
|
|
return null;
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
// Create a list of hold the games
|
|
|
|
|
var games = new List<Models.Logiqx.GameBase>();
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
// Loop through the sorted items and create games for them
|
|
|
|
|
foreach (string key in Items.SortedKeys)
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
var items = Items.FilteredItems(key);
|
|
|
|
|
if (items == null || !items.Any())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the first item for game information
|
|
|
|
|
var machine = items[0].Machine;
|
2023-08-14 13:17:51 -04:00
|
|
|
var game = CreateGame(machine!);
|
2023-07-31 12:51:41 -04:00
|
|
|
|
|
|
|
|
// Create holders for all item types
|
|
|
|
|
var releases = new List<Models.Logiqx.Release>();
|
|
|
|
|
var biossets = new List<Models.Logiqx.BiosSet>();
|
|
|
|
|
var roms = new List<Models.Logiqx.Rom>();
|
|
|
|
|
var disks = new List<Models.Logiqx.Disk>();
|
|
|
|
|
var medias = new List<Models.Logiqx.Media>();
|
|
|
|
|
var samples = new List<Models.Logiqx.Sample>();
|
|
|
|
|
var archives = new List<Models.Logiqx.Archive>();
|
|
|
|
|
var devicerefs = new List<Models.Logiqx.DeviceRef>();
|
|
|
|
|
var softwarelists = new List<Models.Logiqx.SoftwareList>();
|
|
|
|
|
|
|
|
|
|
// Loop through and convert the items to respective lists
|
|
|
|
|
for (int index = 0; index < items.Count; index++)
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
// Get the item
|
|
|
|
|
var item = items[index];
|
|
|
|
|
|
|
|
|
|
// Check for a "null" item
|
|
|
|
|
item = ProcessNullifiedItem(item);
|
|
|
|
|
|
|
|
|
|
// Skip if we're ignoring the item
|
|
|
|
|
if (ShouldIgnore(item, ignoreblanks))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
switch (item)
|
|
|
|
|
{
|
|
|
|
|
case Release release:
|
|
|
|
|
releases.Add(CreateRelease(release));
|
|
|
|
|
break;
|
|
|
|
|
case BiosSet biosset:
|
|
|
|
|
biossets.Add(CreateBiosSet(biosset));
|
|
|
|
|
break;
|
|
|
|
|
case Rom rom:
|
|
|
|
|
roms.Add(CreateRom(rom));
|
|
|
|
|
break;
|
|
|
|
|
case Disk disk:
|
|
|
|
|
disks.Add(CreateDisk(disk));
|
|
|
|
|
break;
|
|
|
|
|
case Media media:
|
|
|
|
|
medias.Add(CreateMedia(media));
|
|
|
|
|
break;
|
|
|
|
|
case Sample sample:
|
|
|
|
|
samples.Add(CreateSample(sample));
|
|
|
|
|
break;
|
|
|
|
|
case Archive archive:
|
|
|
|
|
archives.Add(CreateArchive(archive));
|
|
|
|
|
break;
|
|
|
|
|
case DeviceReference deviceref:
|
|
|
|
|
devicerefs.Add(CreateDeviceRef(deviceref));
|
|
|
|
|
break;
|
|
|
|
|
case Driver driver:
|
2023-08-10 11:35:32 -04:00
|
|
|
game.Driver = CreateDriver(driver);
|
2023-07-31 12:51:41 -04:00
|
|
|
break;
|
|
|
|
|
case DatItems.Formats.SoftwareList softwarelist:
|
|
|
|
|
softwarelists.Add(CreateSoftwareList(softwarelist));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
2023-07-31 12:51:41 -04:00
|
|
|
|
|
|
|
|
// Assign the values to the game
|
2024-02-28 19:19:50 -05:00
|
|
|
game.Release = [.. releases];
|
|
|
|
|
game.BiosSet = [.. biossets];
|
|
|
|
|
game.Rom = [.. roms];
|
|
|
|
|
game.Disk = [.. disks];
|
|
|
|
|
game.Media = [.. medias];
|
|
|
|
|
game.Sample = [.. samples];
|
|
|
|
|
game.Archive = [.. archives];
|
|
|
|
|
game.DeviceRef = [.. devicerefs];
|
|
|
|
|
game.SoftwareList = [.. softwarelists];
|
2023-07-31 12:51:41 -04:00
|
|
|
|
|
|
|
|
// Add the game to the list
|
|
|
|
|
games.Add(game);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 19:19:50 -05:00
|
|
|
return [.. games];
|
2023-07-31 12:51:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-08-01 01:49:34 -04:00
|
|
|
/// Create a GameBase from the current internal information
|
2023-07-31 12:51:41 -04:00
|
|
|
/// <summary>
|
2023-08-10 23:22:14 -04:00
|
|
|
private Models.Logiqx.GameBase CreateGame(Machine machine)
|
2023-07-31 12:51:41 -04:00
|
|
|
{
|
|
|
|
|
Models.Logiqx.GameBase game = _deprecated ? new Models.Logiqx.Game() : new Models.Logiqx.Machine();
|
|
|
|
|
|
|
|
|
|
game.Name = machine.Name;
|
|
|
|
|
game.SourceFile = machine.SourceFile;
|
2024-02-28 22:54:56 -05:00
|
|
|
#if NETFRAMEWORK
|
|
|
|
|
if ((machine.MachineType & MachineType.Bios) != 0)
|
|
|
|
|
game.IsBios = "yes";
|
|
|
|
|
if ((machine.MachineType & MachineType.Device) != 0)
|
|
|
|
|
game.IsDevice = "yes";
|
|
|
|
|
if ((machine.MachineType & MachineType.Mechanical) != 0)
|
|
|
|
|
game.IsMechanical = "yes";
|
|
|
|
|
#else
|
2023-07-31 12:51:41 -04:00
|
|
|
if (machine.MachineType.HasFlag(MachineType.Bios))
|
|
|
|
|
game.IsBios = "yes";
|
|
|
|
|
if (machine.MachineType.HasFlag(MachineType.Device))
|
|
|
|
|
game.IsDevice = "yes";
|
|
|
|
|
if (machine.MachineType.HasFlag(MachineType.Mechanical))
|
|
|
|
|
game.IsMechanical = "yes";
|
2024-02-28 22:54:56 -05:00
|
|
|
#endif
|
2023-07-31 12:51:41 -04:00
|
|
|
game.CloneOf = machine.CloneOf;
|
|
|
|
|
game.RomOf = machine.RomOf;
|
|
|
|
|
game.SampleOf = machine.SampleOf;
|
|
|
|
|
game.Board = machine.Board;
|
|
|
|
|
game.RebuildTo = machine.RebuildTo;
|
|
|
|
|
game.Id = machine.NoIntroId;
|
|
|
|
|
game.CloneOfId = machine.NoIntroCloneOfId;
|
2024-03-05 15:24:11 -05:00
|
|
|
game.Runnable = machine.Runnable.AsStringValue<Runnable>();
|
2023-07-31 12:51:41 -04:00
|
|
|
if (machine.Comment != null)
|
|
|
|
|
{
|
|
|
|
|
if (machine.Comment.Contains(';'))
|
|
|
|
|
game.Comment = machine.Comment.Split(';');
|
|
|
|
|
else
|
2024-02-28 19:19:50 -05:00
|
|
|
game.Comment = [machine.Comment];
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
2023-07-31 12:51:41 -04:00
|
|
|
game.Description = machine.Description;
|
|
|
|
|
game.Year = machine.Year;
|
|
|
|
|
game.Manufacturer = machine.Manufacturer;
|
|
|
|
|
game.Publisher = machine.Publisher;
|
|
|
|
|
if (machine.Category != null)
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
if (machine.Category.Contains(';'))
|
|
|
|
|
game.Category = machine.Category.Split(';');
|
|
|
|
|
else
|
2024-02-28 19:19:50 -05:00
|
|
|
game.Category = [machine.Category];
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
2023-07-31 12:51:41 -04:00
|
|
|
game.Trurip = CreateTrurip(machine);
|
|
|
|
|
|
|
|
|
|
return game;
|
|
|
|
|
}
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Create a Trurip from the current internal information
|
|
|
|
|
/// <summary>
|
|
|
|
|
private static Models.Logiqx.Trurip? CreateTrurip(Machine machine)
|
|
|
|
|
{
|
|
|
|
|
// If we don't have subheader values, we can't do anything
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(machine.TitleID)
|
|
|
|
|
&& string.IsNullOrEmpty(machine.Developer)
|
|
|
|
|
&& string.IsNullOrEmpty(machine.Genre)
|
|
|
|
|
&& string.IsNullOrEmpty(machine.Subgenre)
|
|
|
|
|
&& string.IsNullOrEmpty(machine.Ratings)
|
|
|
|
|
&& string.IsNullOrEmpty(machine.Score)
|
|
|
|
|
&& string.IsNullOrEmpty(machine.Enabled)
|
2023-07-31 12:51:41 -04:00
|
|
|
&& !machine.CrcSpecified
|
2024-02-28 22:54:56 -05:00
|
|
|
&& string.IsNullOrEmpty(machine.RelatedTo))
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
return null;
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
|
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
var trurip = new Models.Logiqx.Trurip
|
|
|
|
|
{
|
|
|
|
|
TitleID = machine.TitleID,
|
|
|
|
|
Publisher = machine.Publisher,
|
|
|
|
|
Developer = machine.Developer,
|
|
|
|
|
Year = machine.Year,
|
|
|
|
|
Genre = machine.Genre,
|
|
|
|
|
Subgenre = machine.Subgenre,
|
|
|
|
|
Ratings = machine.Ratings,
|
|
|
|
|
Score = machine.Score,
|
|
|
|
|
Players = machine.Players,
|
|
|
|
|
Enabled = machine.Enabled,
|
|
|
|
|
CRC = machine.Crc.FromYesNo(),
|
|
|
|
|
Source = machine.SourceFile,
|
|
|
|
|
CloneOf = machine.CloneOf,
|
|
|
|
|
RelatedTo = machine.RelatedTo,
|
|
|
|
|
};
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
return trurip;
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-07-31 12:51:41 -04:00
|
|
|
/// Create a Release from the current Release DatItem
|
|
|
|
|
/// <summary>
|
|
|
|
|
private static Models.Logiqx.Release CreateRelease(Release item)
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
var release = new Models.Logiqx.Release
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
Name = item.Name,
|
|
|
|
|
Region = item.Region,
|
|
|
|
|
Language = item.Language,
|
|
|
|
|
Date = item.Date,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (item.DefaultSpecified)
|
|
|
|
|
release.Default = item.Default.FromYesNo();
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
return release;
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-07-31 12:51:41 -04:00
|
|
|
/// Create a BiosSet from the current BiosSet DatItem
|
|
|
|
|
/// <summary>
|
|
|
|
|
private static Models.Logiqx.BiosSet CreateBiosSet(BiosSet item)
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
var biosset = new Models.Logiqx.BiosSet
|
|
|
|
|
{
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
Description = item.Description,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (item.DefaultSpecified)
|
|
|
|
|
biosset.Default = item.Default.FromYesNo();
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
return biosset;
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-07-31 12:51:41 -04:00
|
|
|
/// Create a Rom from the current Rom DatItem
|
|
|
|
|
/// <summary>
|
|
|
|
|
private static Models.Logiqx.Rom CreateRom(Rom item)
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
var rom = new Models.Logiqx.Rom
|
|
|
|
|
{
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
Size = item.Size?.ToString(),
|
|
|
|
|
CRC = item.CRC,
|
|
|
|
|
MD5 = item.MD5,
|
|
|
|
|
SHA1 = item.SHA1,
|
|
|
|
|
SHA256 = item.SHA256,
|
|
|
|
|
SHA384 = item.SHA384,
|
|
|
|
|
SHA512 = item.SHA512,
|
|
|
|
|
SpamSum = item.SpamSum,
|
|
|
|
|
//xxHash364 = item.xxHash364, // TODO: Add to internal model
|
|
|
|
|
//xxHash3128 = item.xxHash3128, // TODO: Add to internal model
|
|
|
|
|
Merge = item.MergeTag,
|
|
|
|
|
//Serial = item.Serial, // TODO: Add to internal model
|
|
|
|
|
//Header = item.Header, // TODO: Add to internal model
|
|
|
|
|
Date = item.Date,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (item.ItemStatusSpecified)
|
2024-03-05 15:24:11 -05:00
|
|
|
rom.Status = item.ItemStatus.AsStringValue<ItemStatus>(useSecond: false);
|
2023-07-31 12:51:41 -04:00
|
|
|
if (item.InvertedSpecified)
|
|
|
|
|
rom.Inverted = item.Inverted.FromYesNo();
|
|
|
|
|
if (item.MIASpecified)
|
|
|
|
|
rom.MIA = item.MIA.FromYesNo();
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
return rom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a Disk from the current Disk DatItem
|
|
|
|
|
/// <summary>
|
|
|
|
|
private static Models.Logiqx.Disk CreateDisk(Disk item)
|
|
|
|
|
{
|
|
|
|
|
var disk = new Models.Logiqx.Disk
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
Name = item.Name,
|
|
|
|
|
MD5 = item.MD5,
|
|
|
|
|
SHA1 = item.SHA1,
|
|
|
|
|
Merge = item.MergeTag,
|
|
|
|
|
Region = item.Region,
|
|
|
|
|
};
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
if (item.ItemStatusSpecified)
|
2024-03-05 15:24:11 -05:00
|
|
|
disk.Status = item.ItemStatus.AsStringValue<ItemStatus>(useSecond: false);
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
return disk;
|
|
|
|
|
}
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Create a Media from the current Media DatItem
|
|
|
|
|
/// <summary>
|
|
|
|
|
private static Models.Logiqx.Media CreateMedia(Media item)
|
|
|
|
|
{
|
|
|
|
|
var media = new Models.Logiqx.Media
|
|
|
|
|
{
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
MD5 = item.MD5,
|
|
|
|
|
SHA1 = item.SHA1,
|
|
|
|
|
SHA256 = item.SHA256,
|
|
|
|
|
SpamSum = item.SpamSum,
|
|
|
|
|
};
|
|
|
|
|
return media;
|
|
|
|
|
}
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Create a Sample from the current Sample DatItem
|
|
|
|
|
/// <summary>
|
|
|
|
|
private static Models.Logiqx.Sample CreateSample(Sample item)
|
|
|
|
|
{
|
|
|
|
|
var sample = new Models.Logiqx.Sample
|
|
|
|
|
{
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
};
|
|
|
|
|
return sample;
|
|
|
|
|
}
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Create a Archive from the current Archive DatItem
|
|
|
|
|
/// <summary>
|
|
|
|
|
private static Models.Logiqx.Archive CreateArchive(Archive item)
|
|
|
|
|
{
|
|
|
|
|
var archive = new Models.Logiqx.Archive
|
|
|
|
|
{
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
};
|
|
|
|
|
return archive;
|
|
|
|
|
}
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Create a DeviceRef from the current Chip DatItem
|
|
|
|
|
/// <summary>
|
|
|
|
|
private static Models.Logiqx.DeviceRef CreateDeviceRef(DeviceReference item)
|
|
|
|
|
{
|
|
|
|
|
var deviceref = new Models.Logiqx.DeviceRef
|
|
|
|
|
{
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
};
|
|
|
|
|
return deviceref;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a Driver from the current Driver DatItem
|
|
|
|
|
/// <summary>
|
|
|
|
|
private static Models.Logiqx.Driver CreateDriver(Driver item)
|
|
|
|
|
{
|
|
|
|
|
var driver = new Models.Logiqx.Driver
|
|
|
|
|
{
|
2024-03-05 15:24:11 -05:00
|
|
|
Status = item.Status.AsStringValue<SupportStatus>(),
|
|
|
|
|
Emulation = item.Emulation.AsStringValue<SupportStatus>(),
|
|
|
|
|
Cocktail = item.Cocktail.AsStringValue<SupportStatus>(),
|
|
|
|
|
SaveState = item.SaveState.AsStringValue<Supported>(useSecond: true),
|
2023-07-31 12:51:41 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (item.RequiresArtworkSpecified)
|
|
|
|
|
driver.RequiresArtwork = item.RequiresArtwork.FromYesNo();
|
|
|
|
|
if (item.UnofficialSpecified)
|
|
|
|
|
driver.Unofficial = item.Unofficial.FromYesNo();
|
|
|
|
|
if (item.NoSoundHardwareSpecified)
|
|
|
|
|
driver.NoSoundHardware = item.NoSoundHardware.FromYesNo();
|
|
|
|
|
if (item.IncompleteSpecified)
|
|
|
|
|
driver.Incomplete = item.Incomplete.FromYesNo();
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
return driver;
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-07-31 12:51:41 -04:00
|
|
|
/// Create a SoftwareList from the current SoftwareList DatItem
|
|
|
|
|
/// <summary>
|
|
|
|
|
private static Models.Logiqx.SoftwareList CreateSoftwareList(DatItems.Formats.SoftwareList item)
|
2023-07-30 22:06:48 -04:00
|
|
|
{
|
2023-07-31 12:51:41 -04:00
|
|
|
var softwarelist = new Models.Logiqx.SoftwareList
|
|
|
|
|
{
|
|
|
|
|
Tag = item.Tag,
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
Filter = item.Filter,
|
|
|
|
|
};
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
if (item.StatusSpecified)
|
2024-03-05 15:24:11 -05:00
|
|
|
softwarelist.Status = item.Status.AsStringValue<SoftwareListStatus>();
|
2023-07-30 22:06:48 -04:00
|
|
|
|
2023-07-31 12:51:41 -04:00
|
|
|
return softwarelist;
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
2023-07-31 12:51:41 -04:00
|
|
|
|
|
|
|
|
#endregion
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
|
|
|
|
}
|