diff --git a/SabreTools.DatFiles/DatHeader.cs b/SabreTools.DatFiles/DatHeader.cs index 4acc3cc0..26783f3b 100644 --- a/SabreTools.DatFiles/DatHeader.cs +++ b/SabreTools.DatFiles/DatHeader.cs @@ -515,6 +515,15 @@ namespace SabreTools.DatFiles // 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); + + // Strip off the extension if it's a holdover from the DAT + if (Utilities.HasValidDatExtension(filename)) + filename = Path.GetFileNameWithoutExtension(filename); + // Double check the outDir for the end delim if (!outDir.EndsWith(Path.DirectorySeparatorChar.ToString())) outDir += Path.DirectorySeparatorChar; @@ -541,7 +550,7 @@ namespace SabreTools.DatFiles extension = extensions[1]; // Create the filename and set the extension as used - outfileNames.Add(format, CreateOutFileNamesHelper(outDir, extension, overwrite)); + outfileNames.Add(format, CreateOutFileNamesHelper(filename, outDir, extension, overwrite)); usedExtensions.Add(extension); } @@ -551,20 +560,13 @@ namespace SabreTools.DatFiles /// /// Help generating the outfile name /// + /// Base filename to use /// Output directory /// Extension to use for the file /// True if we ignore existing files, false otherwise /// String containing the new filename - private string CreateOutFileNamesHelper(string outDir, string extension, bool overwrite) + private static string CreateOutFileNamesHelper(string? filename, string outDir, string extension, bool overwrite) { - string? filename = string.IsNullOrEmpty(GetStringFieldValue(DatHeader.FileNameKey)) - ? GetStringFieldValue(Models.Metadata.Header.DescriptionKey) - : GetStringFieldValue(DatHeader.FileNameKey); - - // Strip off the extension if it's a holdover from the DAT - if (Utilities.HasValidDatExtension(filename)) - filename = Path.GetFileNameWithoutExtension(filename); - string outfile = $"{outDir}{filename}{extension}"; outfile = outfile.Replace($"{Path.DirectorySeparatorChar}{Path.DirectorySeparatorChar}", Path.DirectorySeparatorChar.ToString()); @@ -588,7 +590,7 @@ namespace SabreTools.DatFiles /// Combined DatFormat value to split /// List representing the individual flag values set /// TODO: Consider making DatFormat a non-flag enum so this doesn't need to happen - private List SplitFormats(DatFormat datFormat) + private static List SplitFormats(DatFormat datFormat) { List usedFormats = [];