2019-10-28 03:15:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
2019-10-29 21:30:27 +00:00
|
|
|
|
using Wabbajack.Lib.NexusApi;
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Test
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class EndToEndTests
|
|
|
|
|
{
|
|
|
|
|
private const string DOWNLOAD_FOLDER = "downloads";
|
|
|
|
|
|
|
|
|
|
private TestUtils utils = new TestUtils();
|
|
|
|
|
|
|
|
|
|
public TestContext TestContext { get; set; }
|
|
|
|
|
|
2019-11-17 04:16:42 +00:00
|
|
|
|
public WorkQueue Queue { get; set; }
|
|
|
|
|
|
2019-10-28 03:15:48 +00:00
|
|
|
|
[TestInitialize]
|
|
|
|
|
public void TestInitialize()
|
|
|
|
|
{
|
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
|
|
|
|
|
2019-11-05 04:14:31 +00:00
|
|
|
|
Utils.LogMessages.Subscribe(f => TestContext.WriteLine(f));
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(DOWNLOAD_FOLDER))
|
|
|
|
|
Directory.CreateDirectory(DOWNLOAD_FOLDER);
|
2019-11-17 04:16:42 +00:00
|
|
|
|
}
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
2019-11-17 04:16:42 +00:00
|
|
|
|
[TestCleanup]
|
|
|
|
|
public void Cleanup()
|
|
|
|
|
{
|
|
|
|
|
Queue.Shutdown();
|
2019-10-28 03:15:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void CreateModlist()
|
|
|
|
|
{
|
|
|
|
|
var profile = utils.AddProfile("Default");
|
|
|
|
|
var mod = utils.AddMod();
|
|
|
|
|
|
|
|
|
|
DownloadAndInstall(
|
|
|
|
|
"https://github.com/ModOrganizer2/modorganizer/releases/download/v2.2.1/Mod.Organizer.2.2.1.7z",
|
|
|
|
|
"Mod.Organizer.2.2.1.7z",
|
|
|
|
|
utils.MO2Folder);
|
|
|
|
|
File.WriteAllLines(Path.Combine(utils.DownloadsFolder, "Mod.Organizer.2.2.1.7z.meta"),
|
|
|
|
|
new List<string>
|
|
|
|
|
{
|
|
|
|
|
"[General]",
|
|
|
|
|
"directURL=https://github.com/ModOrganizer2/modorganizer/releases/download/v2.2.1/Mod.Organizer.2.2.1.7z"
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-29 21:30:27 +00:00
|
|
|
|
DownloadAndInstall(Game.SkyrimSpecialEdition, 12604, "SkyUI");
|
|
|
|
|
|
2019-10-28 03:15:48 +00:00
|
|
|
|
utils.Configure();
|
|
|
|
|
|
|
|
|
|
var modlist = CompileAndInstall(profile);
|
|
|
|
|
|
2019-10-29 21:30:27 +00:00
|
|
|
|
utils.VerifyAllFiles();
|
2019-11-04 04:44:44 +00:00
|
|
|
|
|
|
|
|
|
var loot_folder = Path.Combine(utils.InstallFolder, "LOOT Config Files");
|
|
|
|
|
if (Directory.Exists(loot_folder))
|
2019-11-23 17:37:24 +00:00
|
|
|
|
Utils.DeleteDirectory(loot_folder);
|
2019-11-04 04:36:25 +00:00
|
|
|
|
|
2019-11-18 00:17:06 +00:00
|
|
|
|
var compiler = new MO2Compiler(utils.InstallFolder);
|
2019-11-04 04:36:25 +00:00
|
|
|
|
compiler.MO2DownloadsFolder = Path.Combine(utils.DownloadsFolder);
|
|
|
|
|
compiler.MO2Profile = profile;
|
|
|
|
|
compiler.ShowReportWhenFinished = false;
|
2019-11-17 23:48:32 +00:00
|
|
|
|
Assert.IsTrue(compiler.Begin().Result);
|
2019-11-04 04:36:25 +00:00
|
|
|
|
|
2019-10-28 03:15:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DownloadAndInstall(string url, string filename, string mod_name = null)
|
|
|
|
|
{
|
|
|
|
|
var src = Path.Combine(DOWNLOAD_FOLDER, filename);
|
|
|
|
|
if (!File.Exists(src))
|
|
|
|
|
{
|
|
|
|
|
var state = DownloadDispatcher.ResolveArchive(url);
|
|
|
|
|
state.Download(new Archive() { Name = "Unknown"}, src);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(utils.DownloadsFolder))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(utils.DownloadsFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File.Copy(src, Path.Combine(utils.DownloadsFolder, filename));
|
|
|
|
|
|
2019-11-17 04:16:42 +00:00
|
|
|
|
FileExtractor.ExtractAll(Queue, src,
|
|
|
|
|
mod_name == null ? utils.MO2Folder : Path.Combine(utils.ModsFolder, mod_name));
|
2019-10-28 03:15:48 +00:00
|
|
|
|
}
|
2019-10-29 21:30:27 +00:00
|
|
|
|
|
|
|
|
|
private void DownloadAndInstall(Game game, int modid, string mod_name)
|
|
|
|
|
{
|
|
|
|
|
utils.AddMod(mod_name);
|
|
|
|
|
var client = new NexusApiClient();
|
2019-11-22 05:19:42 +00:00
|
|
|
|
var file = client.GetModFiles(game, modid).files.First(f => f.is_primary);
|
2019-10-29 21:30:27 +00:00
|
|
|
|
var src = Path.Combine(DOWNLOAD_FOLDER, file.file_name);
|
|
|
|
|
|
|
|
|
|
var ini = string.Join("\n",
|
|
|
|
|
new List<string>
|
|
|
|
|
{
|
|
|
|
|
"[General]",
|
|
|
|
|
$"gameName={GameRegistry.Games[game].MO2ArchiveName}",
|
|
|
|
|
$"modID={modid}",
|
|
|
|
|
$"fileID={file.file_id}"
|
|
|
|
|
});
|
|
|
|
|
|
2019-11-11 06:15:52 +00:00
|
|
|
|
if (!File.Exists(src))
|
2019-10-29 21:30:27 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var state = DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
|
|
|
|
state.Download(src);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(utils.DownloadsFolder))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(utils.DownloadsFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dest = Path.Combine(utils.DownloadsFolder, file.file_name);
|
|
|
|
|
File.Copy(src, dest);
|
|
|
|
|
|
2019-11-17 04:16:42 +00:00
|
|
|
|
FileExtractor.ExtractAll(Queue, src, Path.Combine(utils.ModsFolder, mod_name));
|
2019-10-29 21:30:27 +00:00
|
|
|
|
|
|
|
|
|
File.WriteAllText(dest + ".meta", ini);
|
|
|
|
|
}
|
2019-10-28 03:15:48 +00:00
|
|
|
|
|
|
|
|
|
private ModList CompileAndInstall(string profile)
|
|
|
|
|
{
|
|
|
|
|
var compiler = ConfigureAndRunCompiler(profile);
|
|
|
|
|
Install(compiler);
|
|
|
|
|
return compiler.ModList;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-18 00:17:06 +00:00
|
|
|
|
private void 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-11-18 00:17:06 +00:00
|
|
|
|
var installer = new MO2Installer(compiler.ModListOutputFile, modlist, utils.InstallFolder);
|
2019-10-28 03:15:48 +00:00
|
|
|
|
installer.DownloadFolder = utils.DownloadsFolder;
|
|
|
|
|
installer.GameFolder = utils.GameFolder;
|
2019-11-17 23:48:32 +00:00
|
|
|
|
installer.Begin().Wait();
|
2019-10-28 03:15:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-18 00:17:06 +00:00
|
|
|
|
private MO2Compiler ConfigureAndRunCompiler(string profile)
|
2019-10-28 03:15:48 +00:00
|
|
|
|
{
|
2019-11-18 00:17:06 +00:00
|
|
|
|
var compiler = new MO2Compiler(utils.MO2Folder);
|
2019-10-28 03:15:48 +00:00
|
|
|
|
compiler.MO2Profile = profile;
|
|
|
|
|
compiler.ShowReportWhenFinished = false;
|
2019-11-17 23:48:32 +00:00
|
|
|
|
Assert.IsTrue(compiler.Begin().Result);
|
2019-10-28 03:15:48 +00:00
|
|
|
|
return compiler;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|