From a2688d2558ded0c8c2278b0ebb4e72e379dd7195 Mon Sep 17 00:00:00 2001 From: Dario Date: Tue, 30 Dec 2025 16:18:14 -0300 Subject: [PATCH] Add option to apply temporary config changes. --- librecomp/include/librecomp/config.hpp | 4 ++++ librecomp/src/config.cpp | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/librecomp/include/librecomp/config.hpp b/librecomp/include/librecomp/config.hpp index 9727a55..2f5db50 100644 --- a/librecomp/include/librecomp/config.hpp +++ b/librecomp/include/librecomp/config.hpp @@ -296,6 +296,10 @@ namespace recomp { add_option_hidden_dependency(dependent_option_id, source_option_id, values); }; + // Apply any temporary values to the option. + void apply_option_value(const ConfigOption &option); + void apply_option_value(const std::string &option_id); + bool load_config(std::function validate_callback = nullptr); bool save_config(); bool save_config_json(nlohmann::json config_json) const; diff --git a/librecomp/src/config.cpp b/librecomp/src/config.cpp index 070e988..e493983 100644 --- a/librecomp/src/config.cpp +++ b/librecomp/src/config.cpp @@ -409,13 +409,25 @@ bool Config::save_config_json(nlohmann::json config_json) const { return result; } +void Config::apply_option_value(const ConfigOption &option) { + ConfigValueVariant prev_value = get_option_value(option.id); + ConfigValueVariant cur_value = get_temp_option_value(option.id); + storage.value_map[option.id] = cur_value; + try_call_option_change_callback(option.id, cur_value, prev_value, OptionChangeContext::Permanent); +} + +void Config::apply_option_value(const std::string &option_id) { + auto option_by_id_it = schema.options_by_id.find(option_id); + if (option_by_id_it != schema.options_by_id.end()) { + apply_option_value(schema.options[option_by_id_it->second]); + modified_options.erase(option_by_id_it->second); + } +} + bool Config::save_config() { if (requires_confirmation) { for (const auto& option : schema.options) { - ConfigValueVariant prev_value = get_option_value(option.id); - ConfigValueVariant cur_value = get_temp_option_value(option.id); - storage.value_map[option.id] = cur_value; - try_call_option_change_callback(option.id, cur_value, prev_value, OptionChangeContext::Permanent); + apply_option_value(option); } modified_options.clear();