2020-05-11 12:52:23 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2019-10-06 21:58:36 +00:00
|
|
|
|
using System.Text;
|
2020-05-25 16:24:16 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2020-03-23 12:57:18 +00:00
|
|
|
|
using Wabbajack.Common;
|
2020-07-21 22:25:34 +00:00
|
|
|
|
using Wabbajack.Common.FileSignatures;
|
2019-10-06 21:58:36 +00:00
|
|
|
|
|
2020-06-27 17:04:59 +00:00
|
|
|
|
namespace Compression.BSA
|
2019-10-06 21:58:36 +00:00
|
|
|
|
{
|
|
|
|
|
public static class BSADispatch
|
|
|
|
|
{
|
2020-05-25 16:24:16 +00:00
|
|
|
|
public static async ValueTask<IBSAReader> OpenRead(AbsolutePath filename)
|
2019-10-06 21:58:36 +00:00
|
|
|
|
{
|
2020-07-21 22:25:34 +00:00
|
|
|
|
return await BSASignatures.MatchesAsync(filename) switch
|
2019-10-06 21:58:36 +00:00
|
|
|
|
{
|
2020-07-21 22:25:34 +00:00
|
|
|
|
Definitions.FileType.TES3 => await TES3Reader.Load(filename),
|
|
|
|
|
Definitions.FileType.BSA => await BSAReader.LoadAsync(filename),
|
|
|
|
|
Definitions.FileType.BA2 => await BA2Reader.Load(filename),
|
|
|
|
|
_ => throw new InvalidDataException("Filename is not a .bsa or .ba2")
|
|
|
|
|
};
|
2019-10-06 21:58:36 +00:00
|
|
|
|
}
|
2020-05-11 12:52:23 +00:00
|
|
|
|
|
2020-07-21 22:25:34 +00:00
|
|
|
|
private static SignatureChecker BSASignatures = new SignatureChecker(Definitions.FileType.BSA, Definitions.FileType.BA2, Definitions.FileType.TES3);
|
2020-05-25 16:24:16 +00:00
|
|
|
|
public static async ValueTask<bool> MightBeBSA(AbsolutePath filename)
|
2020-05-11 12:52:23 +00:00
|
|
|
|
{
|
2020-07-21 22:25:34 +00:00
|
|
|
|
return await BSASignatures.MatchesAsync(filename) != null;
|
2020-05-11 12:52:23 +00:00
|
|
|
|
}
|
2019-10-06 21:58:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|