2019-09-14 04:35:42 +00:00
|
|
|
|
using System;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2020-04-17 03:52:19 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
|
|
|
|
|
using K4os.Compression.LZ4;
|
|
|
|
|
using K4os.Compression.LZ4.Streams;
|
2020-03-05 04:32:38 +00:00
|
|
|
|
using Wabbajack.Common;
|
2019-08-28 03:22:57 +00:00
|
|
|
|
using File = Alphaleonis.Win32.Filesystem.File;
|
|
|
|
|
using Path = Alphaleonis.Win32.Filesystem.Path;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
|
|
|
|
|
namespace Compression.BSA
|
|
|
|
|
{
|
2019-10-16 21:36:14 +00:00
|
|
|
|
public class BSABuilder : IBSABuilder
|
2019-07-28 23:04:23 +00:00
|
|
|
|
{
|
|
|
|
|
internal uint _archiveFlags;
|
|
|
|
|
internal uint _fileFlags;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
internal byte[] _fileId;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
|
|
|
|
|
private List<FileEntry> _files = new List<FileEntry>();
|
|
|
|
|
internal List<FolderRecordBuilder> _folders = new List<FolderRecordBuilder>();
|
2019-09-14 04:35:42 +00:00
|
|
|
|
internal uint _offset;
|
|
|
|
|
internal uint _totalFileNameLength;
|
|
|
|
|
internal uint _version;
|
2020-03-05 04:32:38 +00:00
|
|
|
|
internal DiskSlabAllocator _slab;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
|
2020-03-09 20:38:35 +00:00
|
|
|
|
public BSABuilder(long size)
|
2019-07-28 23:04:23 +00:00
|
|
|
|
{
|
|
|
|
|
_fileId = Encoding.ASCII.GetBytes("BSA\0");
|
|
|
|
|
_offset = 0x24;
|
2020-03-09 20:38:35 +00:00
|
|
|
|
_slab = new DiskSlabAllocator(size);
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-09 20:38:35 +00:00
|
|
|
|
public BSABuilder(BSAStateObject bsaStateObject, long size) : this(size)
|
2019-10-08 21:20:43 +00:00
|
|
|
|
{
|
|
|
|
|
_version = bsaStateObject.Version;
|
|
|
|
|
_fileFlags = bsaStateObject.FileFlags;
|
|
|
|
|
_archiveFlags = bsaStateObject.ArchiveFlags;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-14 04:35:42 +00:00
|
|
|
|
public IEnumerable<FileEntry> Files => _files;
|
2019-07-29 21:24:05 +00:00
|
|
|
|
|
2019-07-28 23:04:23 +00:00
|
|
|
|
public ArchiveFlags ArchiveFlags
|
|
|
|
|
{
|
2019-09-14 04:35:42 +00:00
|
|
|
|
get => (ArchiveFlags) _archiveFlags;
|
|
|
|
|
set => _archiveFlags = (uint) value;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FileFlags FileFlags
|
|
|
|
|
{
|
2019-09-14 04:35:42 +00:00
|
|
|
|
get => (FileFlags) _archiveFlags;
|
|
|
|
|
set => _archiveFlags = (uint) value;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public VersionType HeaderType
|
|
|
|
|
{
|
2019-09-14 04:35:42 +00:00
|
|
|
|
get => (VersionType) _version;
|
|
|
|
|
set => _version = (uint) value;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 12:57:18 +00:00
|
|
|
|
public IEnumerable<RelativePath> FolderNames
|
2019-07-28 23:04:23 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-03-23 12:57:18 +00:00
|
|
|
|
return _files.Select(f => f.Path.Parent).Distinct();
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-14 04:35:42 +00:00
|
|
|
|
public bool HasFolderNames => (_archiveFlags & 0x1) > 0;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
|
2019-09-14 04:35:42 +00:00
|
|
|
|
public bool HasFileNames => (_archiveFlags & 0x2) > 0;
|
|
|
|
|
|
|
|
|
|
public bool CompressedByDefault => (_archiveFlags & 0x4) > 0;
|
|
|
|
|
|
|
|
|
|
public bool HasNameBlobs => (_archiveFlags & 0x100) > 0;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
|
2020-04-17 03:52:19 +00:00
|
|
|
|
public async ValueTask DisposeAsync()
|
2019-07-28 23:04:23 +00:00
|
|
|
|
{
|
2020-03-05 04:32:38 +00:00
|
|
|
|
_slab.Dispose();
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
2020-04-20 21:36:33 +00:00
|
|
|
|
public async Task AddFile(FileStateObject state, Stream src)
|
2019-10-08 21:20:43 +00:00
|
|
|
|
{
|
|
|
|
|
var ostate = (BSAFileStateObject) state;
|
|
|
|
|
|
2020-04-20 21:36:33 +00:00
|
|
|
|
var r = await FileEntry.Create(this, ostate.Path, src, ostate.FlipCompression);
|
2019-10-08 21:20:43 +00:00
|
|
|
|
|
|
|
|
|
lock (this)
|
|
|
|
|
{
|
|
|
|
|
_files.Add(r);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 21:36:33 +00:00
|
|
|
|
public async Task Build(AbsolutePath outputName)
|
2019-07-28 23:04:23 +00:00
|
|
|
|
{
|
2019-07-29 04:52:04 +00:00
|
|
|
|
RegenFolderRecords();
|
2020-04-20 21:36:33 +00:00
|
|
|
|
await using var fs = outputName.Create();
|
|
|
|
|
await using var wtr = new BinaryWriter(fs);
|
|
|
|
|
|
|
|
|
|
wtr.Write(_fileId);
|
|
|
|
|
wtr.Write(_version);
|
|
|
|
|
wtr.Write(_offset);
|
|
|
|
|
wtr.Write(_archiveFlags);
|
|
|
|
|
var folders = FolderNames.ToList();
|
|
|
|
|
wtr.Write((uint) folders.Count);
|
|
|
|
|
wtr.Write((uint) _files.Count);
|
|
|
|
|
wtr.Write((uint) _folders.Select(f => f._nameBytes.Count() - 1).Sum()); // totalFolderNameLength
|
|
|
|
|
var s = _files.Select(f => f._pathBytes.Count()).Sum();
|
|
|
|
|
_totalFileNameLength = (uint) _files.Select(f => f._nameBytes.Count()).Sum();
|
|
|
|
|
wtr.Write(_totalFileNameLength); // totalFileNameLength
|
|
|
|
|
wtr.Write(_fileFlags);
|
|
|
|
|
|
|
|
|
|
foreach (var folder in _folders) folder.WriteFolderRecord(wtr);
|
|
|
|
|
|
|
|
|
|
foreach (var folder in _folders)
|
2019-07-28 23:04:23 +00:00
|
|
|
|
{
|
2020-04-20 21:36:33 +00:00
|
|
|
|
if (HasFolderNames)
|
|
|
|
|
wtr.Write(folder._nameBytes);
|
|
|
|
|
foreach (var file in folder._files) file.WriteFileRecord(wtr);
|
|
|
|
|
}
|
2019-07-29 04:52:04 +00:00
|
|
|
|
|
2020-04-20 21:36:33 +00:00
|
|
|
|
foreach (var file in _files) wtr.Write(file._nameBytes);
|
2019-07-29 04:52:04 +00:00
|
|
|
|
|
2020-04-20 21:36:33 +00:00
|
|
|
|
await _files.DoProgress("Writing BSA Body", async file =>
|
|
|
|
|
await file.WriteData(wtr));
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RegenFolderRecords()
|
|
|
|
|
{
|
2020-03-23 12:57:18 +00:00
|
|
|
|
_folders = _files.GroupBy(f => f.Path.Parent)
|
2019-09-14 04:35:42 +00:00
|
|
|
|
.Select(f => new FolderRecordBuilder(this, f.Key, f.ToList()))
|
|
|
|
|
.OrderBy(f => f._hash)
|
|
|
|
|
.ToList();
|
2019-07-29 04:52:04 +00:00
|
|
|
|
|
|
|
|
|
foreach (var folder in _folders)
|
2019-09-14 04:35:42 +00:00
|
|
|
|
foreach (var file in folder._files)
|
|
|
|
|
file._folder = folder;
|
2019-07-29 04:52:04 +00:00
|
|
|
|
|
|
|
|
|
_files = (from folder in _folders
|
2019-09-14 04:35:42 +00:00
|
|
|
|
from file in folder._files
|
|
|
|
|
orderby folder._hash, file._hash
|
|
|
|
|
select file).ToList();
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class FolderRecordBuilder
|
|
|
|
|
{
|
|
|
|
|
internal BSABuilder _bsa;
|
|
|
|
|
internal uint _fileCount;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
internal IEnumerable<FileEntry> _files;
|
|
|
|
|
internal ulong _hash;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
internal byte[] _nameBytes;
|
|
|
|
|
internal ulong _offset;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
internal uint _recordSize;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
|
2020-03-23 12:57:18 +00:00
|
|
|
|
public FolderRecordBuilder(BSABuilder bsa, RelativePath folderName, IEnumerable<FileEntry> files)
|
2019-07-29 21:24:05 +00:00
|
|
|
|
{
|
2019-09-14 04:35:42 +00:00
|
|
|
|
_files = files.OrderBy(f => f._hash);
|
2020-03-23 12:57:18 +00:00
|
|
|
|
Name = folderName;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
_bsa = bsa;
|
|
|
|
|
// Folders don't have extensions, so let's make sure we cut it out
|
2020-03-23 12:57:18 +00:00
|
|
|
|
_hash = Name.GetBSAHash();
|
2019-09-14 04:35:42 +00:00
|
|
|
|
_fileCount = (uint) files.Count();
|
|
|
|
|
_nameBytes = folderName.ToBZString(_bsa.HeaderType);
|
|
|
|
|
_recordSize = sizeof(ulong) + sizeof(uint) + sizeof(uint);
|
2019-07-29 21:24:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-14 04:35:42 +00:00
|
|
|
|
public ulong Hash => _hash;
|
|
|
|
|
|
2020-03-23 12:57:18 +00:00
|
|
|
|
public RelativePath Name { get; }
|
2019-07-29 21:24:05 +00:00
|
|
|
|
|
2019-07-28 23:04:23 +00:00
|
|
|
|
public ulong SelfSize
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_bsa.HeaderType == VersionType.SSE)
|
|
|
|
|
return sizeof(ulong) + sizeof(uint) + sizeof(uint) + sizeof(ulong);
|
2019-09-14 04:35:42 +00:00
|
|
|
|
return sizeof(ulong) + sizeof(uint) + sizeof(uint);
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ulong FileRecordSize
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
ulong size = 0;
|
|
|
|
|
if (_bsa.HasFolderNames)
|
2019-09-14 04:35:42 +00:00
|
|
|
|
size += (ulong) _nameBytes.Length;
|
|
|
|
|
size += (ulong) _files.Select(f => sizeof(ulong) + sizeof(uint) + sizeof(uint)).Sum();
|
2019-07-28 23:04:23 +00:00
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 04:52:04 +00:00
|
|
|
|
public void WriteFolderRecord(BinaryWriter wtr)
|
2019-07-28 23:04:23 +00:00
|
|
|
|
{
|
2019-07-29 04:52:04 +00:00
|
|
|
|
var idx = _bsa._folders.IndexOf(this);
|
2019-09-14 04:35:42 +00:00
|
|
|
|
_offset = (ulong) wtr.BaseStream.Position;
|
|
|
|
|
_offset += (ulong) _bsa._folders.Skip(idx).Select(f => (long) f.SelfSize).Sum();
|
2019-07-28 23:04:23 +00:00
|
|
|
|
_offset += _bsa._totalFileNameLength;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
_offset += (ulong) _bsa._folders.Take(idx).Select(f => (long) f.FileRecordSize).Sum();
|
2019-07-28 23:04:23 +00:00
|
|
|
|
|
2019-09-14 04:35:42 +00:00
|
|
|
|
var sp = wtr.BaseStream.Position;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
wtr.Write(_hash);
|
|
|
|
|
wtr.Write(_fileCount);
|
|
|
|
|
if (_bsa.HeaderType == VersionType.SSE)
|
|
|
|
|
{
|
2019-09-14 04:35:42 +00:00
|
|
|
|
wtr.Write((uint) 0); // unk
|
|
|
|
|
wtr.Write(_offset); // offset
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
2019-08-22 04:27:24 +00:00
|
|
|
|
else if (_bsa.HeaderType == VersionType.FO3 || _bsa.HeaderType == VersionType.TES4)
|
|
|
|
|
{
|
2019-09-14 04:35:42 +00:00
|
|
|
|
wtr.Write((uint) _offset);
|
2019-08-22 04:27:24 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException($"Cannot write to BSAs of type {_bsa.HeaderType}");
|
|
|
|
|
}
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class FileEntry
|
|
|
|
|
{
|
|
|
|
|
internal BSABuilder _bsa;
|
|
|
|
|
internal bool _flipCompression;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
internal FolderRecordBuilder _folder;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
|
|
|
|
|
internal ulong _hash;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
internal string _name;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
internal byte[] _nameBytes;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
private long _offsetOffset;
|
|
|
|
|
internal int _originalSize;
|
2020-03-23 12:57:18 +00:00
|
|
|
|
internal RelativePath _path;
|
2019-11-12 04:35:07 +00:00
|
|
|
|
private byte[] _pathBSBytes;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
internal byte[] _pathBytes;
|
2020-03-05 04:32:38 +00:00
|
|
|
|
private Stream _srcData;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
|
2020-04-20 21:36:33 +00:00
|
|
|
|
public static async Task<FileEntry> Create(BSABuilder bsa, RelativePath path, Stream src, bool flipCompression)
|
2019-07-28 23:04:23 +00:00
|
|
|
|
{
|
2019-11-12 04:35:07 +00:00
|
|
|
|
var entry = new FileEntry();
|
|
|
|
|
entry._bsa = bsa;
|
2020-03-23 12:57:18 +00:00
|
|
|
|
entry._path = path;
|
|
|
|
|
entry._name = (string)entry._path.FileName;
|
2019-11-12 04:35:07 +00:00
|
|
|
|
entry._hash = entry._name.GetBSAHash();
|
|
|
|
|
entry._nameBytes = entry._name.ToTermString(bsa.HeaderType);
|
|
|
|
|
entry._pathBytes = entry._path.ToTermString(bsa.HeaderType);
|
|
|
|
|
entry._pathBSBytes = entry._path.ToBSString();
|
|
|
|
|
entry._flipCompression = flipCompression;
|
2020-03-05 04:32:38 +00:00
|
|
|
|
entry._srcData = src;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
|
2020-03-05 04:32:38 +00:00
|
|
|
|
entry._originalSize = (int)entry._srcData.Length;
|
2019-07-28 23:04:23 +00:00
|
|
|
|
|
2019-11-12 04:35:07 +00:00
|
|
|
|
if (entry.Compressed)
|
2020-04-20 21:36:33 +00:00
|
|
|
|
await entry.CompressData();
|
2019-11-12 04:35:07 +00:00
|
|
|
|
return entry;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
}
|
2019-07-28 23:04:23 +00:00
|
|
|
|
|
2019-09-14 04:35:42 +00:00
|
|
|
|
public bool Compressed
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_flipCompression)
|
|
|
|
|
return !_bsa.CompressedByDefault;
|
|
|
|
|
return _bsa.CompressedByDefault;
|
|
|
|
|
}
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 12:57:18 +00:00
|
|
|
|
public RelativePath Path => _path;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
|
|
|
|
|
public bool FlipCompression => _flipCompression;
|
|
|
|
|
|
|
|
|
|
public ulong Hash => _hash;
|
|
|
|
|
|
|
|
|
|
public FolderRecordBuilder Folder => _folder;
|
|
|
|
|
|
2020-04-20 21:36:33 +00:00
|
|
|
|
private async Task CompressData()
|
2019-07-28 23:04:23 +00:00
|
|
|
|
{
|
2020-03-05 04:32:38 +00:00
|
|
|
|
switch (_bsa.HeaderType)
|
2019-07-28 23:04:23 +00:00
|
|
|
|
{
|
2020-03-05 04:32:38 +00:00
|
|
|
|
case VersionType.SSE:
|
2019-09-14 04:35:42 +00:00
|
|
|
|
{
|
2020-03-05 04:32:38 +00:00
|
|
|
|
var r = new MemoryStream();
|
2020-04-20 21:36:33 +00:00
|
|
|
|
await using (var w = LZ4Stream.Encode(r, new LZ4EncoderSettings {CompressionLevel = LZ4Level.L12_MAX}, true))
|
2020-03-05 04:32:38 +00:00
|
|
|
|
{
|
2020-04-20 21:36:33 +00:00
|
|
|
|
await _srcData.CopyToWithStatusAsync(_srcData.Length, w, $"Compressing {_path}");
|
2020-03-05 04:32:38 +00:00
|
|
|
|
}
|
|
|
|
|
_srcData = _bsa._slab.Allocate(r.Length);
|
|
|
|
|
r.Position = 0;
|
2020-04-20 21:36:33 +00:00
|
|
|
|
await r.CopyToWithStatusAsync(r.Length, _srcData, $"Writing {_path}");
|
2020-03-05 04:32:38 +00:00
|
|
|
|
_srcData.Position = 0;
|
|
|
|
|
break;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
}
|
2020-03-05 04:32:38 +00:00
|
|
|
|
case VersionType.FO3:
|
|
|
|
|
case VersionType.TES4:
|
2019-09-14 04:35:42 +00:00
|
|
|
|
{
|
2020-03-05 04:32:38 +00:00
|
|
|
|
var r = new MemoryStream();
|
|
|
|
|
using (var w = new DeflaterOutputStream(r))
|
|
|
|
|
{
|
2020-03-05 05:27:15 +00:00
|
|
|
|
w.IsStreamOwner = false;
|
2020-04-20 21:36:33 +00:00
|
|
|
|
await _srcData.CopyToWithStatusAsync(_srcData.Length, w, $"Compressing {_path}");
|
2020-03-05 04:32:38 +00:00
|
|
|
|
}
|
|
|
|
|
_srcData = _bsa._slab.Allocate(r.Length);
|
|
|
|
|
r.Position = 0;
|
2020-04-20 21:36:33 +00:00
|
|
|
|
await r.CopyToWithStatusAsync(r.Length, _srcData, $"Writing {_path}");
|
2020-03-05 04:32:38 +00:00
|
|
|
|
_srcData.Position = 0;
|
|
|
|
|
break;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
}
|
2020-03-05 04:32:38 +00:00
|
|
|
|
default:
|
|
|
|
|
throw new NotImplementedException($"Can't compress data for {_bsa.HeaderType} BSAs.");
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void WriteFileRecord(BinaryWriter wtr)
|
2019-07-29 04:52:04 +00:00
|
|
|
|
|
2019-07-28 23:04:23 +00:00
|
|
|
|
{
|
|
|
|
|
wtr.Write(_hash);
|
2020-03-05 04:32:38 +00:00
|
|
|
|
var size = _srcData.Length;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
if (_bsa.HasNameBlobs) size += _pathBSBytes.Length;
|
|
|
|
|
if (Compressed) size += 4;
|
2019-07-29 04:52:04 +00:00
|
|
|
|
if (_flipCompression)
|
2019-09-14 04:35:42 +00:00
|
|
|
|
wtr.Write((uint) size | (0x1 << 30));
|
2019-07-29 04:52:04 +00:00
|
|
|
|
else
|
2019-09-14 04:35:42 +00:00
|
|
|
|
wtr.Write((uint) size);
|
2019-07-29 04:52:04 +00:00
|
|
|
|
|
|
|
|
|
_offsetOffset = wtr.BaseStream.Position;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
wtr.Write(0xDEADBEEF);
|
2019-07-29 04:52:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 21:36:33 +00:00
|
|
|
|
internal async Task WriteData(BinaryWriter wtr)
|
2019-07-29 04:52:04 +00:00
|
|
|
|
{
|
2019-09-14 04:35:42 +00:00
|
|
|
|
var offset = (uint) wtr.BaseStream.Position;
|
2019-07-29 04:52:04 +00:00
|
|
|
|
wtr.BaseStream.Position = _offsetOffset;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
wtr.Write(offset);
|
2019-07-29 04:52:04 +00:00
|
|
|
|
wtr.BaseStream.Position = offset;
|
|
|
|
|
|
2019-09-14 04:35:42 +00:00
|
|
|
|
if (_bsa.HasNameBlobs) wtr.Write(_pathBSBytes);
|
2019-08-22 04:27:24 +00:00
|
|
|
|
|
2019-07-29 04:52:04 +00:00
|
|
|
|
if (Compressed)
|
|
|
|
|
{
|
2019-09-14 04:35:42 +00:00
|
|
|
|
wtr.Write((uint) _originalSize);
|
2020-03-05 04:32:38 +00:00
|
|
|
|
_srcData.Position = 0;
|
2020-04-20 21:36:33 +00:00
|
|
|
|
await _srcData.CopyToLimitAsync(wtr.BaseStream, (int)_srcData.Length);
|
|
|
|
|
await _srcData.DisposeAsync();
|
2019-07-29 04:52:04 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-03-05 04:32:38 +00:00
|
|
|
|
_srcData.Position = 0;
|
2020-04-20 21:36:33 +00:00
|
|
|
|
await _srcData.CopyToLimitAsync(wtr.BaseStream, (int)_srcData.Length);
|
|
|
|
|
await _srcData.DisposeAsync();
|
2019-07-29 04:52:04 +00:00
|
|
|
|
}
|
2019-07-28 23:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-24 17:47:49 +00:00
|
|
|
|
}
|