diff --git a/SabreTools.DatFiles/DatHeader.cs b/SabreTools.DatFiles/DatHeader.cs index 26783f3b..deaa3a12 100644 --- a/SabreTools.DatFiles/DatHeader.cs +++ b/SabreTools.DatFiles/DatHeader.cs @@ -507,18 +507,19 @@ namespace SabreTools.DatFiles /// /// Generate a proper outfile name based on a DAT and output directory /// + /// DatHeader value to pull information from /// Output directory /// True if we ignore existing files (default), false otherwise /// Dictionary of output formats mapped to file names - public Dictionary CreateOutFileNames(string outDir, bool overwrite = true) + public static Dictionary CreateOutFileNames(DatHeader datHeader, string outDir, bool overwrite = true) { // Create the output dictionary Dictionary outfileNames = []; // Get the filename to use - string? filename = string.IsNullOrEmpty(GetStringFieldValue(DatHeader.FileNameKey)) - ? GetStringFieldValue(Models.Metadata.Header.DescriptionKey) - : GetStringFieldValue(DatHeader.FileNameKey); + string? filename = string.IsNullOrEmpty(datHeader.GetStringFieldValue(DatHeader.FileNameKey)) + ? datHeader.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + : datHeader.GetStringFieldValue(DatHeader.FileNameKey); // Strip off the extension if it's a holdover from the DAT if (Utilities.HasValidDatExtension(filename)) @@ -529,7 +530,7 @@ namespace SabreTools.DatFiles outDir += Path.DirectorySeparatorChar; // Get the current format types - DatFormat datFormat = GetFieldValue(DatHeader.DatFormatKey); + DatFormat datFormat = datHeader.GetFieldValue(DatHeader.DatFormatKey); List usedFormats = SplitFormats(datFormat); // Get the extensions from the output type diff --git a/SabreTools.DatTools/Writer.cs b/SabreTools.DatTools/Writer.cs index 0a7b9139..ce7a284f 100644 --- a/SabreTools.DatTools/Writer.cs +++ b/SabreTools.DatTools/Writer.cs @@ -16,6 +16,76 @@ namespace SabreTools.DatTools /// public class Writer { + #region Private Constants + + /// + /// Map of all formats to extensions, including "backup" extensions + /// + private static readonly Dictionary ExtensionMappings = new() + { + // .csv + { DatFormat.CSV, new string[] { ".csv" } }, + + // .dat + { DatFormat.ClrMamePro, new string[] { ".dat" } }, + { DatFormat.RomCenter, new string[] { ".dat", ".rc.dat" } }, + { DatFormat.DOSCenter, new string[] { ".dat", ".dc.dat" } }, + + // .json + { DatFormat.SabreJSON, new string[] { ".json" } }, + + // .md2 + { DatFormat.RedumpMD2, new string[] { ".md2" } }, + + // .md4 + { DatFormat.RedumpMD4, new string[] { ".md4" } }, + + // .md5 + { DatFormat.RedumpMD5, new string[] { ".md5" } }, + + // .sfv + { DatFormat.RedumpSFV, new string[] { ".sfv" } }, + + // .sha1 + { DatFormat.RedumpSHA1, new string[] { ".sha1" } }, + + // .sha256 + { DatFormat.RedumpSHA256, new string[] { ".sha256" } }, + + // .sha384 + { DatFormat.RedumpSHA384, new string[] { ".sha384" } }, + + // .sha512 + { DatFormat.RedumpSHA512, new string[] { ".sha512" } }, + + // .spamsum + { DatFormat.RedumpSpamSum, new string[] { ".spamsum" } }, + + // .ssv + { DatFormat.SSV, new string[] { ".ssv" } }, + + // .tsv + { DatFormat.TSV, new string[] { ".tsv" } }, + + // .txt + { DatFormat.AttractMode, new string[] { ".txt" } }, + { DatFormat.Listrom, new string[] { ".txt", ".lr.txt" } }, + { DatFormat.MissFile, new string[] { ".txt", ".miss.txt" } }, + { DatFormat.EverdriveSMDB, new string[] { ".txt", ".smdb.txt" } }, + + // .xml + { DatFormat.Logiqx, new string[] { ".xml" } }, + { DatFormat.LogiqxDeprecated, new string[] { ".xml", ".xml" } }, // Intentional duplicate + { DatFormat.SabreXML, new string[] { ".xml", ".sd.xml" } }, + { DatFormat.SoftwareList, new string[] { ".xml", ".sl.xml" } }, + { DatFormat.Listxml, new string[] { ".xml", ".mame.xml" } }, + { DatFormat.OfflineList, new string[] { ".xml", ".ol.xml" } }, + { DatFormat.OpenMSX, new string[] { ".xml", ".msx.xml" } }, + { DatFormat.ArchiveDotOrg, new string[] { ".xml", ".ado.xml" } }, + }; + + #endregion + #region Logging /// @@ -83,7 +153,7 @@ namespace SabreTools.DatTools _staticLogger.User($"A total of {datFile.DatStatistics.TotalCount - datFile.DatStatistics.RemovedCount} items will be written out to '{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}'"); // Get the outfile names - Dictionary outfiles = datFile.Header.CreateOutFileNames(outDir!, overwrite); + Dictionary outfiles = DatHeader.CreateOutFileNames(datFile.Header, outDir!, overwrite); try { diff --git a/SabreTools.Test/DatFiles/DatHeaderTests.cs b/SabreTools.Test/DatFiles/DatHeaderTests.cs index 7ba07346..87dc3d4b 100644 --- a/SabreTools.Test/DatFiles/DatHeaderTests.cs +++ b/SabreTools.Test/DatFiles/DatHeaderTests.cs @@ -20,7 +20,7 @@ namespace SabreTools.Test.DatFiles // Invoke the method string outDir = "C:\\Test"; - var actual = datHeader.CreateOutFileNames(outDir, overwrite: true); + var actual = DatHeader.CreateOutFileNames(datHeader, outDir, overwrite: true); // Check the result string expected = $"{outDir}{System.IO.Path.DirectorySeparatorChar}test.{extension}"; @@ -38,7 +38,7 @@ namespace SabreTools.Test.DatFiles // Invoke the method string outDir = "C:\\Test"; - var actual = datHeader.CreateOutFileNames(outDir, overwrite: true); + var actual = DatHeader.CreateOutFileNames(datHeader, outDir, overwrite: true); // Check the result Assert.Equal(28, actual.Count);