This commit is contained in:
parent
e7558be416
commit
27a2d25fb2
@ -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") {
|
||||
if (value.is_string() && !value.empty())
|
||||
switch (switchhash(key.c_str())) {
|
||||
case switchhash("name"):
|
||||
name = value;
|
||||
} else if (tolower(key) == "url") {
|
||||
break;
|
||||
case switchhash("url"):
|
||||
url = value;
|
||||
} else if (tolower(key) == "token") {
|
||||
break;
|
||||
case switchhash("token"):
|
||||
token = value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
valid = true;
|
||||
} else {
|
||||
valid = false;
|
||||
valid = (!url.empty()&&!name.empty()); // token can be empty.
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user