2023-07-28 00:44:10 -04:00
|
|
|
using System;
|
|
|
|
|
using SabreTools.Core;
|
|
|
|
|
using SabreTools.Core.Tools;
|
|
|
|
|
|
|
|
|
|
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);
|
2024-03-10 00:27:23 -05:00
|
|
|
var metadata = new Serialization.CrossModel.ClrMamePro().Serialize(metadataFile);
|
2023-07-28 00:44:10 -04:00
|
|
|
|
|
|
|
|
// Convert the header to the internal format
|
|
|
|
|
ConvertHeader(metadataFile?.ClrMamePro, keep);
|
|
|
|
|
|
2024-03-10 00:27:23 -05:00
|
|
|
// Convert to the internal format
|
|
|
|
|
ConvertMetadata(metadata, filename, indexId, statsOnly);
|
2023-07-28 00:44:10 -04:00
|
|
|
}
|
|
|
|
|
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;
|
2023-07-28 00:44:10 -04:00
|
|
|
if (Header.ForcePacking == PackingFlag.None)
|
2024-03-05 15:24:11 -05:00
|
|
|
Header.ForcePacking = cmp.ForceZipping?.AsEnumValue<PackingFlag>() ?? PackingFlag.None;
|
2023-07-28 00:44:10 -04:00
|
|
|
if (Header.ForcePacking == PackingFlag.None)
|
2024-03-05 15:24:11 -05:00
|
|
|
Header.ForcePacking = cmp.ForcePacking?.AsEnumValue<PackingFlag>() ?? PackingFlag.None;
|
2023-07-28 00:44:10 -04:00
|
|
|
|
|
|
|
|
// Handle implied SuperDAT
|
2023-08-10 23:22:14 -04:00
|
|
|
if (cmp.Name?.Contains(" - SuperDAT") == true && keep)
|
2023-07-28 00:44:10 -04:00
|
|
|
Header.Type ??= "SuperDAT";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|