wabbajack/Wabbajack.App.Wpf/Settings.cs
2023-08-20 13:57:16 +02:00

45 lines
1.5 KiB
C#

using Wabbajack.Downloaders;
using Wabbajack.RateLimiter;
using Wabbajack.Util;
namespace Wabbajack
{
public class PerformanceSettings : ViewModel
{
private readonly Configuration.MainSettings _settings;
private readonly int _defaultMaximumMemoryPerDownloadThreadMb;
public PerformanceSettings(Configuration.MainSettings settings, IResource<DownloadDispatcher> downloadResources, SystemParametersConstructor systemParams)
{
var p = systemParams.Create();
_settings = settings;
// Split half of available memory among download threads
_defaultMaximumMemoryPerDownloadThreadMb = (int)(p.SystemMemorySize / downloadResources.MaxTasks / 1024 / 1024) / 2;
_maximumMemoryPerDownloadThreadMb = settings.PerformanceSettings.MaximumMemoryPerDownloadThreadMb;
if (MaximumMemoryPerDownloadThreadMb < 0)
{
ResetMaximumMemoryPerDownloadThreadMb();
}
}
private int _maximumMemoryPerDownloadThreadMb;
public int MaximumMemoryPerDownloadThreadMb
{
get => _maximumMemoryPerDownloadThreadMb;
set
{
RaiseAndSetIfChanged(ref _maximumMemoryPerDownloadThreadMb, value);
_settings.PerformanceSettings.MaximumMemoryPerDownloadThreadMb = value;
}
}
public void ResetMaximumMemoryPerDownloadThreadMb()
{
MaximumMemoryPerDownloadThreadMb = _defaultMaximumMemoryPerDownloadThreadMb;
}
}
}