From 2b67938385615005a5d5c0266690816146959fc6 Mon Sep 17 00:00:00 2001 From: galeon Date: Fri, 19 Jun 2026 21:03:37 +0300 Subject: [PATCH] add button for opening mod folder --- CMakeLists.txt | 4 ++-- Main.qml | 25 +++++++++++++++++++++++++ launcherbackend.cpp | 22 ++++++++++++++++++++++ launcherbackend.h | 2 ++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a4e939..f0fe17b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(Minecraft_launcher VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_package(Qt6 REQUIRED COMPONENTS Quick Core) +find_package(Qt6 REQUIRED COMPONENTS Quick Core Gui) qt_standard_project_setup(REQUIRES 6.8) @@ -35,7 +35,7 @@ set_target_properties(appMinecraft_launcher PROPERTIES ) target_link_libraries(appMinecraft_launcher - PRIVATE Qt6::Quick Qt6::Core + PRIVATE Qt6::Quick Qt6::Core Qt6::Gui ) include(GNUInstallDirs) diff --git a/Main.qml b/Main.qml index 1264e80..aa4cfff 100644 --- a/Main.qml +++ b/Main.qml @@ -450,6 +450,31 @@ Window { } } + // ── Open mods folder button ──────────────────────────────────────────── + Button { + id: folderButton + width: 42 + height: 42 + anchors.left: versionBox.right + anchors.leftMargin: 8 + anchors.verticalCenter: versionBox.verticalCenter + hoverEnabled: true + + background: Image { + id: folderButtonImage + anchors.fill: parent + source: folderButton.pressed ? "images/Folder/Folder_Pressed.svg" + : folderButton.hovered ? "images/Folder/Folder_Active.svg" + : "images/Folder/Folder_Idle.svg" + fillMode: Image.PreserveAspectFit + } + + ToolTip.visible: hovered + ToolTip.text: qsTr("Открыть папку с модами Minecraft") + + onClicked: backend.openMinecraftFolder() + } + // ── Add Profile Dialog ───────────────────────────────────────────────── // Bug fix: header/footer must be Item (not Rectangle) with explicit // implicitHeight so Dialog correctly computes its own total height. diff --git a/launcherbackend.cpp b/launcherbackend.cpp index 6203eb3..7f52c0c 100644 --- a/launcherbackend.cpp +++ b/launcherbackend.cpp @@ -1,11 +1,13 @@ #include "launcherbackend.h" +#include #include #include #include #include #include #include +#include #include LauncherBackend::LauncherBackend(QObject *parent) @@ -117,6 +119,26 @@ void LauncherBackend::launchGame(int profileIndex, int versionIndex) emit launched(profile.name, version.name, version.serverUrl); } +QString LauncherBackend::minecraftDir() const +{ +#if defined(Q_OS_WIN) + return QDir::homePath() + "/AppData/Roaming/.minecraft"; +#elif defined(Q_OS_MACOS) + return QDir::homePath() + "/Library/Application Support/minecraft"; +#else // Linux и прочие Unix-системы + return QDir::homePath() + "/.minecraft"; +#endif +} + +void LauncherBackend::openMinecraftFolder() +{ + const QString modsDir = minecraftDir() + "/mods"; + QDir().mkpath(modsDir); + + if (!QDesktopServices::openUrl(QUrl::fromLocalFile(modsDir))) + emit launchError("Не удалось открыть папку с модами"); +} + void LauncherBackend::loadData() { auto loadFile = [](const QString &path, auto handler) { diff --git a/launcherbackend.h b/launcherbackend.h index 34bbec4..b7a3963 100644 --- a/launcherbackend.h +++ b/launcherbackend.h @@ -28,6 +28,7 @@ public: Q_INVOKABLE void removeProfile(int index); Q_INVOKABLE void removeVersion(int index); Q_INVOKABLE void launchGame(int profileIndex, int versionIndex); + Q_INVOKABLE void openMinecraftFolder(); signals: void profilesChanged(); @@ -42,6 +43,7 @@ private: void loadData(); void saveProfiles(); void saveVersions(); + QString minecraftDir() const; QList m_profiles; QList m_versions;