2020-04-17 03:52:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Compression.BSA;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.VirtualFileSystem
|
|
|
|
|
{
|
|
|
|
|
public class ExtractedBSAFile : IExtractedFile
|
|
|
|
|
{
|
|
|
|
|
private readonly IFile _file;
|
|
|
|
|
public ExtractedBSAFile(IFile file)
|
|
|
|
|
{
|
|
|
|
|
_file = file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RelativePath Path => _file.Path;
|
|
|
|
|
|
|
|
|
|
public async Task<Hash> HashAsync()
|
|
|
|
|
{
|
2020-05-25 16:30:47 +00:00
|
|
|
|
await using var stream = await OpenRead();
|
|
|
|
|
return await stream.xxHashAsync();
|
2020-04-17 03:52:19 +00:00
|
|
|
|
}
|
|
|
|
|
public DateTime LastModifiedUtc => DateTime.UtcNow;
|
|
|
|
|
public long Size => _file.Size;
|
2020-05-25 16:30:47 +00:00
|
|
|
|
public async ValueTask<Stream> OpenRead()
|
2020-04-17 03:52:19 +00:00
|
|
|
|
{
|
|
|
|
|
var ms = new MemoryStream();
|
2020-05-25 16:30:47 +00:00
|
|
|
|
await _file.CopyDataTo(ms);
|
2020-04-17 03:52:19 +00:00
|
|
|
|
ms.Position = 0;
|
|
|
|
|
return ms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> CanExtract()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<ExtractedFiles> ExtractAll(WorkQueue queue, IEnumerable<RelativePath> OnlyFiles)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("BSAs can't contain archives");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task MoveTo(AbsolutePath path)
|
|
|
|
|
{
|
2020-05-25 16:30:47 +00:00
|
|
|
|
await using var fs = await path.Create();
|
|
|
|
|
await _file.CopyDataTo(fs);
|
2020-04-17 03:52:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|