mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Bind new performance settings to UI
This commit is contained in:
parent
7350b632f7
commit
a77bb6cc44
@ -5,10 +5,11 @@ using System.Reactive.Subjects;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Wabbajack.Compiler;
|
||||
using Wabbajack.Downloaders;
|
||||
using Wabbajack.DTOs.JsonConverters;
|
||||
using Wabbajack;
|
||||
using Wabbajack.Paths;
|
||||
using Consts = Wabbajack.Consts;
|
||||
using Wabbajack.RateLimiter;
|
||||
using Wabbajack.Util;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
@ -24,7 +25,6 @@ namespace Wabbajack
|
||||
public InstallerSettings Installer { get; set; } = new();
|
||||
public FiltersSettings Filters { get; set; } = new();
|
||||
public CompilerSettings Compiler { get; set; } = new();
|
||||
public PerformanceSettings Performance { get; set; } = new();
|
||||
|
||||
private Subject<Unit> _saveSignal = new();
|
||||
[JsonIgnore]
|
||||
@ -52,7 +52,7 @@ namespace Wabbajack
|
||||
|
||||
var backup = Consts.SettingsFile.AppendToName("-backup");
|
||||
await backup.DeleteAsync();
|
||||
|
||||
|
||||
await Consts.SettingsFile.CopyToAsync(backup);
|
||||
await Consts.SettingsFile.DeleteAsync();
|
||||
*/
|
||||
@ -97,71 +97,48 @@ namespace Wabbajack
|
||||
public string Search { get; set; }
|
||||
private bool _isPersistent = true;
|
||||
public bool IsPersistent { get => _isPersistent; set => RaiseAndSetIfChanged(ref _isPersistent, value); }
|
||||
|
||||
|
||||
private bool _useCompression = false;
|
||||
public bool UseCompression { get => _useCompression; set => RaiseAndSetIfChanged(ref _useCompression, value); }
|
||||
public bool ShowUtilityLists { get; set; }
|
||||
}
|
||||
|
||||
[JsonName("PerformanceSettings")]
|
||||
[JsonObject(MemberSerialization.OptOut)]
|
||||
public class PerformanceSettings : ViewModel
|
||||
{
|
||||
public PerformanceSettings()
|
||||
private readonly Configuration.MainSettings _settings;
|
||||
private readonly int _defaultMaximumMemoryPerDownloadThreadMb;
|
||||
|
||||
public PerformanceSettings(Configuration.MainSettings settings, IResource<DownloadDispatcher> downloadResources, SystemParametersConstructor systemParams)
|
||||
{
|
||||
_reduceHDDThreads = true;
|
||||
_favorPerfOverRam = false;
|
||||
_diskThreads = Environment.ProcessorCount;
|
||||
_downloadThreads = Environment.ProcessorCount <= 8 ? Environment.ProcessorCount : 8;
|
||||
}
|
||||
var p = systemParams.Create();
|
||||
|
||||
private int _downloadThreads;
|
||||
public int DownloadThreads { get => _downloadThreads; set => RaiseAndSetIfChanged(ref _downloadThreads, value); }
|
||||
|
||||
private int _diskThreads;
|
||||
public int DiskThreads { get => _diskThreads; set => RaiseAndSetIfChanged(ref _diskThreads, value); }
|
||||
_settings = settings;
|
||||
// Split half of available memory among download threads
|
||||
_defaultMaximumMemoryPerDownloadThreadMb = (int)(p.SystemMemorySize / downloadResources.MaxTasks / 1024 / 1024) / 2;
|
||||
_maximumMemoryPerDownloadThreadMb = settings.PerformanceSettings.MaximumMemoryPerDownloadThreadMb;
|
||||
|
||||
private bool _reduceHDDThreads;
|
||||
public bool ReduceHDDThreads { get => _reduceHDDThreads; set => RaiseAndSetIfChanged(ref _reduceHDDThreads, value); }
|
||||
|
||||
private bool _favorPerfOverRam;
|
||||
public bool FavorPerfOverRam { get => _favorPerfOverRam; set => RaiseAndSetIfChanged(ref _favorPerfOverRam, value); }
|
||||
|
||||
private bool _networkWorkaroundMode;
|
||||
public bool NetworkWorkaroundMode
|
||||
{
|
||||
get => _networkWorkaroundMode;
|
||||
set
|
||||
if (MaximumMemoryPerDownloadThreadMb < 0)
|
||||
{
|
||||
Consts.UseNetworkWorkaroundMode = value;
|
||||
RaiseAndSetIfChanged(ref _networkWorkaroundMode, value);
|
||||
ResetMaximumMemoryPerDownloadThreadMb();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private bool _disableTextureResizing;
|
||||
public bool DisableTextureResizing
|
||||
private int _maximumMemoryPerDownloadThreadMb;
|
||||
|
||||
public int MaximumMemoryPerDownloadThreadMb
|
||||
{
|
||||
get => _disableTextureResizing;
|
||||
get => _maximumMemoryPerDownloadThreadMb;
|
||||
set
|
||||
{
|
||||
RaiseAndSetIfChanged(ref _disableTextureResizing, value);
|
||||
RaiseAndSetIfChanged(ref _maximumMemoryPerDownloadThreadMb, value);
|
||||
_settings.PerformanceSettings.MaximumMemoryPerDownloadThreadMb = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
public void SetProcessorSettings(ABatchProcessor processor)
|
||||
public void ResetMaximumMemoryPerDownloadThreadMb()
|
||||
{
|
||||
processor.DownloadThreads = DownloadThreads;
|
||||
processor.DiskThreads = DiskThreads;
|
||||
processor.ReduceHDDThreads = ReduceHDDThreads;
|
||||
processor.FavorPerfOverRam = FavorPerfOverRam;
|
||||
|
||||
if (processor is MO2Compiler mo2c)
|
||||
mo2c.DisableTextureResizing = DisableTextureResizing;
|
||||
}*/
|
||||
MaximumMemoryPerDownloadThreadMb = _defaultMaximumMemoryPerDownloadThreadMb;
|
||||
}
|
||||
}
|
||||
|
||||
[JsonName("CompilationModlistSettings")]
|
||||
@ -174,7 +151,7 @@ namespace Wabbajack
|
||||
public string Website { get; set; }
|
||||
public string Readme { get; set; }
|
||||
public bool IsNSFW { get; set; }
|
||||
|
||||
|
||||
public string MachineUrl { get; set; }
|
||||
public AbsolutePath SplashScreen { get; set; }
|
||||
public bool Publish { get; set; }
|
||||
|
@ -2,25 +2,30 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ReactiveUI;
|
||||
using Wabbajack;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Downloaders;
|
||||
using Wabbajack.LoginManagers;
|
||||
using Wabbajack.Messages;
|
||||
using Wabbajack.Networking.WabbajackClientApi;
|
||||
using Wabbajack.RateLimiter;
|
||||
using Wabbajack.Services.OSIntegrated;
|
||||
using Wabbajack.Services.OSIntegrated.TokenProviders;
|
||||
using Wabbajack.Util;
|
||||
using Wabbajack.View_Models.Settings;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public class SettingsVM : BackNavigatingVM
|
||||
{
|
||||
private readonly Configuration.MainSettings _settings;
|
||||
private readonly SettingsManager _settingsManager;
|
||||
|
||||
public LoginManagerVM Login { get; }
|
||||
public PerformanceSettings Performance { get; }
|
||||
public FiltersSettings Filters { get; }
|
||||
@ -31,12 +36,30 @@ namespace Wabbajack
|
||||
public SettingsVM(ILogger<SettingsVM> logger, IServiceProvider provider)
|
||||
: base(logger)
|
||||
{
|
||||
Login = new LoginManagerVM(provider.GetRequiredService<ILogger<LoginManagerVM>>(), this,
|
||||
_settings = provider.GetRequiredService<Configuration.MainSettings>();
|
||||
_settingsManager = provider.GetRequiredService<SettingsManager>();
|
||||
|
||||
Login = new LoginManagerVM(provider.GetRequiredService<ILogger<LoginManagerVM>>(), this,
|
||||
provider.GetRequiredService<IEnumerable<INeedsLogin>>());
|
||||
AuthorFile = new AuthorFilesVM(provider.GetRequiredService<ILogger<AuthorFilesVM>>()!,
|
||||
AuthorFile = new AuthorFilesVM(provider.GetRequiredService<ILogger<AuthorFilesVM>>()!,
|
||||
provider.GetRequiredService<WabbajackApiTokenProvider>()!, provider.GetRequiredService<Client>()!, this);
|
||||
OpenTerminalCommand = ReactiveCommand.CreateFromTask(OpenTerminal);
|
||||
BackCommand = ReactiveCommand.Create(NavigateBack.Send);
|
||||
Performance = new PerformanceSettings(
|
||||
_settings,
|
||||
provider.GetRequiredService<IResource<DownloadDispatcher>>(),
|
||||
provider.GetRequiredService<SystemParametersConstructor>());
|
||||
BackCommand = ReactiveCommand.Create(() =>
|
||||
{
|
||||
NavigateBack.Send();
|
||||
Unload();
|
||||
});
|
||||
}
|
||||
|
||||
public override void Unload()
|
||||
{
|
||||
_settingsManager.Save(Configuration.MainSettings.SettingsFileName, _settings).FireAndForget();
|
||||
|
||||
base.Unload();
|
||||
}
|
||||
|
||||
private async Task OpenTerminal()
|
||||
|
@ -24,7 +24,7 @@
|
||||
<RowDefinition Height="10" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="25" />
|
||||
@ -34,16 +34,43 @@
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="5" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Grid.ColumnSpan="2"
|
||||
<TextBlock
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="3"
|
||||
FontFamily="Lucida Sans"
|
||||
FontSize="20"
|
||||
FontWeight="Bold"
|
||||
Text="Performance" />
|
||||
<Button Grid.Row="2" x:Name="EditResourceSettings">
|
||||
<Button x:Name="EditResourceSettings" Grid.Row="2">
|
||||
<TextBlock FontSize="14" FontWeight="Bold">Edit Resource Usage Settings and Close Wabbajack</TextBlock>
|
||||
</Button>
|
||||
<TextBlock
|
||||
Grid.Row="4"
|
||||
FontSize="14"
|
||||
Foreground="{StaticResource ForegroundBrush}"
|
||||
Text="Maximum RAM per download thread (MB)"
|
||||
ToolTip="Defines the maximum amount of RAM each download thread can use for buffering. Set to 0 to disable this limit completely." />
|
||||
<xwpf:IntegerUpDown
|
||||
x:Name="MaximumMemoryPerDownloadThreadIntegerUpDown"
|
||||
Grid.Row="4"
|
||||
Grid.Column="2"
|
||||
Width="80"
|
||||
HorizontalAlignment="Left"
|
||||
Foreground="{StaticResource ForegroundBrush}"
|
||||
Maximum="10000"
|
||||
Minimum="0" />
|
||||
<Button
|
||||
x:Name="ResetMaximumMemoryPerDownloadThread"
|
||||
Grid.Row="4"
|
||||
Grid.Column="3"
|
||||
Margin="20,0,0,0"
|
||||
Padding="10,0"
|
||||
HorizontalAlignment="Left">
|
||||
<TextBlock FontSize="14">Reset</TextBlock>
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
</rxui:ReactiveUserControl>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Reactive.Disposables;
|
||||
using ReactiveUI;
|
||||
using Wabbajack.Paths.IO;
|
||||
|
||||
@ -15,12 +16,21 @@ namespace Wabbajack
|
||||
|
||||
this.WhenActivated(disposable =>
|
||||
{
|
||||
this.BindStrict(
|
||||
ViewModel,
|
||||
x => x.MaximumMemoryPerDownloadThreadMb,
|
||||
x => x.MaximumMemoryPerDownloadThreadIntegerUpDown.Value)
|
||||
.DisposeWith(disposable);
|
||||
this.EditResourceSettings.Command = ReactiveCommand.Create(() =>
|
||||
{
|
||||
UIUtils.OpenFile(
|
||||
KnownFolders.WabbajackAppLocal.Combine("saved_settings", "resource_settings.json"));
|
||||
Environment.Exit(0);
|
||||
});
|
||||
ResetMaximumMemoryPerDownloadThread.Command = ReactiveCommand.Create(() =>
|
||||
{
|
||||
ViewModel.ResetMaximumMemoryPerDownloadThreadMb();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,13 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Wabbajack.Configuration;
|
||||
namespace Wabbajack.Configuration;
|
||||
|
||||
public class MainSettings
|
||||
{
|
||||
public const string SettingsFileName = "app_settings";
|
||||
private const int SettingsVersion = 1;
|
||||
|
||||
[JsonInclude]
|
||||
private int CurrentSettingsVersion { get; set; }
|
||||
public int CurrentSettingsVersion { get; private set; }
|
||||
|
||||
public PerformanceSettings PerformanceSettings { get; set; } = new();
|
||||
public PerformanceSettings PerformanceSettings { get; } = new();
|
||||
|
||||
public bool Upgrade()
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Compiler;
|
||||
using Wabbajack.Configuration;
|
||||
using Wabbajack.Downloaders;
|
||||
@ -103,7 +104,7 @@ public static class ServiceExtensions
|
||||
var settings = settingsManager!.Load<MainSettings>(name).Result;
|
||||
if (settings.Upgrade())
|
||||
{
|
||||
settingsManager.Save("app_settings", settings).Wait();
|
||||
settingsManager.Save(MainSettings.SettingsFileName, settings).FireAndForget();
|
||||
}
|
||||
|
||||
return settings;
|
||||
@ -131,7 +132,7 @@ public static class ServiceExtensions
|
||||
|
||||
service.AddSingleton<SettingsManager>();
|
||||
service.AddSingleton<ResourceSettingsManager>();
|
||||
service.AddSingleton<MainSettings>(s => GetAppSettings(s, "app_settings"));
|
||||
service.AddSingleton<MainSettings>(s => GetAppSettings(s, MainSettings.SettingsFileName));
|
||||
|
||||
// Resources
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user