Remove external quotes parameter for CMP

This commit is contained in:
Matt Nadareski
2025-01-12 20:49:22 -05:00
parent a5e9de2fdc
commit 4d4a873b83
4 changed files with 34 additions and 35 deletions

View File

@@ -36,7 +36,7 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <returns>A default Logiqx DatFile</returns> /// <returns>A default Logiqx DatFile</returns>
public static DatFile CreateDatFile() public static DatFile CreateDatFile()
=> CreateDatFile(DatFormat.Logiqx, baseDat: null, quotes: true); => CreateDatFile(DatFormat.Logiqx, baseDat: null);
/// <summary> /// <summary>
/// Create a specific type of DatFile to be used based on a format /// Create a specific type of DatFile to be used based on a format
@@ -44,22 +44,21 @@ namespace SabreTools.DatFiles
/// <param name="datFormat">Format of the DAT to be created</param> /// <param name="datFormat">Format of the DAT to be created</param>
/// <returns>DatFile of the specific internal type</returns> /// <returns>DatFile of the specific internal type</returns>
public static DatFile CreateDatFile(DatFormat datFormat) public static DatFile CreateDatFile(DatFormat datFormat)
=> CreateDatFile(datFormat, baseDat: null, quotes: true); => CreateDatFile(datFormat, baseDat: null);
/// <summary> /// <summary>
/// Create a specific type of DatFile to be used based on a format and a base DAT /// Create a specific type of DatFile to be used based on a format and a base DAT
/// </summary> /// </summary>
/// <param name="datFormat">Format of the DAT to be created</param> /// <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="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> /// <returns>DatFile of the specific internal type that corresponds to the inputs</returns>
public static DatFile CreateDatFile(DatFormat datFormat, DatFile? baseDat, bool quotes) public static DatFile CreateDatFile(DatFormat datFormat, DatFile? baseDat)
{ {
return datFormat switch return datFormat switch
{ {
DatFormat.ArchiveDotOrg => new ArchiveDotOrg(baseDat), DatFormat.ArchiveDotOrg => new ArchiveDotOrg(baseDat),
DatFormat.AttractMode => new AttractMode(baseDat), DatFormat.AttractMode => new AttractMode(baseDat),
DatFormat.ClrMamePro => new ClrMamePro(baseDat, quotes), DatFormat.ClrMamePro => new ClrMamePro(baseDat),
DatFormat.CSV => new CommaSeparatedValue(baseDat), DatFormat.CSV => new CommaSeparatedValue(baseDat),
DatFormat.DOSCenter => new DosCenter(baseDat), DatFormat.DOSCenter => new DosCenter(baseDat),
DatFormat.EverdriveSMDB => new EverdriveSMDB(baseDat), DatFormat.EverdriveSMDB => new EverdriveSMDB(baseDat),

View File

@@ -31,21 +31,14 @@ namespace SabreTools.DatFiles.Formats
ItemType.Sound, ItemType.Sound,
]; ];
/// <summary>
/// Get whether to assume quote usage on read and write or not
/// </summary>
private readonly bool _quotes;
#endregion #endregion
/// <summary> /// <summary>
/// Constructor designed for casting a base DatFile /// Constructor designed for casting a base DatFile
/// </summary> /// </summary>
/// <param name="datFile">Parent DatFile to copy from</param> /// <param name="datFile">Parent DatFile to copy from</param>
/// <param name="quotes">Enable quotes on read and write, false otherwise</param> public ClrMamePro(DatFile? datFile) : base(datFile)
public ClrMamePro(DatFile? datFile, bool quotes) : base(datFile)
{ {
_quotes = quotes;
} }
/// <inheritdoc/> /// <inheritdoc/>
@@ -54,7 +47,7 @@ namespace SabreTools.DatFiles.Formats
try try
{ {
// Deserialize the input file // Deserialize the input file
var metadataFile = Serialization.Deserializers.ClrMamePro.DeserializeFile(filename, _quotes); var metadataFile = Serialization.Deserializers.ClrMamePro.DeserializeFile(filename, quotes: true);
var metadata = new Serialization.CrossModel.ClrMamePro().Serialize(metadataFile); var metadata = new Serialization.CrossModel.ClrMamePro().Serialize(metadataFile);
// Convert to the internal format // Convert to the internal format
@@ -176,7 +169,7 @@ namespace SabreTools.DatFiles.Formats
// Serialize the input file // Serialize the input file
var metadata = ConvertToMetadata(ignoreblanks); var metadata = ConvertToMetadata(ignoreblanks);
var metadataFile = new Serialization.CrossModel.ClrMamePro().Deserialize(metadata); var metadataFile = new Serialization.CrossModel.ClrMamePro().Deserialize(metadata);
if (!Serialization.Serializers.ClrMamePro.SerializeFile(metadataFile, outfile, _quotes)) if (!Serialization.Serializers.ClrMamePro.SerializeFile(metadataFile, outfile, quotes: true))
{ {
_logger.Warning($"File '{outfile}' could not be written! See the log for more details."); _logger.Warning($"File '{outfile}' could not be written! See the log for more details.");
return false; return false;

View File

@@ -48,7 +48,6 @@ namespace SabreTools.DatFiles
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param> /// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="keepext">True if original extension should be kept, false otherwise (default)</param> /// <param name="keepext">True if original extension should be kept, false otherwise (default)</param>
/// <param name="quotes">True if quotes are assumed in supported types (default), false otherwise</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param> /// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
public static void ParseInto( public static void ParseInto(
@@ -57,12 +56,11 @@ namespace SabreTools.DatFiles
int indexId = 0, int indexId = 0,
bool keep = false, bool keep = false,
bool keepext = false, bool keepext = false,
bool quotes = true,
bool statsOnly = false, bool statsOnly = false,
bool throwOnError = false) bool throwOnError = false)
{ {
ParentablePath path = new(filename.Trim('"')); var path = new ParentablePath(filename.Trim('"'));
ParseInto(datFile, path, indexId, keep, keepext, quotes, statsOnly, throwOnError); ParseInto(datFile, path, indexId, keep, keepext, statsOnly, throwOnError);
} }
/// <summary> /// <summary>
@@ -73,7 +71,6 @@ namespace SabreTools.DatFiles
/// <param name="indexId">Index ID for the DAT</param> /// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param> /// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="keepext">True if original extension should be kept, false otherwise (default)</param> /// <param name="keepext">True if original extension should be kept, false otherwise (default)</param>
/// <param name="quotes">True if quotes are assumed in supported types (default), false otherwise</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param> /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param> /// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
public static void ParseInto( public static void ParseInto(
@@ -82,9 +79,8 @@ namespace SabreTools.DatFiles
int indexId = 0, int indexId = 0,
bool keep = false, bool keep = false,
bool keepext = false, bool keepext = false,
bool quotes = true,
bool statsOnly = false, bool statsOnly = false,
bool throwOnError = true) bool throwOnError = false)
{ {
// Get the current path from the filename // Get the current path from the filename
string currentPath = input.CurrentPath; string currentPath = input.CurrentPath;
@@ -112,7 +108,7 @@ namespace SabreTools.DatFiles
// Now parse the correct type of DAT // Now parse the correct type of DAT
try try
{ {
DatFile parsingDatFile = DatFileTool.CreateDatFile(currentPathFormat, datFile, quotes); DatFile parsingDatFile = DatFileTool.CreateDatFile(currentPathFormat, datFile);
parsingDatFile.ParseFile(currentPath, indexId, keep, statsOnly: statsOnly, throwOnError: throwOnError); parsingDatFile.ParseFile(currentPath, indexId, keep, statsOnly: statsOnly, throwOnError: throwOnError);
} }
catch (Exception ex) when (!throwOnError) catch (Exception ex) when (!throwOnError)

View File

@@ -30,18 +30,29 @@ namespace SabreTools.DatTools
/// </summary> /// </summary>
/// <param name="datFile">Current DatFile object to write from</param> /// <param name="datFile">Current DatFile object to write from</param>
/// <param name="outDir">Set the output directory (current directory on null)</param> /// <param name="outDir">Set the output directory (current directory on null)</param>
/// <param name="overwrite">True if files should be overwritten (default), false if they should be renamed instead</param> /// <returns>True if the DAT was written correctly, false otherwise</returns>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param> public static bool Write(DatFile datFile, string? outDir)
/// <param name="quotes">True if quotes are assumed in supported types (default), false otherwise</param> => Write(datFile, outDir, overwrite: true, throwOnError: false);
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">Current DatFile object to write from</param>
/// <param name="outDir">Set the output directory (current directory on null)</param>
/// <param name="overwrite">True if files should be overwritten, false if they should be renamed instead</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
public static bool Write(DatFile datFile, string? outDir, bool overwrite)
=> Write(datFile, outDir, overwrite, throwOnError: false);
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">Current DatFile object to write from</param>
/// <param name="outDir">Set the output directory (current directory on null)</param>
/// <param name="overwrite">True if files should be overwritten, false if they should be renamed instead</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param> /// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns> /// <returns>True if the DAT was written correctly, false otherwise</returns>
public static bool Write( public static bool Write(DatFile datFile, string? outDir, bool overwrite, bool throwOnError)
DatFile datFile,
string? outDir,
bool overwrite = true,
bool ignoreblanks = false,
bool quotes = true,
bool throwOnError = false)
{ {
// If we have nothing writable, abort // If we have nothing writable, abort
if (!HasWritable(datFile)) if (!HasWritable(datFile))
@@ -90,8 +101,8 @@ namespace SabreTools.DatTools
string outfile = outfiles[datFormat]; string outfile = outfiles[datFormat];
try try
{ {
DatFile writingDatFile = DatFileTool.CreateDatFile(datFormat, datFile, quotes); DatFile writingDatFile = DatFileTool.CreateDatFile(datFormat, datFile);
writingDatFile.WriteToFile(outfile, ignoreblanks, throwOnError); writingDatFile.WriteToFile(outfile, ignoreblanks: true, throwOnError);
} }
catch (Exception ex) when (!throwOnError) catch (Exception ex) when (!throwOnError)
{ {