[FileTypes/] Cleanup tabs AND variables

This commit is contained in:
Matt Nadareski
2019-02-08 20:51:44 -08:00
parent f04842851a
commit b09198708e
15 changed files with 4986 additions and 5022 deletions

View File

@@ -11,81 +11,20 @@ namespace SabreTools.Library.FileTypes
{ {
public class BaseFile public class BaseFile
{ {
#region Protected instance variables
protected FileType _fileType;
protected string _filename;
protected string _parent;
protected string _date;
// External hash values for the file
protected long? _size;
protected byte[] _crc;
protected byte[] _md5;
protected byte[] _sha1;
protected byte[] _sha256;
protected byte[] _sha384;
protected byte[] _sha512;
#endregion
#region Publicly facing variables #region Publicly facing variables
// TODO: Get all of these values automatically so there is no public "set" // TODO: Get all of these values automatically so there is no public "set"
public FileType Type public FileType Type { get; protected set; }
{ public string Filename { get; set; }
get { return _fileType; } public string Parent { get; set; }
} public string Date { get; set; }
public string Filename public long? Size { get; set; }
{ public byte[] CRC { get; set; }
get { return _filename; } public byte[] MD5 { get; set; }
set { _filename = value; } public byte[] SHA1 { get; set; }
} public byte[] SHA256 { get; set; }
public string Parent public byte[] SHA384 { get; set; }
{ public byte[] SHA512 { get; set; }
get { return _parent; }
set { _parent = value; }
}
public string Date
{
get { return _date; }
set { _date = value; }
}
public long? Size
{
get { return _size; }
set { _size = value; }
}
public byte[] CRC
{
get { return _crc; }
set { _crc = value; }
}
public byte[] MD5
{
get { return _md5; }
set { _md5 = value; }
}
public byte[] SHA1
{
get { return _sha1; }
set { _sha1 = value; }
}
public byte[] SHA256
{
get { return _sha256; }
set { _sha256 = value; }
}
public byte[] SHA384
{
get { return _sha384; }
set { _sha384 = value; }
}
public byte[] SHA512
{
get { return _sha512; }
set { _sha512 = value; }
}
#endregion #endregion
@@ -105,22 +44,22 @@ namespace SabreTools.Library.FileTypes
/// <param name="getHashes">True if hashes for this file should be calculated (default), false otherwise</param> /// <param name="getHashes">True if hashes for this file should be calculated (default), false otherwise</param>
public BaseFile(string filename, bool getHashes = true) public BaseFile(string filename, bool getHashes = true)
{ {
this._filename = filename; this.Filename = filename;
if (getHashes) if (getHashes)
{ {
BaseFile temp = Utilities.GetFileInfo(_filename); BaseFile temp = Utilities.GetFileInfo(this.Filename);
if (temp != null) if (temp != null)
{ {
this._parent = temp.Parent; this.Parent = temp.Parent;
this._date = temp.Date; this.Date = temp.Date;
this._crc = temp.CRC; this.CRC = temp.CRC;
this._md5 = temp.MD5; this.MD5 = temp.MD5;
this._sha1 = temp.SHA1; this.SHA1 = temp.SHA1;
this._sha256 = temp.SHA256; this.SHA256 = temp.SHA256;
this._sha384 = temp.SHA384; this.SHA384 = temp.SHA384;
this._sha512 = temp.SHA512; this.SHA512 = temp.SHA512;
} }
} }
} }
@@ -133,7 +72,7 @@ namespace SabreTools.Library.FileTypes
/// <param name="getHashes">True if hashes for this file should be calculated (default), false otherwise</param> /// <param name="getHashes">True if hashes for this file should be calculated (default), false otherwise</param>
public BaseFile(string filename, Stream stream, bool getHashes = true) public BaseFile(string filename, Stream stream, bool getHashes = true)
{ {
this._filename = filename; this.Filename = filename;
if (getHashes) if (getHashes)
{ {
@@ -141,19 +80,44 @@ namespace SabreTools.Library.FileTypes
if(temp != null) if(temp != null)
{ {
this._parent = temp.Parent; this.Parent = temp.Parent;
this._date = temp.Date; this.Date = temp.Date;
this._crc = temp.CRC; this.CRC = temp.CRC;
this._md5 = temp.MD5; this.MD5 = temp.MD5;
this._sha1 = temp.SHA1; this.SHA1 = temp.SHA1;
this._sha256 = temp.SHA256; this.SHA256 = temp.SHA256;
this._sha384 = temp.SHA384; this.SHA384 = temp.SHA384;
this._sha512 = temp.SHA512; this.SHA512 = temp.SHA512;
} }
} }
} }
/// <summary>
/// Create a new BaseFile from the given metadata
/// </summary>
/// <param name="filename">Name of the file to use</param>
/// <param name="parent">Parent folder or archive</param>
/// <param name="date">File date</param>
/// <param name="crc">CRC hash as a byte array</param>
/// <param name="md5">MD5 hash as a byte array</param>
/// <param name="sha1">SHA-1 hash as a byte array</param>
/// <param name="sha256">SHA-256 hash as a byte array</param>
/// <param name="sha384">SHA-384 hash as a byte array</param>
/// <param name="sha512">SHA-512 hash as a byte array</param>
public BaseFile(string filename, string parent, string date, byte[] crc, byte[] md5, byte[] sha1, byte[] sha256, byte[] sha384, byte[] sha512)
{
this.Filename = filename;
this.Parent = parent;
this.Date = date;
this.CRC = crc;
this.MD5 = md5;
this.SHA1 = sha1;
this.SHA256 = sha256;
this.SHA384 = sha384;
this.SHA512 = sha512;
}
#endregion #endregion
} }
} }

