2016-05-26 23:55:46 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2016-05-04 17:14:11 -07:00
|
|
|
|
|
2016-06-13 23:54:13 -07:00
|
|
|
|
namespace SabreTools.Helper
|
2016-05-04 17:14:11 -07:00
|
|
|
|
{
|
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-04 17:14:11 -07:00
|
|
|
|
{
|
2016-05-27 09:28:33 -07:00
|
|
|
|
// Private instance variables
|
|
|
|
|
|
private List<String> _inputs;
|
|
|
|
|
|
private bool _single;
|
|
|
|
|
|
private Logger _logger;
|
2016-05-04 17:14:11 -07:00
|
|
|
|
|
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-04 17:14:11 -07:00
|
|
|
|
|
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)
|
2016-05-04 17:14:11 -07:00
|
|
|
|
{
|
2016-05-31 22:51:29 -07:00
|
|
|
|
_logger.User("Beginning stat collection for '" + filename + "'");
|
2016-05-26 23:55:46 -07:00
|
|
|
|
List<String> games = new List<String>();
|
2016-06-16 18:57:34 -07:00
|
|
|
|
Dat datdata = new Dat();
|
2016-06-11 15:08:24 -07:00
|
|
|
|
datdata = DatTools.Parse(filename, 0, 0, datdata, _logger);
|
2016-06-16 18:57:34 -07:00
|
|
|
|
SortedDictionary<string, List<Rom>> newroms = DatTools.BucketByGame(datdata.Roms, false, true, _logger, false);
|
2016-05-04 17:14:11 -07:00
|
|
|
|
|
2016-05-27 09:28:33 -07:00
|
|
|
|
// Output single DAT stats (if asked)
|
|
|
|
|
|
if (_single)
|
|
|
|
|
|
{
|
2016-05-31 23:34:19 -07:00
|
|
|
|
_logger.User(@"\nFor file '" + filename + @"':
|
2016-06-10 02:00:40 -07:00
|
|
|
|
--------------------------------------------------");
|
|
|
|
|
|
OutputStats(datdata, _logger);
|
2016-05-27 09:28:33 -07:00
|
|
|
|
}
|
2016-05-27 09:38:25 -07:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-06-12 21:52:27 -07:00
|
|
|
|
_logger.User("Adding stats for file '" + filename + "'\n");
|
2016-05-27 09:38:25 -07:00
|
|
|
|
}
|
2016-05-04 17:14:11 -07:00
|
|
|
|
|
2016-05-26 23:55:46 -07:00
|
|
|
|
// Add single DAT stats to totals
|
2016-05-31 23:34:19 -07:00
|
|
|
|
totalSize += datdata.TotalSize;
|
|
|
|
|
|
totalGame += newroms.Count;
|
|
|
|
|
|
totalRom += datdata.RomCount;
|
|
|
|
|
|
totalDisk += datdata.DiskCount;
|
|
|
|
|
|
totalCRC += datdata.CRCCount;
|
|
|
|
|
|
totalMD5 += datdata.MD5Count;
|
|
|
|
|
|
totalSHA1 += datdata.SHA1Count;
|
2016-05-31 23:47:37 -07:00
|
|
|
|
totalNodump += datdata.NodumpCount;
|
2016-05-04 17:14:11 -07:00
|
|
|
|
}
|
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-06-16 18:57:34 -07:00
|
|
|
|
Dat totaldata = new Dat
|
2016-06-10 02:00:40 -07:00
|
|
|
|
{
|
|
|
|
|
|
TotalSize = totalSize,
|
|
|
|
|
|
RomCount = totalRom,
|
|
|
|
|
|
DiskCount = totalDisk,
|
|
|
|
|
|
CRCCount = totalCRC,
|
|
|
|
|
|
MD5Count = totalMD5,
|
|
|
|
|
|
SHA1Count = totalSHA1,
|
|
|
|
|
|
NodumpCount = totalNodump,
|
|
|
|
|
|
};
|
2016-05-27 09:28:33 -07:00
|
|
|
|
_logger.User(@"For ALL DATs found
|
2016-06-10 02:00:40 -07:00
|
|
|
|
--------------------------------------------------");
|
2016-06-13 00:30:51 -07:00
|
|
|
|
OutputStats(totaldata, _logger, game:totalGame);
|
2016-06-10 02:00:40 -07:00
|
|
|
|
_logger.User(@"
|
2016-05-27 09:28:33 -07:00
|
|
|
|
Please check the log folder if the stats scrolled offscreen");
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
2016-05-04 17:14:11 -07:00
|
|
|
|
}
|
2016-06-10 02:00:40 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Output the stats in a human-readable format
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="datdata">DatData object to read stats from</param>
|
|
|
|
|
|
/// <param name="logger">Logger object for file and console writing</param>
|
2016-06-10 13:06:43 -07:00
|
|
|
|
/// <param name="recalculate">True if numbers should be recalculated for the DAT, false otherwise (default)</param>
|
2016-06-13 00:30:51 -07:00
|
|
|
|
/// <param name="game">Number of games to use, -1 means recalculate games (default)</param>
|
2016-06-16 18:57:34 -07:00
|
|
|
|
public static void OutputStats(Dat datdata, Logger logger, bool recalculate = false, long game = -1)
|
2016-06-10 02:00:40 -07:00
|
|
|
|
{
|
2016-06-10 13:06:43 -07:00
|
|
|
|
if (recalculate)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Wipe out any stats already there
|
|
|
|
|
|
datdata.RomCount = 0;
|
|
|
|
|
|
datdata.DiskCount = 0;
|
|
|
|
|
|
datdata.TotalSize = 0;
|
|
|
|
|
|
datdata.CRCCount = 0;
|
|
|
|
|
|
datdata.MD5Count = 0;
|
|
|
|
|
|
datdata.SHA1Count = 0;
|
|
|
|
|
|
datdata.NodumpCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Loop through and add
|
2016-06-16 18:57:34 -07:00
|
|
|
|
foreach (List<Rom> roms in datdata.Roms.Values)
|
2016-06-10 13:06:43 -07:00
|
|
|
|
{
|
2016-06-16 18:57:34 -07:00
|
|
|
|
foreach (Rom rom in roms)
|
2016-06-10 13:06:43 -07:00
|
|
|
|
{
|
|
|
|
|
|
datdata.RomCount += (rom.Type == "rom" ? 1 : 0);
|
|
|
|
|
|
datdata.DiskCount += (rom.Type == "disk" ? 1 : 0);
|
2016-06-13 00:37:23 -07:00
|
|
|
|
datdata.TotalSize += (rom.Nodump ? 0 : rom.Size);
|
2016-06-10 13:06:43 -07:00
|
|
|
|
datdata.CRCCount += (String.IsNullOrEmpty(rom.CRC) ? 0 : 1);
|
|
|
|
|
|
datdata.MD5Count += (String.IsNullOrEmpty(rom.MD5) ? 0 : 1);
|
|
|
|
|
|
datdata.SHA1Count += (String.IsNullOrEmpty(rom.SHA1) ? 0 : 1);
|
|
|
|
|
|
datdata.NodumpCount += (rom.Nodump ? 1 : 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-22 21:48:39 -07:00
|
|
|
|
SortedDictionary<string, List<Rom>> newroms = DatTools.BucketByGame(datdata.Roms, false, true, logger, false);
|
2016-06-22 22:01:29 -07:00
|
|
|
|
string line = " Uncompressed size: " + Style.GetBytesReadable(datdata.TotalSize);
|
2016-06-26 23:25:48 -07:00
|
|
|
|
logger.Log(line, Console.CursorTop, 0);
|
2016-06-22 22:01:29 -07:00
|
|
|
|
line = " Games found: " + (game == -1 ? newroms.Count : game);
|
2016-06-26 23:25:48 -07:00
|
|
|
|
logger.Log(line, Console.CursorTop + 1, 0);
|
2016-06-22 22:01:29 -07:00
|
|
|
|
line = " Roms found: " + datdata.RomCount;
|
2016-06-26 23:25:48 -07:00
|
|
|
|
logger.Log(line, Console.CursorTop + 1, 0);
|
2016-06-22 22:01:29 -07:00
|
|
|
|
line = " Disks found: " + datdata.DiskCount;
|
2016-06-26 23:25:48 -07:00
|
|
|
|
logger.Log(line, Console.CursorTop + 1, 0);
|
2016-06-22 22:01:29 -07:00
|
|
|
|
line = " Roms with CRC: " + datdata.CRCCount;
|
2016-06-26 23:25:48 -07:00
|
|
|
|
logger.Log(line, Console.CursorTop + 1, 0);
|
2016-06-22 22:01:29 -07:00
|
|
|
|
line = " Roms with MD5: " + datdata.MD5Count;
|
2016-06-26 23:25:48 -07:00
|
|
|
|
logger.Log(line, Console.CursorTop + 1, 0);
|
2016-06-22 22:01:29 -07:00
|
|
|
|
line = " Roms with SHA-1: " + datdata.SHA1Count;
|
2016-06-26 23:25:48 -07:00
|
|
|
|
logger.Log(line, Console.CursorTop + 1, 0);
|
2016-06-22 22:01:29 -07:00
|
|
|
|
line = " Roms with Nodump status: " + datdata.NodumpCount;
|
2016-06-26 23:25:48 -07:00
|
|
|
|
logger.Log(line, Console.CursorTop + 1, 0);
|
2016-06-22 22:01:29 -07:00
|
|
|
|
logger.User("");
|
2016-06-10 02:00:40 -07:00
|
|
|
|
}
|
2016-05-04 17:14:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|