diff --git a/SabreTools.Library/Tools/ArchiveTools.cs b/SabreTools.Library/Tools/ArchiveTools.cs index 9ebe54df..d9c65864 100644 --- a/SabreTools.Library/Tools/ArchiveTools.cs +++ b/SabreTools.Library/Tools/ArchiveTools.cs @@ -640,19 +640,16 @@ namespace SabreTools.Library.Tools MachineName = gamename, }); } - // Otherwise, extract to a stream + // Otherwise, use the stream directly else { - // Create and populate the entry stream - MemoryStream entryStream = new MemoryStream(); - entry.WriteTo(entryStream); - - // Get and add the extended Rom information - Rom sevenZipEntryRom = FileTools.GetStreamInfo(entryStream, entryStream.Length, omitFromScan: omitFromScan); + Stream entryStream = entry.OpenEntryStream(); + Rom sevenZipEntryRom = FileTools.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan); sevenZipEntryRom.Name = entry.Key; sevenZipEntryRom.MachineName = gamename; sevenZipEntryRom.Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null); found.Add(sevenZipEntryRom); + entryStream.Dispose(); } } @@ -676,22 +673,15 @@ namespace SabreTools.Library.Tools found.Add(tempRom); } - // Otherwise, extract to a stream + // Otherwise, use the stream directly else { - // Create and populate the entry stream - MemoryStream outstream = new MemoryStream(); GZipStream gzstream = new GZipStream(FileTools.TryOpenRead(input), Ionic.Zlib.CompressionMode.Decompress); - gzstream.CopyTo(outstream); - - // Get and add the extended Rom information - Rom gzipEntryRom = FileTools.GetStreamInfo(outstream, outstream.Length, omitFromScan: omitFromScan); + Rom gzipEntryRom = FileTools.GetStreamInfo(gzstream, gzstream.Length, omitFromScan: omitFromScan); gzipEntryRom.Name = gzstream.FileName; gzipEntryRom.MachineName = gamename; gzipEntryRom.Date = (date && gzstream.LastModified != null ? gzstream.LastModified?.ToString("yyyy/MM/dd hh:mm:ss") : null); found.Add(gzipEntryRom); - - // Dispose of the archive gzstream.Dispose(); } break; @@ -715,19 +705,16 @@ namespace SabreTools.Library.Tools MachineName = gamename, }); } - // Otherwise, extract to a stream + // Otherwise, use the stream directly else { - // Create and populate the entry stream - MemoryStream entryStream = new MemoryStream(); - entry.WriteTo(entryStream); - - // Get and add the extended Rom information - Rom sevenZipEntryRom = FileTools.GetStreamInfo(entryStream, entryStream.Length, omitFromScan: omitFromScan); - sevenZipEntryRom.Name = entry.Key; - sevenZipEntryRom.MachineName = gamename; - sevenZipEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss"); - found.Add(sevenZipEntryRom); + Stream entryStream = entry.OpenEntryStream(); + Rom rarEntryRom = FileTools.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan); + rarEntryRom.Name = entry.Key; + rarEntryRom.MachineName = gamename; + rarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss"); + found.Add(rarEntryRom); + entryStream.Dispose(); } } @@ -754,19 +741,16 @@ namespace SabreTools.Library.Tools MachineName = gamename, }); } - // Otherwise, extract to a stream + // Otherwise, use the stream directly else { - // Create and populate the entry stream - MemoryStream entryStream = new MemoryStream(); - entry.WriteTo(entryStream); - - // Get and add the extended Rom information - Rom sevenZipEntryRom = FileTools.GetStreamInfo(entryStream, entryStream.Length, omitFromScan: omitFromScan); - sevenZipEntryRom.Name = entry.Key; - sevenZipEntryRom.MachineName = gamename; - sevenZipEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss"); - found.Add(sevenZipEntryRom); + Stream entryStream = entry.OpenEntryStream(); + Rom tarEntryRom = FileTools.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan); + tarEntryRom.Name = entry.Key; + tarEntryRom.MachineName = gamename; + tarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss"); + found.Add(tarEntryRom); + entryStream.Dispose(); } } @@ -818,7 +802,6 @@ namespace SabreTools.Library.Tools // Otherwise, use the stream directly else { - // Get and add the extended Rom information Rom zipEntryRom = FileTools.GetStreamInfo(readStream, (long)zf.Entries[i].UncompressedSize, omitFromScan: omitFromScan); zipEntryRom.Name = zf.Entries[i].FileName; zipEntryRom.MachineName = gamename; diff --git a/SabreTools.Library/Tools/FileTools.cs b/SabreTools.Library/Tools/FileTools.cs index a9cd5490..707f645f 100644 --- a/SabreTools.Library/Tools/FileTools.cs +++ b/SabreTools.Library/Tools/FileTools.cs @@ -769,6 +769,10 @@ namespace SabreTools.Library.Tools input.Seek(offset, SeekOrigin.Begin); } } + catch (NotSupportedException) + { + Globals.Logger.Verbose("Stream does not support seeking. Stream position not changed"); + } catch (NotImplementedException) { 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); } + catch (NotSupportedException) + { + Globals.Logger.Verbose("Stream does not support seeking. Stream position not changed"); + } catch (NotImplementedException) { Globals.Logger.Verbose("Stream does not support seeking. Stream position not changed");