mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SabreTools, DatFile, Reports] Fix and upgrade stats output
This commit is contained in:
108
SabreTools.Library/Reports/BaseReport.cs
Normal file
108
SabreTools.Library/Reports/BaseReport.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
|
||||
using SabreTools.Library.DatFiles;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
#if MONO
|
||||
using System.IO;
|
||||
#else
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
|
||||
using FileStream = System.IO.FileStream;
|
||||
using IOException = System.IO.IOException;
|
||||
using MemoryStream = System.IO.MemoryStream;
|
||||
using SearchOption = System.IO.SearchOption;
|
||||
using SeekOrigin = System.IO.SeekOrigin;
|
||||
using Stream = System.IO.Stream;
|
||||
using StreamWriter = System.IO.StreamWriter;
|
||||
#endif
|
||||
|
||||
namespace SabreTools.Library.Reports
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for a report output format
|
||||
/// </summary>
|
||||
public abstract class BaseReport
|
||||
{
|
||||
protected DatFile _datFile;
|
||||
protected StreamWriter _writer;
|
||||
protected bool _baddumpCol;
|
||||
protected bool _nodumpCol;
|
||||
|
||||
/// <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="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 BaseReport(DatFile datfile, string filename, bool baddumpCol = false, bool nodumpCol = false)
|
||||
{
|
||||
_datFile = datfile;
|
||||
_writer = new StreamWriter(FileTools.TryCreate(filename));
|
||||
_baddumpCol = baddumpCol;
|
||||
_nodumpCol = nodumpCol;
|
||||
}
|
||||
|
||||
/// <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="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 BaseReport(DatFile datfile, Stream stream, bool baddumpCol = false, bool nodumpCol = false)
|
||||
{
|
||||
_datFile = datfile;
|
||||
|
||||
if (!stream.CanWrite)
|
||||
{
|
||||
throw new ArgumentException(nameof(stream));
|
||||
}
|
||||
|
||||
_writer = new StreamWriter(stream);
|
||||
_baddumpCol = baddumpCol;
|
||||
_nodumpCol = nodumpCol;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace the DatFile that is being output
|
||||
/// </summary>
|
||||
/// <param name="datfile"></param>
|
||||
public void ReplaceDatFile(DatFile datfile)
|
||||
{
|
||||
_datFile = datfile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write the report to the output stream
|
||||
/// </summary>
|
||||
/// <param name="game">Number of games to use, -1 means use the number of keys</param>
|
||||
public abstract void Write(long game = -1);
|
||||
|
||||
/// <summary>
|
||||
/// Write out the header to the stream, if any exists
|
||||
/// </summary>
|
||||
public abstract void WriteStatsHeader();
|
||||
|
||||
/// <summary>
|
||||
/// Write out the mid-header to the stream, if any exists
|
||||
/// </summary>
|
||||
public abstract void WriteStatsMidHeader();
|
||||
|
||||
/// <summary>
|
||||
/// Write out the separator to the stream, if any exists
|
||||
/// </summary>
|
||||
public abstract void WriteStatsMidSeparator();
|
||||
|
||||
/// <summary>
|
||||
/// Write out the footer-separator to the stream, if any exists
|
||||
/// </summary>
|
||||
public abstract void WriteStatsFooterSeparator();
|
||||
|
||||
/// <summary>
|
||||
/// Write out the footer to the stream, if any exists
|
||||
/// </summary>
|
||||
public abstract void WriteStatsFooter();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user