wabbajack/Compression.BSA/BSADispatch.cs

27 lines
782 B
C#
Raw Normal View History

2019-11-16 00:01:37 +00:00
using System.IO;
using System.Text;
2020-03-23 12:57:18 +00:00
using Wabbajack.Common;
namespace Compression.BSA
{
public static class BSADispatch
{
2020-03-23 12:57:18 +00:00
public static IBSAReader OpenRead(AbsolutePath filename)
{
2019-11-16 00:01:37 +00:00
var fourcc = "";
2020-03-23 12:57:18 +00:00
using (var file = filename.OpenRead())
{
2019-11-16 00:01:37 +00:00
fourcc = Encoding.ASCII.GetString(new BinaryReader(file).ReadBytes(4));
}
if (fourcc == TES3Reader.TES3_MAGIC)
return new TES3Reader(filename);
2019-11-16 00:01:37 +00:00
if (fourcc == "BSA\0")
return new BSAReader(filename);
if (fourcc == "BTDX")
return new BA2Reader(filename);
throw new InvalidDataException("Filename is not a .bsa or .ba2, magic " + fourcc);
}
}
}