2023-07-30 22:06:48 -04:00
|
|
|
using System;
|
|
|
|
|
using SabreTools.Core;
|
|
|
|
|
using SabreTools.Core.Tools;
|
|
|
|
|
|
|
|
|
|
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);
|
2024-03-10 00:43:45 -05:00
|
|
|
var metadata = new Serialization.CrossModel.Logiqx().Serialize(metadataFile);
|
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
|
|
|
|
2024-03-10 00:43:45 -05:00
|
|
|
// Convert to the internal format
|
|
|
|
|
ConvertMetadata(metadata, 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
|
2023-08-10 23:22:14 -04:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2023-07-30 22:06:48 -04:00
|
|
|
}
|
|
|
|
|
}
|