public static async ValueTask <IBSAReader> OpenRead(AbsolutePath filename) { return(await BSASignatures.MatchesAsync(filename) switch { Definitions.FileType.TES3 => await TES3Reader.Load(new NativeFileStreamFactory(filename)), Definitions.FileType.BSA => await BSAReader.LoadAsync(new NativeFileStreamFactory(filename)), Definitions.FileType.BA2 => await BA2Reader.Load(new NativeFileStreamFactory(filename)), _ => throw new InvalidDataException("Filename is not a .bsa or .ba2") });
public static async ValueTask <TES3Reader> Load(IStreamFactory factory) { await using var fs = await factory.GetStream(); using var br = new BinaryReader(fs); var rdr = new TES3Reader { _streamFactory = factory, _versionNumber = br.ReadUInt32(), _hashTableOffset = br.ReadUInt32(), _fileCount = br.ReadUInt32() }; rdr._files = new TES3FileEntry[rdr._fileCount]; for (int i = 0; i < rdr._fileCount; i++) { var file = new TES3FileEntry { Index = i, Archive = rdr, Size = br.ReadUInt32(), Offset = br.ReadUInt32() }; rdr._files[i] = file; } for (int i = 0; i < rdr._fileCount; i++) { rdr._files[i].NameOffset = br.ReadUInt32(); } var origPos = br.BaseStream.Position; for (int i = 0; i < rdr._fileCount; i++) { br.BaseStream.Position = origPos + rdr._files[i].NameOffset; rdr._files[i].Path = new RelativePath(br.ReadStringTerm(VersionType.TES3)); } br.BaseStream.Position = rdr._hashTableOffset + 12; for (int i = 0; i < rdr._fileCount; i++) { rdr._files[i].Hash1 = br.ReadUInt32(); rdr._files[i].Hash2 = br.ReadUInt32(); } rdr._dataOffset = br.BaseStream.Position; return(rdr); }
public static async ValueTask <IBSAReader> OpenRead(AbsolutePath filename) { var fourcc = ""; using (var file = await filename.OpenRead()) { fourcc = Encoding.ASCII.GetString(new BinaryReader(file).ReadBytes(4)); } if (fourcc == TES3Reader.TES3_MAGIC) { return(await TES3Reader.Load(filename)); } if (fourcc == "BSA\0") { return(await BSAReader.Load(filename)); } if (fourcc == "BTDX") { return(await BA2Reader.Load(filename)); } throw new InvalidDataException("Filename is not a .bsa or .ba2, magic " + fourcc); }