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

@@ -2094,7 +2094,7 @@ namespace SabreTools.Library.DatFiles
// If we have an archive and we're supposed to scan it
if (archive != null && !asFiles.HasFlag(TreatAsFile.Archive))
extracted = archive.GetChildren(omitFromScan: omitFromScan, date: addDate);
extracted = archive.GetChildren(date: addDate);
// If the file should be skipped based on type, do so now
if ((extracted != null && skipFileType == SkipFileType.Archive)
@@ -2109,7 +2109,7 @@ namespace SabreTools.Library.DatFiles
// Otherwise, add all of the found items
else
ProcessArchive(newItem, newBasePath, addBlanks, archive, extracted);
ProcessArchive(newItem, newBasePath, addBlanks, archive, extracted, omitFromScan);
// Cue to delete the file if it's a copy
if (copyFiles && item != newItem)
@@ -2178,7 +2178,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="addBlanks">True if blank items should be created for empty folders, false otherwise</param>
/// <param name="archive">BaseArchive to get blank folders from, if necessary</param>
/// <param name="extracted">List of BaseFiles representing the internal files</param>
private void ProcessArchive(string item, string basePath, bool addBlanks, BaseArchive archive, List<BaseFile> extracted)
/// <param name="omitFromScan">Hash flag saying what hashes should not be calculated</param>
private void ProcessArchive(string item, string basePath, bool addBlanks, BaseArchive archive, List<BaseFile> extracted, Hash omitFromScan)
{
// Get the parent path for all items
string parent = (Path.GetDirectoryName(Path.GetFullPath(item)) + Path.DirectorySeparatorChar).Remove(0, basePath.Length) + Path.GetFileNameWithoutExtension(item);
@@ -2187,6 +2188,7 @@ namespace SabreTools.Library.DatFiles
Parallel.ForEach(extracted, Globals.ParallelOptions, baseFile =>
{
DatItem datItem = DatItem.Create(baseFile);
datItem.RemoveFields(omitFromScan.AsFields());
ProcessFileHelper(item, datItem, basePath, parent);
});
@@ -2220,8 +2222,9 @@ namespace SabreTools.Library.DatFiles
{
Globals.Logger.Verbose($"'{Path.GetFileName(item)}' treated like a file");
BaseFile baseFile = FileExtensions.GetInfo(item, addDate, Header.HeaderSkipper, asFiles);
baseFile.RemoveHashes(omitFromScan);
ProcessFileHelper(item, DatItem.Create(baseFile), basePath, string.Empty);
DatItem datItem = DatItem.Create(baseFile);
datItem.RemoveFields(omitFromScan.AsFields());
ProcessFileHelper(item, datItem, basePath, string.Empty);
}
/// <summary>
@@ -2607,21 +2610,16 @@ namespace SabreTools.Library.DatFiles
bool isTorrentGzip = tgz.IsTorrent();
// Get the base archive first
BaseArchive archive = BaseArchive.Create(file);
BaseArchive archive = BaseArchive.Create(file, quickScan);
// Now get all extracted items from the archive
if (archive != null)
{
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
entries = archive.GetChildren(omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes), date: date);
}
entries = archive.GetChildren(date: date);
// If the entries list is null, we encountered an error or have a file and should scan externally
if (entries == null && File.Exists(file))
{
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
BaseFile internalFileInfo = FileExtensions.GetInfo(file, asFiles: asFiles);
internalFileInfo.RemoveHashes(quickScan ? Hash.SecureHashes : Hash.DeepHashes);
// Create the correct DatItem
DatItem internalDatItem;

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();
}

View File

@@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems;
@@ -42,6 +43,35 @@ namespace SabreTools.Library.Tools
}
}
/// <summary>
/// Get the fields associated with each hash type
/// </summary>
public static List<Field> AsFields(this Hash hash)
{
List<Field> fields = new List<Field>();
if (hash.HasFlag(Hash.CRC))
fields.Add(Field.DatItem_CRC);
if (hash.HasFlag(Hash.MD5))
fields.Add(Field.DatItem_MD5);
#if NET_FRAMEWORK
if (hash.HasFlag(Hash.RIPEMD160))
fields.Add(Field.DatItem_RIPEMD160);
#endif
if (hash.HasFlag(Hash.SHA1))
fields.Add(Field.DatItem_SHA1);
if (hash.HasFlag(Hash.SHA256))
fields.Add(Field.DatItem_SHA256);
if (hash.HasFlag(Hash.SHA384))
fields.Add(Field.DatItem_SHA384);
if (hash.HasFlag(Hash.SHA512))
fields.Add(Field.DatItem_SHA512);
if (hash.HasFlag(Hash.SpamSum))
fields.Add(Field.DatItem_SpamSum);
return fields;
}
/// <summary>
/// Get the default OutputFormat associated with each PackingFlag
/// </summary>