diff --git a/SabreTools.DatTools/Rebuilder.cs b/SabreTools.DatTools/Rebuilder.cs index fdebfddb..0643aa37 100644 --- a/SabreTools.DatTools/Rebuilder.cs +++ b/SabreTools.DatTools/Rebuilder.cs @@ -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(DatItem.MachineKey)!.SetFieldValue(Models.Metadata.Machine.DescriptionKey, Path.GetFileNameWithoutExtension(item.GetName())); item.GetFieldValue(DatItem.MachineKey)!.SetFieldValue(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(); diff --git a/SabreTools.FileTypes/Archives/GZipArchive.cs b/SabreTools.FileTypes/Archives/GZipArchive.cs index 3f700b20..1116c527 100644 --- a/SabreTools.FileTypes/Archives/GZipArchive.cs +++ b/SabreTools.FileTypes/Archives/GZipArchive.cs @@ -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); diff --git a/SabreTools.FileTypes/Archives/SevenZipArchive.cs b/SabreTools.FileTypes/Archives/SevenZipArchive.cs index 89d8ade1..7738377f 100644 --- a/SabreTools.FileTypes/Archives/SevenZipArchive.cs +++ b/SabreTools.FileTypes/Archives/SevenZipArchive.cs @@ -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 diff --git a/SabreTools.FileTypes/Archives/XZArchive.cs b/SabreTools.FileTypes/Archives/XZArchive.cs index f9a51b75..14ff2eed 100644 --- a/SabreTools.FileTypes/Archives/XZArchive.cs +++ b/SabreTools.FileTypes/Archives/XZArchive.cs @@ -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)!); diff --git a/SabreTools.FileTypes/Archives/ZipArchive.cs b/SabreTools.FileTypes/Archives/ZipArchive.cs index a3bd5267..823e1755 100644 --- a/SabreTools.FileTypes/Archives/ZipArchive.cs +++ b/SabreTools.FileTypes/Archives/ZipArchive.cs @@ -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 diff --git a/SabreTools.FileTypes/FileTypeTool.cs b/SabreTools.FileTypes/FileTypeTool.cs index 61137d18..ed30bf5a 100644 --- a/SabreTools.FileTypes/FileTypeTool.cs +++ b/SabreTools.FileTypes/FileTypeTool.cs @@ -60,24 +60,13 @@ namespace SabreTools.FileTypes } } - /// - /// Retrieve file information for a single stream - /// - /// Stream to get information from - /// Hashes to include in the information - /// Populated BaseFile object if success, null on error - public static BaseFile GetInfo(Stream? input, HashType[] hashes) - => GetInfo(input, hashes, keepReadOpen: false); - /// /// Retrieve file information for a single file /// /// Stream to get information from - /// Size of the input stream /// Hashes to include in the information - /// Indicates if the underlying read stream should be kept open /// Populated BaseFile object if success, empty one on error - 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)