public Romfs(IStorage storage) { BaseStorage = storage; byte[] dirMetaTable; byte[] fileMetaTable; using (var reader = new BinaryReader(BaseStorage.AsStream(), Encoding.Default, true)) { Header = new RomfsHeader(reader); reader.BaseStream.Position = Header.DirMetaTableOffset; dirMetaTable = reader.ReadBytes((int)Header.DirMetaTableSize); reader.BaseStream.Position = Header.FileMetaTableOffset; fileMetaTable = reader.ReadBytes((int)Header.FileMetaTableSize); } using (var reader = new BinaryReader(new MemoryStream(dirMetaTable))) { int position = 0; while (position + 20 < Header.DirMetaTableSize) { var dir = new RomfsDir(reader) { Offset = position }; Directories.Add(dir); if (dir.ParentDirOffset == position) { RootDir = dir; } position = (int)reader.BaseStream.Position; } } using (var reader = new BinaryReader(new MemoryStream(fileMetaTable))) { int position = 0; while (position + 20 < Header.FileMetaTableSize) { var file = new RomfsFile(reader) { Offset = position }; Files.Add(file); position = (int)reader.BaseStream.Position; } } SetReferences(); RomfsEntry.ResolveFilenames(Files); RomfsEntry.ResolveFilenames(Directories); FileDict = Files.ToDictionary(x => x.FullPath, x => x); }
public IStorage OpenFile(RomfsFile file) { return(BaseStorage.Slice(Header.DataOffset + file.DataOffset, file.DataLength)); }
public Stream OpenFile(RomfsFile file) { return(StreamSource.CreateStream(Header.DataOffset + file.DataOffset, file.DataLength)); }