Move static DatFile creation

This commit is contained in:
Matt Nadareski
2025-01-08 17:11:52 -05:00
parent 4c04d0529c
commit aeba336925
11 changed files with 109 additions and 96 deletions

View File

@@ -5,7 +5,6 @@ using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Core.Filter;
using SabreTools.Core.Tools;
using SabreTools.DatFiles.Formats;
using SabreTools.DatItems;
using SabreTools.DatItems.Formats;
using SabreTools.Hashing;
@@ -68,61 +67,6 @@ namespace SabreTools.DatFiles
}
}
/// <summary>
/// Create a specific type of DatFile to be used based on a format and a base DAT
/// </summary>
/// <param name="datFormat">Format of the DAT to be created</param>
/// <param name="baseDat">DatFile containing the information to use in specific operations</param>
/// <param name="quotes">For relevant types, assume the usage of quotes</param>
/// <returns>DatFile of the specific internal type that corresponds to the inputs</returns>
public static DatFile Create(DatFormat? datFormat = null, DatFile? baseDat = null, bool quotes = true)
{
return datFormat switch
{
DatFormat.ArchiveDotOrg => new ArchiveDotOrg(baseDat),
DatFormat.AttractMode => new AttractMode(baseDat),
DatFormat.ClrMamePro => new ClrMamePro(baseDat, quotes),
DatFormat.CSV => new CommaSeparatedValue(baseDat),
DatFormat.DOSCenter => new DosCenter(baseDat),
DatFormat.EverdriveSMDB => new EverdriveSMDB(baseDat),
DatFormat.Listrom => new Listrom(baseDat),
DatFormat.Listxml => new Listxml(baseDat),
DatFormat.Logiqx => new Logiqx(baseDat, false),
DatFormat.LogiqxDeprecated => new Logiqx(baseDat, true),
DatFormat.MissFile => new Missfile(baseDat),
DatFormat.OfflineList => new OfflineList(baseDat),
DatFormat.OpenMSX => new OpenMSX(baseDat),
DatFormat.RedumpMD5 => new Md5File(baseDat),
DatFormat.RedumpSFV => new SfvFile(baseDat),
DatFormat.RedumpSHA1 => new Sha1File(baseDat),
DatFormat.RedumpSHA256 => new Sha256File(baseDat),
DatFormat.RedumpSHA384 => new Sha384File(baseDat),
DatFormat.RedumpSHA512 => new Sha512File(baseDat),
DatFormat.RedumpSpamSum => new SpamSumFile(baseDat),
DatFormat.RomCenter => new RomCenter(baseDat),
DatFormat.SabreJSON => new SabreJSON(baseDat),
DatFormat.SabreXML => new SabreXML(baseDat),
DatFormat.SoftwareList => new Formats.SoftwareList(baseDat),
DatFormat.SSV => new SemicolonSeparatedValue(baseDat),
DatFormat.TSV => new TabSeparatedValue(baseDat),
// We use new-style Logiqx as a backup for generic DatFile
_ => new Logiqx(baseDat, false),
};
}
/// <summary>
/// Create a new DatFile from an existing DatHeader
/// </summary>
/// <param name="datHeader">DatHeader to get the values from</param>
public static DatFile Create(DatHeader datHeader)
{
DatFormat format = datHeader.GetFieldValue<DatFormat>(DatHeader.DatFormatKey);
DatFile datFile = Create(format);
datFile.Header = (DatHeader)datHeader.Clone();
return datFile;
}
/// <summary>
/// Fill the header values based on existing Header and path
/// </summary>
@@ -174,6 +118,15 @@ namespace SabreTools.DatFiles
ItemsDB = new ItemDictionaryDB();
}
/// <summary>
/// Set the internal header
/// </summary>
/// <param name="datHeader">Replacement header to be used</param>
public void SetHeader(DatHeader datHeader)
{
Header = (DatHeader)datHeader.Clone();;
}
#endregion
#region Filtering