diff --git a/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs b/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs index 89391738..7e18b90e 100644 --- a/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs +++ b/Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs @@ -8,6 +8,7 @@ using System.Windows.Media; using DynamicData; using DynamicData.Binding; using System.Reactive; +using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -17,6 +18,7 @@ using Wabbajack.Common; using Wabbajack.DTOs; using Wabbajack.DTOs.JsonConverters; using Wabbajack.Extensions; +using Wabbajack.Hashing.xxHash64; using Wabbajack.Installer; using Wabbajack.Interventions; using Wabbajack.Messages; @@ -38,6 +40,7 @@ public enum ModManager public class InstallerVM : BackNavigatingVM, IBackNavigatingVM { private const string LastLoadedModlist = "last-loaded-modlist"; + private const string InstallSettingsPrefix = "install-settings-"; [Reactive] public ModList ModList { get; set; } @@ -101,6 +104,8 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM Installer = new MO2InstallerVM(this); BackCommand = ReactiveCommand.Create(() => NavigateToGlobal.Send(NavigateToGlobal.ScreenType.ModeSelectionView)); + + BeginCommand = ReactiveCommand.Create(() => BeginInstall().FireAndForget()); OpenReadmeCommand = ReactiveCommand.Create(() => { @@ -155,6 +160,17 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM { ModList = await StandardInstaller.LoadFromFile(_dtos, path); ModListImage = BitmapFrame.Create(await StandardInstaller.ModListImageStream(path)); + + var hex = (await ModListLocation.TargetPath.ToString().Hash()).ToHex(); + var prevSettings = await _settingsManager.Load(InstallSettingsPrefix + hex); + + if (prevSettings.ModListLocation == path) + { + ModListLocation.TargetPath = prevSettings.ModListLocation; + Installer.Location.TargetPath = prevSettings.InstallLocation; + Installer.DownloadLocation.TargetPath = prevSettings.DownloadLoadction; + } + PopulateSlideShow(ModList); ll.Succeed(); @@ -167,6 +183,25 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM } } + public async Task BeginInstall() + { + var postfix = (await ModListLocation.TargetPath.ToString().Hash()).ToHex(); + await _settingsManager.Save(InstallSettingsPrefix + postfix, new SavedInstallSettings + { + ModListLocation = ModListLocation.TargetPath, + InstallLocation = Installer.Location.TargetPath, + DownloadLoadction = Installer.DownloadLocation.TargetPath + }); + + } + + class SavedInstallSettings + { + public AbsolutePath ModListLocation { get; set; } + public AbsolutePath InstallLocation { get; set; } + public AbsolutePath DownloadLoadction { get; set; } + } + private void PopulateSlideShow(ModList modList) { SlideShowTitle = modList.Name; diff --git a/Wabbajack.App.Wpf/Views/Installers/InstallationView.xaml.cs b/Wabbajack.App.Wpf/Views/Installers/InstallationView.xaml.cs index 48c5daee..230c06b0 100644 --- a/Wabbajack.App.Wpf/Views/Installers/InstallationView.xaml.cs +++ b/Wabbajack.App.Wpf/Views/Installers/InstallationView.xaml.cs @@ -40,6 +40,10 @@ namespace Wabbajack .BindToStrict(this, view => view.ModlistLoadingRing.Visibility) .DisposeWith(disposables); + ViewModel.WhenAnyValue(vm => vm.BeginCommand) + .BindToStrict(this, view => view.InstallationConfigurationView.BeginButton.Command) + .DisposeWith(disposables); + // Slideshow ViewModel.WhenAnyValue(vm => vm.SlideShowTitle) .Select(f => f) diff --git a/Wabbajack.Hashing.xxHash64/StringExtensions.cs b/Wabbajack.Hashing.xxHash64/StringExtensions.cs index 261d8293..a09f80d5 100644 --- a/Wabbajack.Hashing.xxHash64/StringExtensions.cs +++ b/Wabbajack.Hashing.xxHash64/StringExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Text; +using System.Threading.Tasks; namespace Wabbajack.Hashing.xxHash64; @@ -30,4 +31,9 @@ public static class StringExtensions { return Convert.FromBase64String(data); } + + public static async ValueTask Hash(this string s) + { + return await Encoding.UTF8.GetBytes(s).Hash(); + } } \ No newline at end of file