From 80832b41e335f63d698e64e109cb486f764b1ea0 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 13 Jan 2025 15:41:57 -0500 Subject: [PATCH] Move more functionality back to DatFile --- .../DatFileTests.Splitting.cs | 30 ++++ SabreTools.DatFiles/DatFile.Splitting.cs | 146 +++++++++++++++++- SabreTools.DatTools/MergeSplit.cs | 145 +---------------- 3 files changed, 174 insertions(+), 147 deletions(-) diff --git a/SabreTools.DatFiles.Test/DatFileTests.Splitting.cs b/SabreTools.DatFiles.Test/DatFileTests.Splitting.cs index b4a74157..a5103761 100644 --- a/SabreTools.DatFiles.Test/DatFileTests.Splitting.cs +++ b/SabreTools.DatFiles.Test/DatFileTests.Splitting.cs @@ -7,6 +7,36 @@ namespace SabreTools.DatFiles.Test { public partial class DatFileTests { + #region ApplyDeviceNonMerged + + // TODO: Implement ApplyDeviceNonMerged tests + + #endregion + + #region ApplyFullyMerged + + // TODO: Implement ApplyFullyMerged tests + + #endregion + + #region ApplyFullyNonMerged + + // TODO: Implement ApplyFullyNonMerged tests + + #endregion + + #region ApplyMerged + + // TODO: Implement ApplyMerged tests + + #endregion + + #region ApplyNonMerged + + // TODO: Implement ApplyNonMerged tests + + #endregion + #region AddItemsFromChildren // TODO: Implement AddItemsFromChildren tests diff --git a/SabreTools.DatFiles/DatFile.Splitting.cs b/SabreTools.DatFiles/DatFile.Splitting.cs index 91deedf1..8862e30a 100644 --- a/SabreTools.DatFiles/DatFile.Splitting.cs +++ b/SabreTools.DatFiles/DatFile.Splitting.cs @@ -8,6 +8,136 @@ namespace SabreTools.DatFiles { public partial class DatFile { + #region Splitting + + /// + /// Use cdevice_ref tags to get full non-merged sets and remove parenting tags + /// + /// This is a destructive process and items will be removed + public void ApplyDeviceNonMerged() + { + _logger.User("Creating device non-merged sets from the DAT"); + + // For sake of ease, the first thing we want to do is bucket by game + BucketBy(ItemKey.Machine, DedupeType.None, norename: true); + + // Now we want to loop through all of the games and set the correct information + while (AddItemsFromDevices(false, false)) ; + while (AddItemsFromDevices(true, false)) ; + + // Then, remove the romof and cloneof tags so it's not picked up by the manager + RemoveMachineRelationshipTags(); + } + + /// + /// Use cloneof tags to create merged sets and remove the tags plus deduplicating if tags don't catch everything + /// + /// This is a destructive process and items will be removed + public void ApplyFullyMerged() + { + _logger.User("Creating fully merged sets from the DAT"); + + // For sake of ease, the first thing we want to do is bucket by game + BucketBy(ItemKey.Machine, DedupeType.None, norename: true); + + // Now we want to loop through all of the games and set the correct information + AddItemsFromChildren(true, false); + + // Now that we have looped through the cloneof tags, we loop through the romof tags + RemoveItemsFromRomOfChild(); + + // Finally, remove the romof and cloneof tags so it's not picked up by the manager + RemoveMachineRelationshipTags(); + } + + /// + /// Use cloneof tags to create non-merged sets and remove the tags plus using the device_ref tags to get full sets + /// + /// This is a destructive process and items will be removed + public void ApplyFullyNonMerged() + { + _logger.User("Creating fully non-merged sets from the DAT"); + + // For sake of ease, the first thing we want to do is bucket by game + BucketBy(ItemKey.Machine, DedupeType.None, norename: true); + + // Now we want to loop through all of the games and set the correct information + while (AddItemsFromDevices(true, true)) ; + AddItemsFromDevices(false, true); + AddItemsFromCloneOfParent(); + + // Now that we have looped through the cloneof tags, we loop through the romof tags + AddItemsFromRomOfParent(); + + // Then, remove the romof and cloneof tags so it's not picked up by the manager + RemoveMachineRelationshipTags(); + } + + /// + /// Use cloneof tags to create merged sets and remove the tags + /// + /// This is a destructive process and items will be removed + public void ApplyMerged() + { + _logger.User("Creating merged sets from the DAT"); + + // For sake of ease, the first thing we want to do is bucket by game + BucketBy(ItemKey.Machine, DedupeType.None, norename: true); + + // Now we want to loop through all of the games and set the correct information + AddItemsFromChildren(true, true); + + // Now that we have looped through the cloneof tags, we loop through the romof tags + RemoveItemsFromRomOfChild(); + + // Finally, remove the romof and cloneof tags so it's not picked up by the manager + RemoveMachineRelationshipTags(); + } + + /// + /// Use cloneof tags to create non-merged sets and remove the tags + /// + /// This is a destructive process and items will be removed + public void ApplyNonMerged() + { + _logger.User("Creating non-merged sets from the DAT"); + + // For sake of ease, the first thing we want to do is bucket by game + BucketBy(ItemKey.Machine, DedupeType.None, norename: true); + + // Now we want to loop through all of the games and set the correct information + AddItemsFromCloneOfParent(); + + // Now that we have looped through the cloneof tags, we loop through the romof tags + RemoveItemsFromRomOfChild(); + + // Finally, remove the romof and cloneof tags so it's not picked up by the manager + RemoveMachineRelationshipTags(); + } + + /// + /// Use cloneof and romof tags to create split sets and remove the tags + /// + /// This is a destructive process and items will be removed + public void ApplySplit() + { + _logger.User("Creating split sets from the DAT"); + + // For sake of ease, the first thing we want to do is bucket by game + BucketBy(ItemKey.Machine, DedupeType.None, norename: true); + + // Now we want to loop through all of the games and set the correct information + RemoveItemsFromCloneOfChild(); + + // Now that we have looped through the cloneof tags, we loop through the romof tags + RemoveItemsFromRomOfChild(); + + // Finally, remove the romof and cloneof tags so it's not picked up by the manager + RemoveMachineRelationshipTags(); + } + + #endregion + #region Splitting Steps /// @@ -16,7 +146,7 @@ namespace SabreTools.DatFiles /// True to add DatItems to subfolder of parent (not including Disk), false otherwise /// True to skip checking for duplicate ROMs in parent, false otherwise /// Assumes items are bucketed by - public void AddItemsFromChildren(bool subfolder, bool skipDedup) + internal void AddItemsFromChildren(bool subfolder, bool skipDedup) { AddItemsFromChildrenImpl(subfolder, skipDedup); AddItemsFromChildrenImplDB(subfolder, skipDedup); @@ -26,7 +156,7 @@ namespace SabreTools.DatFiles /// Use cloneof tags to add items to the children, setting the new romof tag in the process /// /// Assumes items are bucketed by - public void AddItemsFromCloneOfParent() + internal void AddItemsFromCloneOfParent() { AddItemsFromCloneOfParentImpl(); AddItemsFromCloneOfParentImplDB(); @@ -38,7 +168,7 @@ namespace SabreTools.DatFiles /// True if only child device sets are touched, false for non-device sets /// True if slotoptions tags are used as well, false otherwise /// Assumes items are bucketed by - public bool AddItemsFromDevices(bool deviceOnly, bool useSlotOptions) + internal bool AddItemsFromDevices(bool deviceOnly, bool useSlotOptions) { bool foundnew = AddItemsFromDevicesImpl(deviceOnly, useSlotOptions); foundnew |= AddItemsFromDevicesImplDB(deviceOnly, useSlotOptions); @@ -49,7 +179,7 @@ namespace SabreTools.DatFiles /// Use romof tags to add items to the children /// /// Assumes items are bucketed by - public void AddItemsFromRomOfParent() + internal void AddItemsFromRomOfParent() { AddItemsFromRomOfParentImpl(); AddItemsFromRomOfParentImplDB(); @@ -59,7 +189,7 @@ namespace SabreTools.DatFiles /// Remove all BIOS and device sets /// /// Assumes items are bucketed by - public void RemoveBiosAndDeviceSets() + internal void RemoveBiosAndDeviceSets() { RemoveBiosAndDeviceSetsImpl(); RemoveBiosAndDeviceSetsImplDB(); @@ -69,7 +199,7 @@ namespace SabreTools.DatFiles /// Use cloneof tags to remove items from the children /// /// Assumes items are bucketed by - public void RemoveItemsFromCloneOfChild() + internal void RemoveItemsFromCloneOfChild() { RemoveItemsFromCloneOfChildImpl(); RemoveItemsFromCloneOfChildImplDB(); @@ -79,7 +209,7 @@ namespace SabreTools.DatFiles /// Use romof tags to remove bios items from children /// /// Assumes items are bucketed by - public void RemoveItemsFromRomOfChild() + internal void RemoveItemsFromRomOfChild() { // TODO: Figure out why the bios flag is needed RemoveItemsFromRomOfChildImpl(false); @@ -92,7 +222,7 @@ namespace SabreTools.DatFiles /// Remove all romof and cloneof tags from all machines /// /// Assumes items are bucketed by - public void RemoveMachineRelationshipTags() + internal void RemoveMachineRelationshipTags() { RemoveMachineRelationshipTagsImpl(); RemoveMachineRelationshipTagsImplDB(); diff --git a/SabreTools.DatTools/MergeSplit.cs b/SabreTools.DatTools/MergeSplit.cs index 87c5ad8e..ee4d0b54 100644 --- a/SabreTools.DatTools/MergeSplit.cs +++ b/SabreTools.DatTools/MergeSplit.cs @@ -1,7 +1,6 @@ using System; using SabreTools.Core.Tools; using SabreTools.DatFiles; -using SabreTools.DatItems; using SabreTools.IO.Logging; namespace SabreTools.DatTools @@ -26,12 +25,6 @@ namespace SabreTools.DatTools #endregion - // TODO: Should any of these create a new DatFile in the process? - // The reason this comes up is that doing any of the splits or merges - // is an inherently destructive process. Making it output a new DatFile - // might make it easier to deal with multiple internal steps. On the other - // hand, this will increase memory usage significantly and would force the - // existing paths to behave entirely differently #region Running /// @@ -59,24 +52,24 @@ namespace SabreTools.DatTools // No-op break; case MergingFlag.Split: - CreateSplitSets(datFile); + datFile.ApplySplit(); break; case MergingFlag.Merged: - CreateMergedSets(datFile); + datFile.ApplyMerged(); break; case MergingFlag.NonMerged: - CreateNonMergedSets(datFile); + datFile.ApplyNonMerged(); break; // Nonstandard case MergingFlag.FullMerged: - CreateFullyMergedSets(datFile); + datFile.ApplyFullyMerged(); break; case MergingFlag.DeviceNonMerged: - CreateDeviceNonMergedSets(datFile); + datFile.ApplyDeviceNonMerged(); break; case MergingFlag.FullNonMerged: - CreateFullyNonMergedSets(datFile); + datFile.ApplyFullyNonMerged(); break; } } @@ -93,132 +86,6 @@ namespace SabreTools.DatTools return true; } - /// - /// Use cdevice_ref tags to get full non-merged sets and remove parenting tags - /// - /// Current DatFile object to run operations on - internal static void CreateDeviceNonMergedSets(DatFile datFile) - { - _staticLogger.User("Creating device non-merged sets from the DAT"); - - // For sake of ease, the first thing we want to do is bucket by game - datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - - // Now we want to loop through all of the games and set the correct information - while (datFile.AddItemsFromDevices(false, false)) ; - while (datFile.AddItemsFromDevices(true, false)) ; - - // Then, remove the romof and cloneof tags so it's not picked up by the manager - datFile.RemoveMachineRelationshipTags(); - } - - /// - /// Use cloneof tags to create merged sets and remove the tags plus deduplicating if tags don't catch everything - /// - /// Current DatFile object to run operations on - internal static void CreateFullyMergedSets(DatFile datFile) - { - _staticLogger.User("Creating fully merged sets from the DAT"); - - // For sake of ease, the first thing we want to do is bucket by game - datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - - // Now we want to loop through all of the games and set the correct information - datFile.AddItemsFromChildren(true, false); - - // Now that we have looped through the cloneof tags, we loop through the romof tags - datFile.RemoveItemsFromRomOfChild(); - - // Finally, remove the romof and cloneof tags so it's not picked up by the manager - datFile.RemoveMachineRelationshipTags(); - } - - /// - /// Use cloneof tags to create non-merged sets and remove the tags plus using the device_ref tags to get full sets - /// - /// Current DatFile object to run operations on - internal static void CreateFullyNonMergedSets(DatFile datFile) - { - _staticLogger.User("Creating fully non-merged sets from the DAT"); - - // For sake of ease, the first thing we want to do is bucket by game - datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - - // Now we want to loop through all of the games and set the correct information - while (datFile.AddItemsFromDevices(true, true)) ; - datFile.AddItemsFromDevices(false, true); - datFile.AddItemsFromCloneOfParent(); - - // Now that we have looped through the cloneof tags, we loop through the romof tags - datFile.AddItemsFromRomOfParent(); - - // Then, remove the romof and cloneof tags so it's not picked up by the manager - datFile.RemoveMachineRelationshipTags(); - } - - /// - /// Use cloneof tags to create merged sets and remove the tags - /// - /// Current DatFile object to run operations on - internal static void CreateMergedSets(DatFile datFile) - { - _staticLogger.User("Creating merged sets from the DAT"); - - // For sake of ease, the first thing we want to do is bucket by game - datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - - // Now we want to loop through all of the games and set the correct information - datFile.AddItemsFromChildren(true, true); - - // Now that we have looped through the cloneof tags, we loop through the romof tags - datFile.RemoveItemsFromRomOfChild(); - - // Finally, remove the romof and cloneof tags so it's not picked up by the manager - datFile.RemoveMachineRelationshipTags(); - } - - /// - /// Use cloneof tags to create non-merged sets and remove the tags - /// - /// Current DatFile object to run operations on - internal static void CreateNonMergedSets(DatFile datFile) - { - _staticLogger.User("Creating non-merged sets from the DAT"); - - // For sake of ease, the first thing we want to do is bucket by game - datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - - // Now we want to loop through all of the games and set the correct information - datFile.AddItemsFromCloneOfParent(); - - // Now that we have looped through the cloneof tags, we loop through the romof tags - datFile.RemoveItemsFromRomOfChild(); - - // Finally, remove the romof and cloneof tags so it's not picked up by the manager - datFile.RemoveMachineRelationshipTags(); - } - - /// - /// Use cloneof and romof tags to create split sets and remove the tags - /// - /// Current DatFile object to run operations on - internal static void CreateSplitSets(DatFile datFile) - { - _staticLogger.User("Creating split sets from the DAT"); - - // For sake of ease, the first thing we want to do is bucket by game - datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); - - // Now we want to loop through all of the games and set the correct information - datFile.RemoveItemsFromCloneOfChild(); - - // Now that we have looped through the cloneof tags, we loop through the romof tags - datFile.RemoveItemsFromRomOfChild(); - - // Finally, remove the romof and cloneof tags so it's not picked up by the manager - datFile.RemoveMachineRelationshipTags(); - } - #endregion } }