[SabreTools, DatFile] Implement flag

This commit is contained in:
Matt Nadareski
2017-12-14 15:55:06 -08:00
parent 9310cc1224
commit 6dafd36413
3 changed files with 18 additions and 23 deletions

View File

@@ -1590,10 +1590,9 @@ 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="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="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>
/// <param name="replaceMode">ReplaceMode representing what should be updated [only for base replacement]</param>
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 updateNames, bool updateHashes)
bool bare, bool clean, bool remUnicode, bool descAsName, Filter filter, SplitType splitType, ReplaceMode replaceMode)
{
// Ensure we only have files in the inputs
List<string> inputFileNames = Utilities.GetOnlyFilesFromInputs(inputPaths, appendparent: true);
@@ -1647,7 +1646,7 @@ namespace SabreTools.Library.DatFiles
else if ((updateMode & UpdateMode.BaseReplace) != 0
|| (updateMode & UpdateMode.ReverseBaseReplace) != 0)
{
BaseReplace(inputFileNames, baseFileNames, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, updateNames, updateHashes);
BaseReplace(inputFileNames, baseFileNames, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, replaceMode);
}
return;
@@ -1729,10 +1728,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="updateNames">True if names should be updated, false otherwise</param>
/// <param name="updateHashes">True if hashes should be updated, false otherwise</param>
/// <param name="replaceMode">ReplaceMode representing what should be updated</param>
public void BaseReplace(List<string> inputFileNames, List<string> baseFileNames, string outDir, bool inplace, bool clean, bool remUnicode,
bool descAsName, Filter filter, SplitType splitType, bool updateNames, bool updateHashes)
bool descAsName, Filter filter, SplitType splitType, ReplaceMode replaceMode)
{
// First we want to parse all of the base DATs into the input
InternalStopwatch watch = new InternalStopwatch("Populating base DAT for replacement...");
@@ -1789,13 +1787,13 @@ namespace SabreTools.Library.DatFiles
if (dupes.Count > 0)
{
// If we're updating names, replace using the first found name
if (updateNames)
if ((replaceMode & ReplaceMode.Names) != 0)
{
newDatItem.Name = dupes[0].Name;
}
// If we're updating hashes, only replace if the current item doesn't have them
if (updateHashes)
if ((replaceMode & ReplaceMode.Hashes) != 0)
{
if (newDatItem.Type == ItemType.Rom)
{

View File

@@ -233,8 +233,7 @@ namespace SabreTools
/// <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="descAsName">True if descriptions should be used as names, false otherwise (default)</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>
/// <param name="replaceMode">ReplaceMode representing what should be updated [only for base replacement]</param>
private static void InitUpdate(
List<string> inputPaths,
List<string> basePaths,
@@ -257,8 +256,7 @@ namespace SabreTools
bool clean,
bool remUnicode,
bool descAsName,
bool updateNames,
bool updateHashes)
ReplaceMode replaceMode)
{
// Normalize the extensions
datHeader.AddExtension = (String.IsNullOrWhiteSpace(datHeader.AddExtension) || datHeader.AddExtension.StartsWith(".")
@@ -302,17 +300,17 @@ namespace SabreTools
}
}
// If neither the names or hashes are set, select names
if (!updateNames && !updateHashes)
// If no replacement mode is set, default to Names
if (replaceMode == ReplaceMode.None)
{
updateNames = true;
replaceMode = ReplaceMode.Names;
}
// Populate the DatData object
DatFile userInputDat = new DatFile(datHeader);
userInputDat.DetermineUpdateType(inputPaths, basePaths, outDir, updateMode, inplace, skip, bare, clean,
remUnicode, descAsName, filter, splitType, updateNames, updateHashes);
remUnicode, descAsName, filter, splitType, replaceMode);
}
/// <summary>

View File

@@ -93,11 +93,10 @@ namespace SabreTools
showNodumpColumn = false,
shortname = false,
skip = false,
updateDat = false,
updateHashes = false,
updateNames = false;
updateDat = false;
Hash omitFromScan = Hash.DeepHashes; // TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
OutputFormat outputFormat = OutputFormat.Folder;
ReplaceMode replaceMode = ReplaceMode.None;
SkipFileType skipFileType = SkipFileType.None;
SplittingMode splittingMode = SplittingMode.None;
SplitType splitType = SplitType.None;
@@ -490,10 +489,10 @@ namespace SabreTools
updateDat = true;
break;
case "update-hashes":
updateHashes = true;
replaceMode |= ReplaceMode.Hashes;
break;
case "update-names":
updateNames = true;
replaceMode |= ReplaceMode.Names;
break;
case "exclude-of":
datHeader.ExcludeOf = true;
@@ -728,7 +727,7 @@ namespace SabreTools
case "Update":
VerifyInputs(inputs, feature);
InitUpdate(inputs, basePaths, datHeader, updateMode, inplace, skip, removeDateFromAutomaticName, filter,
splitType, outDir, cleanGameNames, removeUnicode, descAsName, updateNames, updateHashes);
splitType, outDir, cleanGameNames, removeUnicode, descAsName, replaceMode);
break;
// If we're using the verifier
case "Verify":