Files
SabreTools/SabreTools.DatFiles/Formats/Hashfile.cs

43 lines
1.4 KiB
C#
Raw Normal View History

2023-07-28 21:34:34 -04:00
using SabreTools.Core;
namespace SabreTools.DatFiles.Formats
{
2019-01-11 13:43:15 -08:00
/// <summary>
2023-07-28 21:34:34 -04:00
/// Represents a hashfile such as an SFV, MD5, or SHA-1 file
2019-01-11 13:43:15 -08:00
/// </summary>
2023-07-28 21:34:34 -04:00
internal partial class Hashfile : DatFile
2019-01-11 13:43:15 -08:00
{
// Private instance variables specific to Hashfile DATs
2023-09-11 10:27:17 -04:00
private readonly Serialization.Hash _hash;
2019-01-11 13:43:15 -08:00
/// <summary>
/// Constructor designed for casting a base DatFile
/// </summary>
/// <param name="datFile">Parent DatFile to copy from</param>
/// <param name="hash">Type of hash that is associated with this DAT</param>
public Hashfile(DatFile? datFile, Hash hash)
: base(datFile)
2019-01-11 13:43:15 -08:00
{
2023-09-11 10:27:17 -04:00
_hash = ConvertHash(hash);
}
/// <summary>
/// Convert hash types between internal and Serialization
/// </summary>
private Serialization.Hash ConvertHash(Hash hash)
{
return hash switch
{
Hash.CRC => Serialization.Hash.CRC,
Hash.MD5 => Serialization.Hash.MD5,
Hash.SHA1 => Serialization.Hash.SHA1,
Hash.SHA256 => Serialization.Hash.SHA256,
Hash.SHA384 => Serialization.Hash.SHA384,
Hash.SHA512 => Serialization.Hash.SHA512,
Hash.SpamSum => Serialization.Hash.SpamSum,
_ => throw new System.ArgumentOutOfRangeException(),
};
2019-01-11 13:43:15 -08:00
}
}
}