using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Core;
namespace SabreTools.Serialization
{
///
/// Deserializer for hashfile variants
///
public partial class Hashfile
{
///
/// Deserializes a hashfile variant to the defined type
///
/// Path to the file to deserialize
/// Hash corresponding to the hashfile variant
/// 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;
}
}
///
/// Deserializes a hashfile variant in a stream to the defined type
///
/// Stream to deserialize
/// Hash corresponding to the hashfile variant
/// 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