diff --git a/Wabbajack.Lib/Installer.cs b/Wabbajack.Lib/Installer.cs index cbedd716..abf0a280 100644 --- a/Wabbajack.Lib/Installer.cs +++ b/Wabbajack.Lib/Installer.cs @@ -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().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); } } diff --git a/Wabbajack.Test/ACompilerTest.cs b/Wabbajack.Test/ACompilerTest.cs index 9a0eb223..78dd2fe9 100644 --- a/Wabbajack.Test/ACompilerTest.cs +++ b/Wabbajack.Test/ACompilerTest.cs @@ -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; } diff --git a/Wabbajack.Test/SanityTests.cs b/Wabbajack.Test/SanityTests.cs index 19115113..210f5aaf 100644 --- a/Wabbajack.Test/SanityTests.cs +++ b/Wabbajack.Test/SanityTests.cs @@ -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(() => 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() { diff --git a/Wabbajack.Test/TestUtils.cs b/Wabbajack.Test/TestUtils.cs index d84811b2..95316f55 100644 --- a/Wabbajack.Test/TestUtils.cs +++ b/Wabbajack.Test/TestUtils.cs @@ -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 /// /// 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()