mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[FileTypes/] BaseFile for life
This commit is contained in:
@@ -12,7 +12,7 @@ using Stream = System.IO.Stream;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
public abstract class BaseArchive : BaseFile
|
||||
public abstract class BaseArchive : Folder
|
||||
{
|
||||
#region Protected instance variables
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// </summary>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
public abstract bool ExtractAll(string outDir);
|
||||
public new abstract bool ExtractAll(string outDir);
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract an entry from an archive
|
||||
@@ -56,7 +56,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
public abstract string ExtractEntry(string entryName, string outDir);
|
||||
public new abstract string ExtractEntry(string entryName, string outDir);
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a stream from an archive
|
||||
@@ -64,7 +64,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
public abstract (MemoryStream, string) ExtractEntryStream(string entryName);
|
||||
public new abstract (MemoryStream, string) ExtractEntryStream(string entryName);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -77,14 +77,14 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <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 abstract List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false);
|
||||
public new abstract List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false);
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of empty folders in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the archive</returns>
|
||||
public abstract List<string> GetEmptyFolders();
|
||||
public new abstract List<string> GetEmptyFolders();
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the input file is a standardized format
|
||||
|
||||
@@ -4,13 +4,14 @@ using SabreTools.Library.Data;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
public abstract class BaseFile
|
||||
public class BaseFile
|
||||
{
|
||||
#region Protected instance variables
|
||||
|
||||
protected FileType _fileType;
|
||||
protected string _filename;
|
||||
protected List<BaseFile> _children;
|
||||
protected string _parent;
|
||||
protected string _date;
|
||||
|
||||
// External hash values for the file
|
||||
protected long? _size;
|
||||
@@ -26,11 +27,25 @@ namespace SabreTools.Library.FileTypes
|
||||
#region Publicly facing variables
|
||||
|
||||
// TODO: Get all of these values automatically so there is no public "set"
|
||||
public FileType Type
|
||||
{
|
||||
get { return _fileType; }
|
||||
}
|
||||
public string Filename
|
||||
{
|
||||
get { return _filename; }
|
||||
set { _filename = value; }
|
||||
}
|
||||
public string Parent
|
||||
{
|
||||
get { return _parent; }
|
||||
set { _parent = value; }
|
||||
}
|
||||
public string Date
|
||||
{
|
||||
get { return _date; }
|
||||
set { _date = value; }
|
||||
}
|
||||
public long? Size
|
||||
{
|
||||
get { return _size; }
|
||||
|
||||
@@ -167,7 +167,7 @@ namespace SabreTools.Library.FileTypes
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -27,8 +27,14 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <summary>
|
||||
/// Represents a folder for reading and writing
|
||||
/// </summary>
|
||||
public class Folder : BaseArchive
|
||||
public class Folder : BaseFile
|
||||
{
|
||||
#region Protected instance variables
|
||||
|
||||
protected List<BaseFile> _children;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
@@ -60,7 +66,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// </summary>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
public override bool ExtractAll(string outDir)
|
||||
public bool ExtractAll(string outDir)
|
||||
{
|
||||
// Copy all files from the current folder to the output directory recursively
|
||||
try
|
||||
@@ -86,7 +92,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
public override string ExtractEntry(string entryName, string outDir)
|
||||
public string ExtractEntry(string entryName, string outDir)
|
||||
{
|
||||
string realentry = null;
|
||||
|
||||
@@ -125,7 +131,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
public override (MemoryStream, string) ExtractEntryStream(string entryName)
|
||||
public (MemoryStream, string) ExtractEntryStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
string realentry = null;
|
||||
@@ -163,33 +169,40 @@ namespace SabreTools.Library.FileTypes
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of DatItem objects from the header values in an archive
|
||||
/// 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 DatItem objects representing the found data</returns>
|
||||
/// <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 override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
public List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (_children == null || _children.Count == 0)
|
||||
{
|
||||
_children = new List<BaseFile>();
|
||||
foreach (string file in Directory.EnumerateFiles(_filename, "*", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
BaseFile nf = Utilities.GetFileInfo(file, omitFromScan: omitFromScan, date: date);
|
||||
_children.Add(nf);
|
||||
}
|
||||
foreach (string dir in Directory.EnumerateDirectories(_filename, "*", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
Folder fl = new Folder(dir);
|
||||
_children.Add(fl);
|
||||
}
|
||||
}
|
||||
|
||||
return _children;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of empty folders in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the archive</returns>
|
||||
public override List<string> GetEmptyFolders()
|
||||
/// <returns>List of empty folders in the folder</returns>
|
||||
public List<string> GetEmptyFolders()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the input file is a standardized format
|
||||
/// </summary>
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return Utilities.GetEmptyDirectories(_filename).ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -206,7 +219,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
|
||||
/// <returns>True if the write was a success, false otherwise</returns>
|
||||
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
|
||||
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool romba = false)
|
||||
public bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool romba = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -221,7 +234,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
|
||||
/// <returns>True if the write was a success, false otherwise</returns>
|
||||
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool romba = false)
|
||||
public bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool romba = false)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
@@ -303,7 +316,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
|
||||
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
|
||||
public bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -194,54 +194,59 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <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<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
{
|
||||
List<Rom> found = new List<Rom>();
|
||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||
|
||||
Rom possibleTgz = GetTorrentGZFileInfo();
|
||||
|
||||
// If it was, then add it to the outputs and continue
|
||||
if (possibleTgz != null && possibleTgz.Name != null)
|
||||
if (_children == null || _children.Count == 0)
|
||||
{
|
||||
found.Add(possibleTgz);
|
||||
return found;
|
||||
}
|
||||
_children = new List<BaseFile>();
|
||||
|
||||
try
|
||||
{
|
||||
// If secure hashes are disabled, do a quickscan
|
||||
if (omitFromScan == Hash.SecureHashes)
|
||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||
|
||||
BaseFile possibleTgz = GetTorrentGZFileInfo();
|
||||
|
||||
// If it was, then add it to the outputs and continue
|
||||
if (possibleTgz != null && possibleTgz.Filename != null)
|
||||
{
|
||||
Rom tempRom = new Rom(gamename, gamename, omitFromScan);
|
||||
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(_filename));
|
||||
br.BaseStream.Seek(-8, SeekOrigin.End);
|
||||
byte[] headercrc = br.ReadBytesReverse(4);
|
||||
tempRom.CRC = Utilities.ByteArrayToString(headercrc);
|
||||
tempRom.Size = br.ReadInt32Reverse();
|
||||
br.Dispose();
|
||||
|
||||
found.Add(tempRom);
|
||||
_children.Add(possibleTgz);
|
||||
}
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(_filename), Ionic.Zlib.CompressionMode.Decompress);
|
||||
Rom gzipEntryRom = (Rom)Utilities.GetStreamInfo(gzstream, gzstream.Length, omitFromScan: omitFromScan);
|
||||
gzipEntryRom.Name = gzstream.FileName;
|
||||
gzipEntryRom.MachineName = gamename;
|
||||
gzipEntryRom.Date = (date && gzstream.LastModified != null ? gzstream.LastModified?.ToString("yyyy/MM/dd hh:mm:ss") : null);
|
||||
found.Add(gzipEntryRom);
|
||||
gzstream.Dispose();
|
||||
try
|
||||
{
|
||||
// If secure hashes are disabled, do a quickscan
|
||||
if (omitFromScan == Hash.SecureHashes)
|
||||
{
|
||||
BaseFile tempRom = new BaseFile(gamename);
|
||||
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(_filename));
|
||||
br.BaseStream.Seek(-8, SeekOrigin.End);
|
||||
byte[] headercrc = br.ReadBytesReverse(4);
|
||||
tempRom.CRC = headercrc;
|
||||
tempRom.Size = br.ReadInt32Reverse();
|
||||
br.Dispose();
|
||||
|
||||
_children.Add(tempRom);
|
||||
}
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(_filename), Ionic.Zlib.CompressionMode.Decompress);
|
||||
BaseFile gzipEntryRom = Utilities.GetStreamInfo(gzstream, gzstream.Length, omitFromScan: omitFromScan);
|
||||
gzipEntryRom.Filename = gzstream.FileName;
|
||||
gzipEntryRom.Parent = gamename;
|
||||
gzipEntryRom.Date = (date && gzstream.LastModified != null ? gzstream.LastModified?.ToString("yyyy/MM/dd hh:mm:ss") : null);
|
||||
_children.Add(gzipEntryRom);
|
||||
gzstream.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Don't log file open errors
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Don't log file open errors
|
||||
return null;
|
||||
}
|
||||
|
||||
return found;
|
||||
return _children;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -325,7 +330,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// Retrieve file information for a single torrent GZ file
|
||||
/// </summary>
|
||||
/// <returns>Populated DatItem object if success, empty one on error</returns>
|
||||
public Rom GetTorrentGZFileInfo()
|
||||
public BaseFile GetTorrentGZFileInfo()
|
||||
{
|
||||
// Check for the file existing first
|
||||
if (!File.Exists(_filename))
|
||||
@@ -386,23 +391,20 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// Now convert the data and get the right position
|
||||
string gzmd5 = Utilities.ByteArrayToString(headermd5);
|
||||
string gzcrc = Utilities.ByteArrayToString(headercrc);
|
||||
long extractedsize = (long)headersz;
|
||||
|
||||
Rom rom = new Rom
|
||||
BaseFile baseFile = new BaseFile
|
||||
{
|
||||
Type = ItemType.Rom,
|
||||
Name = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(),
|
||||
Filename = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(),
|
||||
Size = extractedsize,
|
||||
CRC = gzcrc.ToLowerInvariant(),
|
||||
MD5 = gzmd5.ToLowerInvariant(),
|
||||
SHA1 = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(), // TODO: When updating to SHA-256, this needs to update to SHA256
|
||||
CRC = headercrc,
|
||||
MD5 = headermd5,
|
||||
SHA1 = Utilities.StringToByteArray(Path.GetFileNameWithoutExtension(_filename)), // TODO: When updating to SHA-256, this needs to update to SHA256
|
||||
|
||||
MachineName = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(),
|
||||
Parent = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(),
|
||||
};
|
||||
|
||||
return rom;
|
||||
return baseFile;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -461,7 +463,7 @@ namespace SabreTools.Library.FileTypes
|
||||
outDir = Path.GetFullPath(outDir);
|
||||
|
||||
// Now get the Rom info for the file so we have hashes and size
|
||||
rom = (Rom)Utilities.GetStreamInfo(inputStream, inputStream.Length, keepReadOpen: true);
|
||||
rom = new Rom(Utilities.GetStreamInfo(inputStream, inputStream.Length, keepReadOpen: true));
|
||||
|
||||
// Get the output file name
|
||||
string outfile = null;
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <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<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <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<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -187,9 +187,9 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <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<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
{
|
||||
List<Rom> found = new List<Rom>();
|
||||
List<BaseFile> found = new List<BaseFile>();
|
||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||
|
||||
try
|
||||
@@ -200,24 +200,23 @@ namespace SabreTools.Library.FileTypes
|
||||
// If secure hashes are disabled, do a quickscan
|
||||
if (omitFromScan == Hash.SecureHashes)
|
||||
{
|
||||
found.Add(new Rom
|
||||
found.Add(new BaseFile
|
||||
{
|
||||
Type = ItemType.Rom,
|
||||
Name = entry.Key,
|
||||
Filename = entry.Key,
|
||||
Size = entry.Size,
|
||||
CRC = entry.Crc.ToString("X").ToLowerInvariant(),
|
||||
CRC = BitConverter.GetBytes(entry.Crc),
|
||||
Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null),
|
||||
|
||||
MachineName = gamename,
|
||||
Parent = gamename,
|
||||
});
|
||||
}
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
Stream entryStream = entry.OpenEntryStream();
|
||||
Rom rarEntryRom = (Rom)Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
||||
rarEntryRom.Name = entry.Key;
|
||||
rarEntryRom.MachineName = gamename;
|
||||
BaseFile rarEntryRom = Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
||||
rarEntryRom.Filename = entry.Key;
|
||||
rarEntryRom.Parent = gamename;
|
||||
rarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
|
||||
found.Add(rarEntryRom);
|
||||
entryStream.Dispose();
|
||||
|
||||
@@ -191,9 +191,9 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <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<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
{
|
||||
List<Rom> found = new List<Rom>();
|
||||
List<BaseFile> found = new List<BaseFile>();
|
||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||
|
||||
try
|
||||
@@ -204,24 +204,23 @@ namespace SabreTools.Library.FileTypes
|
||||
// If secure hashes are disabled, do a quickscan
|
||||
if (omitFromScan == Hash.SecureHashes)
|
||||
{
|
||||
found.Add(new Rom
|
||||
found.Add(new BaseFile
|
||||
{
|
||||
Type = ItemType.Rom,
|
||||
Name = entry.Key,
|
||||
Filename = entry.Key,
|
||||
Size = entry.Size,
|
||||
CRC = entry.Crc.ToString("X").ToLowerInvariant(),
|
||||
CRC = BitConverter.GetBytes(entry.Crc),
|
||||
Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null),
|
||||
|
||||
MachineName = gamename,
|
||||
Parent = gamename,
|
||||
});
|
||||
}
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
Stream entryStream = entry.OpenEntryStream();
|
||||
Rom sevenZipEntryRom = (Rom)Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
||||
sevenZipEntryRom.Name = entry.Key;
|
||||
sevenZipEntryRom.MachineName = gamename;
|
||||
BaseFile sevenZipEntryRom = Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
||||
sevenZipEntryRom.Filename = entry.Key;
|
||||
sevenZipEntryRom.Parent = gamename;
|
||||
sevenZipEntryRom.Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null);
|
||||
found.Add(sevenZipEntryRom);
|
||||
entryStream.Dispose();
|
||||
|
||||
@@ -190,9 +190,9 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <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<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
{
|
||||
List<Rom> found = new List<Rom>();
|
||||
List<BaseFile> found = new List<BaseFile>();
|
||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||
|
||||
try
|
||||
@@ -203,24 +203,23 @@ namespace SabreTools.Library.FileTypes
|
||||
// If secure hashes are disabled, do a quickscan
|
||||
if (omitFromScan == Hash.SecureHashes)
|
||||
{
|
||||
found.Add(new Rom
|
||||
found.Add(new BaseFile
|
||||
{
|
||||
Type = ItemType.Rom,
|
||||
Name = entry.Key,
|
||||
Filename = entry.Key,
|
||||
Size = entry.Size,
|
||||
CRC = entry.Crc.ToString("X").ToLowerInvariant(),
|
||||
CRC = BitConverter.GetBytes(entry.Crc),
|
||||
Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null),
|
||||
|
||||
MachineName = gamename,
|
||||
Parent = gamename,
|
||||
});
|
||||
}
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
Stream entryStream = entry.OpenEntryStream();
|
||||
Rom tarEntryRom = (Rom)Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
||||
tarEntryRom.Name = entry.Key;
|
||||
tarEntryRom.MachineName = gamename;
|
||||
BaseFile tarEntryRom = Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
||||
tarEntryRom.Filename = entry.Key;
|
||||
tarEntryRom.Parent = gamename;
|
||||
tarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
|
||||
found.Add(tarEntryRom);
|
||||
entryStream.Dispose();
|
||||
|
||||
@@ -268,9 +268,9 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <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<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
{
|
||||
List<Rom> found = new List<Rom>();
|
||||
List<BaseFile> found = new List<BaseFile>();
|
||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||
|
||||
try
|
||||
@@ -300,26 +300,25 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
string newname = zf.Entries[i].FileName;
|
||||
long newsize = (long)zf.Entries[i].UncompressedSize;
|
||||
string newcrc = BitConverter.ToString(zf.Entries[i].CRC.Reverse().ToArray(), 0, zf.Entries[i].CRC.Length).Replace("-", string.Empty).ToLowerInvariant();
|
||||
byte[] newcrc = zf.Entries[i].CRC.Reverse().ToArray();
|
||||
string convertedDate = Utilities.ConvertMsDosTimeFormatToDateTime(zf.Entries[i].LastMod).ToString("yyyy/MM/dd hh:mm:ss");
|
||||
|
||||
found.Add(new Rom
|
||||
found.Add(new BaseFile
|
||||
{
|
||||
Type = ItemType.Rom,
|
||||
Name = newname,
|
||||
Filename = newname,
|
||||
Size = newsize,
|
||||
CRC = newcrc,
|
||||
Date = (date ? convertedDate : null),
|
||||
|
||||
MachineName = gamename,
|
||||
Parent = gamename,
|
||||
});
|
||||
}
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
Rom zipEntryRom = (Rom)Utilities.GetStreamInfo(readStream, (long)zf.Entries[i].UncompressedSize, omitFromScan: omitFromScan);
|
||||
zipEntryRom.Name = zf.Entries[i].FileName;
|
||||
zipEntryRom.MachineName = gamename;
|
||||
BaseFile zipEntryRom = Utilities.GetStreamInfo(readStream, (long)zf.Entries[i].UncompressedSize, omitFromScan: omitFromScan);
|
||||
zipEntryRom.Filename = zf.Entries[i].FileName;
|
||||
zipEntryRom.Parent = gamename;
|
||||
string convertedDate = Utilities.ConvertMsDosTimeFormatToDateTime(zf.Entries[i].LastMod).ToString("yyyy/MM/dd hh:mm:ss");
|
||||
zipEntryRom.Date = (date ? convertedDate : null);
|
||||
found.Add(zipEntryRom);
|
||||
|
||||
@@ -191,7 +191,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <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<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <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<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <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<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user