mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SabreTools, Flags, DatFile] Add reverse base replacement
This commit is contained in:
@@ -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<string> 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
|
||||
/// <param name="trim">True if we are supposed to trim names to NTFS length, false otherwise</param>
|
||||
/// <param name="single">True if all games should be replaced by '!', false otherwise</param>
|
||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||
/// <param name="reverse">True if the base DATs should be reverse-ordered, false otherwise</param>
|
||||
public void BaseReplace(List<string> inputPaths, List<string> 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);
|
||||
|
||||
@@ -243,6 +243,7 @@ namespace SabreTools.Library.Data
|
||||
|
||||
// Not technically diffs
|
||||
BaseReplace = Against << 1,
|
||||
ReverseBaseReplace = BaseReplace << 1,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1227,7 +1227,7 @@ namespace SabreTools
|
||||
null));
|
||||
update.AddFeature("base-name", new Feature(
|
||||
new List<string>() { "-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<string>() { "-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<string>() { "-bd", "--base-dat" },
|
||||
"Add a base DAT for replacing",
|
||||
FeatureType.List,
|
||||
null));
|
||||
update.AddFeature("game-name", new Feature(
|
||||
new List<string>() { "-gn", "--game-name" },
|
||||
"Filter by game name",
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user