Qt: attempt to download up to 3 times on return_code -255
Some checks are pending
Generate Translation Template / Generate Translation Template (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (/rpcs3/.ci/build-linux-aarch64.sh, gcc, rpcs3/rpcs3-ci-jammy-aarch64:1.9, ubuntu-24.04-arm) (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (/rpcs3/.ci/build-linux.sh, gcc, rpcs3/rpcs3-ci-jammy:1.9, ubuntu-24.04) (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (a1d35836e8d45bfc6f63c26f0a3e5d46ef622fe1, rpcs3/rpcs3-binaries-linux-arm64, /rpcs3/.ci/build-linux-aarch64.sh, clang, rpcs3/rpcs3-ci-jammy-aarch64:1.9, ubuntu-24.04-arm) (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (d812f1254a1157c80fd402f94446310560f54e5f, rpcs3/rpcs3-binaries-linux, /rpcs3/.ci/build-linux.sh, clang, rpcs3/rpcs3-ci-jammy:1.9, ubuntu-24.04) (push) Waiting to run
Build RPCS3 / RPCS3 Mac ${{ matrix.name }} (0, 51ae32f468089a8169aaf1567de355ff4a3e0842, rpcs3/rpcs3-binaries-mac, Intel) (push) Waiting to run
Build RPCS3 / RPCS3 Mac ${{ matrix.name }} (1, 8e21bdbc40711a3fccd18fbf17b742348b0f4281, rpcs3/rpcs3-binaries-mac-arm64, Apple Silicon) (push) Waiting to run
Build RPCS3 / RPCS3 Windows (push) Waiting to run
Build RPCS3 / RPCS3 Windows Clang ${{ matrix.arch }} (aarch64, clang, clangarm64, ARM64, windows-11-arm) (push) Waiting to run
Build RPCS3 / RPCS3 Windows Clang ${{ matrix.arch }} (x86_64, clang, clang64, X64, windows-2025) (push) Waiting to run
Build RPCS3 / RPCS3 FreeBSD (push) Waiting to run

This commit is contained in:
Megamouse 2026-02-28 12:36:43 +01:00
parent df5b624e45
commit 198c2e9eb8
6 changed files with 54 additions and 25 deletions

View file

@ -1,5 +1,6 @@
#include <QApplication>
#include <QThread>
#include <QJsonObject>
#include "downloader.h"
#include "curl_handle.h"
@ -7,6 +8,8 @@
#include "util/logs.hpp"
#include <thread>
LOG_CHANNEL(network_log, "NET");
usz curl_write_cb_compat(char* ptr, usz /*size*/, usz nmemb, void* userdata)
@ -31,7 +34,7 @@ downloader::~downloader()
}
}
void downloader::start(const std::string& url, bool follow_location, bool show_progress_dialog, const QString& progress_dialog_title, bool keep_progress_dialog_open, int expected_size)
void downloader::start(const std::string& url, bool follow_location, bool show_progress_dialog, const QString& progress_dialog_title, bool keep_progress_dialog_open, int expected_size, bool check_return_code, bool again)
{
network_log.notice("Starting download from URL: %s", url);
@ -49,6 +52,21 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p
m_curl_buf.clear();
m_curl_abort = false;
if (again)
{
m_download_attempts++;
if (m_progress_dialog && m_download_attempts > 1)
{
handle_buffer_update(0, 100);
m_progress_dialog->setLabelText(tr("Please wait... Trying again"));
}
}
else
{
m_download_attempts = 1;
}
CURLcode err = curl_easy_setopt(m_curl->get_curl(), CURLOPT_URL, url.c_str());
if (err != CURLE_OK) network_log.error("curl_easy_setopt(CURLOPT_URL, %s) error: %s", url, curl_easy_strerror(err));
@ -77,7 +95,7 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p
}
});
connect(m_thread, &QThread::finished, this, [this]()
connect(m_thread, &QThread::finished, this, [=, this]()
{
if (m_curl_abort)
{
@ -93,6 +111,21 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p
if (m_curl_success)
{
network_log.notice("Download finished");
if (check_return_code && m_download_attempts < 3)
{
const QJsonObject json_data = QJsonDocument::fromJson(m_curl_buf).object();
const int return_code = json_data["return_code"].toInt(-255);
if (return_code == -255)
{
network_log.error("Error during download. Trying to download again (attempts=%d, return_code=%d)", m_download_attempts, return_code);
std::this_thread::sleep_for(500ms); // Wait for a little while
start(url, follow_location, show_progress_dialog, progress_dialog_title, keep_progress_dialog_open, expected_size, check_return_code, true);
return;
}
}
Q_EMIT signal_download_finished(m_curl_buf);
}
});

View file

@ -21,7 +21,7 @@ public:
explicit downloader(QWidget* parent = nullptr);
~downloader();
void start(const std::string& url, bool follow_location, bool show_progress_dialog, const QString& progress_dialog_title = "", bool keep_progress_dialog_open = false, int expected_size = -1);
void start(const std::string& url, bool follow_location, bool show_progress_dialog, const QString& progress_dialog_title = "", bool keep_progress_dialog_open = false, int expected_size = -1, bool check_return_code = true, bool again = false);
usz update_buffer(char* data, usz size);
void update_progress_dialog(const QString& title) const;
@ -46,6 +46,7 @@ private:
atomic_t<bool> m_curl_abort = false;
atomic_t<bool> m_curl_success = false;
double m_actual_download_size = -1.0;
u32 m_download_attempts = 0;
progress_dialog* m_progress_dialog = nullptr;
atomic_t<bool> m_keep_progress_dialog_open = false;

View file

@ -69,7 +69,7 @@ void game_compatibility::handle_download_canceled()
bool game_compatibility::ReadJSON(const QJsonObject& json_data, bool after_download)
{
const int return_code = json_data["return_code"].toInt();
const int return_code = json_data["return_code"].toInt(-255);
if (return_code < 0)
{
@ -78,15 +78,10 @@ bool game_compatibility::ReadJSON(const QJsonObject& json_data, bool after_downl
std::string error_message;
switch (return_code)
{
case -1:
error_message = "Server Error - Internal Error";
break;
case -2:
error_message = "Server Error - Maintenance Mode";
break;
default:
error_message = "Server Error - Unknown Error";
break;
case -1: error_message = "Server Error - Internal Error"; break;
case -2: error_message = "Server Error - Maintenance Mode"; break;
case -255: error_message = "Server Error - Return code not found"; break;
default: error_message = "Server Error - Unknown Error"; break;
}
compat_log.error("%s: return code %d", error_message, return_code);
Q_EMIT DownloadError(QString::fromStdString(error_message) + " " + QString::number(return_code));

View file

@ -1184,9 +1184,9 @@ bool patch_manager_dialog::handle_json(const QByteArray& data)
}
if (return_code != -1)
patch_log.error("Patch download error: %s return code: %d", error_message, return_code);
patch_log.error("Patch download error: %s, return code: %d", error_message, return_code);
else
patch_log.warning("Patch download error: %s return code: %d", error_message, return_code);
patch_log.warning("Patch download error: %s, return code: %d", error_message, return_code);
return false;
}

View file

@ -135,9 +135,9 @@ bool update_manager::handle_json(bool automatic, bool check_only, bool auto_acce
}
if (return_code != -1)
update_log.error("Update error: %s return code: %d", error_message, return_code);
update_log.error("Update error: %s, return code: %d", error_message, return_code);
else
update_log.warning("Update error: %s return code: %d", error_message, return_code);
update_log.warning("Update error: %s, return code: %d", error_message, return_code);
// If a user clicks "Check for Updates" with a custom build ask him if he's sure he wants to update to latest version
if (!automatic && return_code == -1)

View file

@ -13,6 +13,14 @@ class update_manager final : public QObject
{
Q_OBJECT
public:
update_manager(QObject* parent, std::shared_ptr<gui_settings> gui_settings);
void check_for_updates(bool automatic, bool check_only, bool auto_accept, QWidget* parent = nullptr);
void update(bool auto_accept);
Q_SIGNALS:
void signal_update_available(bool update_available);
private:
downloader* m_downloader = nullptr;
QWidget* m_parent = nullptr;
@ -45,12 +53,4 @@ private:
bool handle_json(bool automatic, bool check_only, bool auto_accept, const QByteArray& data);
bool handle_rpcs3(const QByteArray& data, bool auto_accept);
public:
update_manager(QObject* parent, std::shared_ptr<gui_settings> gui_settings);
void check_for_updates(bool automatic, bool check_only, bool auto_accept, QWidget* parent = nullptr);
void update(bool auto_accept);
Q_SIGNALS:
void signal_update_available(bool update_available);
};