diff --git a/SabreTools.DatFiles.Test/DatFileTests.Splitting.cs b/SabreTools.DatFiles.Test/DatFileTests.Splitting.cs index 49024fd9..ea2693d1 100644 --- a/SabreTools.DatFiles.Test/DatFileTests.Splitting.cs +++ b/SabreTools.DatFiles.Test/DatFileTests.Splitting.cs @@ -7,12 +7,6 @@ namespace SabreTools.DatFiles.Test { public partial class DatFileTests { - #region AddItemsFromBios - - // TODO: Implement AddItemsFromBios tests - - #endregion - #region AddItemsFromChildren // TODO: Implement AddItemsFromChildren tests @@ -25,9 +19,15 @@ namespace SabreTools.DatFiles.Test #endregion - #region AddItemsFromParent + #region AddItemsFromCloneOfParent - // TODO: Implement AddItemsFromParent tests + // TODO: Implement AddItemsFromCloneOfParent tests + + #endregion + + #region AddItemsFromRomOfParent + + // TODO: Implement AddItemsFromRomOfParent tests #endregion diff --git a/SabreTools.DatFiles/DatFile.Splitting.cs b/SabreTools.DatFiles/DatFile.Splitting.cs index d528a7ba..480ddfd4 100644 --- a/SabreTools.DatFiles/DatFile.Splitting.cs +++ b/SabreTools.DatFiles/DatFile.Splitting.cs @@ -11,16 +11,6 @@ namespace SabreTools.DatFiles // TODO: Create tests for all of these individually #region Splitting - /// - /// Use romof tags to add items to the children - /// - /// Assumes items are bucketed by - public void AddItemsFromBios() - { - AddItemsFromBiosImpl(); - AddItemsFromBiosImplDB(); - } - /// /// Use cloneof tags to add items to the parents, removing the child sets in the process /// @@ -50,10 +40,20 @@ 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 AddItemsFromParent() + public void AddItemsFromCloneOfParent() { - AddItemsFromParentImpl(); - AddItemsFromParentImplDB(); + AddItemsFromCloneOfParentImpl(); + AddItemsFromCloneOfParentImplDB(); + } + + /// + /// Use romof tags to add items to the children + /// + /// Assumes items are bucketed by + public void AddItemsFromRomOfParent() + { + AddItemsFromRomOfParentImpl(); + AddItemsFromRomOfParentImplDB(); } /// @@ -101,92 +101,6 @@ namespace SabreTools.DatFiles #region Splitting Implementations - /// - /// Use romof tags to add items to the children - /// - /// - /// Applies to . - /// Assumes items are bucketed by . - /// - private void AddItemsFromBiosImpl() - { - List buckets = [.. Items.Keys]; - buckets.Sort(); - - foreach (string bucket in buckets) - { - // If the bucket has no items in it - List items = GetItemsForBucket(bucket); - if (items.Count == 0) - continue; - - // Get the machine - var machine = items[0].GetFieldValue(DatItem.MachineKey); - if (machine == null) - continue; - - // Get the romof parent items - string? romOf = machine.GetStringFieldValue(Models.Metadata.Machine.RomOfKey); - List parentItems = GetItemsForBucket(romOf); - if (parentItems.Count == 0) - continue; - - // If the parent exists and has items, we copy the items from the parent to the current game - DatItem copyFrom = items[0]; - foreach (DatItem item in parentItems) - { - DatItem datItem = (DatItem)item.Clone(); - datItem.CopyMachineInformation(copyFrom); - if (items.FindIndex(i => i.GetName() == datItem.GetName()) == -1 && !items.Contains(datItem)) - Add(bucket, datItem); - } - } - } - - /// - /// Use romof tags to add items to the children - /// - /// - /// Applies to . - /// Assumes items are bucketed by . - /// - private void AddItemsFromBiosImplDB() - { - List buckets = [.. ItemsDB.SortedKeys]; - foreach (string bucket in buckets) - { - // If the bucket has no items in it - Dictionary items = GetItemsForBucketDB(bucket); - if (items.Count == 0) - continue; - - // Get the source for the first item - var source = ItemsDB.GetSourceForItem(items.First().Key); - - // Get the machine for the first item - var machine = ItemsDB.GetMachineForItem(items.First().Key); - if (machine.Value == null) - continue; - - // Get the romof parent items - string? romOf = machine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey); - Dictionary parentItems = GetItemsForBucketDB(romOf); - if (parentItems.Count == 0) - continue; - - // If the parent exists and has items, we copy the items from the parent to the current game - foreach (var item in parentItems) - { - DatItem datItem = (DatItem)item.Value.Clone(); - if (items.Any(i => i.Value.GetName() == datItem.GetName()) - && items.Any(i => i.Value == datItem)) - { - ItemsDB.AddItem(datItem, machine.Key, source.Key); - } - } - } - } - /// /// Use cloneof tags to add items to the parents, removing the child sets in the process /// @@ -771,7 +685,7 @@ namespace SabreTools.DatFiles /// Applies to . /// Assumes items are bucketed by . /// - private void AddItemsFromParentImpl() + private void AddItemsFromCloneOfParentImpl() { List buckets = [.. Items.Keys]; buckets.Sort(); @@ -824,7 +738,7 @@ namespace SabreTools.DatFiles /// Applies to . /// Assumes items are bucketed by . /// - private void AddItemsFromParentImplDB() + private void AddItemsFromCloneOfParentImplDB() { List buckets = [.. ItemsDB.SortedKeys]; foreach (string bucket in buckets) @@ -882,6 +796,92 @@ namespace SabreTools.DatFiles } } + /// + /// Use romof tags to add items to the children + /// + /// + /// Applies to . + /// Assumes items are bucketed by . + /// + private void AddItemsFromRomOfParentImpl() + { + List buckets = [.. Items.Keys]; + buckets.Sort(); + + foreach (string bucket in buckets) + { + // If the bucket has no items in it + List items = GetItemsForBucket(bucket); + if (items.Count == 0) + continue; + + // Get the machine + var machine = items[0].GetFieldValue(DatItem.MachineKey); + if (machine == null) + continue; + + // Get the romof parent items + string? romOf = machine.GetStringFieldValue(Models.Metadata.Machine.RomOfKey); + List parentItems = GetItemsForBucket(romOf); + if (parentItems.Count == 0) + continue; + + // If the parent exists and has items, we copy the items from the parent to the current game + DatItem copyFrom = items[0]; + foreach (DatItem item in parentItems) + { + DatItem datItem = (DatItem)item.Clone(); + datItem.CopyMachineInformation(copyFrom); + if (items.FindIndex(i => i.GetName() == datItem.GetName()) == -1 && !items.Contains(datItem)) + Add(bucket, datItem); + } + } + } + + /// + /// Use romof tags to add items to the children + /// + /// + /// Applies to . + /// Assumes items are bucketed by . + /// + private void AddItemsFromRomOfParentImplDB() + { + List buckets = [.. ItemsDB.SortedKeys]; + foreach (string bucket in buckets) + { + // If the bucket has no items in it + Dictionary items = GetItemsForBucketDB(bucket); + if (items.Count == 0) + continue; + + // Get the source for the first item + var source = ItemsDB.GetSourceForItem(items.First().Key); + + // Get the machine for the first item + var machine = ItemsDB.GetMachineForItem(items.First().Key); + if (machine.Value == null) + continue; + + // Get the romof parent items + string? romOf = machine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey); + Dictionary parentItems = GetItemsForBucketDB(romOf); + if (parentItems.Count == 0) + continue; + + // If the parent exists and has items, we copy the items from the parent to the current game + foreach (var item in parentItems) + { + DatItem datItem = (DatItem)item.Value.Clone(); + if (items.Any(i => i.Value.GetName() == datItem.GetName()) + && items.Any(i => i.Value == datItem)) + { + ItemsDB.AddItem(datItem, machine.Key, source.Key); + } + } + } + } + /// /// Remove all BIOS and device sets /// diff --git a/SabreTools.DatTools/MergeSplit.cs b/SabreTools.DatTools/MergeSplit.cs index 721cba31..c8525568 100644 --- a/SabreTools.DatTools/MergeSplit.cs +++ b/SabreTools.DatTools/MergeSplit.cs @@ -148,10 +148,10 @@ namespace SabreTools.DatTools // 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.AddItemsFromParent(); + datFile.AddItemsFromCloneOfParent(); // Now that we have looped through the cloneof tags, we loop through the romof tags - datFile.AddItemsFromBios(); + datFile.AddItemsFromRomOfParent(); // Then, remove the romof and cloneof tags so it's not picked up by the manager datFile.RemoveMachineRelationshipTags(); @@ -191,7 +191,7 @@ namespace SabreTools.DatTools datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); // Now we want to loop through all of the games and set the correct information - datFile.AddItemsFromParent(); + datFile.AddItemsFromCloneOfParent(); // Now that we have looped through the cloneof tags, we loop through the romof tags datFile.RemoveItemsFromRomOfChild(false);