mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SabreTools] Add "only same" flag for description replacement
This commit is contained in:
@@ -1626,8 +1626,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <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="replaceMode">ReplaceMode representing what should be updated [only for base replacement]</param>
|
/// <param name="replaceMode">ReplaceMode representing what should be updated [only for base replacement]</param>
|
||||||
|
/// <param name="onlySame">True if descriptions should only be replaced if the game name is the same, 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, ReplaceMode replaceMode)
|
bool bare, bool clean, bool remUnicode, bool descAsName, Filter filter, SplitType splitType, ReplaceMode replaceMode, bool onlySame)
|
||||||
{
|
{
|
||||||
// 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);
|
||||||
@@ -1681,7 +1682,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, replaceMode);
|
BaseReplace(inputFileNames, baseFileNames, outDir, inplace, clean, remUnicode, descAsName, filter, splitType, replaceMode, onlySame);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -1764,8 +1765,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <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="replaceMode">ReplaceMode representing what should be updated</param>
|
/// <param name="replaceMode">ReplaceMode representing what should be updated</param>
|
||||||
|
/// <param name="onlySame">True if descriptions should only be replaced if the game name is the same, 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, ReplaceMode replaceMode)
|
bool descAsName, Filter filter, SplitType splitType, ReplaceMode replaceMode, bool onlySame)
|
||||||
{
|
{
|
||||||
// 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...");
|
||||||
@@ -1921,9 +1923,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
if (Contains(key) && this[key].Count() > 0)
|
if (Contains(key) && this[key].Count() > 0)
|
||||||
{
|
{
|
||||||
if ((replaceMode & ReplaceMode.Description) != 0)
|
if ((replaceMode & ReplaceMode.Description) != 0)
|
||||||
|
{
|
||||||
|
if (!onlySame || (onlySame && newDatItem.MachineName == newDatItem.MachineDescription))
|
||||||
{
|
{
|
||||||
newDatItem.MachineDescription = this[key][0].MachineDescription;
|
newDatItem.MachineDescription = this[key][0].MachineDescription;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ((replaceMode & ReplaceMode.Year) != 0)
|
if ((replaceMode & ReplaceMode.Year) != 0)
|
||||||
{
|
{
|
||||||
newDatItem.Year = this[key][0].Year;
|
newDatItem.Year = this[key][0].Year;
|
||||||
|
|||||||
@@ -482,6 +482,17 @@ namespace SabreTools
|
|||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private static Feature onlySameFlag
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new Feature(
|
||||||
|
new List<string>() { "-ons", "--only-same" },
|
||||||
|
"Only update description if machine name matches description",
|
||||||
|
FeatureType.Flag,
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
}
|
||||||
private static Feature outputAllFlag
|
private static Feature outputAllFlag
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -2261,6 +2272,7 @@ namespace SabreTools
|
|||||||
update["base-replace"].AddFeature("update-names", updateNamesFlag);
|
update["base-replace"].AddFeature("update-names", updateNamesFlag);
|
||||||
update["base-replace"].AddFeature("update-hashes", updateHashesFlag);
|
update["base-replace"].AddFeature("update-hashes", updateHashesFlag);
|
||||||
update["base-replace"].AddFeature("update-description", updateDescriptionFlag);
|
update["base-replace"].AddFeature("update-description", updateDescriptionFlag);
|
||||||
|
update["base-replace"]["update-description"].AddFeature("only-same", onlySameFlag);
|
||||||
update["base-replace"].AddFeature("update-year", updateYearFlag);
|
update["base-replace"].AddFeature("update-year", updateYearFlag);
|
||||||
update["base-replace"].AddFeature("update-manufacturer", updateManufacturerFlag);
|
update["base-replace"].AddFeature("update-manufacturer", updateManufacturerFlag);
|
||||||
update.AddFeature("reverse-base-replace", reverseBaseReplaceFlag);
|
update.AddFeature("reverse-base-replace", reverseBaseReplaceFlag);
|
||||||
@@ -2268,6 +2280,7 @@ namespace SabreTools
|
|||||||
update["reverse-base-replace"].AddFeature("update-names", updateNamesFlag);
|
update["reverse-base-replace"].AddFeature("update-names", updateNamesFlag);
|
||||||
update["reverse-base-replace"].AddFeature("update-hashes", updateHashesFlag);
|
update["reverse-base-replace"].AddFeature("update-hashes", updateHashesFlag);
|
||||||
update["reverse-base-replace"].AddFeature("update-description", updateDescriptionFlag);
|
update["reverse-base-replace"].AddFeature("update-description", updateDescriptionFlag);
|
||||||
|
update["reverse-base-replace"]["update-description"].AddFeature("only-same", onlySameFlag);
|
||||||
update["reverse-base-replace"].AddFeature("update-year", updateYearFlag);
|
update["reverse-base-replace"].AddFeature("update-year", updateYearFlag);
|
||||||
update["reverse-base-replace"].AddFeature("update-manufacturer", updateManufacturerFlag);
|
update["reverse-base-replace"].AddFeature("update-manufacturer", updateManufacturerFlag);
|
||||||
update.AddFeature("game-name", gameNameListInput);
|
update.AddFeature("game-name", gameNameListInput);
|
||||||
|
|||||||
@@ -235,6 +235,7 @@ namespace SabreTools
|
|||||||
/// <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="replaceMode">ReplaceMode representing what should be updated [only for base replacement]</param>
|
/// <param name="replaceMode">ReplaceMode representing what should be updated [only for base replacement]</param>
|
||||||
|
/// <param name="onlySame">True if descriptions should only be replaced if the game name is the same, 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,
|
||||||
@@ -257,7 +258,8 @@ namespace SabreTools
|
|||||||
bool clean,
|
bool clean,
|
||||||
bool remUnicode,
|
bool remUnicode,
|
||||||
bool descAsName,
|
bool descAsName,
|
||||||
ReplaceMode replaceMode)
|
ReplaceMode replaceMode,
|
||||||
|
bool onlySame)
|
||||||
{
|
{
|
||||||
// Normalize the extensions
|
// Normalize the extensions
|
||||||
datHeader.AddExtension = (String.IsNullOrWhiteSpace(datHeader.AddExtension) || datHeader.AddExtension.StartsWith(".")
|
datHeader.AddExtension = (String.IsNullOrWhiteSpace(datHeader.AddExtension) || datHeader.AddExtension.StartsWith(".")
|
||||||
@@ -311,7 +313,7 @@ namespace SabreTools
|
|||||||
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, replaceMode);
|
remUnicode, descAsName, filter, splitType, replaceMode, onlySame);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ namespace SabreTools
|
|||||||
inverse = false,
|
inverse = false,
|
||||||
noAutomaticDate = false,
|
noAutomaticDate = false,
|
||||||
nostore = false,
|
nostore = false,
|
||||||
|
onlySame = false,
|
||||||
quickScan = false,
|
quickScan = false,
|
||||||
removeUnicode = false,
|
removeUnicode = false,
|
||||||
showBaddumpColumn = false,
|
showBaddumpColumn = false,
|
||||||
@@ -311,6 +312,9 @@ namespace SabreTools
|
|||||||
case "no-store-header":
|
case "no-store-header":
|
||||||
nostore = true;
|
nostore = true;
|
||||||
break;
|
break;
|
||||||
|
case "only-same":
|
||||||
|
onlySame = true;
|
||||||
|
break;
|
||||||
case "output-all":
|
case "output-all":
|
||||||
datHeader.DatFormat |= DatFormat.ALL;
|
datHeader.DatFormat |= DatFormat.ALL;
|
||||||
break;
|
break;
|
||||||
@@ -774,7 +778,7 @@ namespace SabreTools
|
|||||||
case "Update":
|
case "Update":
|
||||||
VerifyInputs(inputs, feature);
|
VerifyInputs(inputs, feature);
|
||||||
InitUpdate(inputs, basePaths, datHeader, updateMode, inplace, skipFirstOutput, noAutomaticDate, filter,
|
InitUpdate(inputs, basePaths, datHeader, updateMode, inplace, skipFirstOutput, noAutomaticDate, filter,
|
||||||
splitType, outDir, cleanGameNames, removeUnicode, descAsName, replaceMode);
|
splitType, outDir, cleanGameNames, removeUnicode, descAsName, replaceMode, onlySame);
|
||||||
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