2016-06-10 01:38:58 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2016-05-16 11:59:33 -07:00
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.Helper
|
2016-04-12 15:03:47 -07:00
|
|
|
|
{
|
2016-08-29 14:43:31 -07:00
|
|
|
|
#region Dat-to-Hash structs
|
|
|
|
|
|
|
2016-08-29 13:05:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Intermediate struct for holding and processing hash data
|
|
|
|
|
|
/// </summary>
|
2016-08-29 14:43:31 -07:00
|
|
|
|
public struct Hash : IEquatable<Hash>
|
2016-08-29 13:05:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
public long Size;
|
|
|
|
|
|
public string CRC;
|
|
|
|
|
|
public string MD5;
|
|
|
|
|
|
public string SHA1;
|
|
|
|
|
|
|
2016-08-29 14:43:31 -07:00
|
|
|
|
public bool Equals(Hash other)
|
2016-08-29 13:05:32 -07:00
|
|
|
|
{
|
2016-08-29 13:23:47 -07:00
|
|
|
|
return this.Equals(other, false);
|
2016-08-29 13:05:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-29 14:43:31 -07:00
|
|
|
|
public bool Equals(Hash other, bool IsDisk)
|
2016-08-29 13:05:32 -07:00
|
|
|
|
{
|
2016-08-29 13:23:47 -07:00
|
|
|
|
bool equals = false;
|
2016-08-29 13:13:00 -07:00
|
|
|
|
|
2016-08-29 20:45:20 -07:00
|
|
|
|
if (IsDisk &&
|
2016-08-29 13:23:47 -07:00
|
|
|
|
((String.IsNullOrEmpty(this.MD5) || String.IsNullOrEmpty(other.MD5)) || this.MD5 == other.MD5) &&
|
|
|
|
|
|
((String.IsNullOrEmpty(this.SHA1) || String.IsNullOrEmpty(other.SHA1)) || this.SHA1 == other.SHA1))
|
|
|
|
|
|
{
|
|
|
|
|
|
equals = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (!IsDisk &&
|
|
|
|
|
|
(this.Size == other.Size) &&
|
|
|
|
|
|
((String.IsNullOrEmpty(this.CRC) || String.IsNullOrEmpty(other.CRC)) || this.CRC == other.CRC) &&
|
|
|
|
|
|
((String.IsNullOrEmpty(this.MD5) || String.IsNullOrEmpty(other.MD5)) || this.MD5 == other.MD5) &&
|
|
|
|
|
|
((String.IsNullOrEmpty(this.SHA1) || String.IsNullOrEmpty(other.SHA1)) || this.SHA1 == other.SHA1))
|
|
|
|
|
|
{
|
|
|
|
|
|
equals = true;
|
2016-08-29 13:13:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-29 13:23:47 -07:00
|
|
|
|
return equals;
|
2016-08-29 13:05:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-29 14:43:31 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Skipper structs
|
|
|
|
|
|
|
2016-06-16 22:17:58 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Intermediate struct for holding header skipper information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public struct Skipper
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Name;
|
|
|
|
|
|
public string Author;
|
|
|
|
|
|
public string Version;
|
|
|
|
|
|
public List<SkipperRule> Rules;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-16 19:36:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Intermediate struct for holding header skipper rule information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public struct SkipperRule
|
|
|
|
|
|
{
|
2016-06-16 22:17:58 -07:00
|
|
|
|
public long? StartOffset; // null is EOF
|
|
|
|
|
|
public long? EndOffset; // null if EOF
|
|
|
|
|
|
public HeaderSkipOperation Operation;
|
|
|
|
|
|
public List<SkipperTest> Tests;
|
2016-06-16 19:36:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Intermediate struct for holding header test information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public struct SkipperTest
|
|
|
|
|
|
{
|
2016-06-16 22:17:58 -07:00
|
|
|
|
public HeaderSkipTest Type;
|
|
|
|
|
|
public long? Offset; // null is EOF
|
|
|
|
|
|
public byte[] Value;
|
|
|
|
|
|
public bool Result;
|
|
|
|
|
|
public byte[] Mask;
|
|
|
|
|
|
public long? Size; // null is PO2, "power of 2" filesize
|
|
|
|
|
|
public HeaderSkipTestFileOperator Operator;
|
2016-06-16 19:36:05 -07:00
|
|
|
|
}
|
2016-08-29 14:43:31 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2016-04-12 15:03:47 -07:00
|
|
|
|
}
|