mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-13 05:37:42 +02:00
Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into skin_selector
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -38,10 +38,11 @@
|
||||
*/
|
||||
|
||||
#include "NetRequest.h"
|
||||
#include <QUrl>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QFileInfo>
|
||||
#include <QNetworkReply>
|
||||
#include <QUrl>
|
||||
#include <memory>
|
||||
|
||||
#if defined(LAUNCHER_APPLICATION)
|
||||
@ -49,8 +50,6 @@
|
||||
#endif
|
||||
#include "BuildConfig.h"
|
||||
|
||||
#include "net/NetAction.h"
|
||||
|
||||
#include "MMCTime.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
@ -106,7 +105,6 @@ void NetRequest::executeTask()
|
||||
for (auto& header_proxy : m_headerProxies) {
|
||||
header_proxy->writeHeaders(request);
|
||||
}
|
||||
// TODO remove duplication
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
request.setTransferTimeout();
|
||||
@ -115,11 +113,12 @@ void NetRequest::executeTask()
|
||||
m_last_progress_time = m_clock.now();
|
||||
m_last_progress_bytes = 0;
|
||||
|
||||
QNetworkReply* rep = getReply(request);
|
||||
auto rep = getReply(request);
|
||||
if (rep == nullptr) // it failed
|
||||
return;
|
||||
m_reply.reset(rep);
|
||||
connect(rep, &QNetworkReply::downloadProgress, this, &NetRequest::downloadProgress);
|
||||
connect(rep, &QNetworkReply::uploadProgress, this, &NetRequest::onProgress);
|
||||
connect(rep, &QNetworkReply::downloadProgress, this, &NetRequest::onProgress);
|
||||
connect(rep, &QNetworkReply::finished, this, &NetRequest::downloadFinished);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
|
||||
connect(rep, &QNetworkReply::errorOccurred, this, &NetRequest::downloadError);
|
||||
@ -130,7 +129,7 @@ void NetRequest::executeTask()
|
||||
connect(rep, &QNetworkReply::readyRead, this, &NetRequest::downloadReadyRead);
|
||||
}
|
||||
|
||||
void NetRequest::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||
void NetRequest::onProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||
{
|
||||
auto now = m_clock.now();
|
||||
auto elapsed = now - m_last_progress_time;
|
||||
@ -173,7 +172,9 @@ void NetRequest::downloadError(QNetworkReply::NetworkError error)
|
||||
}
|
||||
}
|
||||
// error happened during download.
|
||||
qCCritical(logCat) << getUid().toString() << "Failed " << m_url.toString() << " with reason " << error;
|
||||
qCCritical(logCat) << getUid().toString() << "Failed" << m_url.toString() << "with reason" << error;
|
||||
if (m_reply)
|
||||
qCCritical(logCat) << getUid().toString() << "HTTP Status" << replyStatusCode() << ";error" << errorString();
|
||||
m_state = State::Failed;
|
||||
}
|
||||
}
|
||||
@ -238,7 +239,7 @@ auto NetRequest::handleRedirect() -> bool
|
||||
|
||||
m_url = QUrl(redirect.toString());
|
||||
qCDebug(logCat) << getUid().toString() << "Following redirect to " << m_url.toString();
|
||||
startAction(m_network);
|
||||
executeTask();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -256,21 +257,18 @@ void NetRequest::downloadFinished()
|
||||
{
|
||||
qCDebug(logCat) << getUid().toString() << "Request failed but we are allowed to proceed:" << m_url.toString();
|
||||
m_sink->abort();
|
||||
m_reply.reset();
|
||||
emit succeeded();
|
||||
emit finished();
|
||||
return;
|
||||
} else if (m_state == State::Failed) {
|
||||
qCDebug(logCat) << getUid().toString() << "Request failed in previous step:" << m_url.toString();
|
||||
m_sink->abort();
|
||||
m_reply.reset();
|
||||
emit failed("");
|
||||
emit failed(m_reply->errorString());
|
||||
emit finished();
|
||||
return;
|
||||
} else if (m_state == State::AbortedByUser) {
|
||||
qCDebug(logCat) << getUid().toString() << "Request aborted in previous step:" << m_url.toString();
|
||||
m_sink->abort();
|
||||
m_reply.reset();
|
||||
emit aborted();
|
||||
emit finished();
|
||||
return;
|
||||
@ -284,7 +282,7 @@ void NetRequest::downloadFinished()
|
||||
if (m_state != State::Succeeded) {
|
||||
qCDebug(logCat) << getUid().toString() << "Request failed to write:" << m_url.toString();
|
||||
m_sink->abort();
|
||||
emit failed("");
|
||||
emit failed("failed to write in sink");
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
@ -295,13 +293,11 @@ void NetRequest::downloadFinished()
|
||||
if (m_state != State::Succeeded) {
|
||||
qCDebug(logCat) << getUid().toString() << "Request failed to finalize:" << m_url.toString();
|
||||
m_sink->abort();
|
||||
m_reply.reset();
|
||||
emit failed("");
|
||||
emit failed("failed to finalize the request");
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
|
||||
m_reply.reset();
|
||||
qCDebug(logCat) << getUid().toString() << "Request succeeded:" << m_url.toString();
|
||||
emit succeeded();
|
||||
emit finished();
|
||||
@ -335,4 +331,23 @@ auto NetRequest::abort() -> bool
|
||||
return true;
|
||||
}
|
||||
|
||||
int NetRequest::replyStatusCode() const
|
||||
{
|
||||
return m_reply ? m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() : -1;
|
||||
}
|
||||
|
||||
QNetworkReply::NetworkError NetRequest::error() const
|
||||
{
|
||||
return m_reply ? m_reply->error() : QNetworkReply::NoError;
|
||||
}
|
||||
|
||||
QUrl NetRequest::url() const
|
||||
{
|
||||
return m_url;
|
||||
}
|
||||
|
||||
QString NetRequest::errorString() const
|
||||
{
|
||||
return m_reply ? m_reply->errorString() : "";
|
||||
}
|
||||
} // namespace Net
|
||||
|
Reference in New Issue
Block a user