mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatStats] Add more methods to DatStats
This commit is contained in:
@@ -1,56 +1,87 @@
|
|||||||
namespace SabreTools.Library.Dats
|
using System;
|
||||||
|
|
||||||
|
using SabreTools.Library.Data;
|
||||||
|
|
||||||
|
namespace SabreTools.Library.Dats
|
||||||
{
|
{
|
||||||
public class DatStats
|
public class DatStats
|
||||||
{
|
{
|
||||||
#region Private instance variables
|
#region Private instance variables
|
||||||
|
|
||||||
// Statistical data related to the DAT
|
// Object used to lock stats updates
|
||||||
private object _lockObject;
|
private object _lockObject = new object();
|
||||||
|
|
||||||
|
// Overall item count
|
||||||
private long _count;
|
private long _count;
|
||||||
private long _romCount;
|
|
||||||
|
// Individual DatItem type counts
|
||||||
|
private long _archiveCount;
|
||||||
|
private long _biosSetCount;
|
||||||
private long _diskCount;
|
private long _diskCount;
|
||||||
|
private long _releaseCount;
|
||||||
|
private long _romCount;
|
||||||
|
private long _sampleCount;
|
||||||
|
|
||||||
|
// Total reported size
|
||||||
private long _totalSize;
|
private long _totalSize;
|
||||||
|
|
||||||
|
// Individual hash counts
|
||||||
private long _crcCount;
|
private long _crcCount;
|
||||||
private long _md5Count;
|
private long _md5Count;
|
||||||
private long _sha1Count;
|
private long _sha1Count;
|
||||||
private long _sha256Count;
|
private long _sha256Count;
|
||||||
private long _sha384Count;
|
private long _sha384Count;
|
||||||
private long _sha512Count;
|
private long _sha512Count;
|
||||||
|
|
||||||
|
// Individual status counts
|
||||||
private long _baddumpCount;
|
private long _baddumpCount;
|
||||||
|
private long _goodCount;
|
||||||
private long _nodumpCount;
|
private long _nodumpCount;
|
||||||
|
private long _verifiedCount;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Publicly facing variables
|
#region Publicly facing variables
|
||||||
|
|
||||||
// Statistical data related to the DAT
|
// Overall item count
|
||||||
public object LockObject
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_lockObject == null)
|
|
||||||
{
|
|
||||||
_lockObject = new object();
|
|
||||||
}
|
|
||||||
return _lockObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public long Count
|
public long Count
|
||||||
{
|
{
|
||||||
get { return _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
|
public long DiskCount
|
||||||
{
|
{
|
||||||
get { return _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
|
public long TotalSize
|
||||||
{
|
{
|
||||||
get { return _totalSize; }
|
get { return _totalSize; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Individual hash counts
|
||||||
public long CRCCount
|
public long CRCCount
|
||||||
{
|
{
|
||||||
get { return _crcCount; }
|
get { return _crcCount; }
|
||||||
@@ -75,15 +106,188 @@
|
|||||||
{
|
{
|
||||||
get { return _sha512Count; }
|
get { return _sha512Count; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Individual status counts
|
||||||
public long BaddumpCount
|
public long BaddumpCount
|
||||||
{
|
{
|
||||||
get { return _baddumpCount; }
|
get { return _baddumpCount; }
|
||||||
}
|
}
|
||||||
|
public long GoodCount
|
||||||
|
{
|
||||||
|
get { return _goodCount; }
|
||||||
|
}
|
||||||
public long NodumpCount
|
public long NodumpCount
|
||||||
{
|
{
|
||||||
get { return _nodumpCount; }
|
get { return _nodumpCount; }
|
||||||
}
|
}
|
||||||
|
public long VerifiedCount
|
||||||
|
{
|
||||||
|
get { return _verifiedCount; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Instance Methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add to the statistics given a DatItem
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">Item to add info from</param>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove from the statistics given a DatItem
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">Item to remove info for</param>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reset all statistics
|
||||||
|
/// </summary>
|
||||||
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user