wabbajack/Wabbajack.Test/ACompilerTest.cs

89 lines
2.8 KiB
C#
Raw Normal View History

using System;
2019-12-07 02:54:27 +00:00
using System.Threading.Tasks;
using Wabbajack.Common;
using Wabbajack.Lib;
2019-12-07 17:39:22 +00:00
using Wabbajack.Lib.LibCefHelpers;
2020-03-26 21:15:44 +00:00
using Xunit;
using Xunit.Abstractions;
namespace Wabbajack.Test
{
2020-03-29 20:42:45 +00:00
public abstract class ACompilerTest : XunitContextBase, IDisposable
{
2020-03-29 20:42:45 +00:00
private IDisposable _unsub;
protected TestUtils utils { get; set; }
2020-03-29 20:42:45 +00:00
public ACompilerTest(ITestOutputHelper helper) : base (helper)
{
Helpers.Init();
Consts.TestMode = true;
utils = new TestUtils();
2019-11-16 22:02:36 +00:00
utils.Game = Game.SkyrimSpecialEdition;
2020-03-28 02:54:14 +00:00
DateTime startTime = DateTime.Now;
2020-03-29 20:42:45 +00:00
_unsub = Utils.LogMessages.Subscribe(f => XunitContext.WriteLine($"{DateTime.Now - startTime} - {f.ShortDescription}"));
}
2020-03-29 20:42:45 +00:00
public override void Dispose()
{
utils.DisposeAsync().AsTask().Wait();
2020-03-29 20:42:45 +00:00
_unsub.Dispose();
base.Dispose();
}
2019-12-07 02:54:27 +00:00
protected async Task<MO2Compiler> ConfigureAndRunCompiler(string profile)
{
var compiler = new MO2Compiler(
mo2Folder: utils.MO2Folder,
mo2Profile: profile,
2020-03-26 21:15:44 +00:00
outputFile: OutputFile(profile));
Assert.True(await compiler.Begin());
return compiler;
}
2019-12-07 02:54:27 +00:00
protected async Task<ModList> CompileAndInstall(string profile)
2019-11-02 15:38:03 +00:00
{
2019-12-07 02:54:27 +00:00
var compiler = await ConfigureAndRunCompiler(profile);
2020-03-28 02:54:14 +00:00
Utils.Log("Finished Compiling");
2019-12-22 00:26:51 +00:00
await Install(compiler);
2019-11-02 15:38:03 +00:00
return compiler.ModList;
}
2020-03-26 21:15:44 +00:00
private static AbsolutePath OutputFile(string profile)
{
return ((RelativePath)profile).RelativeToEntryPoint().WithExtension(Consts.ModListExtension);
}
2019-12-22 00:26:51 +00:00
protected async Task Install(MO2Compiler compiler)
2019-11-02 15:38:03 +00:00
{
2020-03-29 03:29:27 +00:00
Utils.Log("Loading Modlist");
2019-11-21 15:05:10 +00:00
var modlist = AInstaller.LoadFromFile(compiler.ModListOutputFile);
2020-03-29 03:29:27 +00:00
Utils.Log("Constructing Installer");
var installer = new MO2Installer(
archive: compiler.ModListOutputFile,
modList: modlist,
outputFolder: utils.InstallFolder,
2020-01-07 13:50:11 +00:00
downloadFolder: utils.DownloadsFolder,
2020-03-26 21:15:44 +00:00
parameters: CreateDummySystemParameters());
installer.WarnOnOverwrite = false;
2019-11-02 15:38:03 +00:00
installer.GameFolder = utils.GameFolder;
2020-03-29 03:29:27 +00:00
Utils.Log("Starting Install");
2019-12-22 00:26:51 +00:00
await installer.Begin();
2019-11-02 15:38:03 +00:00
}
2020-03-26 21:15:44 +00:00
2020-03-28 18:22:53 +00:00
public static SystemParameters CreateDummySystemParameters()
2020-03-26 21:15:44 +00:00
{
return new SystemParameters
{
WindowsVersion = new Version("6.2.4.0"),
ScreenWidth = 1920,
ScreenHeight = 1080,
SystemMemorySize = 16 * 1024 * 1040,
VideoMemorySize = 4 * 1024 * 1024
};
}
}
}