Decouple stream hashing from special file info

This commit is contained in:
Matt Nadareski
2020-09-17 23:07:49 -07:00
parent 3ad55d806b
commit 1e4afb3046
12 changed files with 93 additions and 79 deletions

View File

@@ -1,5 +1,5 @@
using System.IO;
using SabreTools.Library.DatFiles;
using SabreTools.Library.IO;
namespace SabreTools.Library.FileTypes
@@ -99,5 +99,35 @@ namespace SabreTools.Library.FileTypes
}
#endregion
#region Manipulation
/// <summary>
/// Remove hashes from the metadata
/// </summary>
/// <param name="remove">Hash representing hashes to remove</param>
public void RemoveHashes(Hash remove)
{
if (remove.HasFlag(Hash.CRC))
CRC = null;
if (remove.HasFlag(Hash.MD5))
MD5 = null;
#if NET_FRAMEWORK
if (remove.HasFlag(Hash.RIPEMD160))
RIPEMD160 = null;
#endif
if (remove.HasFlag(Hash.SHA1))
SHA1 = null;
if (remove.HasFlag(Hash.SHA256))
SHA256 = null;
if (remove.HasFlag(Hash.SHA384))
SHA384 = null;
if (remove.HasFlag(Hash.SHA512))
SHA512 = null;
if (remove.HasFlag(Hash.SpamSum))
SpamSum = null;
}
#endregion
}
}

View File

@@ -233,7 +233,8 @@ namespace SabreTools.Library.FileTypes
var gz = new gZip();
ZipReturn ret = gz.ZipFileOpen(this.Filename);
ret = gz.ZipFileOpenReadStream(0, out Stream gzstream, out ulong streamSize);
BaseFile gzipEntryRom = gzstream.GetInfo(omitFromScan: omitFromScan, asFiles: TreatAsFiles.AaruFormats | TreatAsFiles.CHDs);
BaseFile gzipEntryRom = gzstream.GetInfo();
gzipEntryRom.RemoveHashes(omitFromScan);
gzipEntryRom.Filename = gz.Filename(0);
gzipEntryRom.Parent = gamename;
gzipEntryRom.Date = (date && gz.TimeStamp > 0 ? gz.TimeStamp.ToString() : null);

View File

@@ -206,7 +206,8 @@ namespace SabreTools.Library.FileTypes
else
{
Stream entryStream = entry.OpenEntryStream();
BaseFile rarEntryRom = entryStream.GetInfo(size: entry.Size, omitFromScan: omitFromScan, asFiles: TreatAsFiles.AaruFormats | TreatAsFiles.CHDs);
BaseFile rarEntryRom = entryStream.GetInfo(size: entry.Size);
rarEntryRom.RemoveHashes(omitFromScan);
rarEntryRom.Filename = entry.Key;
rarEntryRom.Parent = gamename;
rarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");

View File

@@ -318,7 +318,8 @@ namespace SabreTools.Library.FileTypes
// Otherwise, use the stream directly
else
{
BaseFile zipEntryRom = readStream.GetInfo(size: (long)zf.UncompressedSize(i), omitFromScan: omitFromScan, keepReadOpen: true, asFiles: TreatAsFiles.AaruFormats | TreatAsFiles.CHDs);
BaseFile zipEntryRom = readStream.GetInfo(size: (long)zf.UncompressedSize(i), keepReadOpen: true);
zipEntryRom.RemoveHashes(omitFromScan);
zipEntryRom.Filename = zf.Filename(i);
zipEntryRom.Parent = gamename;
found.Add(zipEntryRom);

View File

@@ -211,7 +211,8 @@ namespace SabreTools.Library.FileTypes
else
{
Stream entryStream = entry.OpenEntryStream();
BaseFile tarEntryRom = entryStream.GetInfo(size: entry.Size, omitFromScan: omitFromScan, asFiles: TreatAsFiles.AaruFormats | TreatAsFiles.CHDs);
BaseFile tarEntryRom = entryStream.GetInfo(size: entry.Size);
tarEntryRom.RemoveHashes(omitFromScan);
tarEntryRom.Filename = entry.Key;
tarEntryRom.Parent = gamename;
tarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");

View File

@@ -223,7 +223,8 @@ namespace SabreTools.Library.FileTypes
else
{
var xzStream = new XZStream(File.OpenRead(this.Filename));
BaseFile xzEntryRom = xzStream.GetInfo(omitFromScan: omitFromScan, asFiles: TreatAsFiles.AaruFormats | TreatAsFiles.CHDs);
BaseFile xzEntryRom = xzStream.GetInfo();
xzEntryRom.RemoveHashes(omitFromScan);
xzEntryRom.Filename = gamename;
xzEntryRom.Parent = gamename;
_children.Add(xzEntryRom);

View File

@@ -321,7 +321,8 @@ namespace SabreTools.Library.FileTypes
// Otherwise, use the stream directly
else
{
BaseFile zipEntryRom = readStream.GetInfo(size: (long)zf.UncompressedSize(i), omitFromScan: omitFromScan, keepReadOpen: true, asFiles: TreatAsFiles.AaruFormats | TreatAsFiles.CHDs);
BaseFile zipEntryRom = readStream.GetInfo(size: (long)zf.UncompressedSize(i), keepReadOpen: true);
zipEntryRom.RemoveHashes(omitFromScan);
zipEntryRom.Filename = zf.Filename(i);
zipEntryRom.Parent = gamename;
string convertedDate = zf.LastModified(i).ToString("yyyy/MM/dd hh:mm:ss");