Create passthrough methods for scaffolding

This commit is contained in:
Matt Nadareski
2025-01-12 23:15:30 -05:00
parent d80a6b173c
commit f4743e859e
18 changed files with 508 additions and 368 deletions

View File

@@ -71,7 +71,7 @@ namespace SabreTools.DatFiles
// Loop through the sorted items and create games for them
foreach (string key in Items.SortedKeys)
{
var items = Items.FilteredItems(key);
var items = Items.GetItemsForBucket(key, filter: true);
if (items == null || items.Count == 0)
continue;
@@ -494,7 +494,7 @@ namespace SabreTools.DatFiles
// Loop through the sorted items and create games for them
foreach (string key in ItemsDB.SortedKeys)
{
var items = ItemsDB.GetItemsForBucket(key, filter: true);
var items = GetItemsForBucketDB(key, filter: true);
if (items == null || items.Count == 0)
continue;

View File

@@ -38,6 +38,13 @@ namespace SabreTools.DatFiles
[JsonProperty("items"), XmlElement("items")]
public ItemDictionaryDB ItemsDB { get; private set; } = new ItemDictionaryDB();
/// <summary>
/// DAT statistics
/// </summary>
[JsonIgnore, XmlIgnore]
public DatStatistics DatStatistics => Items.DatStatistics;
//public DatStatistics DatStatistics => ItemsDB.DatStatistics;
/// <summary>
/// List of supported types for writing
/// </summary>
@@ -134,21 +141,7 @@ namespace SabreTools.DatFiles
#endregion
#region Filtering
/// <summary>
/// Execute all filters in a filter runner on the items in the dictionary
/// </summary>
/// <param name="filterRunner">Preconfigured filter runner to use</param>
public void ExecuteFilters(FilterRunner filterRunner)
{
Items.ExecuteFilters(filterRunner);
ItemsDB.ExecuteFilters(filterRunner);
}
#endregion
#region Item Dictionary Manipulation
#region Item Dictionary Passthrough - Accessors
/// <summary>
/// Add a value to the file dictionary
@@ -228,6 +221,18 @@ namespace SabreTools.DatFiles
ItemsDB.ClearMarked();
}
/// <summary>
/// Get the items associated with a bucket name
/// </summary>
public List<DatItem> GetItemsForBucket(string bucketName, bool filter = false)
=> Items.GetItemsForBucket(bucketName, filter);
/// <summary>
/// Get the indices and items associated with a bucket name
/// </summary>
public Dictionary<long, DatItem> GetItemsForBucketDB(string bucketName, bool filter = false)
=> ItemsDB.GetItemsForBucket(bucketName, filter);
/// <summary>
/// Remove a key from the file dictionary if it exists
/// </summary>
@@ -248,6 +253,203 @@ namespace SabreTools.DatFiles
#endregion
#region Item Dictionary Passthrough - Bucketing
/// <summary>
/// Take the arbitrarily bucketed Files Dictionary and convert to one bucketed by a user-defined method
/// </summary>
/// <param name="bucketBy">ItemKey enum representing how to bucket the individual items</param>
/// <param name="dedupeType">Dedupe type that should be used</param>
/// <param name="lower">True if the key should be lowercased (default), false otherwise</param>
/// <param name="norename">True if games should only be compared on game and file name, false if system and source are counted</param>
public void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
{
Items.BucketBy(bucketBy, dedupeType, lower, norename);
ItemsDB.BucketBy(bucketBy, dedupeType, lower, norename);
}
/// <summary>
/// List all duplicates found in a DAT based on a DatItem
/// </summary>
/// <param name="datItem">Item to try to match</param>
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
/// <returns>List of matched DatItem objects</returns>
public List<DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
=> Items.GetDuplicates(datItem, sorted);
/// <summary>
/// List all duplicates found in a DAT based on a DatItem
/// </summary>
/// <param name="datItem">Item to try to match</param>
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
/// <returns>List of matched DatItem objects</returns>
public Dictionary<long, DatItem> GetDuplicatesDB(KeyValuePair<long, DatItem> datItem, bool sorted = false)
=> ItemsDB.GetDuplicates(datItem, sorted);
/// <summary>
/// Check if a DAT contains the given DatItem
/// </summary>
/// <param name="datItem">Item to try to match</param>
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
/// <returns>True if it contains the rom, false otherwise</returns>
public bool HasDuplicates(DatItem datItem, bool sorted = false)
=> Items.HasDuplicates(datItem, sorted);
/// <summary>
/// Check if a DAT contains the given DatItem
/// </summary>
/// <param name="datItem">Item to try to match</param>
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
/// <returns>True if it contains the rom, false otherwise</returns>
public bool HasDuplicates(KeyValuePair<long, DatItem> datItem, bool sorted = false)
=> ItemsDB.HasDuplicates(datItem, sorted);
#endregion
#region Item Dictionary Passthrough - Filtering
/// <summary>
/// Execute all filters in a filter runner on the items in the dictionary
/// </summary>
/// <param name="filterRunner">Preconfigured filter runner to use</param>
public void ExecuteFilters(FilterRunner filterRunner)
{
Items.ExecuteFilters(filterRunner);
ItemsDB.ExecuteFilters(filterRunner);
}
/// <summary>
/// Use game descriptions as names, updating cloneof/romof/sampleof
/// </summary>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
public void MachineDescriptionToName(bool throwOnError = false)
{
Items.MachineDescriptionToName(throwOnError);
ItemsDB.MachineDescriptionToName(throwOnError);
}
/// <summary>
/// Ensure that all roms are in their own game (or at least try to ensure)
/// </summary>
public void SetOneRomPerGame()
{
Items.SetOneRomPerGame();
ItemsDB.SetOneRomPerGame();
}
/// <summary>
/// Filter a DAT using 1G1R logic given an ordered set of regions
/// </summary>
/// <param name="regionList">List of regions in order of priority</param>
/// <remarks>
/// In the most technical sense, the way that the region list is being used does not
/// confine its values to be just regions. Since it's essentially acting like a
/// specialized version of the machine name filter, anything that is usually encapsulated
/// in parenthesis would be matched on, including disc numbers, languages, editions,
/// and anything else commonly used. Please note that, unlike other existing 1G1R
/// solutions, this does not have the ability to contain custom mappings of parent
/// to clone sets based on name, nor does it have the ability to match on the
/// Release DatItem type.
/// </remarks>
public void SetOneGamePerRegion(List<string> regionList)
{
Items.SetOneGamePerRegion(regionList);
ItemsDB.SetOneGamePerRegion(regionList);
}
/// <summary>
/// Strip the dates from the beginning of scene-style set names
/// </summary>
public void StripSceneDatesFromItems()
{
Items.StripSceneDatesFromItems();
ItemsDB.StripSceneDatesFromItems();
}
#endregion
#region Item Dictionary Passthrough - Splitting
/// <summary>
/// Use romof tags to add roms to the children
/// </summary>
public void AddRomsFromBios()
{
Items.AddRomsFromBios();
ItemsDB.AddRomsFromBios();
}
/// <summary>
/// Use device_ref and optionally slotoption tags to add roms to the children
/// </summary>
/// <param name="dev">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>
public bool AddRomsFromDevices(bool dev, bool useSlotOptions)
{
bool foundnew = Items.AddRomsFromDevices(dev, useSlotOptions);
foundnew |= ItemsDB.AddRomsFromDevices(dev, useSlotOptions);
return foundnew;
}
/// <summary>
/// Use cloneof tags to add roms to the parents, removing the child sets in the process
/// </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>
public void AddRomsFromChildren(bool subfolder, bool skipDedup)
{
Items.AddRomsFromChildren(subfolder, skipDedup);
ItemsDB.AddRomsFromChildren(subfolder, skipDedup);
}
/// <summary>
/// Use cloneof tags to add roms to the children, setting the new romof tag in the process
/// </summary>
public void AddRomsFromParent()
{
Items.AddRomsFromParent();
ItemsDB.AddRomsFromParent();
}
/// <summary>
/// Remove all BIOS and device sets
/// </summary>
public void RemoveBiosAndDeviceSets()
{
Items.RemoveBiosAndDeviceSets();
ItemsDB.RemoveBiosAndDeviceSets();
}
/// <summary>
/// Use romof tags to remove bios roms from children
/// </summary>
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
public void RemoveBiosRomsFromChild(bool bios)
{
Items.RemoveBiosRomsFromChild(bios);
ItemsDB.RemoveBiosRomsFromChild(bios);
}
/// <summary>
/// Use cloneof tags to remove roms from the children
/// </summary>
public void RemoveRomsFromChild()
{
Items.RemoveRomsFromChild();
ItemsDB.RemoveRomsFromChild();
}
/// <summary>
/// Remove all romof and cloneof tags from all games
/// </summary>
public void RemoveTagsFromChild()
{
Items.RemoveTagsFromChild();
ItemsDB.RemoveTagsFromChild();
}
#endregion
#region Parsing
/// <summary>

View File

@@ -320,7 +320,7 @@ namespace SabreTools.DatFiles
foreach (var key in keys)
#endif
{
List<DatItem>? items = datFile.Items[key];
List<DatItem>? items = datFile.GetItemsForBucket(key);
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
@@ -391,7 +391,7 @@ namespace SabreTools.DatFiles
foreach (var key in keys)
#endif
{
var items = datFile.ItemsDB.GetItemsForBucket(key);
var items = datFile.GetItemsForBucketDB(key);
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
@@ -462,8 +462,8 @@ namespace SabreTools.DatFiles
if (itemFieldNames.Count > 0)
{
// For comparison's sake, we want to use CRC as the base bucketing
datFile.Items.BucketBy(ItemKey.CRC, DedupeType.Full);
intDat.Items.BucketBy(ItemKey.CRC, DedupeType.None);
datFile.BucketBy(ItemKey.CRC, DedupeType.Full);
intDat.BucketBy(ItemKey.CRC, DedupeType.None);
// Then we do a hashwise comparison against the base DAT
#if NET452_OR_GREATER || NETCOREAPP
@@ -474,7 +474,7 @@ namespace SabreTools.DatFiles
foreach (var key in intDat.Items.Keys)
#endif
{
List<DatItem>? datItems = intDat.Items[key];
List<DatItem>? datItems = intDat.GetItemsForBucket(key);
if (datItems == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
@@ -510,8 +510,8 @@ namespace SabreTools.DatFiles
if (machineFieldNames.Count > 0)
{
// For comparison's sake, we want to use Machine Name as the base bucketing
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.Full);
intDat.Items.BucketBy(ItemKey.Machine, DedupeType.None);
datFile.BucketBy(ItemKey.Machine, DedupeType.Full);
intDat.BucketBy(ItemKey.Machine, DedupeType.None);
// Then we do a namewise comparison against the base DAT
#if NET452_OR_GREATER || NETCOREAPP
@@ -522,7 +522,7 @@ namespace SabreTools.DatFiles
foreach (var key in intDat.Items.Keys)
#endif
{
List<DatItem>? datItems = intDat.Items[key];
List<DatItem>? datItems = intDat.GetItemsForBucket(key);
if (datItems == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
@@ -579,8 +579,8 @@ namespace SabreTools.DatFiles
if (itemFieldNames.Count > 0)
{
// For comparison's sake, we want to use CRC as the base bucketing
datFile.ItemsDB.BucketBy(ItemKey.CRC, DedupeType.Full);
intDat.ItemsDB.BucketBy(ItemKey.CRC, DedupeType.None);
datFile.BucketBy(ItemKey.CRC, DedupeType.Full);
intDat.BucketBy(ItemKey.CRC, DedupeType.None);
// Then we do a hashwise comparison against the base DAT
#if NET452_OR_GREATER || NETCOREAPP
@@ -591,7 +591,7 @@ namespace SabreTools.DatFiles
foreach (var key in intDat.ItemsDB.SortedKeys)
#endif
{
var datItems = intDat.ItemsDB.GetItemsForBucket(key);
var datItems = intDat.GetItemsForBucketDB(key);
if (datItems == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
@@ -601,7 +601,7 @@ namespace SabreTools.DatFiles
foreach (var datItem in datItems)
{
var dupes = datFile.ItemsDB.GetDuplicates(datItem, sorted: true);
var dupes = datFile.GetDuplicatesDB(datItem, sorted: true);
if (datItem.Value.Clone() is not DatItem newDatItem)
continue;
@@ -620,8 +620,8 @@ namespace SabreTools.DatFiles
if (machineFieldNames.Count > 0)
{
// For comparison's sake, we want to use Machine Name as the base bucketing
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.Full);
intDat.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None);
datFile.BucketBy(ItemKey.Machine, DedupeType.Full);
intDat.BucketBy(ItemKey.Machine, DedupeType.None);
// Then we do a namewise comparison against the base DAT
#if NET452_OR_GREATER || NETCOREAPP
@@ -632,7 +632,7 @@ namespace SabreTools.DatFiles
foreach (var key in intDat.ItemsDB.SortedKeys)
#endif
{
var datItems = intDat.ItemsDB.GetItemsForBucket(key);
var datItems = intDat.GetItemsForBucketDB(key);
if (datItems == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
@@ -642,7 +642,7 @@ namespace SabreTools.DatFiles
foreach (var datItem in datItems)
{
var datMachine = datFile.ItemsDB.GetMachineForItem(datFile.ItemsDB.GetItemsForBucket(key)!.First().Key);
var datMachine = datFile.ItemsDB.GetMachineForItem(datFile.GetItemsForBucketDB(key)!.First().Key);
var intMachine = intDat.ItemsDB.GetMachineForItem(datItem.Key);
if (datMachine.Value != null && intMachine.Value != null)
Replacer.ReplaceFields(intMachine.Value, datMachine.Value, machineFieldNames, onlySame);
@@ -671,17 +671,17 @@ namespace SabreTools.DatFiles
{
// For comparison's sake, we want to use a base ordering
if (useGames)
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None);
datFile.BucketBy(ItemKey.Machine, DedupeType.None);
else
datFile.Items.BucketBy(ItemKey.CRC, DedupeType.None);
datFile.BucketBy(ItemKey.CRC, DedupeType.None);
InternalStopwatch watch = new($"Comparing '{intDat.Header.GetStringFieldValue(DatHeader.FileNameKey)}' to base DAT");
// For comparison's sake, we want to a the base bucketing
if (useGames)
intDat.Items.BucketBy(ItemKey.Machine, DedupeType.None);
intDat.BucketBy(ItemKey.Machine, DedupeType.None);
else
intDat.Items.BucketBy(ItemKey.CRC, DedupeType.Full);
intDat.BucketBy(ItemKey.CRC, DedupeType.Full);
// Then we compare against the base DAT
List<string> keys = [.. intDat.Items.Keys];
@@ -740,7 +740,7 @@ namespace SabreTools.DatFiles
// Standard Against uses hashes
else
{
List<DatItem>? datItems = intDat.Items[key];
List<DatItem>? datItems = intDat.GetItemsForBucket(key);
if (datItems == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
@@ -751,7 +751,7 @@ namespace SabreTools.DatFiles
List<DatItem> keepDatItems = [];
foreach (DatItem datItem in datItems)
{
if (!datFile.Items.HasDuplicates(datItem, true))
if (!datFile.HasDuplicates(datItem, true))
keepDatItems.Add(datItem);
}
@@ -780,7 +780,7 @@ namespace SabreTools.DatFiles
List<DatFile> outDats = [];
// Ensure the current DatFile is sorted optimally
datFile.Items.BucketBy(ItemKey.CRC, DedupeType.None);
datFile.BucketBy(ItemKey.CRC, DedupeType.None);
// Loop through each of the inputs and get or create a new DatData object
InternalStopwatch watch = new("Initializing and filling all output DATs");
@@ -795,10 +795,10 @@ namespace SabreTools.DatFiles
for (int j = 0; j < datHeaders.Count; j++)
#endif
{
DatFile diffData = DatFileTool.CreateDatFile(datHeaders[j]);
DatFile diffData = CreateDatFile(datHeaders[j]);
diffData.ResetDictionary();
FillWithSourceIndex(datFile, diffData, j);
//FillWithSourceIndexDB(datFile, diffData, j);
FillWithSourceIndexDB(datFile, diffData, j);
outDatsArray[j] = diffData;
#if NET40_OR_GREATER || NETCOREAPP
});
@@ -844,7 +844,7 @@ namespace SabreTools.DatFiles
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "datFile.All DATs");
string post = " (Duplicates)";
DatFile dupeData = DatFileTool.CreateDatFile(datFile.Header);
DatFile dupeData = CreateDatFile(datFile.Header);
dupeData.Header.SetFieldValue<string?>(DatHeader.FileNameKey, dupeData.Header.GetStringFieldValue(DatHeader.FileNameKey) + post);
dupeData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post);
dupeData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post);
@@ -863,7 +863,7 @@ namespace SabreTools.DatFiles
foreach (var key in datFile.Items.Keys)
#endif
{
List<DatItem> items = Merge(datFile.Items[key]);
List<DatItem> items = Merge(datFile.GetItemsForBucket(key));
// If the rom list is empty or null, just skip it
if (items == null || items.Count == 0)
@@ -922,7 +922,7 @@ namespace SabreTools.DatFiles
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "datFile.All DATs");
string post = " (Duplicates)";
DatFile dupeData = DatFileTool.CreateDatFile(datFile.Header);
DatFile dupeData = CreateDatFile(datFile.Header);
dupeData.Header.SetFieldValue<string?>(DatHeader.FileNameKey, dupeData.Header.GetStringFieldValue(DatHeader.FileNameKey) + post);
dupeData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post);
dupeData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post);
@@ -1060,7 +1060,7 @@ namespace SabreTools.DatFiles
#endif
{
string innerpost = $" ({j} - {inputs[j].GetNormalizedFileName(true)} Only)";
DatFile diffData = DatFileTool.CreateDatFile(datFile.Header);
DatFile diffData = CreateDatFile(datFile.Header);
diffData.Header.SetFieldValue<string?>(DatHeader.FileNameKey, diffData.Header.GetStringFieldValue(DatHeader.FileNameKey) + innerpost);
diffData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + innerpost);
diffData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + innerpost);
@@ -1088,7 +1088,7 @@ namespace SabreTools.DatFiles
foreach (var key in datFile.Items.Keys)
#endif
{
List<DatItem> items = Merge(datFile.Items[key]);
List<DatItem> items = Merge(datFile.GetItemsForBucket(key));
// If the rom list is empty or null, just skip it
if (items == null || items.Count == 0)
@@ -1153,7 +1153,7 @@ namespace SabreTools.DatFiles
#endif
{
string innerpost = $" ({j} - {inputs[j].GetNormalizedFileName(true)} Only)";
DatFile diffData = DatFileTool.CreateDatFile(datFile.Header);
DatFile diffData = CreateDatFile(datFile.Header);
diffData.Header.SetFieldValue<string?>(DatHeader.FileNameKey, diffData.Header.GetStringFieldValue(DatHeader.FileNameKey) + innerpost);
diffData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + innerpost);
diffData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + innerpost);
@@ -1279,7 +1279,7 @@ namespace SabreTools.DatFiles
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "All DATs");
string post = " (No Duplicates)";
DatFile outerDiffData = DatFileTool.CreateDatFile(datFile.Header);
DatFile outerDiffData = CreateDatFile(datFile.Header);
outerDiffData.Header.SetFieldValue<string?>(DatHeader.FileNameKey, outerDiffData.Header.GetStringFieldValue(DatHeader.FileNameKey) + post);
outerDiffData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post);
outerDiffData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post);
@@ -1298,7 +1298,7 @@ namespace SabreTools.DatFiles
foreach (var key in datFile.Items.Keys)
#endif
{
List<DatItem> items = Merge(datFile.Items[key]);
List<DatItem> items = Merge(datFile.GetItemsForBucket(key));
// If the rom list is empty or null, just skip it
if (items == null || items.Count == 0)
@@ -1355,7 +1355,7 @@ namespace SabreTools.DatFiles
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "All DATs");
string post = " (No Duplicates)";
DatFile outerDiffData = DatFileTool.CreateDatFile(datFile.Header);
DatFile outerDiffData = CreateDatFile(datFile.Header);
outerDiffData.Header.SetFieldValue<string?>(DatHeader.FileNameKey, outerDiffData.Header.GetStringFieldValue(DatHeader.FileNameKey) + post);
outerDiffData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post);
outerDiffData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post);
@@ -1488,7 +1488,7 @@ namespace SabreTools.DatFiles
{
var input = inputs[i];
_staticLogger.User($"Adding DAT: {input.CurrentPath}");
datFiles[i] = DatFileTool.CreateDatFile(datFile.Header.CloneFiltering());
datFiles[i] = CreateDatFile(datFile.Header.CloneFiltering());
Parser.ParseInto(datFiles[i], input, i, keep: true);
#if NET40_OR_GREATER || NETCOREAPP
});
@@ -1523,7 +1523,7 @@ namespace SabreTools.DatFiles
foreach (string key in keys)
{
// Add everything from the key to the internal DAT
addTo.Add(key, addFrom.Items[key]);
addTo.Add(key, addFrom.GetItemsForBucket(key));
// Now remove the key from the source DAT
if (delete)
@@ -1616,7 +1616,7 @@ namespace SabreTools.DatFiles
foreach (var key in datFile.Items.Keys)
#endif
{
List<DatItem> items = Merge(datFile.Items[key]);
List<DatItem> items = Merge(datFile.GetItemsForBucket(key));
// If the rom list is empty or null, just skip it
if (items == null || items.Count == 0)

View File

@@ -60,7 +60,7 @@ namespace SabreTools.DatFiles.Formats
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
List<DatItem> datItems = Items.FilteredItems(key);
List<DatItem> datItems = GetItemsForBucket(key, filter: true);
// If this machine doesn't contain any writable items, skip
if (!ContainsWritable(datItems))
@@ -122,7 +122,7 @@ namespace SabreTools.DatFiles.Formats
foreach (string key in ItemsDB.SortedKeys)
{
// If this machine doesn't contain any writable items, skip
var itemsDict = ItemsDB.GetItemsForBucket(key, filter: true);
var itemsDict = GetItemsForBucketDB(key, filter: true);
if (itemsDict == null || !ContainsWritable([.. itemsDict.Values]))
continue;

View File

@@ -396,7 +396,7 @@ namespace SabreTools.DatFiles.Formats
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
List<DatItem> datItems = Items.FilteredItems(key);
List<DatItem> datItems = GetItemsForBucket(key, filter: true);
// If this machine doesn't contain any writable items, skip
if (!ContainsWritable(datItems))
@@ -478,7 +478,7 @@ namespace SabreTools.DatFiles.Formats
foreach (string key in ItemsDB.SortedKeys)
{
// If this machine doesn't contain any writable items, skip
var itemsDict = ItemsDB.GetItemsForBucket(key, filter: true);
var itemsDict = GetItemsForBucketDB(key, filter: true);
if (itemsDict == null || !ContainsWritable([.. itemsDict.Values]))
continue;

View File

@@ -224,7 +224,7 @@ namespace SabreTools.DatFiles.Formats
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)
{
List<DatItem> datItems = Items.FilteredItems(key);
List<DatItem> datItems = GetItemsForBucket(key, filter: true);
// If this machine doesn't contain any writable items, skip
if (!ContainsWritable(datItems))
@@ -307,7 +307,7 @@ namespace SabreTools.DatFiles.Formats
foreach (string key in ItemsDB.SortedKeys)
{
// If this machine doesn't contain any writable items, skip
var itemsDict = ItemsDB.GetItemsForBucket(key, filter: true);
var itemsDict = GetItemsForBucketDB(key, filter: true);
if (itemsDict == null || !ContainsWritable([.. itemsDict.Values]))
continue;

View File

@@ -44,7 +44,7 @@ namespace SabreTools.DatFiles
/// Internal dictionary for the class
/// </summary>
#if NET40_OR_GREATER || NETCOREAPP
private readonly ConcurrentDictionary<string, List<DatItem>?> items = [];
private readonly ConcurrentDictionary<string, List<DatItem>?> _items = [];
#else
private readonly Dictionary<string, List<DatItem>?> items = [];
#endif
@@ -67,7 +67,7 @@ namespace SabreTools.DatFiles
[JsonIgnore, XmlIgnore]
public ICollection<string> Keys
{
get { return items.Keys; }
get { return _items.Keys; }
}
/// <summary>
@@ -79,7 +79,7 @@ namespace SabreTools.DatFiles
{
get
{
List<string> keys = [.. items.Keys];
List<string> keys = [.. _items.Keys];
keys.Sort(new NaturalComparer());
return keys;
}
@@ -130,14 +130,14 @@ namespace SabreTools.DatFiles
EnsureKey(key);
// Now return the value
return items[key];
return _items[key];
}
}
set
{
Remove(key);
if (value == null)
items[key] = null;
_items[key] = null;
else
Add(key, value);
}
@@ -161,7 +161,7 @@ namespace SabreTools.DatFiles
return;
// Now add the value
items[key]!.Add(value);
_items[key]!.Add(value);
// Now update the statistics
DatStatistics.AddItemStatistics(value);
@@ -186,7 +186,7 @@ namespace SabreTools.DatFiles
EnsureKey(key);
// Now add the value
items[key]!.AddRange(value);
_items[key]!.AddRange(value);
// Now update the statistics
foreach (DatItem item in value)
@@ -299,23 +299,23 @@ namespace SabreTools.DatFiles
/// <summary>
/// Remove any keys that have null or empty values
/// </summary>
public void ClearEmpty()
internal void ClearEmpty()
{
string[] keys = [.. Keys];
foreach (string key in keys)
{
#if NET40_OR_GREATER || NETCOREAPP
// If the key doesn't exist, skip
if (!items.TryGetValue(key, out var value))
if (!_items.TryGetValue(key, out var value))
continue;
// If the value is null, remove
else if (value == null)
items.TryRemove(key, out _);
_items.TryRemove(key, out _);
// If there are no non-blank items, remove
else if (value!.FindIndex(i => i != null && i is not Blank) == -1)
items.TryRemove(key, out _);
_items.TryRemove(key, out _);
#else
// If the key doesn't exist, skip
if (!items.ContainsKey(key))
@@ -335,7 +335,7 @@ namespace SabreTools.DatFiles
/// <summary>
/// Remove all items marked for removal
/// </summary>
public void ClearMarked()
internal void ClearMarked()
{
string[] keys = [.. Keys];
foreach (string key in keys)
@@ -366,7 +366,7 @@ namespace SabreTools.DatFiles
// Explicit lock for some weird corner cases
lock (key)
{
return items.ContainsKey(key);
return _items.ContainsKey(key);
}
}
@@ -386,7 +386,7 @@ namespace SabreTools.DatFiles
lock (key)
{
#if NET40_OR_GREATER || NETCOREAPP
if (items.TryGetValue(key, out var list) && list != null)
if (_items.TryGetValue(key, out var list) && list != null)
return list.Contains(value);
#else
if (items.ContainsKey(key) && items[key] != null)
@@ -404,32 +404,34 @@ namespace SabreTools.DatFiles
public void EnsureKey(string key)
{
// If the key is missing from the dictionary, add it
if (!items.ContainsKey(key))
if (!_items.ContainsKey(key))
#if NET40_OR_GREATER || NETCOREAPP
items.TryAdd(key, []);
_items.TryAdd(key, []);
#else
items[key] = [];
#endif
}
/// <summary>
/// Get a list of filtered items for a given key
/// Get the items associated with a bucket name
/// </summary>
/// <param name="key">Key in the dictionary to retrieve</param>
public List<DatItem> FilteredItems(string key)
public List<DatItem> GetItemsForBucket(string bucketName, bool filter = false)
{
lock (key)
{
// Get the list, if possible
List<DatItem>? fi = items[key];
if (fi == null)
return [];
if (!_items.ContainsKey(bucketName))
return [];
// Filter the list
return fi.FindAll(i => i != null)
.FindAll(i => i.GetBoolFieldValue(DatItem.RemoveKey) != true)
.FindAll(i => i.GetFieldValue<Machine>(DatItem.MachineKey) != null);
var items = _items[bucketName];
if (items == null)
return [];
var datItems = new List<DatItem>();
foreach (DatItem item in items)
{
if (!filter || item.GetBoolFieldValue(DatItem.RemoveKey) != true)
datItems.Add(item);
}
return datItems;
}
/// <summary>
@@ -442,18 +444,18 @@ namespace SabreTools.DatFiles
lock (key)
{
// If the key doesn't exist, return
if (!ContainsKey(key) || items[key] == null)
if (!ContainsKey(key) || _items[key] == null)
return false;
// Remove the statistics first
foreach (DatItem item in items[key]!)
foreach (DatItem item in _items[key]!)
{
DatStatistics.RemoveItemStatistics(item);
}
// Remove the key from the dictionary
#if NET40_OR_GREATER || NETCOREAPP
return items.TryRemove(key, out _);
return _items.TryRemove(key, out _);
#else
return items.Remove(key);
#endif
@@ -471,13 +473,13 @@ namespace SabreTools.DatFiles
lock (key)
{
// If the key and value doesn't exist, return
if (!Contains(key, value) || items[key] == null)
if (!Contains(key, value) || _items[key] == null)
return false;
// Remove the statistics first
DatStatistics.RemoveItemStatistics(value);
return items[key]!.Remove(value);
return _items[key]!.Remove(value);
}
}
@@ -488,17 +490,17 @@ namespace SabreTools.DatFiles
public bool Reset(string key)
{
// If the key doesn't exist, return
if (!ContainsKey(key) || items[key] == null)
if (!ContainsKey(key) || _items[key] == null)
return false;
// Remove the statistics first
foreach (DatItem item in items[key]!)
foreach (DatItem item in _items[key]!)
{
DatStatistics.RemoveItemStatistics(item);
}
// Remove the key from the dictionary
items[key] = [];
_items[key] = [];
return true;
}
@@ -522,10 +524,10 @@ namespace SabreTools.DatFiles
/// <param name="dedupeType">Dedupe type that should be used</param>
/// <param name="lower">True if the key should be lowercased (default), false otherwise</param>
/// <param name="norename">True if games should only be compared on game and file name, false if system and source are counted</param>
public void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
internal void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
{
// If we have a situation where there's no dictionary or no keys at all, we skip
if (items == null || items.Count == 0)
if (_items == null || _items.Count == 0)
return;
// If the sorted type isn't the same, we want to sort the dictionary accordingly
@@ -555,7 +557,7 @@ namespace SabreTools.DatFiles
/// <param name="datItem">Item to try to match</param>
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
/// <returns>List of matched DatItem objects</returns>
public List<DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
internal List<DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
{
List<DatItem> output = [];
@@ -607,7 +609,7 @@ namespace SabreTools.DatFiles
/// <param name="datItem">Item to try to match</param>
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
/// <returns>True if it contains the rom, false otherwise</returns>
public bool HasDuplicates(DatItem datItem, bool sorted = false)
internal bool HasDuplicates(DatItem datItem, bool sorted = false)
{
// Check for an empty rom list first
if (DatStatistics.TotalCount == 0)
@@ -820,13 +822,14 @@ namespace SabreTools.DatFiles
#endregion
// TODO: All internal, can this be put into a better location?
#region Filtering
/// <summary>
/// Execute all filters in a filter runner on the items in the dictionary
/// </summary>
/// <param name="filterRunner">Preconfigured filter runner to use</param>
public void ExecuteFilters(FilterRunner filterRunner)
internal void ExecuteFilters(FilterRunner filterRunner)
{
List<string> keys = [.. Keys];
#if NET452_OR_GREATER || NETCOREAPP
@@ -867,7 +870,7 @@ namespace SabreTools.DatFiles
/// Use game descriptions as names, updating cloneof/romof/sampleof
/// </summary>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
public void MachineDescriptionToName(bool throwOnError = false)
internal void MachineDescriptionToName(bool throwOnError = false)
{
try
{
@@ -883,6 +886,39 @@ namespace SabreTools.DatFiles
}
}
/// <summary>
/// Ensure that all roms are in their own game (or at least try to ensure)
/// </summary>
internal void SetOneRomPerGame()
{
// For each rom, we want to update the game to be "<game name>/<rom name>"
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(Keys, Core.Globals.ParallelOptions, key =>
#elif NET40_OR_GREATER
Parallel.ForEach(Keys, key =>
#else
foreach (var key in Keys)
#endif
{
var items = this[key];
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
for (int i = 0; i < items.Count; i++)
{
SetOneRomPerGame(items[i]);
}
#if NET40_OR_GREATER || NETCOREAPP
});
#else
}
#endif
}
/// <summary>
/// Filter a DAT using 1G1R logic given an ordered set of regions
/// </summary>
@@ -897,7 +933,7 @@ namespace SabreTools.DatFiles
/// to clone sets based on name, nor does it have the ability to match on the
/// Release DatItem type.
/// </remarks>
public void SetOneGamePerRegion(List<string> regionList)
internal void SetOneGamePerRegion(List<string> regionList)
{
// If we have null region list, make it empty
regionList ??= [];
@@ -976,43 +1012,10 @@ namespace SabreTools.DatFiles
RemoveTagsFromChild();
}
/// <summary>
/// Ensure that all roms are in their own game (or at least try to ensure)
/// </summary>
public void SetOneRomPerGame()
{
// For each rom, we want to update the game to be "<game name>/<rom name>"
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(Keys, Core.Globals.ParallelOptions, key =>
#elif NET40_OR_GREATER
Parallel.ForEach(Keys, key =>
#else
foreach (var key in Keys)
#endif
{
var items = this[key];
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
for (int i = 0; i < items.Count; i++)
{
SetOneRomPerGame(items[i]);
}
#if NET40_OR_GREATER || NETCOREAPP
});
#else
}
#endif
}
/// <summary>
/// Strip the dates from the beginning of scene-style set names
/// </summary>
public void StripSceneDatesFromItems()
internal void StripSceneDatesFromItems()
{
// Set the regex pattern to use
string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)";
@@ -1184,12 +1187,13 @@ namespace SabreTools.DatFiles
#endregion
// TODO: All internal, can this be put into a better location?
#region Splitting
/// <summary>
/// Use romof tags to add roms to the children
/// </summary>
public void AddRomsFromBios()
internal void AddRomsFromBios()
{
List<string> games = [.. Keys];
games.Sort();
@@ -1233,7 +1237,7 @@ namespace SabreTools.DatFiles
/// </summary>
/// <param name="dev">True if only child device sets are touched, false for non-device sets (default)</param>
/// <param name="useSlotOptions">True if slotoptions tags are used as well, false otherwise</param>
public bool AddRomsFromDevices(bool dev, bool useSlotOptions)
internal bool AddRomsFromDevices(bool dev, bool useSlotOptions)
{
bool foundnew = false;
List<string> machines = [.. Keys];
@@ -1382,7 +1386,7 @@ namespace SabreTools.DatFiles
/// <summary>
/// Use cloneof tags to add roms to the children, setting the new romof tag in the process
/// </summary>
public void AddRomsFromParent()
internal void AddRomsFromParent()
{
List<string> games = [.. Keys];
games.Sort();
@@ -1437,7 +1441,7 @@ namespace SabreTools.DatFiles
/// </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>
public void AddRomsFromChildren(bool subfolder, bool skipDedup)
internal void AddRomsFromChildren(bool subfolder, bool skipDedup)
{
List<string> games = [.. Keys];
games.Sort();
@@ -1563,7 +1567,7 @@ namespace SabreTools.DatFiles
/// <summary>
/// Remove all BIOS and device sets
/// </summary>
public void RemoveBiosAndDeviceSets()
internal void RemoveBiosAndDeviceSets()
{
List<string> games = [.. Keys];
games.Sort();
@@ -1593,7 +1597,7 @@ namespace SabreTools.DatFiles
/// Use romof tags to remove bios roms from children
/// </summary>
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
public void RemoveBiosRomsFromChild(bool bios)
internal void RemoveBiosRomsFromChild(bool bios)
{
// Loop through the romof tags
List<string> games = [.. Keys];
@@ -1640,7 +1644,7 @@ namespace SabreTools.DatFiles
/// <summary>
/// Use cloneof tags to remove roms from the children
/// </summary>
public void RemoveRomsFromChild()
internal void RemoveRomsFromChild()
{
List<string> games = [.. Keys];
games.Sort();
@@ -1690,7 +1694,7 @@ namespace SabreTools.DatFiles
/// <summary>
/// Remove all romof and cloneof tags from all games
/// </summary>
public void RemoveTagsFromChild()
internal void RemoveTagsFromChild()
{
List<string> games = [.. Keys];
games.Sort();
@@ -1724,13 +1728,13 @@ namespace SabreTools.DatFiles
DatStatistics.ResetStatistics();
// If we have a blank Dat in any way, return
if (items == null)
if (_items == null)
return;
// Loop through and add
foreach (string key in items.Keys)
foreach (string key in _items.Keys)
{
List<DatItem>? datItems = items[key];
List<DatItem>? datItems = _items[key];
if (datItems == null)
continue;
@@ -1745,50 +1749,50 @@ namespace SabreTools.DatFiles
#region IDictionary Implementations
public ICollection<List<DatItem>?> Values => ((IDictionary<string, List<DatItem>?>)items).Values;
public ICollection<List<DatItem>?> Values => ((IDictionary<string, List<DatItem>?>)_items).Values;
public int Count => ((ICollection<KeyValuePair<string, List<DatItem>?>>)items).Count;
public int Count => ((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).Count;
public bool IsReadOnly => ((ICollection<KeyValuePair<string, List<DatItem>?>>)items).IsReadOnly;
public bool IsReadOnly => ((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).IsReadOnly;
public bool TryGetValue(string key, out List<DatItem>? value)
{
return ((IDictionary<string, List<DatItem>?>)items).TryGetValue(key, out value);
return ((IDictionary<string, List<DatItem>?>)_items).TryGetValue(key, out value);
}
public void Add(KeyValuePair<string, List<DatItem>?> item)
{
((ICollection<KeyValuePair<string, List<DatItem>?>>)items).Add(item);
((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).Add(item);
}
public void Clear()
{
((ICollection<KeyValuePair<string, List<DatItem>?>>)items).Clear();
((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).Clear();
}
public bool Contains(KeyValuePair<string, List<DatItem>?> item)
{
return ((ICollection<KeyValuePair<string, List<DatItem>?>>)items).Contains(item);
return ((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).Contains(item);
}
public void CopyTo(KeyValuePair<string, List<DatItem>?>[] array, int arrayIndex)
{
((ICollection<KeyValuePair<string, List<DatItem>?>>)items).CopyTo(array, arrayIndex);
((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).CopyTo(array, arrayIndex);
}
public bool Remove(KeyValuePair<string, List<DatItem>?> item)
{
return ((ICollection<KeyValuePair<string, List<DatItem>?>>)items).Remove(item);
return ((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).Remove(item);
}
public IEnumerator<KeyValuePair<string, List<DatItem>?>> GetEnumerator()
{
return ((IEnumerable<KeyValuePair<string, List<DatItem>?>>)items).GetEnumerator();
return ((IEnumerable<KeyValuePair<string, List<DatItem>?>>)_items).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)items).GetEnumerator();
return ((IEnumerable)_items).GetEnumerator();
}
#endregion

View File

@@ -286,7 +286,7 @@ namespace SabreTools.DatFiles
/// <summary>
/// Remove any keys that have null or empty values
/// </summary>
public void ClearEmpty()
internal void ClearEmpty()
{
var keys = Array.FindAll(SortedKeys, k => k != null);
foreach (string key in keys)
@@ -308,7 +308,7 @@ namespace SabreTools.DatFiles
/// <summary>
/// Remove all items marked for removal
/// </summary>
public void ClearMarked()
internal void ClearMarked()
{
var itemIndices = _items.Keys;
foreach (long itemIndex in itemIndices)
@@ -594,7 +594,7 @@ namespace SabreTools.DatFiles
/// <param name="lower">True if the key should be lowercased (default), false otherwise</param>
/// <param name="norename">True if games should only be compared on game and file name, false if system and source are counted</param>
/// <returns></returns>
public void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
internal void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
{
// If the sorted type isn't the same, we want to sort the dictionary accordingly
if (_bucketedBy != bucketBy && bucketBy != ItemKey.NULL)
@@ -618,7 +618,7 @@ namespace SabreTools.DatFiles
/// <param name="datItem">Item to try to match</param>
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
/// <returns>List of matched DatItem objects</returns>
public Dictionary<long, DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
internal Dictionary<long, DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
{
Dictionary<long, DatItem> output = [];
@@ -663,7 +663,7 @@ namespace SabreTools.DatFiles
/// <param name="datItem">Item to try to match</param>
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
/// <returns>List of matched DatItem objects</returns>
public Dictionary<long, DatItem> GetDuplicates(KeyValuePair<long, DatItem> datItem, bool sorted = false)
internal Dictionary<long, DatItem> GetDuplicates(KeyValuePair<long, DatItem> datItem, bool sorted = false)
{
Dictionary<long, DatItem> output = [];
@@ -708,7 +708,7 @@ namespace SabreTools.DatFiles
/// <param name="datItem">Item to try to match</param>
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
/// <returns>True if it contains the rom, false otherwise</returns>
public bool HasDuplicates(KeyValuePair<long, DatItem> datItem, bool sorted = false)
internal bool HasDuplicates(KeyValuePair<long, DatItem> datItem, bool sorted = false)
{
// Check for an empty rom list first
if (DatStatistics.TotalCount == 0)
@@ -1206,13 +1206,14 @@ namespace SabreTools.DatFiles
#endregion
// TODO: All internal, can this be put into a better location?
#region Filtering
/// <summary>
/// Execute all filters in a filter runner on the items in the dictionary
/// </summary>
/// <param name="filterRunner">Preconfigured filter runner to use</param>
public void ExecuteFilters(FilterRunner filterRunner)
internal void ExecuteFilters(FilterRunner filterRunner)
{
List<string> keys = [.. SortedKeys];
#if NET452_OR_GREATER || NETCOREAPP
@@ -1235,7 +1236,7 @@ namespace SabreTools.DatFiles
/// Use game descriptions as names, updating cloneof/romof/sampleof
/// </summary>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
public void MachineDescriptionToName(bool throwOnError = false)
internal void MachineDescriptionToName(bool throwOnError = false)
{
try
{
@@ -1251,6 +1252,39 @@ namespace SabreTools.DatFiles
}
}
/// <summary>
/// Ensure that all roms are in their own game (or at least try to ensure)
/// </summary>
internal void SetOneRomPerGame()
{
// For each rom, we want to update the game to be "<game name>/<rom name>"
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(SortedKeys, Core.Globals.ParallelOptions, key =>
#elif NET40_OR_GREATER
Parallel.ForEach(SortedKeys, key =>
#else
foreach (var key in SortedKeys)
#endif
{
var items = GetItemsForBucket(key);
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
foreach (var item in items)
{
SetOneRomPerGame(item);
}
#if NET40_OR_GREATER || NETCOREAPP
});
#else
}
#endif
}
/// <summary>
/// Filter a DAT using 1G1R logic given an ordered set of regions
/// </summary>
@@ -1265,7 +1299,7 @@ namespace SabreTools.DatFiles
/// to clone sets based on name, nor does it have the ability to match on the
/// Release DatItem type.
/// </remarks>
public void SetOneGamePerRegion(List<string> regionList)
internal void SetOneGamePerRegion(List<string> regionList)
{
// If we have null region list, make it empty
regionList ??= [];
@@ -1351,43 +1385,10 @@ namespace SabreTools.DatFiles
RemoveTagsFromChild();
}
/// <summary>
/// Ensure that all roms are in their own game (or at least try to ensure)
/// </summary>
public void SetOneRomPerGame()
{
// For each rom, we want to update the game to be "<game name>/<rom name>"
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(SortedKeys, Core.Globals.ParallelOptions, key =>
#elif NET40_OR_GREATER
Parallel.ForEach(SortedKeys, key =>
#else
foreach (var key in SortedKeys)
#endif
{
var items = GetItemsForBucket(key);
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
foreach (var item in items)
{
SetOneRomPerGame(item);
}
#if NET40_OR_GREATER || NETCOREAPP
});
#else
}
#endif
}
/// <summary>
/// Strip the dates from the beginning of scene-style set names
/// </summary>
public void StripSceneDatesFromItems()
internal void StripSceneDatesFromItems()
{
// Set the regex pattern to use
string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)";
@@ -1599,12 +1600,13 @@ namespace SabreTools.DatFiles
#endregion
// TODO: All internal, can this be put into a better location?
#region Splitting
/// <summary>
/// Use romof tags to add roms to the children
/// </summary>
public void AddRomsFromBios()
internal void AddRomsFromBios()
{
List<string> games = [.. SortedKeys];
foreach (string game in games)
@@ -1650,7 +1652,7 @@ namespace SabreTools.DatFiles
/// </summary>
/// <param name="dev">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>
public bool AddRomsFromDevices(bool dev, bool useSlotOptions)
internal bool AddRomsFromDevices(bool dev, bool useSlotOptions)
{
bool foundnew = false;
List<string> games = [.. SortedKeys];
@@ -1812,7 +1814,7 @@ namespace SabreTools.DatFiles
/// <summary>
/// Use cloneof tags to add roms to the children, setting the new romof tag in the process
/// </summary>
public void AddRomsFromParent()
internal void AddRomsFromParent()
{
List<string> games = [.. SortedKeys];
foreach (string game in games)
@@ -1875,7 +1877,7 @@ namespace SabreTools.DatFiles
/// </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>
public void AddRomsFromChildren(bool subfolder, bool skipDedup)
internal void AddRomsFromChildren(bool subfolder, bool skipDedup)
{
List<string> games = [.. SortedKeys];
foreach (string game in games)
@@ -2002,7 +2004,7 @@ namespace SabreTools.DatFiles
/// <summary>
/// Remove all BIOS and device sets
/// </summary>
public void RemoveBiosAndDeviceSets()
internal void RemoveBiosAndDeviceSets()
{
List<string> games = [.. SortedKeys];
foreach (string game in games)
@@ -2033,7 +2035,7 @@ namespace SabreTools.DatFiles
/// Use romof tags to remove bios roms from children
/// </summary>
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
public void RemoveBiosRomsFromChild(bool bios)
internal void RemoveBiosRomsFromChild(bool bios)
{
// Loop through the romof tags
List<string> games = [.. SortedKeys];
@@ -2078,7 +2080,7 @@ namespace SabreTools.DatFiles
/// <summary>
/// Use cloneof tags to remove roms from the children
/// </summary>
public void RemoveRomsFromChild()
internal void RemoveRomsFromChild()
{
List<string> games = [.. SortedKeys];
foreach (string game in games)
@@ -2134,7 +2136,7 @@ namespace SabreTools.DatFiles
/// <summary>
/// Remove all romof and cloneof tags from all games
/// </summary>
public void RemoveTagsFromChild()
internal void RemoveTagsFromChild()
{
List<string> games = [.. SortedKeys];
foreach (string game in games)

View File

@@ -24,6 +24,7 @@
<ItemGroup>
<InternalsVisibleTo Include="SabreTools.DatFiles.Test" />
<InternalsVisibleTo Include="SabreTools.Test" />
</ItemGroup>
<ItemGroup>