From ce72a6e80c843da4b3eb4f3ad1349a5d56c90beb Mon Sep 17 00:00:00 2001 From: trawzified <55751269+tr4wzified@users.noreply.github.com> Date: Sun, 5 May 2024 11:40:21 +0200 Subject: [PATCH] Miscellaneous fixes for not saving and loading modlists correctly --- .../Compilers/CompilerSettingsVM.cs | 30 +++++++--- .../ViewModels/Compilers/CompilerVM.cs | 55 ++++++++++++++----- .../ViewModels/CreateModListVM.cs | 7 ++- .../Views/Compilers/CompilerView.xaml.cs | 20 ++++--- .../Views/Compilers/CreateModListView.xaml | 2 +- .../Views/Compilers/CreateModListView.xaml.cs | 4 +- .../CompilerSettingsInferencer.cs | 2 - 7 files changed, 82 insertions(+), 38 deletions(-) diff --git a/Wabbajack.App.Wpf/ViewModels/Compilers/CompilerSettingsVM.cs b/Wabbajack.App.Wpf/ViewModels/Compilers/CompilerSettingsVM.cs index 5c514d10..995d1760 100644 --- a/Wabbajack.App.Wpf/ViewModels/Compilers/CompilerSettingsVM.cs +++ b/Wabbajack.App.Wpf/ViewModels/Compilers/CompilerSettingsVM.cs @@ -31,7 +31,7 @@ public class CompilerSettingsVM : ViewModel ModListDescription = cs.ModListDescription; ModListReadme = cs.ModListReadme; ModListWebsite = cs.ModListWebsite; - ModlistVersion = cs.ModlistVersion; + ModlistVersion = cs.ModlistVersion?.ToString() ?? ""; PublishUpdate = cs.PublishUpdate; MachineUrl = cs.MachineUrl; Profile = cs.Profile; @@ -40,7 +40,7 @@ public class CompilerSettingsVM : ViewModel Include = cs.Include; Ignore = cs.Ignore; AlwaysEnabled = cs.AlwaysEnabled; - Version = cs.Version; + Version = cs.Version?.ToString() ?? ""; Description = cs.Description; } @@ -62,7 +62,7 @@ public class CompilerSettingsVM : ViewModel [Reactive] public string ModListDescription { get; set; } = ""; [Reactive] public string ModListReadme { get; set; } = ""; [Reactive] public Uri? ModListWebsite { get; set; } - [Reactive] public Version ModlistVersion { get; set; } = Version.Parse("0.0.1.0"); + [Reactive] public string ModlistVersion { get; set; } = ""; [Reactive] public bool PublishUpdate { get; set; } = false; [Reactive] public string MachineUrl { get; set; } = ""; @@ -103,7 +103,7 @@ public class CompilerSettingsVM : ViewModel [Reactive] public RelativePath[] Ignore { get; set; } = Array.Empty(); [Reactive] public RelativePath[] AlwaysEnabled { get; set; } = Array.Empty(); - [Reactive] public Version Version { get; set; } + [Reactive] public string Version { get; set; } [Reactive] public string Description { get; set; } public CompilerSettings ToCompilerSettings() @@ -125,7 +125,7 @@ public class CompilerSettingsVM : ViewModel ModListDescription = ModListDescription, ModListReadme = ModListReadme, ModListWebsite = ModListWebsite, - ModlistVersion = ModlistVersion, + ModlistVersion = System.Version.Parse(ModlistVersion), PublishUpdate = PublishUpdate, MachineUrl = MachineUrl, Profile = Profile, @@ -134,10 +134,24 @@ public class CompilerSettingsVM : ViewModel Include = Include, Ignore = Ignore, AlwaysEnabled = AlwaysEnabled, - Version = Version, + Version = System.Version.Parse(Version), Description = Description }; } - public AbsolutePath CompilerSettingsPath => Source.Combine(ModListName).WithExtension(Ext.CompilerSettings); - public AbsolutePath ProfilePath => Source.Combine("profiles").Combine(Profile).Combine("modlist").WithExtension(Ext.Txt); + public AbsolutePath CompilerSettingsPath + { + get + { + if (Source == default || string.IsNullOrEmpty(Profile)) return default; + return Source.Combine(ModListName).WithExtension(Ext.CompilerSettings); + } + } + public AbsolutePath ProfilePath + { + get + { + if (Source == default || string.IsNullOrEmpty(Profile)) return default; + return Source.Combine("profiles").Combine(Profile).Combine("modlist").WithExtension(Ext.Txt); + } + } } diff --git a/Wabbajack.App.Wpf/ViewModels/Compilers/CompilerVM.cs b/Wabbajack.App.Wpf/ViewModels/Compilers/CompilerVM.cs index 1ca754df..d23c3bc8 100644 --- a/Wabbajack.App.Wpf/ViewModels/Compilers/CompilerVM.cs +++ b/Wabbajack.App.Wpf/ViewModels/Compilers/CompilerVM.cs @@ -111,7 +111,8 @@ namespace Wabbajack SubCompilerVM = new MO2CompilerVM(this); ExecuteCommand = ReactiveCommand.CreateFromTask(async () => await StartCompilation()); - ReInferSettingsCommand = ReactiveCommand.CreateFromTask(async () => await ReInferSettings(), + /*ReInferSettingsCommand = ReactiveCommand.CreateFromTask(async () => await ReInferSettings(), + this.WhenAnyValue(vm => vm.Settings.Source) .ObserveOnGuiThread() .Select(v => v != default) @@ -119,6 +120,7 @@ namespace Wabbajack .ObserveOnGuiThread() .Select(p => !string.IsNullOrWhiteSpace(p))) .Select(v => v.First && v.Second)); + */ ModlistLocation = new FilePickerVM { @@ -159,7 +161,7 @@ namespace Wabbajack { Settings = new CompilerSettingsVM(await InferModListFromLocation(p)); } - else await ReInferSettings(); + else if(p.FileName == "modlist.txt".ToRelativePath()) await ReInferSettings(p); }) .DisposeWith(disposables); @@ -177,30 +179,45 @@ namespace Wabbajack .Throttle(TimeSpan.FromSeconds(2)) .Subscribe(_ => SaveSettingsFile().FireAndForget()) .DisposeWith(disposables); + /* - this.WhenAnyValue(x => x.ModListImageLocation.TargetPath) - .BindToStrict(this, vm => vm.Settings.ModListImage) - .DisposeWith(disposables); + ModListImageLocation.WhenAnyValue(x => x.TargetPath) + .BindToStrict(this, vm => vm.Settings.ModListImage) + .DisposeWith(disposables); + + DownloadLocation.WhenAnyValue(x => x.TargetPath) + .BindToStrict(this, vm => vm.Settings.Downloads) + .DisposeWith(disposables); + + Settings.WhenAnyValue(x => x.Downloads) + .BindToStrict(this, vm => vm.DownloadLocation.TargetPath) + .DisposeWith(disposables); + */ - this.WhenAnyValue(x => x.DownloadLocation.TargetPath) - .BindToStrict(this, vm => vm.Settings.Downloads) - .DisposeWith(disposables); }); } - private async Task ReInferSettings() + private async Task ReInferSettings(AbsolutePath filePath) { - var newSettings = await _inferencer.InferModListFromLocation( - Settings.Source.Combine("profiles", Settings.Profile, "modlist.txt")); + var newSettings = await _inferencer.InferModListFromLocation(filePath); if (newSettings == null) { _logger.LogError("Cannot infer settings"); return; } - + + Settings.Source = newSettings.Source; + Settings.Downloads = newSettings.Downloads; + + if (string.IsNullOrEmpty(Settings.ModListName)) + Settings.OutputFile = newSettings.OutputFile.Combine(newSettings.Profile).WithExtension(Ext.Wabbajack); + else + Settings.OutputFile = newSettings.OutputFile.Combine(newSettings.ModListName).WithExtension(Ext.Wabbajack); + + Settings.Game = newSettings.Game; Settings.Include = newSettings.Include; Settings.Ignore = newSettings.Ignore; Settings.AlwaysEnabled = newSettings.AlwaysEnabled; @@ -294,7 +311,7 @@ namespace Wabbajack _logger.LogInformation("Publishing List"); var downloadMetadata = _dtos.Deserialize( await Settings.OutputFile.WithExtension(Ext.Meta).WithExtension(Ext.Json).ReadAllTextAsync())!; - await _wjClient.PublishModlist(Settings.MachineUrl, Settings.Version, Settings.OutputFile, downloadMetadata); + await _wjClient.PublishModlist(Settings.MachineUrl, Version.Parse(Settings.Version), Settings.OutputFile, downloadMetadata); } _logger.LogInformation("Compiler Finished"); @@ -334,18 +351,26 @@ namespace Wabbajack return false; } + if(!Version.TryParse(Settings.Version, out var version)) + { + _logger.LogError("Preflight Check failed, version {Version} was not valid", Settings.Version); + return false; + } + return true; } private async Task SaveSettingsFile() { - if (Settings.Source == default) return; + if (Settings.Source == default || Settings.CompilerSettingsPath == default) return; await using var st = Settings.CompilerSettingsPath.Open(FileMode.Create, FileAccess.Write, FileShare.None); await JsonSerializer.SerializeAsync(st, Settings.ToCompilerSettings(), _dtos.Options); var allSavedCompilerSettings = await _settingsManager.Load>(Consts.AllSavedCompilerSettingsPaths); - allSavedCompilerSettings.Remove(Settings.CompilerSettingsPath); + + // Don't simply remove Settings.CompilerSettingsPath here, because WJ sometimes likes to make default compiler settings files + allSavedCompilerSettings.RemoveAll(path => path.Parent == Settings.Source); allSavedCompilerSettings.Insert(0, Settings.CompilerSettingsPath); await _settingsManager.Save(Consts.AllSavedCompilerSettingsPaths, allSavedCompilerSettings); diff --git a/Wabbajack.App.Wpf/ViewModels/CreateModListVM.cs b/Wabbajack.App.Wpf/ViewModels/CreateModListVM.cs index 5ca18d42..5a3927b9 100644 --- a/Wabbajack.App.Wpf/ViewModels/CreateModListVM.cs +++ b/Wabbajack.App.Wpf/ViewModels/CreateModListVM.cs @@ -36,7 +36,7 @@ namespace Wabbajack private readonly CancellationToken _cancellationToken; private readonly DTOSerializer _dtos; - public ICommand CompileModListCommand { get; set; } + public ICommand NewModListCommand { get; set; } [Reactive] public ObservableCollection CreatedModlists { get; set; } @@ -48,7 +48,10 @@ namespace Wabbajack _settingsManager = settingsManager; _serviceProvider = serviceProvider; _dtos = dtos; - CompileModListCommand = ReactiveCommand.Create(() => NavigateToGlobal.Send(ScreenType.Compiler)); + NewModListCommand = ReactiveCommand.Create(() => { + NavigateToGlobal.Send(ScreenType.Compiler); + LoadModlistForCompiling.Send(new()); + }); this.WhenActivated(disposables => { LoadAllCompilerSettings().DisposeWith(disposables); diff --git a/Wabbajack.App.Wpf/Views/Compilers/CompilerView.xaml.cs b/Wabbajack.App.Wpf/Views/Compilers/CompilerView.xaml.cs index b4e56de8..215d55aa 100644 --- a/Wabbajack.App.Wpf/Views/Compilers/CompilerView.xaml.cs +++ b/Wabbajack.App.Wpf/Views/Compilers/CompilerView.xaml.cs @@ -102,10 +102,18 @@ namespace Wabbajack ViewModel.WhenAnyValue(vm => vm.DownloadLocation) .BindToStrict(this, view => view.CompilerConfigView.DownloadsLocation.PickerVM) .DisposeWith(disposables); + + ViewModel.WhenAnyValue(vm => vm.Settings.Downloads) + .BindToStrict(this, view => view.CompilerConfigView.DownloadsLocation.PickerVM.TargetPath) + .DisposeWith(disposables); ViewModel.WhenAnyValue(vm => vm.OutputLocation) .BindToStrict(this, view => view.CompilerConfigView.OutputLocation.PickerVM) .DisposeWith(disposables); + + ViewModel.WhenAnyValue(vm => vm.Settings.OutputFile) + .BindToStrict(this, view => view.CompilerConfigView.OutputLocation.PickerVM.TargetPath) + .DisposeWith(disposables); UserInterventionsControl.Visibility = Visibility.Collapsed; @@ -145,14 +153,7 @@ namespace Wabbajack this.Bind(ViewModel, vm => vm.Settings.ModListAuthor, view => view.AuthorNameSetting.Text) .DisposeWith(disposables); - this.Bind(ViewModel, - vm => vm.Settings.Version, - view => view.VersionSetting.Text, - vmVersion => vmVersion?.ToString() ?? "", - viewVersion => { - Version.TryParse(viewVersion, out var version); - return version ?? Version.Parse("1.0.0"); - }) + this.Bind(ViewModel, vm => vm.Settings.Version, view => view.VersionSetting.Text) .DisposeWith(disposables); this.Bind(ViewModel, vm => vm.Settings.ModListDescription, view => view.DescriptionSetting.Text) @@ -161,6 +162,9 @@ namespace Wabbajack this.Bind(ViewModel, vm => vm.ModListImageLocation, view => view.ImageFilePicker.PickerVM) .DisposeWith(disposables); + + this.Bind(ViewModel, vm => vm.Settings.ModListImage, view => view.ImageFilePicker.PickerVM.TargetPath) + .DisposeWith(disposables); this.Bind(ViewModel, vm => vm.Settings.ModListWebsite, view => view.WebsiteSetting.Text) .DisposeWith(disposables); diff --git a/Wabbajack.App.Wpf/Views/Compilers/CreateModListView.xaml b/Wabbajack.App.Wpf/Views/Compilers/CreateModListView.xaml index cde9c458..ffb29413 100644 --- a/Wabbajack.App.Wpf/Views/Compilers/CreateModListView.xaml +++ b/Wabbajack.App.Wpf/Views/Compilers/CreateModListView.xaml @@ -29,7 +29,7 @@ - + diff --git a/Wabbajack.App.Wpf/Views/Compilers/CreateModListView.xaml.cs b/Wabbajack.App.Wpf/Views/Compilers/CreateModListView.xaml.cs index a2607484..d9da5f8b 100644 --- a/Wabbajack.App.Wpf/Views/Compilers/CreateModListView.xaml.cs +++ b/Wabbajack.App.Wpf/Views/Compilers/CreateModListView.xaml.cs @@ -34,10 +34,10 @@ namespace Wabbajack .BindToStrict(this, x => x.CreatedModListsControl.ItemsSource) .DisposeWith(dispose); - CompileNewModListBorder + NewModListBorder .Events().MouseDown .Select(args => Unit.Default) - .InvokeCommand(this, x => x.ViewModel.CompileModListCommand) + .InvokeCommand(this, x => x.ViewModel.NewModListCommand) .DisposeWith(dispose); }); } diff --git a/Wabbajack.Compiler/CompilerSettingsInferencer.cs b/Wabbajack.Compiler/CompilerSettingsInferencer.cs index b56dc000..a6de3a6f 100644 --- a/Wabbajack.Compiler/CompilerSettingsInferencer.cs +++ b/Wabbajack.Compiler/CompilerSettingsInferencer.cs @@ -139,8 +139,6 @@ public class CompilerSettingsInferencer { cs.AdditionalProfiles = await otherProfilesFile.ReadAllLinesAsync().ToArray(); } - - cs.OutputFile = cs.Source.Parent.Combine(cs.Profile).WithExtension(Ext.Wabbajack); } return cs;