2025-01-12 23:56:48 -05:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2025-05-11 21:05:54 -04:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using SabreTools.Core;
|
|
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
using SabreTools.DatItems;
|
|
|
|
|
using SabreTools.DatItems.Formats;
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.DatFiles
|
|
|
|
|
{
|
|
|
|
|
public partial class DatFile
|
|
|
|
|
{
|
2025-01-13 15:41:57 -05:00
|
|
|
#region Splitting
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use cdevice_ref tags to get full non-merged sets and remove parenting tags
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>This is a destructive process and items will be removed</remarks>
|
|
|
|
|
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
|
2025-01-14 20:21:54 -05:00
|
|
|
BucketBy(ItemKey.Machine, norename: true);
|
2025-01-13 15:41:57 -05:00
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use cloneof tags to create merged sets and remove the tags plus deduplicating if tags don't catch everything
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>This is a destructive process and items will be removed</remarks>
|
|
|
|
|
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
|
2025-01-14 20:21:54 -05:00
|
|
|
BucketBy(ItemKey.Machine, norename: true);
|
2025-01-13 15:41:57 -05:00
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use cloneof tags to create non-merged sets and remove the tags plus using the device_ref tags to get full sets
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>This is a destructive process and items will be removed</remarks>
|
|
|
|
|
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
|
2025-01-14 20:21:54 -05:00
|
|
|
BucketBy(ItemKey.Machine, norename: true);
|
2025-01-13 15:41:57 -05:00
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use cloneof tags to create merged sets and remove the tags
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>This is a destructive process and items will be removed</remarks>
|
|
|
|
|
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
|
2025-01-14 20:21:54 -05:00
|
|
|
BucketBy(ItemKey.Machine, norename: true);
|
2025-01-13 15:41:57 -05:00
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use cloneof tags to create non-merged sets and remove the tags
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>This is a destructive process and items will be removed</remarks>
|
|
|
|
|
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
|
2025-01-14 20:21:54 -05:00
|
|
|
BucketBy(ItemKey.Machine, norename: true);
|
2025-01-13 15:41:57 -05:00
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use cloneof and romof tags to create split sets and remove the tags
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>This is a destructive process and items will be removed</remarks>
|
|
|
|
|
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
|
2025-01-14 20:21:54 -05:00
|
|
|
BucketBy(ItemKey.Machine, norename: true);
|
2025-01-13 15:41:57 -05:00
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
2025-01-13 15:32:17 -05:00
|
|
|
#region Splitting Steps
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-13 10:45:42 -05:00
|
|
|
/// Use cloneof tags to add items to the parents, removing the child sets in the process
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="subfolder">True to add DatItems to subfolder of parent (not including Disk), false otherwise</param>
|
|
|
|
|
/// <param name="skipDedup">True to skip checking for duplicate ROMs in parent, false otherwise</param>
|
2025-01-13 13:05:53 -05:00
|
|
|
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
|
2025-01-13 15:41:57 -05:00
|
|
|
internal void AddItemsFromChildren(bool subfolder, bool skipDedup)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 10:45:42 -05:00
|
|
|
AddItemsFromChildrenImpl(subfolder, skipDedup);
|
|
|
|
|
AddItemsFromChildrenImplDB(subfolder, skipDedup);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
2025-01-13 13:49:45 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Use cloneof tags to add items to the children, setting the new romof tag in the process
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
|
2025-01-13 15:41:57 -05:00
|
|
|
internal void AddItemsFromCloneOfParent()
|
2025-01-13 13:49:45 -05:00
|
|
|
{
|
|
|
|
|
AddItemsFromCloneOfParentImpl();
|
|
|
|
|
AddItemsFromCloneOfParentImplDB();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-12 23:56:48 -05:00
|
|
|
/// <summary>
|
2025-01-13 10:45:42 -05:00
|
|
|
/// Use device_ref and optionally slotoption tags to add items to the children
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
2025-01-13 14:35:50 -05:00
|
|
|
/// <param name="deviceOnly">True if only child device sets are touched, false for non-device sets</param>
|
2025-01-12 23:56:48 -05:00
|
|
|
/// <param name="useSlotOptions">True if slotoptions tags are used as well, false otherwise</param>
|
2025-01-13 13:05:53 -05:00
|
|
|
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
|
2025-01-13 15:41:57 -05:00
|
|
|
internal bool AddItemsFromDevices(bool deviceOnly, bool useSlotOptions)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 14:35:50 -05:00
|
|
|
bool foundnew = AddItemsFromDevicesImpl(deviceOnly, useSlotOptions);
|
|
|
|
|
foundnew |= AddItemsFromDevicesImplDB(deviceOnly, useSlotOptions);
|
2025-01-12 23:56:48 -05:00
|
|
|
return foundnew;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-13 13:43:38 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Use romof tags to add items to the children
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
|
2025-01-13 15:41:57 -05:00
|
|
|
internal void AddItemsFromRomOfParent()
|
2025-01-13 13:43:38 -05:00
|
|
|
{
|
|
|
|
|
AddItemsFromRomOfParentImpl();
|
|
|
|
|
AddItemsFromRomOfParentImplDB();
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove all BIOS and device sets
|
|
|
|
|
/// </summary>
|
2025-01-13 13:05:53 -05:00
|
|
|
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
|
2025-01-13 15:41:57 -05:00
|
|
|
internal void RemoveBiosAndDeviceSets()
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
RemoveBiosAndDeviceSetsImpl();
|
|
|
|
|
RemoveBiosAndDeviceSetsImplDB();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-13 13:02:17 -05:00
|
|
|
/// Use cloneof tags to remove items from the children
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
2025-01-13 13:05:53 -05:00
|
|
|
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
|
2025-01-13 15:41:57 -05:00
|
|
|
internal void RemoveItemsFromCloneOfChild()
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 13:02:17 -05:00
|
|
|
RemoveItemsFromCloneOfChildImpl();
|
|
|
|
|
RemoveItemsFromCloneOfChildImplDB();
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-13 13:02:17 -05:00
|
|
|
/// Use romof tags to remove bios items from children
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
2025-01-13 13:05:53 -05:00
|
|
|
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
|
2025-01-13 15:41:57 -05:00
|
|
|
internal void RemoveItemsFromRomOfChild()
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 15:46:06 -05:00
|
|
|
RemoveItemsFromRomOfChildImpl();
|
|
|
|
|
RemoveItemsFromRomOfChildImplDB();
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-13 10:45:42 -05:00
|
|
|
/// Remove all romof and cloneof tags from all machines
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
2025-01-13 13:05:53 -05:00
|
|
|
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
|
2025-01-13 15:41:57 -05:00
|
|
|
internal void RemoveMachineRelationshipTags()
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 09:12:07 -05:00
|
|
|
RemoveMachineRelationshipTagsImpl();
|
|
|
|
|
RemoveMachineRelationshipTagsImplDB();
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Splitting Implementations
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-13 10:45:42 -05:00
|
|
|
/// Use cloneof tags to add items to the parents, removing the child sets in the process
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="subfolder">True to add DatItems to subfolder of parent (not including Disk), false otherwise</param>
|
|
|
|
|
/// <param name="skipDedup">True to skip checking for duplicate ROMs in parent, false otherwise</param>
|
2025-01-13 09:27:01 -05:00
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="Items"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
2025-01-13 10:45:42 -05:00
|
|
|
private void AddItemsFromChildrenImpl(bool subfolder, bool skipDedup)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-05-03 23:36:15 -04:00
|
|
|
string[] buckets = [.. Items.SortedKeys];
|
|
|
|
|
foreach (string bucket in buckets)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 09:24:16 -05:00
|
|
|
// If the bucket has no items in it
|
2025-01-13 13:22:48 -05:00
|
|
|
List<DatItem> items = GetItemsForBucket(bucket);
|
|
|
|
|
if (items.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the machine
|
2025-05-02 16:46:20 -04:00
|
|
|
var machine = items[0].GetMachine();
|
2025-01-12 23:56:48 -05:00
|
|
|
if (machine == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-01-13 13:22:48 -05:00
|
|
|
// Get the cloneof parent items
|
2025-01-12 23:56:48 -05:00
|
|
|
string? cloneOf = machine.GetStringFieldValue(Models.Metadata.Machine.CloneOfKey);
|
2025-01-13 13:22:48 -05:00
|
|
|
List<DatItem> parentItems = GetItemsForBucket(cloneOf);
|
2025-01-13 16:36:00 -05:00
|
|
|
if (cloneOf == null)
|
|
|
|
|
continue;
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
// Otherwise, move the items from the current game to a subfolder of the parent game
|
|
|
|
|
DatItem copyFrom;
|
2025-01-13 13:22:48 -05:00
|
|
|
if (parentItems.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
copyFrom = new Rom();
|
2025-05-02 16:46:20 -04:00
|
|
|
copyFrom.GetMachine()!.SetName(cloneOf);
|
|
|
|
|
copyFrom.GetMachine()!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, cloneOf);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
copyFrom = parentItems[0];
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-14 12:48:14 -04:00
|
|
|
items = GetItemsForBucket(bucket);
|
2025-01-13 10:52:27 -05:00
|
|
|
foreach (DatItem item in items)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
// Special disk handling
|
|
|
|
|
if (item is Disk disk)
|
|
|
|
|
{
|
|
|
|
|
string? mergeTag = disk.GetStringFieldValue(Models.Metadata.Disk.MergeKey);
|
|
|
|
|
|
|
|
|
|
// If the merge tag exists and the parent already contains it, skip
|
2025-01-13 13:22:48 -05:00
|
|
|
if (mergeTag != null && GetItemsForBucket(cloneOf)
|
2025-01-12 23:56:48 -05:00
|
|
|
.FindAll(i => i is Disk)
|
2025-01-13 13:54:14 -05:00
|
|
|
.ConvertAll(i => (i as Disk)!.GetName())
|
|
|
|
|
.Contains(mergeTag))
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the merge tag exists but the parent doesn't contain it, add to parent
|
2025-01-13 13:22:48 -05:00
|
|
|
else if (mergeTag != null && !GetItemsForBucket(cloneOf)
|
2025-01-12 23:56:48 -05:00
|
|
|
.FindAll(i => i is Disk)
|
2025-01-13 13:54:14 -05:00
|
|
|
.ConvertAll(i => (i as Disk)!.GetName())
|
|
|
|
|
.Contains(mergeTag))
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
disk.CopyMachineInformation(copyFrom);
|
2025-01-14 15:32:14 -05:00
|
|
|
AddItem(disk, statsOnly: false);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If there is no merge tag, add to parent
|
2025-05-19 11:05:15 -04:00
|
|
|
else if (mergeTag == null && !GetItemsForBucket(cloneOf)
|
|
|
|
|
.FindAll(i => i is Disk)
|
|
|
|
|
.ConvertAll(i => (i as Disk)!.GetName())
|
|
|
|
|
.Contains(disk.GetName()))
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
disk.CopyMachineInformation(copyFrom);
|
2025-01-14 15:32:14 -05:00
|
|
|
AddItem(disk, statsOnly: false);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Special rom handling
|
|
|
|
|
else if (item is Rom rom)
|
|
|
|
|
{
|
2025-05-14 08:52:24 -04:00
|
|
|
string? mergeTag = rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey);
|
2025-05-12 08:54:45 -04:00
|
|
|
|
2025-01-12 23:56:48 -05:00
|
|
|
// If the merge tag exists and the parent already contains it, skip
|
2025-05-12 08:54:45 -04:00
|
|
|
if (mergeTag != null && GetItemsForBucket(cloneOf)
|
2025-01-12 23:56:48 -05:00
|
|
|
.FindAll(i => i is Rom)
|
|
|
|
|
.ConvertAll(i => (i as Rom)!.GetName())
|
2025-05-12 08:54:45 -04:00
|
|
|
.Contains(mergeTag))
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the merge tag exists but the parent doesn't contain it, add to subfolder of parent
|
2025-05-12 08:54:45 -04:00
|
|
|
else if (mergeTag != null && !GetItemsForBucket(cloneOf)
|
2025-01-12 23:56:48 -05:00
|
|
|
.FindAll(i => i is Rom)
|
|
|
|
|
.ConvertAll(i => (i as Rom)!.GetName())
|
2025-05-12 08:54:45 -04:00
|
|
|
.Contains(mergeTag))
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
if (subfolder)
|
2025-05-02 16:46:20 -04:00
|
|
|
rom.SetName($"{rom.GetMachine()!.GetName()}\\{rom.GetName()}");
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
rom.CopyMachineInformation(copyFrom);
|
2025-01-14 15:32:14 -05:00
|
|
|
AddItem(rom, statsOnly: false);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the parent doesn't already contain this item, add to subfolder of parent
|
2025-01-13 13:22:48 -05:00
|
|
|
else if (!GetItemsForBucket(cloneOf).Contains(item) || skipDedup)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
if (subfolder)
|
2025-05-02 16:46:20 -04:00
|
|
|
rom.SetName($"{item.GetMachine()!.GetName()}\\{rom.GetName()}");
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
rom.CopyMachineInformation(copyFrom);
|
2025-01-14 15:32:14 -05:00
|
|
|
AddItem(rom, statsOnly: false);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// All other that would be missing to subfolder of parent
|
2025-01-13 13:22:48 -05:00
|
|
|
else if (!GetItemsForBucket(cloneOf).Contains(item))
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
if (subfolder)
|
2025-05-02 16:46:20 -04:00
|
|
|
item.SetName($"{item.GetMachine()!.GetName()}\\{item.GetName()}");
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
item.CopyMachineInformation(copyFrom);
|
2025-01-14 15:32:14 -05:00
|
|
|
AddItem(item, statsOnly: false);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Then, remove the old game so it's not picked up by the writer
|
2025-01-14 15:32:14 -05:00
|
|
|
RemoveBucket(bucket);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-13 10:45:42 -05:00
|
|
|
/// Use cloneof tags to add items to the parents, removing the child sets in the process
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="subfolder">True to add DatItems to subfolder of parent (not including Disk), false otherwise</param>
|
|
|
|
|
/// <param name="skipDedup">True to skip checking for duplicate ROMs in parent, false otherwise</param>
|
2025-01-13 09:27:01 -05:00
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="ItemsDB"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
2025-01-13 10:45:42 -05:00
|
|
|
private void AddItemsFromChildrenImplDB(bool subfolder, bool skipDedup)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. ItemsDB.SortedKeys];
|
2025-01-13 09:24:16 -05:00
|
|
|
foreach (string bucket in buckets)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 09:24:16 -05:00
|
|
|
// If the bucket has no items in it
|
2025-01-13 13:22:48 -05:00
|
|
|
Dictionary<long, DatItem> items = GetItemsForBucketDB(bucket);
|
|
|
|
|
if (items.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the machine for the first item
|
2025-02-24 09:20:46 -05:00
|
|
|
var machine = GetMachineForItemDB(items.First().Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
if (machine.Value == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the clone parent
|
|
|
|
|
string? cloneOf = machine.Value.GetStringFieldValue(Models.Metadata.Machine.CloneOfKey);
|
|
|
|
|
if (string.IsNullOrEmpty(cloneOf))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the clone parent machine
|
|
|
|
|
var cloneOfMachine = ItemsDB.GetMachine(cloneOf);
|
|
|
|
|
if (cloneOfMachine.Value == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-05-14 12:48:14 -04:00
|
|
|
items = GetItemsForBucketDB(bucket);
|
2025-01-12 23:56:48 -05:00
|
|
|
foreach (var item in items)
|
|
|
|
|
{
|
2025-01-14 21:02:37 -05:00
|
|
|
// Get the source for the current item
|
2025-02-24 09:20:46 -05:00
|
|
|
var source = GetSourceForItemDB(item.Key);
|
2025-01-14 21:02:37 -05:00
|
|
|
|
2025-01-12 23:56:48 -05:00
|
|
|
// Get the parent items and current machine name
|
2025-01-13 13:22:48 -05:00
|
|
|
Dictionary<long, DatItem> parentItems = GetItemsForBucketDB(cloneOf);
|
|
|
|
|
if (parentItems.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
2025-02-24 09:20:46 -05:00
|
|
|
string? machineName = GetMachineForItemDB(item.Key).Value?
|
2025-05-02 16:05:08 -04:00
|
|
|
.GetName();
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
// Special disk handling
|
|
|
|
|
if (item.Value is Disk disk)
|
|
|
|
|
{
|
|
|
|
|
string? mergeTag = disk.GetStringFieldValue(Models.Metadata.Disk.MergeKey);
|
|
|
|
|
|
|
|
|
|
// If the merge tag exists and the parent already contains it, skip
|
2025-01-13 16:36:00 -05:00
|
|
|
if (mergeTag != null && GetItemsForBucketDB(cloneOf).Values
|
2025-01-12 23:56:48 -05:00
|
|
|
.Where(i => i is Disk)
|
|
|
|
|
.Select(i => (i as Disk)!.GetName())
|
|
|
|
|
.Contains(mergeTag))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the merge tag exists but the parent doesn't contain it, add to parent
|
2025-01-13 16:36:00 -05:00
|
|
|
else if (mergeTag != null && !GetItemsForBucketDB(cloneOf).Values
|
2025-01-12 23:56:48 -05:00
|
|
|
.Where(i => i is Disk)
|
|
|
|
|
.Select(i => (i as Disk)!.GetName())
|
|
|
|
|
.Contains(mergeTag))
|
|
|
|
|
{
|
2025-01-14 21:02:37 -05:00
|
|
|
ItemsDB.RemapDatItemToMachine(item.Key, cloneOfMachine.Key);
|
|
|
|
|
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If there is no merge tag, add to parent
|
2025-05-19 11:05:15 -04:00
|
|
|
else if (mergeTag == null && !GetItemsForBucketDB(cloneOf).Values
|
|
|
|
|
.Where(i => i is Disk)
|
|
|
|
|
.Select(i => (i as Disk)!.GetName())
|
|
|
|
|
.Contains(disk.GetName()))
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-14 21:02:37 -05:00
|
|
|
ItemsDB.RemapDatItemToMachine(item.Key, cloneOfMachine.Key);
|
|
|
|
|
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Special rom handling
|
|
|
|
|
else if (item.Value is Rom rom)
|
|
|
|
|
{
|
2025-05-12 08:54:45 -04:00
|
|
|
string? mergeTag = rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey);
|
|
|
|
|
|
2025-01-12 23:56:48 -05:00
|
|
|
// If the merge tag exists and the parent already contains it, skip
|
2025-05-12 08:54:45 -04:00
|
|
|
if (mergeTag != null && GetItemsForBucketDB(cloneOf).Values
|
2025-01-12 23:56:48 -05:00
|
|
|
.Where(i => i is Rom)
|
|
|
|
|
.Select(i => (i as Rom)!.GetName())
|
2025-05-12 08:54:45 -04:00
|
|
|
.Contains(mergeTag))
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the merge tag exists but the parent doesn't contain it, add to subfolder of parent
|
2025-05-12 08:54:45 -04:00
|
|
|
else if (mergeTag != null && !GetItemsForBucketDB(cloneOf).Values
|
2025-01-12 23:56:48 -05:00
|
|
|
.Where(i => i is Rom)
|
|
|
|
|
.Select(i => (i as Rom)!.GetName())
|
2025-05-12 08:54:45 -04:00
|
|
|
.Contains(mergeTag))
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
if (subfolder)
|
|
|
|
|
rom.SetName($"{machineName}\\{rom.GetName()}");
|
|
|
|
|
|
2025-01-14 21:02:37 -05:00
|
|
|
ItemsDB.RemapDatItemToMachine(item.Key, machineIndex: cloneOfMachine.Key);
|
|
|
|
|
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the parent doesn't already contain this item, add to subfolder of parent
|
2025-01-13 16:36:00 -05:00
|
|
|
else if (!GetItemsForBucketDB(cloneOf).Values.Contains(item.Value) || skipDedup)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
if (subfolder)
|
|
|
|
|
rom.SetName($"{machineName}\\{rom.GetName()}");
|
|
|
|
|
|
2025-01-14 21:02:37 -05:00
|
|
|
ItemsDB.RemapDatItemToMachine(item.Key, cloneOfMachine.Key);
|
|
|
|
|
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// All other that would be missing to subfolder of parent
|
2025-01-13 16:36:00 -05:00
|
|
|
else if (!GetItemsForBucketDB(cloneOf).Values.Contains(item.Value))
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
if (subfolder)
|
|
|
|
|
item.Value.SetName($"{machineName}\\{item.Value.GetName()}");
|
|
|
|
|
|
2025-01-14 21:02:37 -05:00
|
|
|
ItemsDB.RemapDatItemToMachine(item.Key, cloneOfMachine.Key);
|
|
|
|
|
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:02:37 -05:00
|
|
|
// Remove the current item
|
2025-01-14 22:34:58 -05:00
|
|
|
RemoveItemDB(item.Key);
|
2025-01-14 21:02:37 -05:00
|
|
|
}
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-13 13:49:45 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Use cloneof tags to add items to the children, setting the new romof tag in the process
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="Items"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
private void AddItemsFromCloneOfParentImpl()
|
|
|
|
|
{
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. Items.SortedKeys];
|
2025-05-03 23:36:15 -04:00
|
|
|
foreach (string bucket in buckets)
|
2025-01-13 13:49:45 -05:00
|
|
|
{
|
|
|
|
|
// If the bucket has no items in it
|
|
|
|
|
List<DatItem> items = GetItemsForBucket(bucket);
|
|
|
|
|
if (items.Count == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the machine
|
2025-05-02 16:46:20 -04:00
|
|
|
var machine = items[0].GetMachine();
|
2025-01-13 13:49:45 -05:00
|
|
|
if (machine == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the cloneof parent items
|
|
|
|
|
string? cloneOf = machine.GetStringFieldValue(Models.Metadata.Machine.CloneOfKey);
|
|
|
|
|
List<DatItem> parentItems = GetItemsForBucket(cloneOf);
|
|
|
|
|
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);
|
2025-01-13 13:54:14 -05:00
|
|
|
if (!items.Exists(i => string.Equals(i.GetName(), datItem.GetName(), StringComparison.OrdinalIgnoreCase))
|
2025-01-13 13:49:45 -05:00
|
|
|
&& !items.Contains(datItem))
|
|
|
|
|
{
|
2025-01-14 15:32:14 -05:00
|
|
|
AddItem(datItem, statsOnly: false);
|
2025-01-13 13:49:45 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now we want to get the parent romof tag and put it in each of the items
|
|
|
|
|
items = GetItemsForBucket(bucket);
|
2025-05-02 16:46:20 -04:00
|
|
|
string? romof = GetItemsForBucket(cloneOf)[0].GetMachine()!.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
|
2025-01-13 13:49:45 -05:00
|
|
|
foreach (DatItem item in items)
|
|
|
|
|
{
|
2025-05-02 16:46:20 -04:00
|
|
|
item.GetMachine()!.SetFieldValue<string?>(Models.Metadata.Machine.RomOfKey, romof);
|
2025-01-13 13:49:45 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use cloneof tags to add items to the children, setting the new romof tag in the process
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="ItemsDB"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
private void AddItemsFromCloneOfParentImplDB()
|
|
|
|
|
{
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. ItemsDB.SortedKeys];
|
2025-01-13 13:49:45 -05:00
|
|
|
foreach (string bucket in buckets)
|
|
|
|
|
{
|
|
|
|
|
// If the bucket has no items in it
|
|
|
|
|
Dictionary<long, DatItem> items = GetItemsForBucketDB(bucket);
|
|
|
|
|
if (items.Count == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the source for the first item
|
2025-02-24 09:20:46 -05:00
|
|
|
var source = GetSourceForItemDB(items.First().Key);
|
2025-01-13 13:49:45 -05:00
|
|
|
|
|
|
|
|
// Get the machine for the first item in the list
|
2025-02-24 09:20:46 -05:00
|
|
|
var machine = GetMachineForItemDB(items.First().Key);
|
2025-01-13 13:49:45 -05:00
|
|
|
if (machine.Value == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the clone parent
|
|
|
|
|
string? cloneOf = machine.Value.GetStringFieldValue(Models.Metadata.Machine.CloneOfKey);
|
|
|
|
|
if (string.IsNullOrEmpty(cloneOf))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// If the parent doesn't have any items, we want to continue
|
|
|
|
|
Dictionary<long, DatItem> parentItems = GetItemsForBucketDB(cloneOf);
|
|
|
|
|
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.Values.Any(i => i.GetName()?.ToLowerInvariant() == datItem.GetName()?.ToLowerInvariant())
|
|
|
|
|
&& items.Values.Any(i => i == datItem))
|
|
|
|
|
{
|
|
|
|
|
ItemsDB.AddItem(datItem, machine.Key, source.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the parent machine
|
2025-02-24 09:20:46 -05:00
|
|
|
var parentMachine = GetMachineForItemDB(GetItemsForBucketDB(cloneOf).First().Key);
|
2025-01-13 13:49:45 -05:00
|
|
|
if (parentMachine.Value == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Now we want to get the parent romof tag and put it in each of the items
|
|
|
|
|
items = GetItemsForBucketDB(bucket);
|
|
|
|
|
string? romof = parentMachine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
|
|
|
|
|
foreach (var key in items.Keys)
|
|
|
|
|
{
|
2025-02-24 09:20:46 -05:00
|
|
|
var itemMachine = GetMachineForItemDB(key);
|
2025-01-13 13:49:45 -05:00
|
|
|
if (itemMachine.Value == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-05-12 12:09:22 -04:00
|
|
|
// TODO: Remove merge tags here
|
2025-01-13 13:49:45 -05:00
|
|
|
itemMachine.Value.SetFieldValue<string?>(Models.Metadata.Machine.RomOfKey, romof);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-12 23:56:48 -05:00
|
|
|
/// <summary>
|
2025-01-13 10:45:42 -05:00
|
|
|
/// Use device_ref and optionally slotoption tags to add items to the children
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
2025-01-13 17:13:30 -05:00
|
|
|
/// <param name="deviceOnly">True if only child device sets are touched, false for non-device sets</param>
|
2025-01-12 23:56:48 -05:00
|
|
|
/// <param name="useSlotOptions">True if slotoptions tags are used as well, false otherwise</param>
|
2025-01-13 09:24:16 -05:00
|
|
|
/// <returns>True if any items were processed, false otherwise</returns>
|
2025-01-13 09:27:01 -05:00
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="Items"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
2025-01-13 16:02:57 -05:00
|
|
|
private bool AddItemsFromDevicesImpl(bool deviceOnly, bool useSlotOptions)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
bool foundnew = false;
|
2025-05-03 23:36:15 -04:00
|
|
|
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. Items.SortedKeys];
|
2025-05-03 23:36:15 -04:00
|
|
|
foreach (string bucket in buckets)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 09:24:16 -05:00
|
|
|
// If the bucket doesn't have items
|
2025-01-13 13:22:48 -05:00
|
|
|
List<DatItem> datItems = GetItemsForBucket(bucket);
|
|
|
|
|
if (datItems.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// If the machine (is/is not) a device, we want to continue
|
2025-05-02 16:46:20 -04:00
|
|
|
if (deviceOnly ^ (datItems[0].GetMachine()!.GetBoolFieldValue(Models.Metadata.Machine.IsDeviceKey) == true))
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
2025-05-14 12:48:14 -04:00
|
|
|
// Get the first item from the bucket
|
2025-05-13 09:39:10 -04:00
|
|
|
DatItem copyFrom = datItems[0];
|
|
|
|
|
|
2025-01-12 23:56:48 -05:00
|
|
|
// Get all device reference names from the current machine
|
2025-05-14 12:48:14 -04:00
|
|
|
HashSet<string?> deviceReferences = [];
|
|
|
|
|
deviceReferences.UnionWith(datItems
|
2025-01-12 23:56:48 -05:00
|
|
|
.FindAll(i => i is DeviceRef)
|
|
|
|
|
.ConvertAll(i => i as DeviceRef)
|
2025-05-14 12:48:14 -04:00
|
|
|
.ConvertAll(dr => dr!.GetName()));
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
// Get all slot option names from the current machine
|
2025-05-14 12:48:14 -04:00
|
|
|
HashSet<string?> slotOptions = [];
|
|
|
|
|
slotOptions.UnionWith(datItems
|
|
|
|
|
.FindAll(i => i is Slot)
|
|
|
|
|
.ConvertAll(i => i as Slot)
|
|
|
|
|
.FindAll(s => s!.SlotOptionsSpecified)
|
|
|
|
|
.SelectMany(s => s!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!)
|
|
|
|
|
.Select(so => so.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)));
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
// If we're checking device references
|
|
|
|
|
if (deviceReferences.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
// Loop through all names and check the corresponding machines
|
|
|
|
|
var newDeviceReferences = new HashSet<string>();
|
|
|
|
|
foreach (string? deviceReference in deviceReferences)
|
|
|
|
|
{
|
|
|
|
|
// Add to the list of new device reference names
|
2025-01-13 13:22:48 -05:00
|
|
|
List<DatItem> devItems = GetItemsForBucket(deviceReference);
|
|
|
|
|
if (devItems.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
newDeviceReferences.UnionWith(devItems
|
|
|
|
|
.FindAll(i => i is DeviceRef)
|
|
|
|
|
.ConvertAll(i => (i as DeviceRef)!.GetName()!));
|
|
|
|
|
|
|
|
|
|
// Set new machine information and add to the current machine
|
|
|
|
|
foreach (DatItem item in devItems)
|
|
|
|
|
{
|
|
|
|
|
// If the parent machine doesn't already contain this item, add it
|
|
|
|
|
if (!datItems.Exists(i => i.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) && i.GetName() == item.GetName()))
|
|
|
|
|
{
|
|
|
|
|
// Set that we found new items
|
|
|
|
|
foundnew = true;
|
|
|
|
|
|
|
|
|
|
// Clone the item and then add it
|
|
|
|
|
DatItem datItem = (DatItem)item.Clone();
|
|
|
|
|
datItem.CopyMachineInformation(copyFrom);
|
2025-05-14 12:48:14 -04:00
|
|
|
datItems.Add(datItem);
|
2025-01-14 15:32:14 -05:00
|
|
|
AddItem(datItem, statsOnly: false);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now that every device reference is accounted for, add the new list of device references, if they don't already exist
|
|
|
|
|
foreach (string deviceReference in newDeviceReferences)
|
|
|
|
|
{
|
|
|
|
|
if (!deviceReferences.Contains(deviceReference))
|
|
|
|
|
{
|
2025-05-14 12:48:14 -04:00
|
|
|
deviceReferences.Add(deviceReference);
|
2025-01-12 23:56:48 -05:00
|
|
|
var deviceRef = new DeviceRef();
|
|
|
|
|
deviceRef.SetName(deviceReference);
|
2025-05-13 09:39:10 -04:00
|
|
|
deviceRef.CopyMachineInformation(copyFrom);
|
|
|
|
|
Items.AddItem(deviceRef, statsOnly: false);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we're checking slotoptions
|
|
|
|
|
if (useSlotOptions && slotOptions.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
// Loop through all names and check the corresponding machines
|
|
|
|
|
var newSlotOptions = new HashSet<string>();
|
|
|
|
|
foreach (string? slotOption in slotOptions)
|
|
|
|
|
{
|
|
|
|
|
// Add to the list of new slot option names
|
2025-01-13 13:22:48 -05:00
|
|
|
List<DatItem> slotItems = GetItemsForBucket(slotOption);
|
|
|
|
|
if (slotItems.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
newSlotOptions.UnionWith(slotItems
|
|
|
|
|
.FindAll(i => i is Slot)
|
|
|
|
|
.FindAll(s => (s as Slot)!.SlotOptionsSpecified)
|
|
|
|
|
.SelectMany(s => (s as Slot)!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!)
|
|
|
|
|
.Select(o => o.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)!));
|
|
|
|
|
|
|
|
|
|
// Set new machine information and add to the current machine
|
|
|
|
|
foreach (DatItem item in slotItems)
|
|
|
|
|
{
|
|
|
|
|
// If the parent machine doesn't already contain this item, add it
|
|
|
|
|
if (!datItems.Exists(i => i.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) && i.GetName() == item.GetName()))
|
|
|
|
|
{
|
|
|
|
|
// Set that we found new items
|
|
|
|
|
foundnew = true;
|
|
|
|
|
|
|
|
|
|
// Clone the item and then add it
|
|
|
|
|
DatItem datItem = (DatItem)item.Clone();
|
|
|
|
|
datItem.CopyMachineInformation(copyFrom);
|
2025-05-14 12:48:14 -04:00
|
|
|
datItems.Add(datItem);
|
2025-01-14 15:32:14 -05:00
|
|
|
AddItem(datItem, statsOnly: false);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now that every device is accounted for, add the new list of slot options, if they don't already exist
|
|
|
|
|
foreach (string slotOption in newSlotOptions)
|
|
|
|
|
{
|
|
|
|
|
if (!slotOptions.Contains(slotOption))
|
|
|
|
|
{
|
2025-05-14 12:48:14 -04:00
|
|
|
slotOptions.Add(slotOption);
|
2025-01-12 23:56:48 -05:00
|
|
|
var slotOptionItem = new SlotOption();
|
|
|
|
|
slotOptionItem.SetFieldValue<string?>(Models.Metadata.SlotOption.DevNameKey, slotOption);
|
2025-05-14 12:48:14 -04:00
|
|
|
slotOptionItem.CopyMachineInformation(copyFrom);
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
var slotItem = new Slot();
|
|
|
|
|
slotItem.SetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey, [slotOptionItem]);
|
2025-05-13 09:39:10 -04:00
|
|
|
slotItem.CopyMachineInformation(copyFrom);
|
2025-01-12 23:56:48 -05:00
|
|
|
|
2025-05-13 09:39:10 -04:00
|
|
|
Items.AddItem(slotItem, statsOnly: false);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return foundnew;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-13 10:45:42 -05:00
|
|
|
/// Use device_ref and optionally slotoption tags to add items to the children
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
2025-01-13 16:02:57 -05:00
|
|
|
/// <param name="deviceOnly">True if only child device sets are touched, false for non-device sets</param>
|
2025-01-12 23:56:48 -05:00
|
|
|
/// <param name="useSlotOptions">True if slotoptions tags are used as well, false otherwise</param>
|
2025-01-13 09:24:16 -05:00
|
|
|
/// <returns>True if any items were processed, false otherwise</returns>
|
2025-01-13 09:27:01 -05:00
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="ItemsDB"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
2025-01-13 16:02:57 -05:00
|
|
|
private bool AddItemsFromDevicesImplDB(bool deviceOnly, bool useSlotOptions)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
|
|
|
|
bool foundnew = false;
|
2025-05-03 23:36:15 -04:00
|
|
|
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. ItemsDB.SortedKeys];
|
2025-01-13 09:24:16 -05:00
|
|
|
foreach (string bucket in buckets)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 09:24:16 -05:00
|
|
|
// If the bucket has no items in it
|
2025-01-13 13:22:48 -05:00
|
|
|
Dictionary<long, DatItem> items = GetItemsForBucketDB(bucket);
|
|
|
|
|
if (items.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the source for the first item
|
2025-02-24 09:20:46 -05:00
|
|
|
var source = GetSourceForItemDB(items.First().Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
// Get the machine for the first item
|
2025-02-24 09:20:46 -05:00
|
|
|
var machine = GetMachineForItemDB(items.First().Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
if (machine.Value == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// If the machine (is/is not) a device, we want to continue
|
2025-01-13 16:02:57 -05:00
|
|
|
if (deviceOnly ^ (machine.Value.GetBoolFieldValue(Models.Metadata.Machine.IsDeviceKey) == true))
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get all device reference names from the current machine
|
|
|
|
|
List<string?> deviceReferences = items.Values
|
|
|
|
|
.Where(i => i is DeviceRef)
|
|
|
|
|
.Select(i => i as DeviceRef)
|
|
|
|
|
.Select(dr => dr!.GetName())
|
|
|
|
|
.Distinct()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
// Get all slot option names from the current machine
|
|
|
|
|
List<string?> slotOptions = items.Values
|
|
|
|
|
.Where(i => i is Slot)
|
|
|
|
|
.Select(i => i as Slot)
|
|
|
|
|
.Where(s => s!.SlotOptionsSpecified)
|
|
|
|
|
.SelectMany(s => s!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!)
|
|
|
|
|
.Select(so => so.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey))
|
|
|
|
|
.Distinct()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
// If we're checking device references
|
|
|
|
|
if (deviceReferences.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
// Loop through all names and check the corresponding machines
|
|
|
|
|
var newDeviceReferences = new HashSet<string>();
|
|
|
|
|
foreach (string? deviceReference in deviceReferences)
|
|
|
|
|
{
|
|
|
|
|
// If the device reference is invalid
|
|
|
|
|
if (deviceReference == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// If the machine doesn't exist then we continue
|
2025-01-13 13:22:48 -05:00
|
|
|
Dictionary<long, DatItem> devItems = GetItemsForBucketDB(deviceReference);
|
|
|
|
|
if (devItems.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Add to the list of new device reference names
|
|
|
|
|
newDeviceReferences.UnionWith(devItems.Values
|
|
|
|
|
.Where(i => i is DeviceRef)
|
|
|
|
|
.Select(i => (i as DeviceRef)!.GetName()!));
|
|
|
|
|
|
|
|
|
|
// Set new machine information and add to the current machine
|
2025-02-24 09:20:46 -05:00
|
|
|
var copyFrom = GetMachineForItemDB(items.First().Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
if (copyFrom.Value == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
foreach (var item in devItems.Values)
|
|
|
|
|
{
|
|
|
|
|
// If the parent machine doesn't already contain this item, add it
|
|
|
|
|
if (!items.Values.Any(i => i.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey)
|
|
|
|
|
&& i.GetName() == item.GetName()))
|
|
|
|
|
{
|
|
|
|
|
// Set that we found new items
|
|
|
|
|
foundnew = true;
|
|
|
|
|
|
|
|
|
|
// Clone the item and then add it
|
2025-01-13 13:31:14 -05:00
|
|
|
DatItem datItem = (DatItem)item.Clone();
|
2025-01-12 23:56:48 -05:00
|
|
|
ItemsDB.AddItem(datItem, machine.Key, source.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now that every device reference is accounted for, add the new list of device references, if they don't already exist
|
|
|
|
|
foreach (string deviceReference in newDeviceReferences)
|
|
|
|
|
{
|
|
|
|
|
if (!deviceReferences.Contains(deviceReference))
|
|
|
|
|
{
|
|
|
|
|
var deviceRef = new DeviceRef();
|
|
|
|
|
deviceRef.SetName(deviceReference);
|
|
|
|
|
ItemsDB.AddItem(deviceRef, machine.Key, source.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we're checking slotoptions
|
|
|
|
|
if (useSlotOptions && slotOptions.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
// Loop through all names and check the corresponding machines
|
|
|
|
|
var newSlotOptions = new HashSet<string>();
|
|
|
|
|
foreach (string? slotOption in slotOptions)
|
|
|
|
|
{
|
|
|
|
|
// If the slot option is invalid
|
|
|
|
|
if (slotOption == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// If the machine doesn't exist then we continue
|
2025-01-13 13:22:48 -05:00
|
|
|
Dictionary<long, DatItem> slotItems = GetItemsForBucketDB(slotOption);
|
|
|
|
|
if (slotItems.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Add to the list of new slot option names
|
|
|
|
|
newSlotOptions.UnionWith(slotItems.Values
|
|
|
|
|
.Where(i => i is Slot)
|
|
|
|
|
.Where(s => (s as Slot)!.SlotOptionsSpecified)
|
|
|
|
|
.SelectMany(s => (s as Slot)!.GetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey)!)
|
|
|
|
|
.Select(o => o.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)!));
|
|
|
|
|
|
|
|
|
|
// Set new machine information and add to the current machine
|
2025-02-24 09:20:46 -05:00
|
|
|
var copyFrom = GetMachineForItemDB(GetItemsForBucketDB(bucket).First().Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
if (copyFrom.Value == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
foreach (var item in slotItems.Values)
|
|
|
|
|
{
|
|
|
|
|
// If the parent machine doesn't already contain this item, add it
|
|
|
|
|
if (!items.Values.Any(i => i.GetStringFieldValue(Models.Metadata.DatItem.TypeKey) == item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey)
|
|
|
|
|
&& i.GetName() == item.GetName()))
|
|
|
|
|
{
|
|
|
|
|
// Set that we found new items
|
|
|
|
|
foundnew = true;
|
|
|
|
|
|
|
|
|
|
// Clone the item and then add it
|
2025-01-13 13:31:14 -05:00
|
|
|
DatItem datItem = (DatItem)item.Clone();
|
2025-01-12 23:56:48 -05:00
|
|
|
ItemsDB.AddItem(datItem, machine.Key, source.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now that every device is accounted for, add the new list of slot options, if they don't already exist
|
|
|
|
|
foreach (string slotOption in newSlotOptions)
|
|
|
|
|
{
|
|
|
|
|
if (!slotOptions.Contains(slotOption))
|
|
|
|
|
{
|
|
|
|
|
var slotOptionItem = new SlotOption();
|
|
|
|
|
slotOptionItem.SetFieldValue<string?>(Models.Metadata.SlotOption.DevNameKey, slotOption);
|
|
|
|
|
|
|
|
|
|
var slotItem = new Slot();
|
|
|
|
|
slotItem.SetFieldValue<SlotOption[]?>(Models.Metadata.Slot.SlotOptionKey, [slotOptionItem]);
|
|
|
|
|
|
|
|
|
|
ItemsDB.AddItem(slotItem, machine.Key, source.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return foundnew;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-13 13:43:38 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Use romof tags to add items to the children
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="Items"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
private void AddItemsFromRomOfParentImpl()
|
|
|
|
|
{
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. Items.SortedKeys];
|
2025-05-03 23:36:15 -04:00
|
|
|
foreach (string bucket in buckets)
|
2025-01-13 13:43:38 -05:00
|
|
|
{
|
|
|
|
|
// If the bucket has no items in it
|
|
|
|
|
List<DatItem> items = GetItemsForBucket(bucket);
|
|
|
|
|
if (items.Count == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the machine
|
2025-05-02 16:46:20 -04:00
|
|
|
var machine = items[0].GetMachine();
|
2025-01-13 13:43:38 -05:00
|
|
|
if (machine == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the romof parent items
|
|
|
|
|
string? romOf = machine.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
|
|
|
|
|
List<DatItem> 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);
|
2025-01-13 13:54:14 -05:00
|
|
|
if (!items.Exists(i => i.GetName() == datItem.GetName()) && !items.Contains(datItem))
|
2025-01-14 15:32:14 -05:00
|
|
|
AddItem(datItem, statsOnly: false);
|
2025-01-13 13:43:38 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use romof tags to add items to the children
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="ItemsDB"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
private void AddItemsFromRomOfParentImplDB()
|
|
|
|
|
{
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. ItemsDB.SortedKeys];
|
2025-01-13 13:43:38 -05:00
|
|
|
foreach (string bucket in buckets)
|
|
|
|
|
{
|
|
|
|
|
// If the bucket has no items in it
|
|
|
|
|
Dictionary<long, DatItem> items = GetItemsForBucketDB(bucket);
|
|
|
|
|
if (items.Count == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the source for the first item
|
2025-02-24 09:20:46 -05:00
|
|
|
var source = GetSourceForItemDB(items.First().Key);
|
2025-01-13 13:43:38 -05:00
|
|
|
|
|
|
|
|
// Get the machine for the first item
|
2025-02-24 09:20:46 -05:00
|
|
|
var machine = GetMachineForItemDB(items.First().Key);
|
2025-01-13 13:43:38 -05:00
|
|
|
if (machine.Value == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the romof parent items
|
|
|
|
|
string? romOf = machine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
|
|
|
|
|
Dictionary<long, DatItem> 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-12 23:56:48 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Remove all BIOS and device sets
|
|
|
|
|
/// </summary>
|
2025-01-13 09:27:01 -05:00
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="Items"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
2025-01-12 23:56:48 -05:00
|
|
|
private void RemoveBiosAndDeviceSetsImpl()
|
|
|
|
|
{
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. Items.SortedKeys];
|
2025-05-11 21:29:34 -04:00
|
|
|
|
|
|
|
|
#if NET452_OR_GREATER || NETCOREAPP
|
|
|
|
|
Parallel.ForEach(buckets, Globals.ParallelOptions, bucket =>
|
|
|
|
|
#elif NET40_OR_GREATER
|
|
|
|
|
Parallel.ForEach(buckets, bucket =>
|
|
|
|
|
#else
|
2025-05-03 23:36:15 -04:00
|
|
|
foreach (string bucket in buckets)
|
2025-05-11 21:29:34 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 09:24:16 -05:00
|
|
|
// If the bucket has no items in it
|
2025-01-13 13:22:48 -05:00
|
|
|
List<DatItem> items = GetItemsForBucket(bucket);
|
|
|
|
|
if (items.Count == 0)
|
2025-05-11 21:29:34 -04:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
|
|
|
|
return;
|
|
|
|
|
#else
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
2025-05-11 21:29:34 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
// Get the machine
|
2025-05-02 16:46:20 -04:00
|
|
|
var machine = items[0].GetMachine();
|
2025-01-12 23:56:48 -05:00
|
|
|
if (machine == null)
|
2025-05-11 21:29:34 -04:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
|
|
|
|
return;
|
|
|
|
|
#else
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
2025-05-11 21:29:34 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
// Remove flagged items
|
|
|
|
|
if ((machine.GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) == true)
|
|
|
|
|
|| (machine.GetBoolFieldValue(Models.Metadata.Machine.IsDeviceKey) == true))
|
|
|
|
|
{
|
2025-01-14 15:32:14 -05:00
|
|
|
RemoveBucket(bucket);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
2025-05-11 21:29:34 -04:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
|
|
|
|
});
|
|
|
|
|
#else
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
2025-05-11 21:29:34 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove all BIOS and device sets
|
|
|
|
|
/// </summary>
|
2025-01-13 09:27:01 -05:00
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="ItemsDB"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
2025-01-12 23:56:48 -05:00
|
|
|
private void RemoveBiosAndDeviceSetsImplDB()
|
|
|
|
|
{
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. ItemsDB.SortedKeys];
|
2025-05-11 21:29:34 -04:00
|
|
|
|
|
|
|
|
#if NET452_OR_GREATER || NETCOREAPP
|
|
|
|
|
Parallel.ForEach(buckets, Globals.ParallelOptions, bucket =>
|
|
|
|
|
#elif NET40_OR_GREATER
|
|
|
|
|
Parallel.ForEach(buckets, bucket =>
|
|
|
|
|
#else
|
2025-01-13 09:24:16 -05:00
|
|
|
foreach (string bucket in buckets)
|
2025-05-11 21:29:34 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 09:24:16 -05:00
|
|
|
// If the bucket has no items in it
|
2025-01-13 13:22:48 -05:00
|
|
|
Dictionary<long, DatItem> items = GetItemsForBucketDB(bucket);
|
|
|
|
|
if (items.Count == 0)
|
2025-05-11 21:29:34 -04:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
|
|
|
|
return;
|
|
|
|
|
#else
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
2025-05-11 21:29:34 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
// Get the machine
|
2025-02-24 09:20:46 -05:00
|
|
|
var machine = GetMachineForItemDB(items.First().Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
if (machine.Value == null)
|
2025-05-11 21:29:34 -04:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
|
|
|
|
return;
|
|
|
|
|
#else
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
2025-05-11 21:29:34 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
// Remove flagged items
|
|
|
|
|
if ((machine.Value.GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) == true)
|
|
|
|
|
|| (machine.Value.GetBoolFieldValue(Models.Metadata.Machine.IsDeviceKey) == true))
|
|
|
|
|
{
|
|
|
|
|
foreach (var key in items.Keys)
|
|
|
|
|
{
|
2025-01-14 22:34:58 -05:00
|
|
|
RemoveItemDB(key);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
2025-01-13 14:14:28 -05:00
|
|
|
|
|
|
|
|
// Remove the machine
|
2025-01-14 22:34:58 -05:00
|
|
|
RemoveMachineDB(machine.Key);
|
2025-05-11 21:29:34 -04:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
|
|
|
|
});
|
|
|
|
|
#else
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
2025-05-11 21:29:34 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-13 13:01:36 -05:00
|
|
|
/// Use cloneof tags to remove items from the children
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
2025-01-13 09:27:01 -05:00
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="Items"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
2025-01-13 13:01:36 -05:00
|
|
|
private void RemoveItemsFromCloneOfChildImpl()
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. Items.SortedKeys];
|
2025-05-03 23:36:15 -04:00
|
|
|
foreach (string bucket in buckets)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 09:24:16 -05:00
|
|
|
// If the bucket has no items in it
|
2025-01-13 13:22:48 -05:00
|
|
|
List<DatItem> items = GetItemsForBucket(bucket);
|
|
|
|
|
if (items.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the machine
|
2025-05-02 16:46:20 -04:00
|
|
|
var machine = items[0].GetMachine();
|
2025-01-12 23:56:48 -05:00
|
|
|
if (machine == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-01-13 13:22:48 -05:00
|
|
|
// Get the cloneof parent items
|
2025-01-13 13:01:36 -05:00
|
|
|
string? cloneOf = machine.GetStringFieldValue(Models.Metadata.Machine.CloneOfKey);
|
2025-01-13 13:22:48 -05:00
|
|
|
List<DatItem> parentItems = GetItemsForBucket(cloneOf);
|
|
|
|
|
if (parentItems.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
2025-01-13 13:01:36 -05:00
|
|
|
// If the parent exists and has items, we remove the parent items from the current game
|
2025-01-12 23:56:48 -05:00
|
|
|
foreach (DatItem item in parentItems)
|
|
|
|
|
{
|
2025-05-03 23:20:23 -04:00
|
|
|
while (true)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-05-03 23:20:23 -04:00
|
|
|
// Find the next index that matches the item
|
|
|
|
|
int index = items.FindIndex(i => i.Equals(item));
|
|
|
|
|
if (index < 0)
|
|
|
|
|
break;
|
|
|
|
|
|
2025-05-11 21:26:37 -04:00
|
|
|
// Remove the item from the local and internal lists
|
2025-05-03 23:20:23 -04:00
|
|
|
RemoveItem(bucket, items[index], index);
|
2025-05-11 22:00:09 -04:00
|
|
|
items.RemoveAt(index);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
2025-01-13 13:01:36 -05:00
|
|
|
|
|
|
|
|
// Now we want to get the parent romof tag and put it in each of the remaining items
|
|
|
|
|
items = GetItemsForBucket(bucket);
|
2025-05-02 16:46:20 -04:00
|
|
|
string? romof = GetItemsForBucket(cloneOf)[0].GetMachine()!.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
|
2025-01-13 13:01:36 -05:00
|
|
|
foreach (DatItem item in items)
|
|
|
|
|
{
|
2025-05-02 16:46:20 -04:00
|
|
|
item.GetMachine()!.SetFieldValue<string?>(Models.Metadata.Machine.RomOfKey, romof);
|
2025-01-13 13:01:36 -05:00
|
|
|
}
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-13 13:01:36 -05:00
|
|
|
/// Use cloneof tags to remove items from the children
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
2025-01-13 09:27:01 -05:00
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="ItemsDB"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
2025-01-13 13:01:36 -05:00
|
|
|
private void RemoveItemsFromCloneOfChildImplDB()
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. ItemsDB.SortedKeys];
|
2025-01-13 09:24:16 -05:00
|
|
|
foreach (string bucket in buckets)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 09:24:16 -05:00
|
|
|
// If the bucket has no items in it
|
2025-01-13 13:22:48 -05:00
|
|
|
Dictionary<long, DatItem> items = GetItemsForBucketDB(bucket);
|
|
|
|
|
if (items.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
2025-01-13 13:01:36 -05:00
|
|
|
// Get the machine for the first item
|
2025-02-24 09:20:46 -05:00
|
|
|
var machine = GetMachineForItemDB(items.First().Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
if (machine.Value == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-01-13 13:22:48 -05:00
|
|
|
// Get the cloneof parent items
|
2025-01-13 13:01:36 -05:00
|
|
|
string? cloneOf = machine.Value.GetStringFieldValue(Models.Metadata.Machine.CloneOfKey);
|
2025-01-13 13:31:14 -05:00
|
|
|
Dictionary<long, DatItem> parentItems = GetItemsForBucketDB(cloneOf);
|
2025-01-12 23:56:48 -05:00
|
|
|
if (parentItems == null || parentItems.Count == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-01-13 13:01:36 -05:00
|
|
|
// If the parent exists and has items, we remove the parent items from the current game
|
2025-01-12 23:56:48 -05:00
|
|
|
foreach (var item in parentItems)
|
|
|
|
|
{
|
2025-01-13 15:21:24 -05:00
|
|
|
var matchedItems = items.Where(i => i.Value.Equals(item.Value));
|
2025-01-12 23:56:48 -05:00
|
|
|
foreach (var match in matchedItems)
|
|
|
|
|
{
|
2025-01-14 22:34:58 -05:00
|
|
|
RemoveItemDB(match.Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
2025-01-13 13:01:36 -05:00
|
|
|
|
|
|
|
|
// Now we want to get the parent romof tag and put it in each of the remaining items
|
|
|
|
|
items = GetItemsForBucketDB(bucket);
|
2025-02-24 09:20:46 -05:00
|
|
|
machine = GetMachineForItemDB(GetItemsForBucketDB(cloneOf).First().Key);
|
2025-01-13 13:01:36 -05:00
|
|
|
if (machine.Value == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
string? romof = machine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
|
|
|
|
|
foreach (var item in items)
|
|
|
|
|
{
|
2025-02-24 09:20:46 -05:00
|
|
|
machine = GetMachineForItemDB(item.Key);
|
2025-01-13 13:01:36 -05:00
|
|
|
if (machine.Value == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
machine.Value.SetFieldValue<string?>(Models.Metadata.Machine.RomOfKey, romof);
|
|
|
|
|
}
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-13 15:46:06 -05:00
|
|
|
/// Use romof tags to remove items from children
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
2025-01-13 09:27:01 -05:00
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="Items"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
2025-01-13 15:46:06 -05:00
|
|
|
private void RemoveItemsFromRomOfChildImpl()
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. Items.SortedKeys];
|
2025-05-03 23:36:15 -04:00
|
|
|
foreach (string bucket in buckets)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 09:24:16 -05:00
|
|
|
// If the bucket has no items in it
|
2025-01-13 13:22:48 -05:00
|
|
|
List<DatItem> items = GetItemsForBucket(bucket);
|
|
|
|
|
if (items.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get the machine
|
2025-05-02 16:46:20 -04:00
|
|
|
var machine = items[0].GetMachine();
|
2025-01-12 23:56:48 -05:00
|
|
|
if (machine == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-01-13 13:22:48 -05:00
|
|
|
// Get the romof parent items
|
2025-01-13 13:01:36 -05:00
|
|
|
string? romOf = machine.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
|
2025-01-13 13:31:14 -05:00
|
|
|
List<DatItem> parentItems = GetItemsForBucket(romOf);
|
2025-01-13 13:22:48 -05:00
|
|
|
if (parentItems.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
2025-05-03 23:20:23 -04:00
|
|
|
// If the parent exists and has items, we remove the parent items from the current game
|
2025-01-13 10:52:27 -05:00
|
|
|
foreach (DatItem item in parentItems)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-05-03 23:20:23 -04:00
|
|
|
while (true)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-05-03 23:20:23 -04:00
|
|
|
// Find the next index that matches the item
|
|
|
|
|
int index = items.FindIndex(i => i.Equals(item));
|
|
|
|
|
if (index < 0)
|
|
|
|
|
break;
|
|
|
|
|
|
2025-05-11 21:19:28 -04:00
|
|
|
// Remove the item from the local and internal lists
|
2025-05-03 23:20:23 -04:00
|
|
|
RemoveItem(bucket, items[index], index);
|
2025-05-11 22:00:09 -04:00
|
|
|
items.RemoveAt(index);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-13 13:01:36 -05:00
|
|
|
/// Use romof tags to remove bios items from children
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
2025-01-13 13:01:36 -05:00
|
|
|
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
|
2025-01-13 09:27:01 -05:00
|
|
|
/// <remarks>
|
|
|
|
|
/// Applies to <see cref="ItemsDB"/>.
|
|
|
|
|
/// Assumes items are bucketed by <see cref="ItemKey.Machine"/>.
|
|
|
|
|
/// </remarks>
|
2025-01-13 15:46:06 -05:00
|
|
|
private void RemoveItemsFromRomOfChildImplDB()
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. ItemsDB.SortedKeys];
|
2025-01-13 09:24:16 -05:00
|
|
|
foreach (string bucket in buckets)
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 09:24:16 -05:00
|
|
|
// If the bucket has no items in it
|
2025-01-13 13:22:48 -05:00
|
|
|
Dictionary<long, DatItem> items = GetItemsForBucketDB(bucket);
|
|
|
|
|
if (items.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
2025-01-13 13:01:36 -05:00
|
|
|
// Get the machine for the item
|
2025-02-24 09:20:46 -05:00
|
|
|
var machine = GetMachineForItemDB(items.First().Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
if (machine.Value == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-01-13 13:22:48 -05:00
|
|
|
// Get the romof parent items
|
2025-01-13 13:01:36 -05:00
|
|
|
string? romOf = machine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
|
2025-01-13 13:31:14 -05:00
|
|
|
Dictionary<long, DatItem> parentItems = GetItemsForBucketDB(romOf);
|
2025-01-13 13:22:48 -05:00
|
|
|
if (parentItems.Count == 0)
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
|
|
|
|
|
2025-01-13 13:01:36 -05:00
|
|
|
// If the parent exists and has items, we remove the items that are in the parent from the current game
|
2025-01-12 23:56:48 -05:00
|
|
|
foreach (var item in parentItems)
|
|
|
|
|
{
|
2025-01-13 15:28:30 -05:00
|
|
|
var matchedItems = items.Where(i => i.Value.Equals(item.Value));
|
2025-01-12 23:56:48 -05:00
|
|
|
foreach (var match in matchedItems)
|
|
|
|
|
{
|
2025-01-14 22:34:58 -05:00
|
|
|
RemoveItemDB(match.Key);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-13 00:29:39 -05:00
|
|
|
/// <summary>
|
2025-01-13 10:45:42 -05:00
|
|
|
/// Remove all romof and cloneof tags from all machines
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
2025-01-13 09:12:07 -05:00
|
|
|
/// <remarks>Applies to <see cref="Items"/></remarks>
|
|
|
|
|
private void RemoveMachineRelationshipTagsImpl()
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-05-03 23:57:57 -04:00
|
|
|
string[] buckets = [.. Items.SortedKeys];
|
2025-05-11 21:05:54 -04:00
|
|
|
|
|
|
|
|
#if NET452_OR_GREATER || NETCOREAPP
|
|
|
|
|
Parallel.ForEach(buckets, Globals.ParallelOptions, bucket =>
|
|
|
|
|
#elif NET40_OR_GREATER
|
|
|
|
|
Parallel.ForEach(buckets, bucket =>
|
|
|
|
|
#else
|
2025-05-03 23:36:15 -04:00
|
|
|
foreach (string bucket in buckets)
|
2025-05-11 21:05:54 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 09:24:16 -05:00
|
|
|
// If the bucket has no items in it
|
2025-01-13 09:37:59 -05:00
|
|
|
var items = GetItemsForBucket(bucket);
|
2025-01-12 23:56:48 -05:00
|
|
|
if (items == null || items.Count == 0)
|
2025-05-11 21:05:54 -04:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
|
|
|
|
return;
|
|
|
|
|
#else
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
2025-05-11 21:05:54 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
|
|
|
|
|
foreach (DatItem item in items)
|
|
|
|
|
{
|
2025-05-14 08:52:24 -04:00
|
|
|
// Remove the merge tag
|
|
|
|
|
item.RemoveField(Models.Metadata.Rom.MergeKey);
|
|
|
|
|
|
2025-01-13 00:31:38 -05:00
|
|
|
// Get the machine
|
2025-05-02 16:46:20 -04:00
|
|
|
var machine = item.GetMachine();
|
2025-01-13 00:31:38 -05:00
|
|
|
if (machine == null)
|
|
|
|
|
continue;
|
2025-01-13 13:22:48 -05:00
|
|
|
|
2025-01-13 00:31:38 -05:00
|
|
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.CloneOfKey, null);
|
|
|
|
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.RomOfKey, null);
|
|
|
|
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.SampleOfKey, null);
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
2025-05-11 21:05:54 -04:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
|
|
|
|
});
|
|
|
|
|
#else
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
2025-05-11 21:05:54 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-01-13 10:45:42 -05:00
|
|
|
/// Remove all romof and cloneof tags from all machines
|
2025-01-12 23:56:48 -05:00
|
|
|
/// </summary>
|
2025-01-13 09:12:07 -05:00
|
|
|
/// <remarks>Applies to <see cref="ItemsDB"/></remarks>
|
|
|
|
|
private void RemoveMachineRelationshipTagsImplDB()
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-01-13 10:01:27 -05:00
|
|
|
var machines = GetMachinesDB();
|
2025-05-11 21:05:54 -04:00
|
|
|
|
|
|
|
|
#if NET452_OR_GREATER || NETCOREAPP
|
|
|
|
|
Parallel.ForEach(machines, Globals.ParallelOptions, machine =>
|
|
|
|
|
#elif NET40_OR_GREATER
|
|
|
|
|
Parallel.ForEach(machines, machine =>
|
|
|
|
|
#else
|
2025-01-13 00:29:39 -05:00
|
|
|
foreach (var machine in machines)
|
2025-05-11 21:05:54 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
{
|
2025-05-14 08:52:24 -04:00
|
|
|
// TODO: Remove merge tags here
|
2025-01-13 00:31:38 -05:00
|
|
|
// Get the machine
|
2025-01-13 00:29:39 -05:00
|
|
|
if (machine.Value == null)
|
2025-05-11 21:05:54 -04:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
|
|
|
|
return;
|
|
|
|
|
#else
|
2025-01-12 23:56:48 -05:00
|
|
|
continue;
|
2025-05-11 21:05:54 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
|
2025-01-13 00:29:39 -05:00
|
|
|
machine.Value.SetFieldValue<string?>(Models.Metadata.Machine.CloneOfKey, null);
|
|
|
|
|
machine.Value.SetFieldValue<string?>(Models.Metadata.Machine.RomOfKey, null);
|
|
|
|
|
machine.Value.SetFieldValue<string?>(Models.Metadata.Machine.SampleOfKey, null);
|
2025-05-11 21:05:54 -04:00
|
|
|
#if NET40_OR_GREATER || NETCOREAPP
|
|
|
|
|
});
|
|
|
|
|
#else
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
2025-05-11 21:05:54 -04:00
|
|
|
#endif
|
2025-01-12 23:56:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|