2019-10-28 03:15:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-12-06 05:29:17 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-10-28 03:15:48 +00:00
|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
2019-10-29 21:30:27 +00:00
|
|
|
|
using Wabbajack.Lib.NexusApi;
|
2020-03-05 00:02:16 +00:00
|
|
|
|
using Wabbajack.VirtualFileSystem;
|
2020-03-28 18:22:53 +00:00
|
|
|
|
using Xunit;
|
|
|
|
|
using Xunit.Abstractions;
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Test
|
|
|
|
|
{
|
2020-03-29 20:42:45 +00:00
|
|
|
|
public class EndToEndTests : XunitContextBase, IDisposable
|
2019-10-28 03:15:48 +00:00
|
|
|
|
{
|
2020-03-28 18:22:53 +00:00
|
|
|
|
private AbsolutePath _downloadFolder = "downloads".RelativeTo(AbsolutePath.EntryPoint);
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
|
|
|
|
private TestUtils utils = new TestUtils();
|
2020-03-29 20:42:45 +00:00
|
|
|
|
private IDisposable _unsub;
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
2019-11-17 04:16:42 +00:00
|
|
|
|
public WorkQueue Queue { get; set; }
|
|
|
|
|
|
2020-03-29 20:42:45 +00:00
|
|
|
|
public EndToEndTests(ITestOutputHelper helper) : base(helper)
|
2019-10-28 03:15:48 +00:00
|
|
|
|
{
|
2019-11-17 04:16:42 +00:00
|
|
|
|
Queue = new WorkQueue();
|
2019-10-28 03:15:48 +00:00
|
|
|
|
Consts.TestMode = true;
|
|
|
|
|
|
|
|
|
|
utils = new TestUtils();
|
2019-11-16 22:02:36 +00:00
|
|
|
|
utils.Game = Game.SkyrimSpecialEdition;
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
2020-03-29 20:42:45 +00:00
|
|
|
|
_unsub = Utils.LogMessages.Subscribe(f => XunitContext.WriteLine($"{DateTime.Now} - {f}"));
|
2020-03-28 18:22:53 +00:00
|
|
|
|
|
|
|
|
|
_downloadFolder.CreateDirectory();
|
2019-11-17 04:16:42 +00:00
|
|
|
|
}
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
2020-03-29 20:42:45 +00:00
|
|
|
|
public override void Dispose()
|
2019-11-17 04:16:42 +00:00
|
|
|
|
{
|
2019-12-07 02:04:42 +00:00
|
|
|
|
Queue.Dispose();
|
2020-03-29 20:42:45 +00:00
|
|
|
|
_unsub.Dispose();
|
2020-04-10 19:33:09 +00:00
|
|
|
|
utils.DisposeAsync().AsTask().Wait();
|
2020-03-29 20:42:45 +00:00
|
|
|
|
base.Dispose();
|
2019-10-28 03:15:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 18:22:53 +00:00
|
|
|
|
[Fact]
|
2019-12-06 05:29:17 +00:00
|
|
|
|
public async Task CreateModlist()
|
2019-10-28 03:15:48 +00:00
|
|
|
|
{
|
|
|
|
|
var profile = utils.AddProfile("Default");
|
2020-05-25 17:34:25 +00:00
|
|
|
|
var mod = await utils.AddMod();
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
2019-12-06 05:29:17 +00:00
|
|
|
|
await DownloadAndInstall(
|
2019-10-28 03:15:48 +00:00
|
|
|
|
"https://github.com/ModOrganizer2/modorganizer/releases/download/v2.2.1/Mod.Organizer.2.2.1.7z",
|
2020-03-28 18:22:53 +00:00
|
|
|
|
"Mod.Organizer.2.2.1.7z");
|
2020-10-18 19:03:50 +00:00
|
|
|
|
await utils.DownloadsPath.Combine("Mod.Organizer.2.2.1.7z.meta").WriteAllLinesAsync(
|
2019-10-28 03:15:48 +00:00
|
|
|
|
"[General]",
|
|
|
|
|
"directURL=https://github.com/ModOrganizer2/modorganizer/releases/download/v2.2.1/Mod.Organizer.2.2.1.7z"
|
2020-03-28 18:22:53 +00:00
|
|
|
|
);
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
2020-02-05 05:17:12 +00:00
|
|
|
|
var modfiles = await Task.WhenAll(
|
|
|
|
|
DownloadAndInstall(Game.SkyrimSpecialEdition, 12604, "SkyUI"),
|
|
|
|
|
DownloadAndInstall(Game.Fallout4, 11925, "Anti-Tank Rifle"),
|
|
|
|
|
DownloadAndInstall(Game.SkyrimSpecialEdition, 4783, "Frost Armor UNP"),
|
2020-07-21 22:25:34 +00:00
|
|
|
|
DownloadAndInstall(Game.SkyrimSpecialEdition, 32359, "Frost Armor HDT"),
|
2020-07-27 21:33:45 +00:00
|
|
|
|
DownloadAndInstall("https://github.com/ShikyoKira/Project-New-Reign---Nemesis-Main/releases/download/v0.84-beta/Nemesis.Unlimited.Behavior.Engine.v0.84-beta.rar", "Nemesis.Unlimited.Behavior.Engine.v0.84-beta.rar", "Nemesis"),
|
2020-11-02 00:30:49 +00:00
|
|
|
|
DownloadAndInstall(Game.Fallout4, 40136, "RAR test File")); // ShouldPullFrom Mirror
|
2020-02-05 05:17:12 +00:00
|
|
|
|
|
|
|
|
|
// We're going to fully patch this mod from another source.
|
2020-05-26 11:31:11 +00:00
|
|
|
|
await modfiles[3].Download.DeleteAsync();
|
2019-10-29 21:30:27 +00:00
|
|
|
|
|
2020-03-28 18:22:53 +00:00
|
|
|
|
await utils.Configure();
|
2020-02-05 05:17:12 +00:00
|
|
|
|
|
2020-03-28 18:22:53 +00:00
|
|
|
|
await modfiles[3].ModFolder.Combine("meta.ini").WriteAllLinesAsync(
|
2020-02-05 05:17:12 +00:00
|
|
|
|
"[General]",
|
2020-03-28 18:22:53 +00:00
|
|
|
|
$"matchAll= {modfiles[2].Download.FileName}"
|
|
|
|
|
);
|
2020-03-10 04:11:11 +00:00
|
|
|
|
|
2020-10-18 19:03:50 +00:00
|
|
|
|
await utils.SourcePath.Combine("startup.bat").WriteAllLinesAsync(
|
2020-03-10 04:11:11 +00:00
|
|
|
|
"ModOrganizer2.exe SKSE"
|
2020-03-28 18:22:53 +00:00
|
|
|
|
);
|
2020-02-05 05:17:12 +00:00
|
|
|
|
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
2020-03-28 18:22:53 +00:00
|
|
|
|
await CompileAndInstall(profile);
|
2020-05-25 17:34:25 +00:00
|
|
|
|
await utils.VerifyAllFiles();
|
2019-11-04 04:44:44 +00:00
|
|
|
|
|
2020-10-18 19:03:50 +00:00
|
|
|
|
await utils.InstallPath.Combine(Consts.LOOTFolderFilesDir).DeleteDirectory();
|
2019-11-04 04:36:25 +00:00
|
|
|
|
|
2019-11-24 00:30:51 +00:00
|
|
|
|
var compiler = new MO2Compiler(
|
2020-10-18 19:03:50 +00:00
|
|
|
|
sourcePath: utils.InstallPath,
|
|
|
|
|
downloadsPath: utils.DownloadsPath,
|
2019-11-24 00:30:51 +00:00
|
|
|
|
mo2Profile: profile,
|
2020-03-28 18:22:53 +00:00
|
|
|
|
outputFile: profile.RelativeTo(AbsolutePath.EntryPoint).WithExtension(Consts.ModListExtension));
|
|
|
|
|
Assert.True(await compiler.Begin());
|
2019-11-04 04:36:25 +00:00
|
|
|
|
|
2019-10-28 03:15:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 21:33:45 +00:00
|
|
|
|
private async Task<(AbsolutePath Download, AbsolutePath ModFolder)> DownloadAndInstall(string url, string filename, string modName = null)
|
2019-10-28 03:15:48 +00:00
|
|
|
|
{
|
2020-07-27 21:33:45 +00:00
|
|
|
|
if (modName != null)
|
|
|
|
|
await utils.AddMod(modName);
|
2020-03-28 18:22:53 +00:00
|
|
|
|
var src = _downloadFolder.Combine(filename);
|
|
|
|
|
if (!src.Exists)
|
2019-10-28 03:15:48 +00:00
|
|
|
|
{
|
|
|
|
|
var state = DownloadDispatcher.ResolveArchive(url);
|
2021-01-06 14:23:09 +00:00
|
|
|
|
await DownloadDispatcher.PrepareAll(new[] {state});
|
2020-04-10 01:29:53 +00:00
|
|
|
|
await state.Download(new Archive(state: null!) { Name = "Unknown"}, src);
|
2019-10-28 03:15:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-18 19:03:50 +00:00
|
|
|
|
utils.DownloadsPath.CreateDirectory();
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
2020-10-18 19:03:50 +00:00
|
|
|
|
var destFile = utils.DownloadsPath.Combine(filename);
|
2020-07-27 21:33:45 +00:00
|
|
|
|
await src.CopyToAsync(destFile);
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
2020-10-18 19:03:50 +00:00
|
|
|
|
var modFolder = modName == null ? utils.SourcePath : utils.ModsPath.Combine(modName);
|
2020-10-10 03:02:58 +00:00
|
|
|
|
await FileExtractor2.ExtractAll(Queue, src, modFolder);
|
2020-07-27 21:33:45 +00:00
|
|
|
|
return (destFile, modFolder);
|
2019-10-28 03:15:48 +00:00
|
|
|
|
}
|
2019-10-29 21:30:27 +00:00
|
|
|
|
|
2020-03-28 18:22:53 +00:00
|
|
|
|
private async Task<(AbsolutePath Download, AbsolutePath ModFolder)> DownloadAndInstall(Game game, int modId, string modName)
|
2019-10-29 21:30:27 +00:00
|
|
|
|
{
|
2020-05-25 17:34:25 +00:00
|
|
|
|
await utils.AddMod(modName);
|
2021-01-06 14:23:09 +00:00
|
|
|
|
var client = DownloadDispatcher.GetInstance<NexusDownloader>();
|
|
|
|
|
await client.Prepare();
|
|
|
|
|
|
|
|
|
|
var resp = await client.Client!.GetModFiles(game, modId);
|
2020-02-05 05:17:12 +00:00
|
|
|
|
var file = resp.files.FirstOrDefault(f => f.is_primary) ?? resp.files.FirstOrDefault(f => !string.IsNullOrEmpty(f.category_name));
|
|
|
|
|
|
2020-03-28 18:22:53 +00:00
|
|
|
|
var src = _downloadFolder.Combine(file.file_name);
|
2019-10-29 21:30:27 +00:00
|
|
|
|
|
|
|
|
|
var ini = string.Join("\n",
|
|
|
|
|
new List<string>
|
|
|
|
|
{
|
|
|
|
|
"[General]",
|
2019-12-09 22:46:03 +00:00
|
|
|
|
$"gameName={game.MetaData().MO2ArchiveName}",
|
2020-03-28 18:22:53 +00:00
|
|
|
|
$"modID={modId}",
|
2019-10-29 21:30:27 +00:00
|
|
|
|
$"fileID={file.file_id}"
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-28 18:22:53 +00:00
|
|
|
|
if (!src.Exists)
|
2019-10-29 21:30:27 +00:00
|
|
|
|
{
|
|
|
|
|
|
2019-12-13 21:48:40 +00:00
|
|
|
|
var state = (AbstractDownloadState)await DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
|
|
|
|
await state.Download(src);
|
2019-10-29 21:30:27 +00:00
|
|
|
|
}
|
2020-03-28 18:22:53 +00:00
|
|
|
|
|
2020-10-18 19:03:50 +00:00
|
|
|
|
utils.DownloadsPath.CreateDirectory();
|
2019-10-29 21:30:27 +00:00
|
|
|
|
|
2020-10-18 19:03:50 +00:00
|
|
|
|
var dest = utils.DownloadsPath.Combine(file.file_name);
|
2020-03-28 18:22:53 +00:00
|
|
|
|
await src.CopyToAsync(dest);
|
2019-10-29 21:30:27 +00:00
|
|
|
|
|
2020-10-18 19:03:50 +00:00
|
|
|
|
var modFolder = utils.ModsPath.Combine(modName);
|
2020-10-10 03:02:58 +00:00
|
|
|
|
await FileExtractor2.ExtractAll(Queue, src, modFolder);
|
2020-09-06 03:19:05 +00:00
|
|
|
|
|
2020-03-28 18:22:53 +00:00
|
|
|
|
await dest.WithExtension(Consts.MetaFileExtension).WriteAllTextAsync(ini);
|
2020-02-05 05:17:12 +00:00
|
|
|
|
return (dest, modFolder);
|
2019-10-29 21:30:27 +00:00
|
|
|
|
}
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
2019-12-07 02:54:27 +00:00
|
|
|
|
private async Task<ModList> CompileAndInstall(string profile)
|
2019-10-28 03:15:48 +00:00
|
|
|
|
{
|
2019-12-07 02:54:27 +00:00
|
|
|
|
var compiler = await ConfigureAndRunCompiler(profile);
|
2019-12-13 13:02:58 +00:00
|
|
|
|
await Install(compiler);
|
2019-10-28 03:15:48 +00:00
|
|
|
|
return compiler.ModList;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-13 13:02:58 +00:00
|
|
|
|
private async Task Install(MO2Compiler compiler)
|
2019-10-28 03:15:48 +00:00
|
|
|
|
{
|
2019-11-21 15:05:10 +00:00
|
|
|
|
var modlist = AInstaller.LoadFromFile(compiler.ModListOutputFile);
|
2019-12-01 20:22:33 +00:00
|
|
|
|
var installer = new MO2Installer(
|
|
|
|
|
archive: compiler.ModListOutputFile,
|
|
|
|
|
modList: modlist,
|
2020-10-18 19:03:50 +00:00
|
|
|
|
outputFolder: utils.InstallPath,
|
|
|
|
|
downloadFolder: utils.DownloadsPath,
|
2020-08-05 22:01:45 +00:00
|
|
|
|
parameters: ACompilerTest.CreateDummySystemParameters())
|
|
|
|
|
{
|
|
|
|
|
UseCompression = true
|
|
|
|
|
};
|
2019-10-28 03:15:48 +00:00
|
|
|
|
installer.GameFolder = utils.GameFolder;
|
2019-12-13 13:02:58 +00:00
|
|
|
|
await installer.Begin();
|
2019-10-28 03:15:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-07 02:54:27 +00:00
|
|
|
|
private async Task<MO2Compiler> ConfigureAndRunCompiler(string profile)
|
2019-10-28 03:15:48 +00:00
|
|
|
|
{
|
2019-11-24 00:30:51 +00:00
|
|
|
|
var compiler = new MO2Compiler(
|
2020-10-18 19:03:50 +00:00
|
|
|
|
sourcePath: utils.SourcePath,
|
|
|
|
|
downloadsPath: utils.DownloadsPath,
|
2019-11-24 00:30:51 +00:00
|
|
|
|
mo2Profile: profile,
|
2020-03-28 18:22:53 +00:00
|
|
|
|
outputFile: profile.RelativeTo(AbsolutePath.EntryPoint).WithExtension(Consts.ModListExtension));
|
|
|
|
|
Assert.True(await compiler.Begin());
|
2019-10-28 03:15:48 +00:00
|
|
|
|
return compiler;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|