mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[FileTypes/] Cleanup tabs AND variables
This commit is contained in:
@@ -11,81 +11,20 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
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
|
||||
|
||||
// TODO: Get all of these values automatically so there is no public "set"
|
||||
public FileType Type
|
||||
{
|
||||
get { return _fileType; }
|
||||
}
|
||||
public string Filename
|
||||
{
|
||||
get { return _filename; }
|
||||
set { _filename = value; }
|
||||
}
|
||||
public string Parent
|
||||
{
|
||||
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; }
|
||||
}
|
||||
public FileType Type { get; protected set; }
|
||||
public string Filename { get; set; }
|
||||
public string Parent { get; set; }
|
||||
public string Date { get; set; }
|
||||
public long? Size { get; set; }
|
||||
public byte[] CRC { get; set; }
|
||||
public byte[] MD5 { get; set; }
|
||||
public byte[] SHA1 { get; set; }
|
||||
public byte[] SHA256 { get; set; }
|
||||
public byte[] SHA384 { get; set; }
|
||||
public byte[] SHA512 { get; set; }
|
||||
|
||||
#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>
|
||||
public BaseFile(string filename, bool getHashes = true)
|
||||
{
|
||||
this._filename = filename;
|
||||
this.Filename = filename;
|
||||
|
||||
if (getHashes)
|
||||
{
|
||||
BaseFile temp = Utilities.GetFileInfo(_filename);
|
||||
BaseFile temp = Utilities.GetFileInfo(this.Filename);
|
||||
|
||||
if (temp != null)
|
||||
{
|
||||
this._parent = temp.Parent;
|
||||
this._date = temp.Date;
|
||||
this._crc = temp.CRC;
|
||||
this._md5 = temp.MD5;
|
||||
this._sha1 = temp.SHA1;
|
||||
this._sha256 = temp.SHA256;
|
||||
this._sha384 = temp.SHA384;
|
||||
this._sha512 = temp.SHA512;
|
||||
this.Parent = temp.Parent;
|
||||
this.Date = temp.Date;
|
||||
this.CRC = temp.CRC;
|
||||
this.MD5 = temp.MD5;
|
||||
this.SHA1 = temp.SHA1;
|
||||
this.SHA256 = temp.SHA256;
|
||||
this.SHA384 = temp.SHA384;
|
||||
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>
|
||||
public BaseFile(string filename, Stream stream, bool getHashes = true)
|
||||
{
|
||||
this._filename = filename;
|
||||
this.Filename = filename;
|
||||
|
||||
if (getHashes)
|
||||
{
|
||||
@@ -141,19 +80,44 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
if(temp != null)
|
||||
{
|
||||
this._parent = temp.Parent;
|
||||
this._date = temp.Date;
|
||||
this._crc = temp.CRC;
|
||||
this._md5 = temp.MD5;
|
||||
this._sha1 = temp.SHA1;
|
||||
this._sha256 = temp.SHA256;
|
||||
this._sha384 = temp.SHA384;
|
||||
this._sha512 = temp.SHA512;
|
||||
this.Parent = temp.Parent;
|
||||
this.Date = temp.Date;
|
||||
this.CRC = temp.CRC;
|
||||
this.MD5 = temp.MD5;
|
||||
this.SHA1 = temp.SHA1;
|
||||
this.SHA256 = temp.SHA256;
|
||||
this.SHA384 = temp.SHA384;
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// </summary>
|
||||
public CHDFile()
|
||||
{
|
||||
this._fileType = FileType.CHD;
|
||||
this.Type = FileType.CHD;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -154,7 +154,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <param name="chdstream">Stream representing the CHD file</param>
|
||||
public CHDFile(Stream chdstream)
|
||||
{
|
||||
_fileType = FileType.CHD;
|
||||
this.Type = FileType.CHD;
|
||||
m_br = new BinaryReader(chdstream);
|
||||
|
||||
_headerVersion = ValidateHeaderVersion();
|
||||
@@ -167,11 +167,11 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
if (hash.Length == Constants.MD5Length)
|
||||
{
|
||||
_md5 = hash;
|
||||
this.MD5 = hash;
|
||||
}
|
||||
else if (hash.Length == Constants.SHA1Length)
|
||||
{
|
||||
_sha1 = hash;
|
||||
this.SHA1 = hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public Folder()
|
||||
: base()
|
||||
{
|
||||
_fileType = FileType.Folder;
|
||||
this.Type = FileType.Folder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,7 +54,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public Folder(string filename, bool getHashes = false)
|
||||
: base(filename, getHashes)
|
||||
{
|
||||
_fileType = FileType.Folder;
|
||||
this.Type = FileType.Folder;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -72,10 +72,10 @@ namespace SabreTools.Library.FileTypes
|
||||
try
|
||||
{
|
||||
// Make sure the folders exist
|
||||
Directory.CreateDirectory(_filename);
|
||||
Directory.CreateDirectory(this.Filename);
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
Directory.Copy(_filename, outDir, true, PathFormat.FullPath);
|
||||
Directory.Copy(this.Filename, outDir, true, PathFormat.FullPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -100,11 +100,11 @@ namespace SabreTools.Library.FileTypes
|
||||
try
|
||||
{
|
||||
// Make sure the folders exist
|
||||
Directory.CreateDirectory(_filename);
|
||||
Directory.CreateDirectory(this.Filename);
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// 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
|
||||
string match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault();
|
||||
@@ -140,10 +140,10 @@ namespace SabreTools.Library.FileTypes
|
||||
try
|
||||
{
|
||||
// Make sure the folders exist
|
||||
Directory.CreateDirectory(_filename);
|
||||
Directory.CreateDirectory(this.Filename);
|
||||
|
||||
// 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
|
||||
string match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault();
|
||||
@@ -180,12 +180,12 @@ namespace SabreTools.Library.FileTypes
|
||||
if (_children == null || _children.Count == 0)
|
||||
{
|
||||
_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);
|
||||
_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);
|
||||
_children.Add(fl);
|
||||
@@ -202,7 +202,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <returns>List of empty folders in the folder</returns>
|
||||
public virtual List<string> GetEmptyFolders()
|
||||
{
|
||||
return Utilities.GetEmptyDirectories(_filename).ToList();
|
||||
return Utilities.GetEmptyDirectories(this.Filename).ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public GZipArchive()
|
||||
: base()
|
||||
{
|
||||
_fileType = FileType.GZipArchive;
|
||||
this.Type = FileType.GZipArchive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,7 +49,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public GZipArchive(string filename, bool getHashes = false)
|
||||
: base(filename, getHashes)
|
||||
{
|
||||
_fileType = FileType.GZipArchive;
|
||||
this.Type = FileType.GZipArchive;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -71,8 +71,8 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// Decompress the _filename stream
|
||||
FileStream outstream = Utilities.TryCreate(Path.Combine(outDir, Path.GetFileNameWithoutExtension(_filename)));
|
||||
GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(_filename), Ionic.Zlib.CompressionMode.Decompress);
|
||||
FileStream outstream = Utilities.TryCreate(Path.Combine(outDir, Path.GetFileNameWithoutExtension(this.Filename)));
|
||||
GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(this.Filename), Ionic.Zlib.CompressionMode.Decompress);
|
||||
gzstream.CopyTo(outstream);
|
||||
|
||||
// Dispose of the streams
|
||||
@@ -158,8 +158,8 @@ namespace SabreTools.Library.FileTypes
|
||||
try
|
||||
{
|
||||
// Decompress the _filename stream
|
||||
realEntry = Path.GetFileNameWithoutExtension(_filename);
|
||||
GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(_filename), Ionic.Zlib.CompressionMode.Decompress);
|
||||
realEntry = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(this.Filename), Ionic.Zlib.CompressionMode.Decompress);
|
||||
|
||||
// Write the file out
|
||||
byte[] gbuffer = new byte[_bufferSize];
|
||||
@@ -201,7 +201,7 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
_children = new List<BaseFile>();
|
||||
|
||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
|
||||
BaseFile possibleTgz = GetTorrentGZFileInfo();
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
Filename = gamename,
|
||||
};
|
||||
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(_filename));
|
||||
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(this.Filename));
|
||||
br.BaseStream.Seek(-8, SeekOrigin.End);
|
||||
byte[] headercrc = br.ReadBytesReverse(4);
|
||||
tempRom.CRC = headercrc;
|
||||
@@ -233,7 +233,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// Otherwise, use the stream directly
|
||||
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);
|
||||
gzipEntryRom.Filename = gzstream.FileName;
|
||||
gzipEntryRom.Parent = gamename;
|
||||
@@ -270,32 +270,32 @@ namespace SabreTools.Library.FileTypes
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
// Check for the file existing first
|
||||
if (!File.Exists(_filename))
|
||||
if (!File.Exists(this.Filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string datum = Path.GetFileName(_filename).ToLowerInvariant();
|
||||
long filesize = new FileInfo(_filename).Length;
|
||||
string datum = Path.GetFileName(this.Filename).ToLowerInvariant();
|
||||
long filesize = new FileInfo(this.Filename).Length;
|
||||
|
||||
// If we have the romba depot files, just skip them gracefully
|
||||
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;
|
||||
}
|
||||
|
||||
// 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
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
// Check if the file is at least the minimum length
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ namespace SabreTools.Library.FileTypes
|
||||
byte[] headermd5; // MD5
|
||||
byte[] headercrc; // CRC
|
||||
ulong headersz; // Int64 size
|
||||
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(_filename));
|
||||
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(this.Filename));
|
||||
header = br.ReadBytes(12);
|
||||
headermd5 = br.ReadBytes(16);
|
||||
headercrc = br.ReadBytes(4);
|
||||
@@ -337,32 +337,32 @@ namespace SabreTools.Library.FileTypes
|
||||
public BaseFile GetTorrentGZFileInfo()
|
||||
{
|
||||
// Check for the file existing first
|
||||
if (!File.Exists(_filename))
|
||||
if (!File.Exists(this.Filename))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string datum = Path.GetFileName(_filename).ToLowerInvariant();
|
||||
long filesize = new FileInfo(_filename).Length;
|
||||
string datum = Path.GetFileName(this.Filename).ToLowerInvariant();
|
||||
long filesize = new FileInfo(this.Filename).Length;
|
||||
|
||||
// If we have the romba depot files, just skip them gracefully
|
||||
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;
|
||||
}
|
||||
|
||||
// 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
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
// Check if the file is at least the minimum length
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ namespace SabreTools.Library.FileTypes
|
||||
byte[] headermd5; // MD5
|
||||
byte[] headercrc; // CRC
|
||||
ulong headersz; // Int64 size
|
||||
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(_filename));
|
||||
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(this.Filename));
|
||||
header = br.ReadBytes(12);
|
||||
headermd5 = br.ReadBytes(16);
|
||||
headercrc = br.ReadBytes(4);
|
||||
@@ -399,13 +399,13 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
BaseFile baseFile = new BaseFile
|
||||
{
|
||||
Filename = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(),
|
||||
Filename = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(),
|
||||
Size = extractedsize,
|
||||
CRC = headercrc,
|
||||
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;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public LRZipArchive()
|
||||
: base()
|
||||
{
|
||||
_fileType = FileType.LRZipArchive;
|
||||
this.Type = FileType.LRZipArchive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,7 +38,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public LRZipArchive(string filename, bool getHashes = false)
|
||||
: base(filename, getHashes)
|
||||
{
|
||||
_fileType = FileType.LRZipArchive;
|
||||
this.Type = FileType.LRZipArchive;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public LZ4Archive()
|
||||
: base()
|
||||
{
|
||||
_fileType = FileType.LZ4Archive;
|
||||
this.Type = FileType.LZ4Archive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,7 +38,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public LZ4Archive(string filename, bool getHashes = false)
|
||||
: base(filename, getHashes)
|
||||
{
|
||||
_fileType = FileType.LZ4Archive;
|
||||
this.Type = FileType.LZ4Archive;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public RarArchive()
|
||||
: base()
|
||||
{
|
||||
_fileType = FileType.RarArchive;
|
||||
this.Type = FileType.RarArchive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,7 +49,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public RarArchive(string filename, bool getHashes = false)
|
||||
: base(filename, getHashes)
|
||||
{
|
||||
_fileType = FileType.RarArchive;
|
||||
this.Type = FileType.RarArchive;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -71,7 +71,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// 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)
|
||||
{
|
||||
entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true });
|
||||
@@ -155,7 +155,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
List<BaseFile> found = new List<BaseFile>();
|
||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
|
||||
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))
|
||||
{
|
||||
// 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
|
||||
public void GetRarFileInfo()
|
||||
{
|
||||
if (!File.Exists(_filename))
|
||||
if (!File.Exists(this.Filename))
|
||||
{
|
||||
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)
|
||||
byte[] signature = br.ReadBytes(8);
|
||||
@@ -464,7 +464,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
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();
|
||||
string lastRarEntry = null;
|
||||
foreach (RarArchiveEntry entry in rarEntries)
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public SevenZipArchive()
|
||||
: base()
|
||||
{
|
||||
_fileType = FileType.SevenZipArchive;
|
||||
this.Type = FileType.SevenZipArchive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,7 +52,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public SevenZipArchive(string filename, bool getHashes = false)
|
||||
: base(filename, getHashes)
|
||||
{
|
||||
_fileType = FileType.SevenZipArchive;
|
||||
this.Type = FileType.SevenZipArchive;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -74,7 +74,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// 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)
|
||||
{
|
||||
entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true });
|
||||
@@ -158,7 +158,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
List<BaseFile> found = new List<BaseFile>();
|
||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
|
||||
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))
|
||||
{
|
||||
// If secure hashes are disabled, do a quickscan
|
||||
@@ -251,7 +251,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
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();
|
||||
string lastSevenZipEntry = null;
|
||||
foreach (SevenZipArchiveEntry entry in sevenZipEntries)
|
||||
@@ -288,11 +288,11 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
bool ist7z = false;
|
||||
|
||||
if (File.Exists(_filename))
|
||||
if (File.Exists(this.Filename))
|
||||
{
|
||||
try
|
||||
{
|
||||
Stream fread = Utilities.TryOpenRead(_filename);
|
||||
Stream fread = Utilities.TryOpenRead(this.Filename);
|
||||
uint ar, offs = 0;
|
||||
fread.Seek(0, SeekOrigin.Begin);
|
||||
byte[] buffer = new byte[128];
|
||||
@@ -314,7 +314,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
catch
|
||||
{
|
||||
Globals.Logger.Warning("File '{0}' could not be opened", _filename);
|
||||
Globals.Logger.Warning("File '{0}' could not be opened", this.Filename);
|
||||
ist7z = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public TapeArchive()
|
||||
: base()
|
||||
{
|
||||
_fileType = FileType.TapeArchive;
|
||||
this.Type = FileType.TapeArchive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,7 +52,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public TapeArchive(string filename, bool getHashes = false)
|
||||
: base(filename, getHashes)
|
||||
{
|
||||
_fileType = FileType.TapeArchive;
|
||||
this.Type = FileType.TapeArchive;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -74,7 +74,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// Extract all files to the temp directory
|
||||
TarArchive ta = TarArchive.Open(_filename);
|
||||
TarArchive ta = TarArchive.Open(this.Filename);
|
||||
foreach (TarArchiveEntry entry in ta.Entries)
|
||||
{
|
||||
entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true });
|
||||
@@ -158,7 +158,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
List<BaseFile> found = new List<BaseFile>();
|
||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
|
||||
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))
|
||||
{
|
||||
// If secure hashes are disabled, do a quickscan
|
||||
@@ -250,7 +250,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
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();
|
||||
string lastTarEntry = null;
|
||||
foreach (TarArchiveEntry entry in tarEntries)
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public XZArchive()
|
||||
: base()
|
||||
{
|
||||
_fileType = FileType.XZArchive;
|
||||
this.Type = FileType.XZArchive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,7 +52,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public XZArchive(string filename, bool getHashes = false)
|
||||
: base(filename, getHashes)
|
||||
{
|
||||
_fileType = FileType.XZArchive;
|
||||
this.Type = FileType.XZArchive;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -74,7 +74,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// 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)
|
||||
{
|
||||
entry.WriteToDirectory(outDir, new ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true });
|
||||
@@ -158,7 +158,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
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)
|
||||
{
|
||||
if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName))
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public ZPAQArchive()
|
||||
: base()
|
||||
{
|
||||
_fileType = FileType.ZPAQArchive;
|
||||
this.Type = FileType.ZPAQArchive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,7 +38,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public ZPAQArchive(string filename, bool getHashes = false)
|
||||
: base(filename, getHashes)
|
||||
{
|
||||
_fileType = FileType.ZPAQArchive;
|
||||
this.Type = FileType.ZPAQArchive;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public ZipArchive()
|
||||
: base()
|
||||
{
|
||||
_fileType = FileType.ZipArchive;
|
||||
this.Type = FileType.ZipArchive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -47,7 +47,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public ZipArchive(string filename, bool getHashes = false)
|
||||
: base(filename, getHashes)
|
||||
{
|
||||
_fileType = FileType.ZipArchive;
|
||||
this.Type = FileType.ZipArchive;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -70,7 +70,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// Extract all files to the temp directory
|
||||
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)
|
||||
{
|
||||
throw new Exception(ZipFile.ZipErrorMessageText(zr));
|
||||
@@ -201,7 +201,7 @@ namespace SabreTools.Library.FileTypes
|
||||
try
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
List<BaseFile> found = new List<BaseFile>();
|
||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
|
||||
|
||||
try
|
||||
{
|
||||
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)
|
||||
{
|
||||
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 (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;
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
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();
|
||||
string lastZipEntry = null;
|
||||
foreach (SharpCompress.Archives.Zip.ZipArchiveEntry entry in zipEntries)
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public ZstdArchive()
|
||||
: base()
|
||||
{
|
||||
_fileType = FileType.ZstdArchive;
|
||||
this.Type = FileType.ZstdArchive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,7 +38,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public ZstdArchive(string filename, bool getHashes)
|
||||
: base(filename, getHashes)
|
||||
{
|
||||
_fileType = FileType.ZstdArchive;
|
||||
this.Type = FileType.ZstdArchive;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user