2024-03-04 23:56:05 -05:00
|
|
|
|
using SabreTools.Hashing;
|
2017-10-09 18:04:49 -07:00
|
|
|
|
|
2020-12-09 22:11:35 -08:00
|
|
|
|
namespace SabreTools.DatFiles.Formats
|
2017-10-09 18:04:49 -07:00
|
|
|
|
{
|
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>
|
2024-03-04 23:56:05 -05:00
|
|
|
|
public Hashfile(DatFile? datFile, HashType hash)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
: 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>
|
2024-03-04 23:56:05 -05:00
|
|
|
|
private static Serialization.Hash ConvertHash(HashType hash)
|
2023-09-11 10:27:17 -04:00
|
|
|
|
{
|
|
|
|
|
|
return hash switch
|
|
|
|
|
|
{
|
2024-03-04 23:56:05 -05:00
|
|
|
|
HashType.CRC32 => Serialization.Hash.CRC,
|
|
|
|
|
|
HashType.MD5 => Serialization.Hash.MD5,
|
|
|
|
|
|
HashType.SHA1 => Serialization.Hash.SHA1,
|
|
|
|
|
|
HashType.SHA256 => Serialization.Hash.SHA256,
|
|
|
|
|
|
HashType.SHA384 => Serialization.Hash.SHA384,
|
|
|
|
|
|
HashType.SHA512 => Serialization.Hash.SHA512,
|
|
|
|
|
|
HashType.SpamSum => Serialization.Hash.SpamSum,
|
2024-02-28 19:19:50 -05:00
|
|
|
|
_ => throw new System.ArgumentOutOfRangeException(nameof(hash)),
|
2023-09-11 10:27:17 -04:00
|
|
|
|
};
|
2019-01-11 13:43:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-09 18:04:49 -07:00
|
|
|
|
}
|