2019-09-24 04:20:24 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-01-05 05:07:00 +00:00
|
|
|
|
using System.IO;
|
2019-09-26 23:08:10 +00:00
|
|
|
|
using System.Linq;
|
2019-12-07 02:54:27 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-09-24 04:20:24 +00:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2019-12-06 04:58:18 +00:00
|
|
|
|
using Wabbajack.Common;
|
2019-10-16 03:10:34 +00:00
|
|
|
|
using Wabbajack.Lib;
|
2019-12-06 00:05:26 +00:00
|
|
|
|
using Wabbajack.Lib.CompilationSteps.CompilationErrors;
|
2019-11-02 21:08:37 +00:00
|
|
|
|
using File = Alphaleonis.Win32.Filesystem.File;
|
|
|
|
|
using Path = Alphaleonis.Win32.Filesystem.Path;
|
2019-09-24 04:20:24 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Test
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
2019-10-31 02:24:42 +00:00
|
|
|
|
public class SanityTests : ACompilerTest
|
2019-09-24 04:20:24 +00:00
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
2019-12-07 02:54:27 +00:00
|
|
|
|
public async Task TestDirectMatch()
|
2019-09-24 04:20:24 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var profile = utils.AddProfile();
|
|
|
|
|
var mod = utils.AddMod();
|
|
|
|
|
var test_pex = utils.AddModFile(mod, @"Data\scripts\test.pex", 10);
|
2019-09-26 22:32:15 +00:00
|
|
|
|
|
2019-09-24 04:20:24 +00:00
|
|
|
|
utils.Configure();
|
|
|
|
|
|
|
|
|
|
utils.AddManualDownload(
|
2019-09-26 22:32:15 +00:00
|
|
|
|
new Dictionary<string, byte[]> {{"/baz/biz.pex", File.ReadAllBytes(test_pex)}});
|
2019-09-24 04:20:24 +00:00
|
|
|
|
|
2019-12-07 02:54:27 +00:00
|
|
|
|
await CompileAndInstall(profile);
|
2019-09-24 04:20:24 +00:00
|
|
|
|
|
2019-09-26 22:32:15 +00:00
|
|
|
|
utils.VerifyInstalledFile(mod, @"Data\scripts\test.pex");
|
|
|
|
|
}
|
2020-01-07 00:24:33 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task TestDirectMatchFromGameFolder()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var profile = utils.AddProfile();
|
|
|
|
|
var mod = utils.AddMod();
|
|
|
|
|
var test_pex = utils.AddGameFile(@"enbstuff\test.pex", 10);
|
|
|
|
|
|
|
|
|
|
utils.Configure();
|
|
|
|
|
|
|
|
|
|
utils.AddManualDownload(
|
|
|
|
|
new Dictionary<string, byte[]> {{"/baz/biz.pex", File.ReadAllBytes(test_pex)}});
|
|
|
|
|
|
|
|
|
|
await CompileAndInstall(profile);
|
|
|
|
|
|
|
|
|
|
utils.VerifyInstalledGameFile(@"enbstuff\test.pex");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task TestDirectMatchIsIgnoredWhenGameFolderFilesOverrideExists()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var profile = utils.AddProfile();
|
|
|
|
|
var mod = utils.AddMod();
|
|
|
|
|
var test_pex = utils.AddGameFile(@"enbstuff\test.pex", 10);
|
|
|
|
|
|
|
|
|
|
utils.Configure();
|
|
|
|
|
|
|
|
|
|
Directory.CreateDirectory(Path.Combine(utils.MO2Folder, Consts.GameFolderFilesDir));
|
|
|
|
|
|
|
|
|
|
utils.AddManualDownload(
|
|
|
|
|
new Dictionary<string, byte[]> {{"/baz/biz.pex", File.ReadAllBytes(test_pex)}});
|
|
|
|
|
|
|
|
|
|
await CompileAndInstall(profile);
|
|
|
|
|
|
|
|
|
|
Assert.IsFalse(File.Exists(Path.Combine(utils.InstallFolder, Consts.GameFolderFilesDir, @"enbstuff\test.pex")));
|
|
|
|
|
}
|
2019-09-26 22:32:15 +00:00
|
|
|
|
|
2019-11-07 04:43:30 +00:00
|
|
|
|
[TestMethod]
|
2019-12-07 02:54:27 +00:00
|
|
|
|
public async Task TestDuplicateFilesAreCopied()
|
2019-11-07 04:43:30 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var profile = utils.AddProfile();
|
|
|
|
|
var mod = utils.AddMod();
|
|
|
|
|
var test_pex = utils.AddModFile(mod, @"Data\scripts\test.pex", 10);
|
|
|
|
|
|
|
|
|
|
// Make a copy to make sure it gets picked up and moved around.
|
|
|
|
|
File.Copy(test_pex, test_pex + ".copy");
|
|
|
|
|
|
|
|
|
|
utils.Configure();
|
|
|
|
|
|
|
|
|
|
utils.AddManualDownload(
|
|
|
|
|
new Dictionary<string, byte[]> { { "/baz/biz.pex", File.ReadAllBytes(test_pex) } });
|
|
|
|
|
|
2019-12-07 02:54:27 +00:00
|
|
|
|
await CompileAndInstall(profile);
|
2019-11-07 04:43:30 +00:00
|
|
|
|
|
|
|
|
|
utils.VerifyInstalledFile(mod, @"Data\scripts\test.pex");
|
|
|
|
|
utils.VerifyInstalledFile(mod, @"Data\scripts\test.pex.copy");
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-18 05:21:24 +00:00
|
|
|
|
[TestMethod]
|
2019-12-07 02:54:27 +00:00
|
|
|
|
public async Task TestUpdating()
|
2019-11-18 05:21:24 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var profile = utils.AddProfile();
|
|
|
|
|
var mod = utils.AddMod();
|
|
|
|
|
var unchanged = utils.AddModFile(mod, @"Data\scripts\unchanged.pex", 10);
|
|
|
|
|
var deleted = utils.AddModFile(mod, @"Data\scripts\deleted.pex", 10);
|
|
|
|
|
var modified = utils.AddModFile(mod, @"Data\scripts\modified.pex", 10);
|
|
|
|
|
|
|
|
|
|
utils.Configure();
|
|
|
|
|
|
|
|
|
|
utils.AddManualDownload(
|
|
|
|
|
new Dictionary<string, byte[]>
|
|
|
|
|
{
|
|
|
|
|
{ "/baz/unchanged.pex", File.ReadAllBytes(unchanged) },
|
|
|
|
|
{ "/baz/deleted.pex", File.ReadAllBytes(deleted) },
|
|
|
|
|
{ "/baz/modified.pex", File.ReadAllBytes(modified) },
|
|
|
|
|
});
|
|
|
|
|
|
2019-12-07 02:54:27 +00:00
|
|
|
|
await CompileAndInstall(profile);
|
2019-11-18 05:21:24 +00:00
|
|
|
|
|
|
|
|
|
utils.VerifyInstalledFile(mod, @"Data\scripts\unchanged.pex");
|
|
|
|
|
utils.VerifyInstalledFile(mod, @"Data\scripts\deleted.pex");
|
|
|
|
|
utils.VerifyInstalledFile(mod, @"Data\scripts\modified.pex");
|
|
|
|
|
|
|
|
|
|
var unchanged_path = utils.PathOfInstalledFile(mod, @"Data\scripts\unchanged.pex");
|
|
|
|
|
var deleted_path = utils.PathOfInstalledFile(mod, @"Data\scripts\deleted.pex");
|
|
|
|
|
var modified_path = utils.PathOfInstalledFile(mod, @"Data\scripts\modified.pex");
|
|
|
|
|
|
2019-11-20 00:15:46 +00:00
|
|
|
|
var extra_path = utils.PathOfInstalledFile(mod, @"something_i_made.foo");
|
|
|
|
|
File.WriteAllText(extra_path, "bleh");
|
|
|
|
|
|
2020-01-05 05:07:00 +00:00
|
|
|
|
var extra_folder = Path.Combine(Path.GetDirectoryName(utils.PathOfInstalledFile(mod, @"something_i_made.foo")), "folder_i_made");
|
|
|
|
|
Directory.CreateDirectory(extra_folder);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(Directory.Exists(extra_folder));
|
|
|
|
|
|
2019-11-18 05:21:24 +00:00
|
|
|
|
|
|
|
|
|
var unchanged_modified = File.GetLastWriteTime(unchanged_path);
|
|
|
|
|
var modified_modified = File.GetLastWriteTime(modified_path);
|
|
|
|
|
|
|
|
|
|
File.WriteAllText(modified_path, "random data");
|
|
|
|
|
File.Delete(deleted_path);
|
|
|
|
|
|
2019-11-20 00:15:46 +00:00
|
|
|
|
Assert.IsTrue(File.Exists(extra_path));
|
|
|
|
|
|
2019-12-07 02:54:27 +00:00
|
|
|
|
await CompileAndInstall(profile);
|
2019-11-18 05:21:24 +00:00
|
|
|
|
|
|
|
|
|
utils.VerifyInstalledFile(mod, @"Data\scripts\unchanged.pex");
|
|
|
|
|
utils.VerifyInstalledFile(mod, @"Data\scripts\deleted.pex");
|
|
|
|
|
utils.VerifyInstalledFile(mod, @"Data\scripts\modified.pex");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(unchanged_modified, File.GetLastWriteTime(unchanged_path));
|
|
|
|
|
Assert.AreNotEqual(modified_modified, File.GetLastWriteTime(modified_path));
|
2019-11-20 00:15:46 +00:00
|
|
|
|
Assert.IsFalse(File.Exists(extra_path));
|
2020-01-05 05:07:00 +00:00
|
|
|
|
Assert.IsFalse(Directory.Exists(extra_folder));
|
2019-11-18 05:21:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-07 04:43:30 +00:00
|
|
|
|
|
2019-11-02 21:08:37 +00:00
|
|
|
|
[TestMethod]
|
2019-12-07 02:54:27 +00:00
|
|
|
|
public async Task CleanedESMTest()
|
2019-11-02 21:08:37 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
2019-12-13 13:02:58 +00:00
|
|
|
|
var modlist = await CompileAndInstall(profile);
|
2019-11-02 21:08:37 +00:00
|
|
|
|
|
|
|
|
|
utils.VerifyInstalledFile(mod, @"Update.esm");
|
|
|
|
|
|
2019-12-07 02:54:27 +00:00
|
|
|
|
var compiler = await ConfigureAndRunCompiler(profile);
|
2019-11-02 21:08:37 +00:00
|
|
|
|
|
|
|
|
|
// Update the file and verify that it throws an error.
|
|
|
|
|
utils.GenerateRandomFileData(game_file, 20);
|
2019-12-23 04:51:20 +00:00
|
|
|
|
var exception = await Assert.ThrowsExceptionAsync<InvalidGameESMError>(async () => await Install(compiler));
|
|
|
|
|
Assert.IsInstanceOfType(exception, typeof(InvalidGameESMError));
|
2019-12-06 04:58:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-12-13 13:02:58 +00:00
|
|
|
|
public async Task SetScreenSizeTest()
|
2019-12-06 04:58:18 +00:00
|
|
|
|
{
|
|
|
|
|
var profile = utils.AddProfile();
|
|
|
|
|
var mod = utils.AddMod("dummy");
|
|
|
|
|
|
|
|
|
|
utils.Configure();
|
|
|
|
|
File.WriteAllLines(Path.Combine(utils.MO2Folder, "profiles", profile, "somegameprefs.ini"),
|
|
|
|
|
new List<string>
|
|
|
|
|
{
|
2019-12-17 23:17:44 +00:00
|
|
|
|
// Beth inis are messy, let's make ours just as messy to catch some parse failures
|
|
|
|
|
"[Display]",
|
|
|
|
|
"foo=4",
|
2019-12-06 04:58:18 +00:00
|
|
|
|
"[Display]",
|
2019-12-16 06:33:44 +00:00
|
|
|
|
"STestFile=f",
|
|
|
|
|
"STestFile=",
|
2019-12-06 04:58:18 +00:00
|
|
|
|
"iSize H=3",
|
2019-12-17 23:17:44 +00:00
|
|
|
|
"iSize W=-200",
|
|
|
|
|
"[Display]",
|
|
|
|
|
"foo=4"
|
2019-12-06 04:58:18 +00:00
|
|
|
|
});
|
|
|
|
|
|
2019-12-13 13:02:58 +00:00
|
|
|
|
var modlist = await CompileAndInstall(profile);
|
2019-11-02 21:08:37 +00:00
|
|
|
|
|
2019-12-06 04:58:18 +00:00
|
|
|
|
var ini = Path.Combine(utils.InstallFolder, "profiles", profile, "somegameprefs.ini").LoadIniFile();
|
2019-11-02 21:08:37 +00:00
|
|
|
|
|
2019-12-06 04:58:18 +00:00
|
|
|
|
Assert.AreEqual(System.Windows.SystemParameters.PrimaryScreenHeight.ToString(), ini?.Display?["iSize H"]);
|
|
|
|
|
Assert.AreEqual(System.Windows.SystemParameters.PrimaryScreenWidth.ToString(), ini?.Display?["iSize W"]);
|
2019-11-02 21:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-26 23:08:10 +00:00
|
|
|
|
[TestMethod]
|
2019-12-07 02:54:27 +00:00
|
|
|
|
public async Task UnmodifiedInlinedFilesArePulledFromArchives()
|
2019-09-26 23:08:10 +00:00
|
|
|
|
{
|
|
|
|
|
var profile = utils.AddProfile();
|
|
|
|
|
var mod = utils.AddMod();
|
|
|
|
|
var ini = utils.AddModFile(mod, @"foo.ini", 10);
|
|
|
|
|
utils.Configure();
|
|
|
|
|
|
|
|
|
|
utils.AddManualDownload(
|
|
|
|
|
new Dictionary<string, byte[]> { { "/baz/biz.pex", File.ReadAllBytes(ini) } });
|
|
|
|
|
|
2019-12-07 02:54:27 +00:00
|
|
|
|
var modlist = await CompileAndInstall(profile);
|
2019-09-26 23:08:10 +00:00
|
|
|
|
var directive = modlist.Directives.Where(m => m.To == $"mods\\{mod}\\foo.ini").FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(directive);
|
|
|
|
|
Assert.IsInstanceOfType(directive, typeof(FromArchive));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-12-07 02:54:27 +00:00
|
|
|
|
public async Task ModifiedIniFilesArePatchedAgainstFileWithSameName()
|
2019-09-26 23:08:10 +00:00
|
|
|
|
{
|
|
|
|
|
var profile = utils.AddProfile();
|
|
|
|
|
var mod = utils.AddMod();
|
|
|
|
|
var ini = utils.AddModFile(mod, @"foo.ini", 10);
|
2019-11-21 21:32:58 +00:00
|
|
|
|
var meta = utils.AddModFile(mod, "meta.ini");
|
|
|
|
|
|
2019-09-26 23:08:10 +00:00
|
|
|
|
utils.Configure();
|
|
|
|
|
|
|
|
|
|
|
2019-11-21 21:32:58 +00:00
|
|
|
|
var archive = utils.AddManualDownload(
|
2019-09-26 23:08:10 +00:00
|
|
|
|
new Dictionary<string, byte[]> { { "/baz/foo.ini", File.ReadAllBytes(ini) } });
|
|
|
|
|
|
2019-11-21 21:32:58 +00:00
|
|
|
|
File.WriteAllLines(meta, new[]
|
|
|
|
|
{
|
|
|
|
|
"[General]",
|
|
|
|
|
$"installationFile={archive}",
|
|
|
|
|
});
|
|
|
|
|
|
2019-09-26 23:08:10 +00:00
|
|
|
|
// Modify after creating mod archive in the downloads folder
|
|
|
|
|
File.WriteAllText(ini, "Wabbajack, Wabbajack, Wabbajack!");
|
|
|
|
|
|
2019-12-07 02:54:27 +00:00
|
|
|
|
var modlist = await CompileAndInstall(profile);
|
2019-09-26 23:08:10 +00:00
|
|
|
|
var directive = modlist.Directives.Where(m => m.To == $"mods\\{mod}\\foo.ini").FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(directive);
|
|
|
|
|
Assert.IsInstanceOfType(directive, typeof(PatchedFromArchive));
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-24 04:20:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|