2021-09-27 12:42:46 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Wabbajack.Common;
|
|
|
|
using Wabbajack.Compression.BSA.Interfaces;
|
|
|
|
using Wabbajack.DTOs.BSA.FileStates;
|
|
|
|
using Wabbajack.DTOs.Streams;
|
|
|
|
using Wabbajack.Paths;
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
namespace Wabbajack.Compression.BSA.TES3Archive;
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public class TES3FileEntry : IFile
|
|
|
|
{
|
|
|
|
public uint Offset { get; set; }
|
|
|
|
public uint NameOffset { get; set; }
|
|
|
|
public uint Hash1 { get; set; }
|
|
|
|
public uint Hash2 { get; set; }
|
|
|
|
public Reader Archive { get; set; }
|
|
|
|
public int Index { get; set; }
|
|
|
|
public RelativePath Path { get; set; }
|
|
|
|
public uint Size { get; set; }
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public AFile State =>
|
|
|
|
new TES3File
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
Index = Index,
|
|
|
|
Path = Path,
|
|
|
|
Size = Size,
|
|
|
|
Offset = Offset,
|
|
|
|
NameOffset = NameOffset,
|
|
|
|
Hash1 = Hash1,
|
|
|
|
Hash2 = Hash2
|
|
|
|
};
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public async ValueTask CopyDataTo(Stream output, CancellationToken token)
|
|
|
|
{
|
|
|
|
await using var fs = await Archive._streamFactory.GetStream();
|
|
|
|
fs.Position = Archive._dataOffset + Offset;
|
|
|
|
await fs.CopyToLimitAsync(output, (int) Size, token);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async ValueTask<IStreamFactory> GetStreamFactory(CancellationToken token)
|
|
|
|
{
|
|
|
|
var ms = new MemoryStream();
|
|
|
|
await CopyDataTo(ms, token);
|
|
|
|
ms.Position = 0;
|
|
|
|
return new MemoryStreamFactory(ms, Path, Archive._streamFactory.LastModifiedUtc);
|
2021-09-27 12:42:46 +00:00
|
|
|
}
|
|
|
|
}
|