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:
@@ -19,16 +19,8 @@ namespace SabreTools.Serialization
|
||||
/// <returns>Deserialized data on success, null on failure</returns>
|
||||
public static MetadataFile? Deserialize(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return Deserialize(stream);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: Handle logging the exception
|
||||
return default;
|
||||
}
|
||||
using var stream = PathProcessor.OpenStream(path);
|
||||
return Deserialize(stream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,59 +30,51 @@ namespace SabreTools.Serialization
|
||||
/// <returns>Deserialized data on success, null on failure</returns>
|
||||
public static MetadataFile? Deserialize(Stream? stream)
|
||||
{
|
||||
try
|
||||
{
|
||||
// If the stream is null
|
||||
if (stream == null)
|
||||
return default;
|
||||
|
||||
// Setup the reader and output
|
||||
var reader = new SeparatedValueReader(stream, Encoding.UTF8)
|
||||
{
|
||||
Header = false,
|
||||
Separator = '\t',
|
||||
VerifyFieldCount = false,
|
||||
};
|
||||
var dat = new MetadataFile();
|
||||
|
||||
// Loop through the rows and parse out values
|
||||
var rows = new List<Row>();
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
// If we have no next line
|
||||
if (!reader.ReadNextLine())
|
||||
break;
|
||||
|
||||
// Parse the line into a row
|
||||
var row = new Row
|
||||
{
|
||||
SHA256 = reader.Line[0],
|
||||
Name = reader.Line[1],
|
||||
SHA1 = reader.Line[2],
|
||||
MD5 = reader.Line[3],
|
||||
CRC32 = reader.Line[4],
|
||||
};
|
||||
|
||||
// If we have the size field
|
||||
if (reader.Line.Count > 5)
|
||||
row.Size = reader.Line[5];
|
||||
|
||||
// If we have additional fields
|
||||
if (reader.Line.Count > 6)
|
||||
row.ADDITIONAL_ELEMENTS = reader.Line.Skip(5).ToArray();
|
||||
|
||||
rows.Add(row);
|
||||
}
|
||||
|
||||
// Assign the rows to the Dat and return
|
||||
dat.Row = rows.ToArray();
|
||||
return dat;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: Handle logging the exception
|
||||
// If the stream is null
|
||||
if (stream == null)
|
||||
return default;
|
||||
|
||||
// Setup the reader and output
|
||||
var reader = new SeparatedValueReader(stream, Encoding.UTF8)
|
||||
{
|
||||
Header = false,
|
||||
Separator = '\t',
|
||||
VerifyFieldCount = false,
|
||||
};
|
||||
var dat = new MetadataFile();
|
||||
|
||||
// Loop through the rows and parse out values
|
||||
var rows = new List<Row>();
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
// If we have no next line
|
||||
if (!reader.ReadNextLine())
|
||||
break;
|
||||
|
||||
// Parse the line into a row
|
||||
var row = new Row
|
||||
{
|
||||
SHA256 = reader.Line[0],
|
||||
Name = reader.Line[1],
|
||||
SHA1 = reader.Line[2],
|
||||
MD5 = reader.Line[3],
|
||||
CRC32 = reader.Line[4],
|
||||
};
|
||||
|
||||
// If we have the size field
|
||||
if (reader.Line.Count > 5)
|
||||
row.Size = reader.Line[5];
|
||||
|
||||
// If we have additional fields
|
||||
if (reader.Line.Count > 6)
|
||||
row.ADDITIONAL_ELEMENTS = reader.Line.Skip(5).ToArray();
|
||||
|
||||
rows.Add(row);
|
||||
}
|
||||
|
||||
// Assign the rows to the Dat and return
|
||||
dat.Row = rows.ToArray();
|
||||
return dat;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user