2020-06-10 22:37:19 -07:00
using System.IO ;
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>
/// Separated-Value report format
/// </summary>
internal class SeparatedValue : BaseReport
{
2020-12-08 13:23:59 -08:00
private readonly char _separator ;
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 filename
2019-02-08 20:53:13 -08:00
/// </summary>
/// <param name="filename">Name of the file to write out to</param>
/// <param name="separator">Separator character to use in output</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 SeparatedValue ( string filename , char separator , bool baddumpCol = false , bool nodumpCol = false )
: base ( filename , baddumpCol , nodumpCol )
2019-02-08 20:53:13 -08:00
{
_separator = separator ;
}
2017-11-07 13:56:15 -08:00
2019-02-08 20:53:13 -08:00
/// <summary>
/// Create a new report from the input DatFile and the stream
/// </summary>
/// <param name="stream">Output stream to write to</param>
/// <param name="separator">Separator character to use in output</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 SeparatedValue ( Stream stream , char separator , bool baddumpCol = false , bool nodumpCol = false )
: base ( stream , baddumpCol , nodumpCol )
2019-02-08 20:53:13 -08:00
{
_separator = separator ;
}
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 = string . Format ( "\"" + _name + "\"{0}"
+ "\"" + _stats . TotalSize + "\"{0}"
+ "\"" + _machineCount + "\"{0}"
+ "\"" + _stats . RomCount + "\"{0}"
+ "\"" + _stats . DiskCount + "\"{0}"
+ "\"" + _stats . CRCCount + "\"{0}"
+ "\"" + _stats . MD5Count + "\"{0}"
+ "\"" + _stats . SHA1Count + "\"{0}"
+ "\"" + _stats . SHA256Count + "\"{0}"
+ "\"" + _stats . SHA384Count + "\"{0}"
+ "\"" + _stats . SHA512Count + "\""
+ ( _baddumpCol ? "{0}\"" + _stats . BaddumpCount + "\"" : string . Empty )
+ ( _nodumpCol ? "{0}\"" + _stats . NodumpCount + "\"" : string . Empty )
2019-02-08 20:53:13 -08:00
+ "\n" , _separator ) ;
2020-07-15 09:41:59 -07:00
2019-02-08 20:53:13 -08:00
_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 ( string . Format ( "\"File Name\"{0}\"Total Size\"{0}\"Games\"{0}\"Roms\"{0}\"Disks\"{0}\"# with CRC\"{0}\"# with MD5\"{0}\"# with SHA-1\"{0}\"# with SHA-256\""
2020-06-10 22:37:19 -07:00
+ ( _baddumpCol ? "{0}\"BadDumps\"" : string . Empty ) + ( _nodumpCol ? "{0}\"Nodumps\"" : string . Empty ) + "\n" , _separator ) ) ;
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 mid-header to the stream, if any exists
/// </summary>
public override void WriteMidHeader ( )
{
// This call is a no-op for separated value formats
}
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 ( )
{
// This call is a no-op for separated value formats
}
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 ( "\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 ( )
{
// This call is a no-op for separated value formats
}
}
2017-11-07 13:56:15 -08:00
}