mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Create passthrough methods for scaffolding
This commit is contained in:
@@ -71,7 +71,7 @@ namespace SabreTools.DatFiles
|
|||||||
// Loop through the sorted items and create games for them
|
// Loop through the sorted items and create games for them
|
||||||
foreach (string key in Items.SortedKeys)
|
foreach (string key in Items.SortedKeys)
|
||||||
{
|
{
|
||||||
var items = Items.FilteredItems(key);
|
var items = Items.GetItemsForBucket(key, filter: true);
|
||||||
if (items == null || items.Count == 0)
|
if (items == null || items.Count == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -494,7 +494,7 @@ namespace SabreTools.DatFiles
|
|||||||
// Loop through the sorted items and create games for them
|
// Loop through the sorted items and create games for them
|
||||||
foreach (string key in ItemsDB.SortedKeys)
|
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)
|
if (items == null || items.Count == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,13 @@ namespace SabreTools.DatFiles
|
|||||||
[JsonProperty("items"), XmlElement("items")]
|
[JsonProperty("items"), XmlElement("items")]
|
||||||
public ItemDictionaryDB ItemsDB { get; private set; } = new ItemDictionaryDB();
|
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>
|
/// <summary>
|
||||||
/// List of supported types for writing
|
/// List of supported types for writing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -134,21 +141,7 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Filtering
|
#region Item Dictionary Passthrough - Accessors
|
||||||
|
|
||||||
/// <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
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a value to the file dictionary
|
/// Add a value to the file dictionary
|
||||||
@@ -228,6 +221,18 @@ namespace SabreTools.DatFiles
|
|||||||
ItemsDB.ClearMarked();
|
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>
|
/// <summary>
|
||||||
/// Remove a key from the file dictionary if it exists
|
/// Remove a key from the file dictionary if it exists
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -248,6 +253,203 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
#endregion
|
#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
|
#region Parsing
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -320,7 +320,7 @@ namespace SabreTools.DatFiles
|
|||||||
foreach (var key in keys)
|
foreach (var key in keys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
List<DatItem>? items = datFile.Items[key];
|
List<DatItem>? items = datFile.GetItemsForBucket(key);
|
||||||
if (items == null)
|
if (items == null)
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
@@ -391,7 +391,7 @@ namespace SabreTools.DatFiles
|
|||||||
foreach (var key in keys)
|
foreach (var key in keys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
var items = datFile.ItemsDB.GetItemsForBucket(key);
|
var items = datFile.GetItemsForBucketDB(key);
|
||||||
if (items == null)
|
if (items == null)
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
@@ -462,8 +462,8 @@ namespace SabreTools.DatFiles
|
|||||||
if (itemFieldNames.Count > 0)
|
if (itemFieldNames.Count > 0)
|
||||||
{
|
{
|
||||||
// For comparison's sake, we want to use CRC as the base bucketing
|
// For comparison's sake, we want to use CRC as the base bucketing
|
||||||
datFile.Items.BucketBy(ItemKey.CRC, DedupeType.Full);
|
datFile.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||||
intDat.Items.BucketBy(ItemKey.CRC, DedupeType.None);
|
intDat.BucketBy(ItemKey.CRC, DedupeType.None);
|
||||||
|
|
||||||
// Then we do a hashwise comparison against the base DAT
|
// Then we do a hashwise comparison against the base DAT
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
@@ -474,7 +474,7 @@ namespace SabreTools.DatFiles
|
|||||||
foreach (var key in intDat.Items.Keys)
|
foreach (var key in intDat.Items.Keys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
List<DatItem>? datItems = intDat.Items[key];
|
List<DatItem>? datItems = intDat.GetItemsForBucket(key);
|
||||||
if (datItems == null)
|
if (datItems == null)
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
@@ -510,8 +510,8 @@ namespace SabreTools.DatFiles
|
|||||||
if (machineFieldNames.Count > 0)
|
if (machineFieldNames.Count > 0)
|
||||||
{
|
{
|
||||||
// For comparison's sake, we want to use Machine Name as the base bucketing
|
// For comparison's sake, we want to use Machine Name as the base bucketing
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.Full);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.Full);
|
||||||
intDat.Items.BucketBy(ItemKey.Machine, DedupeType.None);
|
intDat.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||||
|
|
||||||
// Then we do a namewise comparison against the base DAT
|
// Then we do a namewise comparison against the base DAT
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
@@ -522,7 +522,7 @@ namespace SabreTools.DatFiles
|
|||||||
foreach (var key in intDat.Items.Keys)
|
foreach (var key in intDat.Items.Keys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
List<DatItem>? datItems = intDat.Items[key];
|
List<DatItem>? datItems = intDat.GetItemsForBucket(key);
|
||||||
if (datItems == null)
|
if (datItems == null)
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
@@ -579,8 +579,8 @@ namespace SabreTools.DatFiles
|
|||||||
if (itemFieldNames.Count > 0)
|
if (itemFieldNames.Count > 0)
|
||||||
{
|
{
|
||||||
// For comparison's sake, we want to use CRC as the base bucketing
|
// For comparison's sake, we want to use CRC as the base bucketing
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.CRC, DedupeType.Full);
|
datFile.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||||
intDat.ItemsDB.BucketBy(ItemKey.CRC, DedupeType.None);
|
intDat.BucketBy(ItemKey.CRC, DedupeType.None);
|
||||||
|
|
||||||
// Then we do a hashwise comparison against the base DAT
|
// Then we do a hashwise comparison against the base DAT
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
@@ -591,7 +591,7 @@ namespace SabreTools.DatFiles
|
|||||||
foreach (var key in intDat.ItemsDB.SortedKeys)
|
foreach (var key in intDat.ItemsDB.SortedKeys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
var datItems = intDat.ItemsDB.GetItemsForBucket(key);
|
var datItems = intDat.GetItemsForBucketDB(key);
|
||||||
if (datItems == null)
|
if (datItems == null)
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
@@ -601,7 +601,7 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
foreach (var datItem in datItems)
|
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)
|
if (datItem.Value.Clone() is not DatItem newDatItem)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -620,8 +620,8 @@ namespace SabreTools.DatFiles
|
|||||||
if (machineFieldNames.Count > 0)
|
if (machineFieldNames.Count > 0)
|
||||||
{
|
{
|
||||||
// For comparison's sake, we want to use Machine Name as the base bucketing
|
// For comparison's sake, we want to use Machine Name as the base bucketing
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.Full);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.Full);
|
||||||
intDat.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None);
|
intDat.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||||
|
|
||||||
// Then we do a namewise comparison against the base DAT
|
// Then we do a namewise comparison against the base DAT
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
@@ -632,7 +632,7 @@ namespace SabreTools.DatFiles
|
|||||||
foreach (var key in intDat.ItemsDB.SortedKeys)
|
foreach (var key in intDat.ItemsDB.SortedKeys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
var datItems = intDat.ItemsDB.GetItemsForBucket(key);
|
var datItems = intDat.GetItemsForBucketDB(key);
|
||||||
if (datItems == null)
|
if (datItems == null)
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
@@ -642,7 +642,7 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
foreach (var datItem in datItems)
|
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);
|
var intMachine = intDat.ItemsDB.GetMachineForItem(datItem.Key);
|
||||||
if (datMachine.Value != null && intMachine.Value != null)
|
if (datMachine.Value != null && intMachine.Value != null)
|
||||||
Replacer.ReplaceFields(intMachine.Value, datMachine.Value, machineFieldNames, onlySame);
|
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
|
// For comparison's sake, we want to use a base ordering
|
||||||
if (useGames)
|
if (useGames)
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||||
else
|
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");
|
InternalStopwatch watch = new($"Comparing '{intDat.Header.GetStringFieldValue(DatHeader.FileNameKey)}' to base DAT");
|
||||||
|
|
||||||
// For comparison's sake, we want to a the base bucketing
|
// For comparison's sake, we want to a the base bucketing
|
||||||
if (useGames)
|
if (useGames)
|
||||||
intDat.Items.BucketBy(ItemKey.Machine, DedupeType.None);
|
intDat.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||||
else
|
else
|
||||||
intDat.Items.BucketBy(ItemKey.CRC, DedupeType.Full);
|
intDat.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||||
|
|
||||||
// Then we compare against the base DAT
|
// Then we compare against the base DAT
|
||||||
List<string> keys = [.. intDat.Items.Keys];
|
List<string> keys = [.. intDat.Items.Keys];
|
||||||
@@ -740,7 +740,7 @@ namespace SabreTools.DatFiles
|
|||||||
// Standard Against uses hashes
|
// Standard Against uses hashes
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<DatItem>? datItems = intDat.Items[key];
|
List<DatItem>? datItems = intDat.GetItemsForBucket(key);
|
||||||
if (datItems == null)
|
if (datItems == null)
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
@@ -751,7 +751,7 @@ namespace SabreTools.DatFiles
|
|||||||
List<DatItem> keepDatItems = [];
|
List<DatItem> keepDatItems = [];
|
||||||
foreach (DatItem datItem in datItems)
|
foreach (DatItem datItem in datItems)
|
||||||
{
|
{
|
||||||
if (!datFile.Items.HasDuplicates(datItem, true))
|
if (!datFile.HasDuplicates(datItem, true))
|
||||||
keepDatItems.Add(datItem);
|
keepDatItems.Add(datItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -780,7 +780,7 @@ namespace SabreTools.DatFiles
|
|||||||
List<DatFile> outDats = [];
|
List<DatFile> outDats = [];
|
||||||
|
|
||||||
// Ensure the current DatFile is sorted optimally
|
// 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
|
// Loop through each of the inputs and get or create a new DatData object
|
||||||
InternalStopwatch watch = new("Initializing and filling all output DATs");
|
InternalStopwatch watch = new("Initializing and filling all output DATs");
|
||||||
@@ -795,10 +795,10 @@ namespace SabreTools.DatFiles
|
|||||||
for (int j = 0; j < datHeaders.Count; j++)
|
for (int j = 0; j < datHeaders.Count; j++)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
DatFile diffData = DatFileTool.CreateDatFile(datHeaders[j]);
|
DatFile diffData = CreateDatFile(datHeaders[j]);
|
||||||
diffData.ResetDictionary();
|
diffData.ResetDictionary();
|
||||||
FillWithSourceIndex(datFile, diffData, j);
|
FillWithSourceIndex(datFile, diffData, j);
|
||||||
//FillWithSourceIndexDB(datFile, diffData, j);
|
FillWithSourceIndexDB(datFile, diffData, j);
|
||||||
outDatsArray[j] = diffData;
|
outDatsArray[j] = diffData;
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
});
|
});
|
||||||
@@ -844,7 +844,7 @@ namespace SabreTools.DatFiles
|
|||||||
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "datFile.All DATs");
|
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "datFile.All DATs");
|
||||||
|
|
||||||
string post = " (Duplicates)";
|
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?>(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.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);
|
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)
|
foreach (var key in datFile.Items.Keys)
|
||||||
#endif
|
#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 the rom list is empty or null, just skip it
|
||||||
if (items == null || items.Count == 0)
|
if (items == null || items.Count == 0)
|
||||||
@@ -922,7 +922,7 @@ namespace SabreTools.DatFiles
|
|||||||
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "datFile.All DATs");
|
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "datFile.All DATs");
|
||||||
|
|
||||||
string post = " (Duplicates)";
|
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?>(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.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);
|
dupeData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post);
|
||||||
@@ -1060,7 +1060,7 @@ namespace SabreTools.DatFiles
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
string innerpost = $" ({j} - {inputs[j].GetNormalizedFileName(true)} Only)";
|
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?>(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.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);
|
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)
|
foreach (var key in datFile.Items.Keys)
|
||||||
#endif
|
#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 the rom list is empty or null, just skip it
|
||||||
if (items == null || items.Count == 0)
|
if (items == null || items.Count == 0)
|
||||||
@@ -1153,7 +1153,7 @@ namespace SabreTools.DatFiles
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
string innerpost = $" ({j} - {inputs[j].GetNormalizedFileName(true)} Only)";
|
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?>(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.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);
|
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");
|
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "All DATs");
|
||||||
|
|
||||||
string post = " (No Duplicates)";
|
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?>(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.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);
|
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)
|
foreach (var key in datFile.Items.Keys)
|
||||||
#endif
|
#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 the rom list is empty or null, just skip it
|
||||||
if (items == null || items.Count == 0)
|
if (items == null || items.Count == 0)
|
||||||
@@ -1355,7 +1355,7 @@ namespace SabreTools.DatFiles
|
|||||||
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "All DATs");
|
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "All DATs");
|
||||||
|
|
||||||
string post = " (No Duplicates)";
|
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?>(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.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);
|
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];
|
var input = inputs[i];
|
||||||
_staticLogger.User($"Adding DAT: {input.CurrentPath}");
|
_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);
|
Parser.ParseInto(datFiles[i], input, i, keep: true);
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
});
|
});
|
||||||
@@ -1523,7 +1523,7 @@ namespace SabreTools.DatFiles
|
|||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
// Add everything from the key to the internal DAT
|
// 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
|
// Now remove the key from the source DAT
|
||||||
if (delete)
|
if (delete)
|
||||||
@@ -1616,7 +1616,7 @@ namespace SabreTools.DatFiles
|
|||||||
foreach (var key in datFile.Items.Keys)
|
foreach (var key in datFile.Items.Keys)
|
||||||
#endif
|
#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 the rom list is empty or null, just skip it
|
||||||
if (items == null || items.Count == 0)
|
if (items == null || items.Count == 0)
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
// Use a sorted list of games to output
|
// Use a sorted list of games to output
|
||||||
foreach (string key in Items.SortedKeys)
|
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 this machine doesn't contain any writable items, skip
|
||||||
if (!ContainsWritable(datItems))
|
if (!ContainsWritable(datItems))
|
||||||
@@ -122,7 +122,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
foreach (string key in ItemsDB.SortedKeys)
|
foreach (string key in ItemsDB.SortedKeys)
|
||||||
{
|
{
|
||||||
// If this machine doesn't contain any writable items, skip
|
// 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]))
|
if (itemsDict == null || !ContainsWritable([.. itemsDict.Values]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
// Use a sorted list of games to output
|
// Use a sorted list of games to output
|
||||||
foreach (string key in Items.SortedKeys)
|
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 this machine doesn't contain any writable items, skip
|
||||||
if (!ContainsWritable(datItems))
|
if (!ContainsWritable(datItems))
|
||||||
@@ -478,7 +478,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
foreach (string key in ItemsDB.SortedKeys)
|
foreach (string key in ItemsDB.SortedKeys)
|
||||||
{
|
{
|
||||||
// If this machine doesn't contain any writable items, skip
|
// 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]))
|
if (itemsDict == null || !ContainsWritable([.. itemsDict.Values]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
// Use a sorted list of games to output
|
// Use a sorted list of games to output
|
||||||
foreach (string key in Items.SortedKeys)
|
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 this machine doesn't contain any writable items, skip
|
||||||
if (!ContainsWritable(datItems))
|
if (!ContainsWritable(datItems))
|
||||||
@@ -307,7 +307,7 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
foreach (string key in ItemsDB.SortedKeys)
|
foreach (string key in ItemsDB.SortedKeys)
|
||||||
{
|
{
|
||||||
// If this machine doesn't contain any writable items, skip
|
// 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]))
|
if (itemsDict == null || !ContainsWritable([.. itemsDict.Values]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// Internal dictionary for the class
|
/// Internal dictionary for the class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
private readonly ConcurrentDictionary<string, List<DatItem>?> items = [];
|
private readonly ConcurrentDictionary<string, List<DatItem>?> _items = [];
|
||||||
#else
|
#else
|
||||||
private readonly Dictionary<string, List<DatItem>?> items = [];
|
private readonly Dictionary<string, List<DatItem>?> items = [];
|
||||||
#endif
|
#endif
|
||||||
@@ -67,7 +67,7 @@ namespace SabreTools.DatFiles
|
|||||||
[JsonIgnore, XmlIgnore]
|
[JsonIgnore, XmlIgnore]
|
||||||
public ICollection<string> Keys
|
public ICollection<string> Keys
|
||||||
{
|
{
|
||||||
get { return items.Keys; }
|
get { return _items.Keys; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -79,7 +79,7 @@ namespace SabreTools.DatFiles
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
List<string> keys = [.. items.Keys];
|
List<string> keys = [.. _items.Keys];
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
@@ -130,14 +130,14 @@ namespace SabreTools.DatFiles
|
|||||||
EnsureKey(key);
|
EnsureKey(key);
|
||||||
|
|
||||||
// Now return the value
|
// Now return the value
|
||||||
return items[key];
|
return _items[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Remove(key);
|
Remove(key);
|
||||||
if (value == null)
|
if (value == null)
|
||||||
items[key] = null;
|
_items[key] = null;
|
||||||
else
|
else
|
||||||
Add(key, value);
|
Add(key, value);
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ namespace SabreTools.DatFiles
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Now add the value
|
// Now add the value
|
||||||
items[key]!.Add(value);
|
_items[key]!.Add(value);
|
||||||
|
|
||||||
// Now update the statistics
|
// Now update the statistics
|
||||||
DatStatistics.AddItemStatistics(value);
|
DatStatistics.AddItemStatistics(value);
|
||||||
@@ -186,7 +186,7 @@ namespace SabreTools.DatFiles
|
|||||||
EnsureKey(key);
|
EnsureKey(key);
|
||||||
|
|
||||||
// Now add the value
|
// Now add the value
|
||||||
items[key]!.AddRange(value);
|
_items[key]!.AddRange(value);
|
||||||
|
|
||||||
// Now update the statistics
|
// Now update the statistics
|
||||||
foreach (DatItem item in value)
|
foreach (DatItem item in value)
|
||||||
@@ -299,23 +299,23 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove any keys that have null or empty values
|
/// Remove any keys that have null or empty values
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ClearEmpty()
|
internal void ClearEmpty()
|
||||||
{
|
{
|
||||||
string[] keys = [.. Keys];
|
string[] keys = [.. Keys];
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
// If the key doesn't exist, skip
|
// If the key doesn't exist, skip
|
||||||
if (!items.TryGetValue(key, out var value))
|
if (!_items.TryGetValue(key, out var value))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If the value is null, remove
|
// If the value is null, remove
|
||||||
else if (value == null)
|
else if (value == null)
|
||||||
items.TryRemove(key, out _);
|
_items.TryRemove(key, out _);
|
||||||
|
|
||||||
// If there are no non-blank items, remove
|
// If there are no non-blank items, remove
|
||||||
else if (value!.FindIndex(i => i != null && i is not Blank) == -1)
|
else if (value!.FindIndex(i => i != null && i is not Blank) == -1)
|
||||||
items.TryRemove(key, out _);
|
_items.TryRemove(key, out _);
|
||||||
#else
|
#else
|
||||||
// If the key doesn't exist, skip
|
// If the key doesn't exist, skip
|
||||||
if (!items.ContainsKey(key))
|
if (!items.ContainsKey(key))
|
||||||
@@ -335,7 +335,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove all items marked for removal
|
/// Remove all items marked for removal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ClearMarked()
|
internal void ClearMarked()
|
||||||
{
|
{
|
||||||
string[] keys = [.. Keys];
|
string[] keys = [.. Keys];
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
@@ -366,7 +366,7 @@ namespace SabreTools.DatFiles
|
|||||||
// Explicit lock for some weird corner cases
|
// Explicit lock for some weird corner cases
|
||||||
lock (key)
|
lock (key)
|
||||||
{
|
{
|
||||||
return items.ContainsKey(key);
|
return _items.ContainsKey(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,7 +386,7 @@ namespace SabreTools.DatFiles
|
|||||||
lock (key)
|
lock (key)
|
||||||
{
|
{
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#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);
|
return list.Contains(value);
|
||||||
#else
|
#else
|
||||||
if (items.ContainsKey(key) && items[key] != null)
|
if (items.ContainsKey(key) && items[key] != null)
|
||||||
@@ -404,32 +404,34 @@ namespace SabreTools.DatFiles
|
|||||||
public void EnsureKey(string key)
|
public void EnsureKey(string key)
|
||||||
{
|
{
|
||||||
// If the key is missing from the dictionary, add it
|
// If the key is missing from the dictionary, add it
|
||||||
if (!items.ContainsKey(key))
|
if (!_items.ContainsKey(key))
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
items.TryAdd(key, []);
|
_items.TryAdd(key, []);
|
||||||
#else
|
#else
|
||||||
items[key] = [];
|
items[key] = [];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a list of filtered items for a given key
|
/// Get the items associated with a bucket name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key">Key in the dictionary to retrieve</param>
|
public List<DatItem> GetItemsForBucket(string bucketName, bool filter = false)
|
||||||
public List<DatItem> FilteredItems(string key)
|
|
||||||
{
|
{
|
||||||
lock (key)
|
if (!_items.ContainsKey(bucketName))
|
||||||
{
|
|
||||||
// Get the list, if possible
|
|
||||||
List<DatItem>? fi = items[key];
|
|
||||||
if (fi == null)
|
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
// Filter the list
|
var items = _items[bucketName];
|
||||||
return fi.FindAll(i => i != null)
|
if (items == null)
|
||||||
.FindAll(i => i.GetBoolFieldValue(DatItem.RemoveKey) != true)
|
return [];
|
||||||
.FindAll(i => i.GetFieldValue<Machine>(DatItem.MachineKey) != null);
|
|
||||||
|
var datItems = new List<DatItem>();
|
||||||
|
foreach (DatItem item in items)
|
||||||
|
{
|
||||||
|
if (!filter || item.GetBoolFieldValue(DatItem.RemoveKey) != true)
|
||||||
|
datItems.Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return datItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -442,18 +444,18 @@ namespace SabreTools.DatFiles
|
|||||||
lock (key)
|
lock (key)
|
||||||
{
|
{
|
||||||
// If the key doesn't exist, return
|
// If the key doesn't exist, return
|
||||||
if (!ContainsKey(key) || items[key] == null)
|
if (!ContainsKey(key) || _items[key] == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Remove the statistics first
|
// Remove the statistics first
|
||||||
foreach (DatItem item in items[key]!)
|
foreach (DatItem item in _items[key]!)
|
||||||
{
|
{
|
||||||
DatStatistics.RemoveItemStatistics(item);
|
DatStatistics.RemoveItemStatistics(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the key from the dictionary
|
// Remove the key from the dictionary
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return items.TryRemove(key, out _);
|
return _items.TryRemove(key, out _);
|
||||||
#else
|
#else
|
||||||
return items.Remove(key);
|
return items.Remove(key);
|
||||||
#endif
|
#endif
|
||||||
@@ -471,13 +473,13 @@ namespace SabreTools.DatFiles
|
|||||||
lock (key)
|
lock (key)
|
||||||
{
|
{
|
||||||
// If the key and value doesn't exist, return
|
// 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;
|
return false;
|
||||||
|
|
||||||
// Remove the statistics first
|
// Remove the statistics first
|
||||||
DatStatistics.RemoveItemStatistics(value);
|
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)
|
public bool Reset(string key)
|
||||||
{
|
{
|
||||||
// If the key doesn't exist, return
|
// If the key doesn't exist, return
|
||||||
if (!ContainsKey(key) || items[key] == null)
|
if (!ContainsKey(key) || _items[key] == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Remove the statistics first
|
// Remove the statistics first
|
||||||
foreach (DatItem item in items[key]!)
|
foreach (DatItem item in _items[key]!)
|
||||||
{
|
{
|
||||||
DatStatistics.RemoveItemStatistics(item);
|
DatStatistics.RemoveItemStatistics(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the key from the dictionary
|
// Remove the key from the dictionary
|
||||||
items[key] = [];
|
_items[key] = [];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,10 +524,10 @@ namespace SabreTools.DatFiles
|
|||||||
/// <param name="dedupeType">Dedupe type that should be used</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="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>
|
/// <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 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;
|
return;
|
||||||
|
|
||||||
// If the sorted type isn't the same, we want to sort the dictionary accordingly
|
// 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="datItem">Item to try to match</param>
|
||||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
||||||
/// <returns>List of matched DatItem objects</returns>
|
/// <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 = [];
|
List<DatItem> output = [];
|
||||||
|
|
||||||
@@ -607,7 +609,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <param name="datItem">Item to try to match</param>
|
/// <param name="datItem">Item to try to match</param>
|
||||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</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>
|
/// <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
|
// Check for an empty rom list first
|
||||||
if (DatStatistics.TotalCount == 0)
|
if (DatStatistics.TotalCount == 0)
|
||||||
@@ -820,13 +822,14 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
// TODO: All internal, can this be put into a better location?
|
||||||
#region Filtering
|
#region Filtering
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Execute all filters in a filter runner on the items in the dictionary
|
/// Execute all filters in a filter runner on the items in the dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
||||||
public void ExecuteFilters(FilterRunner filterRunner)
|
internal void ExecuteFilters(FilterRunner filterRunner)
|
||||||
{
|
{
|
||||||
List<string> keys = [.. Keys];
|
List<string> keys = [.. Keys];
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
@@ -867,7 +870,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// Use game descriptions as names, updating cloneof/romof/sampleof
|
/// Use game descriptions as names, updating cloneof/romof/sampleof
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
/// <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
|
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>
|
/// <summary>
|
||||||
/// Filter a DAT using 1G1R logic given an ordered set of regions
|
/// Filter a DAT using 1G1R logic given an ordered set of regions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -897,7 +933,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// to clone sets based on name, nor does it have the ability to match on the
|
/// to clone sets based on name, nor does it have the ability to match on the
|
||||||
/// Release DatItem type.
|
/// Release DatItem type.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public void SetOneGamePerRegion(List<string> regionList)
|
internal void SetOneGamePerRegion(List<string> regionList)
|
||||||
{
|
{
|
||||||
// If we have null region list, make it empty
|
// If we have null region list, make it empty
|
||||||
regionList ??= [];
|
regionList ??= [];
|
||||||
@@ -976,43 +1012,10 @@ namespace SabreTools.DatFiles
|
|||||||
RemoveTagsFromChild();
|
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>
|
/// <summary>
|
||||||
/// Strip the dates from the beginning of scene-style set names
|
/// Strip the dates from the beginning of scene-style set names
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void StripSceneDatesFromItems()
|
internal void StripSceneDatesFromItems()
|
||||||
{
|
{
|
||||||
// Set the regex pattern to use
|
// Set the regex pattern to use
|
||||||
string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)";
|
string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)";
|
||||||
@@ -1184,12 +1187,13 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
// TODO: All internal, can this be put into a better location?
|
||||||
#region Splitting
|
#region Splitting
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use romof tags to add roms to the children
|
/// Use romof tags to add roms to the children
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void AddRomsFromBios()
|
internal void AddRomsFromBios()
|
||||||
{
|
{
|
||||||
List<string> games = [.. Keys];
|
List<string> games = [.. Keys];
|
||||||
games.Sort();
|
games.Sort();
|
||||||
@@ -1233,7 +1237,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dev">True if only child device sets are touched, false for non-device sets (default)</param>
|
/// <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>
|
/// <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;
|
bool foundnew = false;
|
||||||
List<string> machines = [.. Keys];
|
List<string> machines = [.. Keys];
|
||||||
@@ -1382,7 +1386,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use cloneof tags to add roms to the children, setting the new romof tag in the process
|
/// Use cloneof tags to add roms to the children, setting the new romof tag in the process
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void AddRomsFromParent()
|
internal void AddRomsFromParent()
|
||||||
{
|
{
|
||||||
List<string> games = [.. Keys];
|
List<string> games = [.. Keys];
|
||||||
games.Sort();
|
games.Sort();
|
||||||
@@ -1437,7 +1441,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
public void AddRomsFromChildren(bool subfolder, bool skipDedup)
|
internal void AddRomsFromChildren(bool subfolder, bool skipDedup)
|
||||||
{
|
{
|
||||||
List<string> games = [.. Keys];
|
List<string> games = [.. Keys];
|
||||||
games.Sort();
|
games.Sort();
|
||||||
@@ -1563,7 +1567,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove all BIOS and device sets
|
/// Remove all BIOS and device sets
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void RemoveBiosAndDeviceSets()
|
internal void RemoveBiosAndDeviceSets()
|
||||||
{
|
{
|
||||||
List<string> games = [.. Keys];
|
List<string> games = [.. Keys];
|
||||||
games.Sort();
|
games.Sort();
|
||||||
@@ -1593,7 +1597,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// Use romof tags to remove bios roms from children
|
/// Use romof tags to remove bios roms from children
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
|
/// <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
|
// Loop through the romof tags
|
||||||
List<string> games = [.. Keys];
|
List<string> games = [.. Keys];
|
||||||
@@ -1640,7 +1644,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use cloneof tags to remove roms from the children
|
/// Use cloneof tags to remove roms from the children
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void RemoveRomsFromChild()
|
internal void RemoveRomsFromChild()
|
||||||
{
|
{
|
||||||
List<string> games = [.. Keys];
|
List<string> games = [.. Keys];
|
||||||
games.Sort();
|
games.Sort();
|
||||||
@@ -1690,7 +1694,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove all romof and cloneof tags from all games
|
/// Remove all romof and cloneof tags from all games
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void RemoveTagsFromChild()
|
internal void RemoveTagsFromChild()
|
||||||
{
|
{
|
||||||
List<string> games = [.. Keys];
|
List<string> games = [.. Keys];
|
||||||
games.Sort();
|
games.Sort();
|
||||||
@@ -1724,13 +1728,13 @@ namespace SabreTools.DatFiles
|
|||||||
DatStatistics.ResetStatistics();
|
DatStatistics.ResetStatistics();
|
||||||
|
|
||||||
// If we have a blank Dat in any way, return
|
// If we have a blank Dat in any way, return
|
||||||
if (items == null)
|
if (_items == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Loop through and add
|
// 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)
|
if (datItems == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -1745,50 +1749,50 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
#region IDictionary Implementations
|
#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)
|
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)
|
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()
|
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)
|
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)
|
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)
|
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()
|
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()
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
{
|
{
|
||||||
return ((IEnumerable)items).GetEnumerator();
|
return ((IEnumerable)_items).GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove any keys that have null or empty values
|
/// Remove any keys that have null or empty values
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ClearEmpty()
|
internal void ClearEmpty()
|
||||||
{
|
{
|
||||||
var keys = Array.FindAll(SortedKeys, k => k != null);
|
var keys = Array.FindAll(SortedKeys, k => k != null);
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
@@ -308,7 +308,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove all items marked for removal
|
/// Remove all items marked for removal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ClearMarked()
|
internal void ClearMarked()
|
||||||
{
|
{
|
||||||
var itemIndices = _items.Keys;
|
var itemIndices = _items.Keys;
|
||||||
foreach (long itemIndex in itemIndices)
|
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="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>
|
/// <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>
|
/// <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 the sorted type isn't the same, we want to sort the dictionary accordingly
|
||||||
if (_bucketedBy != bucketBy && bucketBy != ItemKey.NULL)
|
if (_bucketedBy != bucketBy && bucketBy != ItemKey.NULL)
|
||||||
@@ -618,7 +618,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <param name="datItem">Item to try to match</param>
|
/// <param name="datItem">Item to try to match</param>
|
||||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
||||||
/// <returns>List of matched DatItem objects</returns>
|
/// <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 = [];
|
Dictionary<long, DatItem> output = [];
|
||||||
|
|
||||||
@@ -663,7 +663,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <param name="datItem">Item to try to match</param>
|
/// <param name="datItem">Item to try to match</param>
|
||||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
||||||
/// <returns>List of matched DatItem objects</returns>
|
/// <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 = [];
|
Dictionary<long, DatItem> output = [];
|
||||||
|
|
||||||
@@ -708,7 +708,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <param name="datItem">Item to try to match</param>
|
/// <param name="datItem">Item to try to match</param>
|
||||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</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>
|
/// <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
|
// Check for an empty rom list first
|
||||||
if (DatStatistics.TotalCount == 0)
|
if (DatStatistics.TotalCount == 0)
|
||||||
@@ -1206,13 +1206,14 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
// TODO: All internal, can this be put into a better location?
|
||||||
#region Filtering
|
#region Filtering
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Execute all filters in a filter runner on the items in the dictionary
|
/// Execute all filters in a filter runner on the items in the dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
||||||
public void ExecuteFilters(FilterRunner filterRunner)
|
internal void ExecuteFilters(FilterRunner filterRunner)
|
||||||
{
|
{
|
||||||
List<string> keys = [.. SortedKeys];
|
List<string> keys = [.. SortedKeys];
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
@@ -1235,7 +1236,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// Use game descriptions as names, updating cloneof/romof/sampleof
|
/// Use game descriptions as names, updating cloneof/romof/sampleof
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
/// <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
|
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>
|
/// <summary>
|
||||||
/// Filter a DAT using 1G1R logic given an ordered set of regions
|
/// Filter a DAT using 1G1R logic given an ordered set of regions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1265,7 +1299,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// to clone sets based on name, nor does it have the ability to match on the
|
/// to clone sets based on name, nor does it have the ability to match on the
|
||||||
/// Release DatItem type.
|
/// Release DatItem type.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public void SetOneGamePerRegion(List<string> regionList)
|
internal void SetOneGamePerRegion(List<string> regionList)
|
||||||
{
|
{
|
||||||
// If we have null region list, make it empty
|
// If we have null region list, make it empty
|
||||||
regionList ??= [];
|
regionList ??= [];
|
||||||
@@ -1351,43 +1385,10 @@ namespace SabreTools.DatFiles
|
|||||||
RemoveTagsFromChild();
|
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>
|
/// <summary>
|
||||||
/// Strip the dates from the beginning of scene-style set names
|
/// Strip the dates from the beginning of scene-style set names
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void StripSceneDatesFromItems()
|
internal void StripSceneDatesFromItems()
|
||||||
{
|
{
|
||||||
// Set the regex pattern to use
|
// Set the regex pattern to use
|
||||||
string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)";
|
string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)";
|
||||||
@@ -1599,12 +1600,13 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
// TODO: All internal, can this be put into a better location?
|
||||||
#region Splitting
|
#region Splitting
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use romof tags to add roms to the children
|
/// Use romof tags to add roms to the children
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void AddRomsFromBios()
|
internal void AddRomsFromBios()
|
||||||
{
|
{
|
||||||
List<string> games = [.. SortedKeys];
|
List<string> games = [.. SortedKeys];
|
||||||
foreach (string game in games)
|
foreach (string game in games)
|
||||||
@@ -1650,7 +1652,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dev">True if only child device sets are touched, false for non-device sets</param>
|
/// <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>
|
/// <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;
|
bool foundnew = false;
|
||||||
List<string> games = [.. SortedKeys];
|
List<string> games = [.. SortedKeys];
|
||||||
@@ -1812,7 +1814,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use cloneof tags to add roms to the children, setting the new romof tag in the process
|
/// Use cloneof tags to add roms to the children, setting the new romof tag in the process
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void AddRomsFromParent()
|
internal void AddRomsFromParent()
|
||||||
{
|
{
|
||||||
List<string> games = [.. SortedKeys];
|
List<string> games = [.. SortedKeys];
|
||||||
foreach (string game in games)
|
foreach (string game in games)
|
||||||
@@ -1875,7 +1877,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
public void AddRomsFromChildren(bool subfolder, bool skipDedup)
|
internal void AddRomsFromChildren(bool subfolder, bool skipDedup)
|
||||||
{
|
{
|
||||||
List<string> games = [.. SortedKeys];
|
List<string> games = [.. SortedKeys];
|
||||||
foreach (string game in games)
|
foreach (string game in games)
|
||||||
@@ -2002,7 +2004,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove all BIOS and device sets
|
/// Remove all BIOS and device sets
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void RemoveBiosAndDeviceSets()
|
internal void RemoveBiosAndDeviceSets()
|
||||||
{
|
{
|
||||||
List<string> games = [.. SortedKeys];
|
List<string> games = [.. SortedKeys];
|
||||||
foreach (string game in games)
|
foreach (string game in games)
|
||||||
@@ -2033,7 +2035,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// Use romof tags to remove bios roms from children
|
/// Use romof tags to remove bios roms from children
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
|
/// <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
|
// Loop through the romof tags
|
||||||
List<string> games = [.. SortedKeys];
|
List<string> games = [.. SortedKeys];
|
||||||
@@ -2078,7 +2080,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use cloneof tags to remove roms from the children
|
/// Use cloneof tags to remove roms from the children
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void RemoveRomsFromChild()
|
internal void RemoveRomsFromChild()
|
||||||
{
|
{
|
||||||
List<string> games = [.. SortedKeys];
|
List<string> games = [.. SortedKeys];
|
||||||
foreach (string game in games)
|
foreach (string game in games)
|
||||||
@@ -2134,7 +2136,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove all romof and cloneof tags from all games
|
/// Remove all romof and cloneof tags from all games
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void RemoveTagsFromChild()
|
internal void RemoveTagsFromChild()
|
||||||
{
|
{
|
||||||
List<string> games = [.. SortedKeys];
|
List<string> games = [.. SortedKeys];
|
||||||
foreach (string game in games)
|
foreach (string game in games)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<InternalsVisibleTo Include="SabreTools.DatFiles.Test" />
|
<InternalsVisibleTo Include="SabreTools.DatFiles.Test" />
|
||||||
|
<InternalsVisibleTo Include="SabreTools.Test" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -106,43 +106,25 @@ namespace SabreTools.DatTools
|
|||||||
|
|
||||||
// Bucket and dedupe according to the flag
|
// Bucket and dedupe according to the flag
|
||||||
if (DedupeRoms == DedupeType.Full)
|
if (DedupeRoms == DedupeType.Full)
|
||||||
{
|
datFile.BucketBy(ItemKey.CRC, DedupeRoms);
|
||||||
datFile.Items.BucketBy(ItemKey.CRC, DedupeRoms);
|
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.CRC, DedupeRoms);
|
|
||||||
}
|
|
||||||
else if (DedupeRoms == DedupeType.Game)
|
else if (DedupeRoms == DedupeType.Game)
|
||||||
{
|
datFile.BucketBy(ItemKey.Machine, DedupeRoms);
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeRoms);
|
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeRoms);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process description to machine name
|
// Process description to machine name
|
||||||
if (DescriptionAsName == true)
|
if (DescriptionAsName == true)
|
||||||
{
|
datFile.MachineDescriptionToName(throwOnError);
|
||||||
datFile.Items.MachineDescriptionToName(throwOnError);
|
|
||||||
datFile.ItemsDB.MachineDescriptionToName(throwOnError);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we are removing scene dates, do that now
|
// If we are removing scene dates, do that now
|
||||||
if (SceneDateStrip == true)
|
if (SceneDateStrip == true)
|
||||||
{
|
datFile.StripSceneDatesFromItems();
|
||||||
datFile.Items.StripSceneDatesFromItems();
|
|
||||||
datFile.ItemsDB.StripSceneDatesFromItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run the one rom per game logic, if required
|
// Run the one rom per game logic, if required
|
||||||
if (OneGamePerRegion == true && RegionList != null)
|
if (OneGamePerRegion == true && RegionList != null)
|
||||||
{
|
datFile.SetOneGamePerRegion(RegionList);
|
||||||
datFile.Items.SetOneGamePerRegion(RegionList);
|
|
||||||
datFile.ItemsDB.SetOneGamePerRegion(RegionList);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run the one rom per game logic, if required
|
// Run the one rom per game logic, if required
|
||||||
if (OneRomPerGame == true)
|
if (OneRomPerGame == true)
|
||||||
{
|
datFile.SetOneRomPerGame();
|
||||||
datFile.Items.SetOneRomPerGame();
|
|
||||||
datFile.ItemsDB.SetOneRomPerGame();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove all marked items
|
// Remove all marked items
|
||||||
datFile.ClearMarked();
|
datFile.ClearMarked();
|
||||||
@@ -174,7 +156,7 @@ namespace SabreTools.DatTools
|
|||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
// For every item in the current key
|
// For every item in the current key
|
||||||
var items = datFile.Items[key];
|
var items = datFile.GetItemsForBucket(key);
|
||||||
if (items == null)
|
if (items == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -203,7 +185,7 @@ namespace SabreTools.DatTools
|
|||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
// For every item in the current key
|
// For every item in the current key
|
||||||
var items = datFile.ItemsDB.GetItemsForBucket(key);
|
var items = datFile.GetItemsForBucketDB(key);
|
||||||
if (items == null)
|
if (items == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ namespace SabreTools.DatTools
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Bucket by game first
|
// Bucket by game first
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||||
|
|
||||||
// Create mappings based on the extra items
|
// Create mappings based on the extra items
|
||||||
var combinedMaps = CombineExtras();
|
var combinedMaps = CombineExtras();
|
||||||
@@ -109,7 +109,7 @@ namespace SabreTools.DatTools
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Get the list of DatItems for the machine
|
// Get the list of DatItems for the machine
|
||||||
var datItems = datFile.Items[machine];
|
var datItems = datFile.GetItemsForBucket(machine);
|
||||||
if (datItems == null)
|
if (datItems == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ namespace SabreTools.DatTools
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Bucket by game first
|
// Bucket by game first
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||||
|
|
||||||
// Create mappings based on the extra items
|
// Create mappings based on the extra items
|
||||||
var combinedMaps = CombineExtras();
|
var combinedMaps = CombineExtras();
|
||||||
@@ -168,7 +168,7 @@ namespace SabreTools.DatTools
|
|||||||
foreach (string game in games)
|
foreach (string game in games)
|
||||||
{
|
{
|
||||||
// Get the list of DatItems for the machine
|
// Get the list of DatItems for the machine
|
||||||
var datItems = datFile.ItemsDB.GetItemsForBucket(game);
|
var datItems = datFile.GetItemsForBucketDB(game);
|
||||||
if (datItems == null)
|
if (datItems == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -102,18 +102,14 @@ namespace SabreTools.DatTools
|
|||||||
_staticLogger.User("Creating device non-merged sets from the DAT");
|
_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
|
// For sake of ease, the first thing we want to do is bucket by game
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
|
||||||
|
|
||||||
// Now we want to loop through all of the games and set the correct information
|
// Now we want to loop through all of the games and set the correct information
|
||||||
while (datFile.Items.AddRomsFromDevices(false, false)) ;
|
while (datFile.AddRomsFromDevices(false, false)) ;
|
||||||
while (datFile.ItemsDB.AddRomsFromDevices(false, false)) ;
|
while (datFile.AddRomsFromDevices(true, false)) ;
|
||||||
while (datFile.Items.AddRomsFromDevices(true, false)) ;
|
|
||||||
while (datFile.ItemsDB.AddRomsFromDevices(true, false)) ;
|
|
||||||
|
|
||||||
// Then, remove the romof and cloneof tags so it's not picked up by the manager
|
// Then, remove the romof and cloneof tags so it's not picked up by the manager
|
||||||
datFile.Items.RemoveTagsFromChild();
|
datFile.RemoveTagsFromChild();
|
||||||
datFile.ItemsDB.RemoveTagsFromChild();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -125,22 +121,17 @@ namespace SabreTools.DatTools
|
|||||||
_staticLogger.User("Creating fully merged sets from the DAT");
|
_staticLogger.User("Creating fully merged sets from the DAT");
|
||||||
|
|
||||||
// For sake of ease, the first thing we want to do is bucket by game
|
// For sake of ease, the first thing we want to do is bucket by game
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
|
||||||
|
|
||||||
// Now we want to loop through all of the games and set the correct information
|
// Now we want to loop through all of the games and set the correct information
|
||||||
datFile.Items.AddRomsFromChildren(true, false);
|
datFile.AddRomsFromChildren(true, false);
|
||||||
datFile.ItemsDB.AddRomsFromChildren(true, false);
|
|
||||||
|
|
||||||
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
||||||
datFile.Items.RemoveBiosRomsFromChild(false);
|
datFile.RemoveBiosRomsFromChild(false);
|
||||||
datFile.ItemsDB.RemoveBiosRomsFromChild(false);
|
datFile.RemoveBiosRomsFromChild(true);
|
||||||
datFile.Items.RemoveBiosRomsFromChild(true);
|
|
||||||
datFile.ItemsDB.RemoveBiosRomsFromChild(true);
|
|
||||||
|
|
||||||
// Finally, remove the romof and cloneof tags so it's not picked up by the manager
|
// Finally, remove the romof and cloneof tags so it's not picked up by the manager
|
||||||
datFile.Items.RemoveTagsFromChild();
|
datFile.RemoveTagsFromChild();
|
||||||
datFile.ItemsDB.RemoveTagsFromChild();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -152,24 +143,18 @@ namespace SabreTools.DatTools
|
|||||||
_staticLogger.User("Creating fully non-merged sets from the DAT");
|
_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
|
// For sake of ease, the first thing we want to do is bucket by game
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
|
||||||
|
|
||||||
// Now we want to loop through all of the games and set the correct information
|
// Now we want to loop through all of the games and set the correct information
|
||||||
while (datFile.Items.AddRomsFromDevices(true, true)) ;
|
while (datFile.AddRomsFromDevices(true, true)) ;
|
||||||
while (datFile.ItemsDB.AddRomsFromDevices(true, true)) ;
|
datFile.AddRomsFromDevices(false, true);
|
||||||
datFile.Items.AddRomsFromDevices(false, true);
|
datFile.AddRomsFromParent();
|
||||||
datFile.ItemsDB.AddRomsFromDevices(false, true);
|
|
||||||
datFile.Items.AddRomsFromParent();
|
|
||||||
datFile.ItemsDB.AddRomsFromParent();
|
|
||||||
|
|
||||||
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
||||||
datFile.Items.AddRomsFromBios();
|
datFile.AddRomsFromBios();
|
||||||
datFile.ItemsDB.AddRomsFromBios();
|
|
||||||
|
|
||||||
// Then, remove the romof and cloneof tags so it's not picked up by the manager
|
// Then, remove the romof and cloneof tags so it's not picked up by the manager
|
||||||
datFile.Items.RemoveTagsFromChild();
|
datFile.RemoveTagsFromChild();
|
||||||
datFile.ItemsDB.RemoveTagsFromChild();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -181,22 +166,17 @@ namespace SabreTools.DatTools
|
|||||||
_staticLogger.User("Creating merged sets from the DAT");
|
_staticLogger.User("Creating merged sets from the DAT");
|
||||||
|
|
||||||
// For sake of ease, the first thing we want to do is bucket by game
|
// For sake of ease, the first thing we want to do is bucket by game
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
|
||||||
|
|
||||||
// Now we want to loop through all of the games and set the correct information
|
// Now we want to loop through all of the games and set the correct information
|
||||||
datFile.Items.AddRomsFromChildren(true, true);
|
datFile.AddRomsFromChildren(true, true);
|
||||||
datFile.ItemsDB.AddRomsFromChildren(true, true);
|
|
||||||
|
|
||||||
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
||||||
datFile.Items.RemoveBiosRomsFromChild(false);
|
datFile.RemoveBiosRomsFromChild(false);
|
||||||
datFile.ItemsDB.RemoveBiosRomsFromChild(false);
|
datFile.RemoveBiosRomsFromChild(true);
|
||||||
datFile.Items.RemoveBiosRomsFromChild(true);
|
|
||||||
datFile.ItemsDB.RemoveBiosRomsFromChild(true);
|
|
||||||
|
|
||||||
// Finally, remove the romof and cloneof tags so it's not picked up by the manager
|
// Finally, remove the romof and cloneof tags so it's not picked up by the manager
|
||||||
datFile.Items.RemoveTagsFromChild();
|
datFile.RemoveTagsFromChild();
|
||||||
datFile.ItemsDB.RemoveTagsFromChild();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -208,22 +188,17 @@ namespace SabreTools.DatTools
|
|||||||
_staticLogger.User("Creating non-merged sets from the DAT");
|
_staticLogger.User("Creating non-merged sets from the DAT");
|
||||||
|
|
||||||
// For sake of ease, the first thing we want to do is bucket by game
|
// For sake of ease, the first thing we want to do is bucket by game
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
|
||||||
|
|
||||||
// Now we want to loop through all of the games and set the correct information
|
// Now we want to loop through all of the games and set the correct information
|
||||||
datFile.Items.AddRomsFromParent();
|
datFile.AddRomsFromParent();
|
||||||
datFile.ItemsDB.AddRomsFromParent();
|
|
||||||
|
|
||||||
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
||||||
datFile.Items.RemoveBiosRomsFromChild(false);
|
datFile.RemoveBiosRomsFromChild(false);
|
||||||
datFile.ItemsDB.RemoveBiosRomsFromChild(false);
|
datFile.RemoveBiosRomsFromChild(true);
|
||||||
datFile.Items.RemoveBiosRomsFromChild(true);
|
|
||||||
datFile.ItemsDB.RemoveBiosRomsFromChild(true);
|
|
||||||
|
|
||||||
// Finally, remove the romof and cloneof tags so it's not picked up by the manager
|
// Finally, remove the romof and cloneof tags so it's not picked up by the manager
|
||||||
datFile.Items.RemoveTagsFromChild();
|
datFile.RemoveTagsFromChild();
|
||||||
datFile.ItemsDB.RemoveTagsFromChild();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -235,22 +210,17 @@ namespace SabreTools.DatTools
|
|||||||
_staticLogger.User("Creating split sets from the DAT");
|
_staticLogger.User("Creating split sets from the DAT");
|
||||||
|
|
||||||
// For sake of ease, the first thing we want to do is bucket by game
|
// For sake of ease, the first thing we want to do is bucket by game
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
|
||||||
|
|
||||||
// Now we want to loop through all of the games and set the correct information
|
// Now we want to loop through all of the games and set the correct information
|
||||||
datFile.Items.RemoveRomsFromChild();
|
datFile.RemoveRomsFromChild();
|
||||||
datFile.ItemsDB.RemoveRomsFromChild();
|
|
||||||
|
|
||||||
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
||||||
datFile.Items.RemoveBiosRomsFromChild(false);
|
datFile.RemoveBiosRomsFromChild(false);
|
||||||
datFile.ItemsDB.RemoveBiosRomsFromChild(false);
|
datFile.RemoveBiosRomsFromChild(true);
|
||||||
datFile.Items.RemoveBiosRomsFromChild(true);
|
|
||||||
datFile.ItemsDB.RemoveBiosRomsFromChild(true);
|
|
||||||
|
|
||||||
// Finally, remove the romof and cloneof tags so it's not picked up by the manager
|
// Finally, remove the romof and cloneof tags so it's not picked up by the manager
|
||||||
datFile.Items.RemoveTagsFromChild();
|
datFile.RemoveTagsFromChild();
|
||||||
datFile.ItemsDB.RemoveTagsFromChild();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace SabreTools.DatTools
|
|||||||
#region Perform setup
|
#region Perform setup
|
||||||
|
|
||||||
// If the DAT is not populated and inverse is not set, inform the user and quit
|
// If the DAT is not populated and inverse is not set, inform the user and quit
|
||||||
if (datFile.Items.DatStatistics.TotalCount == 0 && !inverse)
|
if (datFile.DatStatistics.TotalCount == 0 && !inverse)
|
||||||
{
|
{
|
||||||
_staticLogger.User("No entries were found to rebuild, exiting...");
|
_staticLogger.User("No entries were found to rebuild, exiting...");
|
||||||
return false;
|
return false;
|
||||||
@@ -106,7 +106,7 @@ namespace SabreTools.DatTools
|
|||||||
return success;
|
return success;
|
||||||
|
|
||||||
// Now that we have a list of depots, we want to bucket the input DAT by SHA-1
|
// Now that we have a list of depots, we want to bucket the input DAT by SHA-1
|
||||||
datFile.Items.BucketBy(ItemKey.SHA1, DedupeType.None);
|
datFile.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||||
|
|
||||||
// Then we want to loop through each of the hashes and see if we can rebuild
|
// Then we want to loop through each of the hashes and see if we can rebuild
|
||||||
List<string> keys = [.. datFile.Items.SortedKeys];
|
List<string> keys = [.. datFile.Items.SortedKeys];
|
||||||
@@ -147,10 +147,10 @@ namespace SabreTools.DatTools
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Ensure we are sorted correctly (some other calls can change this)
|
// Ensure we are sorted correctly (some other calls can change this)
|
||||||
//datFile.Items.BucketBy(ItemKey.SHA1, DedupeType.None);
|
//datFile.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||||
|
|
||||||
// If there are no items in the hash, we continue
|
// If there are no items in the hash, we continue
|
||||||
var items = datFile.Items[hash];
|
var items = datFile.GetItemsForBucket(hash);
|
||||||
if (items == null || items.Count == 0)
|
if (items == null || items.Count == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ namespace SabreTools.DatTools
|
|||||||
#region Perform setup
|
#region Perform setup
|
||||||
|
|
||||||
// If the DAT is not populated and inverse is not set, inform the user and quit
|
// If the DAT is not populated and inverse is not set, inform the user and quit
|
||||||
if (datFile.Items.DatStatistics.TotalCount == 0 && !inverse)
|
if (datFile.DatStatistics.TotalCount == 0 && !inverse)
|
||||||
{
|
{
|
||||||
_staticLogger.User("No entries were found to rebuild, exiting...");
|
_staticLogger.User("No entries were found to rebuild, exiting...");
|
||||||
return false;
|
return false;
|
||||||
@@ -451,7 +451,7 @@ namespace SabreTools.DatTools
|
|||||||
if (outputFormat == OutputFormat.Folder && datFile.Header.GetStringFieldValue(Models.Metadata.Header.ForcePackingKey).AsEnumValue<PackingFlag>() == PackingFlag.Partial)
|
if (outputFormat == OutputFormat.Folder && datFile.Header.GetStringFieldValue(Models.Metadata.Header.ForcePackingKey).AsEnumValue<PackingFlag>() == PackingFlag.Partial)
|
||||||
{
|
{
|
||||||
shouldCheck = true;
|
shouldCheck = true;
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, lower: false);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None, lower: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now loop through the list and rebuild accordingly
|
// Now loop through the list and rebuild accordingly
|
||||||
@@ -463,7 +463,7 @@ namespace SabreTools.DatTools
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If we should check for the items in the machine
|
// If we should check for the items in the machine
|
||||||
var items = datFile.Items[machine.GetStringFieldValue(Models.Metadata.Machine.NameKey)!];
|
var items = datFile.GetItemsForBucket(machine.GetStringFieldValue(Models.Metadata.Machine.NameKey)!);
|
||||||
if (shouldCheck && items!.Count > 1)
|
if (shouldCheck && items!.Count > 1)
|
||||||
outputFormat = OutputFormat.Folder;
|
outputFormat = OutputFormat.Folder;
|
||||||
else if (shouldCheck && items!.Count == 1)
|
else if (shouldCheck && items!.Count == 1)
|
||||||
@@ -553,7 +553,7 @@ namespace SabreTools.DatTools
|
|||||||
private static bool ShouldRebuild(DatFile datFile, DatItem datItem, Stream? stream, bool inverse, out List<DatItem> dupes)
|
private static bool ShouldRebuild(DatFile datFile, DatItem datItem, Stream? stream, bool inverse, out List<DatItem> dupes)
|
||||||
{
|
{
|
||||||
// Find if the file has duplicates in the DAT
|
// Find if the file has duplicates in the DAT
|
||||||
dupes = datFile.Items.GetDuplicates(datItem);
|
dupes = datFile.GetDuplicates(datItem);
|
||||||
bool hasDuplicates = dupes.Count > 0;
|
bool hasDuplicates = dupes.Count > 0;
|
||||||
|
|
||||||
// If we have duplicates but we're filtering
|
// If we have duplicates but we're filtering
|
||||||
@@ -609,7 +609,7 @@ namespace SabreTools.DatTools
|
|||||||
private static bool ShouldRebuildDB(DatFile datFile, KeyValuePair<long, DatItem> datItem, Stream? stream, bool inverse, out Dictionary<long, DatItem> dupes)
|
private static bool ShouldRebuildDB(DatFile datFile, KeyValuePair<long, DatItem> datItem, Stream? stream, bool inverse, out Dictionary<long, DatItem> dupes)
|
||||||
{
|
{
|
||||||
// Find if the file has duplicates in the DAT
|
// Find if the file has duplicates in the DAT
|
||||||
dupes = datFile.ItemsDB.GetDuplicates(datItem);
|
dupes = datFile.GetDuplicatesDB(datItem);
|
||||||
bool hasDuplicates = dupes.Count > 0;
|
bool hasDuplicates = dupes.Count > 0;
|
||||||
|
|
||||||
// If we have duplicates but we're filtering
|
// If we have duplicates but we're filtering
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace SabreTools.DatTools
|
|||||||
public static (DatFile? extADat, DatFile? extBDat) SplitByExtension(DatFile datFile, List<string> extA, List<string> extB)
|
public static (DatFile? extADat, DatFile? extBDat) SplitByExtension(DatFile datFile, List<string> extA, List<string> extB)
|
||||||
{
|
{
|
||||||
// If roms is empty, return false
|
// If roms is empty, return false
|
||||||
if (datFile.Items.DatStatistics.TotalCount == 0)
|
if (datFile.DatStatistics.TotalCount == 0)
|
||||||
return (null, null);
|
return (null, null);
|
||||||
|
|
||||||
InternalStopwatch watch = new($"Splitting DAT by extension");
|
InternalStopwatch watch = new($"Splitting DAT by extension");
|
||||||
@@ -73,7 +73,7 @@ namespace SabreTools.DatTools
|
|||||||
foreach (var key in datFile.Items.Keys)
|
foreach (var key in datFile.Items.Keys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
var items = datFile.Items[key];
|
var items = datFile.GetItemsForBucket(key);
|
||||||
if (items == null)
|
if (items == null)
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
@@ -249,7 +249,7 @@ namespace SabreTools.DatTools
|
|||||||
foreach (var key in datFile.Items.Keys)
|
foreach (var key in datFile.Items.Keys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
var items = datFile.Items[key];
|
var items = datFile.GetItemsForBucket(key);
|
||||||
if (items == null)
|
if (items == null)
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
@@ -493,7 +493,7 @@ namespace SabreTools.DatTools
|
|||||||
InternalStopwatch watch = new($"Splitting DAT by level");
|
InternalStopwatch watch = new($"Splitting DAT by level");
|
||||||
|
|
||||||
// First, bucket by games so that we can do the right thing
|
// First, bucket by games so that we can do the right thing
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, lower: false, norename: true);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None, lower: false, norename: true);
|
||||||
|
|
||||||
// Create a temporary DAT to add things to
|
// Create a temporary DAT to add things to
|
||||||
DatFile tempDat = DatFileTool.CreateDatFile(datFile.Header);
|
DatFile tempDat = DatFileTool.CreateDatFile(datFile.Header);
|
||||||
@@ -521,7 +521,7 @@ namespace SabreTools.DatTools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clean the input list and set all games to be pathless
|
// Clean the input list and set all games to be pathless
|
||||||
List<DatItem>? items = datFile.Items[key];
|
List<DatItem>? items = datFile.GetItemsForBucket(key);
|
||||||
if (items == null)
|
if (items == null)
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
@@ -638,7 +638,7 @@ namespace SabreTools.DatTools
|
|||||||
foreach (var key in datFile.Items.Keys)
|
foreach (var key in datFile.Items.Keys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
List<DatItem>? items = datFile.Items[key];
|
List<DatItem>? items = datFile.GetItemsForBucket(key);
|
||||||
if (items == null)
|
if (items == null)
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
@@ -777,7 +777,7 @@ namespace SabreTools.DatTools
|
|||||||
InternalStopwatch watch = new($"Splitting DAT by total size");
|
InternalStopwatch watch = new($"Splitting DAT by total size");
|
||||||
|
|
||||||
// Sort the DatFile by machine name
|
// Sort the DatFile by machine name
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||||
|
|
||||||
// Get the keys in a known order for easier sorting
|
// Get the keys in a known order for easier sorting
|
||||||
var keys = datFile.Items.SortedKeys;
|
var keys = datFile.Items.SortedKeys;
|
||||||
@@ -920,7 +920,7 @@ namespace SabreTools.DatTools
|
|||||||
foreach (var key in datFile.Items.Keys)
|
foreach (var key in datFile.Items.Keys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
List<DatItem> items = DatFileTool.Merge(datFile.Items[key]);
|
List<DatItem> items = DatFileTool.Merge(datFile.GetItemsForBucket(key));
|
||||||
|
|
||||||
// If the rom list is empty or null, just skip it
|
// If the rom list is empty or null, just skip it
|
||||||
if (items == null || items.Count == 0)
|
if (items == null || items.Count == 0)
|
||||||
|
|||||||
@@ -81,21 +81,18 @@ namespace SabreTools.DatTools
|
|||||||
// Add single DAT stats (if asked)
|
// Add single DAT stats (if asked)
|
||||||
if (single)
|
if (single)
|
||||||
{
|
{
|
||||||
DatStatistics individualStats = datdata.Items.DatStatistics;
|
DatStatistics individualStats = datdata.DatStatistics;
|
||||||
//DatStatistics individualStats = datdata.ItemsDB.DatStatistics;
|
|
||||||
individualStats.DisplayName = datdata.Header.GetStringFieldValue(DatHeader.FileNameKey);
|
individualStats.DisplayName = datdata.Header.GetStringFieldValue(DatHeader.FileNameKey);
|
||||||
individualStats.MachineCount = datdata.Items.Keys.Count;
|
individualStats.MachineCount = datdata.Items.Keys.Count;
|
||||||
stats.Add(individualStats);
|
stats.Add(individualStats);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add single DAT stats to dir
|
// Add single DAT stats to dir
|
||||||
dirStats.AddStatistics(datdata.Items.DatStatistics);
|
dirStats.AddStatistics(datdata.DatStatistics);
|
||||||
//dirStats.AddStatistics(datdata.ItemsDB.DatStatistics);
|
|
||||||
dirStats.GameCount += datdata.Items.Keys.Count;
|
dirStats.GameCount += datdata.Items.Keys.Count;
|
||||||
|
|
||||||
// Add single DAT stats to totals
|
// Add single DAT stats to totals
|
||||||
totalStats.AddStatistics(datdata.Items.DatStatistics);
|
totalStats.AddStatistics(datdata.DatStatistics);
|
||||||
//totalStats.AddStatistics(datdata.ItemsDB.DatStatistics);
|
|
||||||
totalStats.GameCount += datdata.Items.Keys.Count;
|
totalStats.GameCount += datdata.Items.Keys.Count;
|
||||||
|
|
||||||
// Make sure to assign the new directory
|
// Make sure to assign the new directory
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace SabreTools.DatTools
|
|||||||
return success;
|
return success;
|
||||||
|
|
||||||
// Now that we have a list of depots, we want to bucket the input DAT by SHA-1
|
// Now that we have a list of depots, we want to bucket the input DAT by SHA-1
|
||||||
datFile.Items.BucketBy(ItemKey.SHA1, DedupeType.None);
|
datFile.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||||
|
|
||||||
// Then we want to loop through each of the hashes and see if we can rebuild
|
// Then we want to loop through each of the hashes and see if we can rebuild
|
||||||
List<string> keys = [.. datFile.Items.SortedKeys];
|
List<string> keys = [.. datFile.Items.SortedKeys];
|
||||||
@@ -96,8 +96,8 @@ namespace SabreTools.DatTools
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Now we want to remove all duplicates from the DAT
|
// Now we want to remove all duplicates from the DAT
|
||||||
datFile.Items.GetDuplicates(fileinfo.ConvertToRom())
|
datFile.GetDuplicates(fileinfo.ConvertToRom())
|
||||||
.AddRange(datFile.Items.GetDuplicates(fileinfo.ConvertToDisk()));
|
.AddRange(datFile.GetDuplicates(fileinfo.ConvertToDisk()));
|
||||||
}
|
}
|
||||||
|
|
||||||
watch.Stop();
|
watch.Stop();
|
||||||
@@ -140,7 +140,7 @@ namespace SabreTools.DatTools
|
|||||||
return success;
|
return success;
|
||||||
|
|
||||||
// Now that we have a list of depots, we want to bucket the input DAT by SHA-1
|
// Now that we have a list of depots, we want to bucket the input DAT by SHA-1
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.SHA1, DedupeType.None);
|
datFile.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||||
|
|
||||||
// Then we want to loop through each of the hashes and see if we can rebuild
|
// Then we want to loop through each of the hashes and see if we can rebuild
|
||||||
List<string> keys = [.. datFile.ItemsDB.SortedKeys];
|
List<string> keys = [.. datFile.ItemsDB.SortedKeys];
|
||||||
@@ -181,8 +181,8 @@ namespace SabreTools.DatTools
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Now we want to remove all duplicates from the DAT
|
// Now we want to remove all duplicates from the DAT
|
||||||
datFile.ItemsDB.GetDuplicates(new KeyValuePair<long, DatItem>(-1, fileinfo.ConvertToRom()))
|
datFile.GetDuplicatesDB(new KeyValuePair<long, DatItem>(-1, fileinfo.ConvertToRom()))
|
||||||
.Concat(datFile.ItemsDB.GetDuplicates(new KeyValuePair<long, DatItem>(-1, fileinfo.ConvertToDisk())));
|
.Concat(datFile.GetDuplicatesDB(new KeyValuePair<long, DatItem>(-1, fileinfo.ConvertToDisk())));
|
||||||
}
|
}
|
||||||
|
|
||||||
watch.Stop();
|
watch.Stop();
|
||||||
@@ -211,15 +211,15 @@ namespace SabreTools.DatTools
|
|||||||
// Force bucketing according to the flags
|
// Force bucketing according to the flags
|
||||||
datFile.Items.SetBucketedBy(ItemKey.NULL);
|
datFile.Items.SetBucketedBy(ItemKey.NULL);
|
||||||
if (hashOnly)
|
if (hashOnly)
|
||||||
datFile.Items.BucketBy(ItemKey.CRC, DedupeType.Full);
|
datFile.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||||
else
|
else
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.Full);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.Full);
|
||||||
|
|
||||||
// Then mark items for removal
|
// Then mark items for removal
|
||||||
List<string> keys = [.. datFile.Items.SortedKeys];
|
List<string> keys = [.. datFile.Items.SortedKeys];
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<DatItem>? items = datFile.Items[key];
|
List<DatItem>? items = datFile.GetItemsForBucket(key);
|
||||||
if (items == null)
|
if (items == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -259,9 +259,9 @@ namespace SabreTools.DatTools
|
|||||||
|
|
||||||
// Force bucketing according to the flags
|
// Force bucketing according to the flags
|
||||||
if (hashOnly)
|
if (hashOnly)
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.CRC, DedupeType.Full);
|
datFile.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||||
else
|
else
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.Full);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.Full);
|
||||||
|
|
||||||
// Then mark items for removal
|
// Then mark items for removal
|
||||||
List<string> keys = [.. datFile.ItemsDB.SortedKeys];
|
List<string> keys = [.. datFile.ItemsDB.SortedKeys];
|
||||||
|
|||||||
@@ -77,12 +77,10 @@ namespace SabreTools.DatTools
|
|||||||
EnsureHeaderFields(datFile);
|
EnsureHeaderFields(datFile);
|
||||||
|
|
||||||
// Bucket roms by game name, if not already
|
// Bucket roms by game name, if not already
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None);
|
|
||||||
|
|
||||||
// Output the number of items we're going to be writing
|
// Output the number of items we're going to be writing
|
||||||
_staticLogger.User($"A total of {datFile.Items.DatStatistics.TotalCount - datFile.Items.DatStatistics.RemovedCount} items will be written out to '{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}'");
|
_staticLogger.User($"A total of {datFile.DatStatistics.TotalCount - datFile.DatStatistics.RemovedCount} items will be written out to '{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}'");
|
||||||
//logger.User($"A total of {datFile.ItemsDB.DatStatistics.TotalCount - datFile.ItemsDB.DatStatistics.RemovedCount} items will be written out to '{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}'");
|
|
||||||
|
|
||||||
// Get the outfile names
|
// Get the outfile names
|
||||||
Dictionary<DatFormat, string> outfiles = datFile.Header.CreateOutFileNames(outDir!, overwrite);
|
Dictionary<DatFormat, string> outfiles = datFile.Header.CreateOutFileNames(outDir!, overwrite);
|
||||||
@@ -133,33 +131,21 @@ namespace SabreTools.DatTools
|
|||||||
/// <param name="datFile">Current DatFile object to write from</param>
|
/// <param name="datFile">Current DatFile object to write from</param>
|
||||||
public static void WriteStatsToConsole(DatFile datFile)
|
public static void WriteStatsToConsole(DatFile datFile)
|
||||||
{
|
{
|
||||||
long diskCount = datFile.Items.DatStatistics.GetItemCount(ItemType.Disk);
|
long diskCount = datFile.DatStatistics.GetItemCount(ItemType.Disk);
|
||||||
long mediaCount = datFile.Items.DatStatistics.GetItemCount(ItemType.Media);
|
long mediaCount = datFile.DatStatistics.GetItemCount(ItemType.Media);
|
||||||
long romCount = datFile.Items.DatStatistics.GetItemCount(ItemType.Rom);
|
long romCount = datFile.DatStatistics.GetItemCount(ItemType.Rom);
|
||||||
|
|
||||||
if (diskCount + mediaCount + romCount == 0)
|
if (diskCount + mediaCount + romCount == 0)
|
||||||
datFile.Items.RecalculateStats();
|
datFile.Items.RecalculateStats();
|
||||||
|
|
||||||
diskCount = datFile.ItemsDB.DatStatistics.GetItemCount(ItemType.Disk);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||||
mediaCount = datFile.ItemsDB.DatStatistics.GetItemCount(ItemType.Media);
|
|
||||||
romCount = datFile.ItemsDB.DatStatistics.GetItemCount(ItemType.Rom);
|
|
||||||
|
|
||||||
if (diskCount + mediaCount + romCount == 0)
|
datFile.DatStatistics.DisplayName = datFile.Header.GetStringFieldValue(DatHeader.FileNameKey);
|
||||||
datFile.ItemsDB.RecalculateStats();
|
datFile.DatStatistics.MachineCount = datFile.Items.Keys.Count;
|
||||||
|
|
||||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
|
||||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
|
||||||
|
|
||||||
datFile.Items.DatStatistics.DisplayName = datFile.Header.GetStringFieldValue(DatHeader.FileNameKey);
|
|
||||||
datFile.Items.DatStatistics.MachineCount = datFile.Items.Keys.Count;
|
|
||||||
|
|
||||||
datFile.ItemsDB.DatStatistics.DisplayName = datFile.Header.GetStringFieldValue(DatHeader.FileNameKey);
|
|
||||||
datFile.ItemsDB.DatStatistics.MachineCount = datFile.Items.Keys.Count;
|
|
||||||
|
|
||||||
List<DatStatistics> statsList =
|
List<DatStatistics> statsList =
|
||||||
[
|
[
|
||||||
datFile.Items.DatStatistics,
|
datFile.DatStatistics,
|
||||||
//datFile.ItemsDB.DatStatistics,
|
|
||||||
];
|
];
|
||||||
var consoleOutput = BaseReport.Create(StatReportFormat.None, statsList);
|
var consoleOutput = BaseReport.Create(StatReportFormat.None, statsList);
|
||||||
consoleOutput!.WriteToFile(null, true, true);
|
consoleOutput!.WriteToFile(null, true, true);
|
||||||
@@ -232,13 +218,13 @@ namespace SabreTools.DatTools
|
|||||||
datFile.ItemsDB.RecalculateStats();
|
datFile.ItemsDB.RecalculateStats();
|
||||||
|
|
||||||
// If there's nothing there, abort
|
// If there's nothing there, abort
|
||||||
if (datFile.Items.DatStatistics.TotalCount == 0)
|
if (datFile.DatStatistics.TotalCount == 0)
|
||||||
return false;
|
return false;
|
||||||
// if (datFile.ItemsDB.DatStatistics.TotalCount == 0)
|
// if (datFile.ItemsDB.DatStatistics.TotalCount == 0)
|
||||||
// return false;
|
// return false;
|
||||||
|
|
||||||
// If every item is removed, abort
|
// If every item is removed, abort
|
||||||
if (datFile.Items.DatStatistics.TotalCount == datFile.Items.DatStatistics.RemovedCount)
|
if (datFile.DatStatistics.TotalCount == datFile.DatStatistics.RemovedCount)
|
||||||
return false;
|
return false;
|
||||||
// if (datFile.ItemsDB.DatStatistics.TotalCount == datFile.ItemsDB.DatStatistics.RemovedCount)
|
// if (datFile.ItemsDB.DatStatistics.TotalCount == datFile.ItemsDB.DatStatistics.RemovedCount)
|
||||||
// return false;
|
// return false;
|
||||||
|
|||||||
@@ -236,8 +236,7 @@ Reset the internal state: reset();";
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Process(BatchState batchState)
|
public override void Process(BatchState batchState)
|
||||||
{
|
{
|
||||||
batchState.DatFile.Items.MachineDescriptionToName();
|
batchState.DatFile.MachineDescriptionToName();
|
||||||
batchState.DatFile.ItemsDB.MachineDescriptionToName();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,8 +607,7 @@ Reset the internal state: reset();";
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Process(BatchState batchState)
|
public override void Process(BatchState batchState)
|
||||||
{
|
{
|
||||||
batchState.DatFile.Items.SetOneGamePerRegion([.. Arguments]);
|
batchState.DatFile.SetOneGamePerRegion([.. Arguments]);
|
||||||
batchState.DatFile.ItemsDB.SetOneGamePerRegion([.. Arguments]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -642,8 +640,7 @@ Reset the internal state: reset();";
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Process(BatchState batchState)
|
public override void Process(BatchState batchState)
|
||||||
{
|
{
|
||||||
batchState.DatFile.Items.SetOneRomPerGame();
|
batchState.DatFile.SetOneRomPerGame();
|
||||||
batchState.DatFile.ItemsDB.SetOneRomPerGame();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -777,8 +774,7 @@ Reset the internal state: reset();";
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Process(BatchState batchState)
|
public override void Process(BatchState batchState)
|
||||||
{
|
{
|
||||||
batchState.DatFile.Items.StripSceneDatesFromItems();
|
batchState.DatFile.StripSceneDatesFromItems();
|
||||||
batchState.DatFile.ItemsDB.StripSceneDatesFromItems();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user