using System.IO;
using SabreTools.Library.DatFiles;
using SabreTools.Library.IO;
namespace SabreTools.Library.FileTypes
{
public class BaseFile
{
// TODO: Get all of these values automatically so there is no public "set"
#region Fields
///
/// Internal type of the represented file
///
public FileType Type { get; protected set; }
///
/// Filename or path to the file
///
public string Filename { get; set; }
///
/// Direct parent of the file
///
public string Parent { get; set; }
///
/// Date stamp of the file
///
public string Date { get; set; }
///
/// Optional size of the file
///
public long? Size { get; set; }
///
/// Hashes that are available for the file
///
public Hash AvailableHashes { get; set; } = Hash.Standard;
///
/// CRC32 hash of the file
///
public byte[] CRC { get; set; } = null;
///
/// MD5 hash of the file
///
public byte[] MD5 { get; set; } = null;
#if NET_FRAMEWORK
///
/// RIPEMD160 hash of the file
///
public byte[] RIPEMD160 { get; set; } = null;
#endif
///
/// SHA-1 hash of the file
///
public byte[] SHA1 { get; set; } = null;
///
/// SHA-256 hash of the file
///
public byte[] SHA256 { get; set; } = null;
///
/// SHA-384 hash of the file
///
public byte[] SHA384 { get; set; } = null;
///
/// SHA-512 hash of the file
///
public byte[] SHA512 { get; set; } = null;
///
/// SpamSum fuzzy hash of the file
///
public byte[] SpamSum { get; set; } = null;
#endregion
#region Construtors
///
/// Create a new BaseFile with no base file
///
public BaseFile()
{
}
///
/// Create a new BaseFile from the given file
///
/// Name of the file to use
/// True if hashes for this file should be calculated (default), false otherwise
public BaseFile(string filename, bool getHashes = true)
{
this.Filename = filename;
if (getHashes)
{
BaseFile temp = FileExtensions.GetInfo(this.Filename, hashes: this.AvailableHashes);
if (temp != null)
{
this.Parent = temp.Parent;
this.Date = temp.Date;
this.CRC = temp.CRC;
this.MD5 = temp.MD5;
#if NET_FRAMEWORK
this.RIPEMD160 = temp.RIPEMD160;
#endif
this.SHA1 = temp.SHA1;
this.SHA256 = temp.SHA256;
this.SHA384 = temp.SHA384;
this.SHA512 = temp.SHA512;
this.SpamSum = temp.SpamSum;
}
}
}
///
/// Create a new BaseFile from the given file
///
/// Name of the file to use
/// Stream to populate information from
/// True if hashes for this file should be calculated (default), false otherwise
public BaseFile(string filename, Stream stream, bool getHashes = true)
{
this.Filename = filename;
if (getHashes)
{
BaseFile temp = stream.GetInfo(hashes: this.AvailableHashes);
if (temp != null)
{
this.Parent = temp.Parent;
this.Date = temp.Date;
this.CRC = temp.CRC;
this.MD5 = temp.MD5;
#if NET_FRAMEWORK
this.RIPEMD160 = temp.RIPEMD160;
#endif
this.SHA1 = temp.SHA1;
this.SHA256 = temp.SHA256;
this.SHA384 = temp.SHA384;
this.SHA512 = temp.SHA512;
this.SpamSum = temp.SpamSum;
}
}
}
#endregion
}
}