2023-07-12 08:32:57 +02:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using ReactiveUI;
|
2023-07-29 14:26:45 -04:00
|
|
|
|
using Serilog;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
using SPTInstaller.Controllers;
|
|
|
|
|
using SPTInstaller.Helpers;
|
|
|
|
|
using SPTInstaller.Models;
|
|
|
|
|
|
2023-07-12 08:32:57 +02:00
|
|
|
|
namespace SPTInstaller.ViewModels;
|
|
|
|
|
|
|
|
|
|
public class PreChecksViewModel : ViewModelBase
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 08:32:57 +02:00
|
|
|
|
private string _installPath;
|
2023-07-12 16:39:37 +02:00
|
|
|
|
private bool _allowInstall;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 08:32:57 +02:00
|
|
|
|
public ObservableCollection<PreCheckBase> PreChecks { get; set; } = new(ServiceHelper.GetAll<PreCheckBase>());
|
|
|
|
|
public ICommand StartInstallCommand { get; set; }
|
2023-07-25 22:07:48 -04:00
|
|
|
|
public ICommand ShowDetailedViewCommand { get; set; }
|
|
|
|
|
|
2023-07-12 08:32:57 +02:00
|
|
|
|
public string InstallPath
|
|
|
|
|
{
|
|
|
|
|
get => _installPath;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _installPath, value);
|
|
|
|
|
}
|
2023-07-12 09:00:00 +02:00
|
|
|
|
|
2023-07-30 16:15:52 -04:00
|
|
|
|
public bool AllowInstall
|
2023-07-12 09:00:00 +02:00
|
|
|
|
{
|
2023-07-12 16:39:37 +02:00
|
|
|
|
get => _allowInstall;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _allowInstall, value);
|
2023-07-12 09:00:00 +02:00
|
|
|
|
}
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-30 16:15:52 -04:00
|
|
|
|
public PreChecksViewModel(IScreen host, Action? dismissUpdateCard) : base(host)
|
2023-07-12 08:32:57 +02:00
|
|
|
|
{
|
|
|
|
|
var data = ServiceHelper.Get<InternalData?>();
|
|
|
|
|
var installer = ServiceHelper.Get<InstallController?>();
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 08:32:57 +02:00
|
|
|
|
if (data == null || installer == null)
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 08:32:57 +02:00
|
|
|
|
NavigateTo(new MessageViewModel(HostScreen, Result.FromError("Failed to get required service for prechecks")));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 08:32:57 +02:00
|
|
|
|
data.OriginalGamePath = PreCheckHelper.DetectOriginalGamePath();
|
2023-07-27 10:03:24 -04:00
|
|
|
|
|
|
|
|
|
if (data.OriginalGamePath == null)
|
|
|
|
|
{
|
|
|
|
|
NavigateTo(new MessageViewModel(HostScreen, Result.FromError("Could not find EFT install.\n\nDo you own and have the game installed?")));
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 08:32:57 +02:00
|
|
|
|
data.TargetInstallPath = Environment.CurrentDirectory;
|
|
|
|
|
InstallPath = data.TargetInstallPath;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-30 16:15:52 -04:00
|
|
|
|
StartInstallCommand = ReactiveCommand.Create(() =>
|
|
|
|
|
{
|
|
|
|
|
dismissUpdateCard?.Invoke();
|
|
|
|
|
NavigateTo(new InstallViewModel(HostScreen));
|
|
|
|
|
});
|
|
|
|
|
|
2023-07-29 14:26:45 -04:00
|
|
|
|
ShowDetailedViewCommand = ReactiveCommand.Create(() =>
|
|
|
|
|
{
|
2023-07-30 16:15:52 -04:00
|
|
|
|
dismissUpdateCard?.Invoke();
|
2023-07-29 14:26:45 -04:00
|
|
|
|
Log.Logger.Information("Opening Detailed PreCheck View");
|
|
|
|
|
NavigateTo(new DetailedPreChecksViewModel(HostScreen));
|
|
|
|
|
});
|
2023-05-14 22:35:06 -04:00
|
|
|
|
|
2023-07-12 08:32:57 +02:00
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
var result = await installer.RunPreChecks();
|
2023-07-12 16:39:37 +02:00
|
|
|
|
AllowInstall = result.Succeeded;
|
2023-07-12 08:32:57 +02:00
|
|
|
|
});
|
2023-05-11 23:11:39 -04:00
|
|
|
|
}
|
2023-07-12 08:32:57 +02:00
|
|
|
|
}
|