feat(Globals): Added value checking to deep_compare method

This commit is contained in:
Yimura 2021-07-24 17:15:31 +02:00
parent 0ae142bd40
commit fcc796e8cb

View File

@ -120,8 +120,11 @@ struct globals {
{
nlohmann::json& j = this->to_json();
if (deep_compare(this->options, j))
if (deep_compare(this->options, j, true))
{
LOG(INFO) << "Settings changed, saving...";
this->save();
}
}
bool load()
@ -140,17 +143,17 @@ struct globals {
file.open(settings_file);
}
try
try
{
file >> this->options;
}
catch (const std::exception&)
{
LOG(WARNING) << "Detected corrupt settings, writing default config...";
this->write_default_config();
return this->load();
file >> this->options;
}
catch (const std::exception&)
{
LOG(WARNING) << "Detected corrupt settings, writing default config...";
this->write_default_config();
return this->load();
}
bool should_save = this->deep_compare(this->options, this->default_options);
@ -169,7 +172,7 @@ struct globals {
private:
const char* settings_location = "\\BigBaseV2\\settings.json";
bool deep_compare(nlohmann::json& current_settings, const nlohmann::json& default_settings)
bool deep_compare(nlohmann::json& current_settings, const nlohmann::json& default_settings, bool compare_value = false)
{
bool should_save = false;
@ -177,7 +180,7 @@ private:
{
const std::string &key = e.key();
if (current_settings.count(key) == 0)
if (current_settings.count(key) == 0 || (compare_value && current_settings[key] != e.value()))
{
current_settings[key] = e.value();
@ -185,7 +188,7 @@ private:
}
else if (current_settings[key].is_structured() && e.value().is_structured())
{
if (deep_compare(current_settings[key], e.value()))
if (deep_compare(current_settings[key], e.value(), compare_value))
should_save = true;
}
else if (!current_settings[key].is_structured() && e.value().is_structured()) {