2023-07-30 21:27:02 -04:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using SabreTools.Core;
|
|
|
|
|
using SabreTools.DatItems;
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.DatFiles.Formats
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents parsing and writing of a Archive.org file list
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal partial class ArchiveDotOrg : DatFile
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
protected override ItemType[] GetSupportedTypes()
|
|
|
|
|
{
|
2024-02-28 19:19:50 -05:00
|
|
|
return
|
|
|
|
|
[
|
2023-07-30 21:27:02 -04:00
|
|
|
ItemType.Rom,
|
2024-02-28 19:19:50 -05:00
|
|
|
];
|
2023-07-30 21:27:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2024-03-11 14:31:48 -04:00
|
|
|
protected override List<string>? GetMissingRequiredFields(DatItem datItem) => null;
|
2023-07-30 21:27:02 -04:00
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
logger.User($"Writing to '{outfile}'...");
|
|
|
|
|
|
2024-03-11 14:31:48 -04:00
|
|
|
// Serialize the input file
|
|
|
|
|
var metadata = ConvertMetadata(ignoreblanks);
|
|
|
|
|
var files = new Serialization.CrossModel.ArchiveDotOrg().Deserialize(metadata);
|
|
|
|
|
if (!new Serialization.Files.ArchiveDotOrg().Serialize(files, outfile))
|
2023-07-30 21:27:02 -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-30 21:27:02 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|