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();
|
||||
|
@ -5,13 +5,6 @@ using Wabbajack.Common;
|
||||
|
||||
namespace Wabbajack.VirtualFileSystem
|
||||
{
|
||||
public interface IStreamFactory
|
||||
{
|
||||
Task<Stream> GetStream();
|
||||
|
||||
DateTime LastModifiedUtc { get; }
|
||||
|
||||
}
|
||||
|
||||
public class UnmanagedStreamFactory : IStreamFactory
|
||||
{
|
||||
@ -23,7 +16,7 @@ namespace Wabbajack.VirtualFileSystem
|
||||
_data = data;
|
||||
_size = size;
|
||||
}
|
||||
public async Task<Stream> GetStream()
|
||||
public async ValueTask<Stream> GetStream()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
@ -32,21 +25,8 @@ namespace Wabbajack.VirtualFileSystem
|
||||
}
|
||||
|
||||
public DateTime LastModifiedUtc => DateTime.UtcNow;
|
||||
public IPath Name => (RelativePath)"Unmanaged Memory Stream";
|
||||
}
|
||||
|
||||
public class NativeFileStreamFactory : IStreamFactory
|
||||
{
|
||||
private AbsolutePath _file;
|
||||
|
||||
public NativeFileStreamFactory(AbsolutePath file)
|
||||
{
|
||||
_file = file;
|
||||
}
|
||||
public async Task<Stream> GetStream()
|
||||
{
|
||||
return await _file.OpenRead();
|
||||
}
|
||||
|
||||
public DateTime LastModifiedUtc => _file.LastModifiedUtc;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user