2022-01-15 06:29:44 +00:00
|
|
|
|
using System;
|
2022-01-27 07:55:07 +00:00
|
|
|
|
using System.Collections.Generic;
|
2022-01-16 13:46:16 +00:00
|
|
|
|
using System.Threading;
|
2022-01-15 06:29:44 +00:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Wabbajack.DTOs;
|
|
|
|
|
using Wabbajack.DTOs.JsonConverters;
|
|
|
|
|
using Wabbajack.Installer;
|
|
|
|
|
using Wabbajack.Paths;
|
2022-01-16 13:46:16 +00:00
|
|
|
|
using Wabbajack.App.Blazor.Utility;
|
2022-01-16 17:38:54 +00:00
|
|
|
|
using Wabbajack.Downloaders.GameFile;
|
|
|
|
|
using Wabbajack.Hashing.xxHash64;
|
|
|
|
|
using Wabbajack.Services.OSIntegrated;
|
2022-01-17 16:45:52 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2022-01-21 13:41:37 +00:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.JSInterop;
|
2022-01-20 08:34:38 +00:00
|
|
|
|
using Wabbajack.App.Blazor.State;
|
2022-01-15 06:29:44 +00:00
|
|
|
|
|
2022-01-20 08:34:38 +00:00
|
|
|
|
namespace Wabbajack.App.Blazor.Pages;
|
|
|
|
|
|
2022-01-27 07:55:07 +00:00
|
|
|
|
public partial class Installing
|
2022-01-15 06:29:44 +00:00
|
|
|
|
{
|
2022-01-21 13:41:37 +00:00
|
|
|
|
[Inject] private ILogger<Configure> Logger { get; set; } = default!;
|
|
|
|
|
[Inject] private IStateContainer StateContainer { get; set; } = default!;
|
|
|
|
|
[Inject] private DTOSerializer DTOs { get; set; } = default!;
|
|
|
|
|
[Inject] private IServiceProvider ServiceProvider { get; set; } = default!;
|
|
|
|
|
[Inject] private SystemParametersConstructor ParametersConstructor { get; set; } = default!;
|
|
|
|
|
[Inject] private IGameLocator GameLocator { get; set; } = default!;
|
|
|
|
|
[Inject] private SettingsManager SettingsManager { get; set; } = default!;
|
2022-01-21 14:44:05 +00:00
|
|
|
|
[Inject] private IJSRuntime JSRuntime { get; set; } = default!;
|
2022-01-21 13:41:37 +00:00
|
|
|
|
|
2022-01-27 07:55:07 +00:00
|
|
|
|
private ModList? Modlist => StateContainer.Modlist;
|
|
|
|
|
private string ModlistImage => StateContainer.ModlistImage;
|
2022-01-21 13:41:37 +00:00
|
|
|
|
private AbsolutePath ModlistPath => StateContainer.ModlistPath;
|
2022-01-27 07:55:07 +00:00
|
|
|
|
private AbsolutePath InstallPath => StateContainer.InstallPath;
|
|
|
|
|
private AbsolutePath DownloadPath => StateContainer.DownloadPath;
|
|
|
|
|
|
|
|
|
|
public string StatusCategory { get; set; }
|
|
|
|
|
|
|
|
|
|
private string LastStatus { get; set; }
|
|
|
|
|
|
|
|
|
|
public List<string> StatusStep { get; set; } = new();
|
2022-01-20 08:34:38 +00:00
|
|
|
|
|
2022-01-21 13:41:37 +00:00
|
|
|
|
private InstallState InstallState => StateContainer.InstallState;
|
2022-01-20 08:34:38 +00:00
|
|
|
|
|
|
|
|
|
private const string InstallSettingsPrefix = "install-settings-";
|
|
|
|
|
|
2022-01-21 13:41:37 +00:00
|
|
|
|
private bool _shouldRender;
|
|
|
|
|
protected override bool ShouldRender() => _shouldRender;
|
|
|
|
|
|
2022-01-27 07:55:07 +00:00
|
|
|
|
protected override void OnInitialized()
|
2022-01-15 06:29:44 +00:00
|
|
|
|
{
|
2022-01-27 07:55:07 +00:00
|
|
|
|
Install();
|
2022-01-21 13:41:37 +00:00
|
|
|
|
_shouldRender = true;
|
2022-01-20 08:34:38 +00:00
|
|
|
|
}
|
2022-01-15 06:29:44 +00:00
|
|
|
|
|
2022-01-28 05:05:30 +00:00
|
|
|
|
private async Task Install()
|
2022-01-20 08:34:38 +00:00
|
|
|
|
{
|
2022-01-21 13:41:37 +00:00
|
|
|
|
if (Modlist is null) return;
|
2022-01-27 07:55:07 +00:00
|
|
|
|
|
2022-01-21 13:41:37 +00:00
|
|
|
|
StateContainer.InstallState = InstallState.Installing;
|
|
|
|
|
await Task.Run(() => BeginInstall(Modlist));
|
2022-01-20 08:34:38 +00:00
|
|
|
|
}
|
2022-01-16 13:46:16 +00:00
|
|
|
|
|
2022-01-21 13:41:37 +00:00
|
|
|
|
private async Task BeginInstall(ModList modlist)
|
2022-01-20 08:34:38 +00:00
|
|
|
|
{
|
2022-01-21 13:41:37 +00:00
|
|
|
|
var postfix = (await ModlistPath.ToString().Hash()).ToHex();
|
|
|
|
|
await SettingsManager.Save(InstallSettingsPrefix + postfix, new SavedInstallSettings
|
2022-01-20 08:34:38 +00:00
|
|
|
|
{
|
2022-01-21 13:41:37 +00:00
|
|
|
|
ModlistLocation = ModlistPath,
|
|
|
|
|
InstallLocation = InstallPath,
|
|
|
|
|
DownloadLocation = DownloadPath
|
2022-01-20 08:34:38 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
try
|
2022-01-16 13:46:16 +00:00
|
|
|
|
{
|
2022-01-21 13:41:37 +00:00
|
|
|
|
var installer = StandardInstaller.Create(ServiceProvider, new InstallerConfiguration
|
2022-01-16 17:38:54 +00:00
|
|
|
|
{
|
2022-01-21 13:41:37 +00:00
|
|
|
|
Game = modlist.GameType,
|
|
|
|
|
Downloads = DownloadPath,
|
|
|
|
|
Install = InstallPath,
|
|
|
|
|
ModList = modlist,
|
|
|
|
|
ModlistArchive = ModlistPath,
|
|
|
|
|
SystemParameters = ParametersConstructor.Create(),
|
|
|
|
|
GameFolder = GameLocator.GameLocation(modlist.GameType)
|
2022-01-16 17:38:54 +00:00
|
|
|
|
});
|
2022-01-27 07:55:07 +00:00
|
|
|
|
|
2022-01-20 08:34:38 +00:00
|
|
|
|
installer.OnStatusUpdate = update =>
|
2022-01-16 17:38:54 +00:00
|
|
|
|
{
|
2022-01-27 07:55:07 +00:00
|
|
|
|
if (LastStatus == update.StatusText) return;
|
|
|
|
|
StatusStep.Insert(0, update.StatusText);
|
|
|
|
|
StatusCategory = update.StatusCategory;
|
|
|
|
|
LastStatus = update.StatusText;
|
|
|
|
|
InvokeAsync(StateHasChanged);
|
2022-01-20 08:34:38 +00:00
|
|
|
|
};
|
2022-01-16 17:38:54 +00:00
|
|
|
|
|
2022-01-20 08:34:38 +00:00
|
|
|
|
await installer.Begin(CancellationToken.None);
|
2022-01-21 13:41:37 +00:00
|
|
|
|
StateContainer.InstallState = InstallState.Success;
|
2022-01-20 08:34:38 +00:00
|
|
|
|
}
|
2022-01-21 13:41:37 +00:00
|
|
|
|
catch (Exception e)
|
2022-01-20 08:34:38 +00:00
|
|
|
|
{
|
2022-01-21 13:41:37 +00:00
|
|
|
|
Logger.LogError(e, "Exception installing Modlist");
|
|
|
|
|
StateContainer.InstallState = InstallState.Failure;
|
2022-01-16 13:46:16 +00:00
|
|
|
|
}
|
2022-01-15 06:29:44 +00:00
|
|
|
|
}
|
2022-01-20 08:34:38 +00:00
|
|
|
|
}
|