wabbajack/Wabbajack/View Models/Installers/VortexInstallerVM.cs

92 lines
2.9 KiB
C#
Raw Normal View History

2019-12-03 02:38:33 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.Common;
using Wabbajack.Lib;
2020-01-07 13:50:11 +00:00
using Wabbajack.Util;
2019-12-03 02:38:33 +00:00
namespace Wabbajack
{
public class VortexInstallerVM : ViewModel, ISubInstallerVM
{
public InstallerVM Parent { get; }
2019-12-03 02:38:33 +00:00
[Reactive]
public AInstaller ActiveInstallation { get; private set; }
private readonly ObservableAsPropertyHelper<string> _DownloadLocation;
public string DownloadLocation => _DownloadLocation.Value;
private readonly ObservableAsPropertyHelper<string> _StagingLocation;
public string StagingLocation => _StagingLocation.Value;
private readonly ObservableAsPropertyHelper<Game> _TargetGame;
public Game TargetGame => _TargetGame.Value;
2019-12-11 04:59:15 +00:00
public bool SupportsAfterInstallNavigation => false;
public int ConfigVisualVerticalOffset => 0;
2019-12-19 01:14:21 +00:00
public IObservable<bool> CanInstall { get; }
2019-12-03 02:38:33 +00:00
public VortexInstallerVM(InstallerVM installerVM)
{
Parent = installerVM;
2019-12-03 02:38:33 +00:00
_TargetGame = installerVM.WhenAny(x => x.ModList.SourceModList.GameType)
.ToGuiProperty(this, nameof(TargetGame));
2019-12-03 02:38:33 +00:00
2019-12-19 01:14:21 +00:00
CanInstall = Observable.CombineLatest(
this.WhenAny(x => x.TargetGame)
.Select(game => VortexCompiler.IsActiveVortexGame(game)),
installerVM.WhenAny(x => x.ModListLocation.InError),
resultSelector: (isVortexGame, modListErr) => isVortexGame && !modListErr);
2019-12-03 02:38:33 +00:00
}
public void Unload()
{
}
2019-12-11 04:59:15 +00:00
public void AfterInstallNavigation()
{
throw new NotImplementedException();
}
2019-12-19 01:14:21 +00:00
public async Task<bool> Install()
2019-12-19 01:14:21 +00:00
{
AInstaller installer;
var download = VortexCompiler.RetrieveDownloadLocation(TargetGame);
var staging = VortexCompiler.RetrieveStagingLocation(TargetGame);
using (installer = new VortexInstaller(
2019-12-19 01:14:21 +00:00
archive: Parent.ModListLocation.TargetPath,
modList: Parent.ModList.SourceModList,
outputFolder: staging,
2020-01-07 13:50:11 +00:00
downloadFolder: download,
parameters: SystemParametersConstructor.Create()))
{
Parent.MWVM.Settings.Performance.AttachToBatchProcessor(installer);
2019-12-19 01:14:21 +00:00
return await Task.Run(async () =>
2019-12-19 01:14:21 +00:00
{
try
{
var workTask = installer.Begin();
ActiveInstallation = installer;
return await workTask;
}
finally
{
ActiveInstallation = null;
}
});
}
2019-12-19 01:14:21 +00:00
}
2019-12-03 02:38:33 +00:00
}
}