diff --git a/SabreTools.Library/Dats/DatStats.cs b/SabreTools.Library/Dats/DatStats.cs
index 459b2934..8974675b 100644
--- a/SabreTools.Library/Dats/DatStats.cs
+++ b/SabreTools.Library/Dats/DatStats.cs
@@ -1,56 +1,87 @@
-namespace SabreTools.Library.Dats
+using System;
+
+using SabreTools.Library.Data;
+
+namespace SabreTools.Library.Dats
{
public class DatStats
{
#region Private instance variables
- // Statistical data related to the DAT
- private object _lockObject;
+ // Object used to lock stats updates
+ private object _lockObject = new object();
+
+ // Overall item count
private long _count;
- private long _romCount;
+
+ // Individual DatItem type counts
+ private long _archiveCount;
+ private long _biosSetCount;
private long _diskCount;
+ private long _releaseCount;
+ private long _romCount;
+ private long _sampleCount;
+
+ // Total reported size
private long _totalSize;
+
+ // Individual hash counts
private long _crcCount;
private long _md5Count;
private long _sha1Count;
private long _sha256Count;
private long _sha384Count;
private long _sha512Count;
+
+ // Individual status counts
private long _baddumpCount;
+ private long _goodCount;
private long _nodumpCount;
+ private long _verifiedCount;
#endregion
#region Publicly facing variables
- // Statistical data related to the DAT
- public object LockObject
- {
- get
- {
- if (_lockObject == null)
- {
- _lockObject = new object();
- }
- return _lockObject;
- }
- }
+ // Overall item count
public long Count
{
get { return _count; }
}
- public long RomCount
+
+ // Individual DatItem type counts
+ public long ArchiveCount
{
- get { return _romCount; }
+ get { return _archiveCount; }
+ }
+ public long BiosSetCount
+ {
+ get { return _biosSetCount; }
}
public long DiskCount
{
get { return _diskCount; }
}
+ public long ReleaseCount
+ {
+ get { return _releaseCount; }
+ }
+ public long RomCount
+ {
+ get { return _romCount; }
+ }
+ public long SampleCount
+ {
+ get { return _sampleCount; }
+ }
+
+ // Total reported size
public long TotalSize
{
get { return _totalSize; }
}
+
+ // Individual hash counts
public long CRCCount
{
get { return _crcCount; }
@@ -75,15 +106,188 @@
{
get { return _sha512Count; }
}
+
+ // Individual status counts
public long BaddumpCount
{
get { return _baddumpCount; }
}
+ public long GoodCount
+ {
+ get { return _goodCount; }
+ }
public long NodumpCount
{
get { return _nodumpCount; }
}
+ public long VerifiedCount
+ {
+ get { return _verifiedCount; }
+ }
#endregion
+
+ #region Instance Methods
+
+ ///
+ /// Add to the statistics given a DatItem
+ ///
+ /// Item to add info from
+ private void AddItem(DatItem item)
+ {
+ // No matter what the item is, we increate the count
+ lock (_lockObject)
+ {
+ _count += 1;
+
+ // Now we do different things for each item type
+
+ switch (item.Type)
+ {
+ case ItemType.Archive:
+ _archiveCount += 1;
+ break;
+ case ItemType.BiosSet:
+ _biosSetCount += 1;
+ break;
+ case ItemType.Disk:
+ _diskCount += 1;
+ if (((Disk)item).ItemStatus != ItemStatus.Nodump)
+ {
+ _md5Count += (String.IsNullOrEmpty(((Disk)item).MD5) ? 0 : 1);
+ _sha1Count += (String.IsNullOrEmpty(((Disk)item).SHA1) ? 0 : 1);
+ _sha256Count += (String.IsNullOrEmpty(((Disk)item).SHA256) ? 0 : 1);
+ _sha384Count += (String.IsNullOrEmpty(((Disk)item).SHA384) ? 0 : 1);
+ _sha512Count += (String.IsNullOrEmpty(((Disk)item).SHA512) ? 0 : 1);
+ }
+
+ _baddumpCount += (((Disk)item).ItemStatus == ItemStatus.BadDump ? 1 : 0);
+ _goodCount += (((Disk)item).ItemStatus == ItemStatus.Good ? 1 : 0);
+ _nodumpCount += (((Disk)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
+ _verifiedCount += (((Disk)item).ItemStatus == ItemStatus.Verified ? 1 : 0);
+ break;
+ case ItemType.Release:
+ _releaseCount += 1;
+ break;
+ case ItemType.Rom:
+ _romCount += 1;
+ if (((Rom)item).ItemStatus != ItemStatus.Nodump)
+ {
+ _totalSize += ((Rom)item).Size;
+ _crcCount += (String.IsNullOrEmpty(((Rom)item).CRC) ? 0 : 1);
+ _md5Count += (String.IsNullOrEmpty(((Rom)item).MD5) ? 0 : 1);
+ _sha1Count += (String.IsNullOrEmpty(((Rom)item).SHA1) ? 0 : 1);
+ _sha256Count += (String.IsNullOrEmpty(((Rom)item).SHA256) ? 0 : 1);
+ _sha384Count += (String.IsNullOrEmpty(((Rom)item).SHA384) ? 0 : 1);
+ _sha512Count += (String.IsNullOrEmpty(((Rom)item).SHA512) ? 0 : 1);
+ }
+
+ _baddumpCount += (((Rom)item).ItemStatus == ItemStatus.BadDump ? 1 : 0);
+ _goodCount += (((Rom)item).ItemStatus == ItemStatus.Good ? 1 : 0);
+ _nodumpCount += (((Rom)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
+ _verifiedCount += (((Rom)item).ItemStatus == ItemStatus.Verified ? 1 : 0);
+ break;
+ case ItemType.Sample:
+ _sampleCount += 1;
+ break;
+ }
+ }
+ }
+
+ ///
+ /// Remove from the statistics given a DatItem
+ ///
+ /// Item to remove info for
+ private void RemoveItem(DatItem item)
+ {
+ // No matter what the item is, we increate the count
+ lock (_lockObject)
+ {
+ _count -= 1;
+
+ // Now we do different things for each item type
+
+ switch (item.Type)
+ {
+ case ItemType.Archive:
+ _archiveCount -= 1;
+ break;
+ case ItemType.BiosSet:
+ _biosSetCount -= 1;
+ break;
+ case ItemType.Disk:
+ _diskCount -= 1;
+ if (((Disk)item).ItemStatus != ItemStatus.Nodump)
+ {
+ _md5Count -= (String.IsNullOrEmpty(((Disk)item).MD5) ? 0 : 1);
+ _sha1Count -= (String.IsNullOrEmpty(((Disk)item).SHA1) ? 0 : 1);
+ _sha256Count -= (String.IsNullOrEmpty(((Disk)item).SHA256) ? 0 : 1);
+ _sha384Count -= (String.IsNullOrEmpty(((Disk)item).SHA384) ? 0 : 1);
+ _sha512Count -= (String.IsNullOrEmpty(((Disk)item).SHA512) ? 0 : 1);
+ }
+
+ _baddumpCount -= (((Disk)item).ItemStatus == ItemStatus.BadDump ? 1 : 0);
+ _goodCount -= (((Disk)item).ItemStatus == ItemStatus.Good ? 1 : 0);
+ _nodumpCount -= (((Disk)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
+ _verifiedCount -= (((Disk)item).ItemStatus == ItemStatus.Verified ? 1 : 0);
+ break;
+ case ItemType.Release:
+ _releaseCount -= 1;
+ break;
+ case ItemType.Rom:
+ _romCount -= 1;
+ if (((Rom)item).ItemStatus != ItemStatus.Nodump)
+ {
+ _totalSize -= ((Rom)item).Size;
+ _crcCount -= (String.IsNullOrEmpty(((Rom)item).CRC) ? 0 : 1);
+ _md5Count -= (String.IsNullOrEmpty(((Rom)item).MD5) ? 0 : 1);
+ _sha1Count -= (String.IsNullOrEmpty(((Rom)item).SHA1) ? 0 : 1);
+ _sha256Count -= (String.IsNullOrEmpty(((Rom)item).SHA256) ? 0 : 1);
+ _sha384Count -= (String.IsNullOrEmpty(((Rom)item).SHA384) ? 0 : 1);
+ _sha512Count -= (String.IsNullOrEmpty(((Rom)item).SHA512) ? 0 : 1);
+ }
+
+ _baddumpCount -= (((Rom)item).ItemStatus == ItemStatus.BadDump ? 1 : 0);
+ _goodCount -= (((Rom)item).ItemStatus == ItemStatus.Good ? 1 : 0);
+ _nodumpCount -= (((Rom)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
+ _verifiedCount -= (((Rom)item).ItemStatus == ItemStatus.Verified ? 1 : 0);
+ break;
+ case ItemType.Sample:
+ _sampleCount -= 1;
+ break;
+ }
+ }
+ }
+
+ ///
+ /// Reset all statistics
+ ///
+ private void Reset()
+ {
+ _count = 0;
+
+ _archiveCount = 0;
+ _biosSetCount = 0;
+ _diskCount = 0;
+ _releaseCount = 0;
+ _romCount = 0;
+ _sampleCount = 0;
+
+ _totalSize = 0;
+
+ _crcCount = 0;
+ _md5Count = 0;
+ _sha1Count = 0;
+ _sha256Count = 0;
+ _sha384Count = 0;
+ _sha512Count = 0;
+
+ _baddumpCount = 0;
+ _goodCount = 0;
+ _nodumpCount = 0;
+ _verifiedCount = 0;
+ }
+
+ #endregion // Instance Methods
}
}