From d2e381090cffaa972a17be1f5b6dad7bdc12a373 Mon Sep 17 00:00:00 2001 From: Simonx22 Date: Sat, 28 Feb 2026 11:12:15 -0500 Subject: [PATCH] DolphinQt: Improve Gecko code download failure message --- Source/Android/jni/Cheats/GeckoCheat.cpp | 7 +++---- Source/Core/Core/GeckoCodeConfig.cpp | 5 ++--- Source/Core/Core/GeckoCodeConfig.h | 3 ++- Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp | 16 +++++++++++----- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Source/Android/jni/Cheats/GeckoCheat.cpp b/Source/Android/jni/Cheats/GeckoCheat.cpp index 276914b27b..3d123466fe 100644 --- a/Source/Android/jni/Cheats/GeckoCheat.cpp +++ b/Source/Android/jni/Cheats/GeckoCheat.cpp @@ -190,11 +190,10 @@ Java_org_dolphinemu_dolphinemu_features_cheats_model_GeckoCheat_downloadCodes(JN { const std::string gametdb_id = GetJString(env, jGameTdbId); - bool success = true; - const std::vector codes = Gecko::DownloadCodes(gametdb_id, &success); - - if (!success) + const auto codes_result = Gecko::DownloadCodes(gametdb_id); + if (!codes_result) return nullptr; + const std::vector& codes = *codes_result; const jobjectArray array = env->NewObjectArray(static_cast(codes.size()), IDCache::GetGeckoCheatClass(), nullptr); diff --git a/Source/Core/Core/GeckoCodeConfig.cpp b/Source/Core/Core/GeckoCodeConfig.cpp index c4a74c8668..46e719b724 100644 --- a/Source/Core/Core/GeckoCodeConfig.cpp +++ b/Source/Core/Core/GeckoCodeConfig.cpp @@ -15,7 +15,7 @@ namespace Gecko { -std::vector DownloadCodes(std::string gametdb_id, bool* succeeded) +std::expected, int> DownloadCodes(std::string gametdb_id) { // codes.rc24.xyz is a mirror of the now defunct geckocodes.org. std::string endpoint{"https://codes.rc24.xyz/txt.php?txt=" + gametdb_id}; @@ -25,9 +25,8 @@ std::vector DownloadCodes(std::string gametdb_id, bool* succeeded) http.FollowRedirects(1); const Common::HttpRequest::Response response = http.Get(endpoint); - *succeeded = response.has_value(); if (!response) - return {}; + return std::unexpected{http.GetLastResponseCode()}; // temp vector containing parsed codes std::vector gcodes; diff --git a/Source/Core/Core/GeckoCodeConfig.h b/Source/Core/Core/GeckoCodeConfig.h index 26126d49e7..8020d83c1e 100644 --- a/Source/Core/Core/GeckoCodeConfig.h +++ b/Source/Core/Core/GeckoCodeConfig.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include #include @@ -17,7 +18,7 @@ class IniFile; namespace Gecko { std::vector LoadCodes(const Common::IniFile& globalIni, const Common::IniFile& localIni); -std::vector DownloadCodes(std::string gametdb_id, bool* succeeded); +std::expected, int> DownloadCodes(std::string gametdb_id); void SaveCodes(Common::IniFile& inifile, const std::vector& gcodes); std::optional DeserializeLine(const std::string& line); diff --git a/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp b/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp index f7917f8f1f..74a3f58950 100644 --- a/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp +++ b/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp @@ -395,16 +395,22 @@ void GeckoCodeWidget::UpdateList() void GeckoCodeWidget::DownloadCodes() { - bool success; + const auto codes_result = Gecko::DownloadCodes(m_gametdb_id); - std::vector codes = Gecko::DownloadCodes(m_gametdb_id, &success); - - if (!success) + if (!codes_result) { - ModalMessageBox::critical(this, tr("Error"), tr("Failed to download codes.")); + QString message = tr("Failed to download Gecko codes. The code server may be temporarily " + "unavailable. Please try again later."); + + const int http_response_code = codes_result.error(); + if (http_response_code > 0) + message += tr("\n\nServer response: HTTP %1.").arg(http_response_code); + + ModalMessageBox::critical(this, tr("Download Failed"), message); return; } + const std::vector& codes = *codes_result; if (codes.empty()) { ModalMessageBox::critical(this, tr("Error"), tr("File contained no codes."));