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:
@@ -6,55 +6,55 @@ namespace SabreTools.Models.SeparatedValue
|
|||||||
public class Row
|
public class Row
|
||||||
{
|
{
|
||||||
/// <remarks>File Name</remarks>
|
/// <remarks>File Name</remarks>
|
||||||
public string FileName { get; set; }
|
public string? FileName { get; set; }
|
||||||
|
|
||||||
/// <remarks>Internal Name</remarks>
|
/// <remarks>Internal Name</remarks>
|
||||||
public string InternalName { get; set; }
|
public string? InternalName { get; set; }
|
||||||
|
|
||||||
/// <remarks>Description</remarks>
|
/// <remarks>Description</remarks>
|
||||||
public string Description { get; set; }
|
public string? Description { get; set; }
|
||||||
|
|
||||||
/// <remarks>Game Name</remarks>
|
/// <remarks>Game Name</remarks>
|
||||||
public string GameName { get; set; }
|
public string GameName { get; set; }
|
||||||
|
|
||||||
/// <remarks>Game Description</remarks>
|
/// <remarks>Game Description</remarks>
|
||||||
public string GameDescription { get; set; }
|
public string? GameDescription { get; set; }
|
||||||
|
|
||||||
/// <remarks>Type</remarks>
|
/// <remarks>Type</remarks>
|
||||||
public string Type { get; set; }
|
public string Type { get; set; }
|
||||||
|
|
||||||
/// <remarks>Rom Name</remarks>
|
/// <remarks>Rom Name</remarks>
|
||||||
public string RomName { get; set; }
|
public string? RomName { get; set; }
|
||||||
|
|
||||||
/// <remarks>Disk Name</remarks>
|
/// <remarks>Disk Name</remarks>
|
||||||
public string DiskName { get; set; }
|
public string? DiskName { get; set; }
|
||||||
|
|
||||||
/// <remarks>Size, Numeric</remarks>
|
/// <remarks>Size, Numeric</remarks>
|
||||||
public string Size { get; set; }
|
public string? Size { get; set; }
|
||||||
|
|
||||||
/// <remarks>CRC</remarks>
|
/// <remarks>CRC</remarks>
|
||||||
public string CRC { get; set; }
|
public string? CRC { get; set; }
|
||||||
|
|
||||||
/// <remarks>MD5</remarks>
|
/// <remarks>MD5</remarks>
|
||||||
public string MD5 { get; set; }
|
public string? MD5 { get; set; }
|
||||||
|
|
||||||
/// <remarks>SHA1</remarks>
|
/// <remarks>SHA1</remarks>
|
||||||
public string SHA1 { get; set; }
|
public string? SHA1 { get; set; }
|
||||||
|
|
||||||
/// <remarks>SHA256</remarks>
|
/// <remarks>SHA256</remarks>
|
||||||
public string SHA256 { get; set; }
|
public string? SHA256 { get; set; }
|
||||||
|
|
||||||
/// <remarks>SHA384, Optional</remarks>
|
/// <remarks>SHA384, Optional</remarks>
|
||||||
public string SHA384 { get; set; }
|
public string? SHA384 { get; set; }
|
||||||
|
|
||||||
/// <remarks>SHA512, Optional</remarks>
|
/// <remarks>SHA512, Optional</remarks>
|
||||||
public string SHA512 { get; set; }
|
public string? SHA512 { get; set; }
|
||||||
|
|
||||||
/// <remarks>SpamSum, Optional</remarks>
|
/// <remarks>SpamSum, Optional</remarks>
|
||||||
public string SpamSum { get; set; }
|
public string? SpamSum { get; set; }
|
||||||
|
|
||||||
/// <remarks>Status, Nodump</remarks>
|
/// <remarks>Status, Nodump</remarks>
|
||||||
public string Status { get; set; }
|
public string? Status { get; set; }
|
||||||
|
|
||||||
#region DO NOT USE IN PRODUCTION
|
#region DO NOT USE IN PRODUCTION
|
||||||
|
|
||||||
|
|||||||
@@ -18,18 +18,10 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="path">Path to the file to deserialize</param>
|
/// <param name="path">Path to the file to deserialize</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static MetadataFile? Deserialize(string path)
|
public static MetadataFile? Deserialize(string path)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = PathProcessor.OpenStream(path);
|
using var stream = PathProcessor.OpenStream(path);
|
||||||
return Deserialize(stream);
|
return Deserialize(stream);
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserializes an AttractMode romlist in a stream to the defined type
|
/// Deserializes an AttractMode romlist in a stream to the defined type
|
||||||
@@ -37,8 +29,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="stream">Stream to deserialize</param>
|
/// <param name="stream">Stream to deserialize</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static MetadataFile? Deserialize(Stream? stream)
|
public static MetadataFile? Deserialize(Stream? stream)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the stream is null
|
// If the stream is null
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -130,11 +120,5 @@ namespace SabreTools.Serialization
|
|||||||
dat.Row = rows.ToArray();
|
dat.Row = rows.ToArray();
|
||||||
return dat;
|
return dat;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,8 +18,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="path">Path to the file to serialize to</param>
|
/// <param name="path">Path to the file to serialize to</param>
|
||||||
/// <returns>True on successful serialization, false otherwise</returns>
|
/// <returns>True on successful serialization, false otherwise</returns>
|
||||||
public static bool SerializeToFile(MetadataFile? metadataFile, string path)
|
public static bool SerializeToFile(MetadataFile? metadataFile, string path)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = SerializeToStream(metadataFile);
|
using var stream = SerializeToStream(metadataFile);
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -30,12 +28,6 @@ namespace SabreTools.Serialization
|
|||||||
stream.CopyTo(fs);
|
stream.CopyTo(fs);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes the defined type to a stream
|
/// Serializes the defined type to a stream
|
||||||
@@ -43,8 +35,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="metadataFile">Data to serialize</param>
|
/// <param name="metadataFile">Data to serialize</param>
|
||||||
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
||||||
public static Stream? SerializeToStream(MetadataFile? metadataFile)
|
public static Stream? SerializeToStream(MetadataFile? metadataFile)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the metadata file is null
|
// If the metadata file is null
|
||||||
if (metadataFile == null)
|
if (metadataFile == null)
|
||||||
@@ -52,7 +42,12 @@ namespace SabreTools.Serialization
|
|||||||
|
|
||||||
// Setup the writer and output
|
// Setup the writer and output
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
var writer = new SeparatedValueWriter(stream, Encoding.UTF8) { Separator = ';', Quotes = false };
|
var writer = new SeparatedValueWriter(stream, Encoding.UTF8)
|
||||||
|
{
|
||||||
|
Separator = ';',
|
||||||
|
Quotes = false,
|
||||||
|
VerifyFieldCount = false,
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: Include flag to write out long or short header
|
// TODO: Include flag to write out long or short header
|
||||||
// Write the short header
|
// Write the short header
|
||||||
@@ -64,12 +59,6 @@ namespace SabreTools.Serialization
|
|||||||
// Return the stream
|
// Return the stream
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write rows information to the current writer
|
/// Write rows information to the current writer
|
||||||
@@ -85,7 +74,7 @@ namespace SabreTools.Serialization
|
|||||||
// Loop through and write out the rows
|
// Loop through and write out the rows
|
||||||
foreach (var row in rows)
|
foreach (var row in rows)
|
||||||
{
|
{
|
||||||
var rowArray = new string[]
|
var rowArray = new string?[]
|
||||||
{
|
{
|
||||||
row.Name,
|
row.Name,
|
||||||
row.Title,
|
row.Title,
|
||||||
|
|||||||
@@ -18,18 +18,10 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="quotes">Enable quotes on read, false otherwise</param>
|
/// <param name="quotes">Enable quotes on read, false otherwise</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static MetadataFile? Deserialize(string path, bool quotes)
|
public static MetadataFile? Deserialize(string path, bool quotes)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = PathProcessor.OpenStream(path);
|
using var stream = PathProcessor.OpenStream(path);
|
||||||
return Deserialize(stream, quotes);
|
return Deserialize(stream, quotes);
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserializes a ClrMamePro metadata file in a stream to the defined type
|
/// Deserializes a ClrMamePro metadata file in a stream to the defined type
|
||||||
@@ -38,8 +30,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="quotes">Enable quotes on read, false otherwise</param>
|
/// <param name="quotes">Enable quotes on read, false otherwise</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static MetadataFile? Deserialize(Stream? stream, bool quotes)
|
public static MetadataFile? Deserialize(Stream? stream, bool quotes)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the stream is null
|
// If the stream is null
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -333,12 +323,6 @@ namespace SabreTools.Serialization
|
|||||||
dat.ADDITIONAL_ELEMENTS = additional.ToArray();
|
dat.ADDITIONAL_ELEMENTS = additional.ToArray();
|
||||||
return dat;
|
return dat;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a Release object from the current reader context
|
/// Create a Release object from the current reader context
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="quotes">Enable quotes on write, false otherwise</param>
|
/// <param name="quotes">Enable quotes on write, false otherwise</param>
|
||||||
/// <returns>True on successful serialization, false otherwise</returns>
|
/// <returns>True on successful serialization, false otherwise</returns>
|
||||||
public static bool SerializeToFile(MetadataFile? metadataFile, string path, bool quotes)
|
public static bool SerializeToFile(MetadataFile? metadataFile, string path, bool quotes)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = SerializeToStream(metadataFile, quotes);
|
using var stream = SerializeToStream(metadataFile, quotes);
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -31,12 +29,6 @@ namespace SabreTools.Serialization
|
|||||||
stream.CopyTo(fs);
|
stream.CopyTo(fs);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes the defined type to a stream
|
/// Serializes the defined type to a stream
|
||||||
@@ -45,8 +37,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="quotes">Enable quotes on write, false otherwise</param>
|
/// <param name="quotes">Enable quotes on write, false otherwise</param>
|
||||||
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
||||||
public static Stream? SerializeToStream(MetadataFile? metadataFile, bool quotes)
|
public static Stream? SerializeToStream(MetadataFile? metadataFile, bool quotes)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the metadata file is null
|
// If the metadata file is null
|
||||||
if (metadataFile == null)
|
if (metadataFile == null)
|
||||||
@@ -65,12 +55,6 @@ namespace SabreTools.Serialization
|
|||||||
// Return the stream
|
// Return the stream
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write header information to the current writer
|
/// Write header information to the current writer
|
||||||
|
|||||||
@@ -18,18 +18,10 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="path">Path to the file to deserialize</param>
|
/// <param name="path">Path to the file to deserialize</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static MetadataFile? Deserialize(string path)
|
public static MetadataFile? Deserialize(string path)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = PathProcessor.OpenStream(path);
|
using var stream = PathProcessor.OpenStream(path);
|
||||||
return Deserialize(stream);
|
return Deserialize(stream);
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserializes an Everdrive SMDB in a stream to the defined type
|
/// Deserializes an Everdrive SMDB in a stream to the defined type
|
||||||
@@ -37,8 +29,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="stream">Stream to deserialize</param>
|
/// <param name="stream">Stream to deserialize</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static MetadataFile? Deserialize(Stream? stream)
|
public static MetadataFile? Deserialize(Stream? stream)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the stream is null
|
// If the stream is null
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -86,11 +76,5 @@ namespace SabreTools.Serialization
|
|||||||
dat.Row = rows.ToArray();
|
dat.Row = rows.ToArray();
|
||||||
return dat;
|
return dat;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,8 +19,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="path">Path to the file to serialize to</param>
|
/// <param name="path">Path to the file to serialize to</param>
|
||||||
/// <returns>True on successful serialization, false otherwise</returns>
|
/// <returns>True on successful serialization, false otherwise</returns>
|
||||||
public static bool SerializeToFile(MetadataFile? metadataFile, string path)
|
public static bool SerializeToFile(MetadataFile? metadataFile, string path)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = SerializeToStream(metadataFile);
|
using var stream = SerializeToStream(metadataFile);
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -31,12 +29,6 @@ namespace SabreTools.Serialization
|
|||||||
stream.CopyTo(fs);
|
stream.CopyTo(fs);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes the defined type to a stream
|
/// Serializes the defined type to a stream
|
||||||
@@ -44,8 +36,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="metadataFile">Data to serialize</param>
|
/// <param name="metadataFile">Data to serialize</param>
|
||||||
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
||||||
public static Stream? SerializeToStream(MetadataFile? metadataFile)
|
public static Stream? SerializeToStream(MetadataFile? metadataFile)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the metadata file is null
|
// If the metadata file is null
|
||||||
if (metadataFile == null)
|
if (metadataFile == null)
|
||||||
@@ -61,12 +51,6 @@ namespace SabreTools.Serialization
|
|||||||
// Return the stream
|
// Return the stream
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write rows information to the current writer
|
/// Write rows information to the current writer
|
||||||
|
|||||||
@@ -18,18 +18,10 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="hash">Hash corresponding to the hashfile variant</param>
|
/// <param name="hash">Hash corresponding to the hashfile variant</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static Models.Hashfile.Hashfile? Deserialize(string path, Hash hash)
|
public static Models.Hashfile.Hashfile? Deserialize(string path, Hash hash)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = PathProcessor.OpenStream(path);
|
using var stream = PathProcessor.OpenStream(path);
|
||||||
return Deserialize(stream, hash);
|
return Deserialize(stream, hash);
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserializes a hashfile variant in a stream to the defined type
|
/// Deserializes a hashfile variant in a stream to the defined type
|
||||||
@@ -38,8 +30,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="hash">Hash corresponding to the hashfile variant</param>
|
/// <param name="hash">Hash corresponding to the hashfile variant</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static Models.Hashfile.Hashfile? Deserialize(Stream? stream, Hash hash)
|
public static Models.Hashfile.Hashfile? Deserialize(Stream? stream, Hash hash)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the stream is null
|
// If the stream is null
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -150,11 +140,5 @@ namespace SabreTools.Serialization
|
|||||||
dat.ADDITIONAL_ELEMENTS = additional.ToArray();
|
dat.ADDITIONAL_ELEMENTS = additional.ToArray();
|
||||||
return dat;
|
return dat;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,8 +21,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="hash">Hash corresponding to the hashfile variant</param>
|
/// <param name="hash">Hash corresponding to the hashfile variant</param>
|
||||||
/// <returns>True on successful serialization, false otherwise</returns>
|
/// <returns>True on successful serialization, false otherwise</returns>
|
||||||
public static bool SerializeToFile(Models.Hashfile.Hashfile? hashfile, string path, Hash hash)
|
public static bool SerializeToFile(Models.Hashfile.Hashfile? hashfile, string path, Hash hash)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = SerializeToStream(hashfile, hash);
|
using var stream = SerializeToStream(hashfile, hash);
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -33,12 +31,6 @@ namespace SabreTools.Serialization
|
|||||||
stream.CopyTo(fs);
|
stream.CopyTo(fs);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes the defined type to a stream
|
/// Serializes the defined type to a stream
|
||||||
@@ -47,8 +39,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="hash">Hash corresponding to the hashfile variant</param>
|
/// <param name="hash">Hash corresponding to the hashfile variant</param>
|
||||||
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
||||||
public static Stream? SerializeToStream(Models.Hashfile.Hashfile? hashfile, Hash hash)
|
public static Stream? SerializeToStream(Models.Hashfile.Hashfile? hashfile, Hash hash)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the metadata file is null
|
// If the metadata file is null
|
||||||
if (hashfile == null)
|
if (hashfile == null)
|
||||||
@@ -56,7 +46,12 @@ namespace SabreTools.Serialization
|
|||||||
|
|
||||||
// Setup the writer and output
|
// Setup the writer and output
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
var writer = new SeparatedValueWriter(stream, Encoding.UTF8) { Separator = ' ', Quotes = false };
|
var writer = new SeparatedValueWriter(stream, Encoding.UTF8)
|
||||||
|
{
|
||||||
|
Separator = ' ',
|
||||||
|
Quotes = false,
|
||||||
|
VerifyFieldCount = false,
|
||||||
|
};
|
||||||
|
|
||||||
// Write out the items, if they exist
|
// Write out the items, if they exist
|
||||||
switch (hash)
|
switch (hash)
|
||||||
@@ -89,12 +84,6 @@ namespace SabreTools.Serialization
|
|||||||
// Return the stream
|
// Return the stream
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write SFV information to the current writer
|
/// Write SFV information to the current writer
|
||||||
|
|||||||
@@ -17,18 +17,10 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="path">Path to the file to deserialize</param>
|
/// <param name="path">Path to the file to deserialize</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static MetadataFile? Deserialize(string path)
|
public static MetadataFile? Deserialize(string path)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = PathProcessor.OpenStream(path);
|
using var stream = PathProcessor.OpenStream(path);
|
||||||
return Deserialize(stream);
|
return Deserialize(stream);
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserializes a MAME listrom file in a stream to the defined type
|
/// Deserializes a MAME listrom file in a stream to the defined type
|
||||||
@@ -36,8 +28,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="stream">Stream to deserialize</param>
|
/// <param name="stream">Stream to deserialize</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static MetadataFile? Deserialize(Stream? stream)
|
public static MetadataFile? Deserialize(Stream? stream)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the stream is null
|
// If the stream is null
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -187,11 +177,5 @@ namespace SabreTools.Serialization
|
|||||||
dat.ADDITIONAL_ELEMENTS = additional.ToArray();
|
dat.ADDITIONAL_ELEMENTS = additional.ToArray();
|
||||||
return dat;
|
return dat;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,18 +18,10 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="path">Path to the file to deserialize</param>
|
/// <param name="path">Path to the file to deserialize</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static MetadataFile? Deserialize(string path)
|
public static MetadataFile? Deserialize(string path)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = PathProcessor.OpenStream(path);
|
using var stream = PathProcessor.OpenStream(path);
|
||||||
return Deserialize(stream);
|
return Deserialize(stream);
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserializes a RomCenter INI file in a stream to the defined type
|
/// Deserializes a RomCenter INI file in a stream to the defined type
|
||||||
@@ -37,8 +29,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="stream">Stream to deserialize</param>
|
/// <param name="stream">Stream to deserialize</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static MetadataFile? Deserialize(Stream? stream)
|
public static MetadataFile? Deserialize(Stream? stream)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the stream is null
|
// If the stream is null
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -230,11 +220,5 @@ namespace SabreTools.Serialization
|
|||||||
}
|
}
|
||||||
return dat;
|
return dat;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,18 +19,10 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="delim">Character delimiter between values</param>
|
/// <param name="delim">Character delimiter between values</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static MetadataFile? Deserialize(string path, char delim)
|
public static MetadataFile? Deserialize(string path, char delim)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = PathProcessor.OpenStream(path);
|
using var stream = PathProcessor.OpenStream(path);
|
||||||
return Deserialize(stream, delim);
|
return Deserialize(stream, delim);
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserializes a separated-value variant in a stream to the defined type
|
/// Deserializes a separated-value variant in a stream to the defined type
|
||||||
@@ -39,8 +31,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="delim">Character delimiter between values</param>
|
/// <param name="delim">Character delimiter between values</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static MetadataFile? Deserialize(Stream? stream, char delim)
|
public static MetadataFile? Deserialize(Stream? stream, char delim)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the stream is null
|
// If the stream is null
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -129,11 +119,5 @@ namespace SabreTools.Serialization
|
|||||||
dat.Row = rows.ToArray();
|
dat.Row = rows.ToArray();
|
||||||
return dat;
|
return dat;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,8 +19,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="delim">Character delimiter between values</param>
|
/// <param name="delim">Character delimiter between values</param>
|
||||||
/// <returns>True on successful serialization, false otherwise</returns>
|
/// <returns>True on successful serialization, false otherwise</returns>
|
||||||
public static bool SerializeToFile(MetadataFile? metadataFile, string path, char delim)
|
public static bool SerializeToFile(MetadataFile? metadataFile, string path, char delim)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = SerializeToStream(metadataFile, delim);
|
using var stream = SerializeToStream(metadataFile, delim);
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -31,12 +29,6 @@ namespace SabreTools.Serialization
|
|||||||
stream.CopyTo(fs);
|
stream.CopyTo(fs);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes the defined type to a stream
|
/// Serializes the defined type to a stream
|
||||||
@@ -45,8 +37,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="delim">Character delimiter between values</param>
|
/// <param name="delim">Character delimiter between values</param>
|
||||||
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
||||||
public static Stream? SerializeToStream(MetadataFile? metadataFile, char delim)
|
public static Stream? SerializeToStream(MetadataFile? metadataFile, char delim)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the metadata file is null
|
// If the metadata file is null
|
||||||
if (metadataFile == null)
|
if (metadataFile == null)
|
||||||
@@ -66,12 +56,6 @@ namespace SabreTools.Serialization
|
|||||||
// Return the stream
|
// Return the stream
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write header information to the current writer
|
/// Write header information to the current writer
|
||||||
@@ -79,7 +63,7 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="writer">SeparatedValueWriter representing the output</param>
|
/// <param name="writer">SeparatedValueWriter representing the output</param>
|
||||||
private static void WriteHeader(SeparatedValueWriter writer)
|
private static void WriteHeader(SeparatedValueWriter writer)
|
||||||
{
|
{
|
||||||
var headerArray = new string[]
|
var headerArray = new string?[]
|
||||||
{
|
{
|
||||||
"File Name",
|
"File Name",
|
||||||
"Internal Name",
|
"Internal Name",
|
||||||
@@ -118,7 +102,7 @@ namespace SabreTools.Serialization
|
|||||||
// Loop through and write out the rows
|
// Loop through and write out the rows
|
||||||
foreach (var row in rows)
|
foreach (var row in rows)
|
||||||
{
|
{
|
||||||
var rowArray = new string[]
|
var rowArray = new string?[]
|
||||||
{
|
{
|
||||||
row.FileName,
|
row.FileName,
|
||||||
row.InternalName,
|
row.InternalName,
|
||||||
|
|||||||
@@ -15,18 +15,10 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="path">Path to the file to deserialize</param>
|
/// <param name="path">Path to the file to deserialize</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static T? Deserialize(string path)
|
public static T? Deserialize(string path)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = PathProcessor.OpenStream(path);
|
using var stream = PathProcessor.OpenStream(path);
|
||||||
return Deserialize(stream);
|
return Deserialize(stream);
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserializes an XML file in a stream to the defined type
|
/// Deserializes an XML file in a stream to the defined type
|
||||||
@@ -34,8 +26,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="stream">Stream to deserialize</param>
|
/// <param name="stream">Stream to deserialize</param>
|
||||||
/// <returns>Deserialized data on success, null on failure</returns>
|
/// <returns>Deserialized data on success, null on failure</returns>
|
||||||
public static T? Deserialize(Stream? stream)
|
public static T? Deserialize(Stream? stream)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the stream is null
|
// If the stream is null
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -54,11 +44,5 @@ namespace SabreTools.Serialization
|
|||||||
// Perform the deserialization and return
|
// Perform the deserialization and return
|
||||||
return (T?)serializer.Deserialize(xmlReader);
|
return (T?)serializer.Deserialize(xmlReader);
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,8 +16,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="path">Path to the file to serialize to</param>
|
/// <param name="path">Path to the file to serialize to</param>
|
||||||
/// <returns>True on successful serialization, false otherwise</returns>
|
/// <returns>True on successful serialization, false otherwise</returns>
|
||||||
public static bool SerializeToFile(T? obj, string path)
|
public static bool SerializeToFile(T? obj, string path)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using var stream = SerializeToStream(obj);
|
using var stream = SerializeToStream(obj);
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
@@ -27,12 +25,6 @@ namespace SabreTools.Serialization
|
|||||||
stream.CopyTo(fs);
|
stream.CopyTo(fs);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes the defined type to a stream
|
/// Serializes the defined type to a stream
|
||||||
@@ -40,8 +32,6 @@ namespace SabreTools.Serialization
|
|||||||
/// <param name="obj">Data to serialize</param>
|
/// <param name="obj">Data to serialize</param>
|
||||||
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
/// <returns>Stream containing serialized data on success, null otherwise</returns>
|
||||||
public static Stream? SerializeToStream(T? obj)
|
public static Stream? SerializeToStream(T? obj)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// If the object is null
|
// If the object is null
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
@@ -61,11 +51,5 @@ namespace SabreTools.Serialization
|
|||||||
serializer.Serialize(xmlWriter, obj);
|
serializer.Serialize(xmlWriter, obj);
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// TODO: Handle logging the exception
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user