comparison src/core/config.cpp @ 61:327568ad9be9

core/fs: finish class-ification of paths
author Paper <mrpapersonic@gmail.com>
date Fri, 29 Sep 2023 15:52:31 -0400
parents cde8f67a7c7d
children 6f7385bd334c
comparison
equal deleted inserted replaced
60:d417e9381ca5 61:327568ad9be9
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 Filesystem::Path cfg_path = Filesystem::GetConfigPath();
51 if (!Filesystem::Exists(cfg_path)) 51 if (!cfg_path.Exists())
52 return 0; 52 return 0;
53 std::ifstream config(cfg_path.c_str(), 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 = 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 =
70 config.close(); 70 config.close();
71 return 0; 71 return 0;
72 } 72 }
73 73
74 int Config::Save() { 74 int Config::Save() {
75 std::string cfg_path = Filesystem::GetConfigPath(); 75 Filesystem::Path cfg_path = Filesystem::GetConfigPath();
76 if (!Filesystem::Exists(Filesystem::GetParentDirectory(cfg_path))) 76 if (!cfg_path.GetParent().Exists())
77 Filesystem::CreateDirectories(Filesystem::GetParentDirectory(cfg_path)); 77 cfg_path.GetParent().CreateDirectories();
78 std::ofstream config(cfg_path.c_str(), 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 }},