# HG changeset patch # User Paper # Date 1701454346 18000 # Node ID 121c2d5b321f803b816638997ada2292c0fa5e37 # Parent 9b10175be38907d41a6f500fa7778170a99cfd07 anime/db: finalize anime db cache diff -r 9b10175be389 -r 121c2d5b321f src/core/anime_db.cc --- a/src/core/anime_db.cc Thu Nov 30 13:52:26 2023 -0500 +++ b/src/core/anime_db.cc Fri Dec 01 13:12:26 2023 -0500 @@ -9,6 +9,9 @@ #include +#include +#include + namespace Anime { int Database::GetTotalAnimeAmount() { @@ -271,8 +274,8 @@ anime.SetDuration(JSON::GetNumber(json, "/duration"_json_pointer, 0)); anime.SetPosterUrl(JSON::GetString(json, "/poster_url"_json_pointer, "")); - if (json.contains("/list_data") && json.at("/list_data").is_array()) - ParseAnimeUserInfoJSON(json, anime); + if (json.contains("/list_data"_json_pointer) && json.at("/list_data"_json_pointer).is_object()) + ParseAnimeUserInfoJSON(json.at("/list_data"_json_pointer), anime); return true; } @@ -293,9 +296,13 @@ return false; /* When parsing, do NOT throw exceptions */ - nlohmann::json json = json.parse(db_file, nullptr, false); - if (json.is_discarded()) - return false; /* Give up */ + nlohmann::json json; + try { + json = json.parse(db_file); + } catch (std::exception const& ex) { + std::cerr << "[anime/db] Failed to parse JSON! " << ex.what() << std::endl; + return false; + } if (!ParseDatabaseJSON(json)) /* How */ return false; diff -r 9b10175be389 -r 121c2d5b321f src/core/filesystem.cc --- a/src/core/filesystem.cc Thu Nov 30 13:52:26 2023 -0500 +++ b/src/core/filesystem.cc Fri Dec 01 13:12:26 2023 -0500 @@ -39,21 +39,27 @@ #ifdef WIN32 std::filesystem::path path; wchar_t* buf; + if (SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE, NULL, &buf) == S_OK) path = buf; else return std::filesystem::path(); + CoTaskMemFree(buf); + return path / CONFIG_DIR; #elif defined(MACOSX) return std::filesystem::path(osx::GetApplicationSupportDirectory()) / CONFIG_DIR; #else // just assume POSIX std::filesystem::path path; const char* home = getenv("HOME"); + # ifdef __linux__ if (!home) home = getpwuid(getuid())->pw_dir; # endif // __linux__ + + /* only do this if the home directory was really found */ if (home) return std::filesystem::path(home) / ".config" / CONFIG_DIR; else