Files
SabreTools/DATabase/Stats.cs

106 lines
3.2 KiB
C#
Raw Normal View History

2016-05-26 23:55:46 -07:00
using System;
using System.Collections.Generic;
using SabreTools.Helper;
namespace SabreTools
{
2016-05-27 09:28:33 -07:00
/// <summary>
/// Get statistics on one or more DAT files
/// </summary>
2016-05-27 09:38:25 -07:00
public class Stats
{
2016-05-27 09:28:33 -07:00
// Private instance variables
private List<String> _inputs;
private bool _single;
private Logger _logger;
2016-05-27 09:28:33 -07:00
/// <summary>
/// Create a new UncompressedSize object
/// </summary>
/// <param name="inputs">List of files and folders to parse</param>
/// <param name="single">True if single DAT stats are output, false otherwise</param>
/// <param name="logger">Logger object for file and console output</param>
2016-05-27 09:38:25 -07:00
public Stats(List<String> inputs, bool single, Logger logger)
2016-05-27 09:28:33 -07:00
{
_inputs = inputs;
_single = single;
_logger = logger;
}
2016-05-27 09:28:33 -07:00
/// <summary>
/// Output all requested statistics
/// </summary>
/// <returns>True if output succeeded, false otherwise</returns>
public bool Process()
{
2016-05-26 23:55:46 -07:00
// Init all total variables
long totalSize = 0;
long totalGame = 0;
long totalRom = 0;
long totalDisk = 0;
long totalCRC = 0;
long totalMD5 = 0;
long totalSHA1 = 0;
long totalNodump = 0;
2016-05-27 09:28:33 -07:00
/// Now process each of the input files
foreach (string filename in _inputs)
{
_logger.User("Beginning stat collection for '" + filename + "'");
2016-05-26 23:55:46 -07:00
List<String> games = new List<String>();
DatData datdata = new DatData();
2016-05-27 09:28:33 -07:00
datdata = RomManipulation.Parse(filename, 0, 0, datdata, _logger);
SortedDictionary<string, List<RomData>> newroms = RomManipulation.BucketByGame(datdata.Roms, false, true, _logger);
2016-05-27 09:28:33 -07:00
// Output single DAT stats (if asked)
if (_single)
{
_logger.User(@"\nFor file '" + filename + @"':
2016-05-26 23:55:46 -07:00
--------------------------------------------------
Uncompressed size: " + Style.GetBytesReadable(datdata.TotalSize) + @"
Games found: " + newroms.Count + @"
Roms found: " + datdata.RomCount + @"
Disks found: " + datdata.DiskCount + @"
Roms with CRC: " + datdata.CRCCount + @"
Roms with MD5: " + datdata.MD5Count + @"
Roms with SHA-1: " + datdata.SHA1Count + @"
Roms with Nodump status: " + datdata.NodumpCount + @"
2016-05-26 23:55:46 -07:00
");
2016-05-27 09:28:33 -07:00
}
2016-05-27 09:38:25 -07:00
else
{
_logger.User("\nAdding stats for file '" + filename + "'");
2016-05-27 09:38:25 -07:00
}
2016-05-26 23:55:46 -07:00
// Add single DAT stats to totals
totalSize += datdata.TotalSize;
totalGame += newroms.Count;
totalRom += datdata.RomCount;
totalDisk += datdata.DiskCount;
totalCRC += datdata.CRCCount;
totalMD5 += datdata.MD5Count;
totalSHA1 += datdata.SHA1Count;
totalNodump += datdata.SHA1Count;
}
2016-05-26 23:55:46 -07:00
// Output total DAT stats
2016-05-27 11:05:16 -07:00
if (!_single) { _logger.User(""); }
2016-05-27 09:28:33 -07:00
_logger.User(@"For ALL DATs found
2016-05-26 23:55:46 -07:00
--------------------------------------------------
Uncompressed size: " + Style.GetBytesReadable(totalSize) + @"
Games found: " + totalGame + @"
Roms found: " + totalRom + @"
Disks found: " + totalDisk + @"
Roms with CRC: " + totalCRC + @"
Roms with MD5: " + totalMD5 + @"
Roms with SHA-1: " + totalSHA1 + @"
Roms with Nodump status: " + totalNodump + @"
2016-05-27 09:28:33 -07:00
Please check the log folder if the stats scrolled offscreen");
return true;
}
}
}