using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using Wabbajack.RateLimiter; using Wabbajack.Services.OSIntegrated; namespace Wabbajack.App.Models; public class ResourceSettingsManager { private readonly SettingsManager _manager; private Dictionary? _settings; public ResourceSettingsManager(SettingsManager manager) { _manager = manager; } private SemaphoreSlim _lock = new(1); public async Task GetSettings(string name) { await _lock.WaitAsync(); try { _settings ??= await _manager.Load>("resource_settings"); if (_settings.TryGetValue(name, out var found)) return found; var newSetting = new ResourceSetting { MaxTasks = Environment.ProcessorCount, MaxThroughput = 0 }; _settings.Add(name, newSetting); await _manager.Save("resource_settings", _settings); return _settings[name]; } finally { _lock.Release(); } } public class ResourceSetting { public long MaxTasks { get; set; } public long MaxThroughput { get; set; } } public async Task SaveSettings(Dictionary settings) { await _manager.Save("resource_settings", settings); } }