Partially decouple splitting from filter

This commit is contained in:
Matt Nadareski
2020-08-28 13:45:01 -07:00
parent 27bbc9df29
commit 0b492b798b
2 changed files with 80 additions and 60 deletions

View File

@@ -695,7 +695,6 @@ namespace SabreTools.Library.DatFiles
#endregion
// TODO: Should the ApplyFilter method contain the splitting logic?
#region Filtering
/// <summary>
@@ -704,6 +703,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="cleaner">Cleaner to use</param>
/// <returns>True if cleaning was successful, false on error</returns>
public bool ApplyCleaning(Cleaner cleaner)
{
try
{
// Perform item-level cleaning
CleanDatItems(cleaner);
@@ -734,6 +735,12 @@ namespace SabreTools.Library.DatFiles
// We remove any blanks, if we aren't supposed to have any
if (cleaner?.KeepEmptyGames == false)
Items.ClearEmpty();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
return false;
}
return true;
}
@@ -807,6 +814,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="filter">Filter to use</param>
/// <param name="useTags">True if DatFile tags override splitting, false otherwise</param>
/// <returns>True if the DatFile was filtered, false on error</returns>
/// TODO: Fully decouple splitting
public bool ApplyFilter(Filter filter, bool useTags)
{
// If we have a null filter, return false
@@ -815,12 +823,8 @@ namespace SabreTools.Library.DatFiles
try
{
// If we are using tags from the DAT, set the proper input for split type unless overridden
if (useTags && filter.InternalSplit == MergingFlag.None)
filter.InternalSplit = Header.ForceMerging;
// Run internal splitting
ProcessSplitType(filter.InternalSplit);
// Apply splitting, if necessary
ApplySplitting(filter.InternalSplit, useTags);
// Loop over every key in the dictionary
List<string> keys = Items.Keys.ToList();
@@ -852,6 +856,52 @@ namespace SabreTools.Library.DatFiles
return true;
}
/// <summary>
/// Apply splitting on the DatFile
/// </summary>
/// <param name="splitType">Split type to try</param>
/// <param name="useTags">True if DatFile tags override splitting, false otherwise</param>
/// <returns>True if the DatFile was split, false on error</returns>
public bool ApplySplitting(MergingFlag splitType, bool useTags)
{
try
{
// If we are using tags from the DAT, set the proper input for split type unless overridden
if (useTags && splitType == MergingFlag.None)
splitType = Header.ForceMerging;
// Run internal splitting
switch (splitType)
{
case MergingFlag.None:
// No-op
break;
case MergingFlag.Device:
CreateDeviceNonMergedSets(DedupeType.None);
break;
case MergingFlag.Full:
CreateFullyNonMergedSets(DedupeType.None);
break;
case MergingFlag.NonMerged:
CreateNonMergedSets(DedupeType.None);
break;
case MergingFlag.Merged:
CreateMergedSets(DedupeType.None);
break;
case MergingFlag.Split:
CreateSplitSets(DedupeType.None);
break;
}
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
return false;
}
return true;
}
/// <summary>
/// Apply SuperDAT naming logic to a merged DatFile
/// </summary>
@@ -1171,36 +1221,6 @@ namespace SabreTools.Library.DatFiles
// existing paths to behave entirely differently
#region Internal Splitting/Merging
/// <summary>
/// Process items according to split type
/// </summary>
/// <param name="splitType">MergingFlag to implement</param>
public void ProcessSplitType(MergingFlag splitType)
{
// Now we pre-process the DAT with the splitting/merging mode
switch (splitType)
{
case MergingFlag.None:
// No-op
break;
case MergingFlag.Device:
CreateDeviceNonMergedSets(DedupeType.None);
break;
case MergingFlag.Full:
CreateFullyNonMergedSets(DedupeType.None);
break;
case MergingFlag.NonMerged:
CreateNonMergedSets(DedupeType.None);
break;
case MergingFlag.Merged:
CreateMergedSets(DedupeType.None);
break;
case MergingFlag.Split:
CreateSplitSets(DedupeType.None);
break;
}
}
/// <summary>
/// Use cdevice_ref tags to get full non-merged sets and remove parenting tags
/// </summary>

View File

@@ -214,7 +214,7 @@ Reset the internal state: reset();";
MergingFlag mergingFlag = command.Arguments[0].AsMergingFlag();
// Apply the merging flag
datFile.ProcessSplitType(mergingFlag);
datFile.ApplySplitting(mergingFlag, false);
break;