diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c0e5b50a..f07a86e6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,6 +15,9 @@ on: SPARKLE_ED25519_KEY: description: Private key for signing Sparkle updates required: false + CACHIX_AUTH_TOKEN: + description: Private token for authenticating against Cachix cache + required: false jobs: build: @@ -230,7 +233,7 @@ jobs: - name: Configure CMake (Windows MSVC) if: runner.os == 'Windows' && matrix.msystem == '' run: | - cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=${{ matrix.name }} -DLauncher_QT_VERSION_MAJOR=${{ matrix.qt_ver }} -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreadedDLL" -A${{ matrix.architecture}} + cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=${{ matrix.name }} -DLauncher_QT_VERSION_MAJOR=${{ matrix.qt_ver }} -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreadedDLL" -A${{ matrix.architecture}} -DLauncher_FORCE_BUNDLED_LIBS=ON # https://github.com/ccache/ccache/wiki/MS-Visual-Studio (I coudn't figure out the compiler prefix) if ("${{ env.CCACHE_VAR }}") { @@ -526,3 +529,33 @@ jobs: bundle: "Prism Launcher.flatpak" manifest-path: flatpak/org.prismlauncher.PrismLauncher.yml cache-key: flatpak-${{ github.sha }}-x86_64 + + nix: + runs-on: ubuntu-latest + strategy: + matrix: + package: + - prismlauncher + - prismlauncher-qt5 + steps: + - name: Clone repository + if: inputs.build_type == 'Debug' + uses: actions/checkout@v3 + with: + submodules: 'true' + - name: Install nix + if: inputs.build_type == 'Debug' + uses: cachix/install-nix-action@v18 + with: + install_url: https://nixos.org/nix/install + extra_nix_config: | + auto-optimise-store = true + experimental-features = nix-command flakes + - uses: cachix/cachix-action@v12 + if: inputs.build_type == 'Debug' + with: + name: prismlauncher + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - name: Build + if: inputs.build_type == 'Debug' + run: nix build .#${{ matrix.package }} --print-build-logs diff --git a/.github/workflows/trigger_builds.yml b/.github/workflows/trigger_builds.yml index 44751fbc..a08193a0 100644 --- a/.github/workflows/trigger_builds.yml +++ b/.github/workflows/trigger_builds.yml @@ -8,7 +8,6 @@ on: - '**.md' - '**/LICENSE' - 'flake.lock' - - '**.nix' - 'packages/**' - '.github/ISSUE_TEMPLATE/**' - '.markdownlint**' @@ -17,7 +16,6 @@ on: - '**.md' - '**/LICENSE' - 'flake.lock' - - '**.nix' - 'packages/**' - '.github/ISSUE_TEMPLATE/**' - '.markdownlint**' @@ -33,3 +31,4 @@ jobs: is_qt_cached: true secrets: SPARKLE_ED25519_KEY: ${{ secrets.SPARKLE_ED25519_KEY }} + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fc0d326..f04b733b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -368,11 +368,11 @@ if(NOT ZLIB_FOUND) set(SKIP_INSTALL_ALL ON) add_subdirectory(libraries/zlib EXCLUDE_FROM_ALL) - set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries/zlib" "${CMAKE_CURRENT_BINARY_DIR}/libraries/zlib") + set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries/zlib" "${CMAKE_CURRENT_BINARY_DIR}/libraries/zlib" CACHE STRING "") set_target_properties(zlibstatic PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIR}") add_library(ZLIB::ZLIB ALIAS zlibstatic) - set(ZLIB_LIBRARY ZLIB::ZLIB) - set(ZLIB_FOUND true) + set(ZLIB_LIBRARY ZLIB::ZLIB CACHE STRING "zlib library name") + find_package(ZLIB REQUIRED) else() message(STATUS "Using system zlib") diff --git a/flake.nix b/flake.nix index d4a25338..b1e07c91 100644 --- a/flake.nix +++ b/flake.nix @@ -23,8 +23,8 @@ pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system}); packagesFn = pkgs: rec { - prismlauncher = pkgs.libsForQt5.callPackage ./nix { inherit version self libnbtplusplus tomlplusplus; }; - prismlauncher-qt6 = pkgs.qt6Packages.callPackage ./nix { inherit version self libnbtplusplus tomlplusplus; }; + prismlauncher-qt5 = pkgs.libsForQt5.callPackage ./nix { inherit version self libnbtplusplus tomlplusplus; }; + prismlauncher = pkgs.qt6Packages.callPackage ./nix { inherit version self libnbtplusplus tomlplusplus; }; }; in { diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 0c6527b1..1da50e21 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -49,6 +49,7 @@ #include "StringUtils.h" #if defined Q_OS_WIN32 +#define WIN32_LEAN_AND_MEAN #include #include #include @@ -188,6 +189,8 @@ bool copy::operator()(const QString& offset, bool dryRun) qDebug() << "Source file:" << src_path; qDebug() << "Destination file:" << dst_path; } + m_copied++; + emit fileCopied(relative_dst_path); }; // We can't use copy_opts::recursive because we need to take into account the @@ -341,12 +344,37 @@ QString getDesktopDir() } // Cross-platform Shortcut creation -bool createShortCut(QString location, QString dest, QStringList args, QString name, QString icon) +bool createShortcut(QString destination, QString target, QStringList args, QString name, QString icon) { -#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) - location = PathCombine(location, name + ".desktop"); +#if defined(Q_OS_MACOS) + destination += ".command"; - QFile f(location); + QFile f(destination); + f.open(QIODevice::WriteOnly | QIODevice::Text); + QTextStream stream(&f); + + QString argstring; + if (!args.empty()) + argstring = " \"" + args.join("\" \"") + "\""; + + stream << "#!/bin/bash" + << "\n"; + stream << "\"" + << target + << "\" " + << argstring + << "\n"; + + stream.flush(); + f.close(); + + f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup | QFileDevice::ExeOther); + + return true; +#elif defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) + destination += ".desktop"; + + QFile f(destination); f.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream stream(&f); @@ -358,10 +386,12 @@ bool createShortCut(QString location, QString dest, QStringList args, QString na << "\n"; stream << "Type=Application" << "\n"; - stream << "TryExec=" << dest.toLocal8Bit() << "\n"; - stream << "Exec=" << dest.toLocal8Bit() << argstring.toLocal8Bit() << "\n"; + stream << "Exec=\"" << target.toLocal8Bit() << "\"" << argstring.toLocal8Bit() << "\n"; stream << "Name=" << name.toLocal8Bit() << "\n"; - stream << "Icon=" << icon.toLocal8Bit() << "\n"; + if (!icon.isEmpty()) + { + stream << "Icon=" << icon.toLocal8Bit() << "\n"; + } stream.flush(); f.close(); @@ -369,25 +399,132 @@ bool createShortCut(QString location, QString dest, QStringList args, QString na f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup | QFileDevice::ExeOther); return true; -#elif defined Q_OS_WIN - // TODO: Fix - // QFile file(PathCombine(location, name + ".lnk")); - // WCHAR *file_w; - // WCHAR *dest_w; - // WCHAR *args_w; - // file.fileName().toWCharArray(file_w); - // dest.toWCharArray(dest_w); +#elif defined(Q_OS_WIN) + QFileInfo targetInfo(target); - // QString argStr; - // for (int i = 0; i < args.count(); i++) - // { - // argStr.append(args[i]); - // argStr.append(" "); - // } - // argStr.toWCharArray(args_w); + if (!targetInfo.exists()) + { + qWarning() << "Target file does not exist!"; + return false; + } - // return SUCCEEDED(CreateLink(file_w, dest_w, args_w)); - return false; + target = targetInfo.absoluteFilePath(); + + if (target.length() >= MAX_PATH) + { + qWarning() << "Target file path is too long!"; + return false; + } + + if (!icon.isEmpty() && icon.length() >= MAX_PATH) + { + qWarning() << "Icon path is too long!"; + return false; + } + + destination += ".lnk"; + + if (destination.length() >= MAX_PATH) + { + qWarning() << "Destination path is too long!"; + return false; + } + + QString argStr; + int argCount = args.count(); + for (int i = 0; i < argCount; i++) + { + if (args[i].contains(' ')) + { + argStr.append('"').append(args[i]).append('"'); + } + else + { + argStr.append(args[i]); + } + + if (i < argCount - 1) + { + argStr.append(" "); + } + } + + if (argStr.length() >= MAX_PATH) + { + qWarning() << "Arguments string is too long!"; + return false; + } + + HRESULT hres; + + // ...yes, you need to initialize the entire COM stack just to make a shortcut + hres = CoInitialize(nullptr); + if (FAILED(hres)) + { + qWarning() << "Failed to initialize COM!"; + return false; + } + + WCHAR wsz[MAX_PATH]; + + IShellLink* psl; + + // create an IShellLink instance - this stores the shortcut's attributes + hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); + if (SUCCEEDED(hres)) + { + wmemset(wsz, 0, MAX_PATH); + target.toWCharArray(wsz); + psl->SetPath(wsz); + + wmemset(wsz, 0, MAX_PATH); + argStr.toWCharArray(wsz); + psl->SetArguments(wsz); + + wmemset(wsz, 0, MAX_PATH); + targetInfo.absolutePath().toWCharArray(wsz); + psl->SetWorkingDirectory(wsz); // "Starts in" attribute + + if (!icon.isEmpty()) + { + wmemset(wsz, 0, MAX_PATH); + icon.toWCharArray(wsz); + psl->SetIconLocation(wsz, 0); + } + + // query an IPersistFile interface from our IShellLink instance + // this is the interface that will actually let us save the shortcut to disk! + IPersistFile* ppf; + hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf); + if (SUCCEEDED(hres)) + { + wmemset(wsz, 0, MAX_PATH); + destination.toWCharArray(wsz); + hres = ppf->Save(wsz, TRUE); + if (FAILED(hres)) + { + qWarning() << "IPresistFile->Save() failed"; + qWarning() << "hres = " << hres; + } + ppf->Release(); + } + else + { + qWarning() << "Failed to query IPersistFile interface from IShellLink instance"; + qWarning() << "hres = " << hres; + } + psl->Release(); + } + else + { + qWarning() << "Failed to create IShellLink instance"; + qWarning() << "hres = " << hres; + } + + // go away COM, nobody likes you + CoUninitialize(); + + return SUCCEEDED(hres); #else qWarning("Desktop Shortcuts not supported on your platform!"); return false; diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index a9a81123..ac893725 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -172,4 +172,9 @@ QString getDesktopDir(); // Overrides one folder with the contents of another, preserving items exclusive to the first folder // Equivalent to doing QDir::rename, but allowing for overrides bool overrideFolder(QString overwritten_path, QString override_path); + +/** + * Creates a shortcut to the specified target file at the specified destination path. + */ +bool createShortcut(QString destination, QString target, QStringList args, QString name, QString icon); } diff --git a/launcher/resources/OSX/OSX.qrc b/launcher/resources/OSX/OSX.qrc index 19fe312b..9d4511d1 100644 --- a/launcher/resources/OSX/OSX.qrc +++ b/launcher/resources/OSX/OSX.qrc @@ -39,5 +39,6 @@ scalable/export.svg scalable/rename.svg scalable/launch.svg + scalable/shortcut.svg diff --git a/launcher/resources/OSX/scalable/shortcut.svg b/launcher/resources/OSX/scalable/shortcut.svg new file mode 100644 index 00000000..a2b7488e --- /dev/null +++ b/launcher/resources/OSX/scalable/shortcut.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/launcher/resources/breeze_dark/breeze_dark.qrc b/launcher/resources/breeze_dark/breeze_dark.qrc index 4d7a69b2..97434abc 100644 --- a/launcher/resources/breeze_dark/breeze_dark.qrc +++ b/launcher/resources/breeze_dark/breeze_dark.qrc @@ -27,6 +27,7 @@ scalable/refresh.svg scalable/resourcepacks.svg scalable/shaderpacks.svg + scalable/shortcut.svg scalable/screenshots.svg scalable/settings.svg scalable/status-bad.svg diff --git a/launcher/resources/breeze_dark/scalable/shortcut.svg b/launcher/resources/breeze_dark/scalable/shortcut.svg new file mode 100644 index 00000000..5559be1d --- /dev/null +++ b/launcher/resources/breeze_dark/scalable/shortcut.svg @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/launcher/resources/breeze_light/breeze_light.qrc b/launcher/resources/breeze_light/breeze_light.qrc index 7d9d99f5..6d868b18 100644 --- a/launcher/resources/breeze_light/breeze_light.qrc +++ b/launcher/resources/breeze_light/breeze_light.qrc @@ -27,6 +27,7 @@ scalable/refresh.svg scalable/resourcepacks.svg scalable/shaderpacks.svg + scalable/shortcut.svg scalable/screenshots.svg scalable/settings.svg scalable/status-bad.svg diff --git a/launcher/resources/breeze_light/scalable/shortcut.svg b/launcher/resources/breeze_light/scalable/shortcut.svg new file mode 100644 index 00000000..426769d1 --- /dev/null +++ b/launcher/resources/breeze_light/scalable/shortcut.svg @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/launcher/resources/flat/flat.qrc b/launcher/resources/flat/flat.qrc index 508e0a9f..a846bd2d 100644 --- a/launcher/resources/flat/flat.qrc +++ b/launcher/resources/flat/flat.qrc @@ -35,6 +35,7 @@ scalable/screenshot-placeholder.svg scalable/screenshots.svg scalable/settings.svg + scalable/shortcut.svg scalable/star.svg scalable/status-bad.svg scalable/status-good.svg diff --git a/launcher/resources/flat/scalable/shortcut.svg b/launcher/resources/flat/scalable/shortcut.svg new file mode 100644 index 00000000..83878d19 --- /dev/null +++ b/launcher/resources/flat/scalable/shortcut.svg @@ -0,0 +1,3 @@ + + + diff --git a/launcher/resources/flat_white/flat_white.qrc b/launcher/resources/flat_white/flat_white.qrc index e11d6316..b0759d8f 100644 --- a/launcher/resources/flat_white/flat_white.qrc +++ b/launcher/resources/flat_white/flat_white.qrc @@ -35,6 +35,7 @@ scalable/screenshot-placeholder.svg scalable/screenshots.svg scalable/settings.svg + scalable/shortcut.svg scalable/star.svg scalable/status-bad.svg scalable/status-good.svg diff --git a/launcher/resources/flat_white/scalable/shortcut.svg b/launcher/resources/flat_white/scalable/shortcut.svg new file mode 100644 index 00000000..b419a77d --- /dev/null +++ b/launcher/resources/flat_white/scalable/shortcut.svg @@ -0,0 +1,3 @@ + + + diff --git a/launcher/resources/iOS/iOS.qrc b/launcher/resources/iOS/iOS.qrc index aa08d811..0b79efb2 100644 --- a/launcher/resources/iOS/iOS.qrc +++ b/launcher/resources/iOS/iOS.qrc @@ -39,5 +39,6 @@ scalable/export.svg scalable/rename.svg scalable/launch.svg + scalable/shortcut.svg diff --git a/launcher/resources/iOS/scalable/shortcut.svg b/launcher/resources/iOS/scalable/shortcut.svg new file mode 100644 index 00000000..16e9fa48 --- /dev/null +++ b/launcher/resources/iOS/scalable/shortcut.svg @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/launcher/resources/multimc/multimc.qrc b/launcher/resources/multimc/multimc.qrc index 3f3d22fc..9741267c 100644 --- a/launcher/resources/multimc/multimc.qrc +++ b/launcher/resources/multimc/multimc.qrc @@ -312,5 +312,14 @@ scalable/instances/fox.svg scalable/instances/bee.svg scalable/instances/prismlauncher.svg + + + scalable/delete.svg + scalable/tag.svg + scalable/rename.svg + scalable/shortcut.svg + + scalable/export.svg + scalable/launch.svg diff --git a/launcher/resources/multimc/scalable/delete.svg b/launcher/resources/multimc/scalable/delete.svg new file mode 100644 index 00000000..414cbd5c --- /dev/null +++ b/launcher/resources/multimc/scalable/delete.svg @@ -0,0 +1,282 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/multimc/scalable/export.svg b/launcher/resources/multimc/scalable/export.svg new file mode 100644 index 00000000..2605de14 --- /dev/null +++ b/launcher/resources/multimc/scalable/export.svg @@ -0,0 +1,466 @@ + + + + + + + + + + + unsorted + + + + + Open Clip Art Library, Source: Oxygen Icons, Source: Oxygen Icons, Source: Oxygen Icons, Source: Oxygen Icons + + + + + + + + + + + + + + image/svg+xml + + + en + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/multimc/scalable/launch.svg b/launcher/resources/multimc/scalable/launch.svg new file mode 100644 index 00000000..321647a0 --- /dev/null +++ b/launcher/resources/multimc/scalable/launch.svg @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/multimc/scalable/rename.svg b/launcher/resources/multimc/scalable/rename.svg new file mode 100644 index 00000000..a585e264 --- /dev/null +++ b/launcher/resources/multimc/scalable/rename.svg @@ -0,0 +1,437 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/multimc/scalable/shortcut.svg b/launcher/resources/multimc/scalable/shortcut.svg new file mode 100644 index 00000000..549c3724 --- /dev/null +++ b/launcher/resources/multimc/scalable/shortcut.svg @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/launcher/resources/multimc/scalable/tag.svg b/launcher/resources/multimc/scalable/tag.svg new file mode 100644 index 00000000..81b5d545 --- /dev/null +++ b/launcher/resources/multimc/scalable/tag.svg @@ -0,0 +1,398 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/pe_blue/pe_blue.qrc b/launcher/resources/pe_blue/pe_blue.qrc index 3121ffe6..639675f0 100644 --- a/launcher/resources/pe_blue/pe_blue.qrc +++ b/launcher/resources/pe_blue/pe_blue.qrc @@ -39,5 +39,6 @@ scalable/export.svg scalable/rename.svg scalable/launch.svg + scalable/shortcut.svg diff --git a/launcher/resources/pe_blue/scalable/shortcut.svg b/launcher/resources/pe_blue/scalable/shortcut.svg new file mode 100644 index 00000000..45b73496 --- /dev/null +++ b/launcher/resources/pe_blue/scalable/shortcut.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/pe_colored/pe_colored.qrc b/launcher/resources/pe_colored/pe_colored.qrc index ce5ad8e2..fac58da8 100644 --- a/launcher/resources/pe_colored/pe_colored.qrc +++ b/launcher/resources/pe_colored/pe_colored.qrc @@ -39,5 +39,6 @@ scalable/export.svg scalable/rename.svg scalable/launch.svg + scalable/shortcut.svg diff --git a/launcher/resources/pe_colored/scalable/shortcut.svg b/launcher/resources/pe_colored/scalable/shortcut.svg new file mode 100644 index 00000000..1469674f --- /dev/null +++ b/launcher/resources/pe_colored/scalable/shortcut.svg @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/launcher/resources/pe_dark/pe_dark.qrc b/launcher/resources/pe_dark/pe_dark.qrc index 156d8f8b..c0c6ee6c 100644 --- a/launcher/resources/pe_dark/pe_dark.qrc +++ b/launcher/resources/pe_dark/pe_dark.qrc @@ -39,5 +39,6 @@ scalable/export.svg scalable/rename.svg scalable/launch.svg + scalable/shortcut.svg diff --git a/launcher/resources/pe_dark/scalable/shortcut.svg b/launcher/resources/pe_dark/scalable/shortcut.svg new file mode 100644 index 00000000..29b45f26 --- /dev/null +++ b/launcher/resources/pe_dark/scalable/shortcut.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/pe_light/pe_light.qrc b/launcher/resources/pe_light/pe_light.qrc index d8e4a1bd..bd6a2496 100644 --- a/launcher/resources/pe_light/pe_light.qrc +++ b/launcher/resources/pe_light/pe_light.qrc @@ -39,5 +39,6 @@ scalable/export.svg scalable/rename.svg scalable/launch.svg + scalable/shortcut.svg diff --git a/launcher/resources/pe_light/scalable/shortcut.svg b/launcher/resources/pe_light/scalable/shortcut.svg new file mode 100644 index 00000000..4d232bcf --- /dev/null +++ b/launcher/resources/pe_light/scalable/shortcut.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index c3c4d10f..e2fb1095 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -39,6 +39,7 @@ #include "Application.h" #include "BuildConfig.h" +#include "FileSystem.h" #include "MainWindow.h" @@ -246,6 +247,7 @@ public: TranslatedAction actionLaunchInstanceOffline; TranslatedAction actionLaunchInstanceDemo; TranslatedAction actionExportInstance; + TranslatedAction actionCreateInstanceShortcut; QVector all_actions; LabeledToolButton *renameButton = nullptr; @@ -633,6 +635,7 @@ public: actionExportInstance->setEnabled(enabled); actionDeleteInstance->setEnabled(enabled); actionCopyInstance->setEnabled(enabled); + actionCreateInstanceShortcut->setEnabled(enabled); } void createStatusBar(QMainWindow *MainWindow) @@ -771,6 +774,15 @@ public: actionCopyInstance->setIcon(APPLICATION->getThemedIcon("copy")); all_actions.append(&actionCopyInstance); + actionCreateInstanceShortcut = TranslatedAction(MainWindow); + actionCreateInstanceShortcut->setObjectName(QStringLiteral("actionCreateInstanceShortcut")); + actionCreateInstanceShortcut.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Create Shortcut")); + actionCreateInstanceShortcut.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Creates a shortcut on your desktop to launch the selected instance.")); + //actionCreateInstanceShortcut->setShortcut(QKeySequence(tr("Ctrl+D"))); // TODO + // FIXME missing on Legacy, Flat and Flat (White) + actionCreateInstanceShortcut->setIcon(APPLICATION->getThemedIcon("shortcut")); + all_actions.append(&actionCreateInstanceShortcut); + setInstanceActionsEnabled(false); } @@ -809,6 +821,8 @@ public: instanceToolBar->addAction(actionCopyInstance); instanceToolBar->addAction(actionDeleteInstance); + instanceToolBar->addAction(actionCreateInstanceShortcut); // TODO find better position for this + QLayout * lay = instanceToolBar->layout(); for(int i = 0; i < lay->count(); i++) { @@ -2188,6 +2202,130 @@ void MainWindow::on_actionKillInstance_triggered() } } +void MainWindow::on_actionCreateInstanceShortcut_triggered() +{ + if (m_selectedInstance) + { + auto desktopPath = FS::getDesktopDir(); + if (desktopPath.isEmpty()) { + // TODO come up with an alternative solution (open "save file" dialog) + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Couldn't find desktop?!")); + return; + } + +#if defined(Q_OS_MACOS) + QString appPath = QApplication::applicationFilePath(); + if (appPath.startsWith("/private/var/")) { + QMessageBox::critical(this, tr("Create instance shortcut"), tr("The launcher is in the folder it was extracted from, therefore it cannot create shortcuts.")); + return; + } + + if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), + appPath, { "--launch", m_selectedInstance->id() }, + m_selectedInstance->name(), "")) { + QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!")); + } + else + { + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); + } +#elif defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) + QString appPath = QApplication::applicationFilePath(); + if (appPath.startsWith("/tmp/.mount_")) { + // AppImage! + appPath = QProcessEnvironment::systemEnvironment().value(QStringLiteral("APPIMAGE")); + if (appPath.isEmpty()) + { + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Launcher is running as misconfigured AppImage? ($APPIMAGE environment variable is missing)")); + } + else if (appPath.endsWith("/")) + { + appPath.chop(1); + } + } + + auto icon = APPLICATION->icons()->icon(m_selectedInstance->iconKey()); + if (icon == nullptr) + { + icon = APPLICATION->icons()->icon("grass"); + } + + QString iconPath = FS::PathCombine(m_selectedInstance->instanceRoot(), "icon.png"); + + QFile iconFile(iconPath); + if (!iconFile.open(QFile::WriteOnly)) + { + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create icon for shortcut.")); + return; + } + bool success = icon->icon().pixmap(64, 64).save(&iconFile, "PNG"); + iconFile.close(); + + if (!success) + { + iconFile.remove(); + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create icon for shortcut.")); + return; + } + + if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), + appPath, { "--launch", m_selectedInstance->id() }, + m_selectedInstance->name(), iconPath)) { + QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!")); + } + else + { + iconFile.remove(); + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); + } +#elif defined(Q_OS_WIN) + auto icon = APPLICATION->icons()->icon(m_selectedInstance->iconKey()); + if (icon == nullptr) + { + icon = APPLICATION->icons()->icon("grass"); + } + + QString iconPath = FS::PathCombine(m_selectedInstance->instanceRoot(), "icon.ico"); + + // part of fix for weird bug involving the window icon being replaced + // dunno why it happens, but this 2-line fix seems to be enough, so w/e + auto appIcon = APPLICATION->getThemedIcon("logo"); + + QFile iconFile(iconPath); + if (!iconFile.open(QFile::WriteOnly)) + { + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create icon for shortcut.")); + return; + } + bool success = icon->icon().pixmap(64, 64).save(&iconFile, "ICO"); + iconFile.close(); + + // restore original window icon + QGuiApplication::setWindowIcon(appIcon); + + if (!success) + { + iconFile.remove(); + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create icon for shortcut.")); + return; + } + + if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), + QApplication::applicationFilePath(), { "--launch", m_selectedInstance->id() }, + m_selectedInstance->name(), iconPath)) { + QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!")); + } + else + { + iconFile.remove(); + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); + } +#else + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Not supported on your platform!")); +#endif + } +} + void MainWindow::taskEnd() { QObject *sender = QObject::sender(); diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h index 0aa01ee2..f96f641d 100644 --- a/launcher/ui/MainWindow.h +++ b/launcher/ui/MainWindow.h @@ -161,6 +161,8 @@ private slots: void on_actionEditInstance_triggered(); + void on_actionCreateInstanceShortcut_triggered(); + void taskEnd(); /** diff --git a/nix/default.nix b/nix/default.nix index c7fc7576..6050fd37 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,100 +1,99 @@ -{ stdenv -, lib -, fetchFromGitHub +{ lib +, stdenv , cmake -, ninja , jdk8 , jdk -, ghc_filesystem , zlib , file , wrapQtAppsHook , xorg , libpulseaudio , qtbase -, quazip +, qtsvg +, qtwayland , libGL -, msaClientID ? "" -, extraJDKs ? [ ] +, quazip +, glfw +, openal , extra-cmake-modules +, ghc_filesystem +, msaClientID ? "" +, jdks ? [ jdk jdk8 ] # flake , self , version , libnbtplusplus , tomlplusplus -, enableLTO ? false }: -let - # Libraries required to run Minecraft - libpath = with xorg; lib.makeLibraryPath [ - libX11 - libXext - libXcursor - libXrandr - libXxf86vm - libpulseaudio - libGL - ]; - - # This variable will be passed to Minecraft by Prism Launcher - gameLibraryPath = libpath + ":/run/opengl-driver/lib"; - - javaPaths = lib.makeSearchPath "bin/java" ([ jdk jdk8 ] ++ extraJDKs); -in - stdenv.mkDerivation rec { pname = "prismlauncher"; inherit version; src = lib.cleanSource self; - nativeBuildInputs = [ cmake extra-cmake-modules ninja jdk ghc_filesystem file wrapQtAppsHook ]; - buildInputs = [ qtbase quazip zlib ]; + nativeBuildInputs = [ extra-cmake-modules cmake file jdk wrapQtAppsHook ]; + buildInputs = [ + qtbase + qtsvg + zlib + quazip + ghc_filesystem + ] ++ lib.optional (lib.versionAtLeast qtbase.version "6") qtwayland; + cmakeFlags = lib.optionals (msaClientID != "") [ "-DLauncher_MSA_CLIENT_ID=${msaClientID}" ] + ++ lib.optionals (lib.versionAtLeast qtbase.version "6") [ "-DLauncher_QT_VERSION_MAJOR=6" ]; dontWrapQtApps = true; postUnpack = '' - # Copy libnbtplusplus rm -rf source/libraries/libnbtplusplus mkdir source/libraries/libnbtplusplus ln -s ${libnbtplusplus}/* source/libraries/libnbtplusplus chmod -R +r+w source/libraries/libnbtplusplus - # Copy tomlplusplus + chown -R $USER: source/libraries/libnbtplusplus rm -rf source/libraries/tomlplusplus mkdir source/libraries/tomlplusplus ln -s ${tomlplusplus}/* source/libraries/tomlplusplus chmod -R +r+w source/libraries/tomlplusplus + chown -R $USER: source/libraries/tomlplusplus ''; - cmakeFlags = [ - "-GNinja" - "-DLauncher_QT_VERSION_MAJOR=${lib.versions.major qtbase.version}" - ] ++ lib.optionals enableLTO [ "-DENABLE_LTO=on" ] - ++ lib.optionals (msaClientID != "") [ "-DLauncher_MSA_CLIENT_ID=${msaClientID}" ]; + postInstall = + let + libpath = with xorg; + lib.makeLibraryPath [ + libX11 + libXext + libXcursor + libXrandr + libXxf86vm + libpulseaudio + libGL + glfw + openal + stdenv.cc.cc.lib + ]; + in + '' + # xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128 + wrapQtApp $out/bin/prismlauncher \ + --set LD_LIBRARY_PATH /run/opengl-driver/lib:${libpath} \ + --prefix PRISMLAUNCHER_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks} \ + --prefix PATH : ${lib.makeBinPath [xorg.xrandr]} + ''; - # we have to check if the system is NixOS before adding stdenv.cc.cc.lib (#923) - postInstall = '' - # xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128 - wrapQtApp $out/bin/prismlauncher \ - --run '[ -f /etc/NIXOS ] && export LD_LIBRARY_PATH="${stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH"' \ - --prefix LD_LIBRARY_PATH : ${gameLibraryPath} \ - --prefix PRISMLAUNCHER_JAVA_PATHS : ${javaPaths} \ - --prefix PATH : ${lib.makeBinPath [ xorg.xrandr ]} - ''; meta = with lib; { homepage = "https://prismlauncher.org/"; - downloadPage = "https://prismlauncher.org/download/"; - changelog = "https://github.com/PrismLauncher/PrismLauncher/releases"; description = "A free, open source launcher for Minecraft"; longDescription = '' Allows you to have multiple, separate instances of Minecraft (each with their own mods, texture packs, saves, etc) and helps you manage them and their associated options with a simple interface. ''; - platforms = platforms.unix; + platforms = platforms.linux; + changelog = "https://github.com/PrismLauncher/PrismLauncher/releases/tag/${version}"; license = licenses.gpl3Only; maintainers = with maintainers; [ minion3665 Scrumplex ]; };