diff --git a/SabreTools.DatFiles/ItemDictionary.cs b/SabreTools.DatFiles/ItemDictionary.cs
index 07f72d7d..54994f95 100644
--- a/SabreTools.DatFiles/ItemDictionary.cs
+++ b/SabreTools.DatFiles/ItemDictionary.cs
@@ -4,6 +4,7 @@ using System.Collections.Concurrent;
#endif
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Xml.Serialization;
using Newtonsoft.Json;
@@ -98,202 +99,10 @@ namespace SabreTools.DatFiles
public long TotalCount { get; private set; } = 0;
///
- /// Number of Adjuster items
+ /// Number of items for each item type
///
[JsonIgnore, XmlIgnore]
- public long AdjusterCount { get; private set; } = 0;
-
- ///
- /// Number of Analog items
- ///
- [JsonIgnore, XmlIgnore]
- public long AnalogCount { get; private set; } = 0;
-
- ///
- /// Number of Archive items
- ///
- [JsonIgnore, XmlIgnore]
- public long ArchiveCount { get; private set; } = 0;
-
- ///
- /// Number of BiosSet items
- ///
- [JsonIgnore, XmlIgnore]
- public long BiosSetCount { get; private set; } = 0;
-
- ///
- /// Number of Chip items
- ///
- [JsonIgnore, XmlIgnore]
- public long ChipCount { get; private set; } = 0;
-
- ///
- /// Number of top-level Condition items
- ///
- [JsonIgnore, XmlIgnore]
- public long ConditionCount { get; private set; } = 0;
-
- ///
- /// Number of Configuration items
- ///
- [JsonIgnore, XmlIgnore]
- public long ConfigurationCount { get; private set; } = 0;
-
- ///
- /// Number of DataArea items
- ///
- [JsonIgnore, XmlIgnore]
- public long DataAreaCount { get; private set; } = 0;
-
- ///
- /// Number of Device items
- ///
- [JsonIgnore, XmlIgnore]
- public long DeviceCount { get; private set; } = 0;
-
- ///
- /// Number of Device Reference items
- ///
- [JsonIgnore, XmlIgnore]
- public long DeviceReferenceCount { get; private set; } = 0;
-
- ///
- /// Number of DIP Switch items
- ///
- [JsonIgnore, XmlIgnore]
- public long DipSwitchCount { get; private set; } = 0;
-
- ///
- /// Number of Disk items
- ///
- [JsonIgnore, XmlIgnore]
- public long DiskCount { get; private set; } = 0;
-
- ///
- /// Number of DiskArea items
- ///
- [JsonIgnore, XmlIgnore]
- public long DiskAreaCount { get; private set; } = 0;
-
- ///
- /// Number of Display items
- ///
- [JsonIgnore, XmlIgnore]
- public long DisplayCount { get; private set; } = 0;
-
- ///
- /// Number of Driver items
- ///
- [JsonIgnore, XmlIgnore]
- public long DriverCount { get; private set; } = 0;
-
- ///
- /// Number of Feature items
- ///
- [JsonIgnore, XmlIgnore]
- public long FeatureCount { get; private set; } = 0;
-
- ///
- /// Number of Info items
- ///
- [JsonIgnore, XmlIgnore]
- public long InfoCount { get; private set; } = 0;
-
- ///
- /// Number of Input items
- ///
- [JsonIgnore, XmlIgnore]
- public long InputCount { get; private set; } = 0;
-
- ///
- /// Number of Media items
- ///
- [JsonIgnore, XmlIgnore]
- public long MediaCount { get; private set; } = 0;
-
- ///
- /// Number of Part items
- ///
- [JsonIgnore, XmlIgnore]
- public long PartCount { get; private set; } = 0;
-
- ///
- /// Number of PartFeature items
- ///
- [JsonIgnore, XmlIgnore]
- public long PartFeatureCount { get; private set; } = 0;
-
- ///
- /// Number of Port items
- ///
- [JsonIgnore, XmlIgnore]
- public long PortCount { get; private set; } = 0;
-
- ///
- /// Number of RamOption items
- ///
- [JsonIgnore, XmlIgnore]
- public long RamOptionCount { get; private set; } = 0;
-
- ///
- /// Number of Release items
- ///
- [JsonIgnore, XmlIgnore]
- public long ReleaseCount { get; private set; } = 0;
-
- ///
- /// Number of ReleaseDetails items
- ///
- [JsonIgnore, XmlIgnore]
- public long ReleaseDetailsCount { get; private set; } = 0;
-
- ///
- /// Number of Rom items
- ///
- [JsonIgnore, XmlIgnore]
- public long RomCount { get; private set; } = 0;
-
- ///
- /// Number of Sample items
- ///
- [JsonIgnore, XmlIgnore]
- public long SampleCount { get; private set; } = 0;
-
- ///
- /// Number of Serials items
- ///
- [JsonIgnore, XmlIgnore]
- public long SerialsCount { get; private set; } = 0;
-
- ///
- /// Number of SharedFeature items
- ///
- [JsonIgnore, XmlIgnore]
- public long SharedFeatureCount { get; private set; } = 0;
-
- ///
- /// Number of Slot items
- ///
- [JsonIgnore, XmlIgnore]
- public long SlotCount { get; private set; } = 0;
-
- ///
- /// Number of SoftwareList items
- ///
- [JsonIgnore, XmlIgnore]
- public long SoftwareListCount { get; private set; } = 0;
-
- ///
- /// Number of Sound items
- ///
- [JsonIgnore, XmlIgnore]
- public long SoundCount { get; private set; } = 0;
-
- ///
- /// Number of SourceDetails items
- ///
- [JsonIgnore, XmlIgnore]
- public long SourceDetailsCount { get; private set; } = 0;
+ public Dictionary ItemCounts { get; private set; } = [];
///
/// Number of machines
@@ -464,44 +273,13 @@ namespace SabreTools.DatFiles
if (item.Remove)
RemovedCount++;
- // Now we do different things for each item type
+ // Increment the item count for the type
+ AddItemCount(item.ItemType);
+
+ // Some item types require special processing
switch (item)
{
- case Adjuster:
- AdjusterCount++;
- break;
- case Analog:
- AnalogCount++;
- break;
- case Archive:
- ArchiveCount++;
- break;
- case BiosSet:
- BiosSetCount++;
- break;
- case Chip:
- ChipCount++;
- break;
- case Condition:
- ConditionCount++;
- break;
- case Configuration:
- ConfigurationCount++;
- break;
- case DataArea:
- DataAreaCount++;
- break;
- case Device:
- DeviceCount++;
- break;
- case DeviceReference:
- DeviceReferenceCount++;
- break;
- case DipSwitch:
- DipSwitchCount++;
- break;
case Disk disk:
- DiskCount++;
if (disk.ItemStatus != ItemStatus.Nodump)
{
MD5Count += (string.IsNullOrEmpty(disk.MD5) ? 0 : 1);
@@ -513,51 +291,13 @@ namespace SabreTools.DatFiles
NodumpCount += (disk.ItemStatus == ItemStatus.Nodump ? 1 : 0);
VerifiedCount += (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
break;
- case DiskArea:
- DiskAreaCount++;
- break;
- case Display:
- DisplayCount++;
- break;
- case Driver:
- DriverCount++;
- break;
- case Feature:
- FeatureCount++;
- break;
- case Info:
- InfoCount++;
- break;
- case Input:
- InputCount++;
- break;
case Media media:
- MediaCount++;
MD5Count += (string.IsNullOrEmpty(media.MD5) ? 0 : 1);
SHA1Count += (string.IsNullOrEmpty(media.SHA1) ? 0 : 1);
SHA256Count += (string.IsNullOrEmpty(media.SHA256) ? 0 : 1);
SpamSumCount += (string.IsNullOrEmpty(media.SpamSum) ? 0 : 1);
break;
- case Part:
- PartCount++;
- break;
- case PartFeature:
- PartFeatureCount++;
- break;
- case Port:
- PortCount++;
- break;
- case RamOption:
- RamOptionCount++;
- break;
- case Release:
- ReleaseCount++;
- break;
- case ReleaseDetails:
- ReleaseDetailsCount++;
- break;
case Rom rom:
- RomCount++;
if (rom.ItemStatus != ItemStatus.Nodump)
{
TotalSize += rom.Size ?? 0;
@@ -575,27 +315,6 @@ namespace SabreTools.DatFiles
NodumpCount += (rom.ItemStatus == ItemStatus.Nodump ? 1 : 0);
VerifiedCount += (rom.ItemStatus == ItemStatus.Verified ? 1 : 0);
break;
- case Sample:
- SampleCount++;
- break;
- case Serials:
- SerialsCount++;
- break;
- case SharedFeature:
- SharedFeatureCount++;
- break;
- case Slot:
- SlotCount++;
- break;
- case SoftwareList:
- SoftwareListCount++;
- break;
- case Sound:
- SoundCount++;
- break;
- case SourceDetails:
- SourceDetailsCount++;
- break;
}
}
}
@@ -636,14 +355,11 @@ namespace SabreTools.DatFiles
{
TotalCount += stats.Count;
- ArchiveCount += stats.ArchiveCount;
- BiosSetCount += stats.BiosSetCount;
- ChipCount += stats.ChipCount;
- DiskCount += stats.DiskCount;
- MediaCount += stats.MediaCount;
- ReleaseCount += stats.ReleaseCount;
- RomCount += stats.RomCount;
- SampleCount += stats.SampleCount;
+ // Loop through and add stats for all items
+ foreach (var itemCountKvp in stats.ItemCounts)
+ {
+ AddItemCount(itemCountKvp.Key, itemCountKvp.Value);
+ }
GameCount += stats.GameCount;
@@ -840,44 +556,13 @@ namespace SabreTools.DatFiles
if (item.Remove)
RemovedCount--;
- // Now we do different things for each item type
+ // Decrement the item count for the type
+ RemoveItemCount(item.ItemType);
+
+ // Some item types require special processing
switch (item)
{
- case Adjuster:
- AdjusterCount--;
- break;
- case Analog:
- AnalogCount--;
- break;
- case Archive:
- ArchiveCount--;
- break;
- case BiosSet:
- BiosSetCount--;
- break;
- case Chip:
- ChipCount--;
- break;
- case Condition:
- ConditionCount--;
- break;
- case Configuration:
- ConfigurationCount--;
- break;
- case DataArea:
- DataAreaCount--;
- break;
- case Device:
- DeviceCount--;
- break;
- case DeviceReference:
- DeviceReferenceCount--;
- break;
- case DipSwitch:
- DipSwitchCount--;
- break;
case Disk disk:
- DiskCount--;
if (disk.ItemStatus != ItemStatus.Nodump)
{
MD5Count -= (string.IsNullOrEmpty(disk.MD5) ? 0 : 1);
@@ -889,47 +574,12 @@ namespace SabreTools.DatFiles
NodumpCount -= (disk.ItemStatus == ItemStatus.Nodump ? 1 : 0);
VerifiedCount -= (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
break;
- case DiskArea:
- DiskAreaCount--;
- break;
- case Display:
- DisplayCount--;
- break;
- case Driver:
- DriverCount--;
- break;
- case Feature:
- FeatureCount--;
- break;
- case Info:
- InfoCount--;
- break;
- case Input:
- InputCount--;
- break;
case Media media:
- MediaCount--;
MD5Count -= (string.IsNullOrEmpty(media.MD5) ? 0 : 1);
SHA1Count -= (string.IsNullOrEmpty(media.SHA1) ? 0 : 1);
SHA256Count -= (string.IsNullOrEmpty(media.SHA256) ? 0 : 1);
break;
- case Part:
- PartCount--;
- break;
- case PartFeature:
- PartFeatureCount--;
- break;
- case Port:
- PortCount--;
- break;
- case RamOption:
- RamOptionCount--;
- break;
- case Release:
- ReleaseCount--;
- break;
case Rom rom:
- RomCount--;
if (rom.ItemStatus != ItemStatus.Nodump)
{
TotalSize -= rom.Size ?? 0;
@@ -946,25 +596,62 @@ namespace SabreTools.DatFiles
NodumpCount -= (rom.ItemStatus == ItemStatus.Nodump ? 1 : 0);
VerifiedCount -= (rom.ItemStatus == ItemStatus.Verified ? 1 : 0);
break;
- case Sample:
- SampleCount--;
- break;
- case SharedFeature:
- SharedFeatureCount--;
- break;
- case Slot:
- SlotCount--;
- break;
- case SoftwareList:
- SoftwareListCount--;
- break;
- case Sound:
- SoundCount--;
- break;
}
}
}
+ ///
+ /// Get the item count for a given item type, defaulting to 0 if it does not exist
+ ///
+ /// Item type to retrieve
+ /// The number of items of that type, if it exists
+ public long GetItemCount(ItemType itemType)
+ {
+ lock (ItemCounts)
+ {
+ if (!ItemCounts.ContainsKey(itemType))
+ return 0;
+
+ return ItemCounts[itemType];
+ }
+ }
+
+ ///
+ /// Increment the item count for a given item type
+ ///
+ /// Item type to increment
+ /// Amount to increment by, defaults to 1
+ private void AddItemCount(ItemType itemType, long interval = 1)
+ {
+ lock (ItemCounts)
+ {
+ if (!ItemCounts.ContainsKey(itemType))
+ ItemCounts[itemType] = 0;
+
+ ItemCounts[itemType] += interval;
+ if (ItemCounts[itemType] < 0)
+ ItemCounts[itemType] = 0;
+ }
+ }
+
+ ///
+ /// Decrement the item count for a given item type
+ ///
+ /// Item type to decrement
+ /// Amount to increment by, defaults to 1
+ private void RemoveItemCount(ItemType itemType, long interval = 1)
+ {
+ lock (ItemCounts)
+ {
+ if (!ItemCounts.ContainsKey(itemType))
+ return;
+
+ ItemCounts[itemType] -= interval;
+ if (ItemCounts[itemType] < 0)
+ ItemCounts[itemType] = 0;
+ }
+ }
+
#endregion
#region Constructors
@@ -1279,14 +966,7 @@ namespace SabreTools.DatFiles
{
TotalCount = 0;
- ArchiveCount = 0;
- BiosSetCount = 0;
- ChipCount = 0;
- DiskCount = 0;
- MediaCount = 0;
- ReleaseCount = 0;
- RomCount = 0;
- SampleCount = 0;
+ ItemCounts = [];
GameCount = 0;
@@ -1312,24 +992,29 @@ namespace SabreTools.DatFiles
///
private ItemKey GetBestAvailable()
{
+ // Get the item counts for the 3 hashable types
+ long diskCount = GetItemCount(ItemType.Disk);
+ long mediaCount = GetItemCount(ItemType.Media);
+ long romCount = GetItemCount(ItemType.Rom);
+
// If all items are supposed to have a SHA-512, we bucket by that
- if (DiskCount + MediaCount + RomCount - NodumpCount == SHA512Count)
+ if (diskCount + mediaCount + romCount - NodumpCount == SHA512Count)
return ItemKey.SHA512;
// If all items are supposed to have a SHA-384, we bucket by that
- else if (DiskCount + MediaCount + RomCount - NodumpCount == SHA384Count)
+ else if (diskCount + mediaCount + romCount - NodumpCount == SHA384Count)
return ItemKey.SHA384;
// If all items are supposed to have a SHA-256, we bucket by that
- else if (DiskCount + MediaCount + RomCount - NodumpCount == SHA256Count)
+ else if (diskCount + mediaCount + romCount - NodumpCount == SHA256Count)
return ItemKey.SHA256;
// If all items are supposed to have a SHA-1, we bucket by that
- else if (DiskCount + MediaCount + RomCount - NodumpCount == SHA1Count)
+ else if (diskCount + mediaCount + romCount - NodumpCount == SHA1Count)
return ItemKey.SHA1;
// If all items are supposed to have a MD5, we bucket by that
- else if (DiskCount + MediaCount + RomCount - NodumpCount == MD5Count)
+ else if (diskCount + mediaCount + romCount - NodumpCount == MD5Count)
return ItemKey.MD5;
// Otherwise, we bucket by CRC
diff --git a/SabreTools.DatFiles/ItemDictionaryDB.cs b/SabreTools.DatFiles/ItemDictionaryDB.cs
index 59365f20..122c9dbb 100644
--- a/SabreTools.DatFiles/ItemDictionaryDB.cs
+++ b/SabreTools.DatFiles/ItemDictionaryDB.cs
@@ -157,202 +157,10 @@ namespace SabreTools.DatFiles
public long TotalCount { get; private set; } = 0;
///
- /// Number of Adjuster items
+ /// Number of items for each item type
///
[JsonIgnore, XmlIgnore]
- public long AdjusterCount { get; private set; } = 0;
-
- ///
- /// Number of Analog items
- ///
- [JsonIgnore, XmlIgnore]
- public long AnalogCount { get; private set; } = 0;
-
- ///
- /// Number of Archive items
- ///
- [JsonIgnore, XmlIgnore]
- public long ArchiveCount { get; private set; } = 0;
-
- ///
- /// Number of BiosSet items
- ///
- [JsonIgnore, XmlIgnore]
- public long BiosSetCount { get; private set; } = 0;
-
- ///
- /// Number of Chip items
- ///
- [JsonIgnore, XmlIgnore]
- public long ChipCount { get; private set; } = 0;
-
- ///
- /// Number of top-level Condition items
- ///
- [JsonIgnore, XmlIgnore]
- public long ConditionCount { get; private set; } = 0;
-
- ///
- /// Number of Configuration items
- ///
- [JsonIgnore, XmlIgnore]
- public long ConfigurationCount { get; private set; } = 0;
-
- ///
- /// Number of DataArea items
- ///
- [JsonIgnore, XmlIgnore]
- public long DataAreaCount { get; private set; } = 0;
-
- ///
- /// Number of Device items
- ///
- [JsonIgnore, XmlIgnore]
- public long DeviceCount { get; private set; } = 0;
-
- ///
- /// Number of Device Reference items
- ///
- [JsonIgnore, XmlIgnore]
- public long DeviceReferenceCount { get; private set; } = 0;
-
- ///
- /// Number of DIP Switch items
- ///
- [JsonIgnore, XmlIgnore]
- public long DipSwitchCount { get; private set; } = 0;
-
- ///
- /// Number of Disk items
- ///
- [JsonIgnore, XmlIgnore]
- public long DiskCount { get; private set; } = 0;
-
- ///
- /// Number of DiskArea items
- ///
- [JsonIgnore, XmlIgnore]
- public long DiskAreaCount { get; private set; } = 0;
-
- ///
- /// Number of Display items
- ///
- [JsonIgnore, XmlIgnore]
- public long DisplayCount { get; private set; } = 0;
-
- ///
- /// Number of Driver items
- ///
- [JsonIgnore, XmlIgnore]
- public long DriverCount { get; private set; } = 0;
-
- ///
- /// Number of Feature items
- ///
- [JsonIgnore, XmlIgnore]
- public long FeatureCount { get; private set; } = 0;
-
- ///
- /// Number of Info items
- ///
- [JsonIgnore, XmlIgnore]
- public long InfoCount { get; private set; } = 0;
-
- ///
- /// Number of Input items
- ///
- [JsonIgnore, XmlIgnore]
- public long InputCount { get; private set; } = 0;
-
- ///
- /// Number of Media items
- ///
- [JsonIgnore, XmlIgnore]
- public long MediaCount { get; private set; } = 0;
-
- ///
- /// Number of Part items
- ///
- [JsonIgnore, XmlIgnore]
- public long PartCount { get; private set; } = 0;
-
- ///
- /// Number of PartFeature items
- ///
- [JsonIgnore, XmlIgnore]
- public long PartFeatureCount { get; private set; } = 0;
-
- ///
- /// Number of Port items
- ///
- [JsonIgnore, XmlIgnore]
- public long PortCount { get; private set; } = 0;
-
- ///
- /// Number of RamOption items
- ///
- [JsonIgnore, XmlIgnore]
- public long RamOptionCount { get; private set; } = 0;
-
- ///
- /// Number of Release items
- ///
- [JsonIgnore, XmlIgnore]
- public long ReleaseCount { get; private set; } = 0;
-
- ///
- /// Number of ReleaseDetails items
- ///
- [JsonIgnore, XmlIgnore]
- public long ReleaseDetailsCount { get; private set; } = 0;
-
- ///
- /// Number of Rom items
- ///
- [JsonIgnore, XmlIgnore]
- public long RomCount { get; private set; } = 0;
-
- ///
- /// Number of Sample items
- ///
- [JsonIgnore, XmlIgnore]
- public long SampleCount { get; private set; } = 0;
-
- ///
- /// Number of Serials items
- ///
- [JsonIgnore, XmlIgnore]
- public long SerialsCount { get; private set; } = 0;
-
- ///
- /// Number of SharedFeature items
- ///
- [JsonIgnore, XmlIgnore]
- public long SharedFeatureCount { get; private set; } = 0;
-
- ///
- /// Number of Slot items
- ///
- [JsonIgnore, XmlIgnore]
- public long SlotCount { get; private set; } = 0;
-
- ///
- /// Number of SoftwareList items
- ///
- [JsonIgnore, XmlIgnore]
- public long SoftwareListCount { get; private set; } = 0;
-
- ///
- /// Number of Sound items
- ///
- [JsonIgnore, XmlIgnore]
- public long SoundCount { get; private set; } = 0;
-
- ///
- /// Number of SourceDetails items
- ///
- [JsonIgnore, XmlIgnore]
- public long SourceDetailsCount { get; private set; } = 0;
+ public Dictionary ItemCounts { get; private set; } = [];
///
/// Number of machines
@@ -584,44 +392,13 @@ namespace SabreTools.DatFiles
if (item.Remove)
RemovedCount++;
- // Now we do different things for each item type
+ // Increment the item count for the type
+ AddItemCount(item.ItemType);
+
+ // Some item types require special processing
switch (item)
{
- case Adjuster:
- AdjusterCount++;
- break;
- case Analog:
- AnalogCount++;
- break;
- case Archive:
- ArchiveCount++;
- break;
- case BiosSet:
- BiosSetCount++;
- break;
- case Chip:
- ChipCount++;
- break;
- case Condition:
- ConditionCount++;
- break;
- case Configuration:
- ConfigurationCount++;
- break;
- case DataArea:
- DataAreaCount++;
- break;
- case Device:
- DeviceCount++;
- break;
- case DeviceReference:
- DeviceReferenceCount++;
- break;
- case DipSwitch:
- DipSwitchCount++;
- break;
case Disk disk:
- DiskCount++;
if (disk.ItemStatus != ItemStatus.Nodump)
{
MD5Count += (string.IsNullOrEmpty(disk.MD5) ? 0 : 1);
@@ -633,51 +410,13 @@ namespace SabreTools.DatFiles
NodumpCount += (disk.ItemStatus == ItemStatus.Nodump ? 1 : 0);
VerifiedCount += (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
break;
- case DiskArea:
- DiskAreaCount++;
- break;
- case Display:
- DisplayCount++;
- break;
- case Driver:
- DriverCount++;
- break;
- case Feature:
- FeatureCount++;
- break;
- case Info:
- InfoCount++;
- break;
- case Input:
- InputCount++;
- break;
case Media media:
- MediaCount++;
MD5Count += (string.IsNullOrEmpty(media.MD5) ? 0 : 1);
SHA1Count += (string.IsNullOrEmpty(media.SHA1) ? 0 : 1);
SHA256Count += (string.IsNullOrEmpty(media.SHA256) ? 0 : 1);
SpamSumCount += (string.IsNullOrEmpty(media.SpamSum) ? 0 : 1);
break;
- case Part:
- PartCount++;
- break;
- case PartFeature:
- PartFeatureCount++;
- break;
- case Port:
- PortCount++;
- break;
- case RamOption:
- RamOptionCount++;
- break;
- case Release:
- ReleaseCount++;
- break;
- case ReleaseDetails:
- ReleaseDetailsCount++;
- break;
case Rom rom:
- RomCount++;
if (rom.ItemStatus != ItemStatus.Nodump)
{
TotalSize += rom.Size ?? 0;
@@ -695,27 +434,6 @@ namespace SabreTools.DatFiles
NodumpCount += (rom.ItemStatus == ItemStatus.Nodump ? 1 : 0);
VerifiedCount += (rom.ItemStatus == ItemStatus.Verified ? 1 : 0);
break;
- case Sample:
- SampleCount++;
- break;
- case Serials:
- SerialsCount++;
- break;
- case SharedFeature:
- SharedFeatureCount++;
- break;
- case Slot:
- SlotCount++;
- break;
- case SoftwareList:
- SoftwareListCount++;
- break;
- case Sound:
- SoundCount++;
- break;
- case SourceDetails:
- SourceDetailsCount++;
- break;
}
}
}
@@ -755,18 +473,15 @@ namespace SabreTools.DatFiles
/// Add statistics from another DatStats object
///
/// DatStats object to add from
- public void AddStatistics(ItemDictionary stats)
+ public void AddStatistics(ItemDictionaryDB stats)
{
TotalCount += stats.Count;
- ArchiveCount += stats.ArchiveCount;
- BiosSetCount += stats.BiosSetCount;
- ChipCount += stats.ChipCount;
- DiskCount += stats.DiskCount;
- MediaCount += stats.MediaCount;
- ReleaseCount += stats.ReleaseCount;
- RomCount += stats.RomCount;
- SampleCount += stats.SampleCount;
+ // Loop through and add stats for all items
+ foreach (var itemCountKvp in stats.ItemCounts)
+ {
+ AddItemCount(itemCountKvp.Key, itemCountKvp.Value);
+ }
GameCount += stats.GameCount;
@@ -987,44 +702,13 @@ namespace SabreTools.DatFiles
if (item.Remove)
RemovedCount--;
- // Now we do different things for each item type
+ // Decrement the item count for the type
+ RemoveItemCount(item.ItemType);
+
+ // Some item types require special processing
switch (item)
{
- case Adjuster:
- AdjusterCount--;
- break;
- case Analog:
- AnalogCount--;
- break;
- case Archive:
- ArchiveCount--;
- break;
- case BiosSet:
- BiosSetCount--;
- break;
- case Chip:
- ChipCount--;
- break;
- case Condition:
- ConditionCount--;
- break;
- case Configuration:
- ConfigurationCount--;
- break;
- case DataArea:
- DataAreaCount--;
- break;
- case Device:
- DeviceCount--;
- break;
- case DeviceReference:
- DeviceReferenceCount--;
- break;
- case DipSwitch:
- DipSwitchCount--;
- break;
case Disk disk:
- DiskCount--;
if (disk.ItemStatus != ItemStatus.Nodump)
{
MD5Count -= (string.IsNullOrEmpty(disk.MD5) ? 0 : 1);
@@ -1036,47 +720,12 @@ namespace SabreTools.DatFiles
NodumpCount -= (disk.ItemStatus == ItemStatus.Nodump ? 1 : 0);
VerifiedCount -= (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
break;
- case DiskArea:
- DiskAreaCount--;
- break;
- case Display:
- DisplayCount--;
- break;
- case Driver:
- DriverCount--;
- break;
- case Feature:
- FeatureCount--;
- break;
- case Info:
- InfoCount--;
- break;
- case Input:
- InputCount--;
- break;
case Media media:
- MediaCount--;
MD5Count -= (string.IsNullOrEmpty(media.MD5) ? 0 : 1);
SHA1Count -= (string.IsNullOrEmpty(media.SHA1) ? 0 : 1);
SHA256Count -= (string.IsNullOrEmpty(media.SHA256) ? 0 : 1);
break;
- case Part:
- PartCount--;
- break;
- case PartFeature:
- PartFeatureCount--;
- break;
- case Port:
- PortCount--;
- break;
- case RamOption:
- RamOptionCount--;
- break;
- case Release:
- ReleaseCount--;
- break;
case Rom rom:
- RomCount--;
if (rom.ItemStatus != ItemStatus.Nodump)
{
TotalSize -= rom.Size ?? 0;
@@ -1093,25 +742,62 @@ namespace SabreTools.DatFiles
NodumpCount -= (rom.ItemStatus == ItemStatus.Nodump ? 1 : 0);
VerifiedCount -= (rom.ItemStatus == ItemStatus.Verified ? 1 : 0);
break;
- case Sample:
- SampleCount--;
- break;
- case SharedFeature:
- SharedFeatureCount--;
- break;
- case Slot:
- SlotCount--;
- break;
- case SoftwareList:
- SoftwareListCount--;
- break;
- case Sound:
- SoundCount--;
- break;
}
}
}
+ ///
+ /// Get the item count for a given item type, defaulting to 0 if it does not exist
+ ///
+ /// Item type to retrieve
+ /// The number of items of that type, if it exists
+ public long GetItemCount(ItemType itemType)
+ {
+ lock (ItemCounts)
+ {
+ if (!ItemCounts.ContainsKey(itemType))
+ return 0;
+
+ return ItemCounts[itemType];
+ }
+ }
+
+ ///
+ /// Increment the item count for a given item type
+ ///
+ /// Item type to increment
+ /// Amount to increment by, defaults to 1
+ private void AddItemCount(ItemType itemType, long interval = 1)
+ {
+ lock (ItemCounts)
+ {
+ if (!ItemCounts.ContainsKey(itemType))
+ ItemCounts[itemType] = 0;
+
+ ItemCounts[itemType] += interval;
+ if (ItemCounts[itemType] < 0)
+ ItemCounts[itemType] = 0;
+ }
+ }
+
+ ///
+ /// Decrement the item count for a given item type
+ ///
+ /// Item type to decrement
+ /// Amount to increment by, defaults to 1
+ private void RemoveItemCount(ItemType itemType, long interval = 1)
+ {
+ lock (ItemCounts)
+ {
+ if (!ItemCounts.ContainsKey(itemType))
+ return;
+
+ ItemCounts[itemType] -= interval;
+ if (ItemCounts[itemType] < 0)
+ ItemCounts[itemType] = 0;
+ }
+ }
+
#endregion
#region Constructors
@@ -1451,14 +1137,7 @@ CREATE TABLE IF NOT EXISTS groups (
{
TotalCount = 0;
- ArchiveCount = 0;
- BiosSetCount = 0;
- ChipCount = 0;
- DiskCount = 0;
- MediaCount = 0;
- ReleaseCount = 0;
- RomCount = 0;
- SampleCount = 0;
+ ItemCounts = [];
GameCount = 0;
@@ -1484,24 +1163,29 @@ CREATE TABLE IF NOT EXISTS groups (
///
private ItemKey GetBestAvailable()
{
+ // Get the item counts for the 3 hashable types
+ long diskCount = GetItemCount(ItemType.Disk);
+ long mediaCount = GetItemCount(ItemType.Media);
+ long romCount = GetItemCount(ItemType.Rom);
+
// If all items are supposed to have a SHA-512, we bucket by that
- if (DiskCount + MediaCount + RomCount - NodumpCount == SHA512Count)
+ if (diskCount + mediaCount + romCount - NodumpCount == SHA512Count)
return ItemKey.SHA512;
// If all items are supposed to have a SHA-384, we bucket by that
- else if (DiskCount + MediaCount + RomCount - NodumpCount == SHA384Count)
+ else if (diskCount + mediaCount + romCount - NodumpCount == SHA384Count)
return ItemKey.SHA384;
// If all items are supposed to have a SHA-256, we bucket by that
- else if (DiskCount + MediaCount + RomCount - NodumpCount == SHA256Count)
+ else if (diskCount + mediaCount + romCount - NodumpCount == SHA256Count)
return ItemKey.SHA256;
// If all items are supposed to have a SHA-1, we bucket by that
- else if (DiskCount + MediaCount + RomCount - NodumpCount == SHA1Count)
+ else if (diskCount + mediaCount + romCount - NodumpCount == SHA1Count)
return ItemKey.SHA1;
// If all items are supposed to have a MD5, we bucket by that
- else if (DiskCount + MediaCount + RomCount - NodumpCount == MD5Count)
+ else if (diskCount + mediaCount + romCount - NodumpCount == MD5Count)
return ItemKey.MD5;
// Otherwise, we bucket by CRC
diff --git a/SabreTools.DatTools/Writer.cs b/SabreTools.DatTools/Writer.cs
index 7042d983..321c2b00 100644
--- a/SabreTools.DatTools/Writer.cs
+++ b/SabreTools.DatTools/Writer.cs
@@ -120,7 +120,11 @@ namespace SabreTools.DatTools
/// Current DatFile object to write from
public static void WriteStatsToConsole(DatFile datFile)
{
- if (datFile.Items.RomCount + datFile.Items.DiskCount == 0)
+ long diskCount = datFile.Items.GetItemCount(ItemType.Disk);
+ long mediaCount = datFile.Items.GetItemCount(ItemType.Media);
+ long romCount = datFile.Items.GetItemCount(ItemType.Rom);
+
+ if (diskCount + mediaCount + romCount == 0)
datFile.Items.RecalculateStats();
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
diff --git a/SabreTools.Reports/Formats/Html.cs b/SabreTools.Reports/Formats/Html.cs
index cb7d6594..8b0c1bcd 100644
--- a/SabreTools.Reports/Formats/Html.cs
+++ b/SabreTools.Reports/Formats/Html.cs
@@ -237,12 +237,12 @@ body {
xtw.WriteStartElement("td");
xtw.WriteAttributeString("align", "right");
- xtw.WriteString(stat.Statistics.RomCount.ToString());
+ xtw.WriteString(stat.Statistics.GetItemCount(Core.ItemType.Rom).ToString());
xtw.WriteEndElement(); // td
xtw.WriteStartElement("td");
xtw.WriteAttributeString("align", "right");
- xtw.WriteString(stat.Statistics.DiskCount.ToString());
+ xtw.WriteString(stat.Statistics.GetItemCount(Core.ItemType.Disk).ToString());
xtw.WriteEndElement(); // td
xtw.WriteStartElement("td");
diff --git a/SabreTools.Reports/Formats/SeparatedValue.cs b/SabreTools.Reports/Formats/SeparatedValue.cs
index a9460741..5f58db2f 100644
--- a/SabreTools.Reports/Formats/SeparatedValue.cs
+++ b/SabreTools.Reports/Formats/SeparatedValue.cs
@@ -131,8 +131,8 @@ namespace SabreTools.Reports.Formats
stat.DisplayName!,
stat.Statistics!.TotalSize.ToString(),
stat.MachineCount.ToString(),
- stat.Statistics.RomCount.ToString(),
- stat.Statistics.DiskCount.ToString(),
+ stat.Statistics.GetItemCount(Core.ItemType.Rom).ToString(),
+ stat.Statistics.GetItemCount(Core.ItemType.Disk).ToString(),
stat.Statistics.CRCCount.ToString(),
stat.Statistics.MD5Count.ToString(),
stat.Statistics.SHA1Count.ToString(),
diff --git a/SabreTools.Reports/Formats/Textfile.cs b/SabreTools.Reports/Formats/Textfile.cs
index b5d1105e..32e5a447 100644
--- a/SabreTools.Reports/Formats/Textfile.cs
+++ b/SabreTools.Reports/Formats/Textfile.cs
@@ -93,8 +93,8 @@ namespace SabreTools.Reports.Formats
--------------------------------------------------
Uncompressed size: " + GetBytesReadable(stat.Statistics!.TotalSize) + @"
Games found: " + stat.MachineCount + @"
- Roms found: " + stat.Statistics.RomCount + @"
- Disks found: " + stat.Statistics.DiskCount + @"
+ Roms found: " + stat.Statistics.GetItemCount(Core.ItemType.Rom) + @"
+ Disks found: " + stat.Statistics.GetItemCount(Core.ItemType.Disk) + @"
Roms with CRC: " + stat.Statistics.CRCCount + @"
Roms with MD5: " + stat.Statistics.MD5Count + @"
Roms with SHA-1: " + stat.Statistics.SHA1Count + @"