mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Let calling locations handle Stream state
This commit is contained in:
@@ -500,7 +500,7 @@ namespace SabreTools.DatTools
|
||||
{
|
||||
// Get the file informations that we will be using
|
||||
HashType[] hashes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
|
||||
Rom headerless = new(FileTypeTool.GetInfo(transformStream, hashes, keepReadOpen: true));
|
||||
Rom headerless = new(FileTypeTool.GetInfo(transformStream, hashes));
|
||||
|
||||
// If we have duplicates and we're not filtering
|
||||
if (ShouldRebuild(datFile, headerless, transformStream, false, out dupes))
|
||||
@@ -575,7 +575,7 @@ namespace SabreTools.DatTools
|
||||
|
||||
// Get the item from the current file
|
||||
HashType[] hashes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
|
||||
Rom item = new(FileTypeTool.GetInfo(stream, hashes, keepReadOpen: true));
|
||||
Rom item = new(FileTypeTool.GetInfo(stream, hashes));
|
||||
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()));
|
||||
|
||||
@@ -633,7 +633,7 @@ namespace SabreTools.DatTools
|
||||
|
||||
// Get the item from the current file
|
||||
HashType[] hashes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
|
||||
var item = new Rom(FileTypeTool.GetInfo(stream, hashes, keepReadOpen: true));
|
||||
var item = new Rom(FileTypeTool.GetInfo(stream, hashes));
|
||||
|
||||
// Create a machine for the current item
|
||||
var machine = new Machine();
|
||||
|
||||
@@ -244,7 +244,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
gzipEntryRom.Filename = gz.GetLocalFile(0).Filename;
|
||||
gzipEntryRom.Parent = gamename;
|
||||
gzipEntryRom.Date = (gz.TimeStamp > 0 ? gz.TimeStamp.ToString() : null);
|
||||
gzstream!.Dispose();
|
||||
gzstream?.Dispose();
|
||||
}
|
||||
|
||||
// Fill in common details and add to the list
|
||||
@@ -438,7 +438,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
outDir = Path.GetFullPath(outDir);
|
||||
|
||||
// If the base file is null, get the hash information
|
||||
baseFile ??= FileTypeTool.GetInfo(stream, _hashTypes, keepReadOpen: true);
|
||||
baseFile ??= FileTypeTool.GetInfo(stream, _hashTypes);
|
||||
|
||||
// Get the output file name
|
||||
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(baseFile.SHA1, Depth) ?? string.Empty);
|
||||
|
||||
@@ -282,9 +282,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
zipEntryRom = FileTypeTool.GetInfo(readStream,
|
||||
_hashTypes,
|
||||
keepReadOpen: true);
|
||||
zipEntryRom = FileTypeTool.GetInfo(readStream, _hashTypes);
|
||||
}
|
||||
|
||||
// Fill in common details and add to the list
|
||||
|
||||
@@ -332,7 +332,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
outDir = Path.GetFullPath(outDir);
|
||||
|
||||
// If the base file is null, get the hash information
|
||||
baseFile ??= FileTypeTool.GetInfo(stream, _hashTypes, keepReadOpen: true);
|
||||
baseFile ??= FileTypeTool.GetInfo(stream, _hashTypes);
|
||||
|
||||
// Get the output file name
|
||||
string outfile = Path.Combine(outDir, Core.Tools.Utilities.GetDepotPath(baseFile.SHA1, Depth)!);
|
||||
|
||||
@@ -361,9 +361,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
zipEntryRom = FileTypeTool.GetInfo(readStream,
|
||||
_hashTypes,
|
||||
keepReadOpen: true);
|
||||
zipEntryRom = FileTypeTool.GetInfo(readStream, _hashTypes);
|
||||
}
|
||||
|
||||
// Fill in common details and add to the list
|
||||
@@ -417,9 +415,7 @@ namespace SabreTools.FileTypes.Archives
|
||||
// Otherwise, use the stream directly
|
||||
else
|
||||
{
|
||||
zipEntryRom = FileTypeTool.GetInfo(readStream,
|
||||
_hashTypes,
|
||||
keepReadOpen: true);
|
||||
zipEntryRom = FileTypeTool.GetInfo(readStream, _hashTypes);
|
||||
}
|
||||
|
||||
// Fill in common details and add to the list
|
||||
|
||||
@@ -60,24 +60,13 @@ namespace SabreTools.FileTypes
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <returns>Populated BaseFile object if success, null on error</returns>
|
||||
public static BaseFile GetInfo(Stream? input, HashType[] hashes)
|
||||
=> GetInfo(input, hashes, keepReadOpen: false);
|
||||
|
||||
/// <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, HashType[] hashes, bool keepReadOpen)
|
||||
public static BaseFile GetInfo(Stream? input, HashType[] hashes)
|
||||
{
|
||||
// If we have no stream
|
||||
if (input == null)
|
||||
@@ -103,17 +92,8 @@ namespace SabreTools.FileTypes
|
||||
SpamSum = hashDict.ContainsKey(HashType.SpamSum) ? hashDict[HashType.SpamSum].FromHexString() : null,
|
||||
};
|
||||
|
||||
// Deal with the input stream
|
||||
if (!keepReadOpen)
|
||||
{
|
||||
input.Close();
|
||||
input.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
input.SeekIfPossible();
|
||||
}
|
||||
|
||||
// Deal with the input stream and return
|
||||
input.SeekIfPossible();
|
||||
return baseFile;
|
||||
}
|
||||
catch
|
||||
@@ -148,7 +128,7 @@ namespace SabreTools.FileTypes
|
||||
private static BaseFile? GetBaseFile(Stream input, FileType? fileType, HashType[] hashes)
|
||||
{
|
||||
// Get external file information
|
||||
BaseFile? baseFile = GetInfo(input, hashes, keepReadOpen: true);
|
||||
BaseFile? baseFile = GetInfo(input, hashes);
|
||||
|
||||
// Get internal hashes, if they exist
|
||||
if (fileType == FileType.AaruFormat)
|
||||
|
||||
Reference in New Issue
Block a user