From 27a2d25fb2178931e5cd7942872e1034ac6a9c07 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 25 May 2025 19:44:10 +1200 Subject: [PATCH] Fixed. --- source/src/config.cpp | 34 +++++++++++++++++++++++----------- source/src/utils/utils.hpp | 6 ++++++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/source/src/config.cpp b/source/src/config.cpp index ecca563..8d955fb 100644 --- a/source/src/config.cpp +++ b/source/src/config.cpp @@ -169,24 +169,36 @@ std::string config::get_template_create_path() std::string config::get_backups_path() { - return mConfig["backups_path"]; + nlohmann::json backups_path = mConfig["backups_path"]; + if (backups_path.empty()) + return ""; + if (backups_path.is_string()) + return backups_path; + warning << "backups_path is not a string: " << backups_path << std::endl; + return ""; } dropshell::tRegistryEntry::tRegistryEntry(nlohmann::json json) { + valid = false; if (json.is_object() && !json.empty()) { for (auto &[key, value] : json.items()) { - if (tolower(key) == "name") { - name = value; - } else if (tolower(key) == "url") { - url = value; - } else if (tolower(key) == "token") { - token = value; + if (value.is_string() && !value.empty()) + switch (switchhash(key.c_str())) { + case switchhash("name"): + name = value; + break; + case switchhash("url"): + url = value; + break; + case switchhash("token"): + token = value; + break; + default: + break; + } } - } - valid = true; - } else { - valid = false; + valid = (!url.empty()&&!name.empty()); // token can be empty. } } diff --git a/source/src/utils/utils.hpp b/source/src/utils/utils.hpp index c87fe5f..f8fc0e1 100644 --- a/source/src/utils/utils.hpp +++ b/source/src/utils/utils.hpp @@ -69,4 +69,10 @@ std::string get_string_from_url(const std::string& url); // replace or append a block of text to a file, matching first and last lines if replacing. bool file_replace_or_add_segment(std::string filepath, std::string segment); + +constexpr unsigned int switchhash(const char *s, int off = 0) +{ + return !s[off] ? 5381 : (switchhash(s, off + 1) * 33) ^ s[off]; +} + } // namespace dropshell \ No newline at end of file