mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Split GetInfo stream implementation
This commit is contained in:
@@ -499,7 +499,8 @@ namespace SabreTools.DatTools
|
||||
if (rule.TransformStream(fileStream, transformStream, keepReadOpen: true, keepWriteOpen: true))
|
||||
{
|
||||
// Get the file informations that we will be using
|
||||
Rom headerless = new(FileTypeTool.GetInfo(transformStream, keepReadOpen: true));
|
||||
HashType[] hashes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
|
||||
Rom headerless = new(FileTypeTool.GetInfo(transformStream, hashes, keepReadOpen: true));
|
||||
|
||||
// If we have duplicates and we're not filtering
|
||||
if (ShouldRebuild(datFile, headerless, transformStream, false, out dupes))
|
||||
@@ -573,7 +574,8 @@ namespace SabreTools.DatTools
|
||||
string? machinename = null;
|
||||
|
||||
// Get the item from the current file
|
||||
Rom item = new(FileTypeTool.GetInfo(stream, keepReadOpen: true));
|
||||
HashType[] hashes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
|
||||
Rom item = new(FileTypeTool.GetInfo(stream, hashes, keepReadOpen: true));
|
||||
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, Path.GetFileNameWithoutExtension(item.GetName()));
|
||||
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, Path.GetFileNameWithoutExtension(item.GetName()));
|
||||
|
||||
@@ -630,7 +632,8 @@ namespace SabreTools.DatTools
|
||||
string? machinename = null;
|
||||
|
||||
// Get the item from the current file
|
||||
var item = new Rom(FileTypeTool.GetInfo(stream, keepReadOpen: true));
|
||||
HashType[] hashes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
|
||||
var item = new Rom(FileTypeTool.GetInfo(stream, hashes, keepReadOpen: true));
|
||||
|
||||
// Create a machine for the current item
|
||||
var machine = new Machine();
|
||||
|
||||
@@ -239,7 +239,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
var gz = new gZip();
|
||||
ZipReturn ret = gz.ZipFileOpen(Filename);
|
||||
ret = gz.ZipFileOpenReadStream(0, out Stream? gzstream, out ulong streamSize);
|
||||
gzipEntryRom = FileTypeTool.GetInfo(gzstream, hashes: _hashTypes);
|
||||
gzipEntryRom = FileTypeTool.GetInfo(gzstream, _hashTypes);
|
||||
gzipEntryRom.Filename = gz.GetLocalFile(0).Filename;
|
||||
gzipEntryRom.Parent = gamename;
|
||||
gzipEntryRom.Date = (gz.TimeStamp > 0 ? gz.TimeStamp.ToString() : null);
|
||||
@@ -440,7 +440,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
outDir = Path.GetFullPath(outDir);
|
||||
|
||||
// Now get the Rom info for the file so we have hashes and size
|
||||
baseFile = FileTypeTool.GetInfo(inputStream, keepReadOpen: true);
|
||||
baseFile = FileTypeTool.GetInfo(inputStream, _hashTypes, keepReadOpen: true);
|
||||
|
||||
// Get the output file name
|
||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(baseFile.SHA1, Depth) ?? string.Empty);
|
||||
|
||||
@@ -210,7 +210,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
else
|
||||
{
|
||||
using Stream entryStream = entry.OpenEntryStream();
|
||||
rarEntryRom = FileTypeTool.GetInfo(entryStream, size: entry.Size, hashes: _hashTypes);
|
||||
rarEntryRom = FileTypeTool.GetInfo(entryStream, entry.Size, _hashTypes);
|
||||
}
|
||||
|
||||
// Fill in common details and add to the list
|
||||
|
||||
@@ -282,7 +282,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
zipEntryRom = FileTypeTool.GetInfo(readStream, size: (long)zf.GetLocalFile(i).UncompressedSize, hashes: _hashTypes, keepReadOpen: true);
|
||||
zipEntryRom = FileTypeTool.GetInfo(readStream,
|
||||
(long)zf.GetLocalFile(i).UncompressedSize,
|
||||
_hashTypes,
|
||||
keepReadOpen: true);
|
||||
}
|
||||
|
||||
// Fill in common details and add to the list
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
else
|
||||
{
|
||||
using Stream entryStream = entry.OpenEntryStream();
|
||||
tarEntryRom = FileTypeTool.GetInfo(entryStream, size: entry.Size, hashes: _hashTypes);
|
||||
tarEntryRom = FileTypeTool.GetInfo(entryStream, entry.Size, _hashTypes);
|
||||
}
|
||||
|
||||
// Fill in common details and add to the list
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
else
|
||||
{
|
||||
var xzStream = new XZStream(File.OpenRead(Filename!));
|
||||
xzEntryRom = FileTypeTool.GetInfo(xzStream, hashes: _hashTypes);
|
||||
xzEntryRom = FileTypeTool.GetInfo(xzStream, _hashTypes);
|
||||
xzEntryRom.Filename = gamename;
|
||||
xzStream.Dispose();
|
||||
}
|
||||
@@ -330,7 +330,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
outDir = Path.GetFullPath(outDir);
|
||||
|
||||
// Now get the Rom info for the file so we have hashes and size
|
||||
baseFile = FileTypeTool.GetInfo(inputStream, keepReadOpen: true);
|
||||
baseFile = FileTypeTool.GetInfo(inputStream, _hashTypes, keepReadOpen: true);
|
||||
|
||||
// Get the output file name
|
||||
string outfile = Path.Combine(outDir, Core.Tools.Utilities.GetDepotPath(baseFile.SHA1, Depth)!);
|
||||
|
||||
@@ -362,8 +362,8 @@ namespace SabreTools.FileTypes.Archives
|
||||
else
|
||||
{
|
||||
zipEntryRom = FileTypeTool.GetInfo(readStream,
|
||||
size: (long)localFile.UncompressedSize,
|
||||
hashes: _hashTypes,
|
||||
(long)localFile.UncompressedSize,
|
||||
_hashTypes,
|
||||
keepReadOpen: true);
|
||||
}
|
||||
|
||||
@@ -419,8 +419,8 @@ namespace SabreTools.FileTypes.Archives
|
||||
else
|
||||
{
|
||||
zipEntryRom = FileTypeTool.GetInfo(readStream,
|
||||
size: localFile.Length,
|
||||
hashes: _hashTypes,
|
||||
localFile.Length,
|
||||
_hashTypes,
|
||||
keepReadOpen: false);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SabreTools.FileTypes.Aaru;
|
||||
using SabreTools.FileTypes.Archives;
|
||||
@@ -20,8 +19,8 @@ namespace SabreTools.FileTypes
|
||||
/// </summary>
|
||||
/// <param name="input">Filename to get information from</param>
|
||||
/// <param name="hashes">Hashes to include in the information</param>
|
||||
/// <returns>Populated BaseFile object if success, null on error</returns>
|
||||
public static BaseFile? GetInfo(string input, HashType[] hashes)
|
||||
/// <returns>Populated BaseFile object if success, empty on error</returns>
|
||||
public static BaseFile GetInfo(string input, HashType[] hashes)
|
||||
=> GetInfo(input, header: null, hashes, asFiles: 0x00);
|
||||
|
||||
/// <summary>
|
||||
@@ -30,8 +29,8 @@ namespace SabreTools.FileTypes
|
||||
/// <param name="input">Filename to get information from</param>
|
||||
/// <param name="hashes">Hashes to include in the information</param>
|
||||
/// <param name="asFiles">TreatAsFiles representing special format scanning</param>
|
||||
/// <returns>Populated BaseFile object if success, null on error</returns>
|
||||
public static BaseFile? GetInfo(string input, HashType[] hashes, TreatAsFile asFiles)
|
||||
/// <returns>Populated BaseFile object if success, empty on error</returns>
|
||||
public static BaseFile GetInfo(string input, HashType[] hashes, TreatAsFile asFiles)
|
||||
=> GetInfo(input, header: null, hashes, asFiles);
|
||||
|
||||
/// <summary>
|
||||
@@ -41,12 +40,12 @@ namespace SabreTools.FileTypes
|
||||
/// <param name="header">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param>
|
||||
/// <param name="hashes">Hashes to include in the information</param>
|
||||
/// <param name="asFiles">TreatAsFiles representing special format scanning</param>
|
||||
/// <returns>Populated BaseFile object if success, null on error</returns>
|
||||
public static BaseFile? GetInfo(string input, string? header, HashType[] hashes, TreatAsFile asFiles)
|
||||
/// <returns>Populated BaseFile object if success, empty on error</returns>
|
||||
public static BaseFile GetInfo(string input, string? header, HashType[] hashes, TreatAsFile asFiles)
|
||||
{
|
||||
// Add safeguard if file doesn't exist
|
||||
if (!File.Exists(input))
|
||||
return null;
|
||||
return new BaseFile();
|
||||
|
||||
// Get input information
|
||||
var fileType = GetFileType(input);
|
||||
@@ -97,22 +96,48 @@ namespace SabreTools.FileTypes
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve file information for a single file
|
||||
/// Retrieve file information for a single stream
|
||||
/// </summary>
|
||||
/// <param name="input">Filename to get information from</param>
|
||||
/// <param name="input">Stream to get information from</param>
|
||||
/// <param name="hashes">Hashes to include in the information</param>
|
||||
/// <returns>Populated BaseFile object if success, null on error</returns>
|
||||
public static BaseFile GetInfo(Stream? input, HashType[] hashes)
|
||||
=> GetInfo(input, size: -1, hashes, keepReadOpen: false);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve file information for a single stream
|
||||
/// </summary>
|
||||
/// <param name="input">Stream to get information from</param>
|
||||
/// <param name="size">Size of the input stream</param>
|
||||
/// <param name="hashes">Hashes to include in the information</param>
|
||||
/// <param name="keepReadOpen">True if the underlying read stream should be kept open, false otherwise</param>
|
||||
/// <returns>Populated BaseFile object if success, null on error</returns>
|
||||
public static BaseFile GetInfo(Stream? input, long size, HashType[] hashes)
|
||||
=> GetInfo(input, size, hashes, keepReadOpen: false);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve file information for a single stream
|
||||
/// </summary>
|
||||
/// <param name="input">Stream to get information from</param>
|
||||
/// <param name="hashes">Hashes to include in the information</param>
|
||||
/// <param name="keepReadOpen">Indicates if the underlying read stream should be kept open</param>
|
||||
/// <returns>Populated BaseFile object if success, null on error</returns>
|
||||
public static BaseFile GetInfo(Stream? input, HashType[] hashes, bool keepReadOpen)
|
||||
=> GetInfo(input, size: -1, hashes, keepReadOpen);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve file information for a single file
|
||||
/// </summary>
|
||||
/// <param name="input">Stream to get information from</param>
|
||||
/// <param name="size">Size of the input stream</param>
|
||||
/// <param name="hashes">Hashes to include in the information</param>
|
||||
/// <param name="keepReadOpen">Indicates if the underlying read stream should be kept open</param>
|
||||
/// <returns>Populated BaseFile object if success, empty one on error</returns>
|
||||
public static BaseFile GetInfo(Stream? input, long size = -1, HashType[]? hashes = null, bool keepReadOpen = false)
|
||||
public static BaseFile GetInfo(Stream? input, long size, HashType[]? hashes, bool keepReadOpen)
|
||||
{
|
||||
// If we have no stream
|
||||
if (input == null)
|
||||
return new BaseFile();
|
||||
|
||||
// If no hashes are set, use the standard array
|
||||
hashes ??= [HashType.CRC32, HashType.MD5, HashType.SHA1];
|
||||
|
||||
// If we want to automatically set the size
|
||||
if (size == -1)
|
||||
size = input.Length;
|
||||
|
||||
Reference in New Issue
Block a user