mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make report writing work with streams
This commit is contained in:
@@ -10,7 +10,6 @@ using SabreTools.Core.Tools;
|
||||
using SabreTools.DatFiles;
|
||||
using SabreTools.DatItems;
|
||||
using SabreTools.Hashing;
|
||||
using SabreTools.IO.Logging;
|
||||
|
||||
namespace SabreTools.Reports.Formats
|
||||
{
|
||||
@@ -30,21 +29,11 @@ namespace SabreTools.Reports.Formats
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool WriteToFile(string? outfile, bool baddumpCol, bool nodumpCol, bool throwOnError = false)
|
||||
public override bool WriteToStream(Stream stream, bool baddumpCol, bool nodumpCol, bool throwOnError = false)
|
||||
{
|
||||
InternalStopwatch watch = new($"Writing statistics to '{outfile}");
|
||||
|
||||
try
|
||||
{
|
||||
// Try to create the output file
|
||||
FileStream fs = File.Create(outfile ?? string.Empty);
|
||||
if (fs == null)
|
||||
{
|
||||
_logger.Warning($"File '{outfile}' could not be created for writing! Please check to see if the file is writable");
|
||||
return false;
|
||||
}
|
||||
|
||||
XmlTextWriter xtw = new(fs, Encoding.UTF8)
|
||||
XmlTextWriter xtw = new(stream, Encoding.UTF8)
|
||||
{
|
||||
Formatting = Formatting.Indented,
|
||||
IndentChar = '\t',
|
||||
@@ -85,17 +74,12 @@ namespace SabreTools.Reports.Formats
|
||||
#if NET452_OR_GREATER
|
||||
xtw.Dispose();
|
||||
#endif
|
||||
fs.Dispose();
|
||||
}
|
||||
catch (Exception ex) when (!throwOnError)
|
||||
{
|
||||
_logger.Error(ex);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
watch.Stop();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user