wabbajack/Compression.BSA/BSADispatch.cs

30 lines
1.1 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
2020-03-23 12:57:18 +00:00
using Wabbajack.Common;
using Wabbajack.Common.FileSignatures;
namespace Compression.BSA
{
public static class BSADispatch
{
public static async ValueTask<IBSAReader> OpenRead(AbsolutePath filename)
{
return await BSASignatures.MatchesAsync(filename) switch
{
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")
};
}
2020-09-04 21:00:29 +00:00
private static SignatureChecker BSASignatures = new SignatureChecker(Definitions.FileType.BSA, Definitions.FileType.BA2, Definitions.FileType.TES3);
public static async ValueTask<bool> MightBeBSA(AbsolutePath filename)
{
return await BSASignatures.MatchesAsync(filename) != null;
}
}
}