From 7705f290ca69c0478f698ddf06a5f1edb731e8fc Mon Sep 17 00:00:00 2001 From: flow Date: Tue, 15 Nov 2022 12:07:11 -0300 Subject: fix: don't retry to load RP images that can't fit in the cache Avoids an infinite loop when the image is too big. Signed-off-by: flow --- launcher/minecraft/mod/ResourcePack.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/mod/ResourcePack.cpp b/launcher/minecraft/mod/ResourcePack.cpp index 3fc10a2f..b97bedf8 100644 --- a/launcher/minecraft/mod/ResourcePack.cpp +++ b/launcher/minecraft/mod/ResourcePack.cpp @@ -47,6 +47,12 @@ void ResourcePack::setImage(QImage new_image) m_pack_image_cache_key.key = QPixmapCache::insert(QPixmap::fromImage(new_image)); m_pack_image_cache_key.was_ever_used = true; + + // This can happen if the pixmap is too big to fit in the cache :c + if (!m_pack_image_cache_key.key.isValid()) { + qWarning() << "Could not insert a image cache entry! Ignoring it."; + m_pack_image_cache_key.was_ever_used = false; + } } QPixmap ResourcePack::image(QSize size) -- cgit From c4c1e75de8825a4af403046536a7b2acd72a56c3 Mon Sep 17 00:00:00 2001 From: flow Date: Tue, 15 Nov 2022 18:13:15 -0300 Subject: fix: use QPixmapCache only from the main thread It's a required condition. Signed-off-by: flow --- launcher/Application.cpp | 6 +++ launcher/CMakeLists.txt | 2 + launcher/MTPixmapCache.h | 95 +++++++++++++++++++++++++++++++++ launcher/minecraft/mod/ResourcePack.cpp | 8 +-- 4 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 launcher/MTPixmapCache.h (limited to 'launcher/minecraft') diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 45cd9422..c3d624ad 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -90,6 +90,7 @@ #include #include "InstanceList.h" +#include "MTPixmapCache.h" #include #include "icons/IconList.h" @@ -134,6 +135,8 @@ static const QLatin1String liveCheckFile("live.check"); +PixmapCache* PixmapCache::s_instance = nullptr; + namespace { void appDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) { @@ -693,6 +696,9 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); } + + PixmapCache::setInstance(new PixmapCache(this)); + qDebug() << "<> Settings loaded."; } diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 8db93429..0605be23 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -89,6 +89,8 @@ set(CORE_SOURCES # Time MMCTime.h MMCTime.cpp + + MTPixmapCache.h ) set(PATHMATCHER_SOURCES diff --git a/launcher/MTPixmapCache.h b/launcher/MTPixmapCache.h new file mode 100644 index 00000000..57847a0e --- /dev/null +++ b/launcher/MTPixmapCache.h @@ -0,0 +1,95 @@ +#pragma once + +#include +#include +#include + +#define GET_TYPE() \ + Qt::ConnectionType type; \ + if (QThread::currentThread() != QCoreApplication::instance()->thread()) \ + type = Qt::BlockingQueuedConnection; \ + else \ + type = Qt::DirectConnection; + +#define DEFINE_FUNC_NO_PARAM(NAME, RET_TYPE) \ + static RET_TYPE NAME() \ + { \ + RET_TYPE ret; \ + GET_TYPE() \ + QMetaObject::invokeMethod(s_instance, "_" #NAME, type, Q_RETURN_ARG(RET_TYPE, ret)); \ + return ret; \ + } +#define DEFINE_FUNC_ONE_PARAM(NAME, RET_TYPE, PARAM_1_TYPE) \ + static RET_TYPE NAME(PARAM_1_TYPE p1) \ + { \ + RET_TYPE ret; \ + GET_TYPE() \ + QMetaObject::invokeMethod(s_instance, "_" #NAME, type, Q_RETURN_ARG(RET_TYPE, ret), Q_ARG(PARAM_1_TYPE, p1)); \ + return ret; \ + } +#define DEFINE_FUNC_TWO_PARAM(NAME, RET_TYPE, PARAM_1_TYPE, PARAM_2_TYPE) \ + static RET_TYPE NAME(PARAM_1_TYPE p1, PARAM_2_TYPE p2) \ + { \ + RET_TYPE ret; \ + GET_TYPE() \ + QMetaObject::invokeMethod(s_instance, "_" #NAME, type, Q_RETURN_ARG(RET_TYPE, ret), Q_ARG(PARAM_1_TYPE, p1), \ + Q_ARG(PARAM_2_TYPE, p2)); \ + return ret; \ + } + +/** A wrapper around QPixmapCache with thread affinity with the main thread. + */ +class PixmapCache final : public QObject { + Q_OBJECT + + public: + PixmapCache(QObject* parent) : QObject(parent) {} + ~PixmapCache() override = default; + + static PixmapCache& instance() { return *s_instance; } + static void setInstance(PixmapCache* i) { s_instance = i; } + + public: + DEFINE_FUNC_NO_PARAM(cacheLimit, int) + DEFINE_FUNC_NO_PARAM(clear, bool) + DEFINE_FUNC_TWO_PARAM(find, bool, const QString&, QPixmap*) + DEFINE_FUNC_TWO_PARAM(find, bool, const QPixmapCache::Key&, QPixmap*) + DEFINE_FUNC_TWO_PARAM(insert, bool, const QString&, const QPixmap&) + DEFINE_FUNC_ONE_PARAM(insert, QPixmapCache::Key, const QPixmap&) + DEFINE_FUNC_ONE_PARAM(remove, bool, const QString&) + DEFINE_FUNC_ONE_PARAM(remove, bool, const QPixmapCache::Key&) + DEFINE_FUNC_TWO_PARAM(replace, bool, const QPixmapCache::Key&, const QPixmap&) + DEFINE_FUNC_ONE_PARAM(setCacheLimit, bool, int) + + // NOTE: Every function returns something non-void to simplify the macros. + private slots: + int _cacheLimit() { return QPixmapCache::cacheLimit(); } + bool _clear() + { + QPixmapCache::clear(); + return true; + } + bool _find(const QString& key, QPixmap* pixmap) { return QPixmapCache::find(key, pixmap); } + bool _find(const QPixmapCache::Key& key, QPixmap* pixmap) { return QPixmapCache::find(key, pixmap); } + bool _insert(const QString& key, const QPixmap& pixmap) { return QPixmapCache::insert(key, pixmap); } + QPixmapCache::Key _insert(const QPixmap& pixmap) { return QPixmapCache::insert(pixmap); } + bool _remove(const QString& key) + { + QPixmapCache::remove(key); + return true; + } + bool _remove(const QPixmapCache::Key& key) + { + QPixmapCache::remove(key); + return true; + } + bool _replace(const QPixmapCache::Key& key, const QPixmap& pixmap) { return QPixmapCache::replace(key, pixmap); } + bool _setCacheLimit(int n) + { + QPixmapCache::setCacheLimit(n); + return true; + } + + private: + static PixmapCache* s_instance; +}; diff --git a/launcher/minecraft/mod/ResourcePack.cpp b/launcher/minecraft/mod/ResourcePack.cpp index b97bedf8..242fd9fe 100644 --- a/launcher/minecraft/mod/ResourcePack.cpp +++ b/launcher/minecraft/mod/ResourcePack.cpp @@ -1,9 +1,11 @@ #include "ResourcePack.h" +#include #include #include #include +#include "MTPixmapCache.h" #include "Version.h" #include "minecraft/mod/tasks/LocalResourcePackParseTask.h" @@ -43,9 +45,9 @@ void ResourcePack::setImage(QImage new_image) Q_ASSERT(!new_image.isNull()); if (m_pack_image_cache_key.key.isValid()) - QPixmapCache::remove(m_pack_image_cache_key.key); + PixmapCache::instance().remove(m_pack_image_cache_key.key); - m_pack_image_cache_key.key = QPixmapCache::insert(QPixmap::fromImage(new_image)); + m_pack_image_cache_key.key = PixmapCache::instance().insert(QPixmap::fromImage(new_image)); m_pack_image_cache_key.was_ever_used = true; // This can happen if the pixmap is too big to fit in the cache :c @@ -58,7 +60,7 @@ void ResourcePack::setImage(QImage new_image) QPixmap ResourcePack::image(QSize size) { QPixmap cached_image; - if (QPixmapCache::find(m_pack_image_cache_key.key, &cached_image)) { + if (PixmapCache::instance().find(m_pack_image_cache_key.key, &cached_image)) { if (size.isNull()) return cached_image; return cached_image.scaled(size); -- cgit From b1bdc6f745d607af4dc1bb592003a538ee03f058 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Sat, 19 Nov 2022 23:38:05 +0800 Subject: fix resource packs and add support for texture packs Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com> --- launcher/Application.cpp | 29 +++++++++++++++++++++-------- launcher/minecraft/mod/ResourcePack.cpp | 5 +++++ launcher/minecraft/mod/ResourcePack.h | 2 ++ launcher/minecraft/mod/TexturePack.cpp | 5 +++++ launcher/minecraft/mod/TexturePack.h | 2 ++ 5 files changed, 35 insertions(+), 8 deletions(-) (limited to 'launcher/minecraft') diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 71cd009a..9258aec4 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -101,6 +101,9 @@ #include #include #include +#include +#include +#include #include "updater/UpdateChecker.h" @@ -920,13 +923,13 @@ bool Application::createSetupWizard() return false; } -bool Application::event(QEvent* event) { +bool Application::event(QEvent* event) +{ #ifdef Q_OS_MACOS if (event->type() == QEvent::ApplicationStateChange) { auto ev = static_cast(event); - if (m_prevAppState == Qt::ApplicationActive - && ev->applicationState() == Qt::ApplicationActive) { + if (m_prevAppState == Qt::ApplicationActive && ev->applicationState() == Qt::ApplicationActive) { emit clickedOnDock(); } m_prevAppState = ev->applicationState(); @@ -936,19 +939,29 @@ bool Application::event(QEvent* event) { if (event->type() == QEvent::FileOpen) { auto ev = static_cast(event); - ResourcePack pack{ QFileInfo(ev->file()) }; + ResourcePack rp{ QFileInfo(ev->file()) }; + TexturePack tp{ QFileInfo(ev->file()) }; - ResourcePackUtils::process(pack); - // + ImportResourcePackDialog dlg(APPLICATION->m_mainWindow); - if (pack.valid()) { - ImportResourcePackDialog dlg(APPLICATION->m_mainWindow); + if (ResourcePackUtils::process(rp) && rp.valid()) { dlg.exec(); + if (dlg.result() == QDialog::Accepted) { + qDebug() << "Selected instance to import resource pack into: " << dlg.selectedInstanceKey; auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey); auto instanceButBuffed = std::dynamic_pointer_cast(instance); instanceButBuffed->resourcePackList()->installResource(ev->file()); } + } else if (TexturePackUtils::process(tp) && tp.valid()) { + dlg.exec(); + + if (dlg.result() == QDialog::Accepted) { + qDebug() << "Selected instance to import texture pack into: " << dlg.selectedInstanceKey; + auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey); + auto instanceButBuffed = std::dynamic_pointer_cast(instance); + instanceButBuffed->texturePackList()->installResource(ev->file()); + } } else { m_mainWindow->droppedURLs({ ev->url() }); } diff --git a/launcher/minecraft/mod/ResourcePack.cpp b/launcher/minecraft/mod/ResourcePack.cpp index 3fc10a2f..9f46cd2c 100644 --- a/launcher/minecraft/mod/ResourcePack.cpp +++ b/launcher/minecraft/mod/ResourcePack.cpp @@ -114,3 +114,8 @@ bool ResourcePack::applyFilter(QRegularExpression filter) const return Resource::applyFilter(filter); } + +bool ResourcePack::valid() const +{ + return m_pack_format != 0; +} diff --git a/launcher/minecraft/mod/ResourcePack.h b/launcher/minecraft/mod/ResourcePack.h index 03121908..7cb414d8 100644 --- a/launcher/minecraft/mod/ResourcePack.h +++ b/launcher/minecraft/mod/ResourcePack.h @@ -42,6 +42,8 @@ class ResourcePack : public Resource { /** Thread-safe. */ void setImage(QImage new_image); + bool valid() const override; + [[nodiscard]] auto compare(Resource const& other, SortType type) const -> std::pair override; [[nodiscard]] bool applyFilter(QRegularExpression filter) const override; diff --git a/launcher/minecraft/mod/TexturePack.cpp b/launcher/minecraft/mod/TexturePack.cpp index 796eb69d..99d55584 100644 --- a/launcher/minecraft/mod/TexturePack.cpp +++ b/launcher/minecraft/mod/TexturePack.cpp @@ -62,3 +62,8 @@ QPixmap TexturePack::image(QSize size) TexturePackUtils::process(*this); return image(size); } + +bool TexturePack::valid() const +{ + return m_description != nullptr; +} diff --git a/launcher/minecraft/mod/TexturePack.h b/launcher/minecraft/mod/TexturePack.h index 6aa5e18e..81bd5c69 100644 --- a/launcher/minecraft/mod/TexturePack.h +++ b/launcher/minecraft/mod/TexturePack.h @@ -48,6 +48,8 @@ class TexturePack : public Resource { /** Thread-safe. */ void setImage(QImage new_image); + bool valid() const override; + protected: mutable QMutex m_data_lock; -- cgit From f527958cb35b976d88e7037bda62762c1ffe6e13 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Sat, 19 Nov 2022 23:42:56 +0800 Subject: fix: check if packFormat is valid for resourcepack parsing Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com> --- launcher/minecraft/mod/ResourcePack.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/mod/ResourcePack.cpp b/launcher/minecraft/mod/ResourcePack.cpp index 9f46cd2c..1e9db596 100644 --- a/launcher/minecraft/mod/ResourcePack.cpp +++ b/launcher/minecraft/mod/ResourcePack.cpp @@ -117,5 +117,5 @@ bool ResourcePack::applyFilter(QRegularExpression filter) const bool ResourcePack::valid() const { - return m_pack_format != 0; + return s_pack_format_versions.contains(m_pack_format); } -- cgit From a33b8049238329fa97545c0b2db5bb8c2f7545c6 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Sat, 19 Nov 2022 23:47:47 +0800 Subject: fix: add resource pack format for 1.19.3 Co-authored-by: Rachel Powers <508861+Ryex@users.noreply.github.com> Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com> --- launcher/minecraft/mod/ResourcePack.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/mod/ResourcePack.cpp b/launcher/minecraft/mod/ResourcePack.cpp index 1e9db596..ef0370d0 100644 --- a/launcher/minecraft/mod/ResourcePack.cpp +++ b/launcher/minecraft/mod/ResourcePack.cpp @@ -15,7 +15,7 @@ static const QMap> s_pack_format_versions = { { 3, { Version("1.11"), Version("1.12.2") } }, { 4, { Version("1.13"), Version("1.14.4") } }, { 5, { Version("1.15"), Version("1.16.1") } }, { 6, { Version("1.16.2"), Version("1.16.5") } }, { 7, { Version("1.17"), Version("1.17.1") } }, { 8, { Version("1.18"), Version("1.18.2") } }, - { 9, { Version("1.19"), Version("1.19.2") } }, + { 9, { Version("1.19"), Version("1.19.2") } }, { 11, { Version("1.19.3"), Version("1.19.3") } }, }; void ResourcePack::setPackFormat(int new_format_id) -- cgit From 1f6b8f9d2bddd73e6cfd9d430ef9e37d1910adff Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Sat, 19 Nov 2022 23:59:30 +0800 Subject: fix instance IDs and resource pack imports Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com> --- launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp | 2 +- launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp | 2 +- launcher/ui/dialogs/ImportResourcePackDialog.cpp | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp b/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp index 4f87bc13..d744c535 100644 --- a/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp +++ b/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp @@ -152,7 +152,7 @@ bool LocalResourcePackParseTask::abort() void LocalResourcePackParseTask::executeTask() { - Q_ASSERT(m_resource_pack.valid()); + // Q_ASSERT(m_resource_pack.valid()); if (!ResourcePackUtils::process(m_resource_pack)) return; diff --git a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp index bf1e308f..f23117ee 100644 --- a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp +++ b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp @@ -143,7 +143,7 @@ bool LocalTexturePackParseTask::abort() void LocalTexturePackParseTask::executeTask() { - Q_ASSERT(m_texture_pack.valid()); + // Q_ASSERT(m_texture_pack.valid()); if (!TexturePackUtils::process(m_texture_pack)) return; diff --git a/launcher/ui/dialogs/ImportResourcePackDialog.cpp b/launcher/ui/dialogs/ImportResourcePackDialog.cpp index ef76445c..4fe28540 100644 --- a/launcher/ui/dialogs/ImportResourcePackDialog.cpp +++ b/launcher/ui/dialogs/ImportResourcePackDialog.cpp @@ -7,6 +7,7 @@ #include "Application.h" #include "InstanceList.h" +#include #include "ui/instanceview/InstanceDelegate.h" ImportResourcePackDialog::ImportResourcePackDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ImportResourcePackDialog) @@ -40,7 +41,7 @@ ImportResourcePackDialog::ImportResourcePackDialog(QWidget* parent) : QDialog(pa void ImportResourcePackDialog::activated(QModelIndex index) { - selectedInstanceKey = index.data(Qt::UserRole).toString(); + selectedInstanceKey = index.data(InstanceList::InstanceIDRole).toString(); accept(); } @@ -49,7 +50,7 @@ void ImportResourcePackDialog::selectionChanged(QItemSelection selected, QItemSe if (selected.empty()) return; - QString key = selected.first().indexes().first().data(Qt::UserRole).toString(); + QString key = selected.first().indexes().first().data(InstanceList::InstanceIDRole).toString(); if (!key.isEmpty()) { selectedInstanceKey = key; } -- cgit From df0f9259c0bf79e10b27ad5b429b53559ffd15f0 Mon Sep 17 00:00:00 2001 From: flow Date: Sun, 20 Nov 2022 11:04:10 -0300 Subject: refactor: move RP/TP validation to their respective utils This makes it easier to validate individual resources, and allows the logic to be used in other places in the future, if we need to. Signed-off-by: flow --- .../mod/tasks/LocalResourcePackParseTask.cpp | 25 +++++++++--- .../mod/tasks/LocalResourcePackParseTask.h | 12 ++++-- .../mod/tasks/LocalTexturePackParseTask.cpp | 25 +++++++++--- .../mod/tasks/LocalTexturePackParseTask.h | 12 ++++-- launcher/ui/MainWindow.cpp | 44 ++++++++++------------ 5 files changed, 78 insertions(+), 40 deletions(-) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp b/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp index d744c535..f58a0620 100644 --- a/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp +++ b/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp @@ -28,14 +28,14 @@ namespace ResourcePackUtils { -bool process(ResourcePack& pack) +bool process(ResourcePack& pack, ProcessingLevel level) { switch (pack.type()) { case ResourceType::FOLDER: - ResourcePackUtils::processFolder(pack); + ResourcePackUtils::processFolder(pack, level); return true; case ResourceType::ZIPFILE: - ResourcePackUtils::processZIP(pack); + ResourcePackUtils::processZIP(pack, level); return true; default: qWarning() << "Invalid type for resource pack parse task!"; @@ -43,7 +43,7 @@ bool process(ResourcePack& pack) } } -void processFolder(ResourcePack& pack) +void processFolder(ResourcePack& pack, ProcessingLevel level) { Q_ASSERT(pack.type() == ResourceType::FOLDER); @@ -60,6 +60,9 @@ void processFolder(ResourcePack& pack) mcmeta_file.close(); } + if (level == ProcessingLevel::BasicInfoOnly) + return; + QFileInfo image_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.png")); if (image_file_info.isFile()) { QFile mcmeta_file(image_file_info.filePath()); @@ -74,7 +77,7 @@ void processFolder(ResourcePack& pack) } } -void processZIP(ResourcePack& pack) +void processZIP(ResourcePack& pack, ProcessingLevel level) { Q_ASSERT(pack.type() == ResourceType::ZIPFILE); @@ -98,6 +101,11 @@ void processZIP(ResourcePack& pack) file.close(); } + if (level == ProcessingLevel::BasicInfoOnly) { + zip.close(); + return; + } + if (zip.setCurrentFile("pack.png")) { if (!file.open(QIODevice::ReadOnly)) { qCritical() << "Failed to open file in zip."; @@ -138,6 +146,13 @@ void processPackPNG(ResourcePack& pack, QByteArray&& raw_data) qWarning() << "Failed to parse pack.png."; } } + +bool validate(QFileInfo file) +{ + ResourcePack rp{ file }; + return ResourcePackUtils::process(rp, ProcessingLevel::BasicInfoOnly) && rp.valid(); +} + } // namespace ResourcePackUtils LocalResourcePackParseTask::LocalResourcePackParseTask(int token, ResourcePack& rp) diff --git a/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.h b/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.h index d3c25464..69dbd6ad 100644 --- a/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.h +++ b/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.h @@ -26,13 +26,19 @@ #include "tasks/Task.h" namespace ResourcePackUtils { -bool process(ResourcePack& pack); -void processZIP(ResourcePack& pack); -void processFolder(ResourcePack& pack); +enum class ProcessingLevel { Full, BasicInfoOnly }; + +bool process(ResourcePack& pack, ProcessingLevel level = ProcessingLevel::Full); + +void processZIP(ResourcePack& pack, ProcessingLevel level = ProcessingLevel::Full); +void processFolder(ResourcePack& pack, ProcessingLevel level = ProcessingLevel::Full); void processMCMeta(ResourcePack& pack, QByteArray&& raw_data); void processPackPNG(ResourcePack& pack, QByteArray&& raw_data); + +/** Checks whether a file is valid as a resource pack or not. */ +bool validate(QFileInfo file); } // namespace ResourcePackUtils class LocalResourcePackParseTask : public Task { diff --git a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp index f23117ee..8da366c1 100644 --- a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp +++ b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp @@ -28,14 +28,14 @@ namespace TexturePackUtils { -bool process(TexturePack& pack) +bool process(TexturePack& pack, ProcessingLevel level) { switch (pack.type()) { case ResourceType::FOLDER: - TexturePackUtils::processFolder(pack); + TexturePackUtils::processFolder(pack, level); return true; case ResourceType::ZIPFILE: - TexturePackUtils::processZIP(pack); + TexturePackUtils::processZIP(pack, level); return true; default: qWarning() << "Invalid type for resource pack parse task!"; @@ -43,7 +43,7 @@ bool process(TexturePack& pack) } } -void processFolder(TexturePack& pack) +void processFolder(TexturePack& pack, ProcessingLevel level) { Q_ASSERT(pack.type() == ResourceType::FOLDER); @@ -60,6 +60,9 @@ void processFolder(TexturePack& pack) mcmeta_file.close(); } + if (level == ProcessingLevel::BasicInfoOnly) + return; + QFileInfo image_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.png")); if (image_file_info.isFile()) { QFile mcmeta_file(image_file_info.filePath()); @@ -74,7 +77,7 @@ void processFolder(TexturePack& pack) } } -void processZIP(TexturePack& pack) +void processZIP(TexturePack& pack, ProcessingLevel level) { Q_ASSERT(pack.type() == ResourceType::ZIPFILE); @@ -98,6 +101,11 @@ void processZIP(TexturePack& pack) file.close(); } + if (level == ProcessingLevel::BasicInfoOnly) { + zip.close(); + return; + } + if (zip.setCurrentFile("pack.png")) { if (!file.open(QIODevice::ReadOnly)) { qCritical() << "Failed to open file in zip."; @@ -129,6 +137,13 @@ void processPackPNG(TexturePack& pack, QByteArray&& raw_data) qWarning() << "Failed to parse pack.png."; } } + +bool validate(QFileInfo file) +{ + TexturePack rp{ file }; + return TexturePackUtils::process(rp, ProcessingLevel::BasicInfoOnly) && rp.valid(); +} + } // namespace TexturePackUtils LocalTexturePackParseTask::LocalTexturePackParseTask(int token, TexturePack& rp) diff --git a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.h b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.h index cb0e404a..9f7aab75 100644 --- a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.h +++ b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.h @@ -27,13 +27,19 @@ #include "tasks/Task.h" namespace TexturePackUtils { -bool process(TexturePack& pack); -void processZIP(TexturePack& pack); -void processFolder(TexturePack& pack); +enum class ProcessingLevel { Full, BasicInfoOnly }; + +bool process(TexturePack& pack, ProcessingLevel level = ProcessingLevel::Full); + +void processZIP(TexturePack& pack, ProcessingLevel level = ProcessingLevel::Full); +void processFolder(TexturePack& pack, ProcessingLevel level = ProcessingLevel::Full); void processPackTXT(TexturePack& pack, QByteArray&& raw_data); void processPackPNG(TexturePack& pack, QByteArray&& raw_data); + +/** Checks whether a file is valid as a texture pack or not. */ +bool validate(QFileInfo file); } // namespace TexturePackUtils class LocalTexturePackParseTask : public Task { diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 98fd79be..5d2a07f3 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -110,10 +110,8 @@ #include "ui/dialogs/ImportResourcePackDialog.h" #include "ui/themes/ITheme.h" -#include #include #include -#include #include #include @@ -1806,32 +1804,30 @@ void MainWindow::droppedURLs(QList urls) for (auto& url : urls) { if (url.isLocalFile()) { auto localFileName = url.toLocalFile(); - - ResourcePack rp{ QFileInfo(localFileName) }; - TexturePack tp{ QFileInfo(localFileName) }; + QFileInfo localFileInfo(localFileName); ImportResourcePackDialog dlg(this); - if (ResourcePackUtils::process(rp) && rp.valid()) { - dlg.exec(); - - if (dlg.result() == QDialog::Accepted) { - qDebug() << "Selected instance to import resource pack into: " << dlg.selectedInstanceKey; - auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey); - auto instanceButBuffed = std::dynamic_pointer_cast(instance); - instanceButBuffed->resourcePackList()->installResource(localFileName); - } - } else if (TexturePackUtils::process(tp) && tp.valid()) { - dlg.exec(); - - if (dlg.result() == QDialog::Accepted) { - qDebug() << "Selected instance to import texture pack into: " << dlg.selectedInstanceKey; - auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey); - auto instanceButBuffed = std::dynamic_pointer_cast(instance); - instanceButBuffed->texturePackList()->installResource(localFileName); - } + if (ResourcePackUtils::validate(localFileInfo)) { + dlg.exec(); + + if (dlg.result() == QDialog::Accepted) { + qDebug() << "Selected instance to import resource pack into: " << dlg.selectedInstanceKey; + auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey); + auto instanceButBuffed = std::dynamic_pointer_cast(instance); + instanceButBuffed->resourcePackList()->installResource(localFileName); + } + } else if (TexturePackUtils::validate(localFileInfo)) { + dlg.exec(); + + if (dlg.result() == QDialog::Accepted) { + qDebug() << "Selected instance to import texture pack into: " << dlg.selectedInstanceKey; + auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey); + auto instanceButBuffed = std::dynamic_pointer_cast(instance); + instanceButBuffed->texturePackList()->installResource(localFileName); + } } else { - addInstance(localFileName); + addInstance(localFileName); } } else { addInstance(url.toString()); -- cgit From f55fc51e9b372e00ada739cfa679387079ffca2a Mon Sep 17 00:00:00 2001 From: flow Date: Sun, 20 Nov 2022 11:09:24 -0300 Subject: fix: remove commented-out assertions They may not hold true at all times, and that's fine. Signed-off-by: flow --- launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp | 2 -- launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp | 2 -- 2 files changed, 4 deletions(-) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp b/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp index f58a0620..6fd4b024 100644 --- a/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp +++ b/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp @@ -167,8 +167,6 @@ bool LocalResourcePackParseTask::abort() void LocalResourcePackParseTask::executeTask() { - // Q_ASSERT(m_resource_pack.valid()); - if (!ResourcePackUtils::process(m_resource_pack)) return; diff --git a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp index 8da366c1..adb19aca 100644 --- a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp +++ b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp @@ -158,8 +158,6 @@ bool LocalTexturePackParseTask::abort() void LocalTexturePackParseTask::executeTask() { - // Q_ASSERT(m_texture_pack.valid()); - if (!TexturePackUtils::process(m_texture_pack)) return; -- cgit From 96e8217b0034a7d73c7a37881955c51d3b248dca Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Tue, 8 Nov 2022 11:20:13 +0000 Subject: Button to add agent Signed-off-by: TheKodeToad --- launcher/minecraft/Agent.h | 2 +- launcher/minecraft/PackProfile.cpp | 72 +++++++++++++++++++++++++++--- launcher/minecraft/PackProfile.h | 7 ++- launcher/ui/pages/instance/VersionPage.cpp | 16 ++++++- launcher/ui/pages/instance/VersionPage.h | 4 +- launcher/ui/pages/instance/VersionPage.ui | 9 ++++ 6 files changed, 101 insertions(+), 9 deletions(-) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/Agent.h b/launcher/minecraft/Agent.h index 01109daf..374e6e94 100644 --- a/launcher/minecraft/Agent.h +++ b/launcher/minecraft/Agent.h @@ -10,7 +10,7 @@ typedef std::shared_ptr AgentPtr; class Agent { public: - Agent(LibraryPtr library, QString &argument) + Agent(LibraryPtr library, const QString &argument) { m_library = library; m_argument = argument; diff --git a/launcher/minecraft/PackProfile.cpp b/launcher/minecraft/PackProfile.cpp index 6ce525eb..bbdf51d8 100644 --- a/launcher/minecraft/PackProfile.cpp +++ b/launcher/minecraft/PackProfile.cpp @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2022 TheKodeToad * * 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 @@ -47,7 +48,6 @@ #include "Exception.h" #include "minecraft/OneSixVersionFormat.h" #include "FileSystem.h" -#include "meta/Index.h" #include "minecraft/MinecraftInstance.h" #include "Json.h" @@ -55,7 +55,6 @@ #include "PackProfile_p.h" #include "ComponentUpdateTask.h" -#include "Application.h" #include "modplatform/ModAPI.h" static const QMap modloaderMapping{ @@ -738,6 +737,11 @@ void PackProfile::installCustomJar(QString selectedFile) installCustomJar_internal(selectedFile); } +void PackProfile::installAgents(QStringList selectedFiles) +{ + installAgents_internal(selectedFiles); +} + bool PackProfile::installEmpty(const QString& uid, const QString& name) { QString patchDir = FS::PathCombine(d->m_instance->instanceRoot(), "patches"); @@ -832,8 +836,7 @@ bool PackProfile::installJarMods_internal(QStringList filepaths) for(auto filepath:filepaths) { QFileInfo sourceInfo(filepath); - auto uuid = QUuid::createUuid(); - QString id = uuid.toString().remove('{').remove('}'); + QString id = QUuid::createUuid().toString(QUuid::WithoutBraces); QString target_filename = id + ".jar"; QString target_id = "org.multimc.jarmod." + id; QString target_name = sourceInfo.completeBaseName() + " (jar mod)"; @@ -939,6 +942,65 @@ bool PackProfile::installCustomJar_internal(QString filepath) return true; } +bool PackProfile::installAgents_internal(QStringList filepaths) +{ + // FIXME code duplication + const QString patchDir = FS::PathCombine(d->m_instance->instanceRoot(), "patches"); + if (!FS::ensureFolderPathExists(patchDir)) + return false; + + const QString libDir = d->m_instance->getLocalLibraryPath(); + if (!FS::ensureFolderPathExists(libDir)) + return false; + + for (const QString& source : filepaths) { + const QFileInfo sourceInfo(source); + const QString id = QUuid::createUuid().toString(QUuid::WithoutBraces); + const QString targetBaseName = id + ".jar"; + const QString targetId = "org.prismlauncher.agent." + id; + const QString targetName = sourceInfo.completeBaseName() + " (agent)"; + const QString target = FS::PathCombine(d->m_instance->getLocalLibraryPath(), targetBaseName); + + const QFileInfo targetInfo(target); + if (targetInfo.exists()) + return false; + + if (!QFile::copy(source, target)) + return false; + + auto versionFile = std::make_shared(); + + auto agent = std::make_shared(); + + agent->setRawName("org.prismlauncher.agents:" + id + ":1"); + agent->setFilename(targetBaseName); + agent->setDisplayName(sourceInfo.completeBaseName()); + agent->setHint("local"); + + versionFile->agents.append(std::make_shared(agent, QString())); + + versionFile->name = targetName; + versionFile->uid = targetId; + + QFile patchFile(FS::PathCombine(patchDir, targetId + ".json")); + + if (!patchFile.open(QFile::WriteOnly)) { + qCritical() << "Error opening" << patchFile.fileName() << "for reading:" << patchFile.errorString(); + return false; + } + + patchFile.write(OneSixVersionFormat::versionFileToJson(versionFile).toJson()); + patchFile.close(); + + appendComponent(new Component(this, versionFile->uid, versionFile)); + } + + scheduleSave(); + invalidateLaunchProfile(); + + return true; +} + std::shared_ptr PackProfile::getProfile() const { if(!d->m_profile) diff --git a/launcher/minecraft/PackProfile.h b/launcher/minecraft/PackProfile.h index 807511a2..2330cca1 100644 --- a/launcher/minecraft/PackProfile.h +++ b/launcher/minecraft/PackProfile.h @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2022 TheKodeToad * * 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 @@ -85,6 +86,9 @@ public: /// install a jar/zip as a replacement for the main jar void installCustomJar(QString selectedFile); + /// install Java agent files + void installAgents(QStringList selectedFiles); + enum MoveDirection { MoveUp, MoveDown }; /// move component file # up or down the list void move(const int index, const MoveDirection direction); @@ -167,6 +171,7 @@ private: bool load(); bool installJarMods_internal(QStringList filepaths); bool installCustomJar_internal(QString filepath); + bool installAgents_internal(QStringList filepaths); bool removeComponent_internal(ComponentPtr patch); private: /* data */ diff --git a/launcher/ui/pages/instance/VersionPage.cpp b/launcher/ui/pages/instance/VersionPage.cpp index a021c633..7f98cba2 100644 --- a/launcher/ui/pages/instance/VersionPage.cpp +++ b/launcher/ui/pages/instance/VersionPage.cpp @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2022 TheKodeToad * * 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 @@ -270,6 +271,7 @@ void VersionPage::updateButtons(int row) ui->actionInstall_mods->setEnabled(controlsEnabled); ui->actionReplace_Minecraft_jar->setEnabled(controlsEnabled); ui->actionAdd_to_Minecraft_jar->setEnabled(controlsEnabled); + ui->actionAdd_Agents->setEnabled(controlsEnabled); } bool VersionPage::reloadPackProfile() @@ -342,6 +344,18 @@ void VersionPage::on_actionReplace_Minecraft_jar_triggered() updateButtons(); } + +void VersionPage::on_actionAdd_Agents_triggered() +{ + QStringList list = GuiUtil::BrowseForFiles("agent", tr("Select agents"), tr("Java agents (*.jar)"), + APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget()); + + if (!list.isEmpty()) + m_profile->installAgents(list); + + updateButtons(); +} + void VersionPage::on_actionMove_up_triggered() { try diff --git a/launcher/ui/pages/instance/VersionPage.h b/launcher/ui/pages/instance/VersionPage.h index 979311fc..23d2a1b3 100644 --- a/launcher/ui/pages/instance/VersionPage.h +++ b/launcher/ui/pages/instance/VersionPage.h @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 Jamie Mansfield + * Copyright (C) 2022 TheKodeToad * * 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 @@ -82,6 +83,7 @@ private slots: void on_actionMove_down_triggered(); void on_actionAdd_to_Minecraft_jar_triggered(); void on_actionReplace_Minecraft_jar_triggered(); + void on_actionAdd_Agents_triggered(); void on_actionRevert_triggered(); void on_actionEdit_triggered(); void on_actionInstall_mods_triggered(); diff --git a/launcher/ui/pages/instance/VersionPage.ui b/launcher/ui/pages/instance/VersionPage.ui index 14b7cd9f..74b9568a 100644 --- a/launcher/ui/pages/instance/VersionPage.ui +++ b/launcher/ui/pages/instance/VersionPage.ui @@ -109,6 +109,7 @@ + @@ -226,6 +227,14 @@ Replace Minecraft.jar + + + Add Agents + + + Add Java agents. + + Add Empty -- cgit From 8cac61f0bea17036346438761728c3b7bef4fbeb Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sun, 27 Nov 2022 18:41:52 +0100 Subject: fix: check resource pack validity solely using pack format Signed-off-by: Sefa Eyeoglu --- launcher/minecraft/mod/ResourcePack.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/mod/ResourcePack.cpp b/launcher/minecraft/mod/ResourcePack.cpp index ef0370d0..4a9ad21b 100644 --- a/launcher/minecraft/mod/ResourcePack.cpp +++ b/launcher/minecraft/mod/ResourcePack.cpp @@ -117,5 +117,5 @@ bool ResourcePack::applyFilter(QRegularExpression filter) const bool ResourcePack::valid() const { - return s_pack_format_versions.contains(m_pack_format); + return m_pack_format != 0; } -- cgit From 4e27e132a06974854f1c49dd8fb7a776915f5d03 Mon Sep 17 00:00:00 2001 From: flow Date: Mon, 28 Nov 2022 12:02:38 -0300 Subject: fix: don't disable interaction on non-mod models when inst. is running It is still useful for mods though, since we don't wnt to allow disabling mods when the instance is running, as that wouldn't affect the running instance, possibly causing confusion Signed-off-by: flow --- launcher/minecraft/MinecraftInstance.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 70d0b949..a3adb268 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -1110,8 +1110,6 @@ std::shared_ptr MinecraftInstance::resourcePackList() c if (!m_resource_pack_list) { m_resource_pack_list.reset(new ResourcePackFolderModel(resourcePacksDir())); - m_resource_pack_list->enableInteraction(!isRunning()); - connect(this, &BaseInstance::runningStatusChanged, m_resource_pack_list.get(), &ResourcePackFolderModel::disableInteraction); } return m_resource_pack_list; } @@ -1121,8 +1119,6 @@ std::shared_ptr MinecraftInstance::texturePackList() con if (!m_texture_pack_list) { m_texture_pack_list.reset(new TexturePackFolderModel(texturePacksDir())); - m_texture_pack_list->disableInteraction(isRunning()); - connect(this, &BaseInstance::runningStatusChanged, m_texture_pack_list.get(), &ModFolderModel::disableInteraction); } return m_texture_pack_list; } @@ -1132,8 +1128,6 @@ std::shared_ptr MinecraftInstance::shaderPackList() const if (!m_shader_pack_list) { m_shader_pack_list.reset(new ShaderPackFolderModel(shaderPacksDir())); - m_shader_pack_list->disableInteraction(isRunning()); - connect(this, &BaseInstance::runningStatusChanged, m_shader_pack_list.get(), &ModFolderModel::disableInteraction); } return m_shader_pack_list; } -- cgit From 31dc82b1a64fef40ab8fadbbb80d7641456bbb0a Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Tue, 29 Nov 2022 09:43:08 +0000 Subject: Make requested changes Signed-off-by: TheKodeToad --- launcher/minecraft/PackProfile.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/PackProfile.cpp b/launcher/minecraft/PackProfile.cpp index bbdf51d8..43fa3f8d 100644 --- a/launcher/minecraft/PackProfile.cpp +++ b/launcher/minecraft/PackProfile.cpp @@ -838,15 +838,12 @@ bool PackProfile::installJarMods_internal(QStringList filepaths) QFileInfo sourceInfo(filepath); QString id = QUuid::createUuid().toString(QUuid::WithoutBraces); QString target_filename = id + ".jar"; - QString target_id = "org.multimc.jarmod." + id; + QString target_id = "custom.jarmod." + id; QString target_name = sourceInfo.completeBaseName() + " (jar mod)"; QString finalPath = FS::PathCombine(d->m_instance->jarModsDir(), target_filename); QFileInfo targetInfo(finalPath); - if(targetInfo.exists()) - { - return false; - } + Q_ASSERT(!targetInfo.exists()); if (!QFile::copy(sourceInfo.absoluteFilePath(),QFileInfo(finalPath).absoluteFilePath())) { @@ -855,7 +852,7 @@ bool PackProfile::installJarMods_internal(QStringList filepaths) auto f = std::make_shared(); auto jarMod = std::make_shared(); - jarMod->setRawName(GradleSpecifier("org.multimc.jarmods:" + id + ":1")); + jarMod->setRawName(GradleSpecifier("custom.jarmods:" + id + ":1")); jarMod->setFilename(target_filename); jarMod->setDisplayName(sourceInfo.completeBaseName()); jarMod->setHint("local"); @@ -895,7 +892,7 @@ bool PackProfile::installCustomJar_internal(QString filepath) return false; } - auto specifier = GradleSpecifier("org.multimc:customjar:1"); + auto specifier = GradleSpecifier("custom:customjar:1"); QFileInfo sourceInfo(filepath); QString target_filename = specifier.getFileName(); QString target_id = specifier.artifactId(); @@ -957,13 +954,12 @@ bool PackProfile::installAgents_internal(QStringList filepaths) const QFileInfo sourceInfo(source); const QString id = QUuid::createUuid().toString(QUuid::WithoutBraces); const QString targetBaseName = id + ".jar"; - const QString targetId = "org.prismlauncher.agent." + id; + const QString targetId = "custom.agent." + id; const QString targetName = sourceInfo.completeBaseName() + " (agent)"; const QString target = FS::PathCombine(d->m_instance->getLocalLibraryPath(), targetBaseName); const QFileInfo targetInfo(target); - if (targetInfo.exists()) - return false; + Q_ASSERT(!targetInfo.exists()); if (!QFile::copy(source, target)) return false; @@ -972,7 +968,7 @@ bool PackProfile::installAgents_internal(QStringList filepaths) auto agent = std::make_shared(); - agent->setRawName("org.prismlauncher.agents:" + id + ":1"); + agent->setRawName("custom.agents:" + id + ":1"); agent->setFilename(targetBaseName); agent->setDisplayName(sourceInfo.completeBaseName()); agent->setHint("local"); -- cgit From 514e7ae6a00811a0ee1f20dfc856f69404fd883c Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Thu, 8 Dec 2022 23:09:14 +0100 Subject: fix: re-add LD_LIBARY_PATH to mangohud Upstream officially supports the use of $LIB/mangohud/ Signed-off-by: Jan200101 --- launcher/minecraft/MinecraftInstance.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index a3adb268..40d56444 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -483,8 +483,11 @@ QProcessEnvironment MinecraftInstance::createLaunchEnvironment() if (settings()->get("EnableMangoHud").toBool() && APPLICATION->capabilities() & Application::SupportsMangoHud) { auto preload = env.value("LD_PRELOAD", "") + ":libMangoHud_dlsym.so:libMangoHud.so"; + // $LIB/mangohud is a supported lib path by upstream, do not remove + auto lib_path = env.value("LD_LIBRARY_PATH", "") + ":/usr/local/$LIB/mangohud/:/usr/$LIB/mangohud/"; env.insert("LD_PRELOAD", preload); + env.insert("LD_LIBRARY_PATH", lib_path); env.insert("MANGOHUD", "1"); } -- cgit From deb9c98630c8c2f2d59908b77dae1e58aad3021d Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sun, 11 Dec 2022 10:32:15 +0100 Subject: chore: replace naive mangohud preload with vklayer detection Signed-off-by: Jan200101 --- launcher/minecraft/MinecraftInstance.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 40d56444..1d37224a 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -88,6 +88,10 @@ #include "minecraft/gameoptions/GameOptions.h" #include "minecraft/update/FoldersTask.h" +#ifdef Q_OS_LINUX +#include "MangoHud.h" +#endif + #define IBUS "@im=ibus" // all of this because keeping things compatible with deprecated old settings @@ -482,12 +486,22 @@ QProcessEnvironment MinecraftInstance::createLaunchEnvironment() #ifdef Q_OS_LINUX if (settings()->get("EnableMangoHud").toBool() && APPLICATION->capabilities() & Application::SupportsMangoHud) { - auto preload = env.value("LD_PRELOAD", "") + ":libMangoHud_dlsym.so:libMangoHud.so"; - // $LIB/mangohud is a supported lib path by upstream, do not remove - auto lib_path = env.value("LD_LIBRARY_PATH", "") + ":/usr/local/$LIB/mangohud/:/usr/$LIB/mangohud/"; - env.insert("LD_PRELOAD", preload); - env.insert("LD_LIBRARY_PATH", lib_path); + auto preloadList = env.value("LD_PRELOAD").split(QLatin1String(":")); + auto libPaths = env.value("LD_LIBRARY_PATH").split(QLatin1String(":")); + + auto mangoHudLibString = MangoHud::getLibraryString(); + if (!mangoHudLibString.isEmpty()) + { + QFileInfo mangoHudLib(mangoHudLibString); + + // dlsym variant is only needed for OpenGL and not included in the vulkan layer + preloadList << "libMangoHud_dlsym.so" << mangoHudLib.fileName(); + libPaths << mangoHudLib.absolutePath(); + } + + env.insert("LD_PRELOAD", preloadList.join(QLatin1String(":"))); + env.insert("LD_LIBRARY_PATH", libPaths.join(QLatin1String(":"))); env.insert("MANGOHUD", "1"); } -- cgit From 822c5a530ed78d1ed4140a0103c144006bc621ca Mon Sep 17 00:00:00 2001 From: Una Date: Sun, 11 Dec 2022 16:11:32 -0800 Subject: Not all libraries are from Mojang Signed-off-by: Una --- launcher/minecraft/update/LibrariesTask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/update/LibrariesTask.cpp b/launcher/minecraft/update/LibrariesTask.cpp index 3b129fe1..33a575c2 100644 --- a/launcher/minecraft/update/LibrariesTask.cpp +++ b/launcher/minecraft/update/LibrariesTask.cpp @@ -12,7 +12,7 @@ LibrariesTask::LibrariesTask(MinecraftInstance * inst) void LibrariesTask::executeTask() { - setStatus(tr("Getting the library files from Mojang...")); + setStatus(tr("Downloading required library files...")); qDebug() << m_inst->name() << ": downloading libraries"; MinecraftInstance *inst = (MinecraftInstance *)m_inst; -- cgit