mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Add install command
This commit is contained in:
parent
97c14f6a7a
commit
c72335d4f0
@ -7,6 +7,9 @@ using System.Text.Json;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
using NLog.Targets;
|
||||||
using Octokit;
|
using Octokit;
|
||||||
using Wabbajack.CLI.TypeConverters;
|
using Wabbajack.CLI.TypeConverters;
|
||||||
using Wabbajack.CLI.Verbs;
|
using Wabbajack.CLI.Verbs;
|
||||||
@ -34,6 +37,7 @@ internal class Program
|
|||||||
new TypeConverterAttribute(typeof(ModListCategoryConverter)));
|
new TypeConverterAttribute(typeof(ModListCategoryConverter)));
|
||||||
|
|
||||||
var host = Host.CreateDefaultBuilder(Array.Empty<string>())
|
var host = Host.CreateDefaultBuilder(Array.Empty<string>())
|
||||||
|
.ConfigureLogging(SetupLogging)
|
||||||
.ConfigureServices((host, services) =>
|
.ConfigureServices((host, services) =>
|
||||||
{
|
{
|
||||||
services.AddSingleton(new JsonSerializerOptions());
|
services.AddSingleton(new JsonSerializerOptions());
|
||||||
@ -68,13 +72,41 @@ internal class Program
|
|||||||
services.AddSingleton<IVerb, SteamAppDumpInfo>();
|
services.AddSingleton<IVerb, SteamAppDumpInfo>();
|
||||||
services.AddSingleton<IVerb, SteamDownloadFile>();
|
services.AddSingleton<IVerb, SteamDownloadFile>();
|
||||||
services.AddSingleton<IVerb, UploadToNexus>();
|
services.AddSingleton<IVerb, UploadToNexus>();
|
||||||
|
services.AddSingleton<IVerb, Install>();
|
||||||
services.AddSingleton<IVerb, ListCreationClubContent>();
|
services.AddSingleton<IVerb, ListCreationClubContent>();
|
||||||
services.AddSingleton<IVerb, Extract>();
|
services.AddSingleton<IVerb, Extract>();
|
||||||
|
|
||||||
services.AddSingleton<IUserInterventionHandler, UserInterventionHandler>();
|
services.AddSingleton<IUserInterventionHandler, UserInterventionHandler>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}).Build();
|
}).Build();
|
||||||
|
|
||||||
var service = host.Services.GetService<CommandLineBuilder>();
|
var service = host.Services.GetService<CommandLineBuilder>();
|
||||||
return await service!.Run(args);
|
return await service!.Run(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void SetupLogging(ILoggingBuilder loggingBuilder)
|
||||||
|
{
|
||||||
|
var config = new NLog.Config.LoggingConfiguration();
|
||||||
|
|
||||||
|
var fileTarget = new FileTarget("file")
|
||||||
|
{
|
||||||
|
FileName = "logs/wabbajack-cli.current.log",
|
||||||
|
ArchiveFileName = "logs/wabbajack-cli.{##}.log",
|
||||||
|
ArchiveOldFileOnStartup = true,
|
||||||
|
MaxArchiveFiles = 10,
|
||||||
|
Layout = "${processtime} [${level:uppercase=true}] (${logger}) ${message:withexception=true}",
|
||||||
|
Header = "############ Wabbajack log file - ${longdate} ############"
|
||||||
|
};
|
||||||
|
|
||||||
|
var consoleTarget = new ConsoleTarget("console");
|
||||||
|
|
||||||
|
config.AddRuleForAllLevels(fileTarget);
|
||||||
|
config.AddRuleForAllLevels(consoleTarget);
|
||||||
|
|
||||||
|
loggingBuilder.ClearProviders();
|
||||||
|
loggingBuilder.SetMinimumLevel(LogLevel.Trace);
|
||||||
|
loggingBuilder.AddNLog(config);
|
||||||
|
}
|
||||||
}
|
}
|
111
Wabbajack.CLI/Verbs/Install.cs
Normal file
111
Wabbajack.CLI/Verbs/Install.cs
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
using System;
|
||||||
|
using System.CommandLine;
|
||||||
|
using System.CommandLine.Invocation;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Wabbajack.Downloaders;
|
||||||
|
using Wabbajack.Downloaders.GameFile;
|
||||||
|
using Wabbajack.DTOs;
|
||||||
|
using Wabbajack.DTOs.JsonConverters;
|
||||||
|
using Wabbajack.Installer;
|
||||||
|
using Wabbajack.Networking.WabbajackClientApi;
|
||||||
|
using Wabbajack.Paths;
|
||||||
|
|
||||||
|
namespace Wabbajack.CLI.Verbs;
|
||||||
|
|
||||||
|
public class Install : IVerb
|
||||||
|
{
|
||||||
|
private readonly ILogger<Install> _logger;
|
||||||
|
private readonly DownloadDispatcher _dispatcher;
|
||||||
|
private readonly Client _wjClient;
|
||||||
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
private readonly DTOSerializer _dtos;
|
||||||
|
private readonly GameLocator _gameLocator;
|
||||||
|
|
||||||
|
public Install(ILogger<Install> logger, DownloadDispatcher dispatcher, Client wjClient, IServiceProvider serviceProvider,
|
||||||
|
DTOSerializer dtos, GameLocator gameLocator)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_dispatcher = dispatcher;
|
||||||
|
_wjClient = wjClient;
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
|
_dtos = dtos;
|
||||||
|
_gameLocator = gameLocator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command MakeCommand()
|
||||||
|
{
|
||||||
|
var command = new Command("install");
|
||||||
|
command.Add(new Option<string>(new[] {"-m", "-machineUrl"}, "MachineURL to download and install"));
|
||||||
|
command.Add(new Option<AbsolutePath>(new[] {"-i", "-inputModlist"}, "Input modlist to install"));
|
||||||
|
command.Add(new Option<AbsolutePath>(new[] {"-d", "-downloads"}, "Downloads Folder"));
|
||||||
|
command.Add(new Option<AbsolutePath>(new[] {"-o", "-output"}, "Install output Folder"));
|
||||||
|
command.Description = "Installs a modlist";
|
||||||
|
command.Handler = CommandHandler.Create(Run);
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<int> Run(CancellationToken token, AbsolutePath inputModlist, string machineUrl, AbsolutePath downloads, AbsolutePath output)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(machineUrl) && inputModlist == default)
|
||||||
|
{
|
||||||
|
_logger.LogError("Need either a inputModlist or a machineUrl");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(machineUrl))
|
||||||
|
{
|
||||||
|
|
||||||
|
var list = (await _wjClient.LoadLists())
|
||||||
|
.FirstOrDefault(l => l.Links.MachineURL == machineUrl);
|
||||||
|
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogError("Cannot find list with machineUrl");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
inputModlist = downloads.Combine($"{machineUrl}_modlist.wabbajack");
|
||||||
|
var hash = await _dispatcher.Download(new Archive
|
||||||
|
{
|
||||||
|
Hash = list.DownloadMetadata!.Hash,
|
||||||
|
Size = list.DownloadMetadata.Size,
|
||||||
|
Name = list.Title,
|
||||||
|
State = _dispatcher.Parse(new Uri(list.Links.Download))!
|
||||||
|
}, inputModlist, token);
|
||||||
|
if (hash != list.DownloadMetadata.Hash)
|
||||||
|
_logger.LogError($"Downloaded hash ({hash}) did not match expected hash ({list.DownloadMetadata.Hash}).");
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Loading Modlist");
|
||||||
|
var modlist = await StandardInstaller.LoadFromFile(_dtos, inputModlist);
|
||||||
|
|
||||||
|
var installer = StandardInstaller.Create(_serviceProvider, new InstallerConfiguration
|
||||||
|
{
|
||||||
|
Game = modlist.GameType,
|
||||||
|
Downloads = downloads,
|
||||||
|
Install = output,
|
||||||
|
ModList = modlist,
|
||||||
|
ModlistArchive = inputModlist,
|
||||||
|
SystemParameters = new SystemParameters()
|
||||||
|
{
|
||||||
|
ScreenWidth = 1920,
|
||||||
|
ScreenHeight = 1080,
|
||||||
|
SystemMemorySize = 16_000_000,
|
||||||
|
SystemPageSize = 16_000_000,
|
||||||
|
VideoMemorySize = 8_000_000
|
||||||
|
},
|
||||||
|
GameFolder = _gameLocator.GameLocation(modlist.GameType)
|
||||||
|
});
|
||||||
|
var result = await installer.Begin(token);
|
||||||
|
if (result)
|
||||||
|
_logger.LogInformation("Modlist installed, enjoy!");
|
||||||
|
else
|
||||||
|
_logger.LogInformation("Modlist install error!");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.2-mauipre.1.22054.8" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.2-mauipre.1.22054.8" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.2-mauipre.1.22054.8" />
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.2-mauipre.1.22054.8" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2-mauipre.1.22054.8" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2-mauipre.1.22054.8" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.0.0-rc2" />
|
||||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21561.1" />
|
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21561.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ public class DownloaderTests
|
|||||||
Game = Game.SkyrimSpecialEdition,
|
Game = Game.SkyrimSpecialEdition,
|
||||||
IsCCMod = true,
|
IsCCMod = true,
|
||||||
ProductId = 4,
|
ProductId = 4,
|
||||||
BranchID = 90898,
|
BranchId = 90898,
|
||||||
ContentId = "4059054"
|
ContentId = "4059054"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -204,7 +204,7 @@ public class DownloaderTests
|
|||||||
Game = Game.SkyrimSpecialEdition,
|
Game = Game.SkyrimSpecialEdition,
|
||||||
IsCCMod = true,
|
IsCCMod = true,
|
||||||
ProductId = 6,
|
ProductId = 6,
|
||||||
BranchID = 9898,
|
BranchId = 9898,
|
||||||
ContentId = "059054"
|
ContentId = "059054"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user