From 1d6f8b3f44087d5c5fc6534154cdf7b711dcd1ec Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 26 Sep 2016 15:26:32 -0700 Subject: [PATCH] [DatFile] Make stats output look way better, especially HTML --- SabreTools.Helper/Objects/Dat/DatFile.cs | 195 ++++++++++++++++++++++- 1 file changed, 191 insertions(+), 4 deletions(-) diff --git a/SabreTools.Helper/Objects/Dat/DatFile.cs b/SabreTools.Helper/Objects/Dat/DatFile.cs index b1c03e74..f43c5d14 100644 --- a/SabreTools.Helper/Objects/Dat/DatFile.cs +++ b/SabreTools.Helper/Objects/Dat/DatFile.cs @@ -5133,7 +5133,10 @@ namespace SabreTools.Helper } } } - newinputs.Sort(new NaturalComparer()); + newinputs = newinputs + .OrderBy(i => Path.GetDirectoryName(i)) + .ThenBy(i => Path.GetFileName(i)) + .ToList(); // newinputs.Sort(new NaturalComparer()) // Write the header, if any string head = ""; @@ -5172,9 +5175,110 @@ namespace SabreTools.Helper long totalSHA1 = 0; long totalNodump = 0; - /// Now process each of the input files + // Init directory-level variables + string lastdir = null; + long dirSize = 0; + long dirGame = 0; + long dirRom = 0; + long dirDisk = 0; + long dirCRC = 0; + long dirMD5 = 0; + long dirSHA1 = 0; + long dirNodump = 0; + + // Now process each of the input files foreach (string filename in newinputs) { + // Get the directory for the current file + string thisdir = Path.GetDirectoryName(filename); + + // If we don't have the first file and the directory has changed, show the previous directory stats and reset + if (lastdir != null && thisdir != lastdir) + { + // Output separator if needed + string imid = ""; + switch (statOutputFormat) + { + case StatOutputFormat.CSV: + break; + case StatOutputFormat.HTML: + imid = "\n"; + break; + case StatOutputFormat.None: + default: + break; + } + sw.Write(imid); + + DatFile lastdirdat = new DatFile + { + FileName = lastdir, + TotalSize = dirSize, + RomCount = dirRom, + DiskCount = dirDisk, + CRCCount = dirCRC, + MD5Count = dirMD5, + SHA1Count = dirSHA1, + NodumpCount = dirNodump, + }; + lastdirdat.OutputStats(sw, statOutputFormat, logger, game: dirGame); + + // Write the footer, if any + string iend = ""; + switch (statOutputFormat) + { + case StatOutputFormat.CSV: + break; + case StatOutputFormat.HTML: + iend = @" +

"; + break; + case StatOutputFormat.None: + default: + break; + case StatOutputFormat.TSV: + break; + } + sw.Write(iend); + + // Write the header, if any + string ihead = ""; + switch (statOutputFormat) + { + case StatOutputFormat.CSV: + ihead = "\"File Name\",\"Total Size\",\"Games\",\"Roms\",\"Disks\",\"# with CRC\",\"# with MD5\",\"# with SHA-1\",\"Nodumps\"\n"; + break; + case StatOutputFormat.HTML: + ihead = @" + +

+ DAT Statistics Report +
+ + + " + + "\n"; + break; + case StatOutputFormat.None: + default: + break; + case StatOutputFormat.TSV: + ihead = "\"File Name\"\t\"Total Size\"\t\"Games\"\t\"Roms\"\t\"Disks\"\t\"# with CRC\"\t\"# with MD5\"\t\"# with SHA-1\"\t\"Nodumps\"\n"; + break; + } + sw.Write(ihead); + + // Reset the directory stats + dirSize = 0; + dirGame = 0; + dirRom = 0; + dirDisk = 0; + dirCRC = 0; + dirMD5 = 0; + dirSHA1 = 0; + dirNodump = 0; + } + logger.Verbose("Beginning stat collection for '" + filename + "'", false); List games = new List(); DatFile datdata = new DatFile(); @@ -5188,6 +5292,16 @@ namespace SabreTools.Helper datdata.OutputStats(sw, statOutputFormat, logger); } + // Add single DAT stats to dir + dirSize += datdata.TotalSize; + dirGame += datdata.Files.Count; + dirRom += datdata.RomCount; + dirDisk += datdata.DiskCount; + dirCRC += datdata.CRCCount; + dirMD5 += datdata.MD5Count; + dirSHA1 += datdata.SHA1Count; + dirNodump += datdata.NodumpCount; + // Add single DAT stats to totals totalSize += datdata.TotalSize; totalGame += datdata.Files.Count; @@ -5197,9 +5311,12 @@ namespace SabreTools.Helper totalMD5 += datdata.MD5Count; totalSHA1 += datdata.SHA1Count; totalNodump += datdata.NodumpCount; + + // Make sure to assign the new directory + lastdir = thisdir; } - // Output midpoint separator if needed + // Output the directory stats one last time string mid = ""; switch (statOutputFormat) { @@ -5214,6 +5331,74 @@ namespace SabreTools.Helper } sw.Write(mid); + DatFile dirdat = new DatFile + { + FileName = lastdir, + TotalSize = dirSize, + RomCount = dirRom, + DiskCount = dirDisk, + CRCCount = dirCRC, + MD5Count = dirMD5, + SHA1Count = dirSHA1, + NodumpCount = dirNodump, + }; + dirdat.OutputStats(sw, statOutputFormat, logger, game: dirGame); + + // Write the footer, if any + string end = ""; + switch (statOutputFormat) + { + case StatOutputFormat.CSV: + break; + case StatOutputFormat.HTML: + end = @"
File NameTotal SizeGamesRomsDisks# with CRC# with MD5# with SHA-1Nodumps
+

"; + break; + case StatOutputFormat.None: + default: + break; + case StatOutputFormat.TSV: + break; + } + sw.Write(end); + + // Write the header, if any + head = ""; + switch (statOutputFormat) + { + case StatOutputFormat.CSV: + head = "\"File Name\",\"Total Size\",\"Games\",\"Roms\",\"Disks\",\"# with CRC\",\"# with MD5\",\"# with SHA-1\",\"Nodumps\"\n"; + break; + case StatOutputFormat.HTML: + head = @" + +

+ DAT Statistics Report +
+ + + " ++ "\n"; + break; + case StatOutputFormat.None: + default: + break; + case StatOutputFormat.TSV: + head = "\"File Name\"\t\"Total Size\"\t\"Games\"\t\"Roms\"\t\"Disks\"\t\"# with CRC\"\t\"# with MD5\"\t\"# with SHA-1\"\t\"Nodumps\"\n"; + break; + } + sw.Write(head); + + // Reset the directory stats + dirSize = 0; + dirGame = 0; + dirRom = 0; + dirDisk = 0; + dirCRC = 0; + dirMD5 = 0; + dirSHA1 = 0; + dirNodump = 0; + // Output total DAT stats DatFile totaldata = new DatFile { @@ -5229,7 +5414,7 @@ namespace SabreTools.Helper totaldata.OutputStats(sw, statOutputFormat, logger, game: totalGame); // Output footer if needed - string end = ""; + end = ""; switch (statOutputFormat) { case StatOutputFormat.CSV: @@ -5243,6 +5428,8 @@ namespace SabreTools.Helper case StatOutputFormat.None: default: break; + case StatOutputFormat.TSV: + break; } sw.Write(end);
File NameTotal SizeGamesRomsDisks# with CRC# with MD5# with SHA-1Nodumps