diff --git a/SabreTools.Models/SeparatedValue/Row.cs b/SabreTools.Models/SeparatedValue/Row.cs
index 1786cea4..44979ffb 100644
--- a/SabreTools.Models/SeparatedValue/Row.cs
+++ b/SabreTools.Models/SeparatedValue/Row.cs
@@ -6,55 +6,55 @@ namespace SabreTools.Models.SeparatedValue
public class Row
{
/// File Name
- public string FileName { get; set; }
+ public string? FileName { get; set; }
/// Internal Name
- public string InternalName { get; set; }
+ public string? InternalName { get; set; }
/// Description
- public string Description { get; set; }
+ public string? Description { get; set; }
/// Game Name
public string GameName { get; set; }
/// Game Description
- public string GameDescription { get; set; }
+ public string? GameDescription { get; set; }
/// Type
public string Type { get; set; }
/// Rom Name
- public string RomName { get; set; }
+ public string? RomName { get; set; }
/// Disk Name
- public string DiskName { get; set; }
+ public string? DiskName { get; set; }
/// Size, Numeric
- public string Size { get; set; }
+ public string? Size { get; set; }
/// CRC
- public string CRC { get; set; }
+ public string? CRC { get; set; }
/// MD5
- public string MD5 { get; set; }
+ public string? MD5 { get; set; }
/// SHA1
- public string SHA1 { get; set; }
+ public string? SHA1 { get; set; }
/// SHA256
- public string SHA256 { get; set; }
+ public string? SHA256 { get; set; }
/// SHA384, Optional
- public string SHA384 { get; set; }
+ public string? SHA384 { get; set; }
/// SHA512, Optional
- public string SHA512 { get; set; }
+ public string? SHA512 { get; set; }
/// SpamSum, Optional
- public string SpamSum { get; set; }
+ public string? SpamSum { get; set; }
/// Status, Nodump
- public string Status { get; set; }
+ public string? Status { get; set; }
#region DO NOT USE IN PRODUCTION
diff --git a/SabreTools.Serialization/AttractMode.Deserializer.cs b/SabreTools.Serialization/AttractMode.Deserializer.cs
index 39a8031c..83de3bdb 100644
--- a/SabreTools.Serialization/AttractMode.Deserializer.cs
+++ b/SabreTools.Serialization/AttractMode.Deserializer.cs
@@ -19,16 +19,8 @@ namespace SabreTools.Serialization
/// Deserialized data on success, null on failure
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);
}
///
@@ -38,103 +30,95 @@ namespace SabreTools.Serialization
/// Deserialized data on success, null on failure
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();
+ 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();
- 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;
}
}
}
\ No newline at end of file
diff --git a/SabreTools.Serialization/AttractMode.Serializer.cs b/SabreTools.Serialization/AttractMode.Serializer.cs
index c51880de..24a91777 100644
--- a/SabreTools.Serialization/AttractMode.Serializer.cs
+++ b/SabreTools.Serialization/AttractMode.Serializer.cs
@@ -19,22 +19,14 @@ namespace SabreTools.Serialization
/// True on successful serialization, false otherwise
public static bool SerializeToFile(MetadataFile? metadataFile, string path)
{
- try
- {
- using var stream = SerializeToStream(metadataFile);
- 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);
+ if (stream == null)
return false;
- }
+
+ using var fs = File.OpenWrite(path);
+ stream.Seek(0, SeekOrigin.Begin);
+ stream.CopyTo(fs);
+ return true;
}
///
@@ -44,31 +36,28 @@ namespace SabreTools.Serialization
/// Stream containing serialized data on success, null otherwise
public static Stream? SerializeToStream(MetadataFile? metadataFile)
{
- 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 = ';', Quotes = false };
-
- // TODO: Include flag to write out long or short header
- // Write the short header
- writer.WriteString(HeaderWithoutRomname); // TODO: Convert to array of values
-
- // 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 = ';',
+ Quotes = false,
+ VerifyFieldCount = false,
+ };
+
+ // TODO: Include flag to write out long or short header
+ // Write the short header
+ writer.WriteString(HeaderWithoutRomname); // TODO: Convert to array of values
+
+ // Write out the rows, if they exist
+ WriteRows(metadataFile.Row, writer);
+
+ // Return the stream
+ return stream;
}
///
@@ -85,7 +74,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.Name,
row.Title,
diff --git a/SabreTools.Serialization/ClrMamePro.Deserializer.cs b/SabreTools.Serialization/ClrMamePro.Deserializer.cs
index 0c282fc2..adf70d7f 100644
--- a/SabreTools.Serialization/ClrMamePro.Deserializer.cs
+++ b/SabreTools.Serialization/ClrMamePro.Deserializer.cs
@@ -19,16 +19,8 @@ namespace SabreTools.Serialization
/// Deserialized data on success, null on failure
public static MetadataFile? Deserialize(string path, bool quotes)
{
- try
- {
- using var stream = PathProcessor.OpenStream(path);
- return Deserialize(stream, quotes);
- }
- catch
- {
- // TODO: Handle logging the exception
- return default;
- }
+ using var stream = PathProcessor.OpenStream(path);
+ return Deserialize(stream, quotes);
}
///
@@ -39,305 +31,297 @@ namespace SabreTools.Serialization
/// Deserialized data on success, null on failure
public static MetadataFile? Deserialize(Stream? stream, bool quotes)
{
- try
+ // If the stream is null
+ if (stream == null)
+ return default;
+
+ // Setup the reader and output
+ var reader = new ClrMameProReader(stream, Encoding.UTF8) { Quotes = quotes };
+ var dat = new MetadataFile();
+
+ // Loop through and parse out the values
+ string lastTopLevel = reader.TopLevel;
+
+ GameBase? game = null;
+ var games = new List();
+ var releases = new List();
+ var biosSets = new List();
+ var roms = new List();
+ var disks = new List();
+ var medias = new List();
+ var samples = new List();
+ var archives = new List();
+ var chips = new List();
+ var dipSwitches = new List();
+
+ var additional = new List();
+ var headerAdditional = new List();
+ var gameAdditional = new List();
+ while (!reader.EndOfStream)
{
- // If the stream is null
- if (stream == null)
- return default;
+ // If we have no next line
+ if (!reader.ReadNextLine())
+ break;
- // Setup the reader and output
- var reader = new ClrMameProReader(stream, Encoding.UTF8) { Quotes = quotes };
- var dat = new MetadataFile();
-
- // Loop through and parse out the values
- string lastTopLevel = reader.TopLevel;
-
- GameBase? game = null;
- var games = new List();
- var releases = new List();
- var biosSets = new List();
- var roms = new List();
- var disks = new List();
- var medias = new List();
- var samples = new List();
- var archives = new List();
- var chips = new List();
- var dipSwitches = new List();
-
- var additional = new List();
- var headerAdditional = new List();
- var gameAdditional = new List();
- while (!reader.EndOfStream)
+ // Ignore certain row types
+ switch (reader.RowType)
{
- // If we have no next line
- if (!reader.ReadNextLine())
- break;
-
- // Ignore certain row types
- switch (reader.RowType)
- {
- case CmpRowType.None:
- case CmpRowType.Comment:
- continue;
- case CmpRowType.EndTopLevel:
- switch (lastTopLevel)
- {
- case "doscenter":
- dat.ClrMamePro!.ADDITIONAL_ELEMENTS = headerAdditional.ToArray();
- headerAdditional.Clear();
- break;
- case "game":
- case "machine":
- case "resource":
- case "set":
- game!.Release = releases.ToArray();
- game.BiosSet = biosSets.ToArray();
- game.Rom = roms.ToArray();
- game.Disk = disks.ToArray();
- game.Media = medias.ToArray();
- game.Sample = samples.ToArray();
- game.Archive = archives.ToArray();
- game.Chip = chips.ToArray();
- game.DipSwitch = dipSwitches.ToArray();
- game.ADDITIONAL_ELEMENTS = gameAdditional.ToArray();
-
- games.Add(game);
- game = null;
-
- releases.Clear();
- biosSets.Clear();
- roms.Clear();
- disks.Clear();
- medias.Clear();
- samples.Clear();
- archives.Clear();
- chips.Clear();
- dipSwitches.Clear();
- gameAdditional.Clear();
- break;
- default:
- // No-op
- break;
- }
- continue;
- }
-
- // If we're at the root
- if (reader.RowType == CmpRowType.TopLevel)
- {
- lastTopLevel = reader.TopLevel;
- switch (reader.TopLevel)
+ case CmpRowType.None:
+ case CmpRowType.Comment:
+ continue;
+ case CmpRowType.EndTopLevel:
+ switch (lastTopLevel)
{
- case "clrmamepro":
- dat.ClrMamePro = new Models.ClrMamePro.ClrMamePro();
+ case "doscenter":
+ dat.ClrMamePro!.ADDITIONAL_ELEMENTS = headerAdditional.ToArray();
+ headerAdditional.Clear();
break;
case "game":
- game = new Game();
- break;
case "machine":
- game = new Machine();
- break;
case "resource":
- game = new Resource();
- break;
case "set":
- game = new Set();
+ game!.Release = releases.ToArray();
+ game.BiosSet = biosSets.ToArray();
+ game.Rom = roms.ToArray();
+ game.Disk = disks.ToArray();
+ game.Media = medias.ToArray();
+ game.Sample = samples.ToArray();
+ game.Archive = archives.ToArray();
+ game.Chip = chips.ToArray();
+ game.DipSwitch = dipSwitches.ToArray();
+ game.ADDITIONAL_ELEMENTS = gameAdditional.ToArray();
+
+ games.Add(game);
+ game = null;
+
+ releases.Clear();
+ biosSets.Clear();
+ roms.Clear();
+ disks.Clear();
+ medias.Clear();
+ samples.Clear();
+ archives.Clear();
+ chips.Clear();
+ dipSwitches.Clear();
+ gameAdditional.Clear();
break;
default:
- additional.Add(reader.CurrentLine);
+ // No-op
break;
}
- }
+ continue;
+ }
- // If we're in the doscenter block
- else if (reader.TopLevel == "clrmamepro"
- && reader.RowType == CmpRowType.Standalone)
+ // If we're at the root
+ if (reader.RowType == CmpRowType.TopLevel)
+ {
+ lastTopLevel = reader.TopLevel;
+ switch (reader.TopLevel)
{
- // Create the block if we haven't already
- dat.ClrMamePro ??= new Models.ClrMamePro.ClrMamePro();
-
- switch (reader.Standalone?.Key?.ToLowerInvariant())
- {
- case "name":
- dat.ClrMamePro.Name = reader.Standalone?.Value;
- break;
- case "description":
- dat.ClrMamePro.Description = reader.Standalone?.Value;
- break;
- case "rootdir":
- dat.ClrMamePro.RootDir = reader.Standalone?.Value;
- break;
- case "category":
- dat.ClrMamePro.Category = reader.Standalone?.Value;
- break;
- case "version":
- dat.ClrMamePro.Version = reader.Standalone?.Value;
- break;
- case "date":
- dat.ClrMamePro.Date = reader.Standalone?.Value;
- break;
- case "author":
- dat.ClrMamePro.Author = reader.Standalone?.Value;
- break;
- case "homepage":
- dat.ClrMamePro.Homepage = reader.Standalone?.Value;
- break;
- case "url":
- dat.ClrMamePro.Url = reader.Standalone?.Value;
- break;
- case "comment":
- dat.ClrMamePro.Comment = reader.Standalone?.Value;
- break;
- case "header":
- dat.ClrMamePro.Header = reader.Standalone?.Value;
- break;
- case "type":
- dat.ClrMamePro.Type = reader.Standalone?.Value;
- break;
- case "forcemerging":
- dat.ClrMamePro.ForceMerging = reader.Standalone?.Value;
- break;
- case "forcezipping":
- dat.ClrMamePro.ForceZipping = reader.Standalone?.Value;
- break;
- case "forcepacking":
- dat.ClrMamePro.ForcePacking = reader.Standalone?.Value;
- break;
- default:
- headerAdditional.Add(reader.CurrentLine);
- break;
- }
- }
-
- // If we're in a game, machine, resource, or set block
- else if ((reader.TopLevel == "game"
- || reader.TopLevel == "machine"
- || reader.TopLevel == "resource"
- || reader.TopLevel == "set")
- && reader.RowType == CmpRowType.Standalone)
- {
- // Create the block if we haven't already
- game ??= reader.TopLevel switch
- {
- "game" => new Game(),
- "machine" => new Machine(),
- "resource" => new Resource(),
- "set" => new Set(),
- _ => throw new FormatException($"Unknown top-level block: {reader.TopLevel}"),
- };
-
- switch (reader.Standalone?.Key?.ToLowerInvariant())
- {
- case "name":
- game.Name = reader.Standalone?.Value;
- break;
- case "description":
- game.Description = reader.Standalone?.Value;
- break;
- case "year":
- game.Year = reader.Standalone?.Value;
- break;
- case "manufacturer":
- game.Manufacturer = reader.Standalone?.Value;
- break;
- case "category":
- game.Category = reader.Standalone?.Value;
- break;
- case "cloneof":
- game.CloneOf = reader.Standalone?.Value;
- break;
- case "romof":
- game.RomOf = reader.Standalone?.Value;
- break;
- case "sampleof":
- game.SampleOf = reader.Standalone?.Value;
- break;
- case "sample":
- var sample = new Sample
- {
- Name = reader.Standalone?.Value ?? string.Empty,
- ADDITIONAL_ELEMENTS = Array.Empty()
- };
- samples.Add(sample);
- break;
- default:
- gameAdditional.Add(reader.CurrentLine);
- break;
- }
- }
-
- // If we're in an item block
- else if ((reader.TopLevel == "game"
- || reader.TopLevel == "machine"
- || reader.TopLevel == "resource"
- || reader.TopLevel == "set")
- && game != null
- && reader.RowType == CmpRowType.Internal)
- {
- // Create the block
- switch (reader.InternalName)
- {
- case "release":
- releases.Add(CreateRelease(reader));
- break;
- case "biosset":
- biosSets.Add(CreateBiosSet(reader));
- break;
- case "rom":
- roms.Add(CreateRom(reader));
- break;
- case "disk":
- disks.Add(CreateDisk(reader));
- break;
- case "media":
- medias.Add(CreateMedia(reader));
- break;
- case "sample":
- samples.Add(CreateSample(reader));
- break;
- case "archive":
- archives.Add(CreateArchive(reader));
- break;
- case "chip":
- chips.Add(CreateChip(reader));
- break;
- case "video":
- game.Video = CreateVideo(reader);
- break;
- case "sound":
- game.Sound = CreateSound(reader);
- break;
- case "input":
- game.Input = CreateInput(reader);
- break;
- case "dipswitch":
- dipSwitches.Add(CreateDipSwitch(reader));
- break;
- case "driver":
- game.Driver = CreateDriver(reader);
- break;
- default:
- gameAdditional.Add(reader.CurrentLine);
- continue;
- }
- }
-
- else
- {
- additional.Add(reader.CurrentLine);
+ case "clrmamepro":
+ dat.ClrMamePro = new Models.ClrMamePro.ClrMamePro();
+ break;
+ case "game":
+ game = new Game();
+ break;
+ case "machine":
+ game = new Machine();
+ break;
+ case "resource":
+ game = new Resource();
+ break;
+ case "set":
+ game = new Set();
+ break;
+ default:
+ additional.Add(reader.CurrentLine);
+ break;
}
}
- // Add extra pieces and return
- dat.Game = games.ToArray();
- dat.ADDITIONAL_ELEMENTS = additional.ToArray();
- return dat;
- }
- catch
- {
- // TODO: Handle logging the exception
- return default;
+ // If we're in the doscenter block
+ else if (reader.TopLevel == "clrmamepro"
+ && reader.RowType == CmpRowType.Standalone)
+ {
+ // Create the block if we haven't already
+ dat.ClrMamePro ??= new Models.ClrMamePro.ClrMamePro();
+
+ switch (reader.Standalone?.Key?.ToLowerInvariant())
+ {
+ case "name":
+ dat.ClrMamePro.Name = reader.Standalone?.Value;
+ break;
+ case "description":
+ dat.ClrMamePro.Description = reader.Standalone?.Value;
+ break;
+ case "rootdir":
+ dat.ClrMamePro.RootDir = reader.Standalone?.Value;
+ break;
+ case "category":
+ dat.ClrMamePro.Category = reader.Standalone?.Value;
+ break;
+ case "version":
+ dat.ClrMamePro.Version = reader.Standalone?.Value;
+ break;
+ case "date":
+ dat.ClrMamePro.Date = reader.Standalone?.Value;
+ break;
+ case "author":
+ dat.ClrMamePro.Author = reader.Standalone?.Value;
+ break;
+ case "homepage":
+ dat.ClrMamePro.Homepage = reader.Standalone?.Value;
+ break;
+ case "url":
+ dat.ClrMamePro.Url = reader.Standalone?.Value;
+ break;
+ case "comment":
+ dat.ClrMamePro.Comment = reader.Standalone?.Value;
+ break;
+ case "header":
+ dat.ClrMamePro.Header = reader.Standalone?.Value;
+ break;
+ case "type":
+ dat.ClrMamePro.Type = reader.Standalone?.Value;
+ break;
+ case "forcemerging":
+ dat.ClrMamePro.ForceMerging = reader.Standalone?.Value;
+ break;
+ case "forcezipping":
+ dat.ClrMamePro.ForceZipping = reader.Standalone?.Value;
+ break;
+ case "forcepacking":
+ dat.ClrMamePro.ForcePacking = reader.Standalone?.Value;
+ break;
+ default:
+ headerAdditional.Add(reader.CurrentLine);
+ break;
+ }
+ }
+
+ // If we're in a game, machine, resource, or set block
+ else if ((reader.TopLevel == "game"
+ || reader.TopLevel == "machine"
+ || reader.TopLevel == "resource"
+ || reader.TopLevel == "set")
+ && reader.RowType == CmpRowType.Standalone)
+ {
+ // Create the block if we haven't already
+ game ??= reader.TopLevel switch
+ {
+ "game" => new Game(),
+ "machine" => new Machine(),
+ "resource" => new Resource(),
+ "set" => new Set(),
+ _ => throw new FormatException($"Unknown top-level block: {reader.TopLevel}"),
+ };
+
+ switch (reader.Standalone?.Key?.ToLowerInvariant())
+ {
+ case "name":
+ game.Name = reader.Standalone?.Value;
+ break;
+ case "description":
+ game.Description = reader.Standalone?.Value;
+ break;
+ case "year":
+ game.Year = reader.Standalone?.Value;
+ break;
+ case "manufacturer":
+ game.Manufacturer = reader.Standalone?.Value;
+ break;
+ case "category":
+ game.Category = reader.Standalone?.Value;
+ break;
+ case "cloneof":
+ game.CloneOf = reader.Standalone?.Value;
+ break;
+ case "romof":
+ game.RomOf = reader.Standalone?.Value;
+ break;
+ case "sampleof":
+ game.SampleOf = reader.Standalone?.Value;
+ break;
+ case "sample":
+ var sample = new Sample
+ {
+ Name = reader.Standalone?.Value ?? string.Empty,
+ ADDITIONAL_ELEMENTS = Array.Empty()
+ };
+ samples.Add(sample);
+ break;
+ default:
+ gameAdditional.Add(reader.CurrentLine);
+ break;
+ }
+ }
+
+ // If we're in an item block
+ else if ((reader.TopLevel == "game"
+ || reader.TopLevel == "machine"
+ || reader.TopLevel == "resource"
+ || reader.TopLevel == "set")
+ && game != null
+ && reader.RowType == CmpRowType.Internal)
+ {
+ // Create the block
+ switch (reader.InternalName)
+ {
+ case "release":
+ releases.Add(CreateRelease(reader));
+ break;
+ case "biosset":
+ biosSets.Add(CreateBiosSet(reader));
+ break;
+ case "rom":
+ roms.Add(CreateRom(reader));
+ break;
+ case "disk":
+ disks.Add(CreateDisk(reader));
+ break;
+ case "media":
+ medias.Add(CreateMedia(reader));
+ break;
+ case "sample":
+ samples.Add(CreateSample(reader));
+ break;
+ case "archive":
+ archives.Add(CreateArchive(reader));
+ break;
+ case "chip":
+ chips.Add(CreateChip(reader));
+ break;
+ case "video":
+ game.Video = CreateVideo(reader);
+ break;
+ case "sound":
+ game.Sound = CreateSound(reader);
+ break;
+ case "input":
+ game.Input = CreateInput(reader);
+ break;
+ case "dipswitch":
+ dipSwitches.Add(CreateDipSwitch(reader));
+ break;
+ case "driver":
+ game.Driver = CreateDriver(reader);
+ break;
+ default:
+ gameAdditional.Add(reader.CurrentLine);
+ continue;
+ }
+ }
+
+ else
+ {
+ additional.Add(reader.CurrentLine);
+ }
}
+
+ // Add extra pieces and return
+ dat.Game = games.ToArray();
+ dat.ADDITIONAL_ELEMENTS = additional.ToArray();
+ return dat;
}
///
diff --git a/SabreTools.Serialization/ClrMamePro.Serializer.cs b/SabreTools.Serialization/ClrMamePro.Serializer.cs
index 52fa24b4..0724201e 100644
--- a/SabreTools.Serialization/ClrMamePro.Serializer.cs
+++ b/SabreTools.Serialization/ClrMamePro.Serializer.cs
@@ -20,22 +20,14 @@ namespace SabreTools.Serialization
/// True on successful serialization, false otherwise
public static bool SerializeToFile(MetadataFile? metadataFile, string path, bool quotes)
{
- try
- {
- using var stream = SerializeToStream(metadataFile, quotes);
- 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, quotes);
+ if (stream == null)
return false;
- }
+
+ using var fs = File.OpenWrite(path);
+ stream.Seek(0, SeekOrigin.Begin);
+ stream.CopyTo(fs);
+ return true;
}
///
@@ -46,30 +38,22 @@ namespace SabreTools.Serialization
/// Stream containing serialized data on success, null otherwise
public static Stream? SerializeToStream(MetadataFile? metadataFile, bool quotes)
{
- try
- {
- // If the metadata file is null
- if (metadataFile == null)
- return null;
-
- // Setup the writer and output
- var stream = new MemoryStream();
- var writer = new ClrMameProWriter(stream, Encoding.UTF8) { Quotes = quotes };
-
- // Write the header, if it exists
- WriteHeader(metadataFile.ClrMamePro, writer);
-
- // Write out the games, if they exist
- WriteGames(metadataFile.Game, 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 ClrMameProWriter(stream, Encoding.UTF8) { Quotes = quotes };
+
+ // Write the header, if it exists
+ WriteHeader(metadataFile.ClrMamePro, writer);
+
+ // Write out the games, if they exist
+ WriteGames(metadataFile.Game, writer);
+
+ // Return the stream
+ return stream;
}
///
diff --git a/SabreTools.Serialization/EverdriveSMDB.Deserializer.cs b/SabreTools.Serialization/EverdriveSMDB.Deserializer.cs
index f736d9f2..9d99757e 100644
--- a/SabreTools.Serialization/EverdriveSMDB.Deserializer.cs
+++ b/SabreTools.Serialization/EverdriveSMDB.Deserializer.cs
@@ -19,16 +19,8 @@ namespace SabreTools.Serialization
/// Deserialized data on success, null on failure
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);
}
///
@@ -38,59 +30,51 @@ namespace SabreTools.Serialization
/// Deserialized data on success, null on failure
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();
- 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();
+ 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;
}
}
}
\ No newline at end of file
diff --git a/SabreTools.Serialization/EverdriveSMDB.Serializer.cs b/SabreTools.Serialization/EverdriveSMDB.Serializer.cs
index ed18821f..6cb44db6 100644
--- a/SabreTools.Serialization/EverdriveSMDB.Serializer.cs
+++ b/SabreTools.Serialization/EverdriveSMDB.Serializer.cs
@@ -20,22 +20,14 @@ namespace SabreTools.Serialization
/// True on successful serialization, false otherwise
public static bool SerializeToFile(MetadataFile? metadataFile, string path)
{
- try
- {
- using var stream = SerializeToStream(metadataFile);
- 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);
+ if (stream == null)
return false;
- }
+
+ using var fs = File.OpenWrite(path);
+ stream.Seek(0, SeekOrigin.Begin);
+ stream.CopyTo(fs);
+ return true;
}
///
@@ -45,27 +37,19 @@ namespace SabreTools.Serialization
/// Stream containing serialized data on success, null otherwise
public static Stream? SerializeToStream(MetadataFile? metadataFile)
{
- 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 = '\t', Quotes = false };
-
- // 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 = '\t', Quotes = false };
+
+ // Write out the rows, if they exist
+ WriteRows(metadataFile.Row, writer);
+
+ // Return the stream
+ return stream;
}
///
diff --git a/SabreTools.Serialization/Hashfile.Deserializer.cs b/SabreTools.Serialization/Hashfile.Deserializer.cs
index a2e2900e..54261d1d 100644
--- a/SabreTools.Serialization/Hashfile.Deserializer.cs
+++ b/SabreTools.Serialization/Hashfile.Deserializer.cs
@@ -19,16 +19,8 @@ namespace SabreTools.Serialization
/// Deserialized data on success, null on failure
public static Models.Hashfile.Hashfile? Deserialize(string path, Hash hash)
{
- try
- {
- using var stream = PathProcessor.OpenStream(path);
- return Deserialize(stream, hash);
- }
- catch
- {
- // TODO: Handle logging the exception
- return default;
- }
+ using var stream = PathProcessor.OpenStream(path);
+ return Deserialize(stream, hash);
}
///
@@ -39,122 +31,114 @@ namespace SabreTools.Serialization
/// Deserialized data on success, null on failure
public static Models.Hashfile.Hashfile? Deserialize(Stream? stream, Hash hash)
{
- try
+ // If the stream is null
+ if (stream == null)
+ return default;
+
+ // Setup the reader and output
+ var reader = new StreamReader(stream);
+ var dat = new Models.Hashfile.Hashfile();
+ var additional = new List();
+
+ // Loop through the rows and parse out values
+ var hashes = new List