From 6e0948afb1bf1504b00601ff195c9fb05e9f2c1c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 3 Nov 2022 23:21:45 +0100 Subject: Path extend fonts (allow ~ in path) --- src/Config.cpp | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/Config.cpp b/src/Config.cpp index c303448..4ce65b5 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -89,6 +89,14 @@ namespace QuickMedia { val = json_val.asDouble(); } + static void get_json_value_path(const Json::Value &json_obj, const char *field_name, std::string &val) { + get_json_value(json_obj, field_name, val); + path_expanduser(val); + while(!val.empty() && val.back() == '/') { + val.pop_back(); + } + } + static void matrix_known_homeservers_fallback() { config->matrix.known_homeservers.insert(config->matrix.known_homeservers.end(), { "midov.pl", @@ -188,28 +196,14 @@ namespace QuickMedia { const Json::Value &local_manga_json = json_root["local_manga"]; if(local_manga_json.isObject()) { - const Json::Value &directory_json = local_manga_json["directory"]; - if(directory_json.isString()) { - 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(); - } - } - + get_json_value_path(local_manga_json, "directory", config->local_manga.directory); get_json_value(local_manga_json, "load_progress", config->local_manga.sort_by_name); get_json_value(local_manga_json, "sort_chapters_by_name", config->local_manga.sort_chapters_by_name); } const Json::Value &local_anime_json = json_root["local_anime"]; if(local_anime_json.isObject()) { - const Json::Value &directory_json = local_anime_json["directory"]; - if(directory_json.isString()) { - 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(); - } - } - + get_json_value_path(local_anime_json, "directory", config->local_anime.directory); get_json_value(local_anime_json, "sort_by_name", config->local_anime.sort_by_name); get_json_value(local_anime_json, "auto_group_episodes", config->local_anime.auto_group_episodes); } @@ -297,10 +291,10 @@ namespace QuickMedia { const Json::Value &font_json = json_root["font"]; if(font_json.isObject()) { - get_json_value(font_json, "latin", config->font.latin); - get_json_value(font_json, "latin_bold", config->font.latin_bold); - get_json_value(font_json, "cjk", config->font.cjk); - get_json_value(font_json, "symbols", config->font.symbols); + get_json_value_path(font_json, "latin", config->font.latin); + get_json_value_path(font_json, "latin_bold", config->font.latin_bold); + get_json_value_path(font_json, "cjk", config->font.cjk); + get_json_value_path(font_json, "symbols", config->font.symbols); } get_json_value(json_root, "use_system_fonts", config->use_system_fonts); -- cgit v1.2.3