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 ++++++ 1 file changed, 6 insertions(+) (limited to 'launcher/Application.cpp') 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."; } -- cgit From 8dacbafc8ba45ae6c2b770da77cc0d3d632849ba Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Sat, 19 Nov 2022 23:04:26 +0800 Subject: feat: initial support for smart resource pack parsing on file handler Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com> --- launcher/Application.cpp | 23 +++++++- launcher/CMakeLists.txt | 3 ++ launcher/ui/dialogs/ImportResourcePackDialog.cpp | 61 +++++++++++++++++++++ launcher/ui/dialogs/ImportResourcePackDialog.h | 24 +++++++++ launcher/ui/dialogs/ImportResourcePackDialog.ui | 67 ++++++++++++++++++++++++ 5 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 launcher/ui/dialogs/ImportResourcePackDialog.cpp create mode 100644 launcher/ui/dialogs/ImportResourcePackDialog.h create mode 100644 launcher/ui/dialogs/ImportResourcePackDialog.ui (limited to 'launcher/Application.cpp') diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 883f8968..71cd009a 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -66,6 +66,7 @@ #include "ui/setupwizard/PasteWizardPage.h" #include "ui/dialogs/CustomMessageBox.h" +#include "ui/dialogs/ImportResourcePackDialog.h" #include "ui/pagedialog/PageDialog.h" @@ -96,6 +97,10 @@ #include "net/HttpMetaCache.h" #include "java/JavaUtils.h" +#include +#include +#include +#include #include "updater/UpdateChecker.h" @@ -930,7 +935,23 @@ bool Application::event(QEvent* event) { if (event->type() == QEvent::FileOpen) { auto ev = static_cast(event); - m_mainWindow->droppedURLs({ ev->url() }); + + ResourcePack pack{ QFileInfo(ev->file()) }; + + ResourcePackUtils::process(pack); + // + + if (pack.valid()) { + ImportResourcePackDialog dlg(APPLICATION->m_mainWindow); + dlg.exec(); + if (dlg.result() == QDialog::Accepted) { + auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey); + auto instanceButBuffed = std::dynamic_pointer_cast(instance); + instanceButBuffed->resourcePackList()->installResource(ev->file()); + } + } else { + m_mainWindow->droppedURLs({ ev->url() }); + } } return QApplication::event(event); diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 8db93429..58d5d964 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -791,6 +791,8 @@ SET(LAUNCHER_SOURCES ui/dialogs/ExportInstanceDialog.h ui/dialogs/IconPickerDialog.cpp ui/dialogs/IconPickerDialog.h + ui/dialogs/ImportResourcePackDialog.cpp + ui/dialogs/ImportResourcePackDialog.h ui/dialogs/LoginDialog.cpp ui/dialogs/LoginDialog.h ui/dialogs/MSALoginDialog.cpp @@ -939,6 +941,7 @@ qt_wrap_ui(LAUNCHER_UI ui/dialogs/SkinUploadDialog.ui ui/dialogs/ExportInstanceDialog.ui ui/dialogs/IconPickerDialog.ui + ui/dialogs/ImportResourcePackDialog.ui ui/dialogs/MSALoginDialog.ui ui/dialogs/OfflineLoginDialog.ui ui/dialogs/AboutDialog.ui diff --git a/launcher/ui/dialogs/ImportResourcePackDialog.cpp b/launcher/ui/dialogs/ImportResourcePackDialog.cpp new file mode 100644 index 00000000..ef76445c --- /dev/null +++ b/launcher/ui/dialogs/ImportResourcePackDialog.cpp @@ -0,0 +1,61 @@ +#include "ImportResourcePackDialog.h" +#include "ui_ImportResourcePackDialog.h" + +#include +#include + +#include "Application.h" +#include "InstanceList.h" + +#include "ui/instanceview/InstanceDelegate.h" + +ImportResourcePackDialog::ImportResourcePackDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ImportResourcePackDialog) +{ + ui->setupUi(this); + setWindowModality(Qt::WindowModal); + + auto contentsWidget = ui->instanceView; + contentsWidget->setViewMode(QListView::ListMode); + contentsWidget->setFlow(QListView::LeftToRight); + contentsWidget->setIconSize(QSize(48, 48)); + contentsWidget->setMovement(QListView::Static); + contentsWidget->setResizeMode(QListView::Adjust); + contentsWidget->setSelectionMode(QAbstractItemView::SingleSelection); + contentsWidget->setSpacing(5); + contentsWidget->setWordWrap(false); + contentsWidget->setWrapping(true); + contentsWidget->setUniformItemSizes(true); + contentsWidget->setTextElideMode(Qt::ElideRight); + contentsWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); + contentsWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + contentsWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + contentsWidget->setItemDelegate(new ListViewDelegate()); + + contentsWidget->setModel(APPLICATION->instances().get()); + + connect(contentsWidget, SIGNAL(doubleClicked(QModelIndex)), SLOT(activated(QModelIndex))); + connect(contentsWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), + SLOT(selectionChanged(QItemSelection, QItemSelection))); +} + +void ImportResourcePackDialog::activated(QModelIndex index) +{ + selectedInstanceKey = index.data(Qt::UserRole).toString(); + accept(); +} + +void ImportResourcePackDialog::selectionChanged(QItemSelection selected, QItemSelection deselected) +{ + if (selected.empty()) + return; + + QString key = selected.first().indexes().first().data(Qt::UserRole).toString(); + if (!key.isEmpty()) { + selectedInstanceKey = key; + } +} + +ImportResourcePackDialog::~ImportResourcePackDialog() +{ + delete ui; +} diff --git a/launcher/ui/dialogs/ImportResourcePackDialog.h b/launcher/ui/dialogs/ImportResourcePackDialog.h new file mode 100644 index 00000000..b077a811 --- /dev/null +++ b/launcher/ui/dialogs/ImportResourcePackDialog.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +namespace Ui { +class ImportResourcePackDialog; +} + +class ImportResourcePackDialog : public QDialog { + Q_OBJECT + + public: + explicit ImportResourcePackDialog(QWidget* parent = 0); + ~ImportResourcePackDialog(); + QString selectedInstanceKey; + + private: + Ui::ImportResourcePackDialog* ui; + + private slots: + void selectionChanged(QItemSelection, QItemSelection); + void activated(QModelIndex); +}; diff --git a/launcher/ui/dialogs/ImportResourcePackDialog.ui b/launcher/ui/dialogs/ImportResourcePackDialog.ui new file mode 100644 index 00000000..2a1de0f9 --- /dev/null +++ b/launcher/ui/dialogs/ImportResourcePackDialog.ui @@ -0,0 +1,67 @@ + + + ImportResourcePackDialog + + + + 0 + 0 + 676 + 555 + + + + Pick icon + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + ImportResourcePackDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ImportResourcePackDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + -- 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/Application.cpp') 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 e0e428ce38ff5662089036a6bbf017a3b39f478f Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Sun, 20 Nov 2022 00:28:35 +0800 Subject: fix: add support for CLI and drag and drop Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com> --- launcher/Application.cpp | 35 +-------------------------------- launcher/ui/MainWindow.cpp | 48 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 42 deletions(-) (limited to 'launcher/Application.cpp') diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 9258aec4..0fbe4ae2 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -66,7 +66,6 @@ #include "ui/setupwizard/PasteWizardPage.h" #include "ui/dialogs/CustomMessageBox.h" -#include "ui/dialogs/ImportResourcePackDialog.h" #include "ui/pagedialog/PageDialog.h" @@ -98,12 +97,6 @@ #include "java/JavaUtils.h" #include -#include -#include -#include -#include -#include -#include #include "updater/UpdateChecker.h" @@ -938,33 +931,7 @@ bool Application::event(QEvent* event) if (event->type() == QEvent::FileOpen) { auto ev = static_cast(event); - - ResourcePack rp{ QFileInfo(ev->file()) }; - TexturePack tp{ QFileInfo(ev->file()) }; - - 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() }); - } + m_mainWindow->droppedURLs({ ev->url() }); } return QApplication::event(event); diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 929f2a85..ed61777e 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -106,8 +106,16 @@ #include "ui/dialogs/UpdateDialog.h" #include "ui/dialogs/EditAccountDialog.h" #include "ui/dialogs/ExportInstanceDialog.h" +#include "ui/dialogs/ImportResourcePackDialog.h" #include "ui/themes/ITheme.h" +#include +#include +#include +#include +#include +#include + #include "UpdateController.h" #include "KonamiCode.h" @@ -1794,16 +1802,40 @@ void MainWindow::on_actionAddInstance_triggered() void MainWindow::droppedURLs(QList urls) { - for(auto & url:urls) - { - if(url.isLocalFile()) - { - addInstance(url.toLocalFile()); - } - else - { + for (auto& url : urls) { + if (url.isLocalFile()) { + auto localFileName = url.toLocalFile(); + + ResourcePack rp{ QFileInfo(localFileName) }; + TexturePack tp{ QFileInfo(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); + } + } else { + addInstance(localFileName); + } + } else { addInstance(url.toString()); } + // Only process one dropped file... break; } -- cgit From d92ae530d7c585eb859d852ba1877230a82d867e Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Sun, 20 Nov 2022 00:31:58 +0800 Subject: fix: stray include Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com> --- launcher/Application.cpp | 1 - launcher/ui/MainWindow.cpp | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'launcher/Application.cpp') diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 0fbe4ae2..c5594b21 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -96,7 +96,6 @@ #include "net/HttpMetaCache.h" #include "java/JavaUtils.h" -#include #include "updater/UpdateChecker.h" diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index ed61777e..98fd79be 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -71,6 +71,7 @@ #include #include +#include #include #include #include -- cgit From 2c1e887c8d7331df6d93dadea7355c019da4185a Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sun, 11 Dec 2022 11:01:33 +0100 Subject: chore: replace naive mangohud detection with vulkan layer detection Signed-off-by: Jan200101 --- launcher/Application.cpp | 14 ++------ launcher/CMakeLists.txt | 9 +++++ launcher/MangoHud.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ launcher/MangoHud.h | 27 +++++++++++++++ 4 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 launcher/MangoHud.cpp create mode 100644 launcher/MangoHud.h (limited to 'launcher/Application.cpp') diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 4ba9eb9b..8447083c 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -125,6 +125,7 @@ #ifdef Q_OS_LINUX #include #include "gamemode_client.h" +#include "MangoHud.h" #endif @@ -1519,17 +1520,8 @@ void Application::updateCapabilities() if (gamemode_query_status() >= 0) m_capabilities |= SupportsGameMode; - { - void *dummy = dlopen("libMangoHud_dlsym.so", RTLD_LAZY); - // try normal variant as well - if (dummy == NULL) - dummy = dlopen("libMangoHud.so", RTLD_LAZY); - - if (dummy != NULL) { - dlclose(dummy); - m_capabilities |= SupportsMangoHud; - } - } + if (!MangoHud::getLibraryString().isEmpty()) + m_capabilities |= SupportsMangoHud; #endif } diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 3eb765dc..879c3157 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -90,6 +90,15 @@ set(CORE_SOURCES MMCTime.h MMCTime.cpp ) +if (UNIX AND NOT CYGWIN AND NOT APPLE) +set(CORE_SOURCES + ${CORE_SOURCES} + + # MangoHud + MangoHud.h + MangoHud.cpp + ) +endif() set(PATHMATCHER_SOURCES # Path matchers diff --git a/launcher/MangoHud.cpp b/launcher/MangoHud.cpp new file mode 100644 index 00000000..d635518e --- /dev/null +++ b/launcher/MangoHud.cpp @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PrismLauncher - Minecraft Launcher + * Copyright (C) 2022 Jan Drögehoff + * + * 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 . + */ + +#include +#include +#include +#include + +#include "MangoHud.h" +#include "FileSystem.h" +#include "Json.h" + +namespace MangoHud { + +QString getLibraryString() +{ + /* + * Check for vulkan layers in this order: + * + * $VK_LAYER_PATH + * $XDG_DATA_DIRS (/usr/local/share/:/usr/share/) + * $XDG_DATA_HOME (~/.local/share) + * /etc + * $XDG_CONFIG_DIRS (/etc/xdg) + * $XDG_CONFIG_HOME (~/.config) + */ + + QStringList vkLayerList; + { + QString home = QDir::homePath(); + + QString vkLayerPath = qEnvironmentVariable("VK_LAYER_PATH"); + if (!vkLayerPath.isEmpty()) { + vkLayerList << vkLayerPath; + } + + QStringList xdgDataDirs = qEnvironmentVariable("XDG_DATA_DIRS", "/usr/local/share/:/usr/share/").split(QLatin1String(":")); + for (QString dir : xdgDataDirs) { + vkLayerList << FS::PathCombine(dir, "vulkan", "implicit_layer.d"); + } + + QString xdgDataHome = qEnvironmentVariable("XDG_DATA_HOME"); + if (xdgDataHome.isEmpty()) { + xdgDataHome = FS::PathCombine(home, ".local", "share"); + } + vkLayerList << FS::PathCombine(xdgDataHome, "vulkan", "implicit_layer.d"); + + vkLayerList << "/etc"; + + QStringList xdgConfigDirs = qEnvironmentVariable("XDG_CONFIG_DIRS", "/etc/xdg").split(QLatin1String(":")); + for (QString dir : xdgConfigDirs) { + vkLayerList << FS::PathCombine(dir, "vulkan", "implicit_layer.d"); + } + + QString xdgConfigHome = qEnvironmentVariable("XDG_CONFIG_HOME"); + if (xdgConfigHome.isEmpty()) { + xdgConfigHome = FS::PathCombine(home, ".config"); + } + vkLayerList << FS::PathCombine(xdgConfigHome, "vulkan", "implicit_layer.d"); + } + + for (QString vkLayer : vkLayerList) { + QString filePath = FS::PathCombine(vkLayer, "MangoHud.json"); + if (!QFile::exists(filePath)) + continue; + + auto conf = Json::requireDocument(filePath, vkLayer); + auto confObject = Json::requireObject(conf, vkLayer); + auto layer = Json::ensureObject(confObject, "layer"); + return Json::ensureString(layer, "library_path"); + } + + return QString(); +} +} // namespace MangoHud diff --git a/launcher/MangoHud.h b/launcher/MangoHud.h new file mode 100644 index 00000000..7b7c2849 --- /dev/null +++ b/launcher/MangoHud.h @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PrismLauncher - Minecraft Launcher + * Copyright (C) 2022 Jan Drögehoff + * + * 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 +#include + +namespace MangoHud { + +QString getLibraryString(); +} -- cgit