diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index cb86800b..842add45 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -695,7 +695,6 @@ namespace SabreTools.Library.DatFiles #endregion - // TODO: Should the ApplyFilter method contain the splitting logic? #region Filtering /// @@ -705,35 +704,43 @@ namespace SabreTools.Library.DatFiles /// True if cleaning was successful, false on error public bool ApplyCleaning(Cleaner cleaner) { - // Perform item-level cleaning - CleanDatItems(cleaner); + try + { + // Perform item-level cleaning + CleanDatItems(cleaner); - // Process description to machine name - if (cleaner?.DescriptionAsName == true) - MachineDescriptionToName(); + // Process description to machine name + if (cleaner?.DescriptionAsName == true) + MachineDescriptionToName(); - // If we are removing scene dates, do that now - if (cleaner?.SceneDateStrip == true) - StripSceneDatesFromItems(); + // If we are removing scene dates, do that now + if (cleaner?.SceneDateStrip == true) + StripSceneDatesFromItems(); - // Run the one rom per game logic, if required - if (cleaner?.OneGamePerRegion == true) - OneGamePerRegion(cleaner.RegionList); + // Run the one rom per game logic, if required + if (cleaner?.OneGamePerRegion == true) + OneGamePerRegion(cleaner.RegionList); - // Run the one rom per game logic, if required - if (cleaner?.OneRomPerGame == true) - OneRomPerGame(); + // Run the one rom per game logic, if required + if (cleaner?.OneRomPerGame == true) + OneRomPerGame(); - // If we are removing fields, do that now - if (cleaner.ExcludeFields != null && cleaner.ExcludeFields.Any()) - RemoveFieldsFromItems(cleaner.ExcludeFields); + // If we are removing fields, do that now + if (cleaner.ExcludeFields != null && cleaner.ExcludeFields.Any()) + RemoveFieldsFromItems(cleaner.ExcludeFields); - // Remove all marked items - Items.ClearMarked(); + // Remove all marked items + Items.ClearMarked(); - // We remove any blanks, if we aren't supposed to have any - if (cleaner?.KeepEmptyGames == false) - Items.ClearEmpty(); + // 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 /// Filter to use /// True if DatFile tags override splitting, false otherwise /// True if the DatFile was filtered, false on error + /// 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 keys = Items.Keys.ToList(); @@ -852,6 +856,52 @@ namespace SabreTools.Library.DatFiles return true; } + /// + /// Apply splitting on the DatFile + /// + /// Split type to try + /// True if DatFile tags override splitting, false otherwise + /// True if the DatFile was split, false on error + 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; + } + /// /// Apply SuperDAT naming logic to a merged DatFile /// @@ -1171,36 +1221,6 @@ namespace SabreTools.Library.DatFiles // existing paths to behave entirely differently #region Internal Splitting/Merging - /// - /// Process items according to split type - /// - /// MergingFlag to implement - 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; - } - } - /// /// Use cdevice_ref tags to get full non-merged sets and remove parenting tags /// diff --git a/SabreTools/Features/Batch.cs b/SabreTools/Features/Batch.cs index 9848f280..10112239 100644 --- a/SabreTools/Features/Batch.cs +++ b/SabreTools/Features/Batch.cs @@ -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;