[DatFile, Flags] Allow for muliple stat output formats at once

This commit is contained in:
Matt Nadareski
2016-12-05 11:43:48 -08:00
parent bf7fae766e
commit fdb14f5b6a
4 changed files with 234 additions and 200 deletions

View File

@@ -285,17 +285,6 @@
NotNodump = 5, // This is a fake flag that is used for filter only NotNodump = 5, // This is a fake flag that is used for filter only
} }
/// <summary>
/// Determine which format to output Stats to
/// </summary>
public enum StatDatFormat
{
None = 0,
HTML = 1,
CSV = 2,
TSV = 3,
}
#endregion #endregion
#region Skippers and Mappers #region Skippers and Mappers

View File

@@ -227,6 +227,18 @@ namespace SabreTools.Helper.Data
ALL = 0xFFFF, ALL = 0xFFFF,
} }
/// <summary>
/// Determine which format to output Stats to
/// </summary>
/// [Flags]
public enum StatDatFormat
{
None = 0x01,
HTML = 0x02,
CSV = 0x04,
TSV = 0x08,
}
#endregion #endregion
#region DatItem related #region DatItem related

View File

@@ -77,14 +77,15 @@ namespace SabreTools.Helper.Dats
/// <summary> /// <summary>
/// Output the stats for the Dat in a human-readable format /// Output the stats for the Dat in a human-readable format
/// </summary> /// </summary>
/// <param name="sw">StreamWriter representing the output file or stream for the statistics</param> /// <param name="outputs">Dictionary representing the outputs</param>
/// <param name="statDatFormat">Set the statistics output format to use</param> /// <param name="statDatFormat">Set the statistics output format to use</param>
/// <param name="logger">Logger object for file and console writing</param> /// <param name="logger">Logger object for file and console writing</param>
/// <param name="recalculate">True if numbers should be recalculated for the DAT, false otherwise (default)</param> /// <param name="recalculate">True if numbers should be recalculated for the DAT, false otherwise (default)</param>
/// <param name="game">Number of games to use, -1 means recalculate games (default)</param> /// <param name="game">Number of games to use, -1 means recalculate games (default)</param>
/// <param name="baddumpCol">True if baddumps should be included in output, false otherwise (default)</param> /// <param name="baddumpCol">True if baddumps should be included in output, false otherwise (default)</param>
/// <param name="nodumpCol">True if nodumps should be included in output, false otherwise (default)</param> /// <param name="nodumpCol">True if nodumps should be included in output, false otherwise (default)</param>
public void OutputStats(StreamWriter sw, StatDatFormat statDatFormat, Logger logger, bool recalculate = false, long game = -1, bool baddumpCol = false, bool nodumpCol = false) public void OutputStats(Dictionary<StatDatFormat, StreamWriter> outputs, StatDatFormat statDatFormat, Logger logger, bool recalculate = false,
long game = -1, bool baddumpCol = false, bool nodumpCol = false)
{ {
// If we're supposed to recalculate the statistics, do so // If we're supposed to recalculate the statistics, do so
if (recalculate) if (recalculate)
@@ -122,10 +123,31 @@ namespace SabreTools.Helper.Dats
// Now write it out to file as well // Now write it out to file as well
string line = ""; string line = "";
switch (statDatFormat) if (outputs.ContainsKey(StatDatFormat.None))
{ {
case StatDatFormat.CSV: line = @"'" + FileName + @"':
line = "\"" + FileName + "\"," --------------------------------------------------
Uncompressed size: " + Style.GetBytesReadable(TotalSize) + @"
Games found: " + (game == -1 ? Count : game) + @"
Roms found: " + RomCount + @"
Disks found: " + DiskCount + @"
Roms with CRC: " + CRCCount + @"
Roms with MD5: " + MD5Count + @"
Roms with SHA-1: " + SHA1Count + "\n";
if (baddumpCol)
{
line += " Roms with BadDump status: " + BaddumpCount + "\n";
}
if (nodumpCol)
{
line += " Roms with Nodump status: " + NodumpCount + "\n";
}
outputs[StatDatFormat.None].Write(line);
}
if (outputs.ContainsKey(StatDatFormat.CSV))
{
line = "\"" + FileName + "\","
+ "\"" + TotalSize + "\"," + "\"" + TotalSize + "\","
+ "\"" + (game == -1 ? Count : game) + "\"," + "\"" + (game == -1 ? Count : game) + "\","
+ "\"" + RomCount + "\"," + "\"" + RomCount + "\","
@@ -134,19 +156,21 @@ namespace SabreTools.Helper.Dats
+ "\"" + MD5Count + "\"," + "\"" + MD5Count + "\","
+ "\"" + SHA1Count + "\""; + "\"" + SHA1Count + "\"";
if (baddumpCol) if (baddumpCol)
{ {
line += ",\"" + BaddumpCount + "\""; line += ",\"" + BaddumpCount + "\"";
} }
if (nodumpCol) if (nodumpCol)
{ {
line += ",\"" + NodumpCount + "\""; line += ",\"" + NodumpCount + "\"";
} }
line += "\n"; line += "\n";
break; outputs[StatDatFormat.CSV].Write(line);
case StatDatFormat.HTML: }
line = "\t\t\t<tr" + (FileName.StartsWith("DIR: ") if (outputs.ContainsKey(StatDatFormat.HTML))
{
line = "\t\t\t<tr" + (FileName.StartsWith("DIR: ")
? " class=\"dir\"><td>" + HttpUtility.HtmlEncode(FileName.Remove(0, 5)) ? " class=\"dir\"><td>" + HttpUtility.HtmlEncode(FileName.Remove(0, 5))
: "><td>" + HttpUtility.HtmlEncode(FileName)) + "</td>" : "><td>" + HttpUtility.HtmlEncode(FileName)) + "</td>"
+ "<td align=\"right\">" + Style.GetBytesReadable(TotalSize) + "</td>" + "<td align=\"right\">" + Style.GetBytesReadable(TotalSize) + "</td>"
@@ -157,40 +181,21 @@ namespace SabreTools.Helper.Dats
+ "<td align=\"right\">" + MD5Count + "</td>" + "<td align=\"right\">" + MD5Count + "</td>"
+ "<td align=\"right\">" + SHA1Count + "</td>"; + "<td align=\"right\">" + SHA1Count + "</td>";
if (baddumpCol) if (baddumpCol)
{ {
line += "<td align=\"right\">" + BaddumpCount + "</td>"; line += "<td align=\"right\">" + BaddumpCount + "</td>";
} }
if (nodumpCol) if (nodumpCol)
{ {
line += "<td align=\"right\">" + NodumpCount + "</td>"; line += "<td align=\"right\">" + NodumpCount + "</td>";
} }
line += "</tr>\n"; line += "</tr>\n";
break; outputs[StatDatFormat.HTML].Write(line);
case StatDatFormat.None: }
default: if (outputs.ContainsKey(StatDatFormat.TSV))
line = @"'" + FileName + @"': {
-------------------------------------------------- line = "\"" + FileName + "\"\t"
Uncompressed size: " + Style.GetBytesReadable(TotalSize) + @"
Games found: " + (game == -1 ? Count : game) + @"
Roms found: " + RomCount + @"
Disks found: " + DiskCount + @"
Roms with CRC: " + CRCCount + @"
Roms with MD5: " + MD5Count + @"
Roms with SHA-1: " + SHA1Count + "\n";
if (baddumpCol)
{
line += " Roms with BadDump status: " + BaddumpCount + "\n";
}
if (nodumpCol)
{
line += " Roms with Nodump status: " + NodumpCount + "\n";
}
break;
case StatDatFormat.TSV:
line = "\"" + FileName + "\"\t"
+ "\"" + TotalSize + "\"\t" + "\"" + TotalSize + "\"\t"
+ "\"" + (game == -1 ? Count : game) + "\"\t" + "\"" + (game == -1 ? Count : game) + "\"\t"
+ "\"" + RomCount + "\"\t" + "\"" + RomCount + "\"\t"
@@ -199,21 +204,18 @@ namespace SabreTools.Helper.Dats
+ "\"" + MD5Count + "\"\t" + "\"" + MD5Count + "\"\t"
+ "\"" + SHA1Count + "\""; + "\"" + SHA1Count + "\"";
if (baddumpCol) if (baddumpCol)
{ {
line += "\t\"" + BaddumpCount + "\""; line += "\t\"" + BaddumpCount + "\"";
} }
if (nodumpCol) if (nodumpCol)
{ {
line += "\t\"" + NodumpCount + "\""; line += "\t\"" + NodumpCount + "\"";
} }
line += "\n"; line += "\n";
break; outputs[StatDatFormat.TSV].Write(line);
} }
// Output the line to the streamwriter
sw.Write(line);
} }
#endregion #endregion
@@ -237,6 +239,12 @@ namespace SabreTools.Helper.Dats
public static void OutputStats(List<string> inputs, string reportName, string outDir, bool single, public static void OutputStats(List<string> inputs, string reportName, string outDir, bool single,
bool baddumpCol, bool nodumpCol, StatDatFormat statDatFormat, Logger logger) bool baddumpCol, bool nodumpCol, StatDatFormat statDatFormat, Logger logger)
{ {
// If there's no output format, set the default
if (statDatFormat == 0x0)
{
statDatFormat = StatDatFormat.None;
}
// Get the proper output file name // Get the proper output file name
if (String.IsNullOrEmpty(outDir)) if (String.IsNullOrEmpty(outDir))
{ {
@@ -247,11 +255,9 @@ namespace SabreTools.Helper.Dats
reportName = "report"; reportName = "report";
} }
outDir = Path.GetFullPath(outDir); outDir = Path.GetFullPath(outDir);
reportName = Style.GetFileNameWithoutExtension(reportName) + OutputStatsGetExtension(statDatFormat);
Path.Combine(outDir, reportName);
// Create the StreamWriter for this file // Get the dictionary of desired outputs
StreamWriter sw = new StreamWriter(File.Open(reportName, FileMode.Create, FileAccess.Write)); Dictionary<StatDatFormat, StreamWriter> outputs = OutputStatsGetOutputWriters(statDatFormat, reportName, outDir);
// Make sure we have all files // Make sure we have all files
List<Tuple<string, string>> newinputs = new List<Tuple<string, string>>(); // item, basepath List<Tuple<string, string>> newinputs = new List<Tuple<string, string>>(); // item, basepath
@@ -275,7 +281,7 @@ namespace SabreTools.Helper.Dats
.ToList(); .ToList();
// Write the header, if any // Write the header, if any
OutputStatsWriteHeader(sw, statDatFormat, baddumpCol, nodumpCol); OutputStatsWriteHeader(outputs, statDatFormat, baddumpCol, nodumpCol);
// Init all total variables // Init all total variables
long totalSize = 0; long totalSize = 0;
@@ -312,7 +318,7 @@ namespace SabreTools.Helper.Dats
if (lastdir != null && thisdir != lastdir) if (lastdir != null && thisdir != lastdir)
{ {
// Output separator if needed // Output separator if needed
OutputStatsWriteMidSeparator(sw, statDatFormat, baddumpCol, nodumpCol); OutputStatsWriteMidSeparator(outputs, statDatFormat, baddumpCol, nodumpCol);
DatFile lastdirdat = new DatFile DatFile lastdirdat = new DatFile
{ {
@@ -326,13 +332,13 @@ namespace SabreTools.Helper.Dats
BaddumpCount = dirBaddump, BaddumpCount = dirBaddump,
NodumpCount = dirNodump, NodumpCount = dirNodump,
}; };
lastdirdat.OutputStats(sw, statDatFormat, logger, game: dirGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol); lastdirdat.OutputStats(outputs, statDatFormat, logger, game: dirGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol);
// Write the mid-footer, if any // Write the mid-footer, if any
OutputStatsWriteMidFooter(sw, statDatFormat, baddumpCol, nodumpCol); OutputStatsWriteMidFooter(outputs, statDatFormat, baddumpCol, nodumpCol);
// Write the header, if any // Write the header, if any
OutputStatsWriteMidHeader(sw, statDatFormat, baddumpCol, nodumpCol); OutputStatsWriteMidHeader(outputs, statDatFormat, baddumpCol, nodumpCol);
// Reset the directory stats // Reset the directory stats
dirSize = 0; dirSize = 0;
@@ -356,7 +362,7 @@ namespace SabreTools.Helper.Dats
logger.User("Adding stats for file '" + filename.Item1 + "'\n", false); logger.User("Adding stats for file '" + filename.Item1 + "'\n", false);
if (single) if (single)
{ {
datdata.OutputStats(sw, statDatFormat, logger, baddumpCol: baddumpCol, nodumpCol: nodumpCol); datdata.OutputStats(outputs, statDatFormat, logger, baddumpCol: baddumpCol, nodumpCol: nodumpCol);
} }
// Add single DAT stats to dir // Add single DAT stats to dir
@@ -386,7 +392,7 @@ namespace SabreTools.Helper.Dats
} }
// Output the directory stats one last time // Output the directory stats one last time
OutputStatsWriteMidSeparator(sw, statDatFormat, baddumpCol, nodumpCol); OutputStatsWriteMidSeparator(outputs, statDatFormat, baddumpCol, nodumpCol);
if (single) if (single)
{ {
@@ -402,14 +408,14 @@ namespace SabreTools.Helper.Dats
BaddumpCount = dirBaddump, BaddumpCount = dirBaddump,
NodumpCount = dirNodump, NodumpCount = dirNodump,
}; };
dirdat.OutputStats(sw, statDatFormat, logger, game: dirGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol); dirdat.OutputStats(outputs, statDatFormat, logger, game: dirGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol);
} }
// Write the mid-footer, if any // Write the mid-footer, if any
OutputStatsWriteMidFooter(sw, statDatFormat, baddumpCol, nodumpCol); OutputStatsWriteMidFooter(outputs, statDatFormat, baddumpCol, nodumpCol);
// Write the header, if any // Write the header, if any
OutputStatsWriteMidHeader(sw, statDatFormat, baddumpCol, nodumpCol); OutputStatsWriteMidHeader(outputs, statDatFormat, baddumpCol, nodumpCol);
// Reset the directory stats // Reset the directory stats
dirSize = 0; dirSize = 0;
@@ -434,13 +440,17 @@ namespace SabreTools.Helper.Dats
BaddumpCount = totalBaddump, BaddumpCount = totalBaddump,
NodumpCount = totalNodump, NodumpCount = totalNodump,
}; };
totaldata.OutputStats(sw, statDatFormat, logger, game: totalGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol); totaldata.OutputStats(outputs, statDatFormat, logger, game: totalGame, baddumpCol: baddumpCol, nodumpCol: nodumpCol);
// Output footer if needed // Output footer if needed
OutputStatsWriteFooter(sw, statDatFormat); OutputStatsWriteFooter(outputs, statDatFormat);
sw.Flush(); // Flush and dispose of the stream writers
sw.Dispose(); foreach (StatDatFormat format in outputs.Keys)
{
outputs[format].Flush();
outputs[format].Dispose();
}
logger.User(@" logger.User(@"
Please check the log folder if the stats scrolled offscreen", false); Please check the log folder if the stats scrolled offscreen", false);
@@ -450,47 +460,71 @@ Please check the log folder if the stats scrolled offscreen", false);
/// Get the proper extension for the stat output format /// Get the proper extension for the stat output format
/// </summary> /// </summary>
/// <param name="statDatFormat">StatDatFormat to get the extension for</param> /// <param name="statDatFormat">StatDatFormat to get the extension for</param>
/// <returns>File extension with leading period</returns> /// <param name="reportName">Name of the input file to use</param>
private static string OutputStatsGetExtension(StatDatFormat statDatFormat) /// <param name="outDir">Output path to use</param>
/// <returns>Dictionary of file types to StreamWriters</returns>
private static Dictionary<StatDatFormat, StreamWriter> OutputStatsGetOutputWriters(StatDatFormat statDatFormat, string reportName, string outDir)
{ {
string reportExtension = ""; Dictionary<StatDatFormat, StreamWriter> output = new Dictionary<StatDatFormat, System.IO.StreamWriter>();
switch (statDatFormat)
// For each output format, get the appropriate stream writer
if ((statDatFormat & StatDatFormat.None) != 0)
{ {
case StatDatFormat.CSV: reportName = Style.GetFileNameWithoutExtension(reportName) + ".txt";
reportExtension = ".csv"; Path.Combine(outDir, reportName);
break;
case StatDatFormat.HTML: // Create the StreamWriter for this file
reportExtension = ".html"; output.Add(StatDatFormat.None, new StreamWriter(File.Open(reportName, FileMode.Create, FileAccess.Write)));
break;
case StatDatFormat.None:
default:
reportExtension = ".txt";
break;
case StatDatFormat.TSV:
reportExtension = ".csv";
break;
} }
return reportExtension; if ((statDatFormat & StatDatFormat.CSV) != 0)
{
reportName = Style.GetFileNameWithoutExtension(reportName) + ".csv";
Path.Combine(outDir, reportName);
// Create the StreamWriter for this file
output.Add(StatDatFormat.CSV, new StreamWriter(File.Open(reportName, FileMode.Create, FileAccess.Write)));
}
if ((statDatFormat & StatDatFormat.HTML) != 0)
{
reportName = Style.GetFileNameWithoutExtension(reportName) + ".html";
Path.Combine(outDir, reportName);
// Create the StreamWriter for this file
output.Add(StatDatFormat.HTML, new StreamWriter(File.Open(reportName, FileMode.Create, FileAccess.Write)));
}
if ((statDatFormat & StatDatFormat.TSV) != 0)
{
reportName = Style.GetFileNameWithoutExtension(reportName) + ".csv";
Path.Combine(outDir, reportName);
// Create the StreamWriter for this file
output.Add(StatDatFormat.TSV, new StreamWriter(File.Open(reportName, FileMode.Create, FileAccess.Write)));
}
return output;
} }
/// <summary> /// <summary>
/// Write out the header to the stream, if any exists /// Write out the header to the stream, if any exists
/// </summary> /// </summary>
/// <param name="sw">StreamWriter representing the output</param> /// <param name="outputs">Dictionary representing the outputs</param>
/// <param name="statDatFormat">StatDatFormat representing output format</param> /// <param name="statDatFormat">StatDatFormat representing output format</param>
/// <param name="baddumpCol">True if baddumps should be included in output, false otherwise</param> /// <param name="baddumpCol">True if baddumps should be included in output, false otherwise</param>
/// <param name="nodumpCol">True if nodumps should be included in output, false otherwise</param> /// <param name="nodumpCol">True if nodumps should be included in output, false otherwise</param>
private static void OutputStatsWriteHeader(StreamWriter sw, StatDatFormat statDatFormat, bool baddumpCol, bool nodumpCol) private static void OutputStatsWriteHeader(Dictionary<StatDatFormat, StreamWriter> outputs, StatDatFormat statDatFormat, bool baddumpCol, bool nodumpCol)
{ {
string head = ""; if (outputs.ContainsKey(StatDatFormat.None))
switch (statDatFormat)
{ {
case StatDatFormat.CSV: // Nothing
head = "\"File Name\",\"Total Size\",\"Games\",\"Roms\",\"Disks\",\"# with CRC\",\"# with MD5\",\"# with SHA-1\"" }
+ (baddumpCol ? ",\"BadDumps\"" : "") + (nodumpCol ? ",\"Nodumps\"" : "") + "\n"; if (outputs.ContainsKey(StatDatFormat.CSV))
break; {
case StatDatFormat.HTML: outputs[StatDatFormat.CSV].Write("\"File Name\",\"Total Size\",\"Games\",\"Roms\",\"Disks\",\"# with CRC\",\"# with MD5\",\"# with SHA-1\""
head = @"<!DOCTYPE html> + (baddumpCol ? ",\"BadDumps\"" : "") + (nodumpCol ? ",\"Nodumps\"" : "") + "\n");
}
if (outputs.ContainsKey(StatDatFormat.HTML))
{
outputs[StatDatFormat.HTML].Write(@"<!DOCTYPE html>
<html> <html>
<header> <header>
<title>DAT Statistics Report</title> <title>DAT Statistics Report</title>
@@ -509,115 +543,113 @@ Please check the log folder if the stats scrolled offscreen", false);
<body> <body>
<h2>DAT Statistics Report (" + DateTime.Now.ToShortDateString() + @")</h2> <h2>DAT Statistics Report (" + DateTime.Now.ToShortDateString() + @")</h2>
<table border=""1"" cellpadding=""5"" cellspacing=""0""> <table border=""1"" cellpadding=""5"" cellspacing=""0"">
"; ");
break; }
case StatDatFormat.None: if (outputs.ContainsKey(StatDatFormat.TSV))
default: {
break; outputs[StatDatFormat.TSV].Write("\"File Name\"\t\"Total Size\"\t\"Games\"\t\"Roms\"\t\"Disks\"\t\"# with CRC\"\t\"# with MD5\"\t\"# with SHA-1\""
case StatDatFormat.TSV: + (baddumpCol ? "\t\"BadDumps\"" : "") + (nodumpCol ? "\t\"Nodumps\"" : "") + "\n");
head = "\"File Name\"\t\"Total Size\"\t\"Games\"\t\"Roms\"\t\"Disks\"\t\"# with CRC\"\t\"# with MD5\"\t\"# with SHA-1\""
+ (baddumpCol ? "\t\"BadDumps\"" : "") + (nodumpCol ? "\t\"Nodumps\"" : "") + "\n";
break;
} }
sw.Write(head);
// Now write the mid header for those who need it // Now write the mid header for those who need it
OutputStatsWriteMidHeader(sw, statDatFormat, baddumpCol, nodumpCol); OutputStatsWriteMidHeader(outputs, statDatFormat, baddumpCol, nodumpCol);
} }
/// <summary> /// <summary>
/// Write out the mid-header to the stream, if any exists /// Write out the mid-header to the stream, if any exists
/// </summary> /// </summary>
/// <param name="sw">StreamWriter representing the output</param> /// <param name="outputs">Dictionary representing the outputs</param>
/// <param name="statDatFormat">StatDatFormat representing output format</param> /// <param name="statDatFormat">StatDatFormat representing output format</param>
/// <param name="baddumpCol">True if baddumps should be included in output, false otherwise</param> /// <param name="baddumpCol">True if baddumps should be included in output, false otherwise</param>
/// <param name="nodumpCol">True if nodumps should be included in output, false otherwise</param> /// <param name="nodumpCol">True if nodumps should be included in output, false otherwise</param>
private static void OutputStatsWriteMidHeader(StreamWriter sw, StatDatFormat statDatFormat, bool baddumpCol, bool nodumpCol) private static void OutputStatsWriteMidHeader(Dictionary<StatDatFormat, StreamWriter> outputs, StatDatFormat statDatFormat, bool baddumpCol, bool nodumpCol)
{ {
string head = ""; if (outputs.ContainsKey(StatDatFormat.None))
switch (statDatFormat)
{ {
case StatDatFormat.CSV: // Nothing
break; }
case StatDatFormat.HTML: if (outputs.ContainsKey(StatDatFormat.CSV))
head = @" <tr bgcolor=""gray""><th>File Name</th><th align=""right"">Total Size</th><th align=""right"">Games</th><th align=""right"">Roms</th>" {
+ @"<th align=""right"">Disks</th><th align=""right"">&#35; with CRC</th><th align=""right"">&#35; with MD5</th><th align=""right"">&#35; with SHA-1</th>" // Nothing
+ (baddumpCol ? "<th class=\".right\">Baddumps</th>" : "") + (nodumpCol ? "<th class=\".right\">Nodumps</th>" : "") + "</tr>\n"; }
break; if (outputs.ContainsKey(StatDatFormat.HTML))
case StatDatFormat.None: {
default: outputs[StatDatFormat.HTML].Write(@" <tr bgcolor=""gray""><th>File Name</th><th align=""right"">Total Size</th><th align=""right"">Games</th><th align=""right"">Roms</th>"
break; + @"<th align=""right"">Disks</th><th align=""right"">&#35; with CRC</th><th align=""right"">&#35; with MD5</th><th align=""right"">&#35; with SHA-1</th>"
case StatDatFormat.TSV: + (baddumpCol ? "<th class=\".right\">Baddumps</th>" : "") + (nodumpCol ? "<th class=\".right\">Nodumps</th>" : "") + "</tr>\n");
break; }
if (outputs.ContainsKey(StatDatFormat.TSV))
{
// Nothing
} }
sw.Write(head);
} }
/// <summary> /// <summary>
/// Write out the separator to the stream, if any exists /// Write out the separator to the stream, if any exists
/// </summary> /// </summary>
/// <param name="sw">StreamWriter representing the output</param> /// <param name="outputs">Dictionary representing the outputs</param>
/// <param name="statDatFormat">StatDatFormat representing output format</param> /// <param name="statDatFormat">StatDatFormat representing output format</param>
/// <param name="baddumpCol">True if baddumps should be included in output, false otherwise</param> /// <param name="baddumpCol">True if baddumps should be included in output, false otherwise</param>
/// <param name="nodumpCol">True if nodumps should be included in output, false otherwise</param> /// <param name="nodumpCol">True if nodumps should be included in output, false otherwise</param>
private static void OutputStatsWriteMidSeparator(StreamWriter sw, StatDatFormat statDatFormat, bool baddumpCol, bool nodumpCol) private static void OutputStatsWriteMidSeparator(Dictionary<StatDatFormat, StreamWriter> outputs, StatDatFormat statDatFormat, bool baddumpCol, bool nodumpCol)
{ {
string mid = ""; if (outputs.ContainsKey(StatDatFormat.None))
switch (statDatFormat)
{ {
case StatDatFormat.CSV: // Nothing
break; }
case StatDatFormat.HTML: if (outputs.ContainsKey(StatDatFormat.CSV))
mid = "<tr><td colspan=\"" {
// Nothing
}
if (outputs.ContainsKey(StatDatFormat.HTML))
{
outputs[StatDatFormat.HTML].Write("<tr><td colspan=\""
+ (baddumpCol && nodumpCol + (baddumpCol && nodumpCol
? "11" ? "11"
: (baddumpCol ^ nodumpCol : (baddumpCol ^ nodumpCol
? "10" ? "10"
: "9") : "9")
) )
+ "\"></td></tr>\n"; + "\"></td></tr>\n");
break; }
case StatDatFormat.None: if (outputs.ContainsKey(StatDatFormat.TSV))
default: {
break; // Nothing
} }
sw.Write(mid);
} }
/// <summary> /// <summary>
/// Write out the footer-separator to the stream, if any exists /// Write out the footer-separator to the stream, if any exists
/// </summary> /// </summary>
/// <param name="sw">StreamWriter representing the output</param> /// <param name="outputs">Dictionary representing the outputs</param>
/// <param name="statDatFormat">StatDatFormat representing output format</param> /// <param name="statDatFormat">StatDatFormat representing output format</param>
/// <param name="baddumpCol">True if baddumps should be included in output, false otherwise</param> /// <param name="baddumpCol">True if baddumps should be included in output, false otherwise</param>
/// <param name="nodumpCol">True if nodumps should be included in output, false otherwise</param> /// <param name="nodumpCol">True if nodumps should be included in output, false otherwise</param>
private static void OutputStatsWriteMidFooter(StreamWriter sw, StatDatFormat statDatFormat, bool baddumpCol, bool nodumpCol) private static void OutputStatsWriteMidFooter(Dictionary<StatDatFormat, StreamWriter> outputs, StatDatFormat statDatFormat, bool baddumpCol, bool nodumpCol)
{ {
string end = ""; if (outputs.ContainsKey(StatDatFormat.None))
switch (statDatFormat)
{ {
case StatDatFormat.CSV: outputs[StatDatFormat.None].Write("\n");
end = "\n"; }
break; if (outputs.ContainsKey(StatDatFormat.CSV))
case StatDatFormat.HTML: {
end = "<tr border=\"0\"><td colspan=\"" outputs[StatDatFormat.CSV].Write("\n");
}
if (outputs.ContainsKey(StatDatFormat.HTML))
{
outputs[StatDatFormat.HTML].Write("<tr border=\"0\"><td colspan=\""
+ (baddumpCol && nodumpCol + (baddumpCol && nodumpCol
? "11" ? "11"
: (baddumpCol ^ nodumpCol : (baddumpCol ^ nodumpCol
? "10" ? "10"
: "9") : "9")
) )
+ "\"></td></tr>\n"; + "\"></td></tr>\n");
break; }
case StatDatFormat.None: if (outputs.ContainsKey(StatDatFormat.TSV))
default: {
end = "\n"; outputs[StatDatFormat.TSV].Write("\n");
break;
case StatDatFormat.TSV:
end = "\n";
break;
} }
sw.Write(end);
} }
/// <summary> /// <summary>
@@ -625,26 +657,27 @@ Please check the log folder if the stats scrolled offscreen", false);
/// </summary> /// </summary>
/// <param name="sw">StreamWriter representing the output</param> /// <param name="sw">StreamWriter representing the output</param>
/// <param name="statDatFormat">StatDatFormat representing output format</param> /// <param name="statDatFormat">StatDatFormat representing output format</param>
private static void OutputStatsWriteFooter(StreamWriter sw, StatDatFormat statDatFormat) private static void OutputStatsWriteFooter(Dictionary<StatDatFormat, StreamWriter> outputs, StatDatFormat statDatFormat)
{ {
string end = ""; if (outputs.ContainsKey(StatDatFormat.None))
switch (statDatFormat)
{ {
case StatDatFormat.CSV: // Nothing
break; }
case StatDatFormat.HTML: if (outputs.ContainsKey(StatDatFormat.CSV))
end = @" </table> {
// Nothing
}
if (outputs.ContainsKey(StatDatFormat.HTML))
{
outputs[StatDatFormat.HTML].Write(@" </table>
</body> </body>
</html> </html>
"; ");
break; }
case StatDatFormat.None: if (outputs.ContainsKey(StatDatFormat.TSV))
default: {
break; // Nothing
case StatDatFormat.TSV:
break;
} }
sw.Write(end);
} }
#endregion #endregion

