From 6541aa206d15e664a31f790dc4d35e712efad037 Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Thu, 15 Jun 2023 00:26:54 -0400 Subject: [PATCH] Added RequestImage to AchievementManager Image requests from RetroAchievements have a slightly different format from other requests, on account of being GET calls that return strings of image data, so this is a separate function that makes such calls. To handle this, I create a BadgeStatus object that ties each badge to a boolean flag for whether it is loaded and thus usable. --- Source/Core/Core/AchievementManager.cpp | 26 +++++++++++++++++++++++++ Source/Core/Core/AchievementManager.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/Source/Core/Core/AchievementManager.cpp b/Source/Core/Core/AchievementManager.cpp index 77661bb43e..5ea4f253b9 100644 --- a/Source/Core/Core/AchievementManager.cpp +++ b/Source/Core/Core/AchievementManager.cpp @@ -944,4 +944,30 @@ AchievementManager::ResponseType AchievementManager::Request( } } +AchievementManager::ResponseType +AchievementManager::RequestImage(rc_api_fetch_image_request_t rc_request, Badge* rc_response) +{ + rc_api_request_t api_request; + Common::HttpRequest http_request; + if (rc_api_init_fetch_image_request(&api_request, &rc_request) != RC_OK) + { + ERROR_LOG_FMT(ACHIEVEMENTS, "Invalid request for image."); + return ResponseType::INVALID_REQUEST; + } + auto http_response = http_request.Get(api_request.url); + if (http_response.has_value() && http_response->size() > 0) + { + rc_api_destroy_request(&api_request); + *rc_response = std::move(*http_response); + return ResponseType::SUCCESS; + } + else + { + WARN_LOG_FMT(ACHIEVEMENTS, "RetroAchievements connection failed on image request.\n URL: {}", + api_request.url); + rc_api_destroy_request(&api_request); + return ResponseType::CONNECTION_FAILED; + } +} + #endif // USE_RETRO_ACHIEVEMENTS diff --git a/Source/Core/Core/AchievementManager.h b/Source/Core/Core/AchievementManager.h index a2ada5f0ee..9b67c1e018 100644 --- a/Source/Core/Core/AchievementManager.h +++ b/Source/Core/Core/AchievementManager.h @@ -56,6 +56,7 @@ public: using FormattedValue = std::array; static constexpr size_t RP_SIZE = 256; using RichPresence = std::array; + using Badge = std::vector; struct UnlockStatus { @@ -129,6 +130,7 @@ private: ResponseType Request(RcRequest rc_request, RcResponse* rc_response, const std::function& init_request, const std::function& process_response); + ResponseType RequestImage(rc_api_fetch_image_request_t rc_request, Badge* rc_response); rc_runtime_t m_runtime{}; Core::System* m_system{};