Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into metadata2
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
commit
af65eb17cf
3
BUILD.md
3
BUILD.md
@ -1,3 +0,0 @@
|
|||||||
# Build Instructions
|
|
||||||
|
|
||||||
Full build instructions are available on [the website](https://prismlauncher.org/wiki/development/build-instructions/).
|
|
@ -61,7 +61,12 @@ The translation effort for Prism Launcher is hosted on [Weblate](https://hosted.
|
|||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
If you want to build Prism Launcher yourself, check the [Build Instructions](https://prismlauncher.org/wiki/development/build-instructions/).
|
If you want to build Prism Launcher yourself, check the build instructions:
|
||||||
|
|
||||||
|
- [Windows](https://prismlauncher.org/wiki/development/build-instructions/windows/)
|
||||||
|
- [Linux](https://prismlauncher.org/wiki/development/build-instructions/linux/)
|
||||||
|
- [MacOS](https://prismlauncher.org/wiki/development/build-instructions/macos/)
|
||||||
|
- [OpenBSD](https://prismlauncher.org/wiki/development/build-instructions/openbsd/)
|
||||||
|
|
||||||
## Sponsors & Partners
|
## Sponsors & Partners
|
||||||
|
|
||||||
|
@ -138,7 +138,6 @@ 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
|
||||||
|
@ -72,7 +72,7 @@ void appendSafe(const QString& filename, const QByteArray& data);
|
|||||||
void append(const QString& filename, const QByteArray& data);
|
void append(const QString& filename, const QByteArray& data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read data from a file safely\
|
* read data from a file safely
|
||||||
*/
|
*/
|
||||||
QByteArray read(const QString& filename);
|
QByteArray read(const QString& filename);
|
||||||
|
|
||||||
|
@ -344,6 +344,17 @@ std::optional<QStringList> extractSubDir(QuaZip* zip, const QString& subdir, con
|
|||||||
qWarning() << (QObject::tr("Could not fix permissions for %1").arg(target_file_path));
|
qWarning() << (QObject::tr("Could not fix permissions for %1").arg(target_file_path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (fileInfo.isDir()) {
|
||||||
|
// Ensure the folder has the minimal required permissions
|
||||||
|
QFile::Permissions minimalPermissions = QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | QFile::ReadGroup |
|
||||||
|
QFile::ExeGroup | QFile::ReadOther | QFile::ExeOther;
|
||||||
|
|
||||||
|
QFile::Permissions currentPermissions = fileInfo.permissions();
|
||||||
|
if ((currentPermissions & minimalPermissions) != minimalPermissions) {
|
||||||
|
if (!QFile::setPermissions(target_file_path, minimalPermissions)) {
|
||||||
|
qWarning() << (QObject::tr("Could not fix permissions for %1").arg(target_file_path));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
qDebug() << "Extracted file" << relative_file_name << "to" << target_file_path;
|
qDebug() << "Extracted file" << relative_file_name << "to" << target_file_path;
|
||||||
} while (zip->goToNextFile());
|
} while (zip->goToNextFile());
|
||||||
@ -560,7 +571,7 @@ auto ExtractZipTask::extractZip() -> ZipResult
|
|||||||
if (!file_name.startsWith(m_subdirectory))
|
if (!file_name.startsWith(m_subdirectory))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto relative_file_name = QDir::fromNativeSeparators(file_name.remove(0, m_subdirectory.size()));
|
auto relative_file_name = QDir::fromNativeSeparators(file_name.mid(m_subdirectory.size()));
|
||||||
auto original_name = relative_file_name;
|
auto original_name = relative_file_name;
|
||||||
setStatus("Unziping: " + relative_file_name);
|
setStatus("Unziping: " + relative_file_name);
|
||||||
|
|
||||||
@ -610,6 +621,17 @@ auto ExtractZipTask::extractZip() -> ZipResult
|
|||||||
logWarning(tr("Could not fix permissions for %1").arg(target_file_path));
|
logWarning(tr("Could not fix permissions for %1").arg(target_file_path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (fileInfo.isDir()) {
|
||||||
|
// Ensure the folder has the minimal required permissions
|
||||||
|
QFile::Permissions minimalPermissions = QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | QFile::ReadGroup |
|
||||||
|
QFile::ExeGroup | QFile::ReadOther | QFile::ExeOther;
|
||||||
|
|
||||||
|
QFile::Permissions currentPermissions = fileInfo.permissions();
|
||||||
|
if ((currentPermissions & minimalPermissions) != minimalPermissions) {
|
||||||
|
if (!QFile::setPermissions(target_file_path, minimalPermissions)) {
|
||||||
|
logWarning(tr("Could not fix permissions for %1").arg(target_file_path));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Extracted file" << relative_file_name << "to" << target_file_path;
|
qDebug() << "Extracted file" << relative_file_name << "to" << target_file_path;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include "minecraft/auth/Parsers.h"
|
#include "minecraft/auth/Parsers.h"
|
||||||
#include "net/Download.h"
|
#include "net/Download.h"
|
||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
#include "net/RawHeaderProxy.h"
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
EntitlementsStep::EntitlementsStep(AccountData* data) : AuthStep(data) {}
|
EntitlementsStep::EntitlementsStep(AccountData* data) : AuthStep(data) {}
|
||||||
@ -33,7 +33,7 @@ void EntitlementsStep::perform()
|
|||||||
|
|
||||||
m_response.reset(new QByteArray());
|
m_response.reset(new QByteArray());
|
||||||
m_request = Net::Download::makeByteArray(url, m_response);
|
m_request = Net::Download::makeByteArray(url, m_response);
|
||||||
m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
m_request->addHeaderProxy(new Net::RawHeaderProxy(headers));
|
||||||
|
|
||||||
m_task.reset(new NetJob("EntitlementsStep", APPLICATION->network()));
|
m_task.reset(new NetJob("EntitlementsStep", APPLICATION->network()));
|
||||||
m_task->setAskRetry(false);
|
m_task->setAskRetry(false);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "minecraft/auth/Parsers.h"
|
#include "minecraft/auth/Parsers.h"
|
||||||
#include "net/NetUtils.h"
|
#include "net/NetUtils.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
#include "net/RawHeaderProxy.h"
|
||||||
#include "net/Upload.h"
|
#include "net/Upload.h"
|
||||||
|
|
||||||
LauncherLoginStep::LauncherLoginStep(AccountData* data) : AuthStep(data) {}
|
LauncherLoginStep::LauncherLoginStep(AccountData* data) : AuthStep(data) {}
|
||||||
@ -38,7 +38,7 @@ void LauncherLoginStep::perform()
|
|||||||
|
|
||||||
m_response.reset(new QByteArray());
|
m_response.reset(new QByteArray());
|
||||||
m_request = Net::Upload::makeByteArray(url, m_response, requestBody.toUtf8());
|
m_request = Net::Upload::makeByteArray(url, m_response, requestBody.toUtf8());
|
||||||
m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
m_request->addHeaderProxy(new Net::RawHeaderProxy(headers));
|
||||||
|
|
||||||
m_task.reset(new NetJob("LauncherLoginStep", APPLICATION->network()));
|
m_task.reset(new NetJob("LauncherLoginStep", APPLICATION->network()));
|
||||||
m_task->setAskRetry(false);
|
m_task->setAskRetry(false);
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
#include "net/RawHeaderProxy.h"
|
||||||
|
|
||||||
// https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-device-code
|
// https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-device-code
|
||||||
MSADeviceCodeStep::MSADeviceCodeStep(AccountData* data) : AuthStep(data)
|
MSADeviceCodeStep::MSADeviceCodeStep(AccountData* data) : AuthStep(data)
|
||||||
@ -68,14 +68,12 @@ void MSADeviceCodeStep::perform()
|
|||||||
};
|
};
|
||||||
m_response.reset(new QByteArray());
|
m_response.reset(new QByteArray());
|
||||||
m_request = Net::Upload::makeByteArray(url, m_response, payload);
|
m_request = Net::Upload::makeByteArray(url, m_response, payload);
|
||||||
m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
m_request->addHeaderProxy(new Net::RawHeaderProxy(headers));
|
||||||
|
|
||||||
m_task.reset(new NetJob("MSADeviceCodeStep", APPLICATION->network()));
|
m_task.reset(new NetJob("MSADeviceCodeStep", APPLICATION->network()));
|
||||||
m_task->setAskRetry(false);
|
m_task->setAskRetry(false);
|
||||||
m_task->addNetAction(m_request);
|
m_task->addNetAction(m_request);
|
||||||
|
|
||||||
connect(m_task.get(), &Task::finished, this, &MSADeviceCodeStep::deviceAutorizationFinished);
|
|
||||||
|
|
||||||
m_task->start();
|
m_task->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +181,7 @@ void MSADeviceCodeStep::authenticateUser()
|
|||||||
};
|
};
|
||||||
m_response.reset(new QByteArray());
|
m_response.reset(new QByteArray());
|
||||||
m_request = Net::Upload::makeByteArray(url, m_response, payload);
|
m_request = Net::Upload::makeByteArray(url, m_response, payload);
|
||||||
m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
m_request->addHeaderProxy(new Net::RawHeaderProxy(headers));
|
||||||
|
|
||||||
connect(m_request.get(), &Task::finished, this, &MSADeviceCodeStep::authenticationFinished);
|
connect(m_request.get(), &Task::finished, this, &MSADeviceCodeStep::authenticationFinished);
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "minecraft/auth/Parsers.h"
|
#include "minecraft/auth/Parsers.h"
|
||||||
#include "net/NetUtils.h"
|
#include "net/NetUtils.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
#include "net/RawHeaderProxy.h"
|
||||||
|
|
||||||
MinecraftProfileStep::MinecraftProfileStep(AccountData* data) : AuthStep(data) {}
|
MinecraftProfileStep::MinecraftProfileStep(AccountData* data) : AuthStep(data) {}
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ void MinecraftProfileStep::perform()
|
|||||||
|
|
||||||
m_response.reset(new QByteArray());
|
m_response.reset(new QByteArray());
|
||||||
m_request = Net::Download::makeByteArray(url, m_response);
|
m_request = Net::Download::makeByteArray(url, m_response);
|
||||||
m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
m_request->addHeaderProxy(new Net::RawHeaderProxy(headers));
|
||||||
|
|
||||||
m_task.reset(new NetJob("MinecraftProfileStep", APPLICATION->network()));
|
m_task.reset(new NetJob("MinecraftProfileStep", APPLICATION->network()));
|
||||||
m_task->setAskRetry(false);
|
m_task->setAskRetry(false);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "minecraft/auth/Parsers.h"
|
#include "minecraft/auth/Parsers.h"
|
||||||
#include "net/NetUtils.h"
|
#include "net/NetUtils.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
#include "net/RawHeaderProxy.h"
|
||||||
#include "net/Upload.h"
|
#include "net/Upload.h"
|
||||||
|
|
||||||
XboxAuthorizationStep::XboxAuthorizationStep(AccountData* data, Token* token, QString relyingParty, QString authorizationKind)
|
XboxAuthorizationStep::XboxAuthorizationStep(AccountData* data, Token* token, QString relyingParty, QString authorizationKind)
|
||||||
@ -43,7 +43,7 @@ void XboxAuthorizationStep::perform()
|
|||||||
};
|
};
|
||||||
m_response.reset(new QByteArray());
|
m_response.reset(new QByteArray());
|
||||||
m_request = Net::Upload::makeByteArray(url, m_response, xbox_auth_data.toUtf8());
|
m_request = Net::Upload::makeByteArray(url, m_response, xbox_auth_data.toUtf8());
|
||||||
m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
m_request->addHeaderProxy(new Net::RawHeaderProxy(headers));
|
||||||
|
|
||||||
m_task.reset(new NetJob("XboxAuthorizationStep", APPLICATION->network()));
|
m_task.reset(new NetJob("XboxAuthorizationStep", APPLICATION->network()));
|
||||||
m_task->setAskRetry(false);
|
m_task->setAskRetry(false);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "net/NetUtils.h"
|
#include "net/NetUtils.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
#include "net/RawHeaderProxy.h"
|
||||||
|
|
||||||
XboxProfileStep::XboxProfileStep(AccountData* data) : AuthStep(data) {}
|
XboxProfileStep::XboxProfileStep(AccountData* data) : AuthStep(data) {}
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ void XboxProfileStep::perform()
|
|||||||
|
|
||||||
m_response.reset(new QByteArray());
|
m_response.reset(new QByteArray());
|
||||||
m_request = Net::Download::makeByteArray(url, m_response);
|
m_request = Net::Download::makeByteArray(url, m_response);
|
||||||
m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
m_request->addHeaderProxy(new Net::RawHeaderProxy(headers));
|
||||||
|
|
||||||
m_task.reset(new NetJob("XboxProfileStep", APPLICATION->network()));
|
m_task.reset(new NetJob("XboxProfileStep", APPLICATION->network()));
|
||||||
m_task->setAskRetry(false);
|
m_task->setAskRetry(false);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "minecraft/auth/Parsers.h"
|
#include "minecraft/auth/Parsers.h"
|
||||||
#include "net/NetUtils.h"
|
#include "net/NetUtils.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
#include "net/RawHeaderProxy.h"
|
||||||
|
|
||||||
XboxUserStep::XboxUserStep(AccountData* data) : AuthStep(data) {}
|
XboxUserStep::XboxUserStep(AccountData* data) : AuthStep(data) {}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ void XboxUserStep::perform()
|
|||||||
};
|
};
|
||||||
m_response.reset(new QByteArray());
|
m_response.reset(new QByteArray());
|
||||||
m_request = Net::Upload::makeByteArray(url, m_response, xbox_auth_data.toUtf8());
|
m_request = Net::Upload::makeByteArray(url, m_response, xbox_auth_data.toUtf8());
|
||||||
m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
m_request->addHeaderProxy(new Net::RawHeaderProxy(headers));
|
||||||
|
|
||||||
m_task.reset(new NetJob("XboxUserStep", APPLICATION->network()));
|
m_task.reset(new NetJob("XboxUserStep", APPLICATION->network()));
|
||||||
m_task->setAskRetry(false);
|
m_task->setAskRetry(false);
|
||||||
|
@ -251,7 +251,7 @@ Task* ModFolderModel::createParseTask(Resource& resource)
|
|||||||
bool ModFolderModel::uninstallMod(const QString& filename, bool preserve_metadata)
|
bool ModFolderModel::uninstallMod(const QString& filename, bool preserve_metadata)
|
||||||
{
|
{
|
||||||
for (auto mod : allMods()) {
|
for (auto mod : allMods()) {
|
||||||
if (mod->fileinfo().fileName() == filename) {
|
if (mod->getOriginalFileName() == filename) {
|
||||||
auto index_dir = indexDir();
|
auto index_dir = indexDir();
|
||||||
mod->destroy(index_dir, preserve_metadata, false);
|
mod->destroy(index_dir, preserve_metadata, false);
|
||||||
|
|
||||||
|
@ -197,3 +197,11 @@ bool Resource::isMoreThanOneHardLink() const
|
|||||||
{
|
{
|
||||||
return FS::hardLinkCount(m_file_info.absoluteFilePath()) > 1;
|
return FS::hardLinkCount(m_file_info.absoluteFilePath()) > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto Resource::getOriginalFileName() const -> QString
|
||||||
|
{
|
||||||
|
auto fileName = m_file_info.fileName();
|
||||||
|
if (!m_enabled)
|
||||||
|
fileName.chop(9);
|
||||||
|
return fileName;
|
||||||
|
}
|
@ -80,6 +80,7 @@ class Resource : public QObject {
|
|||||||
[[nodiscard]] auto internal_id() const -> QString { return m_internal_id; }
|
[[nodiscard]] auto internal_id() const -> QString { return m_internal_id; }
|
||||||
[[nodiscard]] auto type() const -> ResourceType { return m_type; }
|
[[nodiscard]] auto type() const -> ResourceType { return m_type; }
|
||||||
[[nodiscard]] bool enabled() const { return m_enabled; }
|
[[nodiscard]] bool enabled() const { return m_enabled; }
|
||||||
|
[[nodiscard]] auto getOriginalFileName() const -> QString;
|
||||||
[[nodiscard]] QString sizeStr() const { return m_size_str; }
|
[[nodiscard]] QString sizeStr() const { return m_size_str; }
|
||||||
[[nodiscard]] qint64 sizeInfo() const { return m_size_info; }
|
[[nodiscard]] qint64 sizeInfo() const { return m_size_info; }
|
||||||
|
|
||||||
|
@ -39,9 +39,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "net/ByteArraySink.h"
|
#include "net/ByteArraySink.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
#include "net/RawHeaderProxy.h"
|
||||||
|
|
||||||
CapeChange::CapeChange(QString token, QString cape) : NetRequest(), m_capeId(cape), m_token(token)
|
CapeChange::CapeChange(QString cape) : NetRequest(), m_capeId(cape)
|
||||||
{
|
{
|
||||||
logCat = taskMCSkinsLogC;
|
logCat = taskMCSkinsLogC;
|
||||||
}
|
}
|
||||||
@ -57,18 +57,14 @@ QNetworkReply* CapeChange::getReply(QNetworkRequest& request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CapeChange::init()
|
|
||||||
{
|
|
||||||
addHeaderProxy(new Net::StaticHeaderProxy(QList<Net::HeaderPair>{
|
|
||||||
{ "Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit() },
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
CapeChange::Ptr CapeChange::make(QString token, QString capeId)
|
CapeChange::Ptr CapeChange::make(QString token, QString capeId)
|
||||||
{
|
{
|
||||||
auto up = makeShared<CapeChange>(token, capeId);
|
auto up = makeShared<CapeChange>(capeId);
|
||||||
up->m_url = QUrl("https://api.minecraftservices.com/minecraft/profile/capes/active");
|
up->m_url = QUrl("https://api.minecraftservices.com/minecraft/profile/capes/active");
|
||||||
up->setObjectName(QString("BYTES:") + up->m_url.toString());
|
up->setObjectName(QString("BYTES:") + up->m_url.toString());
|
||||||
up->m_sink.reset(new Net::ByteArraySink(std::make_shared<QByteArray>()));
|
up->m_sink.reset(new Net::ByteArraySink(std::make_shared<QByteArray>()));
|
||||||
|
up->addHeaderProxy(new Net::RawHeaderProxy(QList<Net::HeaderPair>{
|
||||||
|
{ "Authorization", QString("Bearer %1").arg(token).toLocal8Bit() },
|
||||||
|
}));
|
||||||
return up;
|
return up;
|
||||||
}
|
}
|
||||||
|
@ -24,16 +24,14 @@ class CapeChange : public Net::NetRequest {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
using Ptr = shared_qobject_ptr<CapeChange>;
|
using Ptr = shared_qobject_ptr<CapeChange>;
|
||||||
CapeChange(QString token, QString capeId);
|
CapeChange(QString capeId);
|
||||||
virtual ~CapeChange() = default;
|
virtual ~CapeChange() = default;
|
||||||
|
|
||||||
static CapeChange::Ptr make(QString token, QString capeId);
|
static CapeChange::Ptr make(QString token, QString capeId);
|
||||||
void init() override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QNetworkReply* getReply(QNetworkRequest&) override;
|
virtual QNetworkReply* getReply(QNetworkRequest&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_capeId;
|
QString m_capeId;
|
||||||
QString m_token;
|
|
||||||
};
|
};
|
||||||
|
@ -37,9 +37,9 @@
|
|||||||
#include "SkinDelete.h"
|
#include "SkinDelete.h"
|
||||||
|
|
||||||
#include "net/ByteArraySink.h"
|
#include "net/ByteArraySink.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
#include "net/RawHeaderProxy.h"
|
||||||
|
|
||||||
SkinDelete::SkinDelete(QString token) : NetRequest(), m_token(token)
|
SkinDelete::SkinDelete() : NetRequest()
|
||||||
{
|
{
|
||||||
logCat = taskMCSkinsLogC;
|
logCat = taskMCSkinsLogC;
|
||||||
}
|
}
|
||||||
@ -50,17 +50,13 @@ QNetworkReply* SkinDelete::getReply(QNetworkRequest& request)
|
|||||||
return m_network->deleteResource(request);
|
return m_network->deleteResource(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkinDelete::init()
|
|
||||||
{
|
|
||||||
addHeaderProxy(new Net::StaticHeaderProxy(QList<Net::HeaderPair>{
|
|
||||||
{ "Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit() },
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
SkinDelete::Ptr SkinDelete::make(QString token)
|
SkinDelete::Ptr SkinDelete::make(QString token)
|
||||||
{
|
{
|
||||||
auto up = makeShared<SkinDelete>(token);
|
auto up = makeShared<SkinDelete>();
|
||||||
up->m_url = QUrl("https://api.minecraftservices.com/minecraft/profile/skins/active");
|
up->m_url = QUrl("https://api.minecraftservices.com/minecraft/profile/skins/active");
|
||||||
up->m_sink.reset(new Net::ByteArraySink(std::make_shared<QByteArray>()));
|
up->m_sink.reset(new Net::ByteArraySink(std::make_shared<QByteArray>()));
|
||||||
|
up->addHeaderProxy(new Net::RawHeaderProxy(QList<Net::HeaderPair>{
|
||||||
|
{ "Authorization", QString("Bearer %1").arg(token).toLocal8Bit() },
|
||||||
|
}));
|
||||||
return up;
|
return up;
|
||||||
}
|
}
|
||||||
|
@ -24,15 +24,11 @@ class SkinDelete : public Net::NetRequest {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
using Ptr = shared_qobject_ptr<SkinDelete>;
|
using Ptr = shared_qobject_ptr<SkinDelete>;
|
||||||
SkinDelete(QString token);
|
SkinDelete();
|
||||||
virtual ~SkinDelete() = default;
|
virtual ~SkinDelete() = default;
|
||||||
|
|
||||||
static SkinDelete::Ptr make(QString token);
|
static SkinDelete::Ptr make(QString token);
|
||||||
void init() override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QNetworkReply* getReply(QNetworkRequest&) override;
|
virtual QNetworkReply* getReply(QNetworkRequest&) override;
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_token;
|
|
||||||
};
|
};
|
||||||
|
@ -40,9 +40,9 @@
|
|||||||
|
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "net/ByteArraySink.h"
|
#include "net/ByteArraySink.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
#include "net/RawHeaderProxy.h"
|
||||||
|
|
||||||
SkinUpload::SkinUpload(QString token, QString path, QString variant) : NetRequest(), m_token(token), m_path(path), m_variant(variant)
|
SkinUpload::SkinUpload(QString path, QString variant) : NetRequest(), m_path(path), m_variant(variant)
|
||||||
{
|
{
|
||||||
logCat = taskMCSkinsLogC;
|
logCat = taskMCSkinsLogC;
|
||||||
}
|
}
|
||||||
@ -67,18 +67,14 @@ QNetworkReply* SkinUpload::getReply(QNetworkRequest& request)
|
|||||||
return m_network->post(request, multiPart);
|
return m_network->post(request, multiPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkinUpload::init()
|
|
||||||
{
|
|
||||||
addHeaderProxy(new Net::StaticHeaderProxy(QList<Net::HeaderPair>{
|
|
||||||
{ "Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit() },
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
SkinUpload::Ptr SkinUpload::make(QString token, QString path, QString variant)
|
SkinUpload::Ptr SkinUpload::make(QString token, QString path, QString variant)
|
||||||
{
|
{
|
||||||
auto up = makeShared<SkinUpload>(token, path, variant);
|
auto up = makeShared<SkinUpload>(path, variant);
|
||||||
up->m_url = QUrl("https://api.minecraftservices.com/minecraft/profile/skins");
|
up->m_url = QUrl("https://api.minecraftservices.com/minecraft/profile/skins");
|
||||||
up->setObjectName(QString("BYTES:") + up->m_url.toString());
|
up->setObjectName(QString("BYTES:") + up->m_url.toString());
|
||||||
up->m_sink.reset(new Net::ByteArraySink(std::make_shared<QByteArray>()));
|
up->m_sink.reset(new Net::ByteArraySink(std::make_shared<QByteArray>()));
|
||||||
|
up->addHeaderProxy(new Net::RawHeaderProxy(QList<Net::HeaderPair>{
|
||||||
|
{ "Authorization", QString("Bearer %1").arg(token).toLocal8Bit() },
|
||||||
|
}));
|
||||||
return up;
|
return up;
|
||||||
}
|
}
|
||||||
|
@ -26,17 +26,15 @@ class SkinUpload : public Net::NetRequest {
|
|||||||
using Ptr = shared_qobject_ptr<SkinUpload>;
|
using Ptr = shared_qobject_ptr<SkinUpload>;
|
||||||
|
|
||||||
// Note this class takes ownership of the file.
|
// Note this class takes ownership of the file.
|
||||||
SkinUpload(QString token, QString path, QString variant);
|
SkinUpload(QString path, QString variant);
|
||||||
virtual ~SkinUpload() = default;
|
virtual ~SkinUpload() = default;
|
||||||
|
|
||||||
static SkinUpload::Ptr make(QString token, QString path, QString variant);
|
static SkinUpload::Ptr make(QString token, QString path, QString variant);
|
||||||
void init() override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QNetworkReply* getReply(QNetworkRequest&) override;
|
virtual QNetworkReply* getReply(QNetworkRequest&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_token;
|
|
||||||
QString m_path;
|
QString m_path;
|
||||||
QString m_variant;
|
QString m_variant;
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "FlameCheckUpdate.h"
|
#include "FlameCheckUpdate.h"
|
||||||
|
#include "Application.h"
|
||||||
#include "FlameAPI.h"
|
#include "FlameAPI.h"
|
||||||
#include "FlameModIndex.h"
|
#include "FlameModIndex.h"
|
||||||
|
|
||||||
@ -124,11 +125,6 @@ void FlameCheckUpdate::executeTask()
|
|||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto* mod : m_mods) {
|
for (auto* mod : m_mods) {
|
||||||
if (!mod->enabled()) {
|
|
||||||
emit checkFailed(mod, tr("Disabled mods won't be updated, to prevent mod duplication issues!"));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
setStatus(tr("Getting API response from CurseForge for '%1'...").arg(mod->name()));
|
setStatus(tr("Getting API response from CurseForge for '%1'...").arg(mod->name()));
|
||||||
setProgress(i++, m_mods.size());
|
setProgress(i++, m_mods.size());
|
||||||
|
|
||||||
@ -177,7 +173,7 @@ void FlameCheckUpdate::executeTask()
|
|||||||
auto download_task = makeShared<ResourceDownloadTask>(pack, latest_ver.value(), m_mods_folder);
|
auto download_task = makeShared<ResourceDownloadTask>(pack, latest_ver.value(), m_mods_folder);
|
||||||
m_updatable.emplace_back(pack->name, mod->metadata()->hash, old_version, latest_ver->version, latest_ver->version_type,
|
m_updatable.emplace_back(pack->name, mod->metadata()->hash, old_version, latest_ver->version, latest_ver->version_type,
|
||||||
api.getModFileChangelog(latest_ver->addonId.toInt(), latest_ver->fileId.toInt()),
|
api.getModFileChangelog(latest_ver->addonId.toInt(), latest_ver->fileId.toInt()),
|
||||||
ModPlatform::ResourceProvider::FLAME, download_task);
|
ModPlatform::ResourceProvider::FLAME, download_task, mod->enabled());
|
||||||
}
|
}
|
||||||
m_deps.append(std::make_shared<GetModDependenciesTask::PackDependency>(pack, latest_ver.value()));
|
m_deps.append(std::make_shared<GetModDependenciesTask::PackDependency>(pack, latest_ver.value()));
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,6 @@ void ModrinthCheckUpdate::executeTask()
|
|||||||
auto hashing_task =
|
auto hashing_task =
|
||||||
makeShared<ConcurrentTask>(this, "MakeModrinthHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt());
|
makeShared<ConcurrentTask>(this, "MakeModrinthHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt());
|
||||||
for (auto* mod : m_mods) {
|
for (auto* mod : m_mods) {
|
||||||
if (!mod->enabled()) {
|
|
||||||
emit checkFailed(mod, tr("Disabled mods won't be updated, to prevent mod duplication issues!"));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto hash = mod->metadata()->hash;
|
auto hash = mod->metadata()->hash;
|
||||||
|
|
||||||
// Sadly the API can only handle one hash type per call, se we
|
// Sadly the API can only handle one hash type per call, se we
|
||||||
@ -95,8 +90,7 @@ void ModrinthCheckUpdate::checkVersionsResponse(std::shared_ptr<QByteArray> resp
|
|||||||
// If the returned project is empty, but we have Modrinth metadata,
|
// If the returned project is empty, but we have Modrinth metadata,
|
||||||
// it means this specific version is not available
|
// it means this specific version is not available
|
||||||
if (project_obj.isEmpty()) {
|
if (project_obj.isEmpty()) {
|
||||||
qDebug() << "Mod " << m_mappings.find(hash).value()->name() << " got an empty response."
|
qDebug() << "Mod " << m_mappings.find(hash).value()->name() << " got an empty response." << "Hash: " << hash;
|
||||||
<< "Hash: " << hash;
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -153,7 +147,7 @@ void ModrinthCheckUpdate::checkVersionsResponse(std::shared_ptr<QByteArray> resp
|
|||||||
auto download_task = makeShared<ResourceDownloadTask>(pack, project_ver, m_mods_folder);
|
auto download_task = makeShared<ResourceDownloadTask>(pack, project_ver, m_mods_folder);
|
||||||
|
|
||||||
m_updatable.emplace_back(pack->name, hash, mod->version(), project_ver.version_number, project_ver.version_type,
|
m_updatable.emplace_back(pack->name, hash, mod->version(), project_ver.version_number, project_ver.version_type,
|
||||||
project_ver.changelog, ModPlatform::ResourceProvider::MODRINTH, download_task);
|
project_ver.changelog, ModPlatform::ResourceProvider::MODRINTH, download_task, mod->enabled());
|
||||||
}
|
}
|
||||||
m_deps.append(std::make_shared<GetModDependenciesTask::PackDependency>(pack, project_ver));
|
m_deps.append(std::make_shared<GetModDependenciesTask::PackDependency>(pack, project_ver));
|
||||||
}
|
}
|
||||||
|
@ -18,47 +18,29 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "net/ApiDownload.h"
|
#include "net/ApiDownload.h"
|
||||||
#include "ByteArraySink.h"
|
#include "net/ApiHeaderProxy.h"
|
||||||
#include "ChecksumValidator.h"
|
|
||||||
#include "MetaCacheSink.h"
|
|
||||||
|
|
||||||
namespace Net {
|
namespace Net {
|
||||||
|
|
||||||
auto ApiDownload::makeCached(QUrl url, MetaEntryPtr entry, Options options) -> Download::Ptr
|
Download::Ptr ApiDownload::makeCached(QUrl url, MetaEntryPtr entry, Download::Options options)
|
||||||
{
|
{
|
||||||
auto dl = makeShared<ApiDownload>();
|
auto dl = Download::makeCached(url, entry, options);
|
||||||
dl->m_url = url;
|
dl->addHeaderProxy(new ApiHeaderProxy());
|
||||||
dl->setObjectName(QString("CACHE:") + url.toString());
|
|
||||||
dl->m_options = options;
|
|
||||||
auto md5Node = new ChecksumValidator(QCryptographicHash::Md5);
|
|
||||||
auto cachedNode = new MetaCacheSink(entry, md5Node, options.testFlag(Option::MakeEternal));
|
|
||||||
dl->m_sink.reset(cachedNode);
|
|
||||||
return dl;
|
return dl;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ApiDownload::makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, Options options) -> Download::Ptr
|
Download::Ptr ApiDownload::makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, Download::Options options)
|
||||||
{
|
{
|
||||||
auto dl = makeShared<ApiDownload>();
|
auto dl = Download::makeByteArray(url, output, options);
|
||||||
dl->m_url = url;
|
dl->addHeaderProxy(new ApiHeaderProxy());
|
||||||
dl->setObjectName(QString("BYTES:") + url.toString());
|
|
||||||
dl->m_options = options;
|
|
||||||
dl->m_sink.reset(new ByteArraySink(output));
|
|
||||||
return dl;
|
return dl;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ApiDownload::makeFile(QUrl url, QString path, Options options) -> Download::Ptr
|
Download::Ptr ApiDownload::makeFile(QUrl url, QString path, Download::Options options)
|
||||||
{
|
{
|
||||||
auto dl = makeShared<ApiDownload>();
|
auto dl = Download::makeFile(url, path, options);
|
||||||
dl->m_url = url;
|
dl->addHeaderProxy(new ApiHeaderProxy());
|
||||||
dl->setObjectName(QString("FILE:") + url.toString());
|
|
||||||
dl->m_options = options;
|
|
||||||
dl->m_sink.reset(new FileSink(path));
|
|
||||||
return dl;
|
return dl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiDownload::init()
|
|
||||||
{
|
|
||||||
auto api_headers = new ApiHeaderProxy();
|
|
||||||
addHeaderProxy(api_headers);
|
|
||||||
}
|
|
||||||
} // namespace Net
|
} // namespace Net
|
||||||
|
@ -19,20 +19,14 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ApiHeaderProxy.h"
|
|
||||||
#include "Download.h"
|
#include "Download.h"
|
||||||
|
|
||||||
namespace Net {
|
namespace Net {
|
||||||
|
|
||||||
class ApiDownload : public Download {
|
namespace ApiDownload {
|
||||||
public:
|
Download::Ptr makeCached(QUrl url, MetaEntryPtr entry, Download::Options options = Download::Option::NoOptions);
|
||||||
virtual ~ApiDownload() = default;
|
Download::Ptr makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, Download::Options options = Download::Option::NoOptions);
|
||||||
|
Download::Ptr makeFile(QUrl url, QString path, Download::Options options = Download::Option::NoOptions);
|
||||||
static auto makeCached(QUrl url, MetaEntryPtr entry, Options options = Option::NoOptions) -> Download::Ptr;
|
}; // namespace ApiDownload
|
||||||
static auto makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, Options options = Option::NoOptions) -> Download::Ptr;
|
|
||||||
static auto makeFile(QUrl url, QString path, Options options = Option::NoOptions) -> Download::Ptr;
|
|
||||||
|
|
||||||
void init() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Net
|
} // namespace Net
|
||||||
|
@ -18,22 +18,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "net/ApiUpload.h"
|
#include "net/ApiUpload.h"
|
||||||
#include "ByteArraySink.h"
|
#include "net/ApiHeaderProxy.h"
|
||||||
|
|
||||||
namespace Net {
|
namespace Net {
|
||||||
|
|
||||||
Upload::Ptr ApiUpload::makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, QByteArray m_post_data)
|
Upload::Ptr ApiUpload::makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, QByteArray m_post_data)
|
||||||
{
|
{
|
||||||
auto up = makeShared<ApiUpload>();
|
auto up = Upload::makeByteArray(url, output, m_post_data);
|
||||||
up->m_url = std::move(url);
|
up->addHeaderProxy(new ApiHeaderProxy());
|
||||||
up->m_sink.reset(new ByteArraySink(output));
|
|
||||||
up->m_post_data = std::move(m_post_data);
|
|
||||||
return up;
|
return up;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiUpload::init()
|
|
||||||
{
|
|
||||||
auto api_headers = new ApiHeaderProxy();
|
|
||||||
addHeaderProxy(api_headers);
|
|
||||||
}
|
|
||||||
} // namespace Net
|
} // namespace Net
|
||||||
|
@ -19,18 +19,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ApiHeaderProxy.h"
|
|
||||||
#include "Upload.h"
|
#include "Upload.h"
|
||||||
|
|
||||||
namespace Net {
|
namespace Net {
|
||||||
|
|
||||||
class ApiUpload : public Upload {
|
namespace ApiUpload {
|
||||||
public:
|
Upload::Ptr makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, QByteArray m_post_data);
|
||||||
virtual ~ApiUpload() = default;
|
|
||||||
|
|
||||||
static Upload::Ptr makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, QByteArray m_post_data);
|
|
||||||
|
|
||||||
void init() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Net
|
} // namespace Net
|
||||||
|
@ -62,8 +62,6 @@ void NetRequest::addValidator(Validator* v)
|
|||||||
|
|
||||||
void NetRequest::executeTask()
|
void NetRequest::executeTask()
|
||||||
{
|
{
|
||||||
init();
|
|
||||||
|
|
||||||
setStatus(tr("Requesting %1").arg(StringUtils::truncateUrlHumanFriendly(m_url, 80)));
|
setStatus(tr("Requesting %1").arg(StringUtils::truncateUrlHumanFriendly(m_url, 80)));
|
||||||
|
|
||||||
if (getState() == Task::State::AbortedByUser) {
|
if (getState() == Task::State::AbortedByUser) {
|
||||||
|
@ -72,8 +72,6 @@ class NetRequest : public Task {
|
|||||||
void setNetwork(shared_qobject_ptr<QNetworkAccessManager> network) { m_network = network; }
|
void setNetwork(shared_qobject_ptr<QNetworkAccessManager> network) { m_network = network; }
|
||||||
void addHeaderProxy(Net::HeaderProxy* proxy) { m_headerProxies.push_back(std::shared_ptr<Net::HeaderProxy>(proxy)); }
|
void addHeaderProxy(Net::HeaderProxy* proxy) { m_headerProxies.push_back(std::shared_ptr<Net::HeaderProxy>(proxy)); }
|
||||||
|
|
||||||
virtual void init() {}
|
|
||||||
|
|
||||||
QUrl url() const;
|
QUrl url() const;
|
||||||
void setUrl(QUrl url) { m_url = url; }
|
void setUrl(QUrl url) { m_url = url; }
|
||||||
int replyStatusCode() const;
|
int replyStatusCode() const;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
* Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -27,7 +28,7 @@ namespace Net {
|
|||||||
|
|
||||||
class RawHeaderProxy : public HeaderProxy {
|
class RawHeaderProxy : public HeaderProxy {
|
||||||
public:
|
public:
|
||||||
RawHeaderProxy() : HeaderProxy() {}
|
RawHeaderProxy(QList<HeaderPair> headers = {}) : HeaderProxy(), m_headers(std::move(headers)) {};
|
||||||
virtual ~RawHeaderProxy() = default;
|
virtual ~RawHeaderProxy() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -36,6 +37,7 @@ class RawHeaderProxy : public HeaderProxy {
|
|||||||
void addHeader(const HeaderPair& header) { m_headers.append(header); }
|
void addHeader(const HeaderPair& header) { m_headers.append(header); }
|
||||||
void addHeader(const QByteArray& headerName, const QByteArray& headerValue) { m_headers.append({ headerName, headerValue }); }
|
void addHeader(const QByteArray& headerName, const QByteArray& headerValue) { m_headers.append({ headerName, headerValue }); }
|
||||||
void addHeaders(const QList<HeaderPair>& headers) { m_headers.append(headers); }
|
void addHeaders(const QList<HeaderPair>& headers) { m_headers.append(headers); }
|
||||||
|
void setHeaders(QList<HeaderPair> headers) { m_headers = headers; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<HeaderPair> m_headers;
|
QList<HeaderPair> m_headers;
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
|
||||||
/*
|
|
||||||
* Prism Launcher - Minecraft Launcher
|
|
||||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.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
|
|
@ -46,7 +46,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "BuildConfig.h"
|
#include "BuildConfig.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
#include "net/RawHeaderProxy.h"
|
||||||
|
|
||||||
Net::NetRequest::Ptr ImgurAlbumCreation::make(std::shared_ptr<ImgurAlbumCreation::Result> output, QList<ScreenShot::Ptr> screenshots)
|
Net::NetRequest::Ptr ImgurAlbumCreation::make(std::shared_ptr<ImgurAlbumCreation::Result> output, QList<ScreenShot::Ptr> screenshots)
|
||||||
{
|
{
|
||||||
@ -54,6 +54,10 @@ Net::NetRequest::Ptr ImgurAlbumCreation::make(std::shared_ptr<ImgurAlbumCreation
|
|||||||
up->m_url = BuildConfig.IMGUR_BASE_URL + "album";
|
up->m_url = BuildConfig.IMGUR_BASE_URL + "album";
|
||||||
up->m_sink.reset(new Sink(output));
|
up->m_sink.reset(new Sink(output));
|
||||||
up->m_screenshots = screenshots;
|
up->m_screenshots = screenshots;
|
||||||
|
up->addHeaderProxy(new Net::RawHeaderProxy(
|
||||||
|
QList<Net::HeaderPair>{ { "Content-Type", "application/x-www-form-urlencoded" },
|
||||||
|
{ "Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toUtf8() },
|
||||||
|
{ "Accept", "application/json" } }));
|
||||||
return up;
|
return up;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,16 +71,6 @@ QNetworkReply* ImgurAlbumCreation::getReply(QNetworkRequest& request)
|
|||||||
return m_network->post(request, data);
|
return m_network->post(request, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImgurAlbumCreation::init()
|
|
||||||
{
|
|
||||||
qDebug() << "Setting up imgur upload";
|
|
||||||
auto api_headers = new Net::StaticHeaderProxy(
|
|
||||||
QList<Net::HeaderPair>{ { "Content-Type", "application/x-www-form-urlencoded" },
|
|
||||||
{ "Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toUtf8() },
|
|
||||||
{ "Accept", "application/json" } });
|
|
||||||
addHeaderProxy(api_headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto ImgurAlbumCreation::Sink::init(QNetworkRequest& request) -> Task::State
|
auto ImgurAlbumCreation::Sink::init(QNetworkRequest& request) -> Task::State
|
||||||
{
|
{
|
||||||
m_output.clear();
|
m_output.clear();
|
||||||
|
@ -67,8 +67,6 @@ class ImgurAlbumCreation : public Net::NetRequest {
|
|||||||
static NetRequest::Ptr make(std::shared_ptr<Result> output, QList<ScreenShot::Ptr> screenshots);
|
static NetRequest::Ptr make(std::shared_ptr<Result> output, QList<ScreenShot::Ptr> screenshots);
|
||||||
QNetworkReply* getReply(QNetworkRequest& request) override;
|
QNetworkReply* getReply(QNetworkRequest& request) override;
|
||||||
|
|
||||||
void init() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<ScreenShot::Ptr> m_screenshots;
|
QList<ScreenShot::Ptr> m_screenshots;
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
#include "ImgurUpload.h"
|
#include "ImgurUpload.h"
|
||||||
#include "BuildConfig.h"
|
#include "BuildConfig.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
#include "net/RawHeaderProxy.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@ -47,14 +47,6 @@
|
|||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
void ImgurUpload::init()
|
|
||||||
{
|
|
||||||
qDebug() << "Setting up imgur upload";
|
|
||||||
auto api_headers = new Net::StaticHeaderProxy(QList<Net::HeaderPair>{
|
|
||||||
{ "Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toUtf8() }, { "Accept", "application/json" } });
|
|
||||||
addHeaderProxy(api_headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
QNetworkReply* ImgurUpload::getReply(QNetworkRequest& request)
|
QNetworkReply* ImgurUpload::getReply(QNetworkRequest& request)
|
||||||
{
|
{
|
||||||
auto file = new QFile(m_fileInfo.absoluteFilePath(), this);
|
auto file = new QFile(m_fileInfo.absoluteFilePath(), this);
|
||||||
@ -125,5 +117,7 @@ Net::NetRequest::Ptr ImgurUpload::make(ScreenShot::Ptr m_shot)
|
|||||||
auto up = makeShared<ImgurUpload>(m_shot->m_file);
|
auto up = makeShared<ImgurUpload>(m_shot->m_file);
|
||||||
up->m_url = std::move(BuildConfig.IMGUR_BASE_URL + "image");
|
up->m_url = std::move(BuildConfig.IMGUR_BASE_URL + "image");
|
||||||
up->m_sink.reset(new Sink(m_shot));
|
up->m_sink.reset(new Sink(m_shot));
|
||||||
|
up->addHeaderProxy(new Net::RawHeaderProxy(QList<Net::HeaderPair>{
|
||||||
|
{ "Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toUtf8() }, { "Accept", "application/json" } }));
|
||||||
return up;
|
return up;
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,6 @@ class ImgurUpload : public Net::NetRequest {
|
|||||||
|
|
||||||
static NetRequest::Ptr make(ScreenShot::Ptr m_shot);
|
static NetRequest::Ptr make(ScreenShot::Ptr m_shot);
|
||||||
|
|
||||||
void init() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual QNetworkReply* getReply(QNetworkRequest&) override;
|
virtual QNetworkReply* getReply(QNetworkRequest&) override;
|
||||||
const QFileInfo m_fileInfo;
|
const QFileInfo m_fileInfo;
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ProfileSetupDialog.h"
|
#include "ProfileSetupDialog.h"
|
||||||
|
#include "net/RawHeaderProxy.h"
|
||||||
#include "ui_ProfileSetupDialog.h"
|
#include "ui_ProfileSetupDialog.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
@ -46,7 +47,6 @@
|
|||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include "minecraft/auth/Parsers.h"
|
#include "minecraft/auth/Parsers.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
|
||||||
#include "net/Upload.h"
|
#include "net/Upload.h"
|
||||||
|
|
||||||
ProfileSetupDialog::ProfileSetupDialog(MinecraftAccountPtr accountToSetup, QWidget* parent)
|
ProfileSetupDialog::ProfileSetupDialog(MinecraftAccountPtr accountToSetup, QWidget* parent)
|
||||||
@ -160,7 +160,7 @@ void ProfileSetupDialog::checkName(const QString& name)
|
|||||||
if (m_check_task)
|
if (m_check_task)
|
||||||
disconnect(m_check_task.get(), nullptr, this, nullptr);
|
disconnect(m_check_task.get(), nullptr, this, nullptr);
|
||||||
m_check_task = Net::Download::makeByteArray(url, m_check_response);
|
m_check_task = Net::Download::makeByteArray(url, m_check_response);
|
||||||
m_check_task->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
m_check_task->addHeaderProxy(new Net::RawHeaderProxy(headers));
|
||||||
|
|
||||||
connect(m_check_task.get(), &Task::finished, this, &ProfileSetupDialog::checkFinished);
|
connect(m_check_task.get(), &Task::finished, this, &ProfileSetupDialog::checkFinished);
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ void ProfileSetupDialog::setupProfile(const QString& profileName)
|
|||||||
|
|
||||||
m_profile_response.reset(new QByteArray());
|
m_profile_response.reset(new QByteArray());
|
||||||
m_profile_task = Net::Upload::makeByteArray(url, m_profile_response, payloadTemplate.arg(profileName).toUtf8());
|
m_profile_task = Net::Upload::makeByteArray(url, m_profile_response, payloadTemplate.arg(profileName).toUtf8());
|
||||||
m_profile_task->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
m_profile_task->addHeaderProxy(new Net::RawHeaderProxy(headers));
|
||||||
|
|
||||||
connect(m_profile_task.get(), &Task::finished, this, &ProfileSetupDialog::setupProfileFinished);
|
connect(m_profile_task.get(), &Task::finished, this, &ProfileSetupDialog::setupProfileFinished);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user