bump version, add check for Cleaned ESMs before install

This commit is contained in:
Timothy Baldridge 2019-11-02 15:08:37 -06:00
parent a177a60c54
commit 979334197f
4 changed files with 63 additions and 9 deletions

View File

@ -98,7 +98,7 @@ namespace Wabbajack.Lib
public void Install()
{
ValidateGameESMs();
ValidateModlist.RunValidation(ModList);
VirtualFileSystem.Clean();
@ -121,7 +121,8 @@ namespace Wabbajack.Lib
var game = GameRegistry.Games[ModList.GameType];
GameFolder = game.GameLocation;
if (GameFolder == null)
GameFolder = game.GameLocation;
if (GameFolder == null)
{
@ -163,6 +164,21 @@ namespace Wabbajack.Lib
//AskToEndorse();
}
private void ValidateGameESMs()
{
foreach (var esm in ModList.Directives.OfType<CleanedESM>().ToList())
{
var filename = Path.GetFileName(esm.To);
var game_file = Path.Combine(GameFolder, "Data", filename);
Utils.Log($"Validating {filename}");
var hash = game_file.FileHash();
if (hash != esm.SourceESMHash)
{
Utils.Error("Game ESM hash doesn't match, is the ESM already cleaned? Please verify your local game files.");
}
}
}
private void AskToEndorse()
{
var mods = ModList.Archives
@ -308,8 +324,9 @@ namespace Wabbajack.Lib
var to_file = Path.Combine(Outputfolder, directive.To);
Status($"Patching {filename}");
using (var output = File.OpenWrite(to_file))
using (var input = File.OpenRead(game_file))
{
BSDiff.Apply(File.OpenRead(game_file), () => new MemoryStream(patch_data), output);
BSDiff.Apply(input, () => new MemoryStream(patch_data), output);
}
}

View File

@ -10,7 +10,7 @@ using Wabbajack.Lib;
namespace Wabbajack.Test
{
public abstract class ACompilerTest
public abstract class ACompilerTest
{
public TestContext TestContext { get; set; }
protected TestUtils utils { get; set; }

View File

@ -1,13 +1,15 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime;
using Alphaleonis.Win32.Filesystem;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting.Logging;
using VFS;
using Wabbajack.Common;
using Wabbajack.Lib;
using File = Alphaleonis.Win32.Filesystem.File;
using Path = Alphaleonis.Win32.Filesystem.Path;
namespace Wabbajack.Test
{
@ -32,6 +34,33 @@ namespace Wabbajack.Test
utils.VerifyInstalledFile(mod, @"Data\scripts\test.pex");
}
[TestMethod]
public void CleanedESMTest()
{
var profile = utils.AddProfile();
var mod = utils.AddMod("Cleaned ESMs");
var update_esm = utils.AddModFile(mod, @"Update.esm", 10);
utils.Configure();
var game_file = Path.Combine(utils.GameFolder, "Data", "Update.esm");
utils.GenerateRandomFileData(game_file, 20);
var modlist = CompileAndInstall(profile);
utils.VerifyInstalledFile(mod, @"Update.esm");
var compiler = ConfigureAndRunCompiler(profile);
// Update the file and verify that it throws an error.
utils.GenerateRandomFileData(game_file, 20);
var exception = Assert.ThrowsException<Exception>(() => Install(compiler));
Assert.AreEqual(exception.Message, "Game ESM hash doesn't match, is the ESM already cleaned? Please verify your local game files.");
}
[TestMethod]
public void UnmodifiedInlinedFilesArePulledFromArchives()
{

View File

@ -53,7 +53,7 @@ namespace Wabbajack.Test
});
Directory.CreateDirectory(DownloadsFolder);
Directory.CreateDirectory(GameFolder);
Directory.CreateDirectory(Path.Combine(GameFolder, "Data"));
Profiles.Do(profile =>
{
@ -92,6 +92,17 @@ namespace Wabbajack.Test
/// <param name="random_fill"></param>
/// <returns></returns>
public string AddModFile(string mod_name, string path, int random_fill=128)
{
var full_path = Path.Combine(ModsFolder, mod_name, path);
Directory.CreateDirectory(Path.GetDirectoryName(full_path));
GenerateRandomFileData(full_path, random_fill);
return full_path;
}
public void GenerateRandomFileData(string full_path, int random_fill)
{
byte[] bytes = new byte[0];
if (random_fill != 0)
@ -100,10 +111,7 @@ namespace Wabbajack.Test
RNG.NextBytes(bytes);
}
var full_path = Path.Combine(ModsFolder, mod_name, path);
Directory.CreateDirectory(Path.GetDirectoryName(full_path));
File.WriteAllBytes(full_path, bytes);
return full_path;
}
public void Dispose()