diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index 264ca137..a2ee3acd 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -1608,7 +1608,10 @@ namespace SabreTools.Library.DatFiles bool bare, bool clean, bool remUnicode, bool descAsName, Filter filter, SplitType splitType, bool trim, bool single, string root) { // If we're in merging or diffing mode, use the full list of inputs - if (merge || (diff != 0 && (diff & DiffMode.Against) == 0) && (diff & DiffMode.BaseReplace) == 0) + if (merge || (diff != 0 + && (diff & DiffMode.Against) == 0) + && (diff & DiffMode.BaseReplace) == 0 + && (diff & DiffMode.ReverseBaseReplace) == 0) { // Make sure there are no folders in inputs List newInputFileNames = FileTools.GetOnlyFilesFromInputs(inputPaths, appendparent: true); @@ -1647,7 +1650,12 @@ namespace SabreTools.Library.DatFiles // If we're in "base replacement" mode, we treat the inputs differently else if ((diff & DiffMode.BaseReplace) != 0) { - BaseReplace(inputPaths, basePaths, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, trim, single, root); + BaseReplace(inputPaths, basePaths, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, trim, single, root, false); + } + // If we're in "reverse base replacement" mode, we treat the inputs differently + else if ((diff & DiffMode.ReverseBaseReplace) != 0) + { + BaseReplace(inputPaths, basePaths, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, trim, single, root, true); } // Otherwise, loop through all of the inputs individually else @@ -1736,8 +1744,9 @@ namespace SabreTools.Library.DatFiles /// True if we are supposed to trim names to NTFS length, false otherwise /// True if all games should be replaced by '!', false otherwise /// String representing root directory to compare against for length calculation + /// True if the base DATs should be reverse-ordered, false otherwise public void BaseReplace(List inputPaths, List basePaths, string outDir, bool inplace, bool clean, bool remUnicode, - bool descAsName, Filter filter, SplitType splitType, bool trim, bool single, string root) + bool descAsName, Filter filter, SplitType splitType, bool trim, bool single, string root, bool reverse) { // First we want to parse all of the base DATs into the input InternalStopwatch watch = new InternalStopwatch("Populating base DAT for replacement..."); @@ -1751,7 +1760,7 @@ namespace SabreTools.Library.DatFiles lock (baseFileNames) { path = baseFileNames[i]; - id = baseFileNames.Count - i; // Inverse because larger numbers take precedence + id = (reverse ? i : baseFileNames.Count - i); } Parse(path, id, id, keep: true, clean: clean, remUnicode: remUnicode, descAsName: descAsName); diff --git a/SabreTools.Library/Data/Flags.cs b/SabreTools.Library/Data/Flags.cs index ad66dc27..bde405aa 100644 --- a/SabreTools.Library/Data/Flags.cs +++ b/SabreTools.Library/Data/Flags.cs @@ -243,6 +243,7 @@ namespace SabreTools.Library.Data // Not technically diffs BaseReplace = Against << 1, + ReverseBaseReplace = BaseReplace << 1, } /// diff --git a/SabreTools.Library/README.1ST b/SabreTools.Library/README.1ST index 25d579cc..3fca33d7 100644 --- a/SabreTools.Library/README.1ST +++ b/SabreTools.Library/README.1ST @@ -1177,12 +1177,14 @@ Options: a second time, this will skip writing it. This can often speed up the output process. - -bn, --base-name Replace matching item names from base DAT + -bn, --base-name Replace item names from base DATs in order + -rbn, --reverse-base-name Replace item names from base DATs in reverse By default, no item names are changed except when there is a merge occurring. This flag enables users to define a DAT or set of base DATs to use as "replacement names" for all input DATs. Note that the first found instance of an item in the base DAT(s) will be - used and all others will be disgarded. + used and all others will be disgarded. For reverse, the first + instance found in the last DAT inputted will be used. -bd=, --base-dat= Add a base DAT for replacing Add a DAT or folder of DATs to the base set to be used in diff --git a/SabreTools/SabreTools.Help.cs b/SabreTools/SabreTools.Help.cs index 7508aff6..2155f8da 100644 --- a/SabreTools/SabreTools.Help.cs +++ b/SabreTools/SabreTools.Help.cs @@ -1227,7 +1227,7 @@ namespace SabreTools null)); update.AddFeature("base-name", new Feature( new List() { "-bn", "--base-name" }, - "Replace matching item names from a base DAT", + "Replace item names from base DATs in order", FeatureType.Flag, null)); update["base-name"].AddFeature("base-dat", new Feature( @@ -1235,6 +1235,16 @@ namespace SabreTools "Add a base DAT for replacing", FeatureType.List, null)); + update.AddFeature("reverse-base-name", new Feature( + new List() { "-rbn", "--reverse-base-name" }, + "Replace item names from base DATs in reverse", + FeatureType.Flag, + null)); + update["reverse-base-name"].AddFeature("base-dat", new Feature( + new List() { "-bd", "--base-dat" }, + "Add a base DAT for replacing", + FeatureType.List, + null)); update.AddFeature("game-name", new Feature( new List() { "-gn", "--game-name" }, "Filter by game name", diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index a3163a1a..f8e52726 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -830,6 +830,10 @@ namespace SabreTools rar = 2; } break; + case "-rbn": + case "--reverse-base-name": + diffMode |= DiffMode.ReverseBaseReplace; + break; case "-rd": case "--root-dir": root = args[++i];