Merge pull request #14427 from Simonx22/qt/cheats-gecko-download-error-message

DolphinQt: Improve Gecko code download failure message
This commit is contained in:
JMC47 2026-03-12 15:25:41 -04:00 committed by GitHub
commit 161f9e82c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 13 deletions

View File

@ -190,11 +190,10 @@ Java_org_dolphinemu_dolphinemu_features_cheats_model_GeckoCheat_downloadCodes(JN
{ {
const std::string gametdb_id = GetJString(env, jGameTdbId); const std::string gametdb_id = GetJString(env, jGameTdbId);
bool success = true; const auto codes_result = Gecko::DownloadCodes(gametdb_id);
const std::vector<Gecko::GeckoCode> codes = Gecko::DownloadCodes(gametdb_id, &success); if (!codes_result)
if (!success)
return nullptr; return nullptr;
const std::vector<Gecko::GeckoCode>& codes = *codes_result;
const jobjectArray array = const jobjectArray array =
env->NewObjectArray(static_cast<jsize>(codes.size()), IDCache::GetGeckoCheatClass(), nullptr); env->NewObjectArray(static_cast<jsize>(codes.size()), IDCache::GetGeckoCheatClass(), nullptr);

View File

@ -15,7 +15,7 @@
namespace Gecko namespace Gecko
{ {
std::vector<GeckoCode> DownloadCodes(std::string gametdb_id, bool* succeeded) std::expected<std::vector<GeckoCode>, int> DownloadCodes(std::string gametdb_id)
{ {
// codes.rc24.xyz is a mirror of the now defunct geckocodes.org. // codes.rc24.xyz is a mirror of the now defunct geckocodes.org.
std::string endpoint{"https://codes.rc24.xyz/txt.php?txt=" + gametdb_id}; std::string endpoint{"https://codes.rc24.xyz/txt.php?txt=" + gametdb_id};
@ -25,9 +25,8 @@ std::vector<GeckoCode> DownloadCodes(std::string gametdb_id, bool* succeeded)
http.FollowRedirects(1); http.FollowRedirects(1);
const Common::HttpRequest::Response response = http.Get(endpoint); const Common::HttpRequest::Response response = http.Get(endpoint);
*succeeded = response.has_value();
if (!response) if (!response)
return {}; return std::unexpected{http.GetLastResponseCode()};
// temp vector containing parsed codes // temp vector containing parsed codes
std::vector<GeckoCode> gcodes; std::vector<GeckoCode> gcodes;

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include <expected>
#include <optional> #include <optional>
#include <string> #include <string>
#include <vector> #include <vector>
@ -17,7 +18,7 @@ class IniFile;
namespace Gecko namespace Gecko
{ {
std::vector<GeckoCode> LoadCodes(const Common::IniFile& globalIni, const Common::IniFile& localIni); std::vector<GeckoCode> LoadCodes(const Common::IniFile& globalIni, const Common::IniFile& localIni);
std::vector<GeckoCode> DownloadCodes(std::string gametdb_id, bool* succeeded); std::expected<std::vector<GeckoCode>, int> DownloadCodes(std::string gametdb_id);
void SaveCodes(Common::IniFile& inifile, const std::vector<GeckoCode>& gcodes); void SaveCodes(Common::IniFile& inifile, const std::vector<GeckoCode>& gcodes);
std::optional<GeckoCode::Code> DeserializeLine(const std::string& line); std::optional<GeckoCode::Code> DeserializeLine(const std::string& line);

View File

@ -395,16 +395,22 @@ void GeckoCodeWidget::UpdateList()
void GeckoCodeWidget::DownloadCodes() void GeckoCodeWidget::DownloadCodes()
{ {
bool success; const auto codes_result = Gecko::DownloadCodes(m_gametdb_id);
std::vector<Gecko::GeckoCode> codes = Gecko::DownloadCodes(m_gametdb_id, &success); if (!codes_result)
if (!success)
{ {
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; return;
} }
const std::vector<Gecko::GeckoCode>& codes = *codes_result;
if (codes.empty()) if (codes.empty())
{ {
ModalMessageBox::critical(this, tr("Error"), tr("File contained no codes.")); ModalMessageBox::critical(this, tr("Error"), tr("File contained no codes."));