mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Gate more seeks
This commit is contained in:
@@ -114,10 +114,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
public override string? CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// Try to extract a stream using the given information
|
||||
(Stream? ms, string? realEntry) = GetEntryStream(entryName);
|
||||
(Stream? stream, string? realEntry) = GetEntryStream(entryName);
|
||||
|
||||
// If the stream and the entry name are both non-null, we write to file
|
||||
if (ms != null && realEntry != null)
|
||||
if (stream != null && realEntry != null)
|
||||
{
|
||||
realEntry = Path.Combine(outDir, realEntry);
|
||||
|
||||
@@ -128,21 +128,23 @@ namespace SabreTools.FileTypes.Archives
|
||||
FileStream fs = File.Create(realEntry);
|
||||
if (fs != null)
|
||||
{
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
if (stream.CanSeek)
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
byte[] zbuffer = new byte[_bufferSize];
|
||||
int zlen;
|
||||
while ((zlen = ms.Read(zbuffer, 0, _bufferSize)) > 0)
|
||||
while ((zlen = stream.Read(zbuffer, 0, _bufferSize)) > 0)
|
||||
{
|
||||
fs.Write(zbuffer, 0, zlen);
|
||||
fs.Flush();
|
||||
}
|
||||
|
||||
ms?.Dispose();
|
||||
stream?.Dispose();
|
||||
fs?.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
ms?.Dispose();
|
||||
stream?.Dispose();
|
||||
fs?.Dispose();
|
||||
realEntry = null;
|
||||
}
|
||||
@@ -208,10 +210,10 @@ namespace SabreTools.FileTypes.Archives
|
||||
BaseFile xzEntryRom = new();
|
||||
|
||||
// Perform a quickscan, if flagged to
|
||||
if (this.AvailableHashTypes.Length == 1 && this.AvailableHashTypes[0] == HashType.CRC32)
|
||||
if (this.AvailableHashTypes.Length == 1 && this.AvailableHashTypes[0] == HashType.CRC32)
|
||||
{
|
||||
xzEntryRom.Filename = gamename;
|
||||
|
||||
|
||||
using BinaryReader br = new(File.OpenRead(this.Filename!));
|
||||
br.BaseStream.Seek(-8, SeekOrigin.End);
|
||||
xzEntryRom.CRC = br.ReadBytesBigEndian(4);
|
||||
|
||||
Reference in New Issue
Block a user