Mercurial > minori
comparison src/config.cpp @ 7:07a9095eaeed
Update
Refactored some code, moved some around
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 24 Aug 2023 23:11:38 -0400 |
parents | 1d82f6e04d7d |
children |
comparison
equal
deleted
inserted
replaced
6:1d82f6e04d7d | 7:07a9095eaeed |
---|---|
39 std::map<std::string, enum AnimeListServices> StringToService { | 39 std::map<std::string, enum AnimeListServices> StringToService { |
40 {"None", NONE}, | 40 {"None", NONE}, |
41 {"AniList", ANILIST} | 41 {"AniList", ANILIST} |
42 }; | 42 }; |
43 | 43 |
44 std::map<enum AnimeTitleLanguage, std::string> AnimeTitleToStringMap = { | |
45 {ROMAJI, "Romaji"}, | |
46 {NATIVE, "Native"}, | |
47 {ENGLISH, "English"} | |
48 }; | |
49 | |
50 std::map<std::string, enum AnimeTitleLanguage> StringToAnimeTitleMap = { | |
51 {"Romaji", ROMAJI}, | |
52 {"Native", NATIVE}, | |
53 {"English", ENGLISH} | |
54 }; | |
55 | |
44 int Config::Load() { | 56 int Config::Load() { |
45 std::filesystem::path cfg_path = get_config_path(); | 57 std::filesystem::path cfg_path = get_config_path(); |
46 if (!std::filesystem::exists(cfg_path)) | 58 if (!std::filesystem::exists(cfg_path)) |
47 return 0; | 59 return 0; |
48 std::ifstream config_in(cfg_path.string().c_str(), std::ifstream::in); | 60 std::ifstream config_in(cfg_path.string().c_str(), std::ifstream::in); |
49 auto config_js = nlohmann::json::parse(config_in); | 61 auto config_js = nlohmann::json::parse(config_in); |
50 service = StringToService[JSON::GetString(config_js, "/General/Service"_json_pointer)]; | 62 service = StringToService[JSON::GetString(config_js, "/General/Service"_json_pointer)]; |
63 anime_list.language = StringToAnimeTitleMap[JSON::GetString(config_js, "/Anime List/Display only aired episodes"_json_pointer, "Romaji")]; | |
64 anime_list.display_aired_episodes = JSON::GetBoolean(config_js, "/Anime List/Display only aired episodes"_json_pointer, true); | |
65 anime_list.display_available_episodes = JSON::GetBoolean(config_js, "/Anime List/Display only available episodes in library"_json_pointer, true); | |
66 anime_list.highlight_anime_if_available = JSON::GetBoolean(config_js, "/Anime List/Highlight anime if available"_json_pointer, true); | |
67 anime_list.highlighted_anime_above_others = JSON::GetBoolean(config_js, "/Anime List/Display highlighted anime above others"_json_pointer); | |
51 anilist.auth_token = JSON::GetString(config_js, "/Authorization/AniList/Auth Token"_json_pointer); | 68 anilist.auth_token = JSON::GetString(config_js, "/Authorization/AniList/Auth Token"_json_pointer); |
52 anilist.username = JSON::GetString(config_js, "/Authorization/AniList/Username"_json_pointer); | 69 anilist.username = JSON::GetString(config_js, "/Authorization/AniList/Username"_json_pointer); |
53 anilist.user_id = JSON::GetInt(config_js, "/Authorization/AniList/User ID"_json_pointer); | 70 anilist.user_id = JSON::GetInt(config_js, "/Authorization/AniList/User ID"_json_pointer); |
54 theme = StringToTheme[JSON::GetString(config_js, "/Appearance/Theme"_json_pointer)]; | 71 theme = StringToTheme[JSON::GetString(config_js, "/Appearance/Theme"_json_pointer)]; |
55 config_in.close(); | 72 config_in.close(); |
63 std::ofstream config_out(cfg_path.string().c_str(), std::ofstream::out | std::ofstream::trunc); | 80 std::ofstream config_out(cfg_path.string().c_str(), std::ofstream::out | std::ofstream::trunc); |
64 nlohmann::json config_js = { | 81 nlohmann::json config_js = { |
65 {"General", { | 82 {"General", { |
66 {"Service", ServiceToString[service]} | 83 {"Service", ServiceToString[service]} |
67 }}, | 84 }}, |
85 {"Anime List", { | |
86 {"Title language", AnimeTitleToStringMap[anime_list.language]}, | |
87 {"Display only aired episodes", anime_list.display_aired_episodes}, | |
88 {"Display only available episodes in library", anime_list.display_available_episodes}, | |
89 {"Highlight anime if available", anime_list.highlight_anime_if_available}, | |
90 {"Display highlighted anime above others", anime_list.highlighted_anime_above_others} | |
91 }}, | |
68 {"Authorization", { | 92 {"Authorization", { |
69 {"AniList", { | 93 {"AniList", { |
70 {"Auth Token", anilist.auth_token}, | 94 {"Auth Token", anilist.auth_token}, |
71 {"Username", anilist.username}, | 95 {"Username", anilist.username}, |
72 {"User ID", anilist.user_id} | 96 {"User ID", anilist.user_id} |