mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Simplify hash count statistics
This commit is contained in:
@@ -118,46 +118,10 @@ namespace SabreTools.DatFiles
|
|||||||
public long TotalSize { get; private set; } = 0;
|
public long TotalSize { get; private set; } = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of items with a CRC hash
|
/// Number of hashes for each hash type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonIgnore, XmlIgnore]
|
[JsonIgnore, XmlIgnore]
|
||||||
public long CRCCount { get; private set; } = 0;
|
public Dictionary<Hash, long> HashCounts { get; private set; } = [];
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of items with an MD5 hash
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore, XmlIgnore]
|
|
||||||
public long MD5Count { get; private set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of items with a SHA-1 hash
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore, XmlIgnore]
|
|
||||||
public long SHA1Count { get; private set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of items with a SHA-256 hash
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore, XmlIgnore]
|
|
||||||
public long SHA256Count { get; private set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of items with a SHA-384 hash
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore, XmlIgnore]
|
|
||||||
public long SHA384Count { get; private set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of items with a SHA-512 hash
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore, XmlIgnore]
|
|
||||||
public long SHA512Count { get; private set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of items with a SpamSum fuzzy hash
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore, XmlIgnore]
|
|
||||||
public long SpamSumCount { get; private set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of items with the baddump status
|
/// Number of items with the baddump status
|
||||||
@@ -282,8 +246,8 @@ namespace SabreTools.DatFiles
|
|||||||
case Disk disk:
|
case Disk disk:
|
||||||
if (disk.ItemStatus != ItemStatus.Nodump)
|
if (disk.ItemStatus != ItemStatus.Nodump)
|
||||||
{
|
{
|
||||||
MD5Count += (string.IsNullOrEmpty(disk.MD5) ? 0 : 1);
|
AddHashCount(Hash.MD5, string.IsNullOrEmpty(disk.MD5) ? 0 : 1);
|
||||||
SHA1Count += (string.IsNullOrEmpty(disk.SHA1) ? 0 : 1);
|
AddHashCount(Hash.SHA1, string.IsNullOrEmpty(disk.SHA1) ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaddumpCount += (disk.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
BaddumpCount += (disk.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
||||||
@@ -292,22 +256,22 @@ namespace SabreTools.DatFiles
|
|||||||
VerifiedCount += (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
|
VerifiedCount += (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
|
||||||
break;
|
break;
|
||||||
case Media media:
|
case Media media:
|
||||||
MD5Count += (string.IsNullOrEmpty(media.MD5) ? 0 : 1);
|
AddHashCount(Hash.MD5, string.IsNullOrEmpty(media.MD5) ? 0 : 1);
|
||||||
SHA1Count += (string.IsNullOrEmpty(media.SHA1) ? 0 : 1);
|
AddHashCount(Hash.SHA1, string.IsNullOrEmpty(media.SHA1) ? 0 : 1);
|
||||||
SHA256Count += (string.IsNullOrEmpty(media.SHA256) ? 0 : 1);
|
AddHashCount(Hash.SHA256, string.IsNullOrEmpty(media.SHA256) ? 0 : 1);
|
||||||
SpamSumCount += (string.IsNullOrEmpty(media.SpamSum) ? 0 : 1);
|
AddHashCount(Hash.SpamSum, string.IsNullOrEmpty(media.SpamSum) ? 0 : 1);
|
||||||
break;
|
break;
|
||||||
case Rom rom:
|
case Rom rom:
|
||||||
if (rom.ItemStatus != ItemStatus.Nodump)
|
if (rom.ItemStatus != ItemStatus.Nodump)
|
||||||
{
|
{
|
||||||
TotalSize += rom.Size ?? 0;
|
TotalSize += rom.Size ?? 0;
|
||||||
CRCCount += (string.IsNullOrEmpty(rom.CRC) ? 0 : 1);
|
AddHashCount(Hash.CRC, string.IsNullOrEmpty(rom.CRC) ? 0 : 1);
|
||||||
MD5Count += (string.IsNullOrEmpty(rom.MD5) ? 0 : 1);
|
AddHashCount(Hash.MD5, string.IsNullOrEmpty(rom.MD5) ? 0 : 1);
|
||||||
SHA1Count += (string.IsNullOrEmpty(rom.SHA1) ? 0 : 1);
|
AddHashCount(Hash.SHA1, string.IsNullOrEmpty(rom.SHA1) ? 0 : 1);
|
||||||
SHA256Count += (string.IsNullOrEmpty(rom.SHA256) ? 0 : 1);
|
AddHashCount(Hash.SHA256, string.IsNullOrEmpty(rom.SHA256) ? 0 : 1);
|
||||||
SHA384Count += (string.IsNullOrEmpty(rom.SHA384) ? 0 : 1);
|
AddHashCount(Hash.SHA384, string.IsNullOrEmpty(rom.SHA384) ? 0 : 1);
|
||||||
SHA512Count += (string.IsNullOrEmpty(rom.SHA512) ? 0 : 1);
|
AddHashCount(Hash.SHA512, string.IsNullOrEmpty(rom.SHA512) ? 0 : 1);
|
||||||
SpamSumCount += (string.IsNullOrEmpty(rom.SpamSum) ? 0 : 1);
|
AddHashCount(Hash.SpamSum, string.IsNullOrEmpty(rom.SpamSum) ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaddumpCount += (rom.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
BaddumpCount += (rom.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
||||||
@@ -366,13 +330,10 @@ namespace SabreTools.DatFiles
|
|||||||
TotalSize += stats.TotalSize;
|
TotalSize += stats.TotalSize;
|
||||||
|
|
||||||
// Individual hash counts
|
// Individual hash counts
|
||||||
CRCCount += stats.CRCCount;
|
foreach (var hashCountKvp in stats.HashCounts)
|
||||||
MD5Count += stats.MD5Count;
|
{
|
||||||
SHA1Count += stats.SHA1Count;
|
AddHashCount(hashCountKvp.Key, hashCountKvp.Value);
|
||||||
SHA256Count += stats.SHA256Count;
|
}
|
||||||
SHA384Count += stats.SHA384Count;
|
|
||||||
SHA512Count += stats.SHA512Count;
|
|
||||||
SpamSumCount += stats.SpamSumCount;
|
|
||||||
|
|
||||||
// Individual status counts
|
// Individual status counts
|
||||||
BaddumpCount += stats.BaddumpCount;
|
BaddumpCount += stats.BaddumpCount;
|
||||||
@@ -565,8 +526,8 @@ namespace SabreTools.DatFiles
|
|||||||
case Disk disk:
|
case Disk disk:
|
||||||
if (disk.ItemStatus != ItemStatus.Nodump)
|
if (disk.ItemStatus != ItemStatus.Nodump)
|
||||||
{
|
{
|
||||||
MD5Count -= (string.IsNullOrEmpty(disk.MD5) ? 0 : 1);
|
RemoveHashCount(Hash.MD5, string.IsNullOrEmpty(disk.MD5) ? 0 : 1);
|
||||||
SHA1Count -= (string.IsNullOrEmpty(disk.SHA1) ? 0 : 1);
|
RemoveHashCount(Hash.SHA1, string.IsNullOrEmpty(disk.SHA1) ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaddumpCount -= (disk.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
BaddumpCount -= (disk.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
||||||
@@ -575,20 +536,22 @@ namespace SabreTools.DatFiles
|
|||||||
VerifiedCount -= (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
|
VerifiedCount -= (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
|
||||||
break;
|
break;
|
||||||
case Media media:
|
case Media media:
|
||||||
MD5Count -= (string.IsNullOrEmpty(media.MD5) ? 0 : 1);
|
RemoveHashCount(Hash.MD5, string.IsNullOrEmpty(media.MD5) ? 0 : 1);
|
||||||
SHA1Count -= (string.IsNullOrEmpty(media.SHA1) ? 0 : 1);
|
RemoveHashCount(Hash.SHA1, string.IsNullOrEmpty(media.SHA1) ? 0 : 1);
|
||||||
SHA256Count -= (string.IsNullOrEmpty(media.SHA256) ? 0 : 1);
|
RemoveHashCount(Hash.SHA256, string.IsNullOrEmpty(media.SHA256) ? 0 : 1);
|
||||||
|
RemoveHashCount(Hash.SpamSum, string.IsNullOrEmpty(media.SpamSum) ? 0 : 1);
|
||||||
break;
|
break;
|
||||||
case Rom rom:
|
case Rom rom:
|
||||||
if (rom.ItemStatus != ItemStatus.Nodump)
|
if (rom.ItemStatus != ItemStatus.Nodump)
|
||||||
{
|
{
|
||||||
TotalSize -= rom.Size ?? 0;
|
TotalSize -= rom.Size ?? 0;
|
||||||
CRCCount -= (string.IsNullOrEmpty(rom.CRC) ? 0 : 1);
|
RemoveHashCount(Hash.CRC, string.IsNullOrEmpty(rom.CRC) ? 0 : 1);
|
||||||
MD5Count -= (string.IsNullOrEmpty(rom.MD5) ? 0 : 1);
|
RemoveHashCount(Hash.MD5, string.IsNullOrEmpty(rom.MD5) ? 0 : 1);
|
||||||
SHA1Count -= (string.IsNullOrEmpty(rom.SHA1) ? 0 : 1);
|
RemoveHashCount(Hash.SHA1, string.IsNullOrEmpty(rom.SHA1) ? 0 : 1);
|
||||||
SHA256Count -= (string.IsNullOrEmpty(rom.SHA256) ? 0 : 1);
|
RemoveHashCount(Hash.SHA256, string.IsNullOrEmpty(rom.SHA256) ? 0 : 1);
|
||||||
SHA384Count -= (string.IsNullOrEmpty(rom.SHA384) ? 0 : 1);
|
RemoveHashCount(Hash.SHA384, string.IsNullOrEmpty(rom.SHA384) ? 0 : 1);
|
||||||
SHA512Count -= (string.IsNullOrEmpty(rom.SHA512) ? 0 : 1);
|
RemoveHashCount(Hash.SHA512, string.IsNullOrEmpty(rom.SHA512) ? 0 : 1);
|
||||||
|
RemoveHashCount(Hash.SpamSum, string.IsNullOrEmpty(rom.SpamSum) ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaddumpCount -= (rom.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
BaddumpCount -= (rom.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
||||||
@@ -600,6 +563,22 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the item count for a given hash type, defaulting to 0 if it does not exist
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hash">Hash type to retrieve</param>
|
||||||
|
/// <returns>The number of items with that hash, if it exists</returns>
|
||||||
|
public long GetHashCount(Hash hash)
|
||||||
|
{
|
||||||
|
lock (HashCounts)
|
||||||
|
{
|
||||||
|
if (!HashCounts.ContainsKey(hash))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return HashCounts[hash];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the item count for a given item type, defaulting to 0 if it does not exist
|
/// Get the item count for a given item type, defaulting to 0 if it does not exist
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -616,6 +595,42 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Increment the hash count for a given hash type
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hash">Hash type to increment</param>
|
||||||
|
/// <param name="interval">Amount to increment by, defaults to 1</param>
|
||||||
|
private void AddHashCount(Hash hash, long interval = 1)
|
||||||
|
{
|
||||||
|
lock (HashCounts)
|
||||||
|
{
|
||||||
|
if (!HashCounts.ContainsKey(hash))
|
||||||
|
HashCounts[hash] = 0;
|
||||||
|
|
||||||
|
HashCounts[hash] += interval;
|
||||||
|
if (HashCounts[hash] < 0)
|
||||||
|
HashCounts[hash] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decrement the hash count for a given hash type
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hash">Hash type to increment</param>
|
||||||
|
/// <param name="interval">Amount to increment by, defaults to 1</param>
|
||||||
|
private void RemoveHashCount(Hash hash, long interval = 1)
|
||||||
|
{
|
||||||
|
lock (HashCounts)
|
||||||
|
{
|
||||||
|
if (!HashCounts.ContainsKey(hash))
|
||||||
|
return;
|
||||||
|
|
||||||
|
HashCounts[hash] -= interval;
|
||||||
|
if (HashCounts[hash] < 0)
|
||||||
|
HashCounts[hash] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Increment the item count for a given item type
|
/// Increment the item count for a given item type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -965,20 +980,10 @@ namespace SabreTools.DatFiles
|
|||||||
public void ResetStatistics()
|
public void ResetStatistics()
|
||||||
{
|
{
|
||||||
TotalCount = 0;
|
TotalCount = 0;
|
||||||
|
|
||||||
ItemCounts = [];
|
ItemCounts = [];
|
||||||
|
|
||||||
GameCount = 0;
|
GameCount = 0;
|
||||||
|
|
||||||
TotalSize = 0;
|
TotalSize = 0;
|
||||||
|
HashCounts = [];
|
||||||
CRCCount = 0;
|
|
||||||
MD5Count = 0;
|
|
||||||
SHA1Count = 0;
|
|
||||||
SHA256Count = 0;
|
|
||||||
SHA384Count = 0;
|
|
||||||
SHA512Count = 0;
|
|
||||||
SpamSumCount = 0;
|
|
||||||
|
|
||||||
BaddumpCount = 0;
|
BaddumpCount = 0;
|
||||||
GoodCount = 0;
|
GoodCount = 0;
|
||||||
@@ -998,23 +1003,23 @@ namespace SabreTools.DatFiles
|
|||||||
long romCount = GetItemCount(ItemType.Rom);
|
long romCount = GetItemCount(ItemType.Rom);
|
||||||
|
|
||||||
// If all items are supposed to have a SHA-512, we bucket by that
|
// 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 == GetHashCount(Hash.SHA512))
|
||||||
return ItemKey.SHA512;
|
return ItemKey.SHA512;
|
||||||
|
|
||||||
// If all items are supposed to have a SHA-384, we bucket by that
|
// 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 == GetHashCount(Hash.SHA384))
|
||||||
return ItemKey.SHA384;
|
return ItemKey.SHA384;
|
||||||
|
|
||||||
// If all items are supposed to have a SHA-256, we bucket by that
|
// 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 == GetHashCount(Hash.SHA256))
|
||||||
return ItemKey.SHA256;
|
return ItemKey.SHA256;
|
||||||
|
|
||||||
// If all items are supposed to have a SHA-1, we bucket by that
|
// 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 == GetHashCount(Hash.SHA1))
|
||||||
return ItemKey.SHA1;
|
return ItemKey.SHA1;
|
||||||
|
|
||||||
// If all items are supposed to have a MD5, we bucket by that
|
// 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 == GetHashCount(Hash.MD5))
|
||||||
return ItemKey.MD5;
|
return ItemKey.MD5;
|
||||||
|
|
||||||
// Otherwise, we bucket by CRC
|
// Otherwise, we bucket by CRC
|
||||||
|
|||||||
@@ -176,46 +176,10 @@ namespace SabreTools.DatFiles
|
|||||||
public long TotalSize { get; private set; } = 0;
|
public long TotalSize { get; private set; } = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of items with a CRC hash
|
/// Number of hashes for each hash type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonIgnore, XmlIgnore]
|
[JsonIgnore, XmlIgnore]
|
||||||
public long CRCCount { get; private set; } = 0;
|
public Dictionary<Hash, long> HashCounts { get; private set; } = [];
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of items with an MD5 hash
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore, XmlIgnore]
|
|
||||||
public long MD5Count { get; private set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of items with a SHA-1 hash
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore, XmlIgnore]
|
|
||||||
public long SHA1Count { get; private set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of items with a SHA-256 hash
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore, XmlIgnore]
|
|
||||||
public long SHA256Count { get; private set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of items with a SHA-384 hash
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore, XmlIgnore]
|
|
||||||
public long SHA384Count { get; private set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of items with a SHA-512 hash
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore, XmlIgnore]
|
|
||||||
public long SHA512Count { get; private set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of items with a SpamSum fuzzy hash
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore, XmlIgnore]
|
|
||||||
public long SpamSumCount { get; private set; } = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of items with the baddump status
|
/// Number of items with the baddump status
|
||||||
@@ -401,8 +365,8 @@ namespace SabreTools.DatFiles
|
|||||||
case Disk disk:
|
case Disk disk:
|
||||||
if (disk.ItemStatus != ItemStatus.Nodump)
|
if (disk.ItemStatus != ItemStatus.Nodump)
|
||||||
{
|
{
|
||||||
MD5Count += (string.IsNullOrEmpty(disk.MD5) ? 0 : 1);
|
AddHashCount(Hash.MD5, string.IsNullOrEmpty(disk.MD5) ? 0 : 1);
|
||||||
SHA1Count += (string.IsNullOrEmpty(disk.SHA1) ? 0 : 1);
|
AddHashCount(Hash.SHA1, string.IsNullOrEmpty(disk.SHA1) ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaddumpCount += (disk.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
BaddumpCount += (disk.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
||||||
@@ -411,22 +375,22 @@ namespace SabreTools.DatFiles
|
|||||||
VerifiedCount += (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
|
VerifiedCount += (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
|
||||||
break;
|
break;
|
||||||
case Media media:
|
case Media media:
|
||||||
MD5Count += (string.IsNullOrEmpty(media.MD5) ? 0 : 1);
|
AddHashCount(Hash.MD5, string.IsNullOrEmpty(media.MD5) ? 0 : 1);
|
||||||
SHA1Count += (string.IsNullOrEmpty(media.SHA1) ? 0 : 1);
|
AddHashCount(Hash.SHA1, string.IsNullOrEmpty(media.SHA1) ? 0 : 1);
|
||||||
SHA256Count += (string.IsNullOrEmpty(media.SHA256) ? 0 : 1);
|
AddHashCount(Hash.SHA256, string.IsNullOrEmpty(media.SHA256) ? 0 : 1);
|
||||||
SpamSumCount += (string.IsNullOrEmpty(media.SpamSum) ? 0 : 1);
|
AddHashCount(Hash.SpamSum, string.IsNullOrEmpty(media.SpamSum) ? 0 : 1);
|
||||||
break;
|
break;
|
||||||
case Rom rom:
|
case Rom rom:
|
||||||
if (rom.ItemStatus != ItemStatus.Nodump)
|
if (rom.ItemStatus != ItemStatus.Nodump)
|
||||||
{
|
{
|
||||||
TotalSize += rom.Size ?? 0;
|
TotalSize += rom.Size ?? 0;
|
||||||
CRCCount += (string.IsNullOrEmpty(rom.CRC) ? 0 : 1);
|
AddHashCount(Hash.CRC, string.IsNullOrEmpty(rom.CRC) ? 0 : 1);
|
||||||
MD5Count += (string.IsNullOrEmpty(rom.MD5) ? 0 : 1);
|
AddHashCount(Hash.MD5, string.IsNullOrEmpty(rom.MD5) ? 0 : 1);
|
||||||
SHA1Count += (string.IsNullOrEmpty(rom.SHA1) ? 0 : 1);
|
AddHashCount(Hash.SHA1, string.IsNullOrEmpty(rom.SHA1) ? 0 : 1);
|
||||||
SHA256Count += (string.IsNullOrEmpty(rom.SHA256) ? 0 : 1);
|
AddHashCount(Hash.SHA256, string.IsNullOrEmpty(rom.SHA256) ? 0 : 1);
|
||||||
SHA384Count += (string.IsNullOrEmpty(rom.SHA384) ? 0 : 1);
|
AddHashCount(Hash.SHA384, string.IsNullOrEmpty(rom.SHA384) ? 0 : 1);
|
||||||
SHA512Count += (string.IsNullOrEmpty(rom.SHA512) ? 0 : 1);
|
AddHashCount(Hash.SHA512, string.IsNullOrEmpty(rom.SHA512) ? 0 : 1);
|
||||||
SpamSumCount += (string.IsNullOrEmpty(rom.SpamSum) ? 0 : 1);
|
AddHashCount(Hash.SpamSum, string.IsNullOrEmpty(rom.SpamSum) ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaddumpCount += (rom.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
BaddumpCount += (rom.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
||||||
@@ -488,13 +452,10 @@ namespace SabreTools.DatFiles
|
|||||||
TotalSize += stats.TotalSize;
|
TotalSize += stats.TotalSize;
|
||||||
|
|
||||||
// Individual hash counts
|
// Individual hash counts
|
||||||
CRCCount += stats.CRCCount;
|
foreach (var hashCountKvp in stats.HashCounts)
|
||||||
MD5Count += stats.MD5Count;
|
{
|
||||||
SHA1Count += stats.SHA1Count;
|
AddHashCount(hashCountKvp.Key, hashCountKvp.Value);
|
||||||
SHA256Count += stats.SHA256Count;
|
}
|
||||||
SHA384Count += stats.SHA384Count;
|
|
||||||
SHA512Count += stats.SHA512Count;
|
|
||||||
SpamSumCount += stats.SpamSumCount;
|
|
||||||
|
|
||||||
// Individual status counts
|
// Individual status counts
|
||||||
BaddumpCount += stats.BaddumpCount;
|
BaddumpCount += stats.BaddumpCount;
|
||||||
@@ -711,8 +672,8 @@ namespace SabreTools.DatFiles
|
|||||||
case Disk disk:
|
case Disk disk:
|
||||||
if (disk.ItemStatus != ItemStatus.Nodump)
|
if (disk.ItemStatus != ItemStatus.Nodump)
|
||||||
{
|
{
|
||||||
MD5Count -= (string.IsNullOrEmpty(disk.MD5) ? 0 : 1);
|
RemoveHashCount(Hash.MD5, string.IsNullOrEmpty(disk.MD5) ? 0 : 1);
|
||||||
SHA1Count -= (string.IsNullOrEmpty(disk.SHA1) ? 0 : 1);
|
RemoveHashCount(Hash.SHA1, string.IsNullOrEmpty(disk.SHA1) ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaddumpCount -= (disk.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
BaddumpCount -= (disk.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
||||||
@@ -721,20 +682,22 @@ namespace SabreTools.DatFiles
|
|||||||
VerifiedCount -= (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
|
VerifiedCount -= (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
|
||||||
break;
|
break;
|
||||||
case Media media:
|
case Media media:
|
||||||
MD5Count -= (string.IsNullOrEmpty(media.MD5) ? 0 : 1);
|
RemoveHashCount(Hash.MD5, string.IsNullOrEmpty(media.MD5) ? 0 : 1);
|
||||||
SHA1Count -= (string.IsNullOrEmpty(media.SHA1) ? 0 : 1);
|
RemoveHashCount(Hash.SHA1, string.IsNullOrEmpty(media.SHA1) ? 0 : 1);
|
||||||
SHA256Count -= (string.IsNullOrEmpty(media.SHA256) ? 0 : 1);
|
RemoveHashCount(Hash.SHA256, string.IsNullOrEmpty(media.SHA256) ? 0 : 1);
|
||||||
|
RemoveHashCount(Hash.SpamSum, string.IsNullOrEmpty(media.SpamSum) ? 0 : 1);
|
||||||
break;
|
break;
|
||||||
case Rom rom:
|
case Rom rom:
|
||||||
if (rom.ItemStatus != ItemStatus.Nodump)
|
if (rom.ItemStatus != ItemStatus.Nodump)
|
||||||
{
|
{
|
||||||
TotalSize -= rom.Size ?? 0;
|
TotalSize -= rom.Size ?? 0;
|
||||||
CRCCount -= (string.IsNullOrEmpty(rom.CRC) ? 0 : 1);
|
RemoveHashCount(Hash.CRC, string.IsNullOrEmpty(rom.CRC) ? 0 : 1);
|
||||||
MD5Count -= (string.IsNullOrEmpty(rom.MD5) ? 0 : 1);
|
RemoveHashCount(Hash.MD5, string.IsNullOrEmpty(rom.MD5) ? 0 : 1);
|
||||||
SHA1Count -= (string.IsNullOrEmpty(rom.SHA1) ? 0 : 1);
|
RemoveHashCount(Hash.SHA1, string.IsNullOrEmpty(rom.SHA1) ? 0 : 1);
|
||||||
SHA256Count -= (string.IsNullOrEmpty(rom.SHA256) ? 0 : 1);
|
RemoveHashCount(Hash.SHA256, string.IsNullOrEmpty(rom.SHA256) ? 0 : 1);
|
||||||
SHA384Count -= (string.IsNullOrEmpty(rom.SHA384) ? 0 : 1);
|
RemoveHashCount(Hash.SHA384, string.IsNullOrEmpty(rom.SHA384) ? 0 : 1);
|
||||||
SHA512Count -= (string.IsNullOrEmpty(rom.SHA512) ? 0 : 1);
|
RemoveHashCount(Hash.SHA512, string.IsNullOrEmpty(rom.SHA512) ? 0 : 1);
|
||||||
|
RemoveHashCount(Hash.SpamSum, string.IsNullOrEmpty(rom.SpamSum) ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaddumpCount -= (rom.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
BaddumpCount -= (rom.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
||||||
@@ -746,6 +709,22 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the item count for a given hash type, defaulting to 0 if it does not exist
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hash">Hash type to retrieve</param>
|
||||||
|
/// <returns>The number of items with that hash, if it exists</returns>
|
||||||
|
public long GetHashCount(Hash hash)
|
||||||
|
{
|
||||||
|
lock (HashCounts)
|
||||||
|
{
|
||||||
|
if (!HashCounts.ContainsKey(hash))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return HashCounts[hash];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the item count for a given item type, defaulting to 0 if it does not exist
|
/// Get the item count for a given item type, defaulting to 0 if it does not exist
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -762,6 +741,42 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Increment the hash count for a given hash type
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hash">Hash type to increment</param>
|
||||||
|
/// <param name="interval">Amount to increment by, defaults to 1</param>
|
||||||
|
private void AddHashCount(Hash hash, long interval = 1)
|
||||||
|
{
|
||||||
|
lock (HashCounts)
|
||||||
|
{
|
||||||
|
if (!HashCounts.ContainsKey(hash))
|
||||||
|
HashCounts[hash] = 0;
|
||||||
|
|
||||||
|
HashCounts[hash] += interval;
|
||||||
|
if (HashCounts[hash] < 0)
|
||||||
|
HashCounts[hash] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decrement the hash count for a given hash type
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hash">Hash type to increment</param>
|
||||||
|
/// <param name="interval">Amount to increment by, defaults to 1</param>
|
||||||
|
private void RemoveHashCount(Hash hash, long interval = 1)
|
||||||
|
{
|
||||||
|
lock (HashCounts)
|
||||||
|
{
|
||||||
|
if (!HashCounts.ContainsKey(hash))
|
||||||
|
return;
|
||||||
|
|
||||||
|
HashCounts[hash] -= interval;
|
||||||
|
if (HashCounts[hash] < 0)
|
||||||
|
HashCounts[hash] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Increment the item count for a given item type
|
/// Increment the item count for a given item type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1136,20 +1151,10 @@ CREATE TABLE IF NOT EXISTS groups (
|
|||||||
public void ResetStatistics()
|
public void ResetStatistics()
|
||||||
{
|
{
|
||||||
TotalCount = 0;
|
TotalCount = 0;
|
||||||
|
|
||||||
ItemCounts = [];
|
ItemCounts = [];
|
||||||
|
|
||||||
GameCount = 0;
|
GameCount = 0;
|
||||||
|
|
||||||
TotalSize = 0;
|
TotalSize = 0;
|
||||||
|
HashCounts = [];
|
||||||
CRCCount = 0;
|
|
||||||
MD5Count = 0;
|
|
||||||
SHA1Count = 0;
|
|
||||||
SHA256Count = 0;
|
|
||||||
SHA384Count = 0;
|
|
||||||
SHA512Count = 0;
|
|
||||||
SpamSumCount = 0;
|
|
||||||
|
|
||||||
BaddumpCount = 0;
|
BaddumpCount = 0;
|
||||||
GoodCount = 0;
|
GoodCount = 0;
|
||||||
@@ -1169,23 +1174,23 @@ CREATE TABLE IF NOT EXISTS groups (
|
|||||||
long romCount = GetItemCount(ItemType.Rom);
|
long romCount = GetItemCount(ItemType.Rom);
|
||||||
|
|
||||||
// If all items are supposed to have a SHA-512, we bucket by that
|
// 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 == GetHashCount(Hash.SHA512))
|
||||||
return ItemKey.SHA512;
|
return ItemKey.SHA512;
|
||||||
|
|
||||||
// If all items are supposed to have a SHA-384, we bucket by that
|
// 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 == GetHashCount(Hash.SHA384))
|
||||||
return ItemKey.SHA384;
|
return ItemKey.SHA384;
|
||||||
|
|
||||||
// If all items are supposed to have a SHA-256, we bucket by that
|
// 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 == GetHashCount(Hash.SHA256))
|
||||||
return ItemKey.SHA256;
|
return ItemKey.SHA256;
|
||||||
|
|
||||||
// If all items are supposed to have a SHA-1, we bucket by that
|
// 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 == GetHashCount(Hash.SHA1))
|
||||||
return ItemKey.SHA1;
|
return ItemKey.SHA1;
|
||||||
|
|
||||||
// If all items are supposed to have a MD5, we bucket by that
|
// 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 == GetHashCount(Hash.MD5))
|
||||||
return ItemKey.MD5;
|
return ItemKey.MD5;
|
||||||
|
|
||||||
// Otherwise, we bucket by CRC
|
// Otherwise, we bucket by CRC
|
||||||
|
|||||||
@@ -247,22 +247,22 @@ body {
|
|||||||
|
|
||||||
xtw.WriteStartElement("td");
|
xtw.WriteStartElement("td");
|
||||||
xtw.WriteAttributeString("align", "right");
|
xtw.WriteAttributeString("align", "right");
|
||||||
xtw.WriteString(stat.Statistics.CRCCount.ToString());
|
xtw.WriteString(stat.Statistics.GetHashCount(Core.Hash.CRC).ToString());
|
||||||
xtw.WriteEndElement(); // td
|
xtw.WriteEndElement(); // td
|
||||||
|
|
||||||
xtw.WriteStartElement("td");
|
xtw.WriteStartElement("td");
|
||||||
xtw.WriteAttributeString("align", "right");
|
xtw.WriteAttributeString("align", "right");
|
||||||
xtw.WriteString(stat.Statistics.MD5Count.ToString());
|
xtw.WriteString(stat.Statistics.GetHashCount(Core.Hash.MD5).ToString());
|
||||||
xtw.WriteEndElement(); // td
|
xtw.WriteEndElement(); // td
|
||||||
|
|
||||||
xtw.WriteStartElement("td");
|
xtw.WriteStartElement("td");
|
||||||
xtw.WriteAttributeString("align", "right");
|
xtw.WriteAttributeString("align", "right");
|
||||||
xtw.WriteString(stat.Statistics.SHA1Count.ToString());
|
xtw.WriteString(stat.Statistics.GetHashCount(Core.Hash.SHA1).ToString());
|
||||||
xtw.WriteEndElement(); // td
|
xtw.WriteEndElement(); // td
|
||||||
|
|
||||||
xtw.WriteStartElement("td");
|
xtw.WriteStartElement("td");
|
||||||
xtw.WriteAttributeString("align", "right");
|
xtw.WriteAttributeString("align", "right");
|
||||||
xtw.WriteString(stat.Statistics.SHA256Count.ToString());
|
xtw.WriteString(stat.Statistics.GetHashCount(Core.Hash.SHA256).ToString());
|
||||||
xtw.WriteEndElement(); // td
|
xtw.WriteEndElement(); // td
|
||||||
|
|
||||||
if (baddumpCol)
|
if (baddumpCol)
|
||||||
|
|||||||
@@ -133,12 +133,12 @@ namespace SabreTools.Reports.Formats
|
|||||||
stat.MachineCount.ToString(),
|
stat.MachineCount.ToString(),
|
||||||
stat.Statistics.GetItemCount(Core.ItemType.Rom).ToString(),
|
stat.Statistics.GetItemCount(Core.ItemType.Rom).ToString(),
|
||||||
stat.Statistics.GetItemCount(Core.ItemType.Disk).ToString(),
|
stat.Statistics.GetItemCount(Core.ItemType.Disk).ToString(),
|
||||||
stat.Statistics.CRCCount.ToString(),
|
stat.Statistics.GetHashCount(Core.Hash.CRC).ToString(),
|
||||||
stat.Statistics.MD5Count.ToString(),
|
stat.Statistics.GetHashCount(Core.Hash.MD5).ToString(),
|
||||||
stat.Statistics.SHA1Count.ToString(),
|
stat.Statistics.GetHashCount(Core.Hash.SHA1).ToString(),
|
||||||
stat.Statistics.SHA256Count.ToString(),
|
stat.Statistics.GetHashCount(Core.Hash.SHA256).ToString(),
|
||||||
stat.Statistics.SHA384Count.ToString(),
|
stat.Statistics.GetHashCount(Core.Hash.SHA384).ToString(),
|
||||||
stat.Statistics.SHA512Count.ToString(),
|
stat.Statistics.GetHashCount(Core.Hash.SHA512).ToString(),
|
||||||
baddumpCol ? stat.Statistics.BaddumpCount.ToString() : string.Empty,
|
baddumpCol ? stat.Statistics.BaddumpCount.ToString() : string.Empty,
|
||||||
nodumpCol ? stat.Statistics.NodumpCount.ToString() : string.Empty,
|
nodumpCol ? stat.Statistics.NodumpCount.ToString() : string.Empty,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -95,12 +95,12 @@ namespace SabreTools.Reports.Formats
|
|||||||
Games found: " + stat.MachineCount + @"
|
Games found: " + stat.MachineCount + @"
|
||||||
Roms found: " + stat.Statistics.GetItemCount(Core.ItemType.Rom) + @"
|
Roms found: " + stat.Statistics.GetItemCount(Core.ItemType.Rom) + @"
|
||||||
Disks found: " + stat.Statistics.GetItemCount(Core.ItemType.Disk) + @"
|
Disks found: " + stat.Statistics.GetItemCount(Core.ItemType.Disk) + @"
|
||||||
Roms with CRC: " + stat.Statistics.CRCCount + @"
|
Roms with CRC: " + stat.Statistics.GetHashCount(Core.Hash.CRC) + @"
|
||||||
Roms with MD5: " + stat.Statistics.MD5Count + @"
|
Roms with MD5: " + stat.Statistics.GetHashCount(Core.Hash.MD5) + @"
|
||||||
Roms with SHA-1: " + stat.Statistics.SHA1Count + @"
|
Roms with SHA-1: " + stat.Statistics.GetHashCount(Core.Hash.SHA1) + @"
|
||||||
Roms with SHA-256: " + stat.Statistics.SHA256Count + @"
|
Roms with SHA-256: " + stat.Statistics.GetHashCount(Core.Hash.SHA256) + @"
|
||||||
Roms with SHA-384: " + stat.Statistics.SHA384Count + @"
|
Roms with SHA-384: " + stat.Statistics.GetHashCount(Core.Hash.SHA384) + @"
|
||||||
Roms with SHA-512: " + stat.Statistics.SHA512Count + "\n";
|
Roms with SHA-512: " + stat.Statistics.GetHashCount(Core.Hash.SHA512) + "\n";
|
||||||
|
|
||||||
if (baddumpCol)
|
if (baddumpCol)
|
||||||
line += " Roms with BadDump status: " + stat.Statistics.BaddumpCount + "\n";
|
line += " Roms with BadDump status: " + stat.Statistics.BaddumpCount + "\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user