View File

@@ -136,7 +136,7 @@ namespace SabreTools.Library.FileTypes
/// </summary> /// </summary>
public CHDFile() public CHDFile()
{ {
this._fileType = FileType.CHD; this.Type = FileType.CHD;
} }
/// <summary> /// <summary>
@@ -154,7 +154,7 @@ namespace SabreTools.Library.FileTypes
/// <param name="chdstream">Stream representing the CHD file</param> /// <param name="chdstream">Stream representing the CHD file</param>
public CHDFile(Stream chdstream) public CHDFile(Stream chdstream)
{ {
_fileType = FileType.CHD; this.Type = FileType.CHD;
m_br = new BinaryReader(chdstream); m_br = new BinaryReader(chdstream);
_headerVersion = ValidateHeaderVersion(); _headerVersion = ValidateHeaderVersion();
@@ -167,11 +167,11 @@ namespace SabreTools.Library.FileTypes
{ {
if (hash.Length == Constants.MD5Length) if (hash.Length == Constants.MD5Length)
{ {
_md5 = hash; this.MD5 = hash;
} }
else if (hash.Length == Constants.SHA1Length) else if (hash.Length == Constants.SHA1Length)
{ {
_sha1 = hash; this.SHA1 = hash;
} }
} }
} }

View File

