mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
a545cb375a
* Add support for new Starfield BA2 versions * Add Starfield BA2 LZ4 texture compression support (WIP, not finished) * Work on replacing DDS.cs with DirectXTexUtility * Fix reading Starfield BA2s with new DirectXTexUtil * Fix builder not exporting new Starfield header options * Fix writing LZ4 chunks in frame format instead of block format * Rename FO4Archive to BA2Archive, merge SFArchive and FO4Archive * Clean up testing code & CLI launch settings * Update changelog
64 lines
2.4 KiB
C#
64 lines
2.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using Wabbajack.Common;
|
|
using Wabbajack.Common.FileSignatures;
|
|
using Wabbajack.Compression.BSA.Interfaces;
|
|
using Wabbajack.Compression.BSA.TES3Archive;
|
|
using Wabbajack.DTOs.BSA.ArchiveStates;
|
|
using Wabbajack.DTOs.Streams;
|
|
using Wabbajack.Paths;
|
|
using Wabbajack.Paths.IO;
|
|
|
|
namespace Wabbajack.Compression.BSA;
|
|
|
|
public static class BSADispatch
|
|
{
|
|
private static readonly SignatureChecker BSASignatures = new(FileType.BSA, FileType.BA2, FileType.TES3);
|
|
|
|
public static async ValueTask<IReader> Open(AbsolutePath filename)
|
|
{
|
|
return await BSASignatures.MatchesAsync(filename) switch
|
|
{
|
|
FileType.TES3 => await Reader.Load(new NativeFileStreamFactory(filename)),
|
|
FileType.BSA => await TES5Archive.Reader.Load(new NativeFileStreamFactory(filename)),
|
|
FileType.BA2 => await BA2Archive.Reader.Load(new NativeFileStreamFactory(filename)),
|
|
_ => throw new InvalidDataException("Filename is not a .bsa or .ba2")
|
|
};
|
|
}
|
|
|
|
public static async ValueTask<IReader> Open(IStreamFactory factory)
|
|
{
|
|
await using var stream = await factory.GetStream();
|
|
return await BSASignatures.MatchesAsync(stream) switch
|
|
{
|
|
FileType.TES3 => await Reader.Load(factory),
|
|
FileType.BSA => await TES5Archive.Reader.Load(factory),
|
|
FileType.BA2 => await BA2Archive.Reader.Load(factory),
|
|
_ => throw new InvalidDataException("Filename is not a .bsa or .ba2")
|
|
};
|
|
}
|
|
|
|
public static async ValueTask<IReader> Open(IStreamFactory factory, FileType sig)
|
|
{
|
|
await using var stream = await factory.GetStream();
|
|
return sig switch
|
|
{
|
|
FileType.TES3 => await Reader.Load(factory),
|
|
FileType.BSA => await TES5Archive.Reader.Load(factory),
|
|
FileType.BA2 => await BA2Archive.Reader.Load(factory),
|
|
_ => throw new InvalidDataException("Filename is not a .bsa or .ba2")
|
|
};
|
|
}
|
|
|
|
public static IBuilder CreateBuilder(IArchive oldState, TemporaryFileManager manager)
|
|
{
|
|
return oldState switch
|
|
{
|
|
TES3State tes3 => new Builder(tes3),
|
|
BSAState bsa => TES5Archive.Builder.Create(bsa, manager),
|
|
BA2State ba2 => BA2Archive.Builder.Create(ba2, manager),
|
|
_ => throw new NotImplementedException()
|
|
};
|
|
}
|
|
} |