Clean up more info instances

This commit is contained in:
Matt Nadareski
2020-09-18 01:50:44 -07:00
parent 817f1528cd
commit 7ed7107fd2
15 changed files with 73 additions and 90 deletions

View File

@@ -2,7 +2,6 @@
using System.IO;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
@@ -12,6 +11,8 @@ namespace SabreTools.Library.FileTypes
{
#region Protected instance variables
protected bool QuickScan { get; set; } = false;
// Buffer size used by archives
protected const int _bufferSize = 4096 * 128;
@@ -40,8 +41,9 @@ namespace SabreTools.Library.FileTypes
/// Create an archive object from a filename, if possible
/// </summary>
/// <param name="input">Name of the file to create the archive from</param>
/// <param name="quickScan">True to use archive header values, false otherwise</param>
/// <returns>Archive object representing the inputs</returns>
public static BaseArchive Create(string input)
public static BaseArchive Create(string input, bool quickScan = false)
{
BaseArchive archive = null;
@@ -81,6 +83,10 @@ namespace SabreTools.Library.FileTypes
break;
}
// Set the quickscan flag
if (archive != null)
archive.QuickScan = quickScan;
return archive;
}
@@ -147,11 +153,10 @@ namespace SabreTools.Library.FileTypes
/// <summary>
/// Generate a list of DatItem objects from the header values in an archive
/// </summary>
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
/// <returns>List of DatItem objects representing the found data</returns>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public override abstract List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false);
public override abstract List<BaseFile> GetChildren(bool date = false);
/// <summary>
/// Generate a list of empty folders in an archive

View File

@@ -99,35 +99,5 @@ 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

