comparison src/core/config.cpp @ 77:6f7385bd334c

*: update formatted all source files, no more subclassing QThread... many other changes :)
author Paper <mrpapersonic@gmail.com>
date Fri, 06 Oct 2023 06:18:53 -0400
parents 327568ad9be9
children
comparison
equal deleted inserted replaced
76:3364fadc8a36 77:6f7385bd334c
51 if (!cfg_path.Exists()) 51 if (!cfg_path.Exists())
52 return 0; 52 return 0;
53 std::ifstream config(cfg_path.GetPath(), std::ifstream::in); 53 std::ifstream config(cfg_path.GetPath(), 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 =
57 config_js, "/Anime List/Display only aired episodes"_json_pointer, "Romaji")]; 57 StringToAnimeTitleMap[JSON::GetString(config_js, "/Anime List/Title language"_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 =
74 int Config::Save() { 74 int Config::Save() {
75 Filesystem::Path cfg_path = Filesystem::GetConfigPath(); 75 Filesystem::Path cfg_path = Filesystem::GetConfigPath();
76 if (!cfg_path.GetParent().Exists()) 76 if (!cfg_path.GetParent().Exists())
77 cfg_path.GetParent().CreateDirectories(); 77 cfg_path.GetParent().CreateDirectories();
78 std::ofstream config(cfg_path.GetPath(), std::ofstream::out | std::ofstream::trunc); 78 std::ofstream config(cfg_path.GetPath(), std::ofstream::out | std::ofstream::trunc);
79 // clang-format off 79 /* clang-format off */
80 nlohmann::json config_js = { 80 nlohmann::json config_js = {
81 {"General", { 81 {"General", {
82 {"Service", ServiceToString[service]} 82 {"Service", ServiceToString[service]}
83 }}, 83 }},
84 {"Anime List", { 84 {"Anime List", {
97 }}, 97 }},
98 {"Appearance", { 98 {"Appearance", {
99 {"Theme", ThemeToString[theme]} 99 {"Theme", ThemeToString[theme]}
100 }} 100 }}
101 }; 101 };
102 // clang-format on 102 /* clang-format on */
103 config << std::setw(4) << config_js << std::endl; 103 config << std::setw(4) << config_js << std::endl;
104 config.close(); 104 config.close();
105 return 0; 105 return 0;
106 } 106 }