mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Enums, Utilities] Remove dependence on SharpCompress for enum
This commit is contained in:
@@ -95,11 +95,14 @@
|
|||||||
public enum FileType
|
public enum FileType
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
|
|
||||||
|
// Archival types
|
||||||
SevenZipArchive,
|
SevenZipArchive,
|
||||||
CHD,
|
CHD,
|
||||||
GZipArchive,
|
GZipArchive,
|
||||||
RARArchive,
|
RarArchive,
|
||||||
TARArchive,
|
TarArchive,
|
||||||
|
ZipArchive,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ using Stream = System.IO.Stream;
|
|||||||
using StreamReader = System.IO.StreamReader;
|
using StreamReader = System.IO.StreamReader;
|
||||||
#endif
|
#endif
|
||||||
using NaturalSort;
|
using NaturalSort;
|
||||||
using SharpCompress.Common;
|
|
||||||
|
|
||||||
namespace SabreTools.Library.Tools
|
namespace SabreTools.Library.Tools
|
||||||
{
|
{
|
||||||
@@ -446,7 +445,7 @@ namespace SabreTools.Library.Tools
|
|||||||
BaseArchive archive = null;
|
BaseArchive archive = null;
|
||||||
|
|
||||||
// First get the archive type
|
// First get the archive type
|
||||||
ArchiveType? at = GetArchiveType(input);
|
FileType? at = GetFileType(input);
|
||||||
|
|
||||||
// If we got back null, then it's not an archive, so we we return
|
// If we got back null, then it's not an archive, so we we return
|
||||||
if (at == null)
|
if (at == null)
|
||||||
@@ -458,21 +457,25 @@ namespace SabreTools.Library.Tools
|
|||||||
Globals.Logger.Verbose("Found archive of type: {0}", at);
|
Globals.Logger.Verbose("Found archive of type: {0}", at);
|
||||||
switch (at)
|
switch (at)
|
||||||
{
|
{
|
||||||
case ArchiveType.GZip:
|
case FileType.GZipArchive:
|
||||||
archive = new GZipArchive(input);
|
archive = new GZipArchive(input);
|
||||||
break;
|
break;
|
||||||
case ArchiveType.Rar:
|
case FileType.RarArchive:
|
||||||
archive = new RarArchive(input);
|
archive = new RarArchive(input);
|
||||||
break;
|
break;
|
||||||
case ArchiveType.SevenZip:
|
case FileType.SevenZipArchive:
|
||||||
archive = new SevenZipArchive(input);
|
archive = new SevenZipArchive(input);
|
||||||
break;
|
break;
|
||||||
case ArchiveType.Tar:
|
case FileType.TarArchive:
|
||||||
archive = new TapeArchive(input);
|
archive = new TapeArchive(input);
|
||||||
break;
|
break;
|
||||||
case ArchiveType.Zip:
|
case FileType.ZipArchive:
|
||||||
archive = new TorrentZipArchive(input);
|
archive = new TorrentZipArchive(input);
|
||||||
break;
|
break;
|
||||||
|
case FileType.CHD:
|
||||||
|
default:
|
||||||
|
// We ignore these types for now
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return archive;
|
return archive;
|
||||||
@@ -483,19 +486,19 @@ namespace SabreTools.Library.Tools
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="archiveType">SharpCompress.Common.ArchiveType representing the archive to create</param>
|
/// <param name="archiveType">SharpCompress.Common.ArchiveType representing the archive to create</param>
|
||||||
/// <returns>Archive object representing the inputs</returns>
|
/// <returns>Archive object representing the inputs</returns>
|
||||||
public static BaseArchive GetArchive(ArchiveType archiveType)
|
public static BaseArchive GetArchive(FileType archiveType)
|
||||||
{
|
{
|
||||||
switch (archiveType)
|
switch (archiveType)
|
||||||
{
|
{
|
||||||
case ArchiveType.GZip:
|
case FileType.GZipArchive:
|
||||||
return new GZipArchive();
|
return new GZipArchive();
|
||||||
case ArchiveType.Rar:
|
case FileType.RarArchive:
|
||||||
return new RarArchive();
|
return new RarArchive();
|
||||||
case ArchiveType.SevenZip:
|
case FileType.SevenZipArchive:
|
||||||
return new SevenZipArchive();
|
return new SevenZipArchive();
|
||||||
case ArchiveType.Tar:
|
case FileType.TarArchive:
|
||||||
return new TapeArchive();
|
return new TapeArchive();
|
||||||
case ArchiveType.Zip:
|
case FileType.ZipArchive:
|
||||||
return new TorrentZipArchive();
|
return new TorrentZipArchive();
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
@@ -1043,65 +1046,6 @@ namespace SabreTools.Library.Tools
|
|||||||
return datItem;
|
return datItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the archive type of an input file
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="input">Input file to check</param>
|
|
||||||
/// <returns>ArchiveType of inputted file (null on error)</returns>
|
|
||||||
public static ArchiveType? GetArchiveType(string input)
|
|
||||||
{
|
|
||||||
ArchiveType? outtype = null;
|
|
||||||
|
|
||||||
// If the file is null, then we have no archive type
|
|
||||||
if (input == null)
|
|
||||||
{
|
|
||||||
return outtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
// First line of defense is going to be the extension, for better or worse
|
|
||||||
if (!HasValidArchiveExtension(input))
|
|
||||||
{
|
|
||||||
return outtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the first bytes of the file and get the magic number
|
|
||||||
try
|
|
||||||
{
|
|
||||||
byte[] magic = new byte[8];
|
|
||||||
BinaryReader br = new BinaryReader(TryOpenRead(input));
|
|
||||||
magic = br.ReadBytes(8);
|
|
||||||
br.Dispose();
|
|
||||||
|
|
||||||
// Now try to match it to a known signature
|
|
||||||
if (magic.StartsWith(Constants.SevenZipSignature))
|
|
||||||
{
|
|
||||||
outtype = ArchiveType.SevenZip;
|
|
||||||
}
|
|
||||||
else if (magic.StartsWith(Constants.GzSignature))
|
|
||||||
{
|
|
||||||
outtype = ArchiveType.GZip;
|
|
||||||
}
|
|
||||||
else if (magic.StartsWith(Constants.RarSignature) || magic.StartsWith(Constants.RarFiveSignature))
|
|
||||||
{
|
|
||||||
outtype = ArchiveType.Rar;
|
|
||||||
}
|
|
||||||
else if (magic.StartsWith(Constants.TarSignature) || magic.StartsWith(Constants.TarZeroSignature))
|
|
||||||
{
|
|
||||||
outtype = ArchiveType.Tar;
|
|
||||||
}
|
|
||||||
else if (magic.StartsWith(Constants.ZipSignature) || magic.StartsWith(Constants.ZipSignatureEmpty) || magic.StartsWith(Constants.ZipSignatureSpanned))
|
|
||||||
{
|
|
||||||
outtype = ArchiveType.Zip;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
// Don't log file open errors
|
|
||||||
}
|
|
||||||
|
|
||||||
return outtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get what type of DAT the input file is
|
/// Get what type of DAT the input file is
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1328,6 +1272,69 @@ namespace SabreTools.Library.Tools
|
|||||||
return datItem;
|
return datItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the file type of an input file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">Input file to check</param>
|
||||||
|
/// <returns>FileType of inputted file (null on error)</returns>
|
||||||
|
public static FileType? GetFileType(string input)
|
||||||
|
{
|
||||||
|
FileType? outFileType = null;
|
||||||
|
|
||||||
|
// If the file is null, then we have no archive type
|
||||||
|
if (input == null)
|
||||||
|
{
|
||||||
|
return outFileType;
|
||||||
|
}
|
||||||
|
|
||||||
|
// First line of defense is going to be the extension, for better or worse
|
||||||
|
if (!HasValidArchiveExtension(input))
|
||||||
|
{
|
||||||
|
return outFileType;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the first bytes of the file and get the magic number
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] magic = new byte[8];
|
||||||
|
BinaryReader br = new BinaryReader(TryOpenRead(input));
|
||||||
|
magic = br.ReadBytes(8);
|
||||||
|
br.Dispose();
|
||||||
|
|
||||||
|
// Now try to match it to a known signature
|
||||||
|
if (magic.StartsWith(Constants.SevenZipSignature))
|
||||||
|
{
|
||||||
|
outFileType = FileType.SevenZipArchive;
|
||||||
|
}
|
||||||
|
else if (magic.StartsWith(Constants.CHDSignature))
|
||||||
|
{
|
||||||
|
outFileType = FileType.CHD;
|
||||||
|
}
|
||||||
|
else if (magic.StartsWith(Constants.GzSignature))
|
||||||
|
{
|
||||||
|
outFileType = FileType.GZipArchive;
|
||||||
|
}
|
||||||
|
else if (magic.StartsWith(Constants.RarSignature) || magic.StartsWith(Constants.RarFiveSignature))
|
||||||
|
{
|
||||||
|
outFileType = FileType.RarArchive;
|
||||||
|
}
|
||||||
|
else if (magic.StartsWith(Constants.TarSignature) || magic.StartsWith(Constants.TarZeroSignature))
|
||||||
|
{
|
||||||
|
outFileType = FileType.TarArchive;
|
||||||
|
}
|
||||||
|
else if (magic.StartsWith(Constants.ZipSignature) || magic.StartsWith(Constants.ZipSignatureEmpty) || magic.StartsWith(Constants.ZipSignatureSpanned))
|
||||||
|
{
|
||||||
|
outFileType = FileType.ZipArchive;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// Don't log file open errors
|
||||||
|
}
|
||||||
|
|
||||||
|
return outFileType;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get if the current file should be scanned internally and externally
|
/// Get if the current file should be scanned internally and externally
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1341,26 +1348,27 @@ namespace SabreTools.Library.Tools
|
|||||||
shouldExternalProcess = true;
|
shouldExternalProcess = true;
|
||||||
shouldInternalProcess = true;
|
shouldInternalProcess = true;
|
||||||
|
|
||||||
ArchiveType? archiveType = GetArchiveType(input);
|
FileType? fileType = GetFileType(input);
|
||||||
switch (archiveType)
|
switch (fileType)
|
||||||
{
|
{
|
||||||
|
case FileType.CHD:
|
||||||
case null:
|
case null:
|
||||||
shouldExternalProcess = true;
|
shouldExternalProcess = true;
|
||||||
shouldInternalProcess = false;
|
shouldInternalProcess = false;
|
||||||
break;
|
break;
|
||||||
case ArchiveType.GZip:
|
case FileType.GZipArchive:
|
||||||
shouldExternalProcess = ((archiveScanLevel & ArchiveScanLevel.GZipExternal) != 0);
|
shouldExternalProcess = ((archiveScanLevel & ArchiveScanLevel.GZipExternal) != 0);
|
||||||
shouldInternalProcess = ((archiveScanLevel & ArchiveScanLevel.GZipInternal) != 0);
|
shouldInternalProcess = ((archiveScanLevel & ArchiveScanLevel.GZipInternal) != 0);
|
||||||
break;
|
break;
|
||||||
case ArchiveType.Rar:
|
case FileType.RarArchive:
|
||||||
shouldExternalProcess = ((archiveScanLevel & ArchiveScanLevel.RarExternal) != 0);
|
shouldExternalProcess = ((archiveScanLevel & ArchiveScanLevel.RarExternal) != 0);
|
||||||
shouldInternalProcess = ((archiveScanLevel & ArchiveScanLevel.RarInternal) != 0);
|
shouldInternalProcess = ((archiveScanLevel & ArchiveScanLevel.RarInternal) != 0);
|
||||||
break;
|
break;
|
||||||
case ArchiveType.SevenZip:
|
case FileType.SevenZipArchive:
|
||||||
shouldExternalProcess = ((archiveScanLevel & ArchiveScanLevel.SevenZipExternal) != 0);
|
shouldExternalProcess = ((archiveScanLevel & ArchiveScanLevel.SevenZipExternal) != 0);
|
||||||
shouldInternalProcess = ((archiveScanLevel & ArchiveScanLevel.SevenZipInternal) != 0);
|
shouldInternalProcess = ((archiveScanLevel & ArchiveScanLevel.SevenZipInternal) != 0);
|
||||||
break;
|
break;
|
||||||
case ArchiveType.Zip:
|
case FileType.ZipArchive:
|
||||||
shouldExternalProcess = ((archiveScanLevel & ArchiveScanLevel.ZipExternal) != 0);
|
shouldExternalProcess = ((archiveScanLevel & ArchiveScanLevel.ZipExternal) != 0);
|
||||||
shouldInternalProcess = ((archiveScanLevel & ArchiveScanLevel.ZipInternal) != 0);
|
shouldInternalProcess = ((archiveScanLevel & ArchiveScanLevel.ZipInternal) != 0);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user