diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-03-02 22:40:55 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-03-02 23:08:31 +0100 |
commit | 996e5c02ca6f24f54e671a321e5f48f16f59836d (patch) | |
tree | 29d752c36ee4e90e0a6906ac9444457fd5ac19f6 /src | |
parent | 46dc098cab659538b2f229636f49b84ac8af86a1 (diff) |
Allow using ~ and $HOME in config paths
Diffstat (limited to 'src')
-rw-r--r-- | src/Config.cpp | 13 | ||||
-rw-r--r-- | src/Theme.cpp | 4 |
2 files changed, 12 insertions, 5 deletions
diff --git a/src/Config.cpp b/src/Config.cpp index 7ddc1af..a1752b1 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -53,6 +53,15 @@ namespace QuickMedia { return scale; } + static std::string path_expanduser(const std::string &path) { + std::string result; + if(!path.empty() && path[0] == '~') + result = get_home_dir().data + path.substr(1); + else + result = path; + return result; + } + // No-op if this has already been called before static void init_config() { if(config_initialized) @@ -135,7 +144,7 @@ namespace QuickMedia { if(local_manga_json.isObject()) { const Json::Value &directory_json = local_manga_json["directory"]; if(directory_json.isString()) { - config->local_manga.directory = directory_json.asString(); + config->local_manga.directory = path_expanduser(directory_json.asString()); while(config->local_manga.directory.size() > 1 && config->local_manga.directory.back() == '/') { config->local_manga.directory.pop_back(); } @@ -154,7 +163,7 @@ namespace QuickMedia { if(local_anime_json.isObject()) { const Json::Value &directory_json = local_anime_json["directory"]; if(directory_json.isString()) { - config->local_anime.directory = directory_json.asString(); + config->local_anime.directory = path_expanduser(directory_json.asString()); while(config->local_anime.directory.size() > 1 && config->local_anime.directory.back() == '/') { config->local_anime.directory.pop_back(); } diff --git a/src/Theme.cpp b/src/Theme.cpp index 8320054..9f525d5 100644 --- a/src/Theme.cpp +++ b/src/Theme.cpp @@ -13,7 +13,7 @@ namespace QuickMedia { if(read_file_as_json(config_path, json_root) && json_root.isObject()) return true; - config_path = Path("/usr/share/quickmedia/themes/").join(theme_name).append(".json"); + config_path = Path("/usr/share/quickmedia/themes").join(theme_name).append(".json"); if(read_file_as_json(config_path, json_root) && json_root.isObject()) return true; @@ -63,8 +63,6 @@ namespace QuickMedia { fprintf(stderr, "Warning: theme variable \"%s\" is an invalid color value. Expected #RRGGBB or #RRGGBBAA, was: %s\n", field_name, color_str); return; } - - // TODO: Test on big endian systems (&new_color.r)[(i - 1)/2] = (c1 << 4) | c2; } color = new_color; |