@@ -42,7 +42,7 @@ namespace SabreTools.Library.FileTypes
public Folder() public Folder()
: base() : base()
{ {
_fileType = FileType.Folder; this.Type = FileType.Folder;
} }
/// <summary> /// <summary>
@@ -54,7 +54,7 @@ namespace SabreTools.Library.FileTypes
public Folder(string filename, bool getHashes = false) public Folder(string filename, bool getHashes = false)
: base(filename, getHashes) : base(filename, getHashes)
{ {
_fileType = FileType.Folder; this.Type = FileType.Folder;
} }
#endregion #endregion
@@ -72,10 +72,10 @@ namespace SabreTools.Library.FileTypes
try try
{ {
// Make sure the folders exist // Make sure the folders exist
Directory.CreateDirectory(_filename); Directory.CreateDirectory(this.Filename);
Directory.CreateDirectory(outDir); Directory.CreateDirectory(outDir);
Directory.Copy(_filename, outDir, true, PathFormat.FullPath); Directory.Copy(this.Filename, outDir, true, PathFormat.FullPath);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -100,11 +100,11 @@ namespace SabreTools.Library.FileTypes
try try
{ {
// Make sure the folders exist // Make sure the folders exist
Directory.CreateDirectory(_filename); Directory.CreateDirectory(this.Filename);
Directory.CreateDirectory(outDir); Directory.CreateDirectory(outDir);
// Get all files from the input directory // Get all files from the input directory
List<string> files = Utilities.RetrieveFiles(_filename, new List<string>()); List<string> files = Utilities.RetrieveFiles(this.Filename, new List<string>());
// Now sort through to find the first file that matches // Now sort through to find the first file that matches
string match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault(); string match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault();
@@ -140,10 +140,10 @@ namespace SabreTools.Library.FileTypes
try try
{ {
// Make sure the folders exist // Make sure the folders exist
Directory.CreateDirectory(_filename); Directory.CreateDirectory(this.Filename);
// Get all files from the input directory // Get all files from the input directory
List<string> files = Utilities.RetrieveFiles(_filename, new List<string>()); List<string> files = Utilities.RetrieveFiles(this.Filename, new List<string>());
// Now sort through to find the first file that matches // Now sort through to find the first file that matches
string match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault(); string match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault();
@@ -180,12 +180,12 @@ namespace SabreTools.Library.FileTypes
if (_children == null || _children.Count == 0) if (_children == null || _children.Count == 0)
{ {
_children = new List<BaseFile>(); _children = new List<BaseFile>();
foreach (string file in Directory.EnumerateFiles(_filename, "*", SearchOption.TopDirectoryOnly)) foreach (string file in Directory.EnumerateFiles(this.Filename, "*", SearchOption.TopDirectoryOnly))
{ {
BaseFile nf = Utilities.GetFileInfo(file, omitFromScan: omitFromScan, date: date); BaseFile nf = Utilities.GetFileInfo(file, omitFromScan: omitFromScan, date: date);
_children.Add(nf); _children.Add(nf);
} }
foreach (string dir in Directory.EnumerateDirectories(_filename, "*", SearchOption.TopDirectoryOnly)) foreach (string dir in Directory.EnumerateDirectories(this.Filename, "*", SearchOption.TopDirectoryOnly))
{ {
Folder fl = new Folder(dir); Folder fl = new Folder(dir);
_children.Add(fl); _children.Add(fl);
@@ -202,7 +202,7 @@ namespace SabreTools.Library.FileTypes
/// <returns>List of empty folders in the folder</returns> /// <returns>List of empty folders in the folder</returns>
public virtual List<string> GetEmptyFolders() public virtual List<string> GetEmptyFolders()
{ {
return Utilities.GetEmptyDirectories(_filename).ToList(); return Utilities.GetEmptyDirectories(this.Filename).ToList();
} }
#endregion #endregion

View File

@@ -37,7 +37,7 @@ namespace SabreTools.Library.FileTypes
public GZipArchive() public GZipArchive()
: base() : base()
{ {
_fileType = FileType.GZipArchive; this.Type = FileType.GZipArchive;
} }
/// <summary> /// <summary>
@@ -49,7 +49,7 @@ namespace SabreTools.Library.FileTypes
public GZipArchive(string filename, bool getHashes = false) public GZipArchive(string filename, bool getHashes = false)
: base(filename, getHashes) : base(filename, getHashes)
{ {
_fileType = FileType.GZipArchive; this.Type = FileType.GZipArchive;
} }
#endregion #endregion
@@ -71,8 +71,8 @@ namespace SabreTools.Library.FileTypes
Directory.CreateDirectory(outDir); Directory.CreateDirectory(outDir);
// Decompress the _filename stream // Decompress the _filename stream
FileStream outstream = Utilities.TryCreate(Path.Combine(outDir, Path.GetFileNameWithoutExtension(_filename))); FileStream outstream = Utilities.TryCreate(Path.Combine(outDir, Path.GetFileNameWithoutExtension(this.Filename)));
GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(_filename), Ionic.Zlib.CompressionMode.Decompress); GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(this.Filename), Ionic.Zlib.CompressionMode.Decompress);
gzstream.CopyTo(outstream); gzstream.CopyTo(outstream);
// Dispose of the streams // Dispose of the streams
@@ -158,8 +158,8 @@ namespace SabreTools.Library.FileTypes
try try
{ {
// Decompress the _filename stream // Decompress the _filename stream
realEntry = Path.GetFileNameWithoutExtension(_filename); realEntry = Path.GetFileNameWithoutExtension(this.Filename);
GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(_filename), Ionic.Zlib.CompressionMode.Decompress); GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(this.Filename), Ionic.Zlib.CompressionMode.Decompress);
// Write the file out // Write the file out
byte[] gbuffer = new byte[_bufferSize]; byte[] gbuffer = new byte[_bufferSize];
@@ -201,7 +201,7 @@ namespace SabreTools.Library.FileTypes
{ {
_children = new List<BaseFile>(); _children = new List<BaseFile>();
string gamename = Path.GetFileNameWithoutExtension(_filename); string gamename = Path.GetFileNameWithoutExtension(this.Filename);
BaseFile possibleTgz = GetTorrentGZFileInfo(); BaseFile possibleTgz = GetTorrentGZFileInfo();
@@ -221,7 +221,7 @@ namespace SabreTools.Library.FileTypes
{ {
Filename = gamename, Filename = gamename,
}; };
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(_filename)); BinaryReader br = new BinaryReader(Utilities.TryOpenRead(this.Filename));
br.BaseStream.Seek(-8, SeekOrigin.End); br.BaseStream.Seek(-8, SeekOrigin.End);
byte[] headercrc = br.ReadBytesReverse(4); byte[] headercrc = br.ReadBytesReverse(4);
tempRom.CRC = headercrc; tempRom.CRC = headercrc;
@@ -233,7 +233,7 @@ namespace SabreTools.Library.FileTypes
// Otherwise, use the stream directly // Otherwise, use the stream directly
else else
{ {
GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(_filename), Ionic.Zlib.CompressionMode.Decompress); GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(this.Filename), Ionic.Zlib.CompressionMode.Decompress);
BaseFile gzipEntryRom = Utilities.GetStreamInfo(gzstream, gzstream.Length, omitFromScan: omitFromScan); BaseFile gzipEntryRom = Utilities.GetStreamInfo(gzstream, gzstream.Length, omitFromScan: omitFromScan);
gzipEntryRom.Filename = gzstream.FileName; gzipEntryRom.Filename = gzstream.FileName;
gzipEntryRom.Parent = gamename; gzipEntryRom.Parent = gamename;
@@ -270,32 +270,32 @@ namespace SabreTools.Library.FileTypes
public override bool IsTorrent() public override bool IsTorrent()
{ {
// Check for the file existing first // Check for the file existing first
if (!File.Exists(_filename)) if (!File.Exists(this.Filename))
{ {
return false; return false;
} }
string datum = Path.GetFileName(_filename).ToLowerInvariant(); string datum = Path.GetFileName(this.Filename).ToLowerInvariant();
long filesize = new FileInfo(_filename).Length; long filesize = new FileInfo(this.Filename).Length;
// If we have the romba depot files, just skip them gracefully // If we have the romba depot files, just skip them gracefully
if (datum == ".romba_size" || datum == ".romba_size.backup") if (datum == ".romba_size" || datum == ".romba_size.backup")
{ {
Globals.Logger.Verbose("Romba depot file found, skipping: {0}", _filename); Globals.Logger.Verbose("Romba depot file found, skipping: {0}", this.Filename);
return false; return false;
} }
// Check if the name is the right length // Check if the name is the right length
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz")) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz")) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length
{ {
Globals.Logger.Warning("Non SHA-1 filename found, skipping: '{0}'", Path.GetFullPath(_filename)); Globals.Logger.Warning("Non SHA-1 filename found, skipping: '{0}'", Path.GetFullPath(this.Filename));
return false; return false;
} }
// Check if the file is at least the minimum length // Check if the file is at least the minimum length
if (filesize < 40 /* bytes */) if (filesize < 40 /* bytes */)
{ {
Globals.Logger.Warning("Possibly corrupt file '{0}' with size {1}", Path.GetFullPath(_filename), Utilities.GetBytesReadable(filesize)); Globals.Logger.Warning("Possibly corrupt file '{0}' with size {1}", Path.GetFullPath(this.Filename), Utilities.GetBytesReadable(filesize));
return false; return false;
} }
@@ -304,7 +304,7 @@ namespace SabreTools.Library.FileTypes
byte[] headermd5; // MD5 byte[] headermd5; // MD5
byte[] headercrc; // CRC byte[] headercrc; // CRC
ulong headersz; // Int64 size ulong headersz; // Int64 size
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(_filename)); BinaryReader br = new BinaryReader(Utilities.TryOpenRead(this.Filename));
header = br.ReadBytes(12); header = br.ReadBytes(12);
headermd5 = br.ReadBytes(16); headermd5 = br.ReadBytes(16);
headercrc = br.ReadBytes(4); headercrc = br.ReadBytes(4);
@@ -337,32 +337,32 @@ namespace SabreTools.Library.FileTypes
public BaseFile GetTorrentGZFileInfo() public BaseFile GetTorrentGZFileInfo()
{ {
// Check for the file existing first // Check for the file existing first
if (!File.Exists(_filename)) if (!File.Exists(this.Filename))
{ {
return null; return null;
} }
string datum = Path.GetFileName(_filename).ToLowerInvariant(); string datum = Path.GetFileName(this.Filename).ToLowerInvariant();
long filesize = new FileInfo(_filename).Length; long filesize = new FileInfo(this.Filename).Length;
// If we have the romba depot files, just skip them gracefully // If we have the romba depot files, just skip them gracefully
if (datum == ".romba_size" || datum == ".romba_size.backup") if (datum == ".romba_size" || datum == ".romba_size.backup")
{ {
Globals.Logger.Verbose("Romba depot file found, skipping: {0}", _filename); Globals.Logger.Verbose("Romba depot file found, skipping: {0}", this.Filename);
return null; return null;
} }
// Check if the name is the right length // Check if the name is the right length
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz")) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz")) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length
{ {
Globals.Logger.Warning("Non SHA-1 filename found, skipping: '{0}'", Path.GetFullPath(_filename)); Globals.Logger.Warning("Non SHA-1 filename found, skipping: '{0}'", Path.GetFullPath(this.Filename));
return null; return null;
} }
// Check if the file is at least the minimum length // Check if the file is at least the minimum length
if (filesize < 40 /* bytes */) if (filesize < 40 /* bytes */)
{ {
Globals.Logger.Warning("Possibly corrupt file '{0}' with size {1}", Path.GetFullPath(_filename), Utilities.GetBytesReadable(filesize)); Globals.Logger.Warning("Possibly corrupt file '{0}' with size {1}", Path.GetFullPath(this.Filename), Utilities.GetBytesReadable(filesize));
return null; return null;
} }
@@ -371,7 +371,7 @@ namespace SabreTools.Library.FileTypes
byte[] headermd5; // MD5 byte[] headermd5; // MD5
byte[] headercrc; // CRC byte[] headercrc; // CRC
ulong headersz; // Int64 size ulong headersz; // Int64 size
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(_filename)); BinaryReader br = new BinaryReader(Utilities.TryOpenRead(this.Filename));
header = br.ReadBytes(12); header = br.ReadBytes(12);
headermd5 = br.ReadBytes(16); headermd5 = br.ReadBytes(16);
headercrc = br.ReadBytes(4); headercrc = br.ReadBytes(4);
@@ -399,13 +399,13 @@ namespace SabreTools.Library.FileTypes
BaseFile baseFile = new BaseFile BaseFile baseFile = new BaseFile
{ {
Filename = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(), Filename = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(),
Size = extractedsize, Size = extractedsize,
CRC = headercrc, CRC = headercrc,
MD5 = headermd5, MD5 = headermd5,
SHA1 = Utilities.StringToByteArray(Path.GetFileNameWithoutExtension(_filename)), // TODO: When updating to SHA-256, this needs to update to SHA256 SHA1 = Utilities.StringToByteArray(Path.GetFileNameWithoutExtension(this.Filename)), // TODO: When updating to SHA-256, this needs to update to SHA256
Parent = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(), Parent = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(),
}; };
return baseFile; return baseFile;

View File

@@ -27,7 +27,7 @@ namespace SabreTools.Library.FileTypes
public LRZipArchive() public LRZipArchive()
: base() : base()
{ {
_fileType = FileType.LRZipArchive; this.Type = FileType.LRZipArchive;
} }
/// <summary> /// <summary>
@@ -38,7 +38,7 @@ namespace SabreTools.Library.FileTypes
public LRZipArchive(string filename, bool getHashes = false) public LRZipArchive(string filename, bool getHashes = false)
: base(filename, getHashes) : base(filename, getHashes)
{ {
_fileType = FileType.LRZipArchive; this.Type = FileType.LRZipArchive;
} }
#endregion #endregion

View File

@@ -27,7 +27,7 @@ namespace SabreTools.Library.FileTypes
public LZ4Archive() public LZ4Archive()
: base() : base()
{ {
_fileType = FileType.LZ4Archive; this.Type = FileType.LZ4Archive;
} }
/// <summary> /// <summary>
@@ -38,7 +38,7 @@ namespace SabreTools.Library.FileTypes
public LZ4Archive(string filename, bool getHashes = false) public LZ4Archive(string filename, bool getHashes = false)
: base(filename, getHashes) : base(filename, getHashes)
{ {
_fileType = FileType.LZ4Archive; this.Type = FileType.LZ4Archive;
} }
#endregion #endregion

View File

@@ -37,7 +37,7 @@ namespace SabreTools.Library.FileTypes
public RarArchive() public RarArchive()
: base() : base()
{ {
_fileType = FileType.RarArchive; this.Type = FileType.RarArchive;
} }
/// <summary> /// <summary>
@@ -49,7 +49,7 @@ namespace SabreTools.Library.FileTypes
public RarArchive(string filename, bool getHashes = false) public RarArchive(string filename, bool getHashes = false)
: base(filename, getHashes) : base(filename, getHashes)
{ {
_fileType = FileType.RarArchive; this.Type = FileType.RarArchive;
} }
#endregion #endregion
@@ -71,7 +71,7 @@ namespace SabreTools.Library.FileTypes
Directory.CreateDirectory(outDir); Directory.CreateDirectory(outDir);
// Extract all files to the temp directory // Extract all files to the temp directory
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(_filename); SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(this.Filename);
foreach (RarArchiveEntry entry in ra.Entries) foreach (RarArchiveEntry entry in ra.Entries)
{ {
entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true }); entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true });
@@ -155,7 +155,7 @@ namespace SabreTools.Library.FileTypes
try try
{ {
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(_filename, new ReaderOptions { LeaveStreamOpen = false, }); SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false, });
foreach (RarArchiveEntry entry in ra.Entries) foreach (RarArchiveEntry entry in ra.Entries)
{ {
if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName)) if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName))
@@ -191,11 +191,11 @@ namespace SabreTools.Library.FileTypes
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false) public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
{ {
List<BaseFile> found = new List<BaseFile>(); List<BaseFile> found = new List<BaseFile>();
string gamename = Path.GetFileNameWithoutExtension(_filename); string gamename = Path.GetFileNameWithoutExtension(this.Filename);
try try
{ {
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(Utilities.TryOpenRead(_filename)); SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(Utilities.TryOpenRead(this.Filename));
foreach (RarArchiveEntry entry in ra.Entries.Where(e => e != null && !e.IsDirectory)) foreach (RarArchiveEntry entry in ra.Entries.Where(e => e != null && !e.IsDirectory))
{ {
// If secure hashes are disabled, do a quickscan // If secure hashes are disabled, do a quickscan
@@ -242,12 +242,12 @@ namespace SabreTools.Library.FileTypes
/// TODO: Write the rest of this RAR file handling /// TODO: Write the rest of this RAR file handling
public void GetRarFileInfo() public void GetRarFileInfo()
{ {
if (!File.Exists(_filename)) if (!File.Exists(this.Filename))
{ {
return; return;
} }
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(_filename)); BinaryReader br = new BinaryReader(Utilities.TryOpenRead(this.Filename));
// Check for the signature first (Skipping the SFX Module) // Check for the signature first (Skipping the SFX Module)
byte[] signature = br.ReadBytes(8); byte[] signature = br.ReadBytes(8);
@@ -464,7 +464,7 @@ namespace SabreTools.Library.FileTypes
try try
{ {
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(_filename, new ReaderOptions { LeaveStreamOpen = false }); SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false });
List<RarArchiveEntry> rarEntries = ra.Entries.OrderBy(e => e.Key, new NaturalSort.NaturalReversedComparer()).ToList(); List<RarArchiveEntry> rarEntries = ra.Entries.OrderBy(e => e.Key, new NaturalSort.NaturalReversedComparer()).ToList();
string lastRarEntry = null; string lastRarEntry = null;
foreach (RarArchiveEntry entry in rarEntries) foreach (RarArchiveEntry entry in rarEntries)

View File

@@ -40,7 +40,7 @@ namespace SabreTools.Library.FileTypes
public SevenZipArchive() public SevenZipArchive()
: base() : base()
{ {
_fileType = FileType.SevenZipArchive; this.Type = FileType.SevenZipArchive;
} }
/// <summary> /// <summary>
@@ -52,7 +52,7 @@ namespace SabreTools.Library.FileTypes
public SevenZipArchive(string filename, bool getHashes = false) public SevenZipArchive(string filename, bool getHashes = false)
: base(filename, getHashes) : base(filename, getHashes)
{ {
_fileType = FileType.SevenZipArchive; this.Type = FileType.SevenZipArchive;
} }
#endregion #endregion
@@ -74,7 +74,7 @@ namespace SabreTools.Library.FileTypes
Directory.CreateDirectory(outDir); Directory.CreateDirectory(outDir);
// Extract all files to the temp directory // Extract all files to the temp directory
SharpCompress.Archives.SevenZip.SevenZipArchive sza = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(Utilities.TryOpenRead(_filename)); SharpCompress.Archives.SevenZip.SevenZipArchive sza = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(Utilities.TryOpenRead(this.Filename));
foreach (SevenZipArchiveEntry entry in sza.Entries) foreach (SevenZipArchiveEntry entry in sza.Entries)
{ {
entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true }); entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true });
@@ -158,7 +158,7 @@ namespace SabreTools.Library.FileTypes
try try
{ {
SharpCompress.Archives.SevenZip.SevenZipArchive sza = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(_filename, new ReaderOptions { LeaveStreamOpen = false, }); SharpCompress.Archives.SevenZip.SevenZipArchive sza = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false, });
foreach (SevenZipArchiveEntry entry in sza.Entries) foreach (SevenZipArchiveEntry entry in sza.Entries)
{ {
if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName)) if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName))
@@ -195,11 +195,11 @@ namespace SabreTools.Library.FileTypes
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false) public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
{ {
List<BaseFile> found = new List<BaseFile>(); List<BaseFile> found = new List<BaseFile>();
string gamename = Path.GetFileNameWithoutExtension(_filename); string gamename = Path.GetFileNameWithoutExtension(this.Filename);
try try
{ {
SharpCompress.Archives.SevenZip.SevenZipArchive sza = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(Utilities.TryOpenRead(_filename)); SharpCompress.Archives.SevenZip.SevenZipArchive sza = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(Utilities.TryOpenRead(this.Filename));
foreach (SevenZipArchiveEntry entry in sza.Entries.Where(e => e != null && !e.IsDirectory)) foreach (SevenZipArchiveEntry entry in sza.Entries.Where(e => e != null && !e.IsDirectory))
{ {
// If secure hashes are disabled, do a quickscan // If secure hashes are disabled, do a quickscan
@@ -251,7 +251,7 @@ namespace SabreTools.Library.FileTypes
try try
{ {
SharpCompress.Archives.SevenZip.SevenZipArchive sza = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(_filename, new ReaderOptions { LeaveStreamOpen = false }); SharpCompress.Archives.SevenZip.SevenZipArchive sza = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false });
List<SevenZipArchiveEntry> sevenZipEntries = sza.Entries.OrderBy(e => e.Key, new NaturalSort.NaturalReversedComparer()).ToList(); List<SevenZipArchiveEntry> sevenZipEntries = sza.Entries.OrderBy(e => e.Key, new NaturalSort.NaturalReversedComparer()).ToList();
string lastSevenZipEntry = null; string lastSevenZipEntry = null;
foreach (SevenZipArchiveEntry entry in sevenZipEntries) foreach (SevenZipArchiveEntry entry in sevenZipEntries)
@@ -288,11 +288,11 @@ namespace SabreTools.Library.FileTypes
{ {
bool ist7z = false; bool ist7z = false;
if (File.Exists(_filename)) if (File.Exists(this.Filename))
{ {
try try
{ {
Stream fread = Utilities.TryOpenRead(_filename); Stream fread = Utilities.TryOpenRead(this.Filename);
uint ar, offs = 0; uint ar, offs = 0;
fread.Seek(0, SeekOrigin.Begin); fread.Seek(0, SeekOrigin.Begin);
byte[] buffer = new byte[128]; byte[] buffer = new byte[128];
@@ -314,7 +314,7 @@ namespace SabreTools.Library.FileTypes
} }
catch catch
{ {
Globals.Logger.Warning("File '{0}' could not be opened", _filename); Globals.Logger.Warning("File '{0}' could not be opened", this.Filename);
ist7z = false; ist7z = false;
} }
} }

View File

@@ -40,7 +40,7 @@ namespace SabreTools.Library.FileTypes
public TapeArchive() public TapeArchive()
: base() : base()
{ {
_fileType = FileType.TapeArchive; this.Type = FileType.TapeArchive;
} }
/// <summary> /// <summary>
@@ -52,7 +52,7 @@ namespace SabreTools.Library.FileTypes
public TapeArchive(string filename, bool getHashes = false) public TapeArchive(string filename, bool getHashes = false)
: base(filename, getHashes) : base(filename, getHashes)
{ {
_fileType = FileType.TapeArchive; this.Type = FileType.TapeArchive;
} }
#endregion #endregion
@@ -74,7 +74,7 @@ namespace SabreTools.Library.FileTypes
Directory.CreateDirectory(outDir); Directory.CreateDirectory(outDir);
// Extract all files to the temp directory // Extract all files to the temp directory
TarArchive ta = TarArchive.Open(_filename); TarArchive ta = TarArchive.Open(this.Filename);
foreach (TarArchiveEntry entry in ta.Entries) foreach (TarArchiveEntry entry in ta.Entries)
{ {
entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true }); entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true });
@@ -158,7 +158,7 @@ namespace SabreTools.Library.FileTypes
try try
{ {
TarArchive ta = TarArchive.Open(_filename, new ReaderOptions { LeaveStreamOpen = false, }); TarArchive ta = TarArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false, });
foreach (TarArchiveEntry entry in ta.Entries) foreach (TarArchiveEntry entry in ta.Entries)
{ {
if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName)) if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName))
@@ -194,11 +194,11 @@ namespace SabreTools.Library.FileTypes
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false) public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
{ {
List<BaseFile> found = new List<BaseFile>(); List<BaseFile> found = new List<BaseFile>();
string gamename = Path.GetFileNameWithoutExtension(_filename); string gamename = Path.GetFileNameWithoutExtension(this.Filename);
try try
{ {
TarArchive ta = TarArchive.Open(Utilities.TryOpenRead(_filename)); TarArchive ta = TarArchive.Open(Utilities.TryOpenRead(this.Filename));
foreach (TarArchiveEntry entry in ta.Entries.Where(e => e != null && !e.IsDirectory)) foreach (TarArchiveEntry entry in ta.Entries.Where(e => e != null && !e.IsDirectory))
{ {
// If secure hashes are disabled, do a quickscan // If secure hashes are disabled, do a quickscan
@@ -250,7 +250,7 @@ namespace SabreTools.Library.FileTypes
try try
{ {
TarArchive ta = TarArchive.Open(_filename, new ReaderOptions { LeaveStreamOpen = false }); TarArchive ta = TarArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false });
List<TarArchiveEntry> tarEntries = ta.Entries.OrderBy(e => e.Key, new NaturalSort.NaturalReversedComparer()).ToList(); List<TarArchiveEntry> tarEntries = ta.Entries.OrderBy(e => e.Key, new NaturalSort.NaturalReversedComparer()).ToList();
string lastTarEntry = null; string lastTarEntry = null;
foreach (TarArchiveEntry entry in tarEntries) foreach (TarArchiveEntry entry in tarEntries)

View File

@@ -40,7 +40,7 @@ namespace SabreTools.Library.FileTypes
public XZArchive() public XZArchive()
: base() : base()
{ {
_fileType = FileType.XZArchive; this.Type = FileType.XZArchive;
} }
/// <summary> /// <summary>
@@ -52,7 +52,7 @@ namespace SabreTools.Library.FileTypes
public XZArchive(string filename, bool getHashes = false) public XZArchive(string filename, bool getHashes = false)
: base(filename, getHashes) : base(filename, getHashes)
{ {
_fileType = FileType.XZArchive; this.Type = FileType.XZArchive;
} }
#endregion #endregion
@@ -74,7 +74,7 @@ namespace SabreTools.Library.FileTypes
Directory.CreateDirectory(outDir); Directory.CreateDirectory(outDir);
// Extract all files to the temp directory // Extract all files to the temp directory
SharpCompress.Archives.SevenZip.SevenZipArchive sza = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(Utilities.TryOpenRead(_filename)); SharpCompress.Archives.SevenZip.SevenZipArchive sza = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(Utilities.TryOpenRead(this.Filename));
foreach (SevenZipArchiveEntry entry in sza.Entries) foreach (SevenZipArchiveEntry entry in sza.Entries)
{ {
entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true }); entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true });
@@ -158,7 +158,7 @@ namespace SabreTools.Library.FileTypes
try try
{ {
SharpCompress.Archives.SevenZip.SevenZipArchive sza = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(_filename, new ReaderOptions { LeaveStreamOpen = false, }); SharpCompress.Archives.SevenZip.SevenZipArchive sza = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false, });
foreach (SevenZipArchiveEntry entry in sza.Entries) foreach (SevenZipArchiveEntry entry in sza.Entries)
{ {
if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName)) if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName))

View File

@@ -27,7 +27,7 @@ namespace SabreTools.Library.FileTypes
public ZPAQArchive() public ZPAQArchive()
: base() : base()
{ {
_fileType = FileType.ZPAQArchive; this.Type = FileType.ZPAQArchive;
} }
/// <summary> /// <summary>
@@ -38,7 +38,7 @@ namespace SabreTools.Library.FileTypes
public ZPAQArchive(string filename, bool getHashes = false) public ZPAQArchive(string filename, bool getHashes = false)
: base(filename, getHashes) : base(filename, getHashes)
{ {
_fileType = FileType.ZPAQArchive; this.Type = FileType.ZPAQArchive;
} }
#endregion #endregion

View File

@@ -35,7 +35,7 @@ namespace SabreTools.Library.FileTypes
public ZipArchive() public ZipArchive()
: base() : base()
{ {
_fileType = FileType.ZipArchive; this.Type = FileType.ZipArchive;
} }
/// <summary> /// <summary>
@@ -47,7 +47,7 @@ namespace SabreTools.Library.FileTypes
public ZipArchive(string filename, bool getHashes = false) public ZipArchive(string filename, bool getHashes = false)
: base(filename, getHashes) : base(filename, getHashes)
{ {
_fileType = FileType.ZipArchive; this.Type = FileType.ZipArchive;
} }
#endregion #endregion
@@ -70,7 +70,7 @@ namespace SabreTools.Library.FileTypes
// Extract all files to the temp directory // Extract all files to the temp directory
ZipFile zf = new ZipFile(); ZipFile zf = new ZipFile();
ZipReturn zr = zf.Open(_filename, new FileInfo(_filename).LastWriteTime.Ticks, true); ZipReturn zr = zf.Open(this.Filename, new FileInfo(this.Filename).LastWriteTime.Ticks, true);
if (zr != ZipReturn.ZipGood) if (zr != ZipReturn.ZipGood)
{ {
throw new Exception(ZipFile.ZipErrorMessageText(zr)); throw new Exception(ZipFile.ZipErrorMessageText(zr));
@@ -201,7 +201,7 @@ namespace SabreTools.Library.FileTypes
try try
{ {
ZipFile zf = new ZipFile(); ZipFile zf = new ZipFile();
ZipReturn zr = zf.Open(_filename, new FileInfo(_filename).LastWriteTime.Ticks, true); ZipReturn zr = zf.Open(this.Filename, new FileInfo(this.Filename).LastWriteTime.Ticks, true);
if (zr != ZipReturn.ZipGood) if (zr != ZipReturn.ZipGood)
{ {
throw new Exception(ZipFile.ZipErrorMessageText(zr)); throw new Exception(ZipFile.ZipErrorMessageText(zr));
@@ -271,12 +271,12 @@ namespace SabreTools.Library.FileTypes
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false) public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
{ {
List<BaseFile> found = new List<BaseFile>(); List<BaseFile> found = new List<BaseFile>();
string gamename = Path.GetFileNameWithoutExtension(_filename); string gamename = Path.GetFileNameWithoutExtension(this.Filename);
try try
{ {
ZipFile zf = new ZipFile(); ZipFile zf = new ZipFile();
ZipReturn zr = zf.Open(_filename, new FileInfo(_filename).LastWriteTime.Ticks, true); ZipReturn zr = zf.Open(this.Filename, new FileInfo(this.Filename).LastWriteTime.Ticks, true);
if (zr != ZipReturn.ZipGood) if (zr != ZipReturn.ZipGood)
{ {
throw new Exception(ZipFile.ZipErrorMessageText(zr)); throw new Exception(ZipFile.ZipErrorMessageText(zr));
@@ -290,7 +290,7 @@ namespace SabreTools.Library.FileTypes
// If we get a read error, log it and continue // If we get a read error, log it and continue
if (zr != ZipReturn.ZipGood) if (zr != ZipReturn.ZipGood)
{ {
Globals.Logger.Warning("An error occurred while reading archive {0}: Zip Error - {1}", _filename, zr); Globals.Logger.Warning("An error occurred while reading archive {0}: Zip Error - {1}", this.Filename, zr);
continue; continue;
} }
@@ -356,7 +356,7 @@ namespace SabreTools.Library.FileTypes
try try
{ {
SharpCompress.Archives.Zip.ZipArchive za = SharpCompress.Archives.Zip.ZipArchive.Open(_filename, new ReaderOptions { LeaveStreamOpen = false }); SharpCompress.Archives.Zip.ZipArchive za = SharpCompress.Archives.Zip.ZipArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false });
List<SharpCompress.Archives.Zip.ZipArchiveEntry> zipEntries = za.Entries.OrderBy(e => e.Key, new NaturalSort.NaturalReversedComparer()).ToList(); List<SharpCompress.Archives.Zip.ZipArchiveEntry> zipEntries = za.Entries.OrderBy(e => e.Key, new NaturalSort.NaturalReversedComparer()).ToList();
string lastZipEntry = null; string lastZipEntry = null;
foreach (SharpCompress.Archives.Zip.ZipArchiveEntry entry in zipEntries) foreach (SharpCompress.Archives.Zip.ZipArchiveEntry entry in zipEntries)

View File

@@ -27,7 +27,7 @@ namespace SabreTools.Library.FileTypes
public ZstdArchive() public ZstdArchive()
: base() : base()
{ {
_fileType = FileType.ZstdArchive; this.Type = FileType.ZstdArchive;
} }
/// <summary> /// <summary>
@@ -38,7 +38,7 @@ namespace SabreTools.Library.FileTypes
public ZstdArchive(string filename, bool getHashes) public ZstdArchive(string filename, bool getHashes)
: base(filename, getHashes) : base(filename, getHashes)
{ {
_fileType = FileType.ZstdArchive; this.Type = FileType.ZstdArchive;
} }
#endregion #endregion