2017-11-07 13:56:15 -08:00
using System.Linq ;
using SabreTools.Library.DatFiles ;
#if MONO
using System.IO ;
#else
using Alphaleonis.Win32.Filesystem ;
using Stream = System . IO . Stream ;
#endif
namespace SabreTools.Library.Reports
{
/// <summary>
/// Separated-Value report format
/// </summary>
2017-11-17 15:08:35 -08:00
internal class SeparatedValue : BaseReport
2017-11-07 13:56:15 -08:00
{
private char _separator ;
/// <summary>
/// Create a new report from the input DatFile and the filename
/// </summary>
/// <param name="datfile">DatFile to write out statistics for</param>
/// <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>
public SeparatedValue ( DatFile datfile , string filename , char separator , bool baddumpCol = false , bool nodumpCol = false )
: base ( datfile , filename , baddumpCol , nodumpCol )
{
_separator = separator ;
}
/// <summary>
/// Create a new report from the input DatFile and the stream
/// </summary>
/// <param name="datfile">DatFile to write out statistics for</param>
/// <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>
public SeparatedValue ( DatFile datfile , Stream stream , char separator , bool baddumpCol = false , bool nodumpCol = false )
: base ( datfile , stream , baddumpCol , nodumpCol )
{
_separator = separator ;
}
/// <summary>
/// Write the report to file
/// </summary>
/// <param name="game">Number of games to use, -1 means use the number of keys</param>
public override void Write ( long game = - 1 )
{
string line = string . Format ( "\"" + _datFile . FileName + "\"{0}"
+ "\"" + _datFile . TotalSize + "\"{0}"
+ "\"" + ( game = = - 1 ? _datFile . Keys . Count ( ) : game ) + "\"{0}"
+ "\"" + _datFile . RomCount + "\"{0}"
+ "\"" + _datFile . DiskCount + "\"{0}"
+ "\"" + _datFile . CRCCount + "\"{0}"
+ "\"" + _datFile . MD5Count + "\"{0}"
+ "\"" + _datFile . SHA1Count + "\"{0}"
+ "\"" + _datFile . SHA256Count + "\"{0}"
+ "\"" + _datFile . SHA384Count + "\"{0}"
+ "\"" + _datFile . SHA512Count + "\""
+ ( _baddumpCol ? "{0}\"" + _datFile . BaddumpCount + "\"" : "" )
+ ( _nodumpCol ? "{0}\"" + _datFile . BaddumpCount + "\"" : "" )
+ "\n" , _separator ) ;
_writer . Write ( line ) ;
_writer . Flush ( ) ;
}
/// <summary>
/// Write out the header to the stream, if any exists
/// </summary>
2017-11-07 14:06:21 -08:00
public override void WriteHeader ( )
2017-11-07 13:56:15 -08:00
{
_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\""
+ ( _baddumpCol ? "{0}\"BadDumps\"" : "" ) + ( _nodumpCol ? "{0}\"Nodumps\"" : "" ) + "\n" , _separator ) ) ;
_writer . Flush ( ) ;
}
/// <summary>
/// Write out the mid-header to the stream, if any exists
/// </summary>
2017-11-07 14:06:21 -08:00
public override void WriteMidHeader ( )
2017-11-07 13:56:15 -08:00
{
// This call is a no-op for separated value formats
}
/// <summary>
/// Write out the separator to the stream, if any exists
/// </summary>
2017-11-07 14:06:21 -08:00
public override void WriteMidSeparator ( )
2017-11-07 13:56:15 -08:00
{
// This call is a no-op for separated value formats
}
/// <summary>
/// Write out the footer-separator to the stream, if any exists
/// </summary>
2017-11-07 14:06:21 -08:00
public override void WriteFooterSeparator ( )
2017-11-07 13:56:15 -08:00
{
_writer . Write ( "\n" ) ;
_writer . Flush ( ) ;
}
/// <summary>
/// Write out the footer to the stream, if any exists
/// </summary>
2017-11-07 14:06:21 -08:00
public override void WriteFooter ( )
2017-11-07 13:56:15 -08:00
{
// This call is a no-op for separated value formats
}
}
}