diff --git a/SabreTools.FileTypes/Archives/GZipArchive.cs b/SabreTools.FileTypes/Archives/GZipArchive.cs
index e1472515..ff5017dc 100644
--- a/SabreTools.FileTypes/Archives/GZipArchive.cs
+++ b/SabreTools.FileTypes/Archives/GZipArchive.cs
@@ -60,11 +60,8 @@ namespace SabreTools.FileTypes.Archives
///
/// Create a new TorrentGZipArchive from the given file
///
- /// Name of the file to use as an archive
- /// True for opening file as read, false for opening file as write
- /// True if hashes for this file should be calculated, false otherwise (default)
- public GZipArchive(string filename, bool getHashes = false)
- : base(filename, getHashes)
+ public GZipArchive(string filename)
+ : base(filename)
{
}
diff --git a/SabreTools.FileTypes/Archives/RarArchive.cs b/SabreTools.FileTypes/Archives/RarArchive.cs
index 501e21e5..0d6f08e7 100644
--- a/SabreTools.FileTypes/Archives/RarArchive.cs
+++ b/SabreTools.FileTypes/Archives/RarArchive.cs
@@ -31,10 +31,8 @@ namespace SabreTools.FileTypes.Archives
/// Create a new TorrentRARArchive from the given file
///
/// Name of the file to use as an archive
- /// True for opening file as read, false for opening file as write
- /// True if hashes for this file should be calculated, false otherwise (default)
- public RarArchive(string filename, bool getHashes = false)
- : base(filename, getHashes)
+ public RarArchive(string filename)
+ : base(filename)
{
}
diff --git a/SabreTools.FileTypes/Archives/SevenZipArchive.cs b/SabreTools.FileTypes/Archives/SevenZipArchive.cs
index 9490b82b..654560d7 100644
--- a/SabreTools.FileTypes/Archives/SevenZipArchive.cs
+++ b/SabreTools.FileTypes/Archives/SevenZipArchive.cs
@@ -38,9 +38,8 @@ namespace SabreTools.FileTypes.Archives
///
/// Name of the file to use as an archive
/// True for opening file as read, false for opening file as write
- /// True if hashes for this file should be calculated, false otherwise (default)
- public SevenZipArchive(string filename, bool getHashes = false)
- : base(filename, getHashes)
+ public SevenZipArchive(string filename)
+ : base(filename)
{
}
diff --git a/SabreTools.FileTypes/Archives/TapeArchive.cs b/SabreTools.FileTypes/Archives/TapeArchive.cs
index dd5705be..1e0687f4 100644
--- a/SabreTools.FileTypes/Archives/TapeArchive.cs
+++ b/SabreTools.FileTypes/Archives/TapeArchive.cs
@@ -36,10 +36,8 @@ namespace SabreTools.FileTypes.Archives
/// Create a new Tape archive from the given file
///
/// Name of the file to use as an archive
- /// True for opening file as read, false for opening file as write
- /// True if hashes for this file should be calculated, false otherwise (default)
- public TapeArchive(string filename, bool getHashes = false)
- : base(filename, getHashes)
+ public TapeArchive(string filename)
+ : base(filename)
{
}
diff --git a/SabreTools.FileTypes/Archives/XZArchive.cs b/SabreTools.FileTypes/Archives/XZArchive.cs
index 8d863a1d..821ad864 100644
--- a/SabreTools.FileTypes/Archives/XZArchive.cs
+++ b/SabreTools.FileTypes/Archives/XZArchive.cs
@@ -46,10 +46,8 @@ namespace SabreTools.FileTypes.Archives
/// Create a new TorrentGZipArchive from the given file
///
/// Name of the file to use as an archive
- /// True for opening file as read, false for opening file as write
- /// True if hashes for this file should be calculated, false otherwise (default)
- public XZArchive(string filename, bool getHashes = false)
- : base(filename, getHashes)
+ public XZArchive(string filename)
+ : base(filename)
{
}
diff --git a/SabreTools.FileTypes/Archives/ZipArchive.cs b/SabreTools.FileTypes/Archives/ZipArchive.cs
index de09df51..77728285 100644
--- a/SabreTools.FileTypes/Archives/ZipArchive.cs
+++ b/SabreTools.FileTypes/Archives/ZipArchive.cs
@@ -44,10 +44,8 @@ namespace SabreTools.FileTypes.Archives
/// Create a new TorrentZipArchive from the given file
///
/// Name of the file to use as an archive
- /// True for opening file as read, false for opening file as write
- /// True if hashes for this file should be calculated, false otherwise (default)
- public ZipArchive(string filename, bool getHashes = false)
- : base(filename, getHashes)
+ public ZipArchive(string filename)
+ : base(filename)
{
}
diff --git a/SabreTools.FileTypes/BaseArchive.cs b/SabreTools.FileTypes/BaseArchive.cs
index 70f210ee..7d6ef574 100644
--- a/SabreTools.FileTypes/BaseArchive.cs
+++ b/SabreTools.FileTypes/BaseArchive.cs
@@ -34,12 +34,11 @@ namespace SabreTools.FileTypes
}
///
- /// Create a new Archive from the given file
+ /// Create a new BaseArchive from the given file
///
- /// Name of the file to use as an archive
- /// True if hashes for this file should be calculated, false otherwise (default)
- public BaseArchive(string filename, bool getHashes = false)
- : base(filename, getHashes)
+ /// Name of the file to use
+ public BaseArchive(string filename)
+ : base(filename)
{
}
diff --git a/SabreTools.FileTypes/BaseFile.cs b/SabreTools.FileTypes/BaseFile.cs
index fa34f0c7..7316ea36 100644
--- a/SabreTools.FileTypes/BaseFile.cs
+++ b/SabreTools.FileTypes/BaseFile.cs
@@ -14,25 +14,16 @@ namespace SabreTools.FileTypes
protected static readonly byte[] SevenZipSignature = [0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c];
protected static readonly byte[] AaruFormatSignature = [0x41, 0x41, 0x52, 0x55, 0x46, 0x52, 0x4d, 0x54];
- protected static readonly byte[] BZ2Signature = [0x42, 0x5a, 0x68];
- protected static readonly byte[] CabinetSignature = [0x4d, 0x53, 0x43, 0x46];
protected static readonly byte[] CHDSignature = [0x4d, 0x43, 0x6f, 0x6d, 0x70, 0x72, 0x48, 0x44];
- protected static readonly byte[] ELFSignature = [0x7f, 0x45, 0x4c, 0x46];
- protected static readonly byte[] FreeArcSignature = [0x41, 0x72, 0x43, 0x01];
protected static readonly byte[] GzSignature = [0x1f, 0x8b, 0x08];
- protected static readonly byte[] PESignature = [0x4d, 0x5a];
protected static readonly byte[] RarSignature = [0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00];
protected static readonly byte[] RarFiveSignature = [0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x01, 0x00];
protected static readonly byte[] TarSignature = [0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00];
protected static readonly byte[] TarZeroSignature = [0x75, 0x73, 0x74, 0x61, 0x72, 0x00, 0x30, 0x30];
protected static readonly byte[] XZSignature = [0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00, 0x00];
- protected static readonly byte[] ZipSignature = [0x50, 0x4b, 0x03, 0x04];
- protected static readonly byte[] ZipSignatureEmpty = [0x50, 0x4b, 0x05, 0x06];
- protected static readonly byte[] ZipSignatureSpanned = [0x50, 0x4b, 0x07, 0x08];
#endregion
- // TODO: Get all of these values automatically so there is no public "set"
#region Fields
///
@@ -110,56 +101,9 @@ namespace SabreTools.FileTypes
/// 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)
+ public BaseFile(string filename)
{
Filename = filename;
-
- if (getHashes)
- {
- BaseFile? temp = GetInfo(Filename, hashes: AvailableHashTypes);
- if (temp != null)
- {
- Parent = temp.Parent;
- Date = temp.Date;
- CRC = temp.CRC;
- MD5 = temp.MD5;
- SHA1 = temp.SHA1;
- SHA256 = temp.SHA256;
- SHA384 = temp.SHA384;
- SHA512 = temp.SHA512;
- 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)
- {
- Filename = filename;
-
- if (getHashes)
- {
- BaseFile temp = GetInfo(stream, hashes: AvailableHashTypes);
- if (temp != null)
- {
- Parent = temp.Parent;
- Date = temp.Date;
- CRC = temp.CRC;
- MD5 = temp.MD5;
- SHA1 = temp.SHA1;
- SHA256 = temp.SHA256;
- SHA384 = temp.SHA384;
- SHA512 = temp.SHA512;
- SpamSum = temp.SpamSum;
- }
- }
-
}
#endregion
@@ -221,9 +165,9 @@ namespace SabreTools.FileTypes
{
outFileType = FileType.XZArchive;
}
- else if (magic.StartsWith(ZipSignature)
- || magic.StartsWith(ZipSignatureEmpty)
- || magic.StartsWith(ZipSignatureSpanned))
+ else if (magic.StartsWith(Models.PKZIP.Constants.LocalFileHeaderSignatureBytes)
+ || magic.StartsWith(Models.PKZIP.Constants.EndOfCentralDirectoryRecordSignatureBytes)
+ || magic.StartsWith(Models.PKZIP.Constants.DataDescriptorSignatureBytes))
{
outFileType = FileType.ZipArchive;
}
diff --git a/SabreTools.FileTypes/CHD/CHDFile.cs b/SabreTools.FileTypes/CHD/CHDFile.cs
index 8f09e163..c7634673 100644
--- a/SabreTools.FileTypes/CHD/CHDFile.cs
+++ b/SabreTools.FileTypes/CHD/CHDFile.cs
@@ -3,10 +3,6 @@ using SabreTools.Models.CHD;
namespace SabreTools.FileTypes.CHD
{
- ///
- /// This is code adapted from chd.h and chd.cpp in MAME
- /// Additional archival code from https://github.com/rtissera/libchdr/blob/master/src/chd.h
- ///
public class CHDFile : BaseFile
{
#region Private instance variables
diff --git a/SabreTools.FileTypes/CHD/Constants.cs b/SabreTools.FileTypes/CHD/Constants.cs
deleted file mode 100644
index 6629efae..00000000
--- a/SabreTools.FileTypes/CHD/Constants.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-namespace SabreTools.FileTypes.CHD
-{
- internal static class Constants
- {
- public const string SignatureString = "MComprHD";
-
- #region Header Sizes
-
- public const int HeaderV1Size = 76;
- public const int HeaderV2Size = 80;
- public const int HeaderV3Size = 120;
- public const int HeaderV4Size = 108;
- public const int HeaderV5Size = 124;
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/SabreTools.FileTypes/Folder.cs b/SabreTools.FileTypes/Folder.cs
index d47b6e1e..d0fbec3b 100644
--- a/SabreTools.FileTypes/Folder.cs
+++ b/SabreTools.FileTypes/Folder.cs
@@ -31,14 +31,14 @@ namespace SabreTools.FileTypes
///
/// Flag specific to Folder to omit Machine name from output path
///
- private readonly bool _writeToParent = false;
+ private readonly bool _writeToParent;
#endregion
#region Constructors
///
- /// Create a new folder with no base file
+ /// Create a new Folder with no base file
///
/// True to write directly to parent, false otherwise
public Folder(bool writeToParent = false)
@@ -49,14 +49,14 @@ namespace SabreTools.FileTypes
}
///
- /// Create a new folder from the given file
+ /// Create a new Folder from the given file
///
- /// Name of the file to use as an archive
- /// True for opening file as read, false for opening file as write
- /// True if hashes for this file should be calculated, false otherwise (default)
- public Folder(string filename, bool getHashes = false)
- : base(filename, getHashes)
+ /// Name of the folder to use
+ /// True to write directly to parent, false otherwise
+ public Folder(string filename, bool writeToParent = false)
+ : base(filename)
{
+ _writeToParent = writeToParent;
logger = new Logger(this);
}
@@ -271,7 +271,7 @@ namespace SabreTools.FileTypes
foreach (string dir in Directory.EnumerateDirectories(Filename, "*", SearchOption.TopDirectoryOnly))
#endif
{
- Folder fl = new(dir);
+ var fl = new Folder(dir);
_children.Add(fl);
}
}