Mercurial > minori
comparison src/core/config.cpp @ 15:cde8f67a7c7d
*: update, megacommit :)
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Tue, 19 Sep 2023 22:36:08 -0400 |
| parents | fc1bf97c528b |
| children | 327568ad9be9 |
comparison
equal
deleted
inserted
replaced
| 14:a29c9402faf0 | 15:cde8f67a7c7d |
|---|---|
| 11 #include <filesystem> | 11 #include <filesystem> |
| 12 #include <fstream> | 12 #include <fstream> |
| 13 #include <limits.h> | 13 #include <limits.h> |
| 14 | 14 |
| 15 std::map<std::string, Themes> StringToTheme = { | 15 std::map<std::string, Themes> StringToTheme = { |
| 16 {"Default", Themes::OS }, | 16 {"Default", Themes::OS }, |
| 17 {"Light", Themes::LIGHT}, | 17 {"Light", Themes::LIGHT}, |
| 18 {"Dark", Themes::DARK } | 18 {"Dark", Themes::DARK } |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 std::map<Themes, std::string> ThemeToString = { | 21 std::map<Themes, std::string> ThemeToString = { |
| 22 {Themes::OS, "Default"}, | 22 {Themes::OS, "Default"}, |
| 23 {Themes::LIGHT, "Light" }, | 23 {Themes::LIGHT, "Light" }, |
| 24 {Themes::DARK, "Dark" } | 24 {Themes::DARK, "Dark" } |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 std::map<Anime::Services, std::string> ServiceToString{ | 27 std::map<Anime::Services, std::string> ServiceToString{ |
| 28 {Anime::Services::NONE, "None" }, | 28 {Anime::Services::NONE, "None" }, |
| 29 {Anime::Services::ANILIST, "AniList"} | 29 {Anime::Services::ANILIST, "AniList"} |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 std::map<std::string, Anime::Services> StringToService{ | 32 std::map<std::string, Anime::Services> StringToService{ |
| 33 {"None", Anime::Services::NONE }, | 33 {"None", Anime::Services::NONE }, |
| 34 {"AniList", Anime::Services::ANILIST} | 34 {"AniList", Anime::Services::ANILIST} |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 std::map<Anime::TitleLanguage, std::string> AnimeTitleToStringMap = { | 37 std::map<Anime::TitleLanguage, std::string> AnimeTitleToStringMap = { |
| 38 {Anime::TitleLanguage::ROMAJI, "Romaji" }, | 38 {Anime::TitleLanguage::ROMAJI, "Romaji" }, |
| 39 {Anime::TitleLanguage::NATIVE, "Native" }, | 39 {Anime::TitleLanguage::NATIVE, "Native" }, |
| 40 {Anime::TitleLanguage::ENGLISH, "English"} | 40 {Anime::TitleLanguage::ENGLISH, "English"} |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 std::map<std::string, Anime::TitleLanguage> StringToAnimeTitleMap = { | 43 std::map<std::string, Anime::TitleLanguage> StringToAnimeTitleMap = { |
| 44 {"Romaji", Anime::TitleLanguage::ROMAJI }, | 44 {"Romaji", Anime::TitleLanguage::ROMAJI }, |
| 45 {"Native", Anime::TitleLanguage::NATIVE }, | 45 {"Native", Anime::TitleLanguage::NATIVE }, |
| 46 {"English", Anime::TitleLanguage::ENGLISH} | 46 {"English", Anime::TitleLanguage::ENGLISH} |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 int Config::Load() { | 49 int Config::Load() { |
| 50 std::string cfg_path = Filesystem::GetConfigPath(); | 50 std::string cfg_path = Filesystem::GetConfigPath(); |
| 51 if (!Filesystem::Exists(cfg_path)) | 51 if (!Filesystem::Exists(cfg_path)) |
| 52 return 0; | 52 return 0; |
| 53 std::ifstream config(cfg_path.c_str(), std::ifstream::in); | 53 std::ifstream config(cfg_path.c_str(), std::ifstream::in); |
| 54 auto config_js = nlohmann::json::parse(config); | 54 auto config_js = nlohmann::json::parse(config); |
| 55 service = StringToService[JSON::GetString(config_js, "/General/Service"_json_pointer)]; | 55 service = StringToService[JSON::GetString(config_js, "/General/Service"_json_pointer)]; |
| 56 anime_list.language = StringToAnimeTitleMap[JSON::GetString( | 56 anime_list.language = StringToAnimeTitleMap[JSON::GetString( |
| 57 config_js, "/Anime List/Display only aired episodes"_json_pointer, "Romaji")]; | 57 config_js, "/Anime List/Display only aired episodes"_json_pointer, "Romaji")]; |
| 58 anime_list.display_aired_episodes = | 58 anime_list.display_aired_episodes = |
| 59 JSON::GetBoolean(config_js, "/Anime List/Display only aired episodes"_json_pointer, true); | 59 JSON::GetBoolean(config_js, "/Anime List/Display only aired episodes"_json_pointer, true); |
| 60 anime_list.display_available_episodes = | 60 anime_list.display_available_episodes = |
| 61 JSON::GetBoolean(config_js, "/Anime List/Display only available episodes in library"_json_pointer, true); | 61 JSON::GetBoolean(config_js, "/Anime List/Display only available episodes in library"_json_pointer, true); |
| 62 anime_list.highlight_anime_if_available = | 62 anime_list.highlight_anime_if_available = |
| 63 JSON::GetBoolean(config_js, "/Anime List/Highlight anime if available"_json_pointer, true); | 63 JSON::GetBoolean(config_js, "/Anime List/Highlight anime if available"_json_pointer, true); |
| 64 anime_list.highlighted_anime_above_others = | 64 anime_list.highlighted_anime_above_others = |
| 65 JSON::GetBoolean(config_js, "/Anime List/Display highlighted anime above others"_json_pointer); | 65 JSON::GetBoolean(config_js, "/Anime List/Display highlighted anime above others"_json_pointer); |
| 66 anilist.auth_token = JSON::GetString(config_js, "/Authorization/AniList/Auth Token"_json_pointer); | 66 anilist.auth_token = JSON::GetString(config_js, "/Authorization/AniList/Auth Token"_json_pointer); |
| 67 anilist.username = JSON::GetString(config_js, "/Authorization/AniList/Username"_json_pointer); | 67 anilist.username = JSON::GetString(config_js, "/Authorization/AniList/Username"_json_pointer); |
| 68 anilist.user_id = JSON::GetInt(config_js, "/Authorization/AniList/User ID"_json_pointer); | 68 anilist.user_id = JSON::GetInt(config_js, "/Authorization/AniList/User ID"_json_pointer); |
| 69 theme = StringToTheme[JSON::GetString(config_js, "/Appearance/Theme"_json_pointer)]; | 69 theme = StringToTheme[JSON::GetString(config_js, "/Appearance/Theme"_json_pointer)]; |
| 70 config.close(); | 70 config.close(); |
