From 3dcf99753e031d5e0b73bd34059ad2967b74dbe0 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 5 Mar 2013 08:13:23 -0800 Subject: [PATCH] Added SaveValues to ConfigService --- NzbDrone.Api/Settings/SettingsModule.cs | 2 ++ NzbDrone.Core/Configuration/ConfigService.cs | 17 +++++++++++++++++ NzbDrone.Core/Configuration/IConfigService.cs | 1 + 3 files changed, 20 insertions(+) diff --git a/NzbDrone.Api/Settings/SettingsModule.cs b/NzbDrone.Api/Settings/SettingsModule.cs index f91cb14a5..a9bd74782 100644 --- a/NzbDrone.Api/Settings/SettingsModule.cs +++ b/NzbDrone.Api/Settings/SettingsModule.cs @@ -32,6 +32,8 @@ namespace NzbDrone.Api.Settings private Response SaveSettings() { var request = Request.Body.FromJson>(); + _configService.SaveValues(request); + return request.AsResponse(); } diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index ed6d138ed..ecf02ca9a 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -593,6 +593,23 @@ namespace NzbDrone.Core.Configuration ClearCache(); } + public void SaveValues(Dictionary configValues) + { + //Todo: make this not suck - we need the pascal case of the key + //Todo: Can we batch save this without savig default values? Or do we care? + + var allWithDefaults = AllWithDefaults(); + + foreach(var configValue in configValues) + { + object currentValue; + allWithDefaults.TryGetValue(configValue.Key, out currentValue); + + if (!configValue.Equals(currentValue)) + SetValue(configValue.Key, configValue.Value.ToString()); + } + } + private void EnsureCache() { lock (_cache) diff --git a/NzbDrone.Core/Configuration/IConfigService.cs b/NzbDrone.Core/Configuration/IConfigService.cs index 43588fb49..f8b3b8fc8 100644 --- a/NzbDrone.Core/Configuration/IConfigService.cs +++ b/NzbDrone.Core/Configuration/IConfigService.cs @@ -87,5 +87,6 @@ namespace NzbDrone.Core.Configuration PriorityType NzbgetRecentTvPriority { get; set; } string GetValue(string key, object defaultValue, bool persist = false); void SetValue(string key, string value); + void SaveValues(Dictionary configValues); } } \ No newline at end of file