[DatFile] Use DatHeader and DatStats

This commit is contained in:
Matt Nadareski
2017-10-06 15:49:32 -07:00
parent ada498b415
commit a20be6fc43
6 changed files with 229 additions and 479 deletions

View File

@@ -10,58 +10,15 @@ namespace SabreTools.Library.Dats
{ {
#region Private instance variables #region Private instance variables
// Data common to most DAT types // Internal DatHeader values
private string _fileName; private DatHeader _datHeader = new DatHeader();
private string _name;
private string _description; // DatItems dictionary
private string _rootDir;
private string _category;
private string _version;
private string _date;
private string _author;
private string _email;
private string _homepage;
private string _url;
private string _comment;
private string _header;
private string _type; // Generally only used for SuperDAT
private ForceMerging _forceMerging;
private ForceNodump _forceNodump;
private ForcePacking _forcePacking;
private DatFormat _datFormat;
private bool _excludeOf;
private DedupeType _dedupeRoms;
private Hash _stripHash;
private bool _oneGameOneRegion;
private List<string> _regions = new List<string>();
private SortedDictionary<string, List<DatItem>> _items = new SortedDictionary<string, List<DatItem>>(); private SortedDictionary<string, List<DatItem>> _items = new SortedDictionary<string, List<DatItem>>();
private SortedBy _sortedBy; private SortedBy _sortedBy;
// Data specific to the Miss DAT type // Internal statistical data
private bool _useGame; DatStats _datStats = new DatStats();
private string _prefix;
private string _postfix;
private bool _quotes;
private string _repExt;
private string _addExt;
private bool _remExt;
private bool _gameName;
private bool _romba;
// Statistical data related to the DAT
private object _statslock = new object();
private long _count;
private long _romCount;
private long _diskCount;
private long _totalSize;
private long _crcCount;
private long _md5Count;
private long _sha1Count;
private long _sha256Count;
private long _sha384Count;
private long _sha512Count;
private long _baddumpCount;
private long _nodumpCount;
#endregion #endregion
@@ -70,118 +27,118 @@ namespace SabreTools.Library.Dats
// Data common to most DAT types // Data common to most DAT types
public string FileName public string FileName
{ {
get { return _fileName; } get { return _datHeader.FileName; }
set { _fileName = value; } set { _datHeader.FileName = value; }
} }
public string Name public string Name
{ {
get { return _name; } get { return _datHeader.Name; }
set { _name = value; } set { _datHeader.Name = value; }
} }
public string Description public string Description
{ {
get { return _description; } get { return _datHeader.Description; }
set { _description = value; } set { _datHeader.Description = value; }
} }
public string RootDir public string RootDir
{ {
get { return _rootDir; } get { return _datHeader.RootDir; }
set { _rootDir = value; } set { _datHeader.RootDir = value; }
} }
public string Category public string Category
{ {
get { return _category; } get { return _datHeader.Category; }
set { _category = value; } set { _datHeader.Category = value; }
} }
public string Version public string Version
{ {
get { return _version; } get { return _datHeader.Version; }
set { _version = value; } set { _datHeader.Version = value; }
} }
public string Date public string Date
{ {
get { return _date; } get { return _datHeader.Date; }
set { _date = value; } set { _datHeader.Date = value; }
} }
public string Author public string Author
{ {
get { return _author; } get { return _datHeader.Author; }
set { _author = value; } set { _datHeader.Author = value; }
} }
public string Email public string Email
{ {
get { return _email; } get { return _datHeader.Email; }
set { _email = value; } set { _datHeader.Email = value; }
} }
public string Homepage public string Homepage
{ {
get { return _homepage; } get { return _datHeader.Homepage; }
set { _homepage = value; } set { _datHeader.Homepage = value; }
} }
public string Url public string Url
{ {
get { return _url; } get { return _datHeader.Url; }
set { _url = value; } set { _datHeader.Url = value; }
} }
public string Comment public string Comment
{ {
get { return _comment; } get { return _datHeader.Comment; }
set { _comment = value; } set { _datHeader.Comment = value; }
} }
public string Header public string Header
{ {
get { return _header; } get { return _datHeader.Header; }
set { _header = value; } set { _datHeader.Header = value; }
} }
public string Type // Generally only used for SuperDAT public string Type // Generally only used for SuperDAT
{ {
get { return _type; } get { return _datHeader.Type; }
set { _type = value; } set { _datHeader.Type = value; }
} }
public ForceMerging ForceMerging public ForceMerging ForceMerging
{ {
get { return _forceMerging; } get { return _datHeader.ForceMerging; }
set { _forceMerging = value; } set { _datHeader.ForceMerging = value; }
} }
public ForceNodump ForceNodump public ForceNodump ForceNodump
{ {
get { return _forceNodump; } get { return _datHeader.ForceNodump; }
set { _forceNodump = value; } set { _datHeader.ForceNodump = value; }
} }
public ForcePacking ForcePacking public ForcePacking ForcePacking
{ {
get { return _forcePacking; } get { return _datHeader.ForcePacking; }
set { _forcePacking = value; } set { _datHeader.ForcePacking = value; }
} }
public DatFormat DatFormat public DatFormat DatFormat
{ {
get { return _datFormat; } get { return _datHeader.DatFormat; }
set { _datFormat = value; } set { _datHeader.DatFormat = value; }
} }
public bool ExcludeOf public bool ExcludeOf
{ {
get { return _excludeOf; } get { return _datHeader.ExcludeOf; }
set { _excludeOf = value; } set { _datHeader.ExcludeOf = value; }
} }
public DedupeType DedupeRoms public DedupeType DedupeRoms
{ {
get { return _dedupeRoms; } get { return _datHeader.DedupeRoms; }
set { _dedupeRoms = value; } set { _datHeader.DedupeRoms = value; }
} }
public Hash StripHash public Hash StripHash
{ {
get { return _stripHash; } get { return _datHeader.StripHash; }
set { _stripHash = value; } set { _datHeader.StripHash = value; }
} }
public bool OneGameOneRegion public bool OneGameOneRegion
{ {
get { return _oneGameOneRegion; } get { return _datHeader.OneGameOneRegion; }
set { _oneGameOneRegion = value; } set { _datHeader.OneGameOneRegion = value; }
} }
public List<string> Regions public List<string> Regions
{ {
get { return _regions; } get { return _datHeader.Regions; }
set { _regions = value; } set { _datHeader.Regions = value; }
} }
public SortedBy SortedBy public SortedBy SortedBy
{ {
@@ -191,98 +148,140 @@ namespace SabreTools.Library.Dats
// Data specific to the Miss DAT type // Data specific to the Miss DAT type
public bool UseGame public bool UseGame
{ {
get { return _useGame; } get { return _datHeader.UseGame; }
set { _useGame = value; } set { _datHeader.UseGame = value; }
} }
public string Prefix public string Prefix
{ {
get { return _prefix; } get { return _datHeader.Prefix; }
set { _prefix = value; } set { _datHeader.Prefix = value; }
} }
public string Postfix public string Postfix
{ {
get { return _postfix; } get { return _datHeader.Postfix; }
set { _postfix = value; } set { _datHeader.Postfix = value; }
} }
public bool Quotes public bool Quotes
{ {
get { return _quotes; } get { return _datHeader.Quotes; }
set { _quotes = value; } set { _datHeader.Quotes = value; }
} }
public string RepExt public string RepExt
{ {
get { return _repExt; } get { return _datHeader.RepExt; }
set { _repExt = value; } set { _datHeader.RepExt = value; }
} }
public string AddExt public string AddExt
{ {
get { return _addExt; } get { return _datHeader.AddExt; }
set { _addExt = value; } set { _datHeader.AddExt = value; }
} }
public bool RemExt public bool RemExt
{ {
get { return _remExt; } get { return _datHeader.RemExt; }
set { _remExt = value; } set { _datHeader.RemExt = value; }
} }
public bool GameName public bool GameName
{ {
get { return _gameName; } get { return _datHeader.GameName; }
set { _gameName = value; } set { _datHeader.GameName = value; }
} }
public bool Romba public bool Romba
{ {
get { return _romba; } get { return _datHeader.Romba; }
set { _romba = value; } set { _datHeader.Romba = value; }
} }
// Statistical data related to the DAT // Statistical data related to the DAT
public long Count public long Count
{ {
get { return _count; } get { return _datStats.Count; }
private set { _datStats.Count = value; }
} }
public long RomCount public long ArchiveCount
{ {
get { return _romCount; } get { return _datStats.ArchiveCount; }
private set { _datStats.ArchiveCount = value; }
}
public long BiosSetCount
{
get { return _datStats.BiosSetCount; }
private set { _datStats.BiosSetCount = value; }
} }
public long DiskCount public long DiskCount
{ {
get { return _diskCount; } get { return _datStats.DiskCount; }
private set { _datStats.DiskCount = value; }
}
public long ReleaseCount
{
get { return _datStats.ReleaseCount; }
private set { _datStats.ReleaseCount = value; }
}
public long RomCount
{
get { return _datStats.RomCount; }
private set { _datStats.RomCount = value; }
}
public long SampleCount
{
get { return _datStats.SampleCount; }
private set { _datStats.SampleCount = value; }
} }
public long TotalSize public long TotalSize
{ {
get { return _totalSize; } get { return _datStats.TotalSize; }
private set { _datStats.TotalSize = value; }
} }
public long CRCCount public long CRCCount
{ {
get { return _crcCount; } get { return _datStats.CRCCount; }
private set { _datStats.CRCCount = value; }
} }
public long MD5Count public long MD5Count
{ {
get { return _md5Count; } get { return _datStats.MD5Count; }
private set { _datStats.MD5Count = value; }
} }
public long SHA1Count public long SHA1Count
{ {
get { return _sha1Count; } get { return _datStats.SHA1Count; }
private set { _datStats.SHA1Count = value; }
} }
public long SHA256Count public long SHA256Count
{ {
get { return _sha256Count; } get { return _datStats.SHA256Count; }
private set { _datStats.SHA256Count = value; }
} }
public long SHA384Count public long SHA384Count
{ {
get { return _sha384Count; } get { return _datStats.SHA384Count; }
private set { _datStats.SHA384Count = value; }
} }
public long SHA512Count public long SHA512Count
{ {
get { return _sha512Count; } get { return _datStats.SHA512Count; }
private set { _datStats.SHA512Count = value; }
} }
public long BaddumpCount public long BaddumpCount
{ {
get { return _baddumpCount; } get { return _datStats.BaddumpCount; }
private set { _datStats.BaddumpCount = value; }
}
public long GoodCount
{
get { return _datStats.GoodCount; }
private set { _datStats.GoodCount = value; }
} }
public long NodumpCount public long NodumpCount
{ {
get { return _nodumpCount; } get { return _datStats.NodumpCount; }
private set { _datStats.NodumpCount = value; }
}
public long VerifiedCount
{
get { return _datStats.VerifiedCount; }
private set { _datStats.VerifiedCount = value; }
} }
#endregion #endregion
@@ -364,7 +363,7 @@ namespace SabreTools.Library.Dats
_items[key].Add(value); _items[key].Add(value);
// Now update the statistics // Now update the statistics
AddItemStatistics(value); _datStats.AddItem(value);
} }
} }
@@ -392,7 +391,7 @@ namespace SabreTools.Library.Dats
// Now update the statistics // Now update the statistics
foreach (DatItem item in value) foreach (DatItem item in value)
{ {
AddItemStatistics(item); _datStats.AddItem(item);
} }
} }
} }
@@ -503,7 +502,7 @@ namespace SabreTools.Library.Dats
// Remove the statistics first // Remove the statistics first
foreach (DatItem item in _items[key]) foreach (DatItem item in _items[key])
{ {
RemoveItemStatistics(item); _datStats.RemoveItem(item);
} }
// Remove the key from the dictionary // Remove the key from the dictionary
@@ -536,7 +535,7 @@ namespace SabreTools.Library.Dats
while (_items.ContainsKey(key) && _items[key].Contains(value)) while (_items.ContainsKey(key) && _items[key].Contains(value))
{ {
// Remove the statistics first // Remove the statistics first
RemoveItemStatistics(value); _datStats.RemoveItem(value);
_items[key].Remove(value); _items[key].Remove(value);
} }
@@ -569,42 +568,12 @@ namespace SabreTools.Library.Dats
} }
/// <summary> /// <summary>
/// Create a new DatFile from an existing one /// Create a new DatFile from an existing one using the header values only
/// </summary> /// </summary>
/// <param name="df"></param> /// <param name="df"></param>
public DatFile(DatFile datFile) public DatFile(DatFile datFile)
{ {
_fileName = datFile.FileName; _datHeader = (DatHeader)datFile._datHeader.Clone();
_name = datFile.Name;
_description = datFile.Description;
_rootDir = datFile.RootDir;
_category = datFile.Category;
_version = datFile.Version;
_date = datFile.Date;
_author = datFile.Author;
_email = datFile.Email;
_homepage = datFile.Homepage;
_url = datFile.Url;
_comment = datFile.Comment;
_header = datFile.Header;
_type = datFile.Type;
_forceMerging = datFile.ForceMerging;
_forceNodump = datFile.ForceNodump;
_forcePacking = datFile.ForcePacking;
_excludeOf = datFile.ExcludeOf;
_datFormat = datFile.DatFormat;
_dedupeRoms = datFile.DedupeRoms;
_stripHash = datFile.StripHash;
_sortedBy = SortedBy.Default;
_useGame = datFile.UseGame;
_prefix = datFile.Prefix;
_postfix = datFile.Postfix;
_quotes = datFile.Quotes;
_repExt = datFile.RepExt;
_addExt = datFile.AddExt;
_remExt = datFile.RemExt;
_gameName = datFile.GameName;
_romba = datFile.Romba;
} }
#endregion #endregion
@@ -653,7 +622,7 @@ namespace SabreTools.Library.Dats
_items = null; _items = null;
// Reset statistics // Reset statistics
ResetStatistics(); _datStats.Reset();
} }
/// <summary> /// <summary>
@@ -664,7 +633,7 @@ namespace SabreTools.Library.Dats
_items = new SortedDictionary<string, List<DatItem>>(); _items = new SortedDictionary<string, List<DatItem>>();
// Reset statistics // Reset statistics
ResetStatistics(); _datStats.Reset();
} }
#endregion #endregion

