diff --git a/src/config/Config.cpp b/src/config/Config.cpp index febea719b..81bf00839 100644 --- a/src/config/Config.cpp +++ b/src/config/Config.cpp @@ -134,16 +134,18 @@ void Config::Erase(const std::string& key) { void Config::EraseBlock(const std::string& key) { nlohmann::json gjson = mFlattenedJson.unflatten(); if (key.find(".") != std::string::npos) { - nlohmann::json& gjson2 = gjson; + nlohmann::json* gjson2 = &gjson; std::vector dots = StringHelper::Split(key, "."); if (dots.size() > 1) { size_t curDot = 0; for (auto& dot : dots) { - if (gjson2.contains(dot)) { - if (curDot == dots.size()) { - gjson2.erase(dot); + if (gjson2->contains(dot)) { + if (curDot == dots.size() - 1) { + gjson2->at(dot).clear(); + gjson2->erase(dot); } else { - gjson2 = gjson2[dot]; + gjson2 = &gjson2->at(dot); + curDot++; } } } @@ -154,6 +156,7 @@ void Config::EraseBlock(const std::string& key) { } } mFlattenedJson = gjson.flatten(); + Save(); } void Config::Copy(const std::string& fromKey, const std::string& toKey) { @@ -296,7 +299,6 @@ void Config::RunVersionUpdates() { SetUInt("ConfigVersion", versionUpdater->GetVersion()); } } - Save(); } ConfigVersionUpdater::ConfigVersionUpdater(uint32_t toVersion) : mVersion(toVersion) { diff --git a/src/config/Config.h b/src/config/Config.h index cf690632b..4422e3c01 100644 --- a/src/config/Config.h +++ b/src/config/Config.h @@ -56,6 +56,7 @@ class Config { void SetInt(const std::string& key, int32_t value); void SetUInt(const std::string& key, uint32_t value); void Erase(const std::string& key); + void EraseChild(nlohmann::json& block); void EraseBlock(const std::string& key); void Copy(const std::string& fromKey, const std::string& toKey); bool Contains(const std::string& key);