@@ -4,7 +4,6 @@ using System.IO;
using System.Linq;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
@@ -257,11 +256,9 @@ namespace SabreTools.Library.FileTypes
/// <summary>
/// Generate a list of immediate children from the current folder
/// </summary>
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
/// <returns>List of BaseFile objects representing the found data</returns>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public virtual List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
public virtual List<BaseFile> GetChildren(bool date = false)
{
if (_children == null || _children.Count == 0)
{
@@ -269,7 +266,6 @@ namespace SabreTools.Library.FileTypes
foreach (string file in Directory.EnumerateFiles(this.Filename, "*", SearchOption.TopDirectoryOnly))
{
BaseFile nf = FileExtensions.GetInfo(file, date: date);
nf.RemoveHashes(omitFromScan);
_children.Add(nf);
}

View File

@@ -189,11 +189,10 @@ namespace SabreTools.Library.FileTypes
/// <summary>
/// Generate a list of DatItem objects from the header values in an archive
/// </summary>
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
/// <returns>List of DatItem objects representing the found data</returns>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
public override List<BaseFile> GetChildren(bool date = false)
{
if (_children == null || _children.Count == 0)
{
@@ -212,8 +211,8 @@ namespace SabreTools.Library.FileTypes
{
try
{
// If secure hashes are disabled, do a quickscan
if (omitFromScan == Hash.SecureHashes)
// Perform a quickscan, if flagged to
if (QuickScan)
{
BaseFile tempRom = new BaseFile()
{
@@ -234,7 +233,6 @@ namespace SabreTools.Library.FileTypes
ZipReturn ret = gz.ZipFileOpen(this.Filename);
ret = gz.ZipFileOpenReadStream(0, out Stream gzstream, out ulong streamSize);
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

@@ -78,11 +78,10 @@ namespace SabreTools.Library.FileTypes
/// <summary>
/// Generate a list of DatItem objects from the header values in an archive
/// </summary>
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
/// <returns>List of DatItem objects representing the found data</returns>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
public override List<BaseFile> GetChildren(bool date = false)
{
throw new NotImplementedException();
}

View File

@@ -78,11 +78,10 @@ namespace SabreTools.Library.FileTypes
/// <summary>
/// Generate a list of DatItem objects from the header values in an archive
/// </summary>
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
/// <returns>List of DatItem objects representing the found data</returns>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
public override List<BaseFile> GetChildren(bool date = false)
{
throw new NotImplementedException();
}

View File

@@ -175,11 +175,10 @@ namespace SabreTools.Library.FileTypes
/// <summary>
/// Generate a list of DatItem objects from the header values in an archive
/// </summary>
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
/// <returns>List of DatItem objects representing the found data</returns>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
public override List<BaseFile> GetChildren(bool date = false)
{
List<BaseFile> found = new List<BaseFile>();
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
@@ -189,8 +188,8 @@ namespace SabreTools.Library.FileTypes
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(FileExtensions.TryOpenRead(this.Filename));
foreach (RarArchiveEntry entry in ra.Entries.Where(e => e != null && !e.IsDirectory))
{
// If secure hashes are disabled, do a quickscan
if (omitFromScan == Hash.SecureHashes)
// Perform a quickscan, if flagged to
if (QuickScan)
{
found.Add(new BaseFile
{
@@ -207,7 +206,6 @@ namespace SabreTools.Library.FileTypes
{
Stream entryStream = entry.OpenEntryStream();
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

@@ -259,11 +259,10 @@ namespace SabreTools.Library.FileTypes
/// <summary>
/// Generate a list of DatItem objects from the header values in an archive
/// </summary>
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
/// <returns>List of DatItem objects representing the found data</returns>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
public override List<BaseFile> GetChildren(bool date = false)
{
List<BaseFile> found = new List<BaseFile>();
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
@@ -299,8 +298,8 @@ namespace SabreTools.Library.FileTypes
continue;
}
// If secure hashes are disabled, do a quickscan
if (omitFromScan == Hash.SecureHashes)
// Perform a quickscan, if flagged to
if (QuickScan)
{
string newname = zf.Filename(i);
long newsize = (long)zf.UncompressedSize(i);
@@ -319,7 +318,6 @@ namespace SabreTools.Library.FileTypes
else
{
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

@@ -180,11 +180,10 @@ namespace SabreTools.Library.FileTypes
/// <summary>
/// Generate a list of DatItem objects from the header values in an archive
/// </summary>
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
/// <returns>List of DatItem objects representing the found data</returns>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
public override List<BaseFile> GetChildren(bool date = false)
{
List<BaseFile> found = new List<BaseFile>();
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
@@ -194,8 +193,8 @@ namespace SabreTools.Library.FileTypes
TarArchive ta = TarArchive.Open(FileExtensions.TryOpenRead(this.Filename));
foreach (TarArchiveEntry entry in ta.Entries.Where(e => e != null && !e.IsDirectory))
{
// If secure hashes are disabled, do a quickscan
if (omitFromScan == Hash.SecureHashes)
// Perform a quickscan, if flagged to
if (QuickScan)
{
found.Add(new BaseFile
{
@@ -212,7 +211,6 @@ namespace SabreTools.Library.FileTypes
{
Stream entryStream = entry.OpenEntryStream();
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

@@ -181,11 +181,10 @@ namespace SabreTools.Library.FileTypes
/// <summary>
/// Generate a list of DatItem objects from the header values in an archive
/// </summary>
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
/// <returns>List of DatItem objects representing the found data</returns>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
public override List<BaseFile> GetChildren(bool date = false)
{
if (_children == null || _children.Count == 0)
{
@@ -204,8 +203,8 @@ namespace SabreTools.Library.FileTypes
{
try
{
// If secure hashes are disabled, do a quickscan
if (omitFromScan == Hash.SecureHashes)
// Perform a quickscan, if flagged to
if (QuickScan)
{
BaseFile tempRom = new BaseFile()
{
@@ -224,7 +223,6 @@ namespace SabreTools.Library.FileTypes
{
var xzStream = new XZStream(File.OpenRead(this.Filename));
BaseFile xzEntryRom = xzStream.GetInfo();
xzEntryRom.RemoveHashes(omitFromScan);
xzEntryRom.Filename = gamename;
xzEntryRom.Parent = gamename;
_children.Add(xzEntryRom);

View File

@@ -78,11 +78,10 @@ namespace SabreTools.Library.FileTypes
/// <summary>
/// Generate a list of DatItem objects from the header values in an archive
/// </summary>
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
/// <returns>List of DatItem objects representing the found data</returns>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
public override List<BaseFile> GetChildren(bool date = false)
{
throw new NotImplementedException();
}

View File

@@ -260,11 +260,10 @@ namespace SabreTools.Library.FileTypes
/// <summary>
/// Generate a list of DatItem objects from the header values in an archive
/// </summary>
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
/// <returns>List of DatItem objects representing the found data</returns>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
public override List<BaseFile> GetChildren(bool date = false)
{
List<BaseFile> found = new List<BaseFile>();
string gamename = Path.GetFileNameWithoutExtension(this.Filename);
@@ -300,8 +299,8 @@ namespace SabreTools.Library.FileTypes
continue;
}
// If secure hashes are disabled, do a quickscan
if (omitFromScan == Hash.SecureHashes)
// Perform a quickscan, if flagged to
if (QuickScan)
{
string newname = zf.Filename(i);
long newsize = (long)zf.UncompressedSize(i);
@@ -322,7 +321,6 @@ namespace SabreTools.Library.FileTypes
else
{
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");

View File

@@ -79,11 +79,10 @@ namespace SabreTools.Library.FileTypes
/// <summary>
/// Generate a list of DatItem objects from the header values in an archive
/// </summary>
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
/// <returns>List of DatItem objects representing the found data</returns>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
public override List<BaseFile> GetChildren(bool date = false)
{
throw new NotImplementedException();
}