Move more functionality back to DatFile

This commit is contained in:
Matt Nadareski
2025-01-13 15:41:57 -05:00
parent 5c8f5c6d99
commit 80832b41e3
3 changed files with 174 additions and 147 deletions

View File

@@ -7,6 +7,36 @@ namespace SabreTools.DatFiles.Test
{ {
public partial class DatFileTests 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 #region AddItemsFromChildren
// TODO: Implement AddItemsFromChildren tests // TODO: Implement AddItemsFromChildren tests

View File

@@ -8,6 +8,136 @@ namespace SabreTools.DatFiles
{ {
public partial class DatFile public partial class DatFile
{ {
#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
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();
}
/// <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
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();
}
/// <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
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();
}
/// <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
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();
}
/// <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
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();
}
/// <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
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 #region Splitting Steps
/// <summary> /// <summary>
@@ -16,7 +146,7 @@ namespace SabreTools.DatFiles
/// <param name="subfolder">True to add DatItems to subfolder of parent (not including Disk), false otherwise</param> /// <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> /// <param name="skipDedup">True to skip checking for duplicate ROMs in parent, false otherwise</param>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks> /// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
public void AddItemsFromChildren(bool subfolder, bool skipDedup) internal void AddItemsFromChildren(bool subfolder, bool skipDedup)
{ {
AddItemsFromChildrenImpl(subfolder, skipDedup); AddItemsFromChildrenImpl(subfolder, skipDedup);
AddItemsFromChildrenImplDB(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 /// Use cloneof tags to add items to the children, setting the new romof tag in the process
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks> /// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
public void AddItemsFromCloneOfParent() internal void AddItemsFromCloneOfParent()
{ {
AddItemsFromCloneOfParentImpl(); AddItemsFromCloneOfParentImpl();
AddItemsFromCloneOfParentImplDB(); AddItemsFromCloneOfParentImplDB();
@@ -38,7 +168,7 @@ namespace SabreTools.DatFiles
/// <param name="deviceOnly">True if only child device sets are touched, false for non-device sets</param> /// <param name="deviceOnly">True if only child device sets are touched, false for non-device sets</param>
/// <param name="useSlotOptions">True if slotoptions tags are used as well, false otherwise</param> /// <param name="useSlotOptions">True if slotoptions tags are used as well, false otherwise</param>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks> /// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
public bool AddItemsFromDevices(bool deviceOnly, bool useSlotOptions) internal bool AddItemsFromDevices(bool deviceOnly, bool useSlotOptions)
{ {
bool foundnew = AddItemsFromDevicesImpl(deviceOnly, useSlotOptions); bool foundnew = AddItemsFromDevicesImpl(deviceOnly, useSlotOptions);
foundnew |= AddItemsFromDevicesImplDB(deviceOnly, useSlotOptions); foundnew |= AddItemsFromDevicesImplDB(deviceOnly, useSlotOptions);
@@ -49,7 +179,7 @@ namespace SabreTools.DatFiles
/// Use romof tags to add items to the children /// Use romof tags to add items to the children
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks> /// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
public void AddItemsFromRomOfParent() internal void AddItemsFromRomOfParent()
{ {
AddItemsFromRomOfParentImpl(); AddItemsFromRomOfParentImpl();
AddItemsFromRomOfParentImplDB(); AddItemsFromRomOfParentImplDB();
@@ -59,7 +189,7 @@ namespace SabreTools.DatFiles
/// Remove all BIOS and device sets /// Remove all BIOS and device sets
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks> /// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
public void RemoveBiosAndDeviceSets() internal void RemoveBiosAndDeviceSets()
{ {
RemoveBiosAndDeviceSetsImpl(); RemoveBiosAndDeviceSetsImpl();
RemoveBiosAndDeviceSetsImplDB(); RemoveBiosAndDeviceSetsImplDB();
@@ -69,7 +199,7 @@ namespace SabreTools.DatFiles
/// Use cloneof tags to remove items from the children /// Use cloneof tags to remove items from the children
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks> /// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
public void RemoveItemsFromCloneOfChild() internal void RemoveItemsFromCloneOfChild()
{ {
RemoveItemsFromCloneOfChildImpl(); RemoveItemsFromCloneOfChildImpl();
RemoveItemsFromCloneOfChildImplDB(); RemoveItemsFromCloneOfChildImplDB();
@@ -79,7 +209,7 @@ namespace SabreTools.DatFiles
/// Use romof tags to remove bios items from children /// Use romof tags to remove bios items from children
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks> /// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
public void RemoveItemsFromRomOfChild() internal void RemoveItemsFromRomOfChild()
{ {
// TODO: Figure out why the bios flag is needed // TODO: Figure out why the bios flag is needed
RemoveItemsFromRomOfChildImpl(false); RemoveItemsFromRomOfChildImpl(false);
@@ -92,7 +222,7 @@ namespace SabreTools.DatFiles
/// Remove all romof and cloneof tags from all machines /// Remove all romof and cloneof tags from all machines
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks> /// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
public void RemoveMachineRelationshipTags() internal void RemoveMachineRelationshipTags()
{ {
RemoveMachineRelationshipTagsImpl(); RemoveMachineRelationshipTagsImpl();
RemoveMachineRelationshipTagsImplDB(); RemoveMachineRelationshipTagsImplDB();

View File

@@ -1,7 +1,6 @@
using System; using System;
using SabreTools.Core.Tools; using SabreTools.Core.Tools;
using SabreTools.DatFiles; using SabreTools.DatFiles;
using SabreTools.DatItems;
using SabreTools.IO.Logging; using SabreTools.IO.Logging;
namespace SabreTools.DatTools namespace SabreTools.DatTools
@@ -26,12 +25,6 @@ namespace SabreTools.DatTools
#endregion #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 #region Running
/// <summary> /// <summary>
@@ -59,24 +52,24 @@ namespace SabreTools.DatTools
// No-op // No-op
break; break;
case MergingFlag.Split: case MergingFlag.Split:
CreateSplitSets(datFile); datFile.ApplySplit();
break; break;
case MergingFlag.Merged: case MergingFlag.Merged:
CreateMergedSets(datFile); datFile.ApplyMerged();
break; break;
case MergingFlag.NonMerged: case MergingFlag.NonMerged:
CreateNonMergedSets(datFile); datFile.ApplyNonMerged();
break; break;
// Nonstandard // Nonstandard
case MergingFlag.FullMerged: case MergingFlag.FullMerged:
CreateFullyMergedSets(datFile); datFile.ApplyFullyMerged();
break; break;
case MergingFlag.DeviceNonMerged: case MergingFlag.DeviceNonMerged:
CreateDeviceNonMergedSets(datFile); datFile.ApplyDeviceNonMerged();
break; break;
case MergingFlag.FullNonMerged: case MergingFlag.FullNonMerged:
CreateFullyNonMergedSets(datFile); datFile.ApplyFullyNonMerged();
break; break;
} }
} }
@@ -93,132 +86,6 @@ namespace SabreTools.DatTools
return true; return true;
} }
/// <summary>
/// Use cdevice_ref tags to get full non-merged sets and remove parenting tags
/// </summary>
/// <param name="datFile">Current DatFile object to run operations on</param>
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();
}
/// <summary>
/// Use cloneof tags to create merged sets and remove the tags plus deduplicating if tags don't catch everything
/// </summary>
/// <param name="datFile">Current DatFile object to run operations on</param>
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();
}
/// <summary>
/// Use cloneof tags to create non-merged sets and remove the tags plus using the device_ref tags to get full sets
/// </summary>
/// <param name="datFile">Current DatFile object to run operations on</param>
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();
}
/// <summary>
/// Use cloneof tags to create merged sets and remove the tags
/// </summary>
/// <param name="datFile">Current DatFile object to run operations on</param>
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();
}
/// <summary>
/// Use cloneof tags to create non-merged sets and remove the tags
/// </summary>
/// <param name="datFile">Current DatFile object to run operations on</param>
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();
}
/// <summary>
/// Use cloneof and romof tags to create split sets and remove the tags
/// </summary>
/// <param name="datFile">Current DatFile object to run operations on</param>
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 #endregion
} }
} }