mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SabreTools, DatFile] Allow updating names AND/OR hashes
This commit is contained in:
@@ -1581,9 +1581,10 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="descAsName">True to allow SL DATs to have game names used instead of descriptions, false otherwise (default)</param>
|
/// <param name="descAsName">True to allow SL DATs to have game names used instead of descriptions, false otherwise (default)</param>
|
||||||
/// <param name="filter">Filter object to be passed to the DatItem level</param>
|
/// <param name="filter">Filter object to be passed to the DatItem level</param>
|
||||||
/// <param name="splitType">Type of the split that should be performed (split, merged, fully merged)</param>
|
/// <param name="splitType">Type of the split that should be performed (split, merged, fully merged)</param>
|
||||||
/// <param name="updateHashes">True if hashes should be updated along with names, false otherwise [Only for base replacement]</param>
|
/// <param name="updateNames">True if names should be updated, false otherwise [only for base replacement]</param>
|
||||||
|
/// <param name="updateHashes">True if hashes should be updated, false otherwise [only for base replacement]</param>
|
||||||
public void DetermineUpdateType(List<string> inputPaths, List<string> basePaths, string outDir, UpdateMode updateMode, bool inplace, bool skip,
|
public void DetermineUpdateType(List<string> inputPaths, List<string> basePaths, string outDir, UpdateMode updateMode, bool inplace, bool skip,
|
||||||
bool bare, bool clean, bool remUnicode, bool descAsName, Filter filter, SplitType splitType, bool updateHashes)
|
bool bare, bool clean, bool remUnicode, bool descAsName, Filter filter, SplitType splitType, bool updateNames, bool updateHashes)
|
||||||
{
|
{
|
||||||
// Ensure we only have files in the inputs
|
// Ensure we only have files in the inputs
|
||||||
List<string> inputFileNames = Utilities.GetOnlyFilesFromInputs(inputPaths, appendparent: true);
|
List<string> inputFileNames = Utilities.GetOnlyFilesFromInputs(inputPaths, appendparent: true);
|
||||||
@@ -1637,7 +1638,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
else if ((updateMode & UpdateMode.BaseReplace) != 0
|
else if ((updateMode & UpdateMode.BaseReplace) != 0
|
||||||
|| (updateMode & UpdateMode.ReverseBaseReplace) != 0)
|
|| (updateMode & UpdateMode.ReverseBaseReplace) != 0)
|
||||||
{
|
{
|
||||||
BaseReplace(inputFileNames, baseFileNames, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, updateHashes);
|
BaseReplace(inputFileNames, baseFileNames, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, updateNames, updateHashes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -1705,7 +1706,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replace item names from on a base set
|
/// Replace item values from the base set
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inputFileNames">Names of the input files</param>
|
/// <param name="inputFileNames">Names of the input files</param>
|
||||||
/// <param name="baseFileNames">Names of base files</param>
|
/// <param name="baseFileNames">Names of base files</param>
|
||||||
@@ -1719,9 +1720,10 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="trim">True if we are supposed to trim names to NTFS length, false otherwise</param>
|
/// <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="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="root">String representing root directory to compare against for length calculation</param>
|
||||||
/// <param name="updateHashes">True if hashes should be updated along with names, false otherwise</param>
|
/// <param name="updateNames">True if names should be updated, false otherwise</param>
|
||||||
|
/// <param name="updateHashes">True if hashes should be updated, false otherwise</param>
|
||||||
public void BaseReplace(List<string> inputFileNames, List<string> baseFileNames, string outDir, bool inplace, bool clean, bool remUnicode,
|
public void BaseReplace(List<string> inputFileNames, List<string> baseFileNames, string outDir, bool inplace, bool clean, bool remUnicode,
|
||||||
bool descAsName, Filter filter, SplitType splitType, bool updateHashes)
|
bool descAsName, Filter filter, SplitType splitType, bool updateNames, bool updateHashes)
|
||||||
{
|
{
|
||||||
// First we want to parse all of the base DATs into the input
|
// First we want to parse all of the base DATs into the input
|
||||||
InternalStopwatch watch = new InternalStopwatch("Populating base DAT for replacement...");
|
InternalStopwatch watch = new InternalStopwatch("Populating base DAT for replacement...");
|
||||||
@@ -1769,10 +1771,14 @@ namespace SabreTools.Library.DatFiles
|
|||||||
DatItem newDatItem = (DatItem)datItem.Clone();
|
DatItem newDatItem = (DatItem)datItem.Clone();
|
||||||
|
|
||||||
if (dupes.Count > 0)
|
if (dupes.Count > 0)
|
||||||
|
{
|
||||||
|
// If we're updating names, replace using the first found name
|
||||||
|
if (updateNames)
|
||||||
{
|
{
|
||||||
newDatItem.Name = dupes[0].Name;
|
newDatItem.Name = dupes[0].Name;
|
||||||
|
}
|
||||||
|
|
||||||
// If we're updating hashes too, only replace if the current item doesn't have them
|
// If we're updating hashes, only replace if the current item doesn't have them
|
||||||
if (updateHashes)
|
if (updateHashes)
|
||||||
{
|
{
|
||||||
if (newDatItem.Type == ItemType.Rom)
|
if (newDatItem.Type == ItemType.Rom)
|
||||||
|
|||||||
@@ -1142,22 +1142,25 @@ Options:
|
|||||||
a second time, this will skip writing it. This can often
|
a second time, this will skip writing it. This can often
|
||||||
speed up the output process.
|
speed up the output process.
|
||||||
|
|
||||||
-bn, --base-name Replace item names from base DATs in order
|
-bn, --base-replace Replace item from base DATs in order
|
||||||
-rbn, --reverse-base-name Replace item names from base DATs in reverse
|
-rbn, --reverse-base-replace Replace item from base DATs in reverse
|
||||||
By default, no item names are changed except when there is a merge
|
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
|
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
|
DATs to use as "replacements" for all input DATs. Note that
|
||||||
the first found instance of an item in the base DAT(s) will be
|
the first found instance of an item in the base DAT(s) will be
|
||||||
used and all others will be disgarded. For reverse, the first
|
used and all others will be disgarded. For reverse, the first
|
||||||
instance found in the last DAT inputted will be used.
|
instance found in the last DAT inputted will be used. If no
|
||||||
|
additional flag is given, it will default to updating names.
|
||||||
|
|
||||||
-bd=, --base-dat= Add a base DAT for replacing
|
-bd=, --base-dat= Add a base DAT for replacing
|
||||||
Add a DAT or folder of DATs to the base set to be used in
|
Add a DAT or folder of DATs to the base set to be used in
|
||||||
item name replacement
|
item name replacement
|
||||||
|
|
||||||
-uh, --update-hashes Update hashes along with the names
|
-un, --update-names Update names from base DATs
|
||||||
By default, only names are updated during the replacement. This
|
This flag enables updating of names from base DATs.
|
||||||
flag also allows updating of missing hashes at the same time.
|
|
||||||
|
-uh, --update-hashes Update hashes from base DATs
|
||||||
|
This flag enables updating of hashes from base DATs.
|
||||||
|
|
||||||
-gn=, --not-game= Filter by game name
|
-gn=, --not-game= Filter by game name
|
||||||
-ngn=, --game-name= Exclude by game name
|
-ngn=, --game-name= Exclude by game name
|
||||||
|
|||||||
@@ -1260,34 +1260,44 @@ namespace SabreTools
|
|||||||
"Don't include the date in automatic name",
|
"Don't include the date in automatic name",
|
||||||
FeatureType.Flag,
|
FeatureType.Flag,
|
||||||
null));
|
null));
|
||||||
update.AddFeature("base-name", new Feature(
|
update.AddFeature("base-replace", new Feature(
|
||||||
new List<string>() { "-bn", "-br", "--base-name", "--base-replace" },
|
new List<string>() { "-br", "--base-replace" },
|
||||||
"Replace item names from base DATs in order",
|
"Replace from base DATs in order",
|
||||||
FeatureType.Flag,
|
FeatureType.Flag,
|
||||||
null));
|
null));
|
||||||
update["base-name"].AddFeature("base-dat", new Feature(
|
update["base-replace"].AddFeature("base-dat", new Feature(
|
||||||
new List<string>() { "-bd", "--base-dat" },
|
new List<string>() { "-bd", "--base-dat" },
|
||||||
"Add a base DAT for replacing",
|
"Add a base DAT for replacing",
|
||||||
FeatureType.List,
|
FeatureType.List,
|
||||||
null));
|
null));
|
||||||
update["base-name"].AddFeature("update-hashes", new Feature(
|
update["base-replace"].AddFeature("update-names", new Feature(
|
||||||
new List<string>() { "-uh", "--update-hashes" },
|
new List<string>() { "-un", "--update-names" },
|
||||||
"Update hashes along with the names",
|
"Update names from base DATs",
|
||||||
FeatureType.Flag,
|
FeatureType.Flag,
|
||||||
null));
|
null));
|
||||||
update.AddFeature("reverse-base-name", new Feature(
|
update["base-replace"].AddFeature("update-hashes", new Feature(
|
||||||
new List<string>() { "-rbn", "-rbr", "--reverse-base-name", "--reverse-base-replace" },
|
new List<string>() { "-uh", "--update-hashes" },
|
||||||
|
"Update hashes from base DATs",
|
||||||
|
FeatureType.Flag,
|
||||||
|
null));
|
||||||
|
update.AddFeature("reverse-base-replace", new Feature(
|
||||||
|
new List<string>() { "-rbr", "--reverse-base-replace" },
|
||||||
"Replace item names from base DATs in reverse",
|
"Replace item names from base DATs in reverse",
|
||||||
FeatureType.Flag,
|
FeatureType.Flag,
|
||||||
null));
|
null));
|
||||||
update["reverse-base-name"].AddFeature("base-dat", new Feature(
|
update["reverse-base-replace"].AddFeature("base-dat", new Feature(
|
||||||
new List<string>() { "-bd", "--base-dat" },
|
new List<string>() { "-bd", "--base-dat" },
|
||||||
"Add a base DAT for replacing",
|
"Add a base DAT for replacing",
|
||||||
FeatureType.List,
|
FeatureType.List,
|
||||||
null));
|
null));
|
||||||
update["reverse-base-name"].AddFeature("update-hashes", new Feature(
|
update["reverse-base-replace"].AddFeature("update-names", new Feature(
|
||||||
|
new List<string>() { "-un", "--update-names" },
|
||||||
|
"Update names from base DATs",
|
||||||
|
FeatureType.Flag,
|
||||||
|
null));
|
||||||
|
update["reverse-base-replace"].AddFeature("update-hashes", new Feature(
|
||||||
new List<string>() { "-uh", "--update-hashes" },
|
new List<string>() { "-uh", "--update-hashes" },
|
||||||
"Update hashes along with the names",
|
"Update hashes from base DATs",
|
||||||
FeatureType.Flag,
|
FeatureType.Flag,
|
||||||
null));
|
null));
|
||||||
update.AddFeature("game-name", new Feature(
|
update.AddFeature("game-name", new Feature(
|
||||||
|
|||||||
@@ -233,7 +233,8 @@ namespace SabreTools
|
|||||||
/// <param name="clean">True to clean the game names to WoD standard, false otherwise (default)</param>
|
/// <param name="clean">True to clean the game names to WoD standard, false otherwise (default)</param>
|
||||||
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
/// <param name="descAsName">True if descriptions should be used as names, false otherwise (default)</param>
|
/// <param name="descAsName">True if descriptions should be used as names, false otherwise (default)</param>
|
||||||
/// <param name="updateHashes">True if hashes should be updated along with names, false otherwise [Only for base replacement]</param>
|
/// <param name="updateNames">True if names should be updated, false otherwise [only for base replacement]</param>
|
||||||
|
/// <param name="updateHashes">True if hashes should be updated, false otherwise [only for base replacement]</param>
|
||||||
private static void InitUpdate(
|
private static void InitUpdate(
|
||||||
List<string> inputPaths,
|
List<string> inputPaths,
|
||||||
List<string> basePaths,
|
List<string> basePaths,
|
||||||
@@ -256,6 +257,7 @@ namespace SabreTools
|
|||||||
bool clean,
|
bool clean,
|
||||||
bool remUnicode,
|
bool remUnicode,
|
||||||
bool descAsName,
|
bool descAsName,
|
||||||
|
bool updateNames,
|
||||||
bool updateHashes)
|
bool updateHashes)
|
||||||
{
|
{
|
||||||
// Normalize the extensions
|
// Normalize the extensions
|
||||||
@@ -300,11 +302,17 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If neither the names or hashes are set, select names
|
||||||
|
if (!updateNames && !updateHashes)
|
||||||
|
{
|
||||||
|
updateNames = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Populate the DatData object
|
// Populate the DatData object
|
||||||
DatFile userInputDat = new DatFile(datHeader);
|
DatFile userInputDat = new DatFile(datHeader);
|
||||||
|
|
||||||
userInputDat.DetermineUpdateType(inputPaths, basePaths, outDir, updateMode, inplace, skip, bare, clean,
|
userInputDat.DetermineUpdateType(inputPaths, basePaths, outDir, updateMode, inplace, skip, bare, clean,
|
||||||
remUnicode, descAsName, filter, splitType, updateHashes);
|
remUnicode, descAsName, filter, splitType, updateNames, updateHashes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -94,7 +94,8 @@ namespace SabreTools
|
|||||||
shortname = false,
|
shortname = false,
|
||||||
skip = false,
|
skip = false,
|
||||||
updateDat = false,
|
updateDat = false,
|
||||||
updateHashes = false;
|
updateHashes = false,
|
||||||
|
updateNames = false;
|
||||||
Hash omitFromScan = Hash.DeepHashes; // TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
|
Hash omitFromScan = Hash.DeepHashes; // TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
|
||||||
OutputFormat outputFormat = OutputFormat.Folder;
|
OutputFormat outputFormat = OutputFormat.Folder;
|
||||||
SkipFileType skipFileType = SkipFileType.None;
|
SkipFileType skipFileType = SkipFileType.None;
|
||||||
@@ -200,7 +201,7 @@ namespace SabreTools
|
|||||||
case "baddump-col":
|
case "baddump-col":
|
||||||
showBaddumpColumn = true;
|
showBaddumpColumn = true;
|
||||||
break;
|
break;
|
||||||
case "base-name":
|
case "base-replace":
|
||||||
updateMode |= UpdateMode.BaseReplace;
|
updateMode |= UpdateMode.BaseReplace;
|
||||||
break;
|
break;
|
||||||
case "cascade":
|
case "cascade":
|
||||||
@@ -491,6 +492,9 @@ namespace SabreTools
|
|||||||
case "update-hashes":
|
case "update-hashes":
|
||||||
updateHashes = true;
|
updateHashes = true;
|
||||||
break;
|
break;
|
||||||
|
case "update-names":
|
||||||
|
updateNames = true;
|
||||||
|
break;
|
||||||
case "exclude-of":
|
case "exclude-of":
|
||||||
datHeader.ExcludeOf = true;
|
datHeader.ExcludeOf = true;
|
||||||
break;
|
break;
|
||||||
@@ -720,7 +724,7 @@ namespace SabreTools
|
|||||||
case "Update":
|
case "Update":
|
||||||
VerifyInputs(inputs, feature);
|
VerifyInputs(inputs, feature);
|
||||||
InitUpdate(inputs, basePaths, datHeader, updateMode, inplace, skip, removeDateFromAutomaticName, filter,
|
InitUpdate(inputs, basePaths, datHeader, updateMode, inplace, skip, removeDateFromAutomaticName, filter,
|
||||||
splitType, outDir, cleanGameNames, removeUnicode, descAsName, updateHashes);
|
splitType, outDir, cleanGameNames, removeUnicode, descAsName, updateNames, updateHashes);
|
||||||
break;
|
break;
|
||||||
// If we're using the verifier
|
// If we're using the verifier
|
||||||
case "Verify":
|
case "Verify":
|
||||||
|
|||||||
Reference in New Issue
Block a user