mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-03-18 19:32:41 +00:00
Merge pull request #14427 from Simonx22/qt/cheats-gecko-download-error-message
DolphinQt: Improve Gecko code download failure message
This commit is contained in:
commit
161f9e82c1
@ -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<Gecko::GeckoCode> codes = Gecko::DownloadCodes(gametdb_id, &success);
|
||||
|
||||
if (!success)
|
||||
const auto codes_result = Gecko::DownloadCodes(gametdb_id);
|
||||
if (!codes_result)
|
||||
return nullptr;
|
||||
const std::vector<Gecko::GeckoCode>& codes = *codes_result;
|
||||
|
||||
const jobjectArray array =
|
||||
env->NewObjectArray(static_cast<jsize>(codes.size()), IDCache::GetGeckoCheatClass(), nullptr);
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
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.
|
||||
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);
|
||||
|
||||
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<GeckoCode> gcodes;
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <expected>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -17,7 +18,7 @@ class IniFile;
|
||||
namespace Gecko
|
||||
{
|
||||
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);
|
||||
|
||||
std::optional<GeckoCode::Code> DeserializeLine(const std::string& line);
|
||||
|
||||
@ -395,16 +395,22 @@ void GeckoCodeWidget::UpdateList()
|
||||
|
||||
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 (!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<Gecko::GeckoCode>& codes = *codes_result;
|
||||
if (codes.empty())
|
||||
{
|
||||
ModalMessageBox::critical(this, tr("Error"), tr("File contained no codes."));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user