Fix some nasty bugs with name blob sizes and hashes in Compression.BSA

This commit is contained in:
Timothy Baldridge 2020-08-14 19:27:33 -06:00
parent 167b81d586
commit 3cf766c941
3 changed files with 27 additions and 3 deletions

View File

@ -0,0 +1,19 @@
using Wabbajack.Common;
using Xunit;
namespace Compression.BSA.Test
{
public class UnitTests
{
[Fact]
public void HashesRespectFolderExtensions()
{
Assert.Equal((ulong)0x085B31F63008E2B6, BSAUtils.GetBSAHash("005930b6.dds"));
// Old code has a bug where we were stripping the `.esp` from the folder which we shoudn't do when creating folder paths
Assert.Equal((ulong)0x38C7A858743A7370, BSAUtils.GetFolderBSAHash((RelativePath)@"textures\actors\character\facegendata\facetint\darkend.esp"));
}
}
}

View File

@ -152,7 +152,7 @@ namespace Compression.BSA
Name = folderName;
_bsa = bsa;
// Folders don't have extensions, so let's make sure we cut it out
_hash = Name.GetBSAHash();
_hash = Name.GetFolderBSAHash();
_fileCount = (uint) files.Count();
_nameBytes = folderName.ToBZString(_bsa.HeaderType);
_recordSize = sizeof(ulong) + sizeof(uint) + sizeof(uint);

View File

@ -8,11 +8,11 @@ using Path = Alphaleonis.Win32.Filesystem.Path;
namespace Compression.BSA
{
internal static class Utils
public static class BSAUtils
{
private static readonly Encoding Windows1252;
static Utils()
static BSAUtils()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Windows1252 = Encoding.GetEncoding(1252);
@ -129,6 +129,11 @@ namespace Compression.BSA
{
return ((string)name).GetBSAHash();
}
public static ulong GetFolderBSAHash(this RelativePath name)
{
return GetBSAHash((string)name, "");
}
public static ulong GetBSAHash(this string name, string ext)
{