[DatFile, ArchiveTools, FileTools] Fix DFD

This commit is contained in:
Matt Nadareski
2017-10-16 14:02:41 -07:00
parent a9d0483a17
commit 89489a10d0
3 changed files with 109 additions and 115 deletions

View File

@@ -815,45 +815,17 @@ namespace SabreTools.Library.Tools
MachineName = gamename,
});
}
// Otherwise, extract to a stream
// Otherwise, use the stream directly
else
{
MemoryStream entryStream = new MemoryStream();
// If the stream is smaller than the buffer, just run one loop through to avoid issues
if (streamsize < _bufferSize)
{
byte[] ibuffer = new byte[streamsize];
int ilen = readStream.Read(ibuffer, 0, (int)streamsize);
entryStream.Write(ibuffer, 0, ilen);
entryStream.Flush();
}
// Otherwise, we do the normal loop
else
{
byte[] ibuffer = new byte[_bufferSize];
int ilen;
while (streamsize > _bufferSize)
{
ilen = readStream.Read(ibuffer, 0, _bufferSize);
entryStream.Write(ibuffer, 0, ilen);
entryStream.Flush();
streamsize -= _bufferSize;
}
ilen = readStream.Read(ibuffer, 0, (int)streamsize);
entryStream.Write(ibuffer, 0, ilen);
entryStream.Flush();
}
zr = zf.CloseReadStream();
// Get and add the extended Rom information
Rom zipEntryRom = FileTools.GetStreamInfo(entryStream, entryStream.Length, omitFromScan: omitFromScan);
Rom zipEntryRom = FileTools.GetStreamInfo(readStream, (long)zf.Entries[i].UncompressedSize, omitFromScan: omitFromScan);
zipEntryRom.Name = zf.Entries[i].FileName;
zipEntryRom.MachineName = gamename;
string convertedDate = Style.ConvertMsDosTimeFormatToDateTime(zf.Entries[i].LastMod).ToString("yyyy/MM/dd hh:mm:ss");
zipEntryRom.Date = (date ? convertedDate : null);
found.Add(zipEntryRom);
zr = zf.CloseReadStream();
}
}

View File

@@ -758,13 +758,20 @@ namespace SabreTools.Library.Tools
xxHash.Init();
// Seek to the starting position, if one is set
if (offset < 0)
try
{
input.Seek(offset, SeekOrigin.End);
if (offset < 0)
{
input.Seek(offset, SeekOrigin.End);
}
else if (offset > 0)
{
input.Seek(offset, SeekOrigin.Begin);
}
}
else
catch (NotImplementedException)
{
input.Seek(offset, SeekOrigin.Begin);
Globals.Logger.Warning("Stream does not support seeking. Stream position not changed");
}
byte[] buffer = new byte[8 * 1024];
@@ -845,8 +852,15 @@ namespace SabreTools.Library.Tools
}
finally
{
// Seek to the beginning of the stream
input.Seek(0, SeekOrigin.Begin);
// Seek to the beginning of the stream if possible
try
{
input.Seek(0, SeekOrigin.Begin);
}
catch (NotImplementedException)
{
Globals.Logger.Verbose("Stream does not support seeking. Stream position not changed");
}
if (!keepReadOpen)
{