Exemplo n.º 1
0
 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")
     });
Exemplo n.º 2
0
        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);
        }