2019-10-31 02:24:42 +00:00
|
|
|
|
using System;
|
2019-12-07 02:54:27 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-10-31 02:24:42 +00:00
|
|
|
|
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;
|
2019-10-31 02:24:42 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Test
|
|
|
|
|
{
|
2020-06-01 20:26:03 +00:00
|
|
|
|
public abstract class ACompilerTest : XunitContextBase, IAsyncDisposable
|
2019-10-31 02:24:42 +00:00
|
|
|
|
{
|
2020-03-29 20:42:45 +00:00
|
|
|
|
private IDisposable _unsub;
|
2019-10-31 02:24:42 +00:00
|
|
|
|
protected TestUtils utils { get; set; }
|
|
|
|
|
|
2020-03-29 20:42:45 +00:00
|
|
|
|
public ACompilerTest(ITestOutputHelper helper) : base (helper)
|
2019-10-31 02:24:42 +00:00
|
|
|
|
{
|
2019-12-27 00:41:33 +00:00
|
|
|
|
Helpers.Init();
|
2019-10-31 02:24:42 +00:00
|
|
|
|
Consts.TestMode = true;
|
|
|
|
|
|
|
|
|
|
utils = new TestUtils();
|
2019-11-16 22:02:36 +00:00
|
|
|
|
utils.Game = Game.SkyrimSpecialEdition;
|
2019-10-31 02:24:42 +00:00
|
|
|
|
|
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}"));
|
2019-10-31 02:24:42 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-01 20:26:03 +00:00
|
|
|
|
public async ValueTask DisposeAsync()
|
2019-10-31 02:24:42 +00:00
|
|
|
|
{
|
2020-06-01 20:26:03 +00:00
|
|
|
|
await utils.DisposeAsync();
|
2020-03-29 20:42:45 +00:00
|
|
|
|
_unsub.Dispose();
|
|
|
|
|
base.Dispose();
|
2019-10-31 02:24:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-02 02:18:32 +00:00
|
|
|
|
protected async Task<MO2Compiler> ConfigureAndRunCompiler(string profile, bool useGameFiles= false)
|
2019-10-31 02:24:42 +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-26 21:15:44 +00:00
|
|
|
|
outputFile: OutputFile(profile));
|
2020-06-02 02:18:32 +00:00
|
|
|
|
compiler.UseGamePaths = useGameFiles;
|
2020-03-26 21:15:44 +00:00
|
|
|
|
Assert.True(await compiler.Begin());
|
2019-10-31 02:24:42 +00:00
|
|
|
|
return compiler;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-02 02:18:32 +00:00
|
|
|
|
protected async Task<ModList> CompileAndInstall(string profile, bool useGameFiles = false)
|
2019-11-02 15:38:03 +00:00
|
|
|
|
{
|
2020-06-02 02:18:32 +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");
|
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-03-26 21:15:44 +00:00
|
|
|
|
parameters: CreateDummySystemParameters());
|
2019-11-18 05:21:24 +00:00
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
}
|
2019-10-31 02:24:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|