diff --git a/libhac/Pfs.cs b/libhac/Pfs.cs index e2004106..f28168d4 100644 --- a/libhac/Pfs.cs +++ b/libhac/Pfs.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using libhac.Streams; namespace libhac { @@ -13,7 +14,7 @@ namespace libhac public PfsFileEntry[] Files { get; } private Dictionary FileDict { get; } - private Stream Stream { get; set; } + private SharedStreamSource StreamSource { get; } public Pfs(Stream stream) { @@ -25,7 +26,7 @@ namespace libhac HeaderSize = Header.HeaderSize; Files = Header.Files; FileDict = Header.Files.ToDictionary(x => x.Name, x => x); - Stream = stream; + StreamSource = new SharedStreamSource(stream); } public Stream OpenFile(string filename) @@ -52,7 +53,7 @@ namespace libhac public Stream OpenFile(PfsFileEntry file) { - return new SubStream(Stream, HeaderSize + file.Offset, file.Size); + return StreamSource.CreateStream(HeaderSize + file.Offset, file.Size); } public bool FileExists(string filename) diff --git a/libhac/Romfs.cs b/libhac/Romfs.cs index 0691637a..682a2f6c 100644 --- a/libhac/Romfs.cs +++ b/libhac/Romfs.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Text; +using libhac.Streams; namespace libhac { @@ -15,13 +16,15 @@ namespace libhac public RomfsDir RootDir { get; } private Dictionary FileDict { get; } - private Stream Stream { get; set; } + private SharedStreamSource StreamSource { get; } public Romfs(Stream stream) { + StreamSource = new SharedStreamSource(stream); + byte[] dirMetaTable; byte[] fileMetaTable; - using (var reader = new BinaryReader(stream, Encoding.Default, true)) + using (var reader = new BinaryReader(StreamSource.CreateStream(), Encoding.Default, true)) { Header = new RomfsHeader(reader); stream.Position = Header.DirMetaTableOffset; @@ -53,11 +56,9 @@ namespace libhac } } - SetReferences(); ResolveFilenames(); FileDict = Files.ToDictionary(x => x.FullPath, x => x); - Stream = stream; } public Stream OpenFile(string filename) @@ -72,7 +73,7 @@ namespace libhac public Stream OpenFile(RomfsFile file) { - return new SubStream(Stream, Header.DataOffset + file.DataOffset, file.DataLength); + return StreamSource.CreateStream(Header.DataOffset + file.DataOffset, file.DataLength); } public byte[] GetFile(string filename)