mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Save and loading settings
This commit is contained in:
parent
b4f84a1fb0
commit
87f2f08fb7
@ -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;
|
||||
@ -34,16 +35,6 @@ 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);
|
||||
|
||||
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;
|
||||
Dispatcher.UIThread.Post(() => {
|
||||
CurrentThroughput = _resource.StatusReport.Transferred;
|
||||
ThroughputHumanFriendly = _resource.StatusReport.Transferred.ToFileSizeString();
|
||||
});
|
||||
}
|
||||
}
|
@ -35,7 +35,7 @@
|
||||
</Border>
|
||||
|
||||
<Border x:Name="ResourcesBorder" Margin="5" BorderThickness="1" Classes="ResourceSettings StandardBorder">
|
||||
<Grid RowDefinitions="Auto, Auto, Auto" ColumnDefinitions="140, 100, 140, 100">
|
||||
<Grid RowDefinitions="Auto, Auto, Auto, Auto" ColumnDefinitions="140, 100, 140, 100">
|
||||
<TextBlock Grid.Row="0" Text="Resources" FontSize="20" Grid.ColumnSpan="4" Margin="4"></TextBlock>
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="Name" FontWeight="Bold" Margin="4, 4"></TextBlock>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Text="Max Tasks" FontWeight="Bold" Margin="4, 4"></TextBlock>
|
||||
@ -53,6 +53,10 @@
|
||||
</ItemsRepeater.ItemTemplate>
|
||||
</ItemsRepeater>
|
||||
|
||||
<Button Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" HorizontalAlignment="Stretch" Margin="4" Click="SaveSettingsAndRestart">
|
||||
<TextBlock Text="Save Settings and Restart Wabbajack" HorizontalAlignment="Center" TextAlignment="Center"></TextBlock>
|
||||
</Button>
|
||||
|
||||
</Grid>
|
||||
</Border>
|
||||
</WrapPanel>
|
||||
|
@ -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<SettingsViewModel>
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void SaveSettingsAndRestart(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
ViewModel!.SaveResourceSettingsAndRestart().FireAndForget();
|
||||
}
|
||||
}
|
@ -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<AbsolutePath> _fileSystemEvents = new();
|
||||
private readonly ILogger<SettingsViewModel> _logger;
|
||||
public readonly IEnumerable<ResourceViewModel> Resources;
|
||||
private readonly ResourceSettingsManager _resourceSettingsManager;
|
||||
|
||||
public SettingsViewModel(ILogger<SettingsViewModel> logger, Configuration configuration,
|
||||
ResourceSettingsManager resourceSettingsManager,
|
||||
NexusApiTokenProvider nexusProvider, IEnumerable<IResource> 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);
|
||||
}
|
||||
}
|
@ -55,4 +55,8 @@ public class ResourceSettingsManager
|
||||
public long MaxThroughput { get; set; }
|
||||
}
|
||||
|
||||
public async Task SaveSettings(Dictionary<string, ResourceSetting> settings)
|
||||
{
|
||||
await _manager.Save("resource_settings", settings);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user