2017-11-07 13:56:15 -08:00
using System ;
2020-06-10 22:37:19 -07:00
using System.IO ;
2019-03-29 00:15:40 -07:00
using System.Net ;
2017-11-07 13:56:15 -08:00
2020-12-11 10:10:56 -08:00
namespace SabreTools.Reports.Formats
2017-11-07 13:56:15 -08:00
{
2019-02-08 20:53:13 -08:00
/// <summary>
/// HTML report format
/// </summary>
/// TODO: Make output standard width, without making the entire thing a table
internal class Html : BaseReport
{
/// <summary>
2020-07-15 09:41:59 -07:00
/// Create a new report from the filename
2019-02-08 20:53:13 -08:00
/// </summary>
/// <param name="filename">Name of the file to write out to</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>
2020-07-15 09:41:59 -07:00
public Html ( string filename , bool baddumpCol = false , bool nodumpCol = false )
: base ( filename , baddumpCol , nodumpCol )
2019-02-08 20:53:13 -08:00
{
}
2017-11-07 13:56:15 -08:00
2019-02-08 20:53:13 -08:00
/// <summary>
2020-07-15 09:41:59 -07:00
/// Create a new report from the stream
2019-02-08 20:53:13 -08:00
/// </summary>
/// <param name="datfile">DatFile to write out statistics for</param>
/// <param name="stream">Output stream to write to</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>
2020-07-15 09:41:59 -07:00
public Html ( Stream stream , bool baddumpCol = false , bool nodumpCol = false )
: base ( stream , baddumpCol , nodumpCol )
2019-02-08 20:53:13 -08:00
{
}
2017-11-07 13:56:15 -08:00
2019-02-08 20:53:13 -08:00
/// <summary>
/// Write the report to file
/// </summary>
2020-07-15 09:41:59 -07:00
public override void Write ( )
2019-02-08 20:53:13 -08:00
{
2020-07-15 09:41:59 -07:00
string line = "\t\t\t<tr" + ( _name . StartsWith ( "DIR: " )
? $" class=\" dir \ "><td>{WebUtility.HtmlEncode(_name.Remove(0, 5))}"
: $"><td>{WebUtility.HtmlEncode(_name)}" ) + "</td>"
2020-12-08 11:09:05 -08:00
+ $"<td align=\" right \ ">{GetBytesReadable(_stats.TotalSize)}</td>"
2020-07-15 09:41:59 -07:00
+ $"<td align=\" right \ ">{_machineCount}</td>"
+ $"<td align=\" right \ ">{_stats.RomCount}</td>"
+ $"<td align=\" right \ ">{_stats.DiskCount}</td>"
+ $"<td align=\" right \ ">{_stats.CRCCount}</td>"
+ $"<td align=\" right \ ">{_stats.MD5Count}</td>"
+ $"<td align=\" right \ ">{_stats.SHA1Count}</td>"
+ $"<td align=\" right \ ">{_stats.SHA256Count}</td>"
+ ( _baddumpCol ? $"<td align=\" right \ ">{_stats.BaddumpCount}</td>" : string . Empty )
+ ( _nodumpCol ? $"<td align=\" right \ ">{_stats.NodumpCount}</td>" : string . Empty )
2019-02-08 20:53:13 -08:00
+ "</tr>\n" ;
_writer . Write ( line ) ;
_writer . Flush ( ) ;
}
2017-11-07 13:56:15 -08:00
2019-02-08 20:53:13 -08:00
/// <summary>
/// Write out the header to the stream, if any exists
/// </summary>
public override void WriteHeader ( )
{
_writer . Write ( @ "<!DOCTYPE html>
2017-11-07 13:56:15 -08:00
< html >
2019-02-08 20:53:13 -08:00
< header >
< title > DAT Statistics Report < / title >
< style >
body {
background - color : lightgray ;
}
. dir {
color : # 0088F F ;
}
. right {
align : right ;
}
< / style >
< / header >
< body >
< h2 > DAT Statistics Report ( " + DateTime.Now.ToShortDateString() + @" ) < / h2 >
2020-06-10 22:37:19 -07:00
< table border = string . Empty1string . Empty cellpadding = string . Empty5string . Empty cellspacing = string . Empty0string . Empty >
2017-11-07 13:56:15 -08:00
");
2019-02-08 20:53:13 -08:00
_writer . Flush ( ) ;
2017-11-07 13:56:15 -08:00
2019-02-08 20:53:13 -08:00
// Now write the mid header for those who need it
WriteMidHeader ( ) ;
}
2017-11-07 13:56:15 -08:00
2019-02-08 20:53:13 -08:00
/// <summary>
/// Write out the mid-header to the stream, if any exists
/// </summary>
public override void WriteMidHeader ( )
{
2020-06-10 22:37:19 -07:00
_writer . Write ( @" <tr bgcolor=string.Emptygraystring.Empty><th>File Name</th><th align=string.Emptyrightstring.Empty>Total Size</th><th align=string.Emptyrightstring.Empty>Games</th><th align=string.Emptyrightstring.Empty>Roms</th>"
+ @"<th align=string.Emptyrightstring.Empty>Disks</th><th align=string.Emptyrightstring.Empty># with CRC</th><th align=string.Emptyrightstring.Empty># with MD5</th><th align=string.Emptyrightstring.Empty># with SHA-1</th><th align=string.Emptyrightstring.Empty># with SHA-256</th>"
+ ( _baddumpCol ? "<th class=\".right\">Baddumps</th>" : string . Empty ) + ( _nodumpCol ? "<th class=\".right\">Nodumps</th>" : string . Empty ) + "</tr>\n" ) ;
2019-02-08 20:53:13 -08:00
_writer . Flush ( ) ;
}
2017-11-07 13:56:15 -08:00
2019-02-08 20:53:13 -08:00
/// <summary>
/// Write out the separator to the stream, if any exists
/// </summary>
public override void WriteMidSeparator ( )
{
_writer . Write ( "<tr><td colspan=\""
+ ( _baddumpCol & & _nodumpCol
? "12"
: ( _baddumpCol ^ _nodumpCol
? "11"
: "10" )
)
+ "\"></td></tr>\n" ) ;
_writer . Flush ( ) ;
}
2017-11-07 13:56:15 -08:00
2019-02-08 20:53:13 -08:00
/// <summary>
/// Write out the footer-separator to the stream, if any exists
/// </summary>
public override void WriteFooterSeparator ( )
{
_writer . Write ( "<tr border=\"0\"><td colspan=\""
+ ( _baddumpCol & & _nodumpCol
? "12"
: ( _baddumpCol ^ _nodumpCol
? "11"
: "10" )
)
+ "\"></td></tr>\n" ) ;
_writer . Flush ( ) ;
}
2017-11-07 13:56:15 -08:00
2019-02-08 20:53:13 -08:00
/// <summary>
/// Write out the footer to the stream, if any exists
/// </summary>
public override void WriteFooter ( )
{
_writer . Write ( @ " </table>
< / body >
2017-11-07 13:56:15 -08:00
< / html >
");
2019-02-08 20:53:13 -08:00
_writer . Flush ( ) ;
}
}
2017-11-07 13:56:15 -08:00
}