2020-09-05 14:01:32 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
2020-05-11 12:52:23 +00:00
|
|
|
|
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-09-05 14:01:32 +00:00
|
|
|
|
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)),
|
2020-07-21 22:25:34 +00:00
|
|
|
|
_ => throw new InvalidDataException("Filename is not a .bsa or .ba2")
|
|
|
|
|
};
|
2019-10-06 21:58:36 +00:00
|
|
|
|
}
|
2020-09-04 21:00:29 +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
|
|
|
|
}
|
2020-09-05 14:01:32 +00:00
|
|
|
|
|
|
|
|
|
public static async ValueTask<IBSAReader> OpenRead(IStreamFactory sFn, Definitions.FileType sig)
|
|
|
|
|
{
|
|
|
|
|
switch(sig)
|
|
|
|
|
{
|
|
|
|
|
case Definitions.FileType.TES3:
|
|
|
|
|
return await TES3Reader.Load(sFn);
|
|
|
|
|
case Definitions.FileType.BSA:
|
|
|
|
|
return await BSAReader.LoadAsync(sFn);
|
|
|
|
|
case Definitions.FileType.BA2:
|
|
|
|
|
return await BA2Reader.Load(sFn);
|
|
|
|
|
default:
|
|
|
|
|
throw new Exception($"Bad archive format for {sFn.Name}");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-06 21:58:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|