fixed issue with bsa files of 0 length

This commit is contained in:
Timothy Baldridge 2019-09-08 16:44:15 -06:00
parent bbdef88296
commit b1c2f17784
4 changed files with 30 additions and 30 deletions

View File

@ -10,7 +10,7 @@ namespace Compression.BSA.Test
{
class Program
{
const string TestDir = @"D:\Personal YASHed\";
const string TestDir = @"D:\MO2 Instances\";
const string TempDir = "c:\\tmp\\out";
static void Main(string[] args)
{

View File

@ -249,7 +249,7 @@ namespace Compression.BSA
private BSAReader _bsa;
private ulong _hash;
private bool _compressedFlag;
private int _size;
private uint _size;
private uint _offset;
private FolderRecord _folder;
private string _name;
@ -263,7 +263,7 @@ namespace Compression.BSA
{
_bsa = bsa;
_hash = src.ReadUInt64();
var size = src.ReadInt32();
var size = src.ReadUInt32();
_compressedFlag = (size & (0x1 << 30)) > 0;
if (_compressedFlag)
@ -275,7 +275,6 @@ namespace Compression.BSA
_size -= 4;
_offset = src.ReadUInt32();
_folder = folderRecord;
var old_pos = src.BaseStream.Position;
@ -285,6 +284,7 @@ namespace Compression.BSA
if (bsa.HasNameBlobs)
_nameBlob = src.ReadStringLenNoTerm(bsa.HeaderType);
if (Compressed)
_originalSize = src.ReadUInt32();
@ -312,6 +312,7 @@ namespace Compression.BSA
{
get
{
if (string.IsNullOrEmpty(_folder.Name)) return _name;
return _folder.Name + "\\" + _name;
}
}
@ -333,26 +334,6 @@ namespace Compression.BSA
}
}
private void LoadOriginalSize()
{
using (var in_file = File.OpenRead(_bsa._fileName))
using (var rdr = new BinaryReader(in_file))
{
rdr.BaseStream.Position = _offset;
string _name;
int file_size = _size;
if (_bsa.HasNameBlobs)
{
var name_size = rdr.ReadByte();
file_size -= name_size + 1;
rdr.BaseStream.Position = _offset + 1 + name_size;
}
_originalSize = rdr.ReadUInt32();
}
}
public ulong Hash {
get
{

View File

@ -19,6 +19,12 @@ namespace Compression.BSA
public static string ReadStringLen(this BinaryReader rdr, VersionType version)
{
var len = rdr.ReadByte();
if (len == 0)
{
//rdr.ReadByte();
return "";
}
var bytes = rdr.ReadBytes(len - 1);
rdr.ReadByte();
return GetEncoding(version).GetString(bytes);
@ -99,7 +105,11 @@ namespace Compression.BSA
{
name = name.ToLowerInvariant();
ext = ext.ToLowerInvariant();
var hashBytes = new byte[]
if (string.IsNullOrEmpty(name))
return 0;
var hashBytes = new[]
{
(byte)(name.Length == 0 ? '\0' : name[name.Length - 1]),
(byte)(name.Length < 3 ? '\0' : name[name.Length - 2]),

View File

@ -43,7 +43,10 @@ namespace Wabbajack.Common
public static void ExtractAll(string source, string dest)
{
if (source.EndsWith(".bsa")) {
try
{
if (source.EndsWith(".bsa"))
{
ExtractAllWithBSA(source, dest);
}
else
@ -51,6 +54,12 @@ namespace Wabbajack.Common
ExtractAllWith7Zip(source, dest);
}
}
catch (Exception ex)
{
Utils.Log($"Error while extracting {source}");
throw ex;
}
}
private static void ExtractAllWithBSA(string source, string dest)
{