View File

@@ -358,17 +358,17 @@ namespace SabreTools.Library.Dats
DatFile dupeData = new DatFile(); DatFile dupeData = new DatFile();
// Fill in any information not in the base DAT // Fill in any information not in the base DAT
if (String.IsNullOrEmpty(_fileName)) if (String.IsNullOrEmpty(FileName))
{ {
_fileName = "All DATs"; FileName = "All DATs";
} }
if (String.IsNullOrEmpty(_name)) if (String.IsNullOrEmpty(Name))
{ {
_name = "All DATs"; Name = "All DATs";
} }
if (String.IsNullOrEmpty(_description)) if (String.IsNullOrEmpty(Description))
{ {
_description = "All DATs"; Description = "All DATs";
} }
// Don't have External dupes // Don't have External dupes

View File

@@ -157,7 +157,7 @@ namespace SabreTools.Library.Dats
// If we are using tags from the DAT, set the proper input for split type unless overridden // If we are using tags from the DAT, set the proper input for split type unless overridden
if (useTags && splitType == SplitType.None) if (useTags && splitType == SplitType.None)
{ {
switch (_forceMerging) switch (ForceMerging)
{ {
case ForceMerging.None: case ForceMerging.None:
// No-op // No-op

View File

@@ -205,9 +205,9 @@ namespace SabreTools.Library.Dats
// If we're updating the DAT, output to the rebuild directory // If we're updating the DAT, output to the rebuild directory
if (updateDat) if (updateDat)
{ {
_fileName = "fixDAT_" + _fileName; FileName = "fixDAT_" + FileName;
_name = "fixDAT_" + _name; Name = "fixDAT_" + Name;
_description = "fixDAT_" + _description; Description = "fixDAT_" + Description;
WriteToFile(outDir); WriteToFile(outDir);
} }
@@ -351,9 +351,9 @@ namespace SabreTools.Library.Dats
// If we're updating the DAT, output to the rebuild directory // If we're updating the DAT, output to the rebuild directory
if (updateDat) if (updateDat)
{ {
_fileName = "fixDAT_" + _fileName; FileName = "fixDAT_" + FileName;
_name = "fixDAT_" + _name; Name = "fixDAT_" + Name;
_description = "fixDAT_" + _description; Description = "fixDAT_" + Description;
WriteToFile(outDir); WriteToFile(outDir);
} }
@@ -937,9 +937,9 @@ namespace SabreTools.Library.Dats
watch.Stop(); watch.Stop();
// If there are any entries in the DAT, output to the rebuild directory // If there are any entries in the DAT, output to the rebuild directory
_fileName = "fixDAT_" + _fileName; FileName = "fixDAT_" + FileName;
_name = "fixDAT_" + _name; Name = "fixDAT_" + Name;
_description = "fixDAT_" + _description; Description = "fixDAT_" + Description;
WriteToFile(null); WriteToFile(null);
return success; return success;

View File

@@ -28,146 +28,13 @@ namespace SabreTools.Library.Dats
#region Statistics #region Statistics
/// <summary>
/// Add to the internal statistics given a DatItem
/// </summary>
/// <param name="item">Item to add info from</param>
private void AddItemStatistics(DatItem item)
{
// No matter what the item is, we increate the count
lock (_statslock)
{
_count += 1;
// Now we do different things for each item type
switch (item.Type)
{
case ItemType.Archive:
break;
case ItemType.BiosSet:
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);
_nodumpCount += (((Disk)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
break;
case ItemType.Release:
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);
_nodumpCount += (((Rom)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
break;
case ItemType.Sample:
break;
}
}
}
/// <summary>
/// Remove from the internal statistics given a DatItem
/// </summary>
/// <param name="item">Item to remove info for</param>
private void RemoveItemStatistics(DatItem item)
{
// No matter what the item is, we increate the count
lock (_statslock)
{
_count -= 1;
// Now we do different things for each item type
switch (item.Type)
{
case ItemType.Archive:
break;
case ItemType.BiosSet:
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);
_nodumpCount -= (((Disk)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
break;
case ItemType.Release:
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);
_nodumpCount -= (((Rom)item).ItemStatus == ItemStatus.Nodump ? 1 : 0);
break;
case ItemType.Sample:
break;
}
}
}
/// <summary>
/// Reset all statistics
/// </summary>
private void ResetStatistics()
{
_count = 0;
_romCount = 0;
_diskCount = 0;
_totalSize = 0;
_crcCount = 0;
_md5Count = 0;
_sha1Count = 0;
_sha256Count = 0;
_sha384Count = 0;
_sha512Count = 0;
_baddumpCount = 0;
_nodumpCount = 0;
}
/// <summary> /// <summary>
/// Recalculate the statistics for the Dat /// Recalculate the statistics for the Dat
/// </summary> /// </summary>
public void RecalculateStats() public void RecalculateStats()
{ {
// Wipe out any stats already there // Wipe out any stats already there
ResetStatistics(); _datStats.Reset();
// If we have a blank Dat in any way, return // If we have a blank Dat in any way, return
if (this == null || Count == 0) if (this == null || Count == 0)
@@ -182,7 +49,7 @@ namespace SabreTools.Library.Dats
List<DatItem> items = this[key]; List<DatItem> items = this[key];
foreach(DatItem item in items) foreach(DatItem item in items)
{ {
AddItemStatistics(item); _datStats.AddItem(item);
} }
}); });
} }
@@ -206,32 +73,32 @@ namespace SabreTools.Library.Dats
} }
BucketBy(SortedBy.Game, DedupeType.None, norename: true); BucketBy(SortedBy.Game, DedupeType.None, norename: true);
if (_totalSize < 0) if (TotalSize < 0)
{ {
_totalSize = Int64.MaxValue + _totalSize; TotalSize = Int64.MaxValue + TotalSize;
} }
// Log the results to screen // Log the results to screen
string results = @"For '" + _fileName + @"': string results = @"For '" + FileName + @"':
-------------------------------------------------- --------------------------------------------------
Uncompressed size: " + Style.GetBytesReadable(_totalSize) + @" Uncompressed size: " + Style.GetBytesReadable(TotalSize) + @"
Games found: " + (game == -1 ? Keys.Count() : game) + @" Games found: " + (game == -1 ? Keys.Count() : game) + @"
Roms found: " + _romCount + @" Roms found: " + RomCount + @"
Disks found: " + _diskCount + @" Disks found: " + DiskCount + @"
Roms with CRC: " + _crcCount + @" Roms with CRC: " + CRCCount + @"
Roms with MD5: " + _md5Count + @" Roms with MD5: " + MD5Count + @"
Roms with SHA-1: " + _sha1Count + @" Roms with SHA-1: " + SHA1Count + @"
Roms with SHA-256: " + _sha256Count + @" Roms with SHA-256: " + SHA256Count + @"
Roms with SHA-384: " + _sha384Count + @" Roms with SHA-384: " + SHA384Count + @"
Roms with SHA-512: " + _sha512Count + "\n"; Roms with SHA-512: " + SHA512Count + "\n";
if (baddumpCol) if (baddumpCol)
{ {
results += " Roms with BadDump status: " + _baddumpCount + "\n"; results += " Roms with BadDump status: " + BaddumpCount + "\n";
} }
if (nodumpCol) if (nodumpCol)
{ {
results += " Roms with Nodump status: " + _nodumpCount + "\n"; results += " Roms with Nodump status: " + NodumpCount + "\n";
} }
// For spacing between DATs // For spacing between DATs
@@ -243,25 +110,25 @@ namespace SabreTools.Library.Dats
string line = ""; string line = "";
if (outputs.ContainsKey(StatDatFormat.None)) if (outputs.ContainsKey(StatDatFormat.None))
{ {
line = @"'" + _fileName + @"': line = @"'" + FileName + @"':
-------------------------------------------------- --------------------------------------------------
Uncompressed size: " + Style.GetBytesReadable(_totalSize) + @" Uncompressed size: " + Style.GetBytesReadable(TotalSize) + @"
Games found: " + (game == -1 ? Keys.Count() : game) + @" Games found: " + (game == -1 ? Keys.Count() : game) + @"
Roms found: " + _romCount + @" Roms found: " + RomCount + @"
Disks found: " + _diskCount + @" Disks found: " + DiskCount + @"
Roms with CRC: " + _crcCount + @" Roms with CRC: " + CRCCount + @"
Roms with SHA-1: " + _sha1Count + @" Roms with SHA-1: " + SHA1Count + @"
Roms with SHA-256: " + _sha256Count + @" Roms with SHA-256: " + SHA256Count + @"
Roms with SHA-384: " + _sha384Count + @" Roms with SHA-384: " + SHA384Count + @"
Roms with SHA-512: " + _sha512Count + "\n"; Roms with SHA-512: " + SHA512Count + "\n";
if (baddumpCol) if (baddumpCol)
{ {
line += " Roms with BadDump status: " + _baddumpCount + "\n"; line += " Roms with BadDump status: " + BaddumpCount + "\n";
} }
if (nodumpCol) if (nodumpCol)
{ {
line += " Roms with Nodump status: " + _nodumpCount + "\n"; line += " Roms with Nodump status: " + NodumpCount + "\n";
} }
// For spacing between DATs // For spacing between DATs
@@ -271,25 +138,25 @@ namespace SabreTools.Library.Dats
} }
if (outputs.ContainsKey(StatDatFormat.CSV)) if (outputs.ContainsKey(StatDatFormat.CSV))
{ {
line = "\"" + _fileName + "\"," line = "\"" + FileName + "\","
+ "\"" + _totalSize + "\"," + "\"" + TotalSize + "\","
+ "\"" + (game == -1 ? Keys.Count() : game) + "\"," + "\"" + (game == -1 ? Keys.Count() : game) + "\","
+ "\"" + _romCount + "\"," + "\"" + RomCount + "\","
+ "\"" + _diskCount + "\"," + "\"" + DiskCount + "\","
+ "\"" + _crcCount + "\"," + "\"" + CRCCount + "\","
+ "\"" + _md5Count + "\"," + "\"" + MD5Count + "\","
+ "\"" + _sha1Count + "\"," + "\"" + SHA1Count + "\","
+ "\"" + _sha256Count + "\"," + "\"" + SHA256Count + "\","
+ "\"" + _sha384Count + "\"," + "\"" + SHA384Count + "\","
+ "\"" + _sha512Count + "\""; + "\"" + SHA512Count + "\"";
if (baddumpCol) if (baddumpCol)
{ {
line += ",\"" + _baddumpCount + "\""; line += ",\"" + BaddumpCount + "\"";
} }
if (nodumpCol) if (nodumpCol)
{ {
line += ",\"" + _nodumpCount + "\""; line += ",\"" + NodumpCount + "\"";
} }
line += "\n"; line += "\n";
@@ -297,25 +164,25 @@ namespace SabreTools.Library.Dats
} }
if (outputs.ContainsKey(StatDatFormat.HTML)) if (outputs.ContainsKey(StatDatFormat.HTML))
{ {
line = "\t\t\t<tr" + (_fileName.StartsWith("DIR: ") line = "\t\t\t<tr" + (FileName.StartsWith("DIR: ")
? " class=\"dir\"><td>" + HttpUtility.HtmlEncode(_fileName.Remove(0, 5)) ? " class=\"dir\"><td>" + HttpUtility.HtmlEncode(FileName.Remove(0, 5))
: "><td>" + HttpUtility.HtmlEncode(_fileName)) + "</td>" : "><td>" + HttpUtility.HtmlEncode(FileName)) + "</td>"
+ "<td align=\"right\">" + Style.GetBytesReadable(_totalSize) + "</td>" + "<td align=\"right\">" + Style.GetBytesReadable(TotalSize) + "</td>"
+ "<td align=\"right\">" + (game == -1 ? Keys.Count() : game) + "</td>" + "<td align=\"right\">" + (game == -1 ? Keys.Count() : game) + "</td>"
+ "<td align=\"right\">" + _romCount + "</td>" + "<td align=\"right\">" + RomCount + "</td>"
+ "<td align=\"right\">" + _diskCount + "</td>" + "<td align=\"right\">" + DiskCount + "</td>"
+ "<td align=\"right\">" + _crcCount + "</td>" + "<td align=\"right\">" + CRCCount + "</td>"
+ "<td align=\"right\">" + _md5Count + "</td>" + "<td align=\"right\">" + MD5Count + "</td>"
+ "<td align=\"right\">" + _sha1Count + "</td>" + "<td align=\"right\">" + SHA1Count + "</td>"
+ "<td align=\"right\">" + _sha256Count + "</td>"; + "<td align=\"right\">" + SHA256Count + "</td>";
if (baddumpCol) if (baddumpCol)
{ {
line += "<td align=\"right\">" + _baddumpCount + "</td>"; line += "<td align=\"right\">" + BaddumpCount + "</td>";
} }
if (nodumpCol) if (nodumpCol)
{ {
line += "<td align=\"right\">" + _nodumpCount + "</td>"; line += "<td align=\"right\">" + NodumpCount + "</td>";
} }
line += "</tr>\n"; line += "</tr>\n";
@@ -323,25 +190,25 @@ namespace SabreTools.Library.Dats
} }
if (outputs.ContainsKey(StatDatFormat.TSV)) if (outputs.ContainsKey(StatDatFormat.TSV))
{ {
line = "\"" + _fileName + "\"\t" line = "\"" + FileName + "\"\t"
+ "\"" + _totalSize + "\"\t" + "\"" + TotalSize + "\"\t"
+ "\"" + (game == -1 ? Keys.Count() : game) + "\"\t" + "\"" + (game == -1 ? Keys.Count() : game) + "\"\t"
+ "\"" + _romCount + "\"\t" + "\"" + RomCount + "\"\t"
+ "\"" + _diskCount + "\"\t" + "\"" + DiskCount + "\"\t"
+ "\"" + _crcCount + "\"\t" + "\"" + CRCCount + "\"\t"
+ "\"" + _md5Count + "\"\t" + "\"" + MD5Count + "\"\t"
+ "\"" + _sha1Count + "\"\t" + "\"" + SHA1Count + "\"\t"
+ "\"" + _sha256Count + "\"\t" + "\"" + SHA256Count + "\"\t"
+ "\"" + _sha384Count + "\"\t" + "\"" + SHA384Count + "\"\t"
+ "\"" + _sha512Count + "\""; + "\"" + SHA512Count + "\"";
if (baddumpCol) if (baddumpCol)
{ {
line += "\t\"" + _baddumpCount + "\""; line += "\t\"" + BaddumpCount + "\"";
} }
if (nodumpCol) if (nodumpCol)
{ {
line += "\t\"" + _nodumpCount + "\""; line += "\t\"" + NodumpCount + "\"";
} }
line += "\n"; line += "\n";
@@ -417,35 +284,15 @@ namespace SabreTools.Library.Dats
OutputStatsWriteHeader(outputs, statDatFormat, baddumpCol, nodumpCol); OutputStatsWriteHeader(outputs, statDatFormat, baddumpCol, nodumpCol);
// Init all total variables // Init all total variables
long totalSize = 0; DatStats totalStats = new DatStats();
long totalGame = 0; long totalGame = 0;
long totalRom = 0;
long totalDisk = 0;
long totalCRC = 0;
long totalMD5 = 0;
long totalSHA1 = 0;
long totalSHA256 = 0;
long totalSHA384 = 0;
long totalSHA512 = 0;
long totalBaddump = 0;
long totalNodump = 0;
// Init directory-level variables // Init directory-level variables
string lastdir = null; string lastdir = null;
string basepath = null; string basepath = null;
long dirSize = 0; DatStats dirStats = new DatStats();
long dirGame = 0; long dirGame = 0;
long dirRom = 0;
long dirDisk = 0;
long dirCRC = 0;
long dirMD5 = 0;
long dirSHA1 = 0;
long dirSHA256 = 0;
long dirSHA384 = 0;
long dirSHA512 = 0;
long dirBaddump = 0;
long dirNodump = 0;
// Now process each of the input files // Now process each of the input files
foreach (Tuple<string, string> filename in newinputs) foreach (Tuple<string, string> filename in newinputs)
{ {
@@ -461,19 +308,10 @@ namespace SabreTools.Library.Dats
DatFile lastdirdat = new DatFile DatFile lastdirdat = new DatFile
{ {
_fileName = "DIR: " + HttpUtility.HtmlEncode(lastdir.Remove(0, basepath.Length + (basepath.Length == 0 ? 0 : 1))), FileName = "DIR: " + HttpUtility.HtmlEncode(lastdir.Remove(0, basepath.Length + (basepath.Length == 0 ? 0 : 1))),
_totalSize = dirSize, _datStats = dirStats,
_romCount = dirRom,
_diskCount = dirDisk,
_crcCount = dirCRC,
_md5Count = dirMD5,
_sha1Count = dirSHA1,
_sha256Count = dirSHA256,
_sha384Count = dirSHA384,
_sha512Count = dirSHA512,
_baddumpCount = dirBaddump,
_nodumpCount = dirNodump,
}; };
lastdirdat.OutputStats(outputs, statDatFormat, lastdirdat.OutputStats(outputs, statDatFormat,
game: dirGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol); game: dirGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol);
@@ -484,18 +322,8 @@ namespace SabreTools.Library.Dats
OutputStatsWriteMidHeader(outputs, statDatFormat, baddumpCol, nodumpCol); OutputStatsWriteMidHeader(outputs, statDatFormat, baddumpCol, nodumpCol);
// Reset the directory stats // Reset the directory stats
dirSize = 0; dirStats.Reset();
dirGame = 0; dirGame = 0;
dirRom = 0;
dirDisk = 0;
dirCRC = 0;
dirMD5 = 0;
dirSHA1 = 0;
dirSHA256 = 0;
dirSHA384 = 0;
dirSHA512 = 0;
dirBaddump = 0;
dirNodump = 0;
} }
Globals.Logger.Verbose("Beginning stat collection for '{0}'", false, filename.Item1); Globals.Logger.Verbose("Beginning stat collection for '{0}'", false, filename.Item1);
@@ -513,32 +341,12 @@ namespace SabreTools.Library.Dats
} }
// Add single DAT stats to dir // Add single DAT stats to dir
dirSize += datdata.TotalSize; dirStats.AddStats(datdata._datStats);
dirGame += datdata.Keys.Count(); dirGame += datdata.Keys.Count();
dirRom += datdata.RomCount;
dirDisk += datdata.DiskCount;
dirCRC += datdata.CRCCount;
dirMD5 += datdata.MD5Count;
dirSHA1 += datdata.SHA1Count;
dirSHA256 += datdata.SHA256Count;
dirSHA384 += datdata.SHA384Count;
dirSHA512 += datdata.SHA512Count;
dirBaddump += datdata.BaddumpCount;
dirNodump += datdata.NodumpCount;
// Add single DAT stats to totals // Add single DAT stats to totals
totalSize += datdata.TotalSize; totalStats.AddStats(datdata._datStats);
totalGame += datdata.Keys.Count(); totalGame += datdata.Keys.Count();
totalRom += datdata.RomCount;
totalDisk += datdata.DiskCount;
totalCRC += datdata.CRCCount;
totalMD5 += datdata.MD5Count;
totalSHA1 += datdata.SHA1Count;
totalSHA256 += datdata.SHA256Count;
totalSHA384 += datdata.SHA384Count;
totalSHA512 += datdata.SHA512Count;
totalBaddump += datdata.BaddumpCount;
totalNodump += datdata.NodumpCount;
// Make sure to assign the new directory // Make sure to assign the new directory
lastdir = thisdir; lastdir = thisdir;
@@ -551,19 +359,10 @@ namespace SabreTools.Library.Dats
{ {
DatFile dirdat = new DatFile DatFile dirdat = new DatFile
{ {
_fileName = "DIR: " + HttpUtility.HtmlEncode(lastdir.Remove(0, basepath.Length + (basepath.Length == 0 ? 0 : 1))), FileName = "DIR: " + HttpUtility.HtmlEncode(lastdir.Remove(0, basepath.Length + (basepath.Length == 0 ? 0 : 1))),
_totalSize = dirSize, _datStats = dirStats,
_romCount = dirRom,
_diskCount = dirDisk,
_crcCount = dirCRC,
_md5Count = dirMD5,
_sha1Count = dirSHA1,
_sha256Count = dirSHA256,
_sha384Count = dirSHA384,
_sha512Count = dirSHA512,
_baddumpCount = dirBaddump,
_nodumpCount = dirNodump,
}; };
dirdat.OutputStats(outputs, statDatFormat, dirdat.OutputStats(outputs, statDatFormat,
game: dirGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol); game: dirGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol);
} }
@@ -575,34 +374,16 @@ namespace SabreTools.Library.Dats
OutputStatsWriteMidHeader(outputs, statDatFormat, baddumpCol, nodumpCol); OutputStatsWriteMidHeader(outputs, statDatFormat, baddumpCol, nodumpCol);
// Reset the directory stats // Reset the directory stats
dirSize = 0; dirStats.Reset();
dirGame = 0; dirGame = 0;
dirRom = 0;
dirDisk = 0;
dirCRC = 0;
dirMD5 = 0;
dirSHA1 = 0;
dirSHA256 = 0;
dirSHA384 = 0;
dirSHA512 = 0;
dirNodump = 0;
// Output total DAT stats // Output total DAT stats
DatFile totaldata = new DatFile DatFile totaldata = new DatFile
{ {
_fileName = "DIR: All DATs", FileName = "DIR: All DATs",
_totalSize = totalSize, _datStats = totalStats,
_romCount = totalRom,
_diskCount = totalDisk,
_crcCount = totalCRC,
_md5Count = totalMD5,
_sha1Count = totalSHA1,
_sha256Count = totalSHA256,
_sha384Count = totalSHA384,
_sha512Count = totalSHA512,
_baddumpCount = totalBaddump,
_nodumpCount = totalNodump,
}; };
totaldata.OutputStats(outputs, statDatFormat, totaldata.OutputStats(outputs, statDatFormat,
game: totalGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol); game: totalGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol);

View File

@@ -125,7 +125,7 @@ namespace SabreTools.Library.Dats
// TODO: Create 1G1R logic before write // TODO: Create 1G1R logic before write
// If we are removing hashes, do that now // If we are removing hashes, do that now
if (_stripHash != 0x0) if (StripHash != 0x0)
{ {
StripHashesFromItems(); StripHashesFromItems();
} }