diff --git a/SabreTools.Helper/Objects/Dat/DatFile.cs b/SabreTools.Helper/Objects/Dat/DatFile.cs index 6f4a35ba..46f56b4f 100644 --- a/SabreTools.Helper/Objects/Dat/DatFile.cs +++ b/SabreTools.Helper/Objects/Dat/DatFile.cs @@ -5171,24 +5171,24 @@ namespace SabreTools.Helper StreamWriter sw = new StreamWriter(File.Open(reportName, FileMode.Create, FileAccess.Write)); // Make sure we have all files - List newinputs = new List(); + List> newinputs = new List>(); // item, basepath foreach (string input in inputs) { if (File.Exists(input)) { - newinputs.Add(Path.GetFullPath(input)); + newinputs.Add(Tuple.Create(Path.GetFullPath(input), Path.GetDirectoryName(Path.GetFullPath(input)))); } if (Directory.Exists(input)) { foreach (string file in Directory.GetFiles(input, "*", SearchOption.AllDirectories)) { - newinputs.Add(Path.GetFullPath(file)); + newinputs.Add(Tuple.Create(Path.GetFullPath(file), Path.GetFullPath(input))); } } } newinputs = newinputs - .OrderBy(i => Path.GetDirectoryName(i)) - .ThenBy(i => Path.GetFileName(i)) + .OrderBy(i => Path.GetDirectoryName(i.Item1)) + .ThenBy(i => Path.GetFileName(i.Item1)) .ToList(); // Write the header, if any @@ -5207,6 +5207,7 @@ namespace SabreTools.Helper // Init directory-level variables string lastdir = null; + string basepath = null; long dirSize = 0; long dirGame = 0; long dirRom = 0; @@ -5218,10 +5219,11 @@ namespace SabreTools.Helper long dirNodump = 0; // Now process each of the input files - foreach (string filename in newinputs) + foreach (Tuple filename in newinputs) { // Get the directory for the current file - string thisdir = Path.GetDirectoryName(filename); + string thisdir = Path.GetDirectoryName(filename.Item1); + basepath = Path.GetDirectoryName(filename.Item2); // 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) @@ -5231,7 +5233,7 @@ namespace SabreTools.Helper DatFile lastdirdat = new DatFile { - FileName = lastdir, + FileName = lastdir.Remove(0, basepath.Length + (basepath.Length == 0 ? 0 : 1)), TotalSize = dirSize, RomCount = dirRom, DiskCount = dirDisk, @@ -5244,10 +5246,10 @@ namespace SabreTools.Helper lastdirdat.OutputStats(sw, statOutputFormat, logger, game: dirGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol); // Write the mid-footer, if any - OutputStatsWriteMidFooter(sw, statOutputFormat); + OutputStatsWriteMidFooter(sw, statOutputFormat, baddumpCol, nodumpCol); // Write the header, if any - OutputStatsWriteHeader(sw, statOutputFormat, baddumpCol, nodumpCol); + OutputStatsWriteMidHeader(sw, statOutputFormat, baddumpCol, nodumpCol); // Reset the directory stats dirSize = 0; @@ -5264,7 +5266,7 @@ namespace SabreTools.Helper logger.Verbose("Beginning stat collection for '" + filename + "'", false); List games = new List(); DatFile datdata = new DatFile(); - datdata.Parse(filename, 0, 0, logger); + datdata.Parse(filename.Item1, 0, 0, logger); datdata.BucketByGame(false, true, logger, false); // Output single DAT stats (if asked) @@ -5307,7 +5309,7 @@ namespace SabreTools.Helper { DatFile dirdat = new DatFile { - FileName = lastdir, + FileName = lastdir.Remove(0, basepath.Length + (basepath.Length == 0 ? 0 : 1)), TotalSize = dirSize, RomCount = dirRom, DiskCount = dirDisk, @@ -5321,10 +5323,10 @@ namespace SabreTools.Helper } // Write the mid-footer, if any - OutputStatsWriteMidFooter(sw, statOutputFormat); + OutputStatsWriteMidFooter(sw, statOutputFormat, baddumpCol, nodumpCol); // Write the header, if any - OutputStatsWriteHeader(sw, statOutputFormat, baddumpCol, nodumpCol); + OutputStatsWriteMidHeader(sw, statOutputFormat, baddumpCol, nodumpCol); // Reset the directory stats dirSize = 0; @@ -5349,7 +5351,7 @@ namespace SabreTools.Helper BaddumpCount = totalBaddump, NodumpCount = totalNodump, }; - totaldata.OutputStats(sw, statOutputFormat, logger, game: totalGame); + totaldata.OutputStats(sw, statOutputFormat, logger, game: totalGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol); // Output footer if needed OutputStatsWriteFooter(sw, statOutputFormat); @@ -5401,8 +5403,6 @@ Please check the log folder if the stats scrolled offscreen", false); switch (statOutputFormat) { case StatOutputFormat.CSV: - head = "\"File Name\",\"Total Size\",\"Games\",\"Roms\",\"Disks\",\"# with CRC\",\"# with MD5\",\"# with SHA-1\"" - + (baddumpCol ? ",\"BadDumps\"" : "") + (nodumpCol ? ",\"Nodumps\"" : "") + "\n"; break; case StatOutputFormat.HTML: head = @" @@ -5412,7 +5412,38 @@ Please check the log folder if the stats scrolled offscreen", false); - " +"; + break; + case StatOutputFormat.None: + default: + break; + case StatOutputFormat.TSV: + break; + } + sw.Write(head); + + // Now write the mid header for those who need it + OutputStatsWriteMidHeader(sw, statOutputFormat, baddumpCol, nodumpCol); + } + + /// + /// Write out the mid-header to the stream, if any exists + /// + /// StreamWriter representing the output + /// StatOutputFormat representing output format + /// True if baddumps should be included in output, false otherwise + /// True if nodumps should be included in output, false otherwise + private static void OutputStatsWriteMidHeader(StreamWriter sw, StatOutputFormat statOutputFormat, bool baddumpCol, bool nodumpCol) + { + string head = ""; + switch (statOutputFormat) + { + case StatOutputFormat.CSV: + head = "\"File Name\",\"Total Size\",\"Games\",\"Roms\",\"Disks\",\"# with CRC\",\"# with MD5\",\"# with SHA-1\"" + + (baddumpCol ? ",\"BadDumps\"" : "") + (nodumpCol ? ",\"Nodumps\"" : "") + "\n"; + break; + case StatOutputFormat.HTML: + head = @" " + "" + (baddumpCol ? "" : "") + (nodumpCol ? "" : "") + "\n"; break; case StatOutputFormat.None: @@ -5462,7 +5493,9 @@ Please check the log folder if the stats scrolled offscreen", false); /// /// StreamWriter representing the output /// StatOutputFormat representing output format - private static void OutputStatsWriteMidFooter(StreamWriter sw, StatOutputFormat statOutputFormat) + /// True if baddumps should be included in output, false otherwise + /// True if nodumps should be included in output, false otherwise + private static void OutputStatsWriteMidFooter(StreamWriter sw, StatOutputFormat statOutputFormat, bool baddumpCol, bool nodumpCol) { string end = ""; switch (statOutputFormat) @@ -5471,8 +5504,14 @@ Please check the log folder if the stats scrolled offscreen", false); end = "\n"; break; case StatOutputFormat.HTML: - end = @"
File NameTotal SizeGamesRomsDisks# with CRC
File NameTotal SizeGamesRomsDisks# with CRC# with MD5# with SHA-1BaddumpsNodumps
-

"; + end = "\n"; break; case StatOutputFormat.None: default: