2023-07-29 00:06:31 -04:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using SabreTools.Core;
|
|
|
|
|
using SabreTools.DatItems;
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.DatFiles.Formats
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents parsing and writing of an AttractMode DAT
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal partial class AttractMode : DatFile
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
protected override ItemType[] GetSupportedTypes()
|
|
|
|
|
{
|
2024-02-28 19:19:50 -05:00
|
|
|
return
|
|
|
|
|
[
|
|
|
|
|
ItemType.Rom
|
|
|
|
|
];
|
2023-07-29 00:06:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2024-03-05 23:41:00 -05:00
|
|
|
protected override List<string>? GetMissingRequiredFields(DatItem datItem)
|
2023-07-29 00:06:31 -04:00
|
|
|
{
|
2024-03-05 23:41:00 -05:00
|
|
|
var missingFields = new List<string>();
|
2023-07-29 00:06:31 -04:00
|
|
|
|
|
|
|
|
// Check item name
|
2024-02-28 22:54:56 -05:00
|
|
|
if (string.IsNullOrEmpty(datItem.GetName()))
|
2024-03-05 23:41:00 -05:00
|
|
|
missingFields.Add(Models.Metadata.Rom.NameKey);
|
2023-07-29 00:06:31 -04:00
|
|
|
|
|
|
|
|
return missingFields;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
logger.User($"Writing to '{outfile}'...");
|
|
|
|
|
|
2024-03-11 14:54:33 -04:00
|
|
|
// Serialize the input file
|
|
|
|
|
var metadata = ConvertMetadata(ignoreblanks);
|
2024-03-11 15:02:28 -04:00
|
|
|
var metadataFile = new Serialization.CrossModel.AttractMode().Deserialize(metadata);
|
2023-09-11 01:20:21 -04:00
|
|
|
if (!(new Serialization.Files.AttractMode().Serialize(metadataFile, outfile)))
|
2023-07-29 00:06:31 -04:00
|
|
|
{
|
|
|
|
|
logger.Warning($"File '{outfile}' could not be written! See the log for more details.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) when (!throwOnError)
|
|
|
|
|
{
|
|
|
|
|
logger.Error(ex);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 11:33:03 -04:00
|
|
|
logger.User($"'{outfile}' written!{Environment.NewLine}");
|
2023-07-29 00:06:31 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|