mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Let exceptions boil up
This commit is contained in:
@@ -20,22 +20,14 @@ namespace SabreTools.Serialization
|
||||
/// <returns>True on successful serialization, false otherwise</returns>
|
||||
public static bool SerializeToFile(MetadataFile? metadataFile, string path, char delim)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var stream = SerializeToStream(metadataFile, delim);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using var fs = File.OpenWrite(path);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: Handle logging the exception
|
||||
using var stream = SerializeToStream(metadataFile, delim);
|
||||
if (stream == null)
|
||||
return false;
|
||||
}
|
||||
|
||||
using var fs = File.OpenWrite(path);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -46,31 +38,23 @@ namespace SabreTools.Serialization
|
||||
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
||||
public static Stream? SerializeToStream(MetadataFile? metadataFile, char delim)
|
||||
{
|
||||
try
|
||||
{
|
||||
// If the metadata file is null
|
||||
if (metadataFile == null)
|
||||
return null;
|
||||
|
||||
// Setup the writer and output
|
||||
var stream = new MemoryStream();
|
||||
var writer = new SeparatedValueWriter(stream, Encoding.UTF8) { Separator = delim, Quotes = true };
|
||||
|
||||
// TODO: Include flag to write out long or short header
|
||||
// Write the short header
|
||||
WriteHeader(writer);
|
||||
|
||||
// Write out the rows, if they exist
|
||||
WriteRows(metadataFile.Row, writer);
|
||||
|
||||
// Return the stream
|
||||
return stream;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: Handle logging the exception
|
||||
// If the metadata file is null
|
||||
if (metadataFile == null)
|
||||
return null;
|
||||
}
|
||||
|
||||
// Setup the writer and output
|
||||
var stream = new MemoryStream();
|
||||
var writer = new SeparatedValueWriter(stream, Encoding.UTF8) { Separator = delim, Quotes = true };
|
||||
|
||||
// TODO: Include flag to write out long or short header
|
||||
// Write the short header
|
||||
WriteHeader(writer);
|
||||
|
||||
// Write out the rows, if they exist
|
||||
WriteRows(metadataFile.Row, writer);
|
||||
|
||||
// Return the stream
|
||||
return stream;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -79,7 +63,7 @@ namespace SabreTools.Serialization
|
||||
/// <param name="writer">SeparatedValueWriter representing the output</param>
|
||||
private static void WriteHeader(SeparatedValueWriter writer)
|
||||
{
|
||||
var headerArray = new string[]
|
||||
var headerArray = new string?[]
|
||||
{
|
||||
"File Name",
|
||||
"Internal Name",
|
||||
@@ -118,7 +102,7 @@ namespace SabreTools.Serialization
|
||||
// Loop through and write out the rows
|
||||
foreach (var row in rows)
|
||||
{
|
||||
var rowArray = new string[]
|
||||
var rowArray = new string?[]
|
||||
{
|
||||
row.FileName,
|
||||
row.InternalName,
|
||||
|
||||
Reference in New Issue
Block a user