mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Use SharedStreams for PartitionFS and RomFS
This commit is contained in:
parent
a68426751f
commit
02464eaa60
2 changed files with 10 additions and 8 deletions
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using libhac.Streams;
|
||||||
|
|
||||||
namespace libhac
|
namespace libhac
|
||||||
{
|
{
|
||||||
|
@ -13,7 +14,7 @@ namespace libhac
|
||||||
public PfsFileEntry[] Files { get; }
|
public PfsFileEntry[] Files { get; }
|
||||||
|
|
||||||
private Dictionary<string, PfsFileEntry> FileDict { get; }
|
private Dictionary<string, PfsFileEntry> FileDict { get; }
|
||||||
private Stream Stream { get; set; }
|
private SharedStreamSource StreamSource { get; }
|
||||||
|
|
||||||
public Pfs(Stream stream)
|
public Pfs(Stream stream)
|
||||||
{
|
{
|
||||||
|
@ -25,7 +26,7 @@ namespace libhac
|
||||||
HeaderSize = Header.HeaderSize;
|
HeaderSize = Header.HeaderSize;
|
||||||
Files = Header.Files;
|
Files = Header.Files;
|
||||||
FileDict = Header.Files.ToDictionary(x => x.Name, x => x);
|
FileDict = Header.Files.ToDictionary(x => x.Name, x => x);
|
||||||
Stream = stream;
|
StreamSource = new SharedStreamSource(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream OpenFile(string filename)
|
public Stream OpenFile(string filename)
|
||||||
|
@ -52,7 +53,7 @@ namespace libhac
|
||||||
|
|
||||||
public Stream OpenFile(PfsFileEntry file)
|
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)
|
public bool FileExists(string filename)
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using libhac.Streams;
|
||||||
|
|
||||||
namespace libhac
|
namespace libhac
|
||||||
{
|
{
|
||||||
|
@ -15,13 +16,15 @@ namespace libhac
|
||||||
public RomfsDir RootDir { get; }
|
public RomfsDir RootDir { get; }
|
||||||
|
|
||||||
private Dictionary<string, RomfsFile> FileDict { get; }
|
private Dictionary<string, RomfsFile> FileDict { get; }
|
||||||
private Stream Stream { get; set; }
|
private SharedStreamSource StreamSource { get; }
|
||||||
|
|
||||||
public Romfs(Stream stream)
|
public Romfs(Stream stream)
|
||||||
{
|
{
|
||||||
|
StreamSource = new SharedStreamSource(stream);
|
||||||
|
|
||||||
byte[] dirMetaTable;
|
byte[] dirMetaTable;
|
||||||
byte[] fileMetaTable;
|
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);
|
Header = new RomfsHeader(reader);
|
||||||
stream.Position = Header.DirMetaTableOffset;
|
stream.Position = Header.DirMetaTableOffset;
|
||||||
|
@ -53,11 +56,9 @@ namespace libhac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SetReferences();
|
SetReferences();
|
||||||
ResolveFilenames();
|
ResolveFilenames();
|
||||||
FileDict = Files.ToDictionary(x => x.FullPath, x => x);
|
FileDict = Files.ToDictionary(x => x.FullPath, x => x);
|
||||||
Stream = stream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream OpenFile(string filename)
|
public Stream OpenFile(string filename)
|
||||||
|
@ -72,7 +73,7 @@ namespace libhac
|
||||||
|
|
||||||
public Stream OpenFile(RomfsFile file)
|
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)
|
public byte[] GetFile(string filename)
|
||||||
|
|
Loading…
Reference in a new issue