2022-03-13 22:47:30 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Reactive.Disposables;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ReactiveUI;
|
|
|
|
|
using ReactiveUI.Fody.Helpers;
|
|
|
|
|
using Wabbajack.Installer;
|
|
|
|
|
using Wabbajack.DTOs.Interventions;
|
2022-05-16 23:25:02 +00:00
|
|
|
|
using Wabbajack.Paths;
|
2022-03-13 22:47:30 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
|
|
|
|
public class MO2InstallerVM : ViewModel, ISubInstallerVM
|
|
|
|
|
{
|
|
|
|
|
public InstallerVM Parent { get; }
|
2023-10-12 18:33:06 +00:00
|
|
|
|
|
2022-03-13 22:47:30 +00:00
|
|
|
|
[Reactive]
|
|
|
|
|
public ErrorResponse CanInstall { get; set; }
|
|
|
|
|
|
|
|
|
|
[Reactive]
|
|
|
|
|
public IInstaller ActiveInstallation { get; private set; }
|
|
|
|
|
|
2023-10-12 18:33:06 +00:00
|
|
|
|
[Reactive]
|
|
|
|
|
public Mo2ModlistInstallationSettings CurrentSettings { get; set; }
|
2022-03-13 22:47:30 +00:00
|
|
|
|
|
|
|
|
|
public FilePickerVM Location { get; }
|
|
|
|
|
|
|
|
|
|
public FilePickerVM DownloadLocation { get; }
|
|
|
|
|
|
|
|
|
|
public bool SupportsAfterInstallNavigation => true;
|
|
|
|
|
|
|
|
|
|
[Reactive]
|
|
|
|
|
public bool AutomaticallyOverwrite { get; set; }
|
|
|
|
|
|
|
|
|
|
public int ConfigVisualVerticalOffset => 25;
|
|
|
|
|
|
|
|
|
|
public MO2InstallerVM(InstallerVM installerVM)
|
|
|
|
|
{
|
|
|
|
|
Parent = installerVM;
|
|
|
|
|
|
|
|
|
|
Location = new FilePickerVM()
|
|
|
|
|
{
|
|
|
|
|
ExistCheckOption = FilePickerVM.CheckOptions.Off,
|
|
|
|
|
PathType = FilePickerVM.PathTypeOptions.Folder,
|
|
|
|
|
PromptTitle = "Select Installation Directory",
|
|
|
|
|
};
|
2022-05-16 23:25:02 +00:00
|
|
|
|
Location.WhenAnyValue(t => t.TargetPath)
|
|
|
|
|
.Subscribe(newPath =>
|
|
|
|
|
{
|
|
|
|
|
if (newPath != default && DownloadLocation!.TargetPath == AbsolutePath.Empty)
|
|
|
|
|
{
|
|
|
|
|
DownloadLocation.TargetPath = newPath.Combine("downloads");
|
|
|
|
|
}
|
|
|
|
|
}).DisposeWith(CompositeDisposable);
|
2023-10-12 18:33:06 +00:00
|
|
|
|
|
2022-03-13 22:47:30 +00:00
|
|
|
|
DownloadLocation = new FilePickerVM()
|
|
|
|
|
{
|
|
|
|
|
ExistCheckOption = FilePickerVM.CheckOptions.Off,
|
|
|
|
|
PathType = FilePickerVM.PathTypeOptions.Folder,
|
|
|
|
|
PromptTitle = "Select a location for MO2 downloads",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unload()
|
|
|
|
|
{
|
|
|
|
|
SaveSettings(this.CurrentSettings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SaveSettings(Mo2ModlistInstallationSettings settings)
|
|
|
|
|
{
|
|
|
|
|
//Parent.MWVM.Settings.Installer.LastInstalledListLocation = Parent.ModListLocation.TargetPath;
|
|
|
|
|
if (settings == null) return;
|
|
|
|
|
settings.InstallationLocation = Location.TargetPath;
|
|
|
|
|
settings.DownloadLocation = DownloadLocation.TargetPath;
|
|
|
|
|
settings.AutomaticallyOverrideExistingInstall = AutomaticallyOverwrite;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AfterInstallNavigation()
|
|
|
|
|
{
|
|
|
|
|
Process.Start("explorer.exe", Location.TargetPath.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> Install()
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
using (var installer = new MO2Installer(
|
|
|
|
|
archive: Parent.ModListLocation.TargetPath,
|
|
|
|
|
modList: Parent.ModList.SourceModList,
|
|
|
|
|
outputFolder: Location.TargetPath,
|
|
|
|
|
downloadFolder: DownloadLocation.TargetPath,
|
|
|
|
|
parameters: SystemParametersConstructor.Create()))
|
|
|
|
|
{
|
|
|
|
|
installer.Metadata = Parent.ModList.SourceModListMetadata;
|
|
|
|
|
installer.UseCompression = Parent.MWVM.Settings.Filters.UseCompression;
|
|
|
|
|
Parent.MWVM.Settings.Performance.SetProcessorSettings(installer);
|
|
|
|
|
|
|
|
|
|
return await Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var workTask = installer.Begin();
|
|
|
|
|
ActiveInstallation = installer;
|
|
|
|
|
return await workTask;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
ActiveInstallation = null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-10-12 18:33:06 +00:00
|
|
|
|
|
2022-03-13 22:47:30 +00:00
|
|
|
|
public IUserIntervention InterventionConverter(IUserIntervention intervention)
|
|
|
|
|
{
|
|
|
|
|
switch (intervention)
|
|
|
|
|
{
|
|
|
|
|
case ConfirmUpdateOfExistingInstall confirm:
|
|
|
|
|
return new ConfirmUpdateOfExistingInstallVM(this, confirm);
|
|
|
|
|
default:
|
|
|
|
|
return intervention;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|