mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Output, Stats] Make stat output on write optional, include optional recalculation too
This commit is contained in:
@@ -16,17 +16,21 @@ namespace SabreTools.Helper
|
||||
/// <param name="outDir">Set the output directory</param>
|
||||
/// <param name="logger">Logger object for console and/or file output</param>
|
||||
/// <param name="norename">True if games should only be compared on game and file name (default), false if system and source are counted</param>
|
||||
/// <param name="stats">True if DAT statistics should be output on write, false otherwise (default)</param>
|
||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||
/// <remarks>
|
||||
/// The following features have been requested for file output:
|
||||
/// - Have the ability to strip special (non-ASCII) characters from rom information
|
||||
/// - Add a flag for ignoring roms with blank sizes
|
||||
/// </remarks>
|
||||
public static bool WriteDatfile(DatData datdata, string outDir, Logger logger, bool norename = true)
|
||||
public static bool WriteDatfile(DatData datdata, string outDir, Logger logger, bool norename = true, bool stats = false)
|
||||
{
|
||||
// Output initial statistics, for kicks
|
||||
Stats.OutputStats(datdata, logger);
|
||||
|
||||
if (stats)
|
||||
{
|
||||
Stats.OutputStats(datdata, logger, (datdata.RomCount + datdata.DiskCount == 0));
|
||||
}
|
||||
|
||||
// Bucket roms by game name and optionally dedupe
|
||||
SortedDictionary<string, List<RomData>> sortable = RomManipulation.BucketByGame(datdata.Roms, datdata.MergeRoms, norename, logger);
|
||||
|
||||
|
||||
@@ -102,8 +102,36 @@ Please check the log folder if the stats scrolled offscreen");
|
||||
/// </summary>
|
||||
/// <param name="datdata">DatData object to read stats from</param>
|
||||
/// <param name="logger">Logger object for file and console writing</param>
|
||||
public static void OutputStats(DatData datdata, Logger logger)
|
||||
/// <param name="recalculate">True if numbers should be recalculated for the DAT, false otherwise (default)</param>
|
||||
public static void OutputStats(DatData datdata, Logger logger, bool recalculate = false)
|
||||
{
|
||||
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
|
||||
foreach (List<RomData> roms in datdata.Roms.Values)
|
||||
{
|
||||
foreach (RomData rom in roms)
|
||||
{
|
||||
datdata.RomCount += (rom.Type == "rom" ? 1 : 0);
|
||||
datdata.DiskCount += (rom.Type == "disk" ? 1 : 0);
|
||||
datdata.TotalSize += rom.Size;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SortedDictionary<string, List<RomData>> newroms = RomManipulation.BucketByGame(datdata.Roms, false, true, logger);
|
||||
logger.User(@" Uncompressed size: " + Style.GetBytesReadable(datdata.TotalSize) + @"
|
||||
Games found: " + newroms.Count + @"
|
||||
|
||||
Reference in New Issue
Block a user