From f7f7bc68653a3bfbfd9a571624582d45ef5e224b Mon Sep 17 00:00:00 2001 From: Trial97 Date: Tue, 15 Aug 2023 20:52:17 +0300 Subject: [PATCH 1/9] Removed update disabled warning Signed-off-by: Trial97 --- launcher/minecraft/mod/ModFolderModel.cpp | 5 ++++- launcher/modplatform/CheckUpdateTask.h | 11 ++++++++++- launcher/modplatform/flame/FlameCheckUpdate.cpp | 7 +------ launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp | 7 +------ launcher/ui/dialogs/ModUpdateDialog.cpp | 4 +--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp index 280e70d7b..1b96590a4 100644 --- a/launcher/minecraft/mod/ModFolderModel.cpp +++ b/launcher/minecraft/mod/ModFolderModel.cpp @@ -196,7 +196,10 @@ Task* ModFolderModel::createParseTask(Resource& resource) bool ModFolderModel::uninstallMod(const QString& filename, bool preserve_metadata) { for (auto mod : allMods()) { - if (mod->fileinfo().fileName() == filename) { + auto modfilename = mod->fileinfo().fileName(); + if (!mod->enabled() && modfilename.endsWith(".disabled")) + modfilename.chop(9); + if (modfilename == filename) { auto index_dir = indexDir(); mod->destroy(index_dir, preserve_metadata, false); diff --git a/launcher/modplatform/CheckUpdateTask.h b/launcher/modplatform/CheckUpdateTask.h index 6d968ea48..6afa9c290 100644 --- a/launcher/modplatform/CheckUpdateTask.h +++ b/launcher/modplatform/CheckUpdateTask.h @@ -24,6 +24,7 @@ class CheckUpdateTask : public Task { QString old_version; QString new_version; QString changelog; + bool enabled; ModPlatform::ResourceProvider provider; shared_qobject_ptr download; @@ -33,9 +34,17 @@ class CheckUpdateTask : public Task { QString old_v, QString new_v, QString changelog, + bool enabled, ModPlatform::ResourceProvider p, shared_qobject_ptr t) - : name(name), old_hash(old_h), old_version(old_v), new_version(new_v), changelog(changelog), provider(p), download(t) + : name(name) + , old_hash(old_h) + , old_version(old_v) + , new_version(new_v) + , changelog(changelog) + , enabled(enabled) + , provider(p) + , download(t) {} }; diff --git a/launcher/modplatform/flame/FlameCheckUpdate.cpp b/launcher/modplatform/flame/FlameCheckUpdate.cpp index e10fedc3c..79ae82e69 100644 --- a/launcher/modplatform/flame/FlameCheckUpdate.cpp +++ b/launcher/modplatform/flame/FlameCheckUpdate.cpp @@ -124,11 +124,6 @@ void FlameCheckUpdate::executeTask() int i = 0; 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())); setProgress(i++, m_mods.size()); @@ -176,7 +171,7 @@ void FlameCheckUpdate::executeTask() auto download_task = makeShared(pack, latest_ver, m_mods_folder); m_updatable.emplace_back(pack->name, mod->metadata()->hash, old_version, latest_ver.version, - api.getModFileChangelog(latest_ver.addonId.toInt(), latest_ver.fileId.toInt()), + api.getModFileChangelog(latest_ver.addonId.toInt(), latest_ver.fileId.toInt()), mod->enabled(), ModPlatform::ResourceProvider::FLAME, download_task); } } diff --git a/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp b/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp index a7c22832a..41eac6415 100644 --- a/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp +++ b/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp @@ -41,11 +41,6 @@ void ModrinthCheckUpdate::executeTask() ConcurrentTask hashing_task(this, "MakeModrinthHashesTask", 10); 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; // Sadly the API can only handle one hash type per call, se we @@ -163,7 +158,7 @@ void ModrinthCheckUpdate::executeTask() auto download_task = makeShared(pack, project_ver, m_mods_folder); m_updatable.emplace_back(pack->name, hash, mod->version(), project_ver.version_number, project_ver.changelog, - ModPlatform::ResourceProvider::MODRINTH, download_task); + mod->enabled(), ModPlatform::ResourceProvider::MODRINTH, download_task); } } } catch (Json::JsonException& e) { diff --git a/launcher/ui/dialogs/ModUpdateDialog.cpp b/launcher/ui/dialogs/ModUpdateDialog.cpp index 0af1ec59b..639887a5d 100644 --- a/launcher/ui/dialogs/ModUpdateDialog.cpp +++ b/launcher/ui/dialogs/ModUpdateDialog.cpp @@ -5,8 +5,6 @@ #include "ScrollMessageBox.h" #include "ui_ReviewMessageBox.h" -#include "FileSystem.h" -#include "Json.h" #include "Markdown.h" #include "tasks/ConcurrentTask.h" @@ -351,7 +349,7 @@ void ModUpdateDialog::onMetadataFailed(Mod* mod, bool try_others, ModPlatform::R void ModUpdateDialog::appendMod(CheckUpdateTask::UpdatableMod const& info) { auto item_top = new QTreeWidgetItem(ui->modTreeWidget); - item_top->setCheckState(0, Qt::CheckState::Checked); + item_top->setCheckState(0, info.enabled ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); item_top->setText(0, info.name); item_top->setExpanded(true); From c41c39b5d86b168a189a82460fc6edb7873cfa6e Mon Sep 17 00:00:00 2001 From: Trial97 Date: Tue, 15 Aug 2023 23:55:09 +0300 Subject: [PATCH 2/9] cleanup the mod name checking Signed-off-by: Trial97 --- launcher/minecraft/mod/ModFolderModel.cpp | 5 +---- launcher/minecraft/mod/Resource.cpp | 8 ++++++++ launcher/minecraft/mod/Resource.h | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp index 1b96590a4..1f10a5a2f 100644 --- a/launcher/minecraft/mod/ModFolderModel.cpp +++ b/launcher/minecraft/mod/ModFolderModel.cpp @@ -196,10 +196,7 @@ Task* ModFolderModel::createParseTask(Resource& resource) bool ModFolderModel::uninstallMod(const QString& filename, bool preserve_metadata) { for (auto mod : allMods()) { - auto modfilename = mod->fileinfo().fileName(); - if (!mod->enabled() && modfilename.endsWith(".disabled")) - modfilename.chop(9); - if (modfilename == filename) { + if (mod->getOriginalFileName() == filename) { auto index_dir = indexDir(); mod->destroy(index_dir, preserve_metadata, false); diff --git a/launcher/minecraft/mod/Resource.cpp b/launcher/minecraft/mod/Resource.cpp index da806f0f4..6a60473fb 100644 --- a/launcher/minecraft/mod/Resource.cpp +++ b/launcher/minecraft/mod/Resource.cpp @@ -169,3 +169,11 @@ bool Resource::isMoreThanOneHardLink() const { 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; +} \ No newline at end of file diff --git a/launcher/minecraft/mod/Resource.h b/launcher/minecraft/mod/Resource.h index c1ed49461..f0d34705c 100644 --- a/launcher/minecraft/mod/Resource.h +++ b/launcher/minecraft/mod/Resource.h @@ -45,6 +45,7 @@ class Resource : public QObject { [[nodiscard]] auto internal_id() const -> QString { return m_internal_id; } [[nodiscard]] auto type() const -> ResourceType { return m_type; } [[nodiscard]] bool enabled() const { return m_enabled; } + [[nodiscard]] auto getOriginalFileName() const -> QString; [[nodiscard]] virtual auto name() const -> QString { return m_name; } [[nodiscard]] virtual bool valid() const { return m_type != ResourceType::UNKNOWN; } From 0ff98c5876f73556e328cba352fb12566f889e08 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sun, 15 Oct 2023 21:22:59 +0300 Subject: [PATCH 3/9] allways enable dependencies Signed-off-by: Trial97 --- launcher/ui/dialogs/ModUpdateDialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/launcher/ui/dialogs/ModUpdateDialog.cpp b/launcher/ui/dialogs/ModUpdateDialog.cpp index a0c2f2f44..9499378a5 100644 --- a/launcher/ui/dialogs/ModUpdateDialog.cpp +++ b/launcher/ui/dialogs/ModUpdateDialog.cpp @@ -220,8 +220,8 @@ void ModUpdateDialog::checkCandidates() changelog = api.getModFileChangelog(dep->version.addonId.toInt(), dep->version.fileId.toInt()); auto download_task = makeShared(dep->pack, dep->version, m_mod_model); CheckUpdateTask::UpdatableMod updatable = { - dep->pack->name, dep->version.hash, "", dep->version.version, dep->version.version_type, - changelog, dep->pack->provider, download_task + dep->pack->name, dep->version.hash, "", dep->version.version, dep->version.version_type, changelog, true, + dep->pack->provider, download_task }; appendMod(updatable, getRequiredBy.value(dep->version.addonId.toString())); From c07260e836b2e2884e6694f99882d6eebbc7c130 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sun, 7 Jul 2024 02:49:27 +0300 Subject: [PATCH 4/9] remove duplicate code from net folder Signed-off-by: Trial97 --- launcher/CMakeLists.txt | 1 - .../minecraft/auth/steps/EntitlementsStep.cpp | 4 +- .../auth/steps/LauncherLoginStep.cpp | 4 +- .../auth/steps/MSADeviceCodeStep.cpp | 6 +-- .../auth/steps/MinecraftProfileStep.cpp | 4 +- .../auth/steps/XboxAuthorizationStep.cpp | 4 +- .../minecraft/auth/steps/XboxProfileStep.cpp | 4 +- .../minecraft/auth/steps/XboxUserStep.cpp | 4 +- launcher/minecraft/skins/CapeChange.cpp | 16 +++----- launcher/minecraft/skins/CapeChange.h | 4 +- launcher/minecraft/skins/SkinDelete.cpp | 16 +++----- launcher/minecraft/skins/SkinDelete.h | 6 +-- launcher/minecraft/skins/SkinUpload.cpp | 16 +++----- launcher/minecraft/skins/SkinUpload.h | 4 +- .../modplatform/flame/FileResolvingTask.cpp | 4 +- launcher/net/ApiDownload.cpp | 39 +++++-------------- launcher/net/ApiDownload.h | 16 +++----- launcher/net/ApiUpload.cpp | 14 ++----- launcher/net/ApiUpload.h | 10 +---- launcher/net/NetRequest.cpp | 2 - launcher/net/NetRequest.h | 2 - launcher/net/RawHeaderProxy.h | 4 +- launcher/net/StaticHeaderProxy.h | 39 ------------------- launcher/screenshots/ImgurAlbumCreation.cpp | 16 +++----- launcher/screenshots/ImgurAlbumCreation.h | 2 - launcher/screenshots/ImgurUpload.cpp | 12 ++---- launcher/screenshots/ImgurUpload.h | 2 - launcher/ui/dialogs/ProfileSetupDialog.cpp | 6 +-- 28 files changed, 72 insertions(+), 189 deletions(-) delete mode 100644 launcher/net/StaticHeaderProxy.h diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 366719dec..0208c5ec3 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -138,7 +138,6 @@ set(NET_SOURCES net/HeaderProxy.h net/RawHeaderProxy.h net/ApiHeaderProxy.h - net/StaticHeaderProxy.h net/ApiDownload.h net/ApiDownload.cpp net/ApiUpload.cpp diff --git a/launcher/minecraft/auth/steps/EntitlementsStep.cpp b/launcher/minecraft/auth/steps/EntitlementsStep.cpp index 19cbe6898..24b9677cf 100644 --- a/launcher/minecraft/auth/steps/EntitlementsStep.cpp +++ b/launcher/minecraft/auth/steps/EntitlementsStep.cpp @@ -10,7 +10,7 @@ #include "Logging.h" #include "minecraft/auth/Parsers.h" #include "net/Download.h" -#include "net/StaticHeaderProxy.h" +#include "net/RawHeaderProxy.h" #include "tasks/Task.h" EntitlementsStep::EntitlementsStep(AccountData* data) : AuthStep(data) {} @@ -32,7 +32,7 @@ void EntitlementsStep::perform() m_response.reset(new QByteArray()); m_task = Net::Download::makeByteArray(url, m_response); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_task->addHeaderProxy(new Net::RawHeaderProxy(headers)); connect(m_task.get(), &Task::finished, this, &EntitlementsStep::onRequestDone); diff --git a/launcher/minecraft/auth/steps/LauncherLoginStep.cpp b/launcher/minecraft/auth/steps/LauncherLoginStep.cpp index d72346c74..3f5a4e8cc 100644 --- a/launcher/minecraft/auth/steps/LauncherLoginStep.cpp +++ b/launcher/minecraft/auth/steps/LauncherLoginStep.cpp @@ -7,7 +7,7 @@ #include "Logging.h" #include "minecraft/auth/Parsers.h" #include "net/NetUtils.h" -#include "net/StaticHeaderProxy.h" +#include "net/RawHeaderProxy.h" #include "net/Upload.h" LauncherLoginStep::LauncherLoginStep(AccountData* data) : AuthStep(data) {} @@ -38,7 +38,7 @@ void LauncherLoginStep::perform() m_response.reset(new QByteArray()); m_task = Net::Upload::makeByteArray(url, m_response, requestBody.toUtf8()); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_task->addHeaderProxy(new Net::RawHeaderProxy(headers)); connect(m_task.get(), &Task::finished, this, &LauncherLoginStep::onRequestDone); diff --git a/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp b/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp index 7df93d04d..19cce2a81 100644 --- a/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp +++ b/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp @@ -40,7 +40,7 @@ #include "Application.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 MSADeviceCodeStep::MSADeviceCodeStep(AccountData* data) : AuthStep(data) @@ -68,7 +68,7 @@ void MSADeviceCodeStep::perform() }; m_response.reset(new QByteArray()); m_task = Net::Upload::makeByteArray(url, m_response, payload); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_task->addHeaderProxy(new Net::RawHeaderProxy(headers)); connect(m_task.get(), &Task::finished, this, &MSADeviceCodeStep::deviceAutorizationFinished); @@ -180,7 +180,7 @@ void MSADeviceCodeStep::authenticateUser() }; m_response.reset(new QByteArray()); m_task = Net::Upload::makeByteArray(url, m_response, payload); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_task->addHeaderProxy(new Net::RawHeaderProxy(headers)); connect(m_task.get(), &Task::finished, this, &MSADeviceCodeStep::authenticationFinished); diff --git a/launcher/minecraft/auth/steps/MinecraftProfileStep.cpp b/launcher/minecraft/auth/steps/MinecraftProfileStep.cpp index aef6f43af..145eabec2 100644 --- a/launcher/minecraft/auth/steps/MinecraftProfileStep.cpp +++ b/launcher/minecraft/auth/steps/MinecraftProfileStep.cpp @@ -5,7 +5,7 @@ #include "Application.h" #include "minecraft/auth/Parsers.h" #include "net/NetUtils.h" -#include "net/StaticHeaderProxy.h" +#include "net/RawHeaderProxy.h" MinecraftProfileStep::MinecraftProfileStep(AccountData* data) : AuthStep(data) {} @@ -23,7 +23,7 @@ void MinecraftProfileStep::perform() m_response.reset(new QByteArray()); m_task = Net::Download::makeByteArray(url, m_response); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_task->addHeaderProxy(new Net::RawHeaderProxy(headers)); connect(m_task.get(), &Task::finished, this, &MinecraftProfileStep::onRequestDone); diff --git a/launcher/minecraft/auth/steps/XboxAuthorizationStep.cpp b/launcher/minecraft/auth/steps/XboxAuthorizationStep.cpp index f07220986..f5a890dc4 100644 --- a/launcher/minecraft/auth/steps/XboxAuthorizationStep.cpp +++ b/launcher/minecraft/auth/steps/XboxAuthorizationStep.cpp @@ -8,7 +8,7 @@ #include "Logging.h" #include "minecraft/auth/Parsers.h" #include "net/NetUtils.h" -#include "net/StaticHeaderProxy.h" +#include "net/RawHeaderProxy.h" #include "net/Upload.h" XboxAuthorizationStep::XboxAuthorizationStep(AccountData* data, Token* token, QString relyingParty, QString authorizationKind) @@ -43,7 +43,7 @@ void XboxAuthorizationStep::perform() }; m_response.reset(new QByteArray()); m_task = Net::Upload::makeByteArray(url, m_response, xbox_auth_data.toUtf8()); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_task->addHeaderProxy(new Net::RawHeaderProxy(headers)); connect(m_task.get(), &Task::finished, this, &XboxAuthorizationStep::onRequestDone); diff --git a/launcher/minecraft/auth/steps/XboxProfileStep.cpp b/launcher/minecraft/auth/steps/XboxProfileStep.cpp index 440a4657c..5777bd2e4 100644 --- a/launcher/minecraft/auth/steps/XboxProfileStep.cpp +++ b/launcher/minecraft/auth/steps/XboxProfileStep.cpp @@ -6,7 +6,7 @@ #include "Application.h" #include "Logging.h" #include "net/NetUtils.h" -#include "net/StaticHeaderProxy.h" +#include "net/RawHeaderProxy.h" XboxProfileStep::XboxProfileStep(AccountData* data) : AuthStep(data) {} @@ -35,7 +35,7 @@ void XboxProfileStep::perform() m_response.reset(new QByteArray()); m_task = Net::Download::makeByteArray(url, m_response); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_task->addHeaderProxy(new Net::RawHeaderProxy(headers)); connect(m_task.get(), &Task::finished, this, &XboxProfileStep::onRequestDone); diff --git a/launcher/minecraft/auth/steps/XboxUserStep.cpp b/launcher/minecraft/auth/steps/XboxUserStep.cpp index c9453dba1..561fa0767 100644 --- a/launcher/minecraft/auth/steps/XboxUserStep.cpp +++ b/launcher/minecraft/auth/steps/XboxUserStep.cpp @@ -5,7 +5,7 @@ #include "Application.h" #include "minecraft/auth/Parsers.h" #include "net/NetUtils.h" -#include "net/StaticHeaderProxy.h" +#include "net/RawHeaderProxy.h" XboxUserStep::XboxUserStep(AccountData* data) : AuthStep(data) {} @@ -39,7 +39,7 @@ void XboxUserStep::perform() }; m_response.reset(new QByteArray()); m_task = Net::Upload::makeByteArray(url, m_response, xbox_auth_data.toUtf8()); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_task->addHeaderProxy(new Net::RawHeaderProxy(headers)); connect(m_task.get(), &Task::finished, this, &XboxUserStep::onRequestDone); diff --git a/launcher/minecraft/skins/CapeChange.cpp b/launcher/minecraft/skins/CapeChange.cpp index 4db28e245..abbaa0b67 100644 --- a/launcher/minecraft/skins/CapeChange.cpp +++ b/launcher/minecraft/skins/CapeChange.cpp @@ -39,9 +39,9 @@ #include #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; } @@ -57,18 +57,14 @@ QNetworkReply* CapeChange::getReply(QNetworkRequest& request) } } -void CapeChange::init() -{ - addHeaderProxy(new Net::StaticHeaderProxy(QList{ - { "Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit() }, - })); -} - CapeChange::Ptr CapeChange::make(QString token, QString capeId) { - auto up = makeShared(token, capeId); + auto up = makeShared(capeId); up->m_url = QUrl("https://api.minecraftservices.com/minecraft/profile/capes/active"); up->setObjectName(QString("BYTES:") + up->m_url.toString()); up->m_sink.reset(new Net::ByteArraySink(std::make_shared())); + up->addHeaderProxy(new Net::RawHeaderProxy(QList{ + { "Authorization", QString("Bearer %1").arg(token).toLocal8Bit() }, + })); return up; } diff --git a/launcher/minecraft/skins/CapeChange.h b/launcher/minecraft/skins/CapeChange.h index bcafcde87..2be904f4d 100644 --- a/launcher/minecraft/skins/CapeChange.h +++ b/launcher/minecraft/skins/CapeChange.h @@ -24,16 +24,14 @@ class CapeChange : public Net::NetRequest { Q_OBJECT public: using Ptr = shared_qobject_ptr; - CapeChange(QString token, QString capeId); + CapeChange(QString capeId); virtual ~CapeChange() = default; static CapeChange::Ptr make(QString token, QString capeId); - void init() override; protected: virtual QNetworkReply* getReply(QNetworkRequest&) override; private: QString m_capeId; - QString m_token; }; diff --git a/launcher/minecraft/skins/SkinDelete.cpp b/launcher/minecraft/skins/SkinDelete.cpp index 3c50cf313..94aca62ca 100644 --- a/launcher/minecraft/skins/SkinDelete.cpp +++ b/launcher/minecraft/skins/SkinDelete.cpp @@ -37,9 +37,9 @@ #include "SkinDelete.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; } @@ -50,17 +50,13 @@ QNetworkReply* SkinDelete::getReply(QNetworkRequest& request) return m_network->deleteResource(request); } -void SkinDelete::init() -{ - addHeaderProxy(new Net::StaticHeaderProxy(QList{ - { "Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit() }, - })); -} - SkinDelete::Ptr SkinDelete::make(QString token) { - auto up = makeShared(token); + auto up = makeShared(); up->m_url = QUrl("https://api.minecraftservices.com/minecraft/profile/skins/active"); up->m_sink.reset(new Net::ByteArraySink(std::make_shared())); + up->addHeaderProxy(new Net::RawHeaderProxy(QList{ + { "Authorization", QString("Bearer %1").arg(token).toLocal8Bit() }, + })); return up; } diff --git a/launcher/minecraft/skins/SkinDelete.h b/launcher/minecraft/skins/SkinDelete.h index 5d02e0cc4..d6a68d22c 100644 --- a/launcher/minecraft/skins/SkinDelete.h +++ b/launcher/minecraft/skins/SkinDelete.h @@ -24,15 +24,11 @@ class SkinDelete : public Net::NetRequest { Q_OBJECT public: using Ptr = shared_qobject_ptr; - SkinDelete(QString token); + SkinDelete(); virtual ~SkinDelete() = default; static SkinDelete::Ptr make(QString token); - void init() override; protected: virtual QNetworkReply* getReply(QNetworkRequest&) override; - - private: - QString m_token; }; diff --git a/launcher/minecraft/skins/SkinUpload.cpp b/launcher/minecraft/skins/SkinUpload.cpp index dc1bc0bf9..ccc29d281 100644 --- a/launcher/minecraft/skins/SkinUpload.cpp +++ b/launcher/minecraft/skins/SkinUpload.cpp @@ -40,9 +40,9 @@ #include "FileSystem.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; } @@ -67,18 +67,14 @@ QNetworkReply* SkinUpload::getReply(QNetworkRequest& request) return m_network->post(request, multiPart); } -void SkinUpload::init() -{ - addHeaderProxy(new Net::StaticHeaderProxy(QList{ - { "Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit() }, - })); -} - SkinUpload::Ptr SkinUpload::make(QString token, QString path, QString variant) { - auto up = makeShared(token, path, variant); + auto up = makeShared(path, variant); up->m_url = QUrl("https://api.minecraftservices.com/minecraft/profile/skins"); up->setObjectName(QString("BYTES:") + up->m_url.toString()); up->m_sink.reset(new Net::ByteArraySink(std::make_shared())); + up->addHeaderProxy(new Net::RawHeaderProxy(QList{ + { "Authorization", QString("Bearer %1").arg(token).toLocal8Bit() }, + })); return up; } diff --git a/launcher/minecraft/skins/SkinUpload.h b/launcher/minecraft/skins/SkinUpload.h index f24cef5a2..c1a4930b7 100644 --- a/launcher/minecraft/skins/SkinUpload.h +++ b/launcher/minecraft/skins/SkinUpload.h @@ -26,17 +26,15 @@ class SkinUpload : public Net::NetRequest { using Ptr = shared_qobject_ptr; // Note this class takes ownership of the file. - SkinUpload(QString token, QString path, QString variant); + SkinUpload(QString path, QString variant); virtual ~SkinUpload() = default; static SkinUpload::Ptr make(QString token, QString path, QString variant); - void init() override; protected: virtual QNetworkReply* getReply(QNetworkRequest&) override; private: - QString m_token; QString m_path; QString m_variant; }; diff --git a/launcher/modplatform/flame/FileResolvingTask.cpp b/launcher/modplatform/flame/FileResolvingTask.cpp index 8d23896d9..f81452c96 100644 --- a/launcher/modplatform/flame/FileResolvingTask.cpp +++ b/launcher/modplatform/flame/FileResolvingTask.cpp @@ -103,7 +103,7 @@ void Flame::FileResolvingTask::netJobFinished() auto url = QString("https://api.modrinth.com/v2/version_file/%1?algorithm=sha1").arg(hash); auto output = std::make_shared(); auto dl = Net::ApiDownload::makeByteArray(QUrl(url), output); - QObject::connect(dl.get(), &Net::ApiDownload::succeeded, [&out]() { out.resolved = true; }); + QObject::connect(dl.get(), &Task::succeeded, [&out]() { out.resolved = true; }); m_checkJob->addNetAction(dl); blockedProjects.insert(&out, output); @@ -175,7 +175,7 @@ void Flame::FileResolvingTask::modrinthCheckFinished() auto url = QString("https://api.curseforge.com/v1/mods/%1").arg(projectId); auto dl = Net::ApiDownload::makeByteArray(url, output); qDebug() << "Fetching url slug for file:" << mod->fileName; - QObject::connect(dl.get(), &Net::ApiDownload::succeeded, [block, index, output]() { + QObject::connect(dl.get(), &Task::succeeded, [block, index, output]() { auto mod = block->at(index); // use the shared_ptr so it is captured and only freed when we are done auto json = QJsonDocument::fromJson(*output); auto base = diff --git a/launcher/net/ApiDownload.cpp b/launcher/net/ApiDownload.cpp index 8768b63f8..78eb1f851 100644 --- a/launcher/net/ApiDownload.cpp +++ b/launcher/net/ApiDownload.cpp @@ -18,48 +18,29 @@ */ #include "net/ApiDownload.h" -#include "ByteArraySink.h" -#include "ChecksumValidator.h" -#include "MetaCacheSink.h" +#include "net/ApiHeaderProxy.h" 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(); - dl->m_url = url; - 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); + auto dl = Download::makeCached(url, entry, options); + dl->addHeaderProxy(new ApiHeaderProxy()); return dl; } -auto ApiDownload::makeByteArray(QUrl url, std::shared_ptr output, Options options) -> Download::Ptr +Download::Ptr ApiDownload::makeByteArray(QUrl url, std::shared_ptr output, Download::Options options) { - auto dl = makeShared(); - dl->m_url = url; - dl->setObjectName(QString("BYTES:") + url.toString()); - dl->m_options = options; - dl->m_sink.reset(new ByteArraySink(output)); + auto dl = Download::makeByteArray(url, output, options); + dl->addHeaderProxy(new ApiHeaderProxy()); 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(); - dl->m_url = url; - dl->setObjectName(QString("FILE:") + url.toString()); - dl->m_options = options; - dl->m_sink.reset(new FileSink(path)); + auto dl = Download::makeFile(url, path, options); + dl->addHeaderProxy(new ApiHeaderProxy()); return dl; } -void ApiDownload::init() -{ - qDebug() << "Setting up api download"; - auto api_headers = new ApiHeaderProxy(); - addHeaderProxy(api_headers); -} } // namespace Net diff --git a/launcher/net/ApiDownload.h b/launcher/net/ApiDownload.h index 638c94e11..842c25c56 100644 --- a/launcher/net/ApiDownload.h +++ b/launcher/net/ApiDownload.h @@ -19,20 +19,14 @@ #pragma once -#include "ApiHeaderProxy.h" #include "Download.h" namespace Net { -class ApiDownload : public Download { - public: - virtual ~ApiDownload() = default; - - static auto makeCached(QUrl url, MetaEntryPtr entry, Options options = Option::NoOptions) -> Download::Ptr; - static auto makeByteArray(QUrl url, std::shared_ptr output, Options options = Option::NoOptions) -> Download::Ptr; - static auto makeFile(QUrl url, QString path, Options options = Option::NoOptions) -> Download::Ptr; - - void init() override; -}; +namespace ApiDownload { +Download::Ptr makeCached(QUrl url, MetaEntryPtr entry, Download::Options options = Download::Option::NoOptions); +Download::Ptr makeByteArray(QUrl url, std::shared_ptr output, Download::Options options = Download::Option::NoOptions); +Download::Ptr makeFile(QUrl url, QString path, Download::Options options = Download::Option::NoOptions); +}; // namespace ApiDownload } // namespace Net diff --git a/launcher/net/ApiUpload.cpp b/launcher/net/ApiUpload.cpp index 505cbd9f9..a2b8f357b 100644 --- a/launcher/net/ApiUpload.cpp +++ b/launcher/net/ApiUpload.cpp @@ -18,23 +18,15 @@ */ #include "net/ApiUpload.h" -#include "ByteArraySink.h" +#include "net/ApiHeaderProxy.h" namespace Net { Upload::Ptr ApiUpload::makeByteArray(QUrl url, std::shared_ptr output, QByteArray m_post_data) { - auto up = makeShared(); - up->m_url = std::move(url); - up->m_sink.reset(new ByteArraySink(output)); - up->m_post_data = std::move(m_post_data); + auto up = Upload::makeByteArray(url, output, m_post_data); + up->addHeaderProxy(new ApiHeaderProxy()); return up; } -void ApiUpload::init() -{ - qDebug() << "Setting up api upload"; - auto api_headers = new ApiHeaderProxy(); - addHeaderProxy(api_headers); -} } // namespace Net diff --git a/launcher/net/ApiUpload.h b/launcher/net/ApiUpload.h index b12842b05..674a3b93f 100644 --- a/launcher/net/ApiUpload.h +++ b/launcher/net/ApiUpload.h @@ -19,18 +19,12 @@ #pragma once -#include "ApiHeaderProxy.h" #include "Upload.h" namespace Net { -class ApiUpload : public Upload { - public: - virtual ~ApiUpload() = default; - - static Upload::Ptr makeByteArray(QUrl url, std::shared_ptr output, QByteArray m_post_data); - - void init() override; +namespace ApiUpload { +Upload::Ptr makeByteArray(QUrl url, std::shared_ptr output, QByteArray m_post_data); }; } // namespace Net diff --git a/launcher/net/NetRequest.cpp b/launcher/net/NetRequest.cpp index 203f1f950..e8e858350 100644 --- a/launcher/net/NetRequest.cpp +++ b/launcher/net/NetRequest.cpp @@ -62,8 +62,6 @@ void NetRequest::addValidator(Validator* v) void NetRequest::executeTask() { - init(); - setStatus(tr("Requesting %1").arg(StringUtils::truncateUrlHumanFriendly(m_url, 80))); if (getState() == Task::State::AbortedByUser) { diff --git a/launcher/net/NetRequest.h b/launcher/net/NetRequest.h index 0cd6ceabc..6b3f643d6 100644 --- a/launcher/net/NetRequest.h +++ b/launcher/net/NetRequest.h @@ -72,8 +72,6 @@ class NetRequest : public Task { void setNetwork(shared_qobject_ptr network) { m_network = network; } void addHeaderProxy(Net::HeaderProxy* proxy) { m_headerProxies.push_back(std::shared_ptr(proxy)); } - virtual void init() {} - QUrl url() const; void setUrl(QUrl url) { m_url = url; } int replyStatusCode() const; diff --git a/launcher/net/RawHeaderProxy.h b/launcher/net/RawHeaderProxy.h index 09b3d4d02..682cc9e4d 100644 --- a/launcher/net/RawHeaderProxy.h +++ b/launcher/net/RawHeaderProxy.h @@ -4,6 +4,7 @@ * Copyright (c) 2022 flowln * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com> + * Copyright (c) 2023 Trial97 * * 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 @@ -27,7 +28,7 @@ namespace Net { class RawHeaderProxy : public HeaderProxy { public: - RawHeaderProxy() : HeaderProxy() {} + RawHeaderProxy(QList headers = {}) : HeaderProxy(), m_headers(headers) {}; virtual ~RawHeaderProxy() = default; public: @@ -36,6 +37,7 @@ class RawHeaderProxy : public HeaderProxy { void addHeader(const HeaderPair& header) { m_headers.append(header); } void addHeader(const QByteArray& headerName, const QByteArray& headerValue) { m_headers.append({ headerName, headerValue }); } void addHeaders(const QList& headers) { m_headers.append(headers); } + void setHeaders(QList headers) { m_headers = headers; }; private: QList m_headers; diff --git a/launcher/net/StaticHeaderProxy.h b/launcher/net/StaticHeaderProxy.h deleted file mode 100644 index 73678c026..000000000 --- a/launcher/net/StaticHeaderProxy.h +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/* - * Prism Launcher - Minecraft Launcher - * Copyright (c) 2023 Trial97 - * - * 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 . - * - */ - -#pragma once - -#include "net/HeaderProxy.h" - -namespace Net { - -class StaticHeaderProxy : public HeaderProxy { - public: - StaticHeaderProxy(QList hdrs = {}) : HeaderProxy(), m_hdrs(hdrs) {}; - virtual ~StaticHeaderProxy() = default; - - public: - virtual QList headers(const QNetworkRequest&) const override { return m_hdrs; }; - void setHeaders(QList hdrs) { m_hdrs = hdrs; }; - - private: - QList m_hdrs; -}; - -} // namespace Net diff --git a/launcher/screenshots/ImgurAlbumCreation.cpp b/launcher/screenshots/ImgurAlbumCreation.cpp index c63c8b39b..8eecc2aaa 100644 --- a/launcher/screenshots/ImgurAlbumCreation.cpp +++ b/launcher/screenshots/ImgurAlbumCreation.cpp @@ -46,7 +46,7 @@ #include #include "BuildConfig.h" -#include "net/StaticHeaderProxy.h" +#include "net/RawHeaderProxy.h" Net::NetRequest::Ptr ImgurAlbumCreation::make(std::shared_ptr output, QList screenshots) { @@ -54,6 +54,10 @@ Net::NetRequest::Ptr ImgurAlbumCreation::make(std::shared_ptrm_url = BuildConfig.IMGUR_BASE_URL + "album"; up->m_sink.reset(new Sink(output)); up->m_screenshots = screenshots; + up->addHeaderProxy(new Net::RawHeaderProxy( + QList{ { "Content-Type", "application/x-www-form-urlencoded" }, + { "Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toUtf8() }, + { "Accept", "application/json" } })); return up; } @@ -67,16 +71,6 @@ QNetworkReply* ImgurAlbumCreation::getReply(QNetworkRequest& request) return m_network->post(request, data); }; -void ImgurAlbumCreation::init() -{ - qDebug() << "Setting up imgur upload"; - auto api_headers = new Net::StaticHeaderProxy( - QList{ { "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 { m_output.clear(); diff --git a/launcher/screenshots/ImgurAlbumCreation.h b/launcher/screenshots/ImgurAlbumCreation.h index ecb225394..f10409b20 100644 --- a/launcher/screenshots/ImgurAlbumCreation.h +++ b/launcher/screenshots/ImgurAlbumCreation.h @@ -67,8 +67,6 @@ class ImgurAlbumCreation : public Net::NetRequest { static NetRequest::Ptr make(std::shared_ptr output, QList screenshots); QNetworkReply* getReply(QNetworkRequest& request) override; - void init() override; - private: QList m_screenshots; }; diff --git a/launcher/screenshots/ImgurUpload.cpp b/launcher/screenshots/ImgurUpload.cpp index 941b92ce6..78b50f52e 100644 --- a/launcher/screenshots/ImgurUpload.cpp +++ b/launcher/screenshots/ImgurUpload.cpp @@ -36,7 +36,7 @@ #include "ImgurUpload.h" #include "BuildConfig.h" -#include "net/StaticHeaderProxy.h" +#include "net/RawHeaderProxy.h" #include #include @@ -47,14 +47,6 @@ #include #include -void ImgurUpload::init() -{ - qDebug() << "Setting up imgur upload"; - auto api_headers = new Net::StaticHeaderProxy(QList{ - { "Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toUtf8() }, { "Accept", "application/json" } }); - addHeaderProxy(api_headers); -} - QNetworkReply* ImgurUpload::getReply(QNetworkRequest& request) { auto file = new QFile(m_fileInfo.absoluteFilePath(), this); @@ -125,5 +117,7 @@ Net::NetRequest::Ptr ImgurUpload::make(ScreenShot::Ptr m_shot) auto up = makeShared(m_shot->m_file); up->m_url = std::move(BuildConfig.IMGUR_BASE_URL + "image"); up->m_sink.reset(new Sink(m_shot)); + up->addHeaderProxy(new Net::RawHeaderProxy(QList{ + { "Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toUtf8() }, { "Accept", "application/json" } })); return up; } diff --git a/launcher/screenshots/ImgurUpload.h b/launcher/screenshots/ImgurUpload.h index 5a58ad2b5..f4f71859d 100644 --- a/launcher/screenshots/ImgurUpload.h +++ b/launcher/screenshots/ImgurUpload.h @@ -62,8 +62,6 @@ class ImgurUpload : public Net::NetRequest { static NetRequest::Ptr make(ScreenShot::Ptr m_shot); - void init() override; - private: virtual QNetworkReply* getReply(QNetworkRequest&) override; const QFileInfo m_fileInfo; diff --git a/launcher/ui/dialogs/ProfileSetupDialog.cpp b/launcher/ui/dialogs/ProfileSetupDialog.cpp index c5d4c2621..385094e23 100644 --- a/launcher/ui/dialogs/ProfileSetupDialog.cpp +++ b/launcher/ui/dialogs/ProfileSetupDialog.cpp @@ -34,6 +34,7 @@ */ #include "ProfileSetupDialog.h" +#include "net/RawHeaderProxy.h" #include "ui_ProfileSetupDialog.h" #include @@ -46,7 +47,6 @@ #include #include "minecraft/auth/Parsers.h" -#include "net/StaticHeaderProxy.h" #include "net/Upload.h" ProfileSetupDialog::ProfileSetupDialog(MinecraftAccountPtr accountToSetup, QWidget* parent) @@ -160,7 +160,7 @@ void ProfileSetupDialog::checkName(const QString& name) if (m_check_task) disconnect(m_check_task.get(), nullptr, this, nullptr); 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); @@ -204,7 +204,7 @@ void ProfileSetupDialog::setupProfile(const QString& profileName) m_profile_response.reset(new QByteArray()); 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); From e5b1fa1e3a2eecd4849dd7f77e93fb8d1b4ee44d Mon Sep 17 00:00:00 2001 From: Edgars Cirulis Date: Tue, 9 Jul 2024 02:21:50 +0300 Subject: [PATCH 5/9] readme: build instructions Signed-off-by: Edgars Cirulis --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b32132d49..9c4909509 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,12 @@ The translation effort for Prism Launcher is hosted on [Weblate](https://hosted. ## 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 From 3076e5b961d2e0a24ff8fec9d0d1c1e1b95e3cd2 Mon Sep 17 00:00:00 2001 From: Edgars Cirulis Date: Tue, 9 Jul 2024 22:21:13 +0300 Subject: [PATCH 6/9] remove useless BUILD.md orphaned file Signed-off-by: Edgars Cirulis --- BUILD.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 BUILD.md diff --git a/BUILD.md b/BUILD.md deleted file mode 100644 index a139039df..000000000 --- a/BUILD.md +++ /dev/null @@ -1,3 +0,0 @@ -# Build Instructions - -Full build instructions are available on [the website](https://prismlauncher.org/wiki/development/build-instructions/). From 33bf370d17a90f6bfaa4859a05db4230e5dadd92 Mon Sep 17 00:00:00 2001 From: Alexandru Ionut Tripon Date: Mon, 22 Jul 2024 21:51:20 +0300 Subject: [PATCH 7/9] Update launcher/net/RawHeaderProxy.h Co-authored-by: TheKodeToad Signed-off-by: Alexandru Ionut Tripon --- launcher/net/RawHeaderProxy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/net/RawHeaderProxy.h b/launcher/net/RawHeaderProxy.h index 682cc9e4d..9de18efc7 100644 --- a/launcher/net/RawHeaderProxy.h +++ b/launcher/net/RawHeaderProxy.h @@ -28,7 +28,7 @@ namespace Net { class RawHeaderProxy : public HeaderProxy { public: - RawHeaderProxy(QList headers = {}) : HeaderProxy(), m_headers(headers) {}; + RawHeaderProxy(QList headers = {}) : HeaderProxy(), m_headers(std::move(headers)) {}; virtual ~RawHeaderProxy() = default; public: From 61e62dce1bd7727b85679b7e3b76af9a382e1f59 Mon Sep 17 00:00:00 2001 From: src_resources Date: Mon, 29 Jul 2024 21:04:23 +0800 Subject: [PATCH 8/9] Fix a typo in comment Signed-off-by: src_resources --- launcher/FileSystem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index 66adf7a36..c5beef7bd 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -72,7 +72,7 @@ void appendSafe(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); From ca5df3ea609be9962a58af85471006da4b355bb0 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Tue, 30 Jul 2024 01:32:46 +0300 Subject: [PATCH 9/9] ensure minimal folder permissions when extracting files Signed-off-by: Trial97 --- launcher/MMCZip.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/launcher/MMCZip.cpp b/launcher/MMCZip.cpp index 00658b42b..cb9ee9940 100644 --- a/launcher/MMCZip.cpp +++ b/launcher/MMCZip.cpp @@ -344,6 +344,17 @@ std::optional extractSubDir(QuaZip* zip, const QString& subdir, con 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; } while (zip->goToNextFile()); @@ -560,7 +571,7 @@ auto ExtractZipTask::extractZip() -> ZipResult if (!file_name.startsWith(m_subdirectory)) 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; 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)); } } + } 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;