refactored skin apis
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
c01e95b79c
commit
609eaa67ab
@ -139,6 +139,7 @@ set(NET_SOURCES
|
|||||||
net/HeaderProxy.h
|
net/HeaderProxy.h
|
||||||
net/RawHeaderProxy.h
|
net/RawHeaderProxy.h
|
||||||
net/ApiHeaderProxy.h
|
net/ApiHeaderProxy.h
|
||||||
|
net/StaticHeaderProxy.h
|
||||||
net/ApiDownload.h
|
net/ApiDownload.h
|
||||||
net/ApiDownload.cpp
|
net/ApiDownload.cpp
|
||||||
net/ApiUpload.cpp
|
net/ApiUpload.cpp
|
||||||
|
@ -35,87 +35,38 @@
|
|||||||
|
|
||||||
#include "CapeChange.h"
|
#include "CapeChange.h"
|
||||||
|
|
||||||
#include <QHttpMultiPart>
|
#include <memory>
|
||||||
#include <QNetworkRequest>
|
|
||||||
|
|
||||||
#include "Application.h"
|
#include "net/ByteArraySink.h"
|
||||||
|
#include "net/StaticHeaderProxy.h"
|
||||||
|
|
||||||
CapeChange::CapeChange(QObject* parent, QString token, QString cape) : Task(parent), m_capeId(cape), m_token(token) {}
|
CapeChange::CapeChange(QString token, QString cape) : NetRequest(), m_capeId(cape), m_token(token)
|
||||||
|
|
||||||
void CapeChange::setCape([[maybe_unused]] QString& cape)
|
|
||||||
{
|
{
|
||||||
QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/capes/active"));
|
logCat = taskMCServicesLogC;
|
||||||
auto requestString = QString("{\"capeId\":\"%1\"}").arg(m_capeId);
|
};
|
||||||
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit());
|
|
||||||
QNetworkReply* rep = APPLICATION->network()->put(request, requestString.toUtf8());
|
|
||||||
|
|
||||||
setStatus(tr("Equipping cape"));
|
QNetworkReply* CapeChange::getReply(QNetworkRequest& request)
|
||||||
|
|
||||||
m_reply = shared_qobject_ptr<QNetworkReply>(rep);
|
|
||||||
connect(rep, &QNetworkReply::uploadProgress, this, &CapeChange::setProgress);
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
|
|
||||||
connect(rep, &QNetworkReply::errorOccurred, this, &CapeChange::downloadError);
|
|
||||||
#else
|
|
||||||
connect(rep, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &CapeChange::downloadError);
|
|
||||||
#endif
|
|
||||||
connect(rep, &QNetworkReply::sslErrors, this, &CapeChange::sslErrors);
|
|
||||||
connect(rep, &QNetworkReply::finished, this, &CapeChange::downloadFinished);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CapeChange::clearCape()
|
|
||||||
{
|
|
||||||
QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/capes/active"));
|
|
||||||
auto requestString = QString("{\"capeId\":\"%1\"}").arg(m_capeId);
|
|
||||||
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit());
|
|
||||||
QNetworkReply* rep = APPLICATION->network()->deleteResource(request);
|
|
||||||
|
|
||||||
setStatus(tr("Removing cape"));
|
|
||||||
|
|
||||||
m_reply = shared_qobject_ptr<QNetworkReply>(rep);
|
|
||||||
connect(rep, &QNetworkReply::uploadProgress, this, &CapeChange::setProgress);
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
|
|
||||||
connect(rep, &QNetworkReply::errorOccurred, this, &CapeChange::downloadError);
|
|
||||||
#else
|
|
||||||
connect(rep, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &CapeChange::downloadError);
|
|
||||||
#endif
|
|
||||||
connect(rep, &QNetworkReply::sslErrors, this, &CapeChange::sslErrors);
|
|
||||||
connect(rep, &QNetworkReply::finished, this, &CapeChange::downloadFinished);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CapeChange::executeTask()
|
|
||||||
{
|
{
|
||||||
if (m_capeId.isEmpty()) {
|
if (m_capeId.isEmpty()) {
|
||||||
clearCape();
|
setStatus(tr("Removing cape"));
|
||||||
|
return m_network->deleteResource(request);
|
||||||
} else {
|
} else {
|
||||||
setCape(m_capeId);
|
setStatus(tr("Equipping cape"));
|
||||||
|
return m_network->post(request, QString("{\"capeId\":\"%1\"}").arg(m_capeId).toUtf8());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CapeChange::downloadError(QNetworkReply::NetworkError error)
|
void CapeChange::init()
|
||||||
{
|
{
|
||||||
// error happened during download.
|
addHeaderProxy(new Net::StaticHeaderProxy(QList<Net::HeaderPair>{
|
||||||
qCritical() << "Network error: " << error;
|
{ "Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit() },
|
||||||
emitFailed(m_reply->errorString());
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CapeChange::sslErrors(const QList<QSslError>& errors)
|
CapeChange::Ptr CapeChange::make(QString token, QString capeId)
|
||||||
{
|
{
|
||||||
int i = 1;
|
auto up = makeShared<CapeChange>(token, capeId);
|
||||||
for (auto error : errors) {
|
up->m_url = QUrl("https://api.minecraftservices.com/minecraft/profile/capes/active");
|
||||||
qCritical() << "Cape change SSL Error #" << i << " : " << error.errorString();
|
up->m_sink.reset(new Net::ByteArraySink(std::make_shared<QByteArray>()));
|
||||||
auto cert = error.certificate();
|
return up;
|
||||||
qCritical() << "Certificate in question:\n" << cert.toText();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CapeChange::downloadFinished()
|
|
||||||
{
|
|
||||||
// if the download failed
|
|
||||||
if (m_reply->error() != QNetworkReply::NetworkError::NoError) {
|
|
||||||
emitFailed(QString("Network error: %1").arg(m_reply->errorString()));
|
|
||||||
m_reply.reset();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
emitSucceeded();
|
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,21 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QFile>
|
#include "net/NetRequest.h"
|
||||||
#include <QtNetwork/QtNetwork>
|
|
||||||
#include <memory>
|
|
||||||
#include "QObjectPtr.h"
|
|
||||||
#include "tasks/Task.h"
|
|
||||||
|
|
||||||
class CapeChange : public Task {
|
class CapeChange : public Net::NetRequest {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CapeChange(QObject* parent, QString token, QString capeId);
|
using Ptr = shared_qobject_ptr<CapeChange>;
|
||||||
virtual ~CapeChange() {}
|
CapeChange(QString token, QString capeId);
|
||||||
|
virtual ~CapeChange() = default;
|
||||||
|
|
||||||
private:
|
static CapeChange::Ptr make(QString token, QString capeId);
|
||||||
void setCape(QString& cape);
|
void init() override;
|
||||||
void clearCape();
|
|
||||||
|
protected:
|
||||||
|
virtual QNetworkReply* getReply(QNetworkRequest&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_capeId;
|
QString m_capeId;
|
||||||
QString m_token;
|
QString m_token;
|
||||||
shared_qobject_ptr<QNetworkReply> m_reply;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void executeTask();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void downloadError(QNetworkReply::NetworkError);
|
|
||||||
void sslErrors(const QList<QSslError>& errors);
|
|
||||||
void downloadFinished();
|
|
||||||
};
|
};
|
||||||
|
@ -35,56 +35,31 @@
|
|||||||
|
|
||||||
#include "SkinDelete.h"
|
#include "SkinDelete.h"
|
||||||
|
|
||||||
#include <QHttpMultiPart>
|
#include "net/ByteArraySink.h"
|
||||||
#include <QNetworkRequest>
|
#include "net/StaticHeaderProxy.h"
|
||||||
|
|
||||||
#include "Application.h"
|
SkinDelete::SkinDelete(QString token) : NetRequest(), m_token(token)
|
||||||
|
|
||||||
SkinDelete::SkinDelete(QObject* parent, QString token) : Task(parent), m_token(token) {}
|
|
||||||
|
|
||||||
void SkinDelete::executeTask()
|
|
||||||
{
|
{
|
||||||
QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/skins/active"));
|
logCat = taskMCServicesLogC;
|
||||||
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit());
|
};
|
||||||
QNetworkReply* rep = APPLICATION->network()->deleteResource(request);
|
|
||||||
m_reply = shared_qobject_ptr<QNetworkReply>(rep);
|
|
||||||
|
|
||||||
|
QNetworkReply* SkinDelete::getReply(QNetworkRequest& request)
|
||||||
|
{
|
||||||
setStatus(tr("Deleting skin"));
|
setStatus(tr("Deleting skin"));
|
||||||
connect(rep, &QNetworkReply::uploadProgress, this, &SkinDelete::setProgress);
|
return m_network->deleteResource(request);
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
|
|
||||||
connect(rep, &QNetworkReply::errorOccurred, this, &SkinDelete::downloadError);
|
|
||||||
#else
|
|
||||||
connect(rep, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &SkinDelete::downloadError);
|
|
||||||
#endif
|
|
||||||
connect(rep, &QNetworkReply::sslErrors, this, &SkinDelete::sslErrors);
|
|
||||||
connect(rep, &QNetworkReply::finished, this, &SkinDelete::downloadFinished);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkinDelete::downloadError(QNetworkReply::NetworkError error)
|
void SkinDelete::init()
|
||||||
{
|
{
|
||||||
// error happened during download.
|
addHeaderProxy(new Net::StaticHeaderProxy(QList<Net::HeaderPair>{
|
||||||
qCritical() << "Network error: " << error;
|
{ "Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit() },
|
||||||
emitFailed(m_reply->errorString());
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkinDelete::sslErrors(const QList<QSslError>& errors)
|
SkinDelete::Ptr SkinDelete::make(QString token)
|
||||||
{
|
{
|
||||||
int i = 1;
|
auto up = makeShared<SkinDelete>(token);
|
||||||
for (auto error : errors) {
|
up->m_url = QUrl("https://api.minecraftservices.com/minecraft/profile/skins/active");
|
||||||
qCritical() << "Skin Delete SSL Error #" << i << " : " << error.errorString();
|
up->m_sink.reset(new Net::ByteArraySink(std::make_shared<QByteArray>()));
|
||||||
auto cert = error.certificate();
|
return up;
|
||||||
qCritical() << "Certificate in question:\n" << cert.toText();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SkinDelete::downloadFinished()
|
|
||||||
{
|
|
||||||
// if the download failed
|
|
||||||
if (m_reply->error() != QNetworkReply::NetworkError::NoError) {
|
|
||||||
emitFailed(QString("Network error: %1").arg(m_reply->errorString()));
|
|
||||||
m_reply.reset();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
emitSucceeded();
|
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QFile>
|
#include "net/NetRequest.h"
|
||||||
#include <QtNetwork/QtNetwork>
|
|
||||||
#include "tasks/Task.h"
|
|
||||||
|
|
||||||
typedef shared_qobject_ptr<class SkinDelete> SkinDeletePtr;
|
class SkinDelete : public Net::NetRequest {
|
||||||
|
|
||||||
class SkinDelete : public Task {
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SkinDelete(QObject* parent, QString token);
|
using Ptr = shared_qobject_ptr<SkinDelete>;
|
||||||
|
SkinDelete(QString token);
|
||||||
virtual ~SkinDelete() = default;
|
virtual ~SkinDelete() = default;
|
||||||
|
|
||||||
|
static SkinDelete::Ptr make(QString token);
|
||||||
|
void init() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual QNetworkReply* getReply(QNetworkRequest&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_token;
|
QString m_token;
|
||||||
shared_qobject_ptr<QNetworkReply> m_reply;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void executeTask();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void downloadError(QNetworkReply::NetworkError);
|
|
||||||
void sslErrors(const QList<QSslError>& errors);
|
|
||||||
void downloadFinished();
|
|
||||||
};
|
};
|
||||||
|
@ -36,30 +36,17 @@
|
|||||||
#include "SkinUpload.h"
|
#include "SkinUpload.h"
|
||||||
|
|
||||||
#include <QHttpMultiPart>
|
#include <QHttpMultiPart>
|
||||||
#include <QNetworkRequest>
|
|
||||||
|
|
||||||
#include "Application.h"
|
#include "net/ByteArraySink.h"
|
||||||
|
#include "net/StaticHeaderProxy.h"
|
||||||
|
|
||||||
QByteArray getVariant(SkinUpload::Model model)
|
SkinUpload::SkinUpload(QString token, QByteArray skin, SkinUpload::Model model) : NetRequest(), m_model(model), m_skin(skin), m_token(token)
|
||||||
{
|
{
|
||||||
switch (model) {
|
logCat = taskMCServicesLogC;
|
||||||
default:
|
};
|
||||||
qDebug() << "Unknown skin type!";
|
|
||||||
case SkinUpload::STEVE:
|
|
||||||
return "CLASSIC";
|
|
||||||
case SkinUpload::ALEX:
|
|
||||||
return "SLIM";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SkinUpload::SkinUpload(QObject* parent, QString token, QByteArray skin, SkinUpload::Model model)
|
QNetworkReply* SkinUpload::getReply(QNetworkRequest& request)
|
||||||
: Task(parent), m_model(model), m_skin(skin), m_token(token)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void SkinUpload::executeTask()
|
|
||||||
{
|
{
|
||||||
QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/skins"));
|
|
||||||
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit());
|
|
||||||
QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
||||||
|
|
||||||
QHttpPart skin;
|
QHttpPart skin;
|
||||||
@ -69,50 +56,37 @@ void SkinUpload::executeTask()
|
|||||||
|
|
||||||
QHttpPart model;
|
QHttpPart model;
|
||||||
model.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"variant\""));
|
model.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"variant\""));
|
||||||
model.setBody(getVariant(m_model));
|
|
||||||
|
switch (m_model) {
|
||||||
|
default:
|
||||||
|
qDebug() << "Unknown skin type!";
|
||||||
|
emitFailed("Unknown skin type!");
|
||||||
|
return nullptr;
|
||||||
|
case SkinUpload::STEVE:
|
||||||
|
model.setBody("CLASSIC");
|
||||||
|
break;
|
||||||
|
case SkinUpload::ALEX:
|
||||||
|
model.setBody("SLIM");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
multiPart->append(skin);
|
multiPart->append(skin);
|
||||||
multiPart->append(model);
|
multiPart->append(model);
|
||||||
|
|
||||||
QNetworkReply* rep = APPLICATION->network()->post(request, multiPart);
|
|
||||||
m_reply = shared_qobject_ptr<QNetworkReply>(rep);
|
|
||||||
|
|
||||||
setStatus(tr("Uploading skin"));
|
setStatus(tr("Uploading skin"));
|
||||||
connect(rep, &QNetworkReply::uploadProgress, this, &SkinUpload::setProgress);
|
return m_network->post(request, multiPart);
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
|
|
||||||
connect(rep, &QNetworkReply::errorOccurred, this, &SkinUpload::downloadError);
|
|
||||||
#else
|
|
||||||
connect(rep, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &SkinUpload::downloadError);
|
|
||||||
#endif
|
|
||||||
connect(rep, &QNetworkReply::sslErrors, this, &SkinUpload::sslErrors);
|
|
||||||
connect(rep, &QNetworkReply::finished, this, &SkinUpload::downloadFinished);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkinUpload::downloadError(QNetworkReply::NetworkError error)
|
void SkinUpload::init()
|
||||||
{
|
{
|
||||||
// error happened during download.
|
addHeaderProxy(new Net::StaticHeaderProxy(QList<Net::HeaderPair>{
|
||||||
qCritical() << "Network error: " << error;
|
{ "Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit() },
|
||||||
emitFailed(m_reply->errorString());
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkinUpload::sslErrors(const QList<QSslError>& errors)
|
SkinUpload::Ptr SkinUpload::make(QString token, QByteArray skin, SkinUpload::Model model)
|
||||||
{
|
{
|
||||||
int i = 1;
|
auto up = makeShared<SkinUpload>(token, skin, model);
|
||||||
for (auto error : errors) {
|
up->m_url = QUrl("https://api.minecraftservices.com/minecraft/profile/skins");
|
||||||
qCritical() << "Skin Upload SSL Error #" << i << " : " << error.errorString();
|
up->m_sink.reset(new Net::ByteArraySink(std::make_shared<QByteArray>()));
|
||||||
auto cert = error.certificate();
|
return up;
|
||||||
qCritical() << "Certificate in question:\n" << cert.toText();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SkinUpload::downloadFinished()
|
|
||||||
{
|
|
||||||
// if the download failed
|
|
||||||
if (m_reply->error() != QNetworkReply::NetworkError::NoError) {
|
|
||||||
emitFailed(QString("Network error: %1").arg(m_reply->errorString()));
|
|
||||||
m_reply.reset();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
emitSucceeded();
|
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,25 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QFile>
|
#include "net/NetRequest.h"
|
||||||
#include <QtNetwork/QtNetwork>
|
|
||||||
#include <memory>
|
|
||||||
#include "tasks/Task.h"
|
|
||||||
|
|
||||||
typedef shared_qobject_ptr<class SkinUpload> SkinUploadPtr;
|
class SkinUpload : public Net::NetRequest {
|
||||||
|
|
||||||
class SkinUpload : public Task {
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
using Ptr = shared_qobject_ptr<SkinUpload>;
|
||||||
enum Model { STEVE, ALEX };
|
enum Model { STEVE, ALEX };
|
||||||
|
|
||||||
// Note this class takes ownership of the file.
|
// Note this class takes ownership of the file.
|
||||||
SkinUpload(QObject* parent, QString token, QByteArray skin, Model model = STEVE);
|
SkinUpload(QString token, QByteArray skin, Model model = STEVE);
|
||||||
virtual ~SkinUpload() {}
|
virtual ~SkinUpload() = default;
|
||||||
|
|
||||||
|
static SkinUpload::Ptr make(QString token, QByteArray skin, Model model = STEVE);
|
||||||
|
void init() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual QNetworkReply* getReply(QNetworkRequest&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Model m_model;
|
Model m_model;
|
||||||
QByteArray m_skin;
|
QByteArray m_skin;
|
||||||
QString m_token;
|
QString m_token;
|
||||||
shared_qobject_ptr<QNetworkReply> m_reply;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void executeTask();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
|
|
||||||
void downloadError(QNetworkReply::NetworkError);
|
|
||||||
void sslErrors(const QList<QSslError>& errors);
|
|
||||||
|
|
||||||
void downloadFinished();
|
|
||||||
};
|
};
|
||||||
|
@ -22,5 +22,6 @@
|
|||||||
Q_LOGGING_CATEGORY(taskNetLogC, "launcher.task.net")
|
Q_LOGGING_CATEGORY(taskNetLogC, "launcher.task.net")
|
||||||
Q_LOGGING_CATEGORY(taskDownloadLogC, "launcher.task.net.download")
|
Q_LOGGING_CATEGORY(taskDownloadLogC, "launcher.task.net.download")
|
||||||
Q_LOGGING_CATEGORY(taskUploadLogC, "launcher.task.net.upload")
|
Q_LOGGING_CATEGORY(taskUploadLogC, "launcher.task.net.upload")
|
||||||
|
Q_LOGGING_CATEGORY(taskMCServicesLogC, "launcher.task.minecraft.servicies")
|
||||||
Q_LOGGING_CATEGORY(taskMetaCacheLogC, "launcher.task.net.metacache")
|
Q_LOGGING_CATEGORY(taskMetaCacheLogC, "launcher.task.net.metacache")
|
||||||
Q_LOGGING_CATEGORY(taskHttpMetaCacheLogC, "launcher.task.net.metacache.http")
|
Q_LOGGING_CATEGORY(taskHttpMetaCacheLogC, "launcher.task.net.metacache.http")
|
||||||
|
@ -24,5 +24,6 @@
|
|||||||
Q_DECLARE_LOGGING_CATEGORY(taskNetLogC)
|
Q_DECLARE_LOGGING_CATEGORY(taskNetLogC)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(taskDownloadLogC)
|
Q_DECLARE_LOGGING_CATEGORY(taskDownloadLogC)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(taskUploadLogC)
|
Q_DECLARE_LOGGING_CATEGORY(taskUploadLogC)
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(taskMCServicesLogC)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(taskMetaCacheLogC)
|
Q_DECLARE_LOGGING_CATEGORY(taskMetaCacheLogC)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(taskHttpMetaCacheLogC)
|
Q_DECLARE_LOGGING_CATEGORY(taskHttpMetaCacheLogC)
|
||||||
|
@ -111,6 +111,8 @@ void NetRequest::executeTask()
|
|||||||
m_last_progress_bytes = 0;
|
m_last_progress_bytes = 0;
|
||||||
|
|
||||||
QNetworkReply* rep = getReply(request);
|
QNetworkReply* rep = getReply(request);
|
||||||
|
if (rep == nullptr) // it failed
|
||||||
|
return;
|
||||||
m_reply.reset(rep);
|
m_reply.reset(rep);
|
||||||
connect(rep, &QNetworkReply::downloadProgress, this, &NetRequest::downloadProgress);
|
connect(rep, &QNetworkReply::downloadProgress, this, &NetRequest::downloadProgress);
|
||||||
connect(rep, &QNetworkReply::finished, this, &NetRequest::downloadFinished);
|
connect(rep, &QNetworkReply::finished, this, &NetRequest::downloadFinished);
|
||||||
|
39
launcher/net/StaticHeaderProxy.h
Normal file
39
launcher/net/StaticHeaderProxy.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "net/HeaderProxy.h"
|
||||||
|
|
||||||
|
namespace Net {
|
||||||
|
|
||||||
|
class StaticHeaderProxy : public HeaderProxy {
|
||||||
|
public:
|
||||||
|
StaticHeaderProxy(QList<HeaderPair> hdrs = {}) : HeaderProxy(), m_hdrs(hdrs){};
|
||||||
|
virtual ~StaticHeaderProxy() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual QList<HeaderPair> headers(const QNetworkRequest&) const override { return m_hdrs; };
|
||||||
|
void setHeaders(QList<HeaderPair> hdrs) { m_hdrs = hdrs; };
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<HeaderPair> m_hdrs;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Net
|
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QMimeDatabase>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include <FileSystem.h>
|
#include <FileSystem.h>
|
||||||
@ -101,12 +102,12 @@ void SkinUploadDialog::on_buttonBox_accepted()
|
|||||||
} else if (ui->alexBtn->isChecked()) {
|
} else if (ui->alexBtn->isChecked()) {
|
||||||
model = SkinUpload::ALEX;
|
model = SkinUpload::ALEX;
|
||||||
}
|
}
|
||||||
skinUpload.addTask(shared_qobject_ptr<SkinUpload>(new SkinUpload(this, m_acct->accessToken(), FS::read(fileName), model)));
|
skinUpload.addTask(SkinUpload::make(m_acct->accessToken(), FS::read(fileName), model));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto selectedCape = ui->capeCombo->currentData().toString();
|
auto selectedCape = ui->capeCombo->currentData().toString();
|
||||||
if (selectedCape != m_acct->accountData()->minecraftProfile.currentCape) {
|
if (selectedCape != m_acct->accountData()->minecraftProfile.currentCape) {
|
||||||
skinUpload.addTask(shared_qobject_ptr<CapeChange>(new CapeChange(this, m_acct->accessToken(), selectedCape)));
|
skinUpload.addTask(CapeChange::make(m_acct->accessToken(), selectedCape));
|
||||||
}
|
}
|
||||||
if (prog.execWithTask(&skinUpload) != QDialog::Accepted) {
|
if (prog.execWithTask(&skinUpload) != QDialog::Accepted) {
|
||||||
CustomMessageBox::selectable(this, tr("Skin Upload"), tr("Failed to upload skin!"), QMessageBox::Warning)->exec();
|
CustomMessageBox::selectable(this, tr("Skin Upload"), tr("Failed to upload skin!"), QMessageBox::Warning)->exec();
|
||||||
|
@ -268,7 +268,7 @@ void AccountListPage::on_actionDeleteSkin_triggered()
|
|||||||
QModelIndex selected = selection.first();
|
QModelIndex selected = selection.first();
|
||||||
MinecraftAccountPtr account = selected.data(AccountList::PointerRole).value<MinecraftAccountPtr>();
|
MinecraftAccountPtr account = selected.data(AccountList::PointerRole).value<MinecraftAccountPtr>();
|
||||||
ProgressDialog prog(this);
|
ProgressDialog prog(this);
|
||||||
auto deleteSkinTask = std::make_shared<SkinDelete>(this, account->accessToken());
|
auto deleteSkinTask = SkinDelete::make(account->accessToken());
|
||||||
if (prog.execWithTask((Task*)deleteSkinTask.get()) != QDialog::Accepted) {
|
if (prog.execWithTask((Task*)deleteSkinTask.get()) != QDialog::Accepted) {
|
||||||
CustomMessageBox::selectable(this, tr("Skin Delete"), tr("Failed to delete current skin!"), QMessageBox::Warning)->exec();
|
CustomMessageBox::selectable(this, tr("Skin Delete"), tr("Failed to delete current skin!"), QMessageBox::Warning)->exec();
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user