diff --git a/SabreHelper/Output.cs b/SabreHelper/Output.cs
index c35f9d14..2d1abfda 100644
--- a/SabreHelper/Output.cs
+++ b/SabreHelper/Output.cs
@@ -16,17 +16,21 @@ namespace SabreTools.Helper
/// Set the output directory
/// Logger object for console and/or file output
/// True if games should only be compared on game and file name (default), false if system and source are counted
+ /// True if DAT statistics should be output on write, false otherwise (default)
/// True if the DAT was written correctly, false otherwise
///
/// 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
///
- 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> sortable = RomManipulation.BucketByGame(datdata.Roms, datdata.MergeRoms, norename, logger);
diff --git a/SabreHelper/Stats.cs b/SabreHelper/Stats.cs
index 68209ca4..2afdb402 100644
--- a/SabreHelper/Stats.cs
+++ b/SabreHelper/Stats.cs
@@ -102,8 +102,36 @@ Please check the log folder if the stats scrolled offscreen");
///
/// DatData object to read stats from
/// Logger object for file and console writing
- public static void OutputStats(DatData datdata, Logger logger)
+ /// True if numbers should be recalculated for the DAT, false otherwise (default)
+ 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 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> newroms = RomManipulation.BucketByGame(datdata.Roms, false, true, logger);
logger.User(@" Uncompressed size: " + Style.GetBytesReadable(datdata.TotalSize) + @"
Games found: " + newroms.Count + @"