several small fixes

This commit is contained in:
Timothy Baldridge 2019-09-07 21:34:18 -06:00
parent dd157d9e28
commit bbdef88296
8 changed files with 46 additions and 25 deletions

View File

@ -1,5 +1,16 @@
### Changelog
#### Version 0.9.2 - ???
* Fixed a bug with BSA string encoding
* Fixed another profile issue confirmed that they are properly included now
* Log when the executable is being generated
* Fixed a integer overflow resulting in a crash in very large BSA reading
* Fix a bug in BSA string encoding
#### Version 0.9.1 - 9/5/2019
* Fixed a bug where having only one profile selected would result in no profiles being selected
#### Version 0.9 - 9/5/2019
* Added log information for when modlists start parsing during installation
* Check all links during mod list creation

View File

@ -10,11 +10,11 @@ namespace Compression.BSA.Test
{
class Program
{
const string TestDir = "d:\\MO2 Instances\\";
const string TestDir = @"D:\Personal YASHed\";
const string TempDir = "c:\\tmp\\out";
static void Main(string[] args)
{
foreach (var bsa in Directory.EnumerateFiles(TestDir, "*.bsa", SearchOption.AllDirectories).Skip(2))
foreach (var bsa in Directory.EnumerateFiles(TestDir, "*.bsa", SearchOption.AllDirectories).Skip(0))
{
Console.WriteLine($"From {bsa}");
Console.WriteLine("Cleaning Output Dir");
@ -59,7 +59,7 @@ namespace Compression.BSA.Test
});
w.Build("c:\\tmp\\built.bsa");
w.Build("c:\\tmp\\tmp.bsa");
// Sanity Checks
Equal(a.Files.Count(), w.Files.Count());
@ -79,7 +79,7 @@ namespace Compression.BSA.Test
}
Console.WriteLine($"Verifying {bsa}");
using (var b = new BSAReader("c:\\tmp\\built.bsa"))
using (var b = new BSAReader("c:\\tmp\\tmp.bsa"))
{
Console.WriteLine($"Performing A/B tests on {bsa}");
Equal((uint)a.ArchiveFlags, (uint)b.ArchiveFlags);

View File

@ -265,7 +265,7 @@ namespace Compression.BSA
// Folders don't have extensions, so let's make sure we cut it out
_hash = _name.GetBSAHash("");
_fileCount = (uint)files.Count();
_nameBytes = folderName.ToBZString();
_nameBytes = folderName.ToBZString(_bsa.HeaderType);
_recordSize = sizeof(ulong) + sizeof(uint) + sizeof(uint);
}
@ -321,8 +321,8 @@ namespace Compression.BSA
_path = path.ToLowerInvariant();
_name = System.IO.Path.GetFileName(_path);
_hash = _name.GetBSAHash();
_nameBytes = _name.ToTermString();
_pathBytes = _path.ToTermString();
_nameBytes = _name.ToTermString(bsa.HeaderType);
_pathBytes = _path.ToTermString(bsa.HeaderType);
_pathBSBytes = _path.ToBSString();
_flipCompression = flipCompression;

View File

@ -232,7 +232,7 @@ namespace Compression.BSA
{
if (bsa.HasFolderNames)
{
Name = src.ReadStringLen();
Name = src.ReadStringLen(bsa.HeaderType);
}
_files = new List<FileRecord>();
@ -250,7 +250,7 @@ namespace Compression.BSA
private ulong _hash;
private bool _compressedFlag;
private int _size;
private int _offset;
private uint _offset;
private FolderRecord _folder;
private string _name;
private uint _originalSize;
@ -274,7 +274,7 @@ namespace Compression.BSA
if (Compressed)
_size -= 4;
_offset = src.ReadInt32();
_offset = src.ReadUInt32();
_folder = folderRecord;
@ -283,7 +283,7 @@ namespace Compression.BSA
src.BaseStream.Position = _offset;
if (bsa.HasNameBlobs)
_nameBlob = src.ReadStringLenNoTerm();
_nameBlob = src.ReadStringLenNoTerm(bsa.HeaderType);
if (Compressed)
_originalSize = src.ReadUInt32();
@ -305,7 +305,7 @@ namespace Compression.BSA
internal void LoadFileRecord(BSAReader bsaReader, FolderRecord folder, FileRecord file, BinaryReader rdr)
{
_name = rdr.ReadStringTerm();
_name = rdr.ReadStringTerm(_bsa.HeaderType);
}
public string Path

View File

@ -8,24 +8,30 @@ namespace Compression.BSA
{
internal static class Utils
{
private static Encoding Windows1251 = Encoding.UTF7;// Encoding.GetEncoding(1251);
private static Encoding Windows1252 = Encoding.GetEncoding(1252);
private static Encoding GetEncoding(VersionType version)
{
if (version == VersionType.SSE)
return Windows1252;
return Encoding.UTF7;
}
public static string ReadStringLen(this BinaryReader rdr)
public static string ReadStringLen(this BinaryReader rdr, VersionType version)
{
var len = rdr.ReadByte();
var bytes = rdr.ReadBytes(len - 1);
rdr.ReadByte();
return Windows1251.GetString(bytes);
return GetEncoding(version).GetString(bytes);
}
public static string ReadStringLenNoTerm(this BinaryReader rdr)
public static string ReadStringLenNoTerm(this BinaryReader rdr, VersionType version)
{
var len = rdr.ReadByte();
var bytes = rdr.ReadBytes(len);
return Windows1251.GetString(bytes);
return GetEncoding(version).GetString(bytes);
}
public static string ReadStringTerm(this BinaryReader rdr)
public static string ReadStringTerm(this BinaryReader rdr, VersionType version)
{
List<byte> acc = new List<byte>();
while (true)
@ -36,7 +42,7 @@ namespace Compression.BSA
acc.Add(c);
}
return Windows1251.GetString(acc.ToArray());
return GetEncoding(version).GetString(acc.ToArray());
}
@ -45,9 +51,9 @@ namespace Compression.BSA
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static byte[] ToBZString(this string val)
public static byte[] ToBZString(this string val, VersionType version)
{
var b = Windows1251.GetBytes(val);
var b = GetEncoding(version).GetBytes(val);
var b2 = new byte[b.Length + 2];
b.CopyTo(b2, 1);
b2[0] = (byte)(b.Length + 1);
@ -74,9 +80,9 @@ namespace Compression.BSA
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static byte[] ToTermString(this string val)
public static byte[] ToTermString(this string val, VersionType version)
{
var b = Windows1251.GetBytes(val);
var b = GetEncoding(version).GetBytes(val);
var b2 = new byte[b.Length + 1];
b.CopyTo(b2, 0);
b[0] = (byte)b.Length;

View File

@ -11,7 +11,7 @@ namespace VirtualFileSystem.Test
Utils.SetStatusFn((s, i) => Console.WriteLine(s));
WorkQueue.Init((a, b, c) => { return; },
(a, b) => { return; });
VFS.VirtualFileSystem.VFS.AddRoot(@"D:\MO2 Instances\Mod Organizer 2");
VFS.VirtualFileSystem.VFS.AddRoot(@"D:\tmp\Interesting NPCs SSE 3.42\Data");
}
}
}

View File

@ -993,7 +993,7 @@ namespace Wabbajack
{
if (source.Path.StartsWith("profiles\\"))
{
if (profiles.Any(profile => !source.Path.StartsWith(profile)))
if (profiles.Any(profile => source.Path.StartsWith(profile)))
{
return null;
}
@ -1104,6 +1104,7 @@ namespace Wabbajack
internal void PatchExecutable()
{
Utils.Log("Exporting Installer");
var settings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto };
var data = JsonConvert.SerializeObject(ModList, settings).BZip2String();
var executable = Assembly.GetExecutingAssembly().Location;

View File

@ -170,6 +170,9 @@ namespace Wabbajack
public static ModInfo GetModInfo(NexusMod archive, string apikey)
{
if (!Directory.Exists(Consts.NexusCacheDirectory))
Directory.CreateDirectory(Consts.NexusCacheDirectory);
string path = Path.Combine(Consts.NexusCacheDirectory, $"mod-info-{archive.GameName}-{archive.ModID}.json");
if (File.Exists(path))
return path.FromJSON<ModInfo>();