wabbajack/Wabbajack.Test/ACompilerTest.cs

113 lines
4.0 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-06-01 20:26:03 +00:00
public abstract class ACompilerTest : XunitContextBase, IAsyncDisposable
{
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-06-01 20:26:03 +00:00
public async ValueTask DisposeAsync()
{
2020-06-01 20:26:03 +00:00
await utils.DisposeAsync();
2020-03-29 20:42:45 +00:00
_unsub.Dispose();
base.Dispose();
}
protected async Task<MO2Compiler> ConfigureAndRunCompiler(string profile, bool useGameFiles= false)
{
var compiler = new MO2Compiler(
2020-10-18 19:03:50 +00:00
sourcePath: utils.SourcePath,
downloadsPath: utils.DownloadsPath,
mo2Profile: profile,
2020-03-26 21:15:44 +00:00
outputFile: OutputFile(profile));
compiler.UseGamePaths = useGameFiles;
2020-03-26 21:15:44 +00:00
Assert.True(await compiler.Begin());
return compiler;
}
protected async Task<ModList> CompileAndInstall(string profile, bool useGameFiles = false)
2019-11-02 15:38:03 +00:00
{
var compiler = await ConfigureAndRunCompiler(profile, useGameFiles: useGameFiles);
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-10-18 19:03:50 +00:00
protected async Task<NativeCompiler> ConfigureAndRunCompiler(AbsolutePath configPath, bool useGameFiles= false)
{
var settings = configPath.FromJson<NativeCompilerSettings>();
var profile = utils.AddProfile();
var compiler = new NativeCompiler(
settings: settings,
sourcePath: utils.SourcePath,
downloadsPath: utils.DownloadsPath,
outputModListPath: OutputFile(profile))
{UseGamePaths = useGameFiles};
Assert.True(await compiler.Begin());
return compiler;
}
protected async Task<ModList> CompileAndInstall(AbsolutePath settingsPath, bool useGameFiles = false)
{
var compiler = await ConfigureAndRunCompiler(settingsPath, useGameFiles: useGameFiles);
Utils.Log("Finished Compiling");
await Install(compiler);
return compiler.ModList;
}
2019-11-02 15:38:03 +00:00
2020-03-26 21:15:44 +00:00
private static AbsolutePath OutputFile(string profile)
{
return ((RelativePath)profile).RelativeToEntryPoint().WithExtension(Consts.ModListExtension);
}
2020-10-18 19:03:50 +00:00
protected async Task Install(ACompiler 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,
2020-10-18 19:03:50 +00:00
outputFolder: utils.InstallPath,
downloadFolder: utils.DownloadsPath,
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
};
}
}
}