mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Patching and extraction works, fewer failing tests
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Compression.BSA;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Common.FileSignatures;
|
||||
using Wabbajack.VirtualFileSystem.SevenZipExtractor;
|
||||
@ -14,7 +15,7 @@ namespace Wabbajack.VirtualFileSystem
|
||||
Definitions.FileType.BSA,
|
||||
Definitions.FileType.BA2,
|
||||
Definitions.FileType.ZIP,
|
||||
Definitions.FileType.EXE,
|
||||
//Definitions.FileType.EXE,
|
||||
Definitions.FileType.RAR,
|
||||
Definitions.FileType._7Z);
|
||||
|
||||
@ -31,11 +32,33 @@ namespace Wabbajack.VirtualFileSystem
|
||||
case Definitions.FileType.ZIP:
|
||||
return await GatheringExtractWith7Zip<T>(archive, (Definitions.FileType)sig, shouldExtract, mapfn);
|
||||
|
||||
case Definitions.FileType.TES3:
|
||||
case Definitions.FileType.BSA:
|
||||
case Definitions.FileType.BA2:
|
||||
return await GatheringExtractWithBSA(sFn, (Definitions.FileType)sig, shouldExtract, mapfn);
|
||||
|
||||
|
||||
default:
|
||||
throw new Exception("Invalid file format");
|
||||
throw new Exception($"Invalid file format {sFn.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<Dictionary<RelativePath,T>> GatheringExtractWithBSA<T>(IStreamFactory sFn, Definitions.FileType sig, Predicate<RelativePath> shouldExtract, Func<RelativePath,IStreamFactory,ValueTask<T>> mapfn)
|
||||
{
|
||||
var archive = await BSADispatch.OpenRead(sFn, sig);
|
||||
var results = new Dictionary<RelativePath, T>();
|
||||
foreach (var entry in archive.Files)
|
||||
{
|
||||
if (!shouldExtract(entry.Path))
|
||||
continue;
|
||||
|
||||
var result = await mapfn(entry.Path, await entry.GetStreamFactory());
|
||||
results.Add(entry.Path, result);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private static async Task<Dictionary<RelativePath,T>> GatheringExtractWith7Zip<T>(Stream stream, Definitions.FileType sig, Predicate<RelativePath> shouldExtract, Func<RelativePath,IStreamFactory,ValueTask<T>> mapfn)
|
||||
{
|
||||
return await new GatheringExtractor<T>(stream, sig, shouldExtract, mapfn).Extract();
|
||||
|
Reference in New Issue
Block a user