Mercurial > minori
diff src/core/config.cpp @ 11:fc1bf97c528b
*: use C++11 standard
I've been meaning to do this for a while, but I didn't want to reimplement
the filesystem code. Now we are on C++11 and most compilers from the past 5 centuries should support this now
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 17 Sep 2023 06:14:30 -0400 |
parents | 5c0397762b53 |
children | cde8f67a7c7d |
line wrap: on
line diff
--- a/src/core/config.cpp Sat Sep 16 02:06:01 2023 -0400 +++ b/src/core/config.cpp Sun Sep 17 06:14:30 2023 -0400 @@ -47,11 +47,11 @@ }; int Config::Load() { - std::filesystem::path cfg_path = get_config_path(); - if (!std::filesystem::exists(cfg_path)) + std::string cfg_path = Filesystem::GetConfigPath(); + if (!Filesystem::Exists(cfg_path)) return 0; - std::ifstream config_in(cfg_path.string().c_str(), std::ifstream::in); - auto config_js = nlohmann::json::parse(config_in); + std::ifstream config(cfg_path.c_str(), std::ifstream::in); + auto config_js = nlohmann::json::parse(config); service = StringToService[JSON::GetString(config_js, "/General/Service"_json_pointer)]; anime_list.language = StringToAnimeTitleMap[JSON::GetString( config_js, "/Anime List/Display only aired episodes"_json_pointer, "Romaji")]; @@ -67,15 +67,15 @@ anilist.username = JSON::GetString(config_js, "/Authorization/AniList/Username"_json_pointer); anilist.user_id = JSON::GetInt(config_js, "/Authorization/AniList/User ID"_json_pointer); theme = StringToTheme[JSON::GetString(config_js, "/Appearance/Theme"_json_pointer)]; - config_in.close(); + config.close(); return 0; } int Config::Save() { - std::filesystem::path cfg_path = get_config_path(); - if (!std::filesystem::exists(cfg_path.parent_path())) - std::filesystem::create_directories(cfg_path.parent_path()); - std::ofstream config_out(cfg_path.string().c_str(), std::ofstream::out | std::ofstream::trunc); + std::string cfg_path = Filesystem::GetConfigPath(); + if (!Filesystem::Exists(Filesystem::GetParentDirectory(cfg_path))) + Filesystem::CreateDirectories(Filesystem::GetParentDirectory(cfg_path)); + std::ofstream config(cfg_path.c_str(), std::ofstream::out | std::ofstream::trunc); // clang-format off nlohmann::json config_js = { {"General", { @@ -100,7 +100,7 @@ }} }; // clang-format on - config_out << std::setw(4) << config_js << std::endl; - config_out.close(); + config << std::setw(4) << config_js << std::endl; + config.close(); return 0; }