diff --git a/SabreTools.DatFiles/DatFile.FromMetadata.cs b/SabreTools.DatFiles/DatFile.FromMetadata.cs index a32f19e5..4dbcd92a 100644 --- a/SabreTools.DatFiles/DatFile.FromMetadata.cs +++ b/SabreTools.DatFiles/DatFile.FromMetadata.cs @@ -275,7 +275,7 @@ namespace SabreTools.DatFiles if (item.ContainsKey(Models.Metadata.Machine.DeviceRefKey)) { var items = item.ReadItemArray(Models.Metadata.Machine.DeviceRefKey); - ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner); + ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.DipSwitchKey)) { @@ -361,7 +361,7 @@ namespace SabreTools.DatFiles if (item.ContainsKey(Models.Metadata.Machine.SlotKey)) { var items = item.ReadItemArray(Models.Metadata.Machine.SlotKey); - ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly, filterRunner); + ProcessItems(items, machine, machineIndex: 0, source, sourceIndex, statsOnly); } if (item.ContainsKey(Models.Metadata.Machine.SoftwareListKey)) { @@ -581,8 +581,8 @@ namespace SabreTools.DatFiles /// Source to use with the converted items /// Index of the Source to use with the converted items /// True to only add item statistics while parsing, false otherwise - /// Optional FilterRunner to filter items on parse - private void ProcessItems(Models.Metadata.DeviceRef[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner) + /// Does not get filtered here just in case merging or splitting is done + private void ProcessItems(Models.Metadata.DeviceRef[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) @@ -591,10 +591,6 @@ namespace SabreTools.DatFiles // Loop through the items and add foreach (var item in items) { - // If the item doesn't pass the filter - if (filterRunner != null && !filterRunner.Run(item)) - continue; - var datItem = new DeviceRef(item); datItem.SetFieldValue(DatItem.SourceKey, source); datItem.CopyMachineInformation(machine); @@ -1300,8 +1296,8 @@ namespace SabreTools.DatFiles /// Source to use with the converted items /// Index of the Source to use with the converted items /// True to only add item statistics while parsing, false otherwise - /// Optional FilterRunner to filter items on parse - private void ProcessItems(Models.Metadata.Slot[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly, FilterRunner? filterRunner) + /// Does not get filtered here just in case merging or splitting is done + private void ProcessItems(Models.Metadata.Slot[]? items, Machine machine, long machineIndex, Source source, long sourceIndex, bool statsOnly) { // If the array is null or empty, return without processing if (items == null || items.Length == 0) @@ -1310,10 +1306,6 @@ namespace SabreTools.DatFiles // Loop through the items and add foreach (var item in items) { - // If the item doesn't pass the filter - if (filterRunner != null && !filterRunner.Run(item)) - continue; - var datItem = new Slot(item); datItem.SetFieldValue(DatItem.SourceKey, source); datItem.CopyMachineInformation(machine); diff --git a/SabreTools.DatFiles/DatFile.Splitting.cs b/SabreTools.DatFiles/DatFile.Splitting.cs index ff904434..29250a4c 100644 --- a/SabreTools.DatFiles/DatFile.Splitting.cs +++ b/SabreTools.DatFiles/DatFile.Splitting.cs @@ -276,6 +276,7 @@ namespace SabreTools.DatFiles copyFrom = parentItems[0]; } + items = GetItemsForBucket(bucket); foreach (DatItem item in items) { // Special disk handling @@ -398,6 +399,7 @@ namespace SabreTools.DatFiles if (cloneOfMachine.Value == null) continue; + items = GetItemsForBucketDB(bucket); foreach (var item in items) { // Get the source for the current item @@ -640,26 +642,24 @@ namespace SabreTools.DatFiles if (deviceOnly ^ (datItems[0].GetMachine()!.GetBoolFieldValue(Models.Metadata.Machine.IsDeviceKey) == true)) continue; - // Get the first item for the machine + // Get the first item from the bucket DatItem copyFrom = datItems[0]; // Get all device reference names from the current machine - List deviceReferences = datItems + HashSet deviceReferences = []; + deviceReferences.UnionWith(datItems .FindAll(i => i is DeviceRef) .ConvertAll(i => i as DeviceRef) - .ConvertAll(dr => dr!.GetName()) - .Distinct() - .ToList(); + .ConvertAll(dr => dr!.GetName())); // Get all slot option names from the current machine - List slotOptions = datItems - .FindAll(i => i is Slot) - .ConvertAll(i => i as Slot) - .FindAll(s => s!.SlotOptionsSpecified) - .SelectMany(s => s!.GetFieldValue(Models.Metadata.Slot.SlotOptionKey)!) - .Select(so => so.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)) - .Distinct() - .ToList(); + HashSet slotOptions = []; + slotOptions.UnionWith(datItems + .FindAll(i => i is Slot) + .ConvertAll(i => i as Slot) + .FindAll(s => s!.SlotOptionsSpecified) + .SelectMany(s => s!.GetFieldValue(Models.Metadata.Slot.SlotOptionKey)!) + .Select(so => so.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey))); // If we're checking device references if (deviceReferences.Count > 0) @@ -689,6 +689,7 @@ namespace SabreTools.DatFiles // Clone the item and then add it DatItem datItem = (DatItem)item.Clone(); datItem.CopyMachineInformation(copyFrom); + datItems.Add(datItem); AddItem(datItem, statsOnly: false); } } @@ -699,6 +700,7 @@ namespace SabreTools.DatFiles { if (!deviceReferences.Contains(deviceReference)) { + deviceReferences.Add(deviceReference); var deviceRef = new DeviceRef(); deviceRef.SetName(deviceReference); deviceRef.CopyMachineInformation(copyFrom); @@ -737,6 +739,7 @@ namespace SabreTools.DatFiles // Clone the item and then add it DatItem datItem = (DatItem)item.Clone(); datItem.CopyMachineInformation(copyFrom); + datItems.Add(datItem); AddItem(datItem, statsOnly: false); } } @@ -747,8 +750,10 @@ namespace SabreTools.DatFiles { if (!slotOptions.Contains(slotOption)) { + slotOptions.Add(slotOption); var slotOptionItem = new SlotOption(); slotOptionItem.SetFieldValue(Models.Metadata.SlotOption.DevNameKey, slotOption); + slotOptionItem.CopyMachineInformation(copyFrom); var slotItem = new Slot(); slotItem.SetFieldValue(Models.Metadata.Slot.SlotOptionKey, [slotOptionItem]);