View File

@@ -101,7 +101,7 @@ namespace SabreTools
DatFormat datFormat = 0x0; DatFormat datFormat = 0x0;
DiffMode diffMode = 0x0; DiffMode diffMode = 0x0;
OutputFormat outputFormat = OutputFormat.Folder; OutputFormat outputFormat = OutputFormat.Folder;
StatDatFormat statDatFormat = StatDatFormat.None; StatDatFormat statDatFormat = 0x0;
// User inputs // User inputs
int gz = 2, // SimpleSort int gz = 2, // SimpleSort
@@ -242,7 +242,7 @@ namespace SabreTools
break; break;
case "-csv": case "-csv":
case "--csv": case "--csv":
statDatFormat = StatDatFormat.CSV; statDatFormat |= StatDatFormat.CSV;
break; break;
case "-dd": case "-dd":
case "--dedup": case "--dedup":
@@ -282,7 +282,7 @@ namespace SabreTools
break; break;
case "-html": case "-html":
case "--html": case "--html":
statDatFormat = StatDatFormat.HTML; statDatFormat |= StatDatFormat.HTML;
break; break;
case "-in": case "-in":
case "--inverse": case "--inverse":
@@ -438,7 +438,7 @@ namespace SabreTools
break; break;
case "-tsv": case "-tsv":
case "--tsv": case "--tsv":
statDatFormat = StatDatFormat.TSV; statDatFormat |= StatDatFormat.TSV;
break; break;
case "-txz": case "-txz":
case "--txz": case "--txz":