diff --git a/SabreTools.Library/Dats/DatFile.cs b/SabreTools.Library/Dats/DatFile.cs index 484fb52c..debf923b 100644 --- a/SabreTools.Library/Dats/DatFile.cs +++ b/SabreTools.Library/Dats/DatFile.cs @@ -10,58 +10,15 @@ namespace SabreTools.Library.Dats { #region Private instance variables - // Data common to most DAT types - private string _fileName; - private string _name; - private string _description; - 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 _regions = new List(); + // Internal DatHeader values + private DatHeader _datHeader = new DatHeader(); + + // DatItems dictionary private SortedDictionary> _items = new SortedDictionary>(); private SortedBy _sortedBy; - // Data specific to the Miss DAT type - private bool _useGame; - 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; + // Internal statistical data + DatStats _datStats = new DatStats(); #endregion @@ -70,118 +27,118 @@ namespace SabreTools.Library.Dats // Data common to most DAT types public string FileName { - get { return _fileName; } - set { _fileName = value; } + get { return _datHeader.FileName; } + set { _datHeader.FileName = value; } } public string Name { - get { return _name; } - set { _name = value; } + get { return _datHeader.Name; } + set { _datHeader.Name = value; } } public string Description { - get { return _description; } - set { _description = value; } + get { return _datHeader.Description; } + set { _datHeader.Description = value; } } public string RootDir { - get { return _rootDir; } - set { _rootDir = value; } + get { return _datHeader.RootDir; } + set { _datHeader.RootDir = value; } } public string Category { - get { return _category; } - set { _category = value; } + get { return _datHeader.Category; } + set { _datHeader.Category = value; } } public string Version { - get { return _version; } - set { _version = value; } + get { return _datHeader.Version; } + set { _datHeader.Version = value; } } public string Date { - get { return _date; } - set { _date = value; } + get { return _datHeader.Date; } + set { _datHeader.Date = value; } } public string Author { - get { return _author; } - set { _author = value; } + get { return _datHeader.Author; } + set { _datHeader.Author = value; } } public string Email { - get { return _email; } - set { _email = value; } + get { return _datHeader.Email; } + set { _datHeader.Email = value; } } public string Homepage { - get { return _homepage; } - set { _homepage = value; } + get { return _datHeader.Homepage; } + set { _datHeader.Homepage = value; } } public string Url { - get { return _url; } - set { _url = value; } + get { return _datHeader.Url; } + set { _datHeader.Url = value; } } public string Comment { - get { return _comment; } - set { _comment = value; } + get { return _datHeader.Comment; } + set { _datHeader.Comment = value; } } public string Header { - get { return _header; } - set { _header = value; } + get { return _datHeader.Header; } + set { _datHeader.Header = value; } } public string Type // Generally only used for SuperDAT { - get { return _type; } - set { _type = value; } + get { return _datHeader.Type; } + set { _datHeader.Type = value; } } public ForceMerging ForceMerging { - get { return _forceMerging; } - set { _forceMerging = value; } + get { return _datHeader.ForceMerging; } + set { _datHeader.ForceMerging = value; } } public ForceNodump ForceNodump { - get { return _forceNodump; } - set { _forceNodump = value; } + get { return _datHeader.ForceNodump; } + set { _datHeader.ForceNodump = value; } } public ForcePacking ForcePacking { - get { return _forcePacking; } - set { _forcePacking = value; } + get { return _datHeader.ForcePacking; } + set { _datHeader.ForcePacking = value; } } public DatFormat DatFormat { - get { return _datFormat; } - set { _datFormat = value; } + get { return _datHeader.DatFormat; } + set { _datHeader.DatFormat = value; } } public bool ExcludeOf { - get { return _excludeOf; } - set { _excludeOf = value; } + get { return _datHeader.ExcludeOf; } + set { _datHeader.ExcludeOf = value; } } public DedupeType DedupeRoms { - get { return _dedupeRoms; } - set { _dedupeRoms = value; } + get { return _datHeader.DedupeRoms; } + set { _datHeader.DedupeRoms = value; } } public Hash StripHash { - get { return _stripHash; } - set { _stripHash = value; } + get { return _datHeader.StripHash; } + set { _datHeader.StripHash = value; } } public bool OneGameOneRegion { - get { return _oneGameOneRegion; } - set { _oneGameOneRegion = value; } + get { return _datHeader.OneGameOneRegion; } + set { _datHeader.OneGameOneRegion = value; } } public List Regions { - get { return _regions; } - set { _regions = value; } + get { return _datHeader.Regions; } + set { _datHeader.Regions = value; } } public SortedBy SortedBy { @@ -191,98 +148,140 @@ namespace SabreTools.Library.Dats // Data specific to the Miss DAT type public bool UseGame { - get { return _useGame; } - set { _useGame = value; } + get { return _datHeader.UseGame; } + set { _datHeader.UseGame = value; } } public string Prefix { - get { return _prefix; } - set { _prefix = value; } + get { return _datHeader.Prefix; } + set { _datHeader.Prefix = value; } } public string Postfix { - get { return _postfix; } - set { _postfix = value; } + get { return _datHeader.Postfix; } + set { _datHeader.Postfix = value; } } public bool Quotes { - get { return _quotes; } - set { _quotes = value; } + get { return _datHeader.Quotes; } + set { _datHeader.Quotes = value; } } public string RepExt { - get { return _repExt; } - set { _repExt = value; } + get { return _datHeader.RepExt; } + set { _datHeader.RepExt = value; } } public string AddExt { - get { return _addExt; } - set { _addExt = value; } + get { return _datHeader.AddExt; } + set { _datHeader.AddExt = value; } } public bool RemExt { - get { return _remExt; } - set { _remExt = value; } + get { return _datHeader.RemExt; } + set { _datHeader.RemExt = value; } } public bool GameName { - get { return _gameName; } - set { _gameName = value; } + get { return _datHeader.GameName; } + set { _datHeader.GameName = value; } } public bool Romba { - get { return _romba; } - set { _romba = value; } + get { return _datHeader.Romba; } + set { _datHeader.Romba = value; } } // Statistical data related to the DAT 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 { - 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 { - get { return _totalSize; } + get { return _datStats.TotalSize; } + private set { _datStats.TotalSize = value; } } public long CRCCount { - get { return _crcCount; } + get { return _datStats.CRCCount; } + private set { _datStats.CRCCount = value; } } public long MD5Count { - get { return _md5Count; } + get { return _datStats.MD5Count; } + private set { _datStats.MD5Count = value; } } public long SHA1Count { - get { return _sha1Count; } + get { return _datStats.SHA1Count; } + private set { _datStats.SHA1Count = value; } } public long SHA256Count { - get { return _sha256Count; } + get { return _datStats.SHA256Count; } + private set { _datStats.SHA256Count = value; } } public long SHA384Count { - get { return _sha384Count; } + get { return _datStats.SHA384Count; } + private set { _datStats.SHA384Count = value; } } public long SHA512Count { - get { return _sha512Count; } + get { return _datStats.SHA512Count; } + private set { _datStats.SHA512Count = value; } } 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 { - 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 @@ -364,7 +363,7 @@ namespace SabreTools.Library.Dats _items[key].Add(value); // Now update the statistics - AddItemStatistics(value); + _datStats.AddItem(value); } } @@ -392,7 +391,7 @@ namespace SabreTools.Library.Dats // Now update the statistics foreach (DatItem item in value) { - AddItemStatistics(item); + _datStats.AddItem(item); } } } @@ -503,7 +502,7 @@ namespace SabreTools.Library.Dats // Remove the statistics first foreach (DatItem item in _items[key]) { - RemoveItemStatistics(item); + _datStats.RemoveItem(item); } // Remove the key from the dictionary @@ -536,7 +535,7 @@ namespace SabreTools.Library.Dats while (_items.ContainsKey(key) && _items[key].Contains(value)) { // Remove the statistics first - RemoveItemStatistics(value); + _datStats.RemoveItem(value); _items[key].Remove(value); } @@ -569,42 +568,12 @@ namespace SabreTools.Library.Dats } /// - /// Create a new DatFile from an existing one + /// Create a new DatFile from an existing one using the header values only /// /// public DatFile(DatFile datFile) { - _fileName = datFile.FileName; - _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; + _datHeader = (DatHeader)datFile._datHeader.Clone(); } #endregion @@ -653,7 +622,7 @@ namespace SabreTools.Library.Dats _items = null; // Reset statistics - ResetStatistics(); + _datStats.Reset(); } /// @@ -664,7 +633,7 @@ namespace SabreTools.Library.Dats _items = new SortedDictionary>(); // Reset statistics - ResetStatistics(); + _datStats.Reset(); } #endregion diff --git a/SabreTools.Library/Dats/Partials/DatFile.ConvertUpdate.cs b/SabreTools.Library/Dats/Partials/DatFile.ConvertUpdate.cs index 6c4713bf..a9144115 100644 --- a/SabreTools.Library/Dats/Partials/DatFile.ConvertUpdate.cs +++ b/SabreTools.Library/Dats/Partials/DatFile.ConvertUpdate.cs @@ -358,17 +358,17 @@ namespace SabreTools.Library.Dats DatFile dupeData = new DatFile(); // 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 diff --git a/SabreTools.Library/Dats/Partials/DatFile.Parsers.cs b/SabreTools.Library/Dats/Partials/DatFile.Parsers.cs index e884b7a0..617429e4 100644 --- a/SabreTools.Library/Dats/Partials/DatFile.Parsers.cs +++ b/SabreTools.Library/Dats/Partials/DatFile.Parsers.cs @@ -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 (useTags && splitType == SplitType.None) { - switch (_forceMerging) + switch (ForceMerging) { case ForceMerging.None: // No-op diff --git a/SabreTools.Library/Dats/Partials/DatFile.Rebuild.cs b/SabreTools.Library/Dats/Partials/DatFile.Rebuild.cs index 25a52c57..d777a6ae 100644 --- a/SabreTools.Library/Dats/Partials/DatFile.Rebuild.cs +++ b/SabreTools.Library/Dats/Partials/DatFile.Rebuild.cs @@ -205,9 +205,9 @@ namespace SabreTools.Library.Dats // If we're updating the DAT, output to the rebuild directory if (updateDat) { - _fileName = "fixDAT_" + _fileName; - _name = "fixDAT_" + _name; - _description = "fixDAT_" + _description; + FileName = "fixDAT_" + FileName; + Name = "fixDAT_" + Name; + Description = "fixDAT_" + Description; WriteToFile(outDir); } @@ -351,9 +351,9 @@ namespace SabreTools.Library.Dats // If we're updating the DAT, output to the rebuild directory if (updateDat) { - _fileName = "fixDAT_" + _fileName; - _name = "fixDAT_" + _name; - _description = "fixDAT_" + _description; + FileName = "fixDAT_" + FileName; + Name = "fixDAT_" + Name; + Description = "fixDAT_" + Description; WriteToFile(outDir); } @@ -937,9 +937,9 @@ namespace SabreTools.Library.Dats watch.Stop(); // If there are any entries in the DAT, output to the rebuild directory - _fileName = "fixDAT_" + _fileName; - _name = "fixDAT_" + _name; - _description = "fixDAT_" + _description; + FileName = "fixDAT_" + FileName; + Name = "fixDAT_" + Name; + Description = "fixDAT_" + Description; WriteToFile(null); return success; diff --git a/SabreTools.Library/Dats/Partials/DatFile.Statistics.cs b/SabreTools.Library/Dats/Partials/DatFile.Statistics.cs index 1786d495..55318093 100644 --- a/SabreTools.Library/Dats/Partials/DatFile.Statistics.cs +++ b/SabreTools.Library/Dats/Partials/DatFile.Statistics.cs @@ -28,146 +28,13 @@ namespace SabreTools.Library.Dats #region Statistics - /// - /// Add to the internal statistics given a DatItem - /// - /// Item to add info from - 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; - } - } - } - - /// - /// Remove from the internal statistics given a DatItem - /// - /// Item to remove info for - 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; - } - } - } - - /// - /// Reset all statistics - /// - 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; - } - /// /// Recalculate the statistics for the Dat /// public void RecalculateStats() { // Wipe out any stats already there - ResetStatistics(); + _datStats.Reset(); // If we have a blank Dat in any way, return if (this == null || Count == 0) @@ -182,7 +49,7 @@ namespace SabreTools.Library.Dats List items = this[key]; 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); - if (_totalSize < 0) + if (TotalSize < 0) { - _totalSize = Int64.MaxValue + _totalSize; + TotalSize = Int64.MaxValue + TotalSize; } // 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) + @" - Roms found: " + _romCount + @" - Disks found: " + _diskCount + @" - Roms with CRC: " + _crcCount + @" - Roms with MD5: " + _md5Count + @" - Roms with SHA-1: " + _sha1Count + @" - Roms with SHA-256: " + _sha256Count + @" - Roms with SHA-384: " + _sha384Count + @" - Roms with SHA-512: " + _sha512Count + "\n"; + Roms found: " + RomCount + @" + Disks found: " + DiskCount + @" + Roms with CRC: " + CRCCount + @" + Roms with MD5: " + MD5Count + @" + Roms with SHA-1: " + SHA1Count + @" + Roms with SHA-256: " + SHA256Count + @" + Roms with SHA-384: " + SHA384Count + @" + Roms with SHA-512: " + SHA512Count + "\n"; if (baddumpCol) { - results += " Roms with BadDump status: " + _baddumpCount + "\n"; + results += " Roms with BadDump status: " + BaddumpCount + "\n"; } if (nodumpCol) { - results += " Roms with Nodump status: " + _nodumpCount + "\n"; + results += " Roms with Nodump status: " + NodumpCount + "\n"; } // For spacing between DATs @@ -243,25 +110,25 @@ namespace SabreTools.Library.Dats string line = ""; 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) + @" - Roms found: " + _romCount + @" - Disks found: " + _diskCount + @" - Roms with CRC: " + _crcCount + @" - Roms with SHA-1: " + _sha1Count + @" - Roms with SHA-256: " + _sha256Count + @" - Roms with SHA-384: " + _sha384Count + @" - Roms with SHA-512: " + _sha512Count + "\n"; + Roms found: " + RomCount + @" + Disks found: " + DiskCount + @" + Roms with CRC: " + CRCCount + @" + Roms with SHA-1: " + SHA1Count + @" + Roms with SHA-256: " + SHA256Count + @" + Roms with SHA-384: " + SHA384Count + @" + Roms with SHA-512: " + SHA512Count + "\n"; if (baddumpCol) { - line += " Roms with BadDump status: " + _baddumpCount + "\n"; + line += " Roms with BadDump status: " + BaddumpCount + "\n"; } if (nodumpCol) { - line += " Roms with Nodump status: " + _nodumpCount + "\n"; + line += " Roms with Nodump status: " + NodumpCount + "\n"; } // For spacing between DATs @@ -271,25 +138,25 @@ namespace SabreTools.Library.Dats } if (outputs.ContainsKey(StatDatFormat.CSV)) { - line = "\"" + _fileName + "\"," - + "\"" + _totalSize + "\"," + line = "\"" + FileName + "\"," + + "\"" + TotalSize + "\"," + "\"" + (game == -1 ? Keys.Count() : game) + "\"," - + "\"" + _romCount + "\"," - + "\"" + _diskCount + "\"," - + "\"" + _crcCount + "\"," - + "\"" + _md5Count + "\"," - + "\"" + _sha1Count + "\"," - + "\"" + _sha256Count + "\"," - + "\"" + _sha384Count + "\"," - + "\"" + _sha512Count + "\""; + + "\"" + RomCount + "\"," + + "\"" + DiskCount + "\"," + + "\"" + CRCCount + "\"," + + "\"" + MD5Count + "\"," + + "\"" + SHA1Count + "\"," + + "\"" + SHA256Count + "\"," + + "\"" + SHA384Count + "\"," + + "\"" + SHA512Count + "\""; if (baddumpCol) { - line += ",\"" + _baddumpCount + "\""; + line += ",\"" + BaddumpCount + "\""; } if (nodumpCol) { - line += ",\"" + _nodumpCount + "\""; + line += ",\"" + NodumpCount + "\""; } line += "\n"; @@ -297,25 +164,25 @@ namespace SabreTools.Library.Dats } if (outputs.ContainsKey(StatDatFormat.HTML)) { - line = "\t\t\t" + HttpUtility.HtmlEncode(_fileName.Remove(0, 5)) - : ">" + HttpUtility.HtmlEncode(_fileName)) + "" - + "" + Style.GetBytesReadable(_totalSize) + "" + line = "\t\t\t" + HttpUtility.HtmlEncode(FileName.Remove(0, 5)) + : ">" + HttpUtility.HtmlEncode(FileName)) + "" + + "" + Style.GetBytesReadable(TotalSize) + "" + "" + (game == -1 ? Keys.Count() : game) + "" - + "" + _romCount + "" - + "" + _diskCount + "" - + "" + _crcCount + "" - + "" + _md5Count + "" - + "" + _sha1Count + "" - + "" + _sha256Count + ""; + + "" + RomCount + "" + + "" + DiskCount + "" + + "" + CRCCount + "" + + "" + MD5Count + "" + + "" + SHA1Count + "" + + "" + SHA256Count + ""; if (baddumpCol) { - line += "" + _baddumpCount + ""; + line += "" + BaddumpCount + ""; } if (nodumpCol) { - line += "" + _nodumpCount + ""; + line += "" + NodumpCount + ""; } line += "\n"; @@ -323,25 +190,25 @@ namespace SabreTools.Library.Dats } if (outputs.ContainsKey(StatDatFormat.TSV)) { - line = "\"" + _fileName + "\"\t" - + "\"" + _totalSize + "\"\t" + line = "\"" + FileName + "\"\t" + + "\"" + TotalSize + "\"\t" + "\"" + (game == -1 ? Keys.Count() : game) + "\"\t" - + "\"" + _romCount + "\"\t" - + "\"" + _diskCount + "\"\t" - + "\"" + _crcCount + "\"\t" - + "\"" + _md5Count + "\"\t" - + "\"" + _sha1Count + "\"\t" - + "\"" + _sha256Count + "\"\t" - + "\"" + _sha384Count + "\"\t" - + "\"" + _sha512Count + "\""; + + "\"" + RomCount + "\"\t" + + "\"" + DiskCount + "\"\t" + + "\"" + CRCCount + "\"\t" + + "\"" + MD5Count + "\"\t" + + "\"" + SHA1Count + "\"\t" + + "\"" + SHA256Count + "\"\t" + + "\"" + SHA384Count + "\"\t" + + "\"" + SHA512Count + "\""; if (baddumpCol) { - line += "\t\"" + _baddumpCount + "\""; + line += "\t\"" + BaddumpCount + "\""; } if (nodumpCol) { - line += "\t\"" + _nodumpCount + "\""; + line += "\t\"" + NodumpCount + "\""; } line += "\n"; @@ -417,35 +284,15 @@ namespace SabreTools.Library.Dats OutputStatsWriteHeader(outputs, statDatFormat, baddumpCol, nodumpCol); // Init all total variables - long totalSize = 0; + DatStats totalStats = new DatStats(); 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 string lastdir = null; string basepath = null; - long dirSize = 0; + DatStats dirStats = new DatStats(); 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 foreach (Tuple filename in newinputs) { @@ -461,19 +308,10 @@ namespace SabreTools.Library.Dats DatFile lastdirdat = new DatFile { - _fileName = "DIR: " + HttpUtility.HtmlEncode(lastdir.Remove(0, basepath.Length + (basepath.Length == 0 ? 0 : 1))), - _totalSize = dirSize, - _romCount = dirRom, - _diskCount = dirDisk, - _crcCount = dirCRC, - _md5Count = dirMD5, - _sha1Count = dirSHA1, - _sha256Count = dirSHA256, - _sha384Count = dirSHA384, - _sha512Count = dirSHA512, - _baddumpCount = dirBaddump, - _nodumpCount = dirNodump, + FileName = "DIR: " + HttpUtility.HtmlEncode(lastdir.Remove(0, basepath.Length + (basepath.Length == 0 ? 0 : 1))), + _datStats = dirStats, }; + lastdirdat.OutputStats(outputs, statDatFormat, game: dirGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol); @@ -484,18 +322,8 @@ namespace SabreTools.Library.Dats OutputStatsWriteMidHeader(outputs, statDatFormat, baddumpCol, nodumpCol); // Reset the directory stats - dirSize = 0; + dirStats.Reset(); 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); @@ -513,32 +341,12 @@ namespace SabreTools.Library.Dats } // Add single DAT stats to dir - dirSize += datdata.TotalSize; + dirStats.AddStats(datdata._datStats); 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 - totalSize += datdata.TotalSize; + totalStats.AddStats(datdata._datStats); 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 lastdir = thisdir; @@ -551,19 +359,10 @@ namespace SabreTools.Library.Dats { DatFile dirdat = new DatFile { - _fileName = "DIR: " + HttpUtility.HtmlEncode(lastdir.Remove(0, basepath.Length + (basepath.Length == 0 ? 0 : 1))), - _totalSize = dirSize, - _romCount = dirRom, - _diskCount = dirDisk, - _crcCount = dirCRC, - _md5Count = dirMD5, - _sha1Count = dirSHA1, - _sha256Count = dirSHA256, - _sha384Count = dirSHA384, - _sha512Count = dirSHA512, - _baddumpCount = dirBaddump, - _nodumpCount = dirNodump, + FileName = "DIR: " + HttpUtility.HtmlEncode(lastdir.Remove(0, basepath.Length + (basepath.Length == 0 ? 0 : 1))), + _datStats = dirStats, }; + dirdat.OutputStats(outputs, statDatFormat, game: dirGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol); } @@ -575,34 +374,16 @@ namespace SabreTools.Library.Dats OutputStatsWriteMidHeader(outputs, statDatFormat, baddumpCol, nodumpCol); // Reset the directory stats - dirSize = 0; + dirStats.Reset(); dirGame = 0; - dirRom = 0; - dirDisk = 0; - dirCRC = 0; - dirMD5 = 0; - dirSHA1 = 0; - dirSHA256 = 0; - dirSHA384 = 0; - dirSHA512 = 0; - dirNodump = 0; // Output total DAT stats DatFile totaldata = new DatFile { - _fileName = "DIR: All DATs", - _totalSize = totalSize, - _romCount = totalRom, - _diskCount = totalDisk, - _crcCount = totalCRC, - _md5Count = totalMD5, - _sha1Count = totalSHA1, - _sha256Count = totalSHA256, - _sha384Count = totalSHA384, - _sha512Count = totalSHA512, - _baddumpCount = totalBaddump, - _nodumpCount = totalNodump, + FileName = "DIR: All DATs", + _datStats = totalStats, }; + totaldata.OutputStats(outputs, statDatFormat, game: totalGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol); diff --git a/SabreTools.Library/Dats/Partials/DatFile.Writers.cs b/SabreTools.Library/Dats/Partials/DatFile.Writers.cs index a15c683d..a66b4b4e 100644 --- a/SabreTools.Library/Dats/Partials/DatFile.Writers.cs +++ b/SabreTools.Library/Dats/Partials/DatFile.Writers.cs @@ -125,7 +125,7 @@ namespace SabreTools.Library.Dats // TODO: Create 1G1R logic before write // If we are removing hashes, do that now - if (_stripHash != 0x0) + if (StripHash != 0x0) { StripHashesFromItems(); }