mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
EndToEnd Tests pass
This commit is contained in:
@ -3,6 +3,9 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Compression.BSA;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
|
||||
using SharpCompress.Archives.SevenZip;
|
||||
using SharpCompress.Readers;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Common.FileSignatures;
|
||||
using Wabbajack.VirtualFileSystem.SevenZipExtractor;
|
||||
@ -16,7 +19,8 @@ namespace Wabbajack.VirtualFileSystem
|
||||
Definitions.FileType.BA2,
|
||||
Definitions.FileType.ZIP,
|
||||
//Definitions.FileType.EXE,
|
||||
Definitions.FileType.RAR,
|
||||
Definitions.FileType.RAR_OLD,
|
||||
Definitions.FileType.RAR_NEW,
|
||||
Definitions.FileType._7Z);
|
||||
|
||||
|
||||
@ -29,6 +33,9 @@ namespace Wabbajack.VirtualFileSystem
|
||||
|
||||
switch (sig)
|
||||
{
|
||||
case Definitions.FileType.RAR_OLD:
|
||||
case Definitions.FileType.RAR_NEW:
|
||||
case Definitions.FileType._7Z:
|
||||
case Definitions.FileType.ZIP:
|
||||
return await GatheringExtractWith7Zip<T>(archive, (Definitions.FileType)sig, shouldExtract, mapfn);
|
||||
|
||||
@ -62,6 +69,43 @@ namespace Wabbajack.VirtualFileSystem
|
||||
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();
|
||||
/*
|
||||
IReader reader;
|
||||
if (sig == Definitions.FileType._7Z)
|
||||
reader = SevenZipArchive.Open(stream).ExtractAllEntries();
|
||||
else
|
||||
{
|
||||
reader = ReaderFactory.Open(stream);
|
||||
}
|
||||
|
||||
var results = new Dictionary<RelativePath, T>();
|
||||
while (reader.MoveToNextEntry())
|
||||
{
|
||||
var path = (RelativePath)reader.Entry.Key;
|
||||
if (!reader.Entry.IsDirectory && shouldExtract(path))
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
reader.WriteEntryTo(ms);
|
||||
ms.Position = 0;
|
||||
var result = await mapfn(path, new MemoryStreamFactory(ms));
|
||||
results.Add(path, result);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
*/
|
||||
}
|
||||
|
||||
public static async Task ExtractAll(AbsolutePath src, AbsolutePath dest)
|
||||
{
|
||||
await GatheringExtract(new NativeFileStreamFactory(src), _ => true, async (path, factory) =>
|
||||
{
|
||||
var abs = path.RelativeTo(dest);
|
||||
abs.Parent.CreateDirectory();
|
||||
await using var stream = await factory.GetStream();
|
||||
await abs.WriteAllAsync(stream);
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user