2022-07-12 13:03:02 +00:00
|
|
|
using System;
|
|
|
|
using System.CommandLine;
|
2022-09-29 05:10:49 +00:00
|
|
|
using System.CommandLine.NamingConventionBinder;
|
2022-07-12 13:03:02 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2022-10-14 22:08:21 +00:00
|
|
|
using Wabbajack.CLI.Builder;
|
2022-07-12 13:03:02 +00:00
|
|
|
using Wabbajack.Compiler;
|
|
|
|
using Wabbajack.Downloaders;
|
|
|
|
using Wabbajack.Downloaders.GameFile;
|
|
|
|
using Wabbajack.DTOs.JsonConverters;
|
|
|
|
using Wabbajack.Networking.WabbajackClientApi;
|
|
|
|
using Wabbajack.Paths;
|
2023-11-15 03:19:53 +00:00
|
|
|
using Wabbajack.Paths.IO;
|
2022-07-12 13:03:02 +00:00
|
|
|
using Wabbajack.VFS;
|
|
|
|
|
|
|
|
namespace Wabbajack.CLI.Verbs;
|
|
|
|
|
2022-10-14 22:08:21 +00:00
|
|
|
public class Compile
|
2022-07-12 13:03:02 +00:00
|
|
|
{
|
|
|
|
private readonly ILogger<Compile> _logger;
|
|
|
|
private readonly Client _wjClient;
|
|
|
|
private readonly DownloadDispatcher _dispatcher;
|
|
|
|
private readonly DTOSerializer _dtos;
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly FileHashCache _cache;
|
|
|
|
private readonly GameLocator _gameLocator;
|
|
|
|
private readonly CompilerSettingsInferencer _inferencer;
|
|
|
|
|
|
|
|
public Compile(ILogger<Compile> logger, Client wjClient, DownloadDispatcher dispatcher, DTOSerializer dtos,
|
|
|
|
FileHashCache cache, GameLocator gameLocator, IServiceProvider serviceProvider, CompilerSettingsInferencer inferencer)
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_wjClient = wjClient;
|
|
|
|
_dispatcher = dispatcher;
|
|
|
|
_dtos = dtos;
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
_cache = cache;
|
|
|
|
_gameLocator = gameLocator;
|
|
|
|
_inferencer = inferencer;
|
|
|
|
}
|
|
|
|
|
2022-10-01 01:35:36 +00:00
|
|
|
public static VerbDefinition Definition = new("compile", "Compiles a modlist",
|
|
|
|
new[]
|
2022-07-12 13:03:02 +00:00
|
|
|
{
|
2022-10-01 01:35:36 +00:00
|
|
|
new OptionDefinition(typeof(AbsolutePath), "i", "installPath", "Install Path"),
|
|
|
|
new OptionDefinition(typeof(AbsolutePath), "o", "outputPath", "OutputPath")
|
|
|
|
});
|
2022-07-12 13:03:02 +00:00
|
|
|
public async Task<int> Run(AbsolutePath installPath, AbsolutePath outputPath,
|
|
|
|
CancellationToken token)
|
|
|
|
{
|
|
|
|
_logger.LogInformation("Inferring settings");
|
|
|
|
var inferredSettings = await _inferencer.InferFromRootPath(installPath);
|
|
|
|
if (inferredSettings == null)
|
|
|
|
{
|
|
|
|
_logger.LogInformation("Error inferencing settings");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
inferredSettings.UseGamePaths = true;
|
|
|
|
|
2023-11-15 03:19:53 +00:00
|
|
|
if(outputPath.DirectoryExists())
|
|
|
|
{
|
|
|
|
inferredSettings.OutputFile = outputPath.Combine(inferredSettings.OutputFile.FileName);
|
|
|
|
_logger.LogInformation("Output file will be in: {outputPath}", inferredSettings.OutputFile);
|
|
|
|
}
|
|
|
|
|
2022-07-12 13:03:02 +00:00
|
|
|
var compiler = MO2Compiler.Create(_serviceProvider, inferredSettings);
|
|
|
|
var result = await compiler.Begin(token);
|
|
|
|
if (!result)
|
|
|
|
return result ? 0 : 3;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|