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,103 +30,95 @@ 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)
|
||||
{
|
||||
// If the stream is null
|
||||
if (stream == null)
|
||||
return default;
|
||||
Separator = ';',
|
||||
VerifyFieldCount = false,
|
||||
};
|
||||
var dat = new MetadataFile();
|
||||
|
||||
// Setup the reader and output
|
||||
var reader = new SeparatedValueReader(stream, Encoding.UTF8)
|
||||
// Read the header values first
|
||||
if (!reader.ReadHeader())
|
||||
return null;
|
||||
|
||||
dat.Header = reader.HeaderValues.ToArray();
|
||||
|
||||
// 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
|
||||
Row? row = null;
|
||||
if (reader.Line.Count < HeaderWithRomnameCount)
|
||||
{
|
||||
Separator = ';',
|
||||
VerifyFieldCount = false,
|
||||
};
|
||||
var dat = new MetadataFile();
|
||||
row = new Row
|
||||
{
|
||||
Name = reader.Line[0],
|
||||
Title = reader.Line[1],
|
||||
Emulator = reader.Line[2],
|
||||
CloneOf = reader.Line[3],
|
||||
Year = reader.Line[4],
|
||||
Manufacturer = reader.Line[5],
|
||||
Category = reader.Line[6],
|
||||
Players = reader.Line[7],
|
||||
Rotation = reader.Line[8],
|
||||
Control = reader.Line[9],
|
||||
Status = reader.Line[10],
|
||||
DisplayCount = reader.Line[11],
|
||||
DisplayType = reader.Line[12],
|
||||
AltRomname = reader.Line[13],
|
||||
AltTitle = reader.Line[14],
|
||||
Extra = reader.Line[15],
|
||||
Buttons = reader.Line[16],
|
||||
};
|
||||
|
||||
// Read the header values first
|
||||
if (!reader.ReadHeader())
|
||||
return null;
|
||||
|
||||
dat.Header = reader.HeaderValues.ToArray();
|
||||
|
||||
// Loop through the rows and parse out values
|
||||
var rows = new List<Row>();
|
||||
while (!reader.EndOfStream)
|
||||
// If we have additional fields
|
||||
if (reader.Line.Count > HeaderWithoutRomnameCount)
|
||||
row.ADDITIONAL_ELEMENTS = reader.Line.Skip(HeaderWithoutRomnameCount).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we have no next line
|
||||
if (!reader.ReadNextLine())
|
||||
break;
|
||||
|
||||
// Parse the line into a row
|
||||
Row? row = null;
|
||||
if (reader.Line.Count < HeaderWithRomnameCount)
|
||||
row = new Row
|
||||
{
|
||||
row = new Row
|
||||
{
|
||||
Name = reader.Line[0],
|
||||
Title = reader.Line[1],
|
||||
Emulator = reader.Line[2],
|
||||
CloneOf = reader.Line[3],
|
||||
Year = reader.Line[4],
|
||||
Manufacturer = reader.Line[5],
|
||||
Category = reader.Line[6],
|
||||
Players = reader.Line[7],
|
||||
Rotation = reader.Line[8],
|
||||
Control = reader.Line[9],
|
||||
Status = reader.Line[10],
|
||||
DisplayCount = reader.Line[11],
|
||||
DisplayType = reader.Line[12],
|
||||
AltRomname = reader.Line[13],
|
||||
AltTitle = reader.Line[14],
|
||||
Extra = reader.Line[15],
|
||||
Buttons = reader.Line[16],
|
||||
};
|
||||
Name = reader.Line[0],
|
||||
Title = reader.Line[1],
|
||||
Emulator = reader.Line[2],
|
||||
CloneOf = reader.Line[3],
|
||||
Year = reader.Line[4],
|
||||
Manufacturer = reader.Line[5],
|
||||
Category = reader.Line[6],
|
||||
Players = reader.Line[7],
|
||||
Rotation = reader.Line[8],
|
||||
Control = reader.Line[9],
|
||||
Status = reader.Line[10],
|
||||
DisplayCount = reader.Line[11],
|
||||
DisplayType = reader.Line[12],
|
||||
AltRomname = reader.Line[13],
|
||||
AltTitle = reader.Line[14],
|
||||
Extra = reader.Line[15],
|
||||
Buttons = reader.Line[16],
|
||||
};
|
||||
|
||||
// If we have additional fields
|
||||
if (reader.Line.Count > HeaderWithoutRomnameCount)
|
||||
row.ADDITIONAL_ELEMENTS = reader.Line.Skip(HeaderWithoutRomnameCount).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
row = new Row
|
||||
{
|
||||
Name = reader.Line[0],
|
||||
Title = reader.Line[1],
|
||||
Emulator = reader.Line[2],
|
||||
CloneOf = reader.Line[3],
|
||||
Year = reader.Line[4],
|
||||
Manufacturer = reader.Line[5],
|
||||
Category = reader.Line[6],
|
||||
Players = reader.Line[7],
|
||||
Rotation = reader.Line[8],
|
||||
Control = reader.Line[9],
|
||||
Status = reader.Line[10],
|
||||
DisplayCount = reader.Line[11],
|
||||
DisplayType = reader.Line[12],
|
||||
AltRomname = reader.Line[13],
|
||||
AltTitle = reader.Line[14],
|
||||
Extra = reader.Line[15],
|
||||
Buttons = reader.Line[16],
|
||||
};
|
||||
|
||||
// If we have additional fields
|
||||
if (reader.Line.Count > HeaderWithRomnameCount)
|
||||
row.ADDITIONAL_ELEMENTS = reader.Line.Skip(HeaderWithRomnameCount).ToArray();
|
||||
}
|
||||
|
||||
rows.Add(row);
|
||||
// If we have additional fields
|
||||
if (reader.Line.Count > HeaderWithRomnameCount)
|
||||
row.ADDITIONAL_ELEMENTS = reader.Line.Skip(HeaderWithRomnameCount).ToArray();
|
||||
}
|
||||
|
||||
// Assign the rows to the Dat and return
|
||||
dat.Row = rows.ToArray();
|
||||
return dat;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: Handle logging the exception
|
||||
return default;
|
||||
rows.Add(row);
|
||||
}
|
||||
|
||||
// Assign the rows to the Dat and return
|
||||
dat.Row = rows.ToArray();
|
||||
return dat;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user