[ArchiveTools, FileTools] Pattern size safety of other archives off Zip

This commit is contained in:
Matt Nadareski
2017-10-18 22:39:24 -07:00
parent 3b250af990
commit be781c3d1c
2 changed files with 30 additions and 39 deletions

View File

@@ -640,19 +640,16 @@ namespace SabreTools.Library.Tools
MachineName = gamename, MachineName = gamename,
}); });
} }
// Otherwise, extract to a stream // Otherwise, use the stream directly
else else
{ {
// Create and populate the entry stream Stream entryStream = entry.OpenEntryStream();
MemoryStream entryStream = new MemoryStream(); Rom sevenZipEntryRom = FileTools.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
entry.WriteTo(entryStream);
// Get and add the extended Rom information
Rom sevenZipEntryRom = FileTools.GetStreamInfo(entryStream, entryStream.Length, omitFromScan: omitFromScan);
sevenZipEntryRom.Name = entry.Key; sevenZipEntryRom.Name = entry.Key;
sevenZipEntryRom.MachineName = gamename; sevenZipEntryRom.MachineName = gamename;
sevenZipEntryRom.Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null); sevenZipEntryRom.Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null);
found.Add(sevenZipEntryRom); found.Add(sevenZipEntryRom);
entryStream.Dispose();
} }
} }
@@ -676,22 +673,15 @@ namespace SabreTools.Library.Tools
found.Add(tempRom); found.Add(tempRom);
} }
// Otherwise, extract to a stream // Otherwise, use the stream directly
else else
{ {
// Create and populate the entry stream
MemoryStream outstream = new MemoryStream();
GZipStream gzstream = new GZipStream(FileTools.TryOpenRead(input), Ionic.Zlib.CompressionMode.Decompress); GZipStream gzstream = new GZipStream(FileTools.TryOpenRead(input), Ionic.Zlib.CompressionMode.Decompress);
gzstream.CopyTo(outstream); Rom gzipEntryRom = FileTools.GetStreamInfo(gzstream, gzstream.Length, omitFromScan: omitFromScan);
// Get and add the extended Rom information
Rom gzipEntryRom = FileTools.GetStreamInfo(outstream, outstream.Length, omitFromScan: omitFromScan);
gzipEntryRom.Name = gzstream.FileName; gzipEntryRom.Name = gzstream.FileName;
gzipEntryRom.MachineName = gamename; gzipEntryRom.MachineName = gamename;
gzipEntryRom.Date = (date && gzstream.LastModified != null ? gzstream.LastModified?.ToString("yyyy/MM/dd hh:mm:ss") : null); gzipEntryRom.Date = (date && gzstream.LastModified != null ? gzstream.LastModified?.ToString("yyyy/MM/dd hh:mm:ss") : null);
found.Add(gzipEntryRom); found.Add(gzipEntryRom);
// Dispose of the archive
gzstream.Dispose(); gzstream.Dispose();
} }
break; break;
@@ -715,19 +705,16 @@ namespace SabreTools.Library.Tools
MachineName = gamename, MachineName = gamename,
}); });
} }
// Otherwise, extract to a stream // Otherwise, use the stream directly
else else
{ {
// Create and populate the entry stream Stream entryStream = entry.OpenEntryStream();
MemoryStream entryStream = new MemoryStream(); Rom rarEntryRom = FileTools.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
entry.WriteTo(entryStream); rarEntryRom.Name = entry.Key;
rarEntryRom.MachineName = gamename;
// Get and add the extended Rom information rarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
Rom sevenZipEntryRom = FileTools.GetStreamInfo(entryStream, entryStream.Length, omitFromScan: omitFromScan); found.Add(rarEntryRom);
sevenZipEntryRom.Name = entry.Key; entryStream.Dispose();
sevenZipEntryRom.MachineName = gamename;
sevenZipEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
found.Add(sevenZipEntryRom);
} }
} }
@@ -754,19 +741,16 @@ namespace SabreTools.Library.Tools
MachineName = gamename, MachineName = gamename,
}); });
} }
// Otherwise, extract to a stream // Otherwise, use the stream directly
else else
{ {
// Create and populate the entry stream Stream entryStream = entry.OpenEntryStream();
MemoryStream entryStream = new MemoryStream(); Rom tarEntryRom = FileTools.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
entry.WriteTo(entryStream); tarEntryRom.Name = entry.Key;
tarEntryRom.MachineName = gamename;
// Get and add the extended Rom information tarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
Rom sevenZipEntryRom = FileTools.GetStreamInfo(entryStream, entryStream.Length, omitFromScan: omitFromScan); found.Add(tarEntryRom);
sevenZipEntryRom.Name = entry.Key; entryStream.Dispose();
sevenZipEntryRom.MachineName = gamename;
sevenZipEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
found.Add(sevenZipEntryRom);
} }
} }
@@ -818,7 +802,6 @@ namespace SabreTools.Library.Tools
// Otherwise, use the stream directly // Otherwise, use the stream directly
else else
{ {
// Get and add the extended Rom information
Rom zipEntryRom = FileTools.GetStreamInfo(readStream, (long)zf.Entries[i].UncompressedSize, omitFromScan: omitFromScan); Rom zipEntryRom = FileTools.GetStreamInfo(readStream, (long)zf.Entries[i].UncompressedSize, omitFromScan: omitFromScan);
zipEntryRom.Name = zf.Entries[i].FileName; zipEntryRom.Name = zf.Entries[i].FileName;
zipEntryRom.MachineName = gamename; zipEntryRom.MachineName = gamename;

View File

@@ -769,6 +769,10 @@ namespace SabreTools.Library.Tools
input.Seek(offset, SeekOrigin.Begin); input.Seek(offset, SeekOrigin.Begin);
} }
} }
catch (NotSupportedException)
{
Globals.Logger.Verbose("Stream does not support seeking. Stream position not changed");
}
catch (NotImplementedException) catch (NotImplementedException)
{ {
Globals.Logger.Warning("Stream does not support seeking. Stream position not changed"); Globals.Logger.Warning("Stream does not support seeking. Stream position not changed");
@@ -857,6 +861,10 @@ namespace SabreTools.Library.Tools
{ {
input.Seek(0, SeekOrigin.Begin); input.Seek(0, SeekOrigin.Begin);
} }
catch (NotSupportedException)
{
Globals.Logger.Verbose("Stream does not support seeking. Stream position not changed");
}
catch (NotImplementedException) catch (NotImplementedException)
{ {
Globals.Logger.Verbose("Stream does not support seeking. Stream position not changed"); Globals.Logger.Verbose("Stream does not support seeking. Stream position not changed");