From 2a297d45b28006c8cc9713d68f24bca1121470d5 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Tue, 9 Nov 2021 15:40:21 -0700 Subject: [PATCH 1/9] Fix login/logout buttons --- Wabbajack.App/Screens/SettingsView.axaml.cs | 13 ++++++++++ Wabbajack.App/Screens/SettingsViewModel.cs | 27 ++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Wabbajack.App/Screens/SettingsView.axaml.cs b/Wabbajack.App/Screens/SettingsView.axaml.cs index fb7fc1cb..14d0306e 100644 --- a/Wabbajack.App/Screens/SettingsView.axaml.cs +++ b/Wabbajack.App/Screens/SettingsView.axaml.cs @@ -15,6 +15,19 @@ public partial class SettingsView : ScreenBase .DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.NexusLogout, view => view.NexusLogOut) .DisposeWith(disposables); + + this.BindCommand(ViewModel, vm => vm.LoversLabLogin, view => view.LoversLabLogIn) + .DisposeWith(disposables); + this.BindCommand(ViewModel, vm => vm.LoversLabLogout, view => view.LoversLabLogOut) + .DisposeWith(disposables); + + + this.BindCommand(ViewModel, vm => vm.VectorPlexusLogin, view => view.VectorPlexusLogIn) + .DisposeWith(disposables); + this.BindCommand(ViewModel, vm => vm.VectorPlexusLogout, view => view.VectorPlexusLogOut) + .DisposeWith(disposables); + + this.OneWayBind(ViewModel, vm => vm.Resources, view => view.ResourceList.Items) .DisposeWith(disposables); }); diff --git a/Wabbajack.App/Screens/SettingsViewModel.cs b/Wabbajack.App/Screens/SettingsViewModel.cs index e2cbbe40..679b910d 100644 --- a/Wabbajack.App/Screens/SettingsViewModel.cs +++ b/Wabbajack.App/Screens/SettingsViewModel.cs @@ -24,7 +24,7 @@ public class SettingsViewModel : ViewModelBase public readonly IEnumerable Resources; public SettingsViewModel(ILogger logger, Configuration configuration, - NexusApiTokenProvider nexusProvider, IEnumerable resources) + NexusApiTokenProvider nexusProvider, IEnumerable resources, LoversLabTokenProvider llProvider, VectorPlexusTokenProvider vpProvider) { _logger = logger; Resources = resources.Select(r => new ResourceViewModel(r)).ToArray(); @@ -50,12 +50,37 @@ public class SettingsViewModel : ViewModelBase ReactiveCommand.Create(() => { MessageBus.Current.SendMessage(new NavigateTo(typeof(NexusLoginViewModel))); }, haveNexusToken.Select(x => !x)); NexusLogout = ReactiveCommand.Create(nexusProvider.DeleteToken, haveNexusToken.Select(x => x)); + + var haveLLToken = _fileSystemEvents + .StartWith(AbsolutePath.Empty) + .Select(_ => llProvider.HaveToken()); + + LoversLabLogin = + ReactiveCommand.Create(() => { MessageBus.Current.SendMessage(new NavigateTo(typeof(LoversLabOAuthLoginViewModel))); }, + haveLLToken.Select(x => !x)); + LoversLabLogout = ReactiveCommand.Create(llProvider.DeleteToken, haveLLToken.Select(x => x)); + + var haveVectorPlexusToken = _fileSystemEvents + .StartWith(AbsolutePath.Empty) + .Select(_ => vpProvider.HaveToken()); + + VectorPlexusLogin = + ReactiveCommand.Create(() => { MessageBus.Current.SendMessage(new NavigateTo(typeof(VectorPlexusOAuthLoginViewModel))); }, + haveVectorPlexusToken.Select(x => !x)); + VectorPlexusLogout = ReactiveCommand.Create(vpProvider.DeleteToken, haveVectorPlexusToken.Select(x => x)); }); } public ReactiveCommand NexusLogin { get; set; } public ReactiveCommand NexusLogout { get; set; } + + public ReactiveCommand LoversLabLogin { get; set; } + public ReactiveCommand LoversLabLogout { get; set; } + + public ReactiveCommand VectorPlexusLogin { get; set; } + public ReactiveCommand VectorPlexusLogout { get; set; } + public FileSystemWatcher Watcher { get; set; } private void Pulse(object sender, FileSystemEventArgs e) From 6253f3d2eea2d9903ec49aae3cf5cfab872b2bcf Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Tue, 9 Nov 2021 16:58:36 -0700 Subject: [PATCH 2/9] Enable website/readme buttons on launcher --- Wabbajack.App/Controls/ResourceView.axaml | 19 +++++----- Wabbajack.App/Controls/ResourceView.axaml.cs | 18 +++++++-- Wabbajack.App/Screens/LauncherView.axaml | 6 +-- Wabbajack.App/Screens/LauncherView.axaml.cs | 19 ++++++++++ .../Screens/StandardInstallationViewModel.cs | 3 +- Wabbajack.App/Utilities/OSUtil.cs | 38 +++++++++++++++++++ .../InstallConfigurationViewModel.cs | 3 +- .../ViewModels/NexusLoginViewModel.cs | 2 + .../ViewModels/OAuthLoginViewModel.cs | 5 +++ Wabbajack.DTOs/ModList/ModList.cs | 16 ++++++++ .../SavedSettings/InstallationSettings.cs | 2 +- Wabbajack.Paths.IO/KnownFolders.cs | 3 ++ 12 files changed, 115 insertions(+), 19 deletions(-) create mode 100644 Wabbajack.App/Utilities/OSUtil.cs diff --git a/Wabbajack.App/Controls/ResourceView.axaml b/Wabbajack.App/Controls/ResourceView.axaml index 3097a736..1fdc9cca 100644 --- a/Wabbajack.App/Controls/ResourceView.axaml +++ b/Wabbajack.App/Controls/ResourceView.axaml @@ -4,13 +4,14 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Wabbajack.App.Controls.ResourceView"> - - - - - - - - - + + + Total Throughput: + + Tasks: + + Throughput: + + + \ No newline at end of file diff --git a/Wabbajack.App/Controls/ResourceView.axaml.cs b/Wabbajack.App/Controls/ResourceView.axaml.cs index bcf518de..ffb29248 100644 --- a/Wabbajack.App/Controls/ResourceView.axaml.cs +++ b/Wabbajack.App/Controls/ResourceView.axaml.cs @@ -15,10 +15,20 @@ public partial class ResourceView : ReactiveUserControl, IAct this.OneWayBind(ViewModel, vm => vm.Name, view => view.ResourceName.Text) .DisposeWith(disposables); - this.Bind(ViewModel, vm => vm.MaxTasks, view => view.MaxTasks.Text) - .DisposeWith(disposables); - this.Bind(ViewModel, vm => vm.MaxThroughput, view => view.MaxThroughput.Text) - .DisposeWith(disposables); + //this.Bind(ViewModel, vm => vm.MaxTasks, view => view.MaxTasks.Text) + // .DisposeWith(disposables); + /*this.Bind(ViewModel, vm => vm.MaxThroughput, view => view.MaxThroughput.Text, + l => l is 0 or long.MaxValue ? "∞" : (l / 1024 / 1024).ToString(), + v => + { + v = v.Trim(); + if (v is "0" or "∞" || v == long.MaxValue.ToString()) + { + return long.MaxValue; + } + return long.TryParse(v, out var l) ? l * 1024 * 1024 : long.MaxValue; + }) + .DisposeWith(disposables);*/ this.OneWayBind(ViewModel, vm => vm.CurrentThroughput, view => view.CurrentThrougput.Text, val => val.FileSizeToString()) diff --git a/Wabbajack.App/Screens/LauncherView.axaml b/Wabbajack.App/Screens/LauncherView.axaml index b1dd6f62..1aadfd0e 100644 --- a/Wabbajack.App/Screens/LauncherView.axaml +++ b/Wabbajack.App/Screens/LauncherView.axaml @@ -24,9 +24,9 @@ - - - + + + .DisposeWith(disposables); }); } + + private void ShowWebsite(object? sender, RoutedEventArgs e) + { + OSUtil.OpenWebsite(ViewModel!.Setting!.StrippedModListData?.Website!); + } + + private void ShowReadme(object? sender, RoutedEventArgs e) + { + OSUtil.OpenWebsite(new Uri(ViewModel!.Setting!.StrippedModListData?.Readme!)); + } + + private void ShowLocalFiles(object? sender, RoutedEventArgs e) + { + OSUtil.OpenFolder(ViewModel!.Setting!.Install); + } } \ No newline at end of file diff --git a/Wabbajack.App/Screens/StandardInstallationViewModel.cs b/Wabbajack.App/Screens/StandardInstallationViewModel.cs index 72da3c17..855c8c80 100644 --- a/Wabbajack.App/Screens/StandardInstallationViewModel.cs +++ b/Wabbajack.App/Screens/StandardInstallationViewModel.cs @@ -225,7 +225,8 @@ public class StandardInstallationViewModel : ViewModelBase Install = config.Install, Metadata = config.Metadata, ModList = config.ModlistArchive, - Image = path + Image = path, + StrippedModListData = config.ModList.Strip() }); MessageBus.Current.SendMessage(new ConfigureLauncher(config.Install)); diff --git a/Wabbajack.App/Utilities/OSUtil.cs b/Wabbajack.App/Utilities/OSUtil.cs new file mode 100644 index 00000000..7c0777c4 --- /dev/null +++ b/Wabbajack.App/Utilities/OSUtil.cs @@ -0,0 +1,38 @@ +using System; +using System.Runtime.InteropServices; +using Microsoft.CodeAnalysis; +using Wabbajack.Common; +using Wabbajack.Paths; +using Wabbajack.Paths.IO; + +namespace Wabbajack.App.Utilities; + +public static class OSUtil +{ + public static void OpenWebsite(Uri uri) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + var helper = new ProcessHelper() + { + Path = "cmd.exe".ToRelativePath().RelativeTo(KnownFolders.WindowsSystem32), + Arguments = new[] {"/C", $"rundll32 url.dll,FileProtocolHandler {uri}"} + }; + helper.Start().FireAndForget(); + } + + } + + public static void OpenFolder(AbsolutePath path) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + var helper = new ProcessHelper() + { + Path = "explorer.exe".ToRelativePath().RelativeTo(KnownFolders.Windows), + Arguments = new object[] {path} + }; + helper.Start().FireAndForget(); + } + } +} \ No newline at end of file diff --git a/Wabbajack.App/ViewModels/InstallConfigurationViewModel.cs b/Wabbajack.App/ViewModels/InstallConfigurationViewModel.cs index 589ff0ab..8552b32c 100644 --- a/Wabbajack.App/ViewModels/InstallConfigurationViewModel.cs +++ b/Wabbajack.App/ViewModels/InstallConfigurationViewModel.cs @@ -124,7 +124,8 @@ public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewMode ModList = ModListPath, Downloads = Download, Install = Install, - Metadata = metadata + Metadata = metadata, + StrippedModListData = ModList?.Strip() }); await _settingsManager.Save("last-install-path", ModListPath); diff --git a/Wabbajack.App/ViewModels/NexusLoginViewModel.cs b/Wabbajack.App/ViewModels/NexusLoginViewModel.cs index f5ec6ad4..a6cc7ee2 100644 --- a/Wabbajack.App/ViewModels/NexusLoginViewModel.cs +++ b/Wabbajack.App/ViewModels/NexusLoginViewModel.cs @@ -97,5 +97,7 @@ public class NexusLoginViewModel : GuidedWebViewModel Cookies = cookies, ApiKey = key }); + + MessageBus.Current.SendMessage(new NavigateBack()); } } \ No newline at end of file diff --git a/Wabbajack.App/ViewModels/OAuthLoginViewModel.cs b/Wabbajack.App/ViewModels/OAuthLoginViewModel.cs index f3b9d519..91ec3b3e 100644 --- a/Wabbajack.App/ViewModels/OAuthLoginViewModel.cs +++ b/Wabbajack.App/ViewModels/OAuthLoginViewModel.cs @@ -9,8 +9,11 @@ using System.Web; using CefNet; using Microsoft.Extensions.Logging; using Wabbajack.App.Extensions; +using Wabbajack.App.Messages; using Wabbajack.DTOs.Logins; using Wabbajack.Services.OSIntegrated; +using Xunit.Sdk; +using MessageBus = ReactiveUI.MessageBus; namespace Wabbajack.App.ViewModels; @@ -87,6 +90,8 @@ public abstract class OAuthLoginViewModel : GuidedWebViewModel Cookies = cookies, ResultState = data! }); + + MessageBus.Current.SendMessage(new NavigateBack()); } private class AsyncSchemeHandler : CefSchemeHandlerFactory diff --git a/Wabbajack.DTOs/ModList/ModList.cs b/Wabbajack.DTOs/ModList/ModList.cs index e8409cb1..3f95355d 100644 --- a/Wabbajack.DTOs/ModList/ModList.cs +++ b/Wabbajack.DTOs/ModList/ModList.cs @@ -66,4 +66,20 @@ public class ModList /// Whether the Modlist is NSFW or not /// public bool IsNSFW { get; set; } + + public ModList Strip() + { + return new ModList + { + Author = Author, + Description = Description, + GameType = GameType, + Name = Name, + Readme = Readme, + WabbajackVersion = WabbajackVersion, + Website = Website, + Version = Version, + IsNSFW = IsNSFW, + }; + } } \ No newline at end of file diff --git a/Wabbajack.DTOs/SavedSettings/InstallationSettings.cs b/Wabbajack.DTOs/SavedSettings/InstallationSettings.cs index 5c5f50de..eaeee715 100644 --- a/Wabbajack.DTOs/SavedSettings/InstallationSettings.cs +++ b/Wabbajack.DTOs/SavedSettings/InstallationSettings.cs @@ -20,5 +20,5 @@ public class InstallationConfigurationSetting public ModlistMetadata? Metadata { get; set; } public AbsolutePath Image { get; set; } - + public ModList? StrippedModListData { get; set; } } \ No newline at end of file diff --git a/Wabbajack.Paths.IO/KnownFolders.cs b/Wabbajack.Paths.IO/KnownFolders.cs index f91c71a8..dfe1ad84 100644 --- a/Wabbajack.Paths.IO/KnownFolders.cs +++ b/Wabbajack.Paths.IO/KnownFolders.cs @@ -11,6 +11,9 @@ public static class KnownFolders public static AbsolutePath AppDataLocal => Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).ToAbsolutePath(); + public static AbsolutePath WindowsSystem32 => Environment.GetFolderPath(Environment.SpecialFolder.System).ToAbsolutePath(); + public static AbsolutePath WabbajackAppLocal => AppDataLocal.Combine("Wabbajack"); public static AbsolutePath CurrentDirectory => Directory.GetCurrentDirectory().ToAbsolutePath(); + public static AbsolutePath Windows => Environment.GetFolderPath(Environment.SpecialFolder.Windows).ToAbsolutePath(); } \ No newline at end of file From 3d92b44f9ff6175d2ce834bfd8e52bde1dc60d7b Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Tue, 9 Nov 2021 17:06:19 -0700 Subject: [PATCH 3/9] Show readme before/after install --- Wabbajack.App/Screens/StandardInstallationViewModel.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Wabbajack.App/Screens/StandardInstallationViewModel.cs b/Wabbajack.App/Screens/StandardInstallationViewModel.cs index 855c8c80..36169ac8 100644 --- a/Wabbajack.App/Screens/StandardInstallationViewModel.cs +++ b/Wabbajack.App/Screens/StandardInstallationViewModel.cs @@ -198,8 +198,15 @@ public class StandardInstallationViewModel : ViewModelBase _logger.LogInformation("Installer created, starting the installation process"); try { + + if (!string.IsNullOrWhiteSpace(_config.ModList.Readme)) + OSUtil.OpenWebsite(new Uri(_config.ModList.Readme)); + var result = await Task.Run(async () => await _installer.Begin(CancellationToken.None)); if (!result) throw new Exception("Installation failed"); + + if (!string.IsNullOrWhiteSpace(_config.ModList.Readme)) + OSUtil.OpenWebsite(new Uri(_config.ModList.Readme)); if (result) await SaveConfigAndContinue(_config); } @@ -219,6 +226,7 @@ public class StandardInstallationViewModel : ViewModelBase await image.CopyToAsync(os); } + await _installStateManager.SetLastState(new InstallationConfigurationSetting { Downloads = config.Downloads, From 5fc070e5d3586764122d8bf0e7d8e233efb416bc Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Tue, 9 Nov 2021 21:51:37 -0700 Subject: [PATCH 4/9] Move config code into OSIntegrated --- Wabbajack.App/App.axaml | 1 + Wabbajack.App/Controls/BrowseItemViewModel.cs | 1 + Wabbajack.App/Controls/ResourceViewModel.cs | 6 +- Wabbajack.App/Models/ImageCache.cs | 1 + Wabbajack.App/Screens/BrowseViewModel.cs | 4 +- .../Screens/CompilerConfigurationViewModel.cs | 1 + Wabbajack.App/Screens/SettingsView.axaml | 32 +++++++---- Wabbajack.App/Screens/SettingsView.axaml.cs | 3 +- Wabbajack.App/Screens/SettingsViewModel.cs | 10 +++- Wabbajack.App/ServiceExtensions.cs | 11 ---- Wabbajack.App/Utilities/LoggerProvider.cs | 1 + .../InstallConfigurationViewModel.cs | 1 + Wabbajack.CLI/Program.cs | 1 - Wabbajack.Compiler.Test/Startup.cs | 1 + .../ServiceExtensions.cs | 2 + .../ServiceExtensions.cs | 3 +- .../Configuration.cs | 2 +- .../ResourceSettingsManager.cs | 55 +++++++++++++++++++ .../ServiceExtensions.cs | 16 ++++++ .../SettingsManager.cs | 2 +- 20 files changed, 122 insertions(+), 32 deletions(-) rename {Wabbajack.App => Wabbajack.Services.OSIntegrated}/Configuration.cs (88%) create mode 100644 Wabbajack.Services.OSIntegrated/ResourceSettingsManager.cs rename {Wabbajack.App/Models => Wabbajack.Services.OSIntegrated}/SettingsManager.cs (97%) diff --git a/Wabbajack.App/App.axaml b/Wabbajack.App/App.axaml index 842e97aa..2f026076 100644 --- a/Wabbajack.App/App.axaml +++ b/Wabbajack.App/App.axaml @@ -9,6 +9,7 @@ + + + diff --git a/Wabbajack.App/Screens/SettingsView.axaml b/Wabbajack.App/Screens/SettingsView.axaml index d2742e5c..0ecb9b7e 100644 --- a/Wabbajack.App/Screens/SettingsView.axaml +++ b/Wabbajack.App/Screens/SettingsView.axaml @@ -34,30 +34,18 @@ - - - Resource Limits - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/Wabbajack.App/Screens/SettingsView.axaml.cs b/Wabbajack.App/Screens/SettingsView.axaml.cs index 1861acff..6ff3ebec 100644 --- a/Wabbajack.App/Screens/SettingsView.axaml.cs +++ b/Wabbajack.App/Screens/SettingsView.axaml.cs @@ -27,9 +27,6 @@ public partial class SettingsView : ScreenBase this.BindCommand(ViewModel, vm => vm.VectorPlexusLogout, view => view.VectorPlexusLogOut) .DisposeWith(disposables); - - this.OneWayBind(ViewModel, vm => vm.Resources, view => view.ResourcesList.Items) - .DisposeWith(disposables); }); } diff --git a/Wabbajack.Services.OSIntegrated/ResourceSettingsManager.cs b/Wabbajack.Services.OSIntegrated/ResourceSettingsManager.cs index 1bfc3b3d..18c71ca9 100644 --- a/Wabbajack.Services.OSIntegrated/ResourceSettingsManager.cs +++ b/Wabbajack.Services.OSIntegrated/ResourceSettingsManager.cs @@ -33,9 +33,9 @@ public class ResourceSettingsManager var newSetting = new ResourceSetting { MaxTasks = Environment.ProcessorCount, - MaxThroughput = long.MaxValue + MaxThroughput = 0 }; - + _settings.Add(name, newSetting); await _manager.Save("resource_settings", _settings); From b4f84a1fb0943840ec0bb40b71480907e12861cf Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Wed, 10 Nov 2021 07:14:28 -0700 Subject: [PATCH 8/9] Add resourse settings grid that doesn't look like crap --- Wabbajack.App/Controls/ResourceView.axaml | 14 +++++--------- Wabbajack.App/Controls/ResourceView.axaml.cs | 11 ++++++----- Wabbajack.App/Controls/ResourceViewModel.cs | 5 +++++ Wabbajack.App/Screens/SettingsView.axaml | 16 +++++++++++----- Wabbajack.App/Screens/SettingsView.axaml.cs | 3 +++ Wabbajack.RateLimiter/Resource.cs | 3 ++- 6 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Wabbajack.App/Controls/ResourceView.axaml b/Wabbajack.App/Controls/ResourceView.axaml index 1fdc9cca..9cbd59da 100644 --- a/Wabbajack.App/Controls/ResourceView.axaml +++ b/Wabbajack.App/Controls/ResourceView.axaml @@ -4,14 +4,10 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Wabbajack.App.Controls.ResourceView"> - - - Total Throughput: - - Tasks: - - Throughput: - - + + + + + \ No newline at end of file diff --git a/Wabbajack.App/Controls/ResourceView.axaml.cs b/Wabbajack.App/Controls/ResourceView.axaml.cs index ffb29248..ad795dbd 100644 --- a/Wabbajack.App/Controls/ResourceView.axaml.cs +++ b/Wabbajack.App/Controls/ResourceView.axaml.cs @@ -15,9 +15,10 @@ public partial class ResourceView : ReactiveUserControl, IAct this.OneWayBind(ViewModel, vm => vm.Name, view => view.ResourceName.Text) .DisposeWith(disposables); - //this.Bind(ViewModel, vm => vm.MaxTasks, view => view.MaxTasks.Text) - // .DisposeWith(disposables); - /*this.Bind(ViewModel, vm => vm.MaxThroughput, view => view.MaxThroughput.Text, + this.Bind(ViewModel, vm => vm.MaxTasks, view => view.MaxTasks.Text) + .DisposeWith(disposables); + + this.Bind(ViewModel, vm => vm.MaxThroughput, view => view.MaxThroughput.Text, l => l is 0 or long.MaxValue ? "∞" : (l / 1024 / 1024).ToString(), v => { @@ -28,9 +29,9 @@ public partial class ResourceView : ReactiveUserControl, IAct } return long.TryParse(v, out var l) ? l * 1024 * 1024 : long.MaxValue; }) - .DisposeWith(disposables);*/ + .DisposeWith(disposables); - this.OneWayBind(ViewModel, vm => vm.CurrentThroughput, view => view.CurrentThrougput.Text, + this.OneWayBind(ViewModel, vm => vm.CurrentThroughput, view => view.CurrentThroughput.Text, val => val.FileSizeToString()) .DisposeWith(disposables); }); diff --git a/Wabbajack.App/Controls/ResourceViewModel.cs b/Wabbajack.App/Controls/ResourceViewModel.cs index f6f41f0f..c189dc24 100644 --- a/Wabbajack.App/Controls/ResourceViewModel.cs +++ b/Wabbajack.App/Controls/ResourceViewModel.cs @@ -34,6 +34,7 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab _timer.Elapsed -= TimerElapsed; }).DisposeWith(disposables); + /* this.WhenAnyValue(vm => vm.MaxThroughput) .Skip(1) .Subscribe(v => { _resource.MaxThroughput = MaxThroughput; }).DisposeWith(disposables); @@ -41,6 +42,10 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab this.WhenAnyValue(vm => vm.MaxTasks) .Skip(1) .Subscribe(v => { _resource.MaxTasks = MaxTasks; }).DisposeWith(disposables); + */ + + MaxTasks = _resource.MaxTasks; + MaxThroughput = _resource.MaxThroughput; }); } diff --git a/Wabbajack.App/Screens/SettingsView.axaml b/Wabbajack.App/Screens/SettingsView.axaml index 0ecb9b7e..15e74cf7 100644 --- a/Wabbajack.App/Screens/SettingsView.axaml +++ b/Wabbajack.App/Screens/SettingsView.axaml @@ -35,17 +35,23 @@ - + - - - - + + + + + + + + + + diff --git a/Wabbajack.App/Screens/SettingsView.axaml.cs b/Wabbajack.App/Screens/SettingsView.axaml.cs index 6ff3ebec..1861acff 100644 --- a/Wabbajack.App/Screens/SettingsView.axaml.cs +++ b/Wabbajack.App/Screens/SettingsView.axaml.cs @@ -27,6 +27,9 @@ public partial class SettingsView : ScreenBase this.BindCommand(ViewModel, vm => vm.VectorPlexusLogout, view => view.VectorPlexusLogOut) .DisposeWith(disposables); + + this.OneWayBind(ViewModel, vm => vm.Resources, view => view.ResourcesList.Items) + .DisposeWith(disposables); }); } diff --git a/Wabbajack.RateLimiter/Resource.cs b/Wabbajack.RateLimiter/Resource.cs index 4bf25fa6..f22efa4d 100644 --- a/Wabbajack.RateLimiter/Resource.cs +++ b/Wabbajack.RateLimiter/Resource.cs @@ -32,6 +32,7 @@ public class Resource : IResource public Resource(string humanName, Func> settingGetter) { + Name = humanName; _tasks = new ConcurrentDictionary>(); Task.Run(async () => @@ -103,7 +104,7 @@ public class Resource : IResource await foreach (var item in _channel.Reader.ReadAllAsync(token)) { Interlocked.Add(ref _totalUsed, item.Size); - if (MaxThroughput == long.MaxValue) + if (MaxThroughput is long.MaxValue or 0) { item.Result.TrySetResult(); sw.Restart(); From 87f2f08fb7d50dfdd521ad74c51c5e95efe6b661 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Wed, 10 Nov 2021 16:04:12 -0700 Subject: [PATCH 9/9] Save and loading settings --- Wabbajack.App/Controls/ResourceViewModel.cs | 21 ++++---------- Wabbajack.App/Screens/SettingsView.axaml | 6 +++- Wabbajack.App/Screens/SettingsView.axaml.cs | 7 +++++ Wabbajack.App/Screens/SettingsViewModel.cs | 29 +++++++++++++++++++ .../ResourceSettingsManager.cs | 4 +++ 5 files changed, 51 insertions(+), 16 deletions(-) diff --git a/Wabbajack.App/Controls/ResourceViewModel.cs b/Wabbajack.App/Controls/ResourceViewModel.cs index c189dc24..067bbe97 100644 --- a/Wabbajack.App/Controls/ResourceViewModel.cs +++ b/Wabbajack.App/Controls/ResourceViewModel.cs @@ -2,6 +2,7 @@ using System; using System.Reactive.Disposables; using System.Reactive.Linq; using System.Timers; +using Avalonia.Threading; using ReactiveUI; using ReactiveUI.Fody.Helpers; using Wabbajack.App.ViewModels; @@ -33,17 +34,7 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab _timer.Stop(); _timer.Elapsed -= TimerElapsed; }).DisposeWith(disposables); - - /* - this.WhenAnyValue(vm => vm.MaxThroughput) - .Skip(1) - .Subscribe(v => { _resource.MaxThroughput = MaxThroughput; }).DisposeWith(disposables); - - this.WhenAnyValue(vm => vm.MaxTasks) - .Skip(1) - .Subscribe(v => { _resource.MaxTasks = MaxTasks; }).DisposeWith(disposables); - */ - + MaxTasks = _resource.MaxTasks; MaxThroughput = _resource.MaxThroughput; }); @@ -67,9 +58,9 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab private void TimerElapsed(object? sender, ElapsedEventArgs e) { - MaxTasks = _resource.MaxTasks; - MaxThroughput = _resource.MaxThroughput; - CurrentThroughput = _resource.StatusReport.Transferred; - ThroughputHumanFriendly = _resource.StatusReport.Transferred.ToFileSizeString(); + Dispatcher.UIThread.Post(() => { + CurrentThroughput = _resource.StatusReport.Transferred; + ThroughputHumanFriendly = _resource.StatusReport.Transferred.ToFileSizeString(); + }); } } \ No newline at end of file diff --git a/Wabbajack.App/Screens/SettingsView.axaml b/Wabbajack.App/Screens/SettingsView.axaml index 15e74cf7..41273e7b 100644 --- a/Wabbajack.App/Screens/SettingsView.axaml +++ b/Wabbajack.App/Screens/SettingsView.axaml @@ -35,7 +35,7 @@ - + @@ -52,6 +52,10 @@ + + diff --git a/Wabbajack.App/Screens/SettingsView.axaml.cs b/Wabbajack.App/Screens/SettingsView.axaml.cs index 1861acff..0fe9ad1f 100644 --- a/Wabbajack.App/Screens/SettingsView.axaml.cs +++ b/Wabbajack.App/Screens/SettingsView.axaml.cs @@ -1,6 +1,8 @@ using System.Reactive.Disposables; +using Avalonia.Interactivity; using ReactiveUI; using Wabbajack.App.Views; +using Wabbajack.Common; namespace Wabbajack.App.Screens; @@ -33,4 +35,9 @@ public partial class SettingsView : ScreenBase }); } + + private void SaveSettingsAndRestart(object? sender, RoutedEventArgs e) + { + ViewModel!.SaveResourceSettingsAndRestart().FireAndForget(); + } } \ No newline at end of file diff --git a/Wabbajack.App/Screens/SettingsViewModel.cs b/Wabbajack.App/Screens/SettingsViewModel.cs index ee04e0d0..2187979b 100644 --- a/Wabbajack.App/Screens/SettingsViewModel.cs +++ b/Wabbajack.App/Screens/SettingsViewModel.cs @@ -1,15 +1,21 @@ +using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reactive; using System.Reactive.Disposables; using System.Reactive.Linq; using System.Reactive.Subjects; +using System.Reflection; +using System.Threading.Tasks; using Microsoft.Extensions.Logging; using ReactiveUI; using Wabbajack.App.Controls; using Wabbajack.App.Messages; +using Wabbajack.App.Models; using Wabbajack.App.ViewModels; +using Wabbajack.Common; using Wabbajack.Paths; using Wabbajack.Paths.IO; using Wabbajack.RateLimiter; @@ -23,10 +29,13 @@ public class SettingsViewModel : ViewModelBase private readonly Subject _fileSystemEvents = new(); private readonly ILogger _logger; public readonly IEnumerable Resources; + private readonly ResourceSettingsManager _resourceSettingsManager; public SettingsViewModel(ILogger logger, Configuration configuration, + ResourceSettingsManager resourceSettingsManager, NexusApiTokenProvider nexusProvider, IEnumerable resources, LoversLabTokenProvider llProvider, VectorPlexusTokenProvider vpProvider) { + _resourceSettingsManager = resourceSettingsManager; _logger = logger; Resources = resources.Select(r => new ResourceViewModel(r)) .OrderBy(o => o.Name) @@ -95,4 +104,24 @@ public class SettingsViewModel : ViewModelBase { _fileSystemEvents.OnNext(e.FullPath?.ToAbsolutePath() ?? default); } + + public async Task SaveResourceSettingsAndRestart() + { + await _resourceSettingsManager.SaveSettings(Resources.ToDictionary(r => r.Name, r => + new ResourceSettingsManager.ResourceSetting() + { + MaxTasks = r.MaxTasks, + MaxThroughput = r.MaxThroughput + })); + + var proc = new Process() + { + StartInfo = new ProcessStartInfo() + { + FileName = Process.GetCurrentProcess().MainModule!.FileName + } + }; + proc.Start(); + Environment.Exit(0); + } } \ No newline at end of file diff --git a/Wabbajack.Services.OSIntegrated/ResourceSettingsManager.cs b/Wabbajack.Services.OSIntegrated/ResourceSettingsManager.cs index 18c71ca9..72050732 100644 --- a/Wabbajack.Services.OSIntegrated/ResourceSettingsManager.cs +++ b/Wabbajack.Services.OSIntegrated/ResourceSettingsManager.cs @@ -55,4 +55,8 @@ public class ResourceSettingsManager public long MaxThroughput { get; set; } } + public async Task SaveSettings(Dictionary settings) + { + await _manager.Save("resource_settings", settings); + } } \ No newline at end of file