aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
-rw-r--r--flake.lock18
-rw-r--r--flatpak/libdecor.json22
-rw-r--r--flatpak/org.prismlauncher.PrismLauncher.yml115
-rw-r--r--flatpak/patches/0003-Don-t-crash-on-calls-to-focus-or-icon.patch24
-rw-r--r--flatpak/patches/0005-Add-warning-about-being-an-unofficial-patch.patch17
-rw-r--r--flatpak/patches/0007-Platform-Prefer-Wayland-over-X11.patch20
-rw-r--r--flatpak/patches/weird_libdecor.patch40
-rw-r--r--flatpak/prismlauncher4
m---------flatpak/shared-modules0
-rw-r--r--launcher/BaseVersion.h19
-rw-r--r--launcher/MMCZip.cpp253
-rw-r--r--launcher/MMCZip.h254
-rw-r--r--launcher/java/JavaInstall.cpp51
-rw-r--r--launcher/java/JavaInstall.h57
-rw-r--r--launcher/minecraft/MinecraftInstance.cpp7
-rw-r--r--launcher/minecraft/auth/AuthSession.cpp1
-rw-r--r--launcher/minecraft/auth/MinecraftAccount.cpp32
-rw-r--r--launcher/minecraft/auth/MinecraftAccount.h2
-rw-r--r--launcher/ui/dialogs/ExportInstanceDialog.cpp99
-rw-r--r--launcher/ui/dialogs/ExportInstanceDialog.h25
21 files changed, 712 insertions, 351 deletions
diff --git a/.gitmodules b/.gitmodules
index 87703fee..0f437d27 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -19,3 +19,6 @@
[submodule "libraries/cmark"]
path = libraries/cmark
url = https://github.com/commonmark/cmark.git
+[submodule "flatpak/shared-modules"]
+ path = flatpak/shared-modules
+ url = https://github.com/flathub/shared-modules.git
diff --git a/flake.lock b/flake.lock
index 91a67f08..370250c4 100644
--- a/flake.lock
+++ b/flake.lock
@@ -21,11 +21,11 @@
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
- "lastModified": 1688254665,
- "narHash": "sha256-8FHEgBrr7gYNiS/NzCxIO3m4hvtLRW9YY1nYo1ivm3o=",
+ "lastModified": 1688466019,
+ "narHash": "sha256-VeM2akYrBYMsb4W/MmBo1zmaMfgbL4cH3Pu8PGyIwJ0=",
"owner": "hercules-ci",
"repo": "flake-parts",
- "rev": "267149c58a14d15f7f81b4d737308421de9d7152",
+ "rev": "8e8d955c22df93dbe24f19ea04f47a74adbdc5ec",
"type": "github"
},
"original": {
@@ -91,11 +91,11 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1688221086,
- "narHash": "sha256-cdW6qUL71cNWhHCpMPOJjlw0wzSRP0pVlRn2vqX/VVg=",
+ "lastModified": 1689413807,
+ "narHash": "sha256-exuzOvOhGAEKWQKwDuZAL4N8a1I837hH5eocaTcIbLc=",
"owner": "nixos",
"repo": "nixpkgs",
- "rev": "cd99c2b3c9f160cd004318e0697f90bbd5960825",
+ "rev": "46ed466081b9cad1125b11f11a2af5cc40b942c7",
"type": "github"
},
"original": {
@@ -138,11 +138,11 @@
]
},
"locked": {
- "lastModified": 1688386108,
- "narHash": "sha256-Vffto9QaVonzYAcPlAzd0soqWYpPpKk60dfNLSIXcFA=",
+ "lastModified": 1689328505,
+ "narHash": "sha256-9B3+OeUn1a/CvzE3GW6nWNwS5J7PDHTyHGlpL3wV5oA=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
- "rev": "42587d3414d1747999a5f71e92a83cf6547b62da",
+ "rev": "5e28316db471d1ac234beb70031b635437421dd6",
"type": "github"
},
"original": {
diff --git a/flatpak/libdecor.json b/flatpak/libdecor.json
new file mode 100644
index 00000000..12afad69
--- /dev/null
+++ b/flatpak/libdecor.json
@@ -0,0 +1,22 @@
+{
+ "name": "libdecor",
+ "buildsystem": "meson",
+ "config-opts": [
+ "-Ddemo=false"
+ ],
+ "sources": [
+ {
+ "type": "git",
+ "url": "https://gitlab.freedesktop.org/libdecor/libdecor.git",
+ "commit": "73260393a97291c887e1074ab7f318e031be0ac6"
+ },
+ {
+ "type": "patch",
+ "path": "patches/weird_libdecor.patch"
+ }
+ ],
+ "cleanup": [
+ "/include",
+ "/lib/pkgconfig"
+ ]
+}
diff --git a/flatpak/org.prismlauncher.PrismLauncher.yml b/flatpak/org.prismlauncher.PrismLauncher.yml
index 0524946f..a9b9762f 100644
--- a/flatpak/org.prismlauncher.PrismLauncher.yml
+++ b/flatpak/org.prismlauncher.PrismLauncher.yml
@@ -5,13 +5,6 @@ sdk: org.kde.Sdk
sdk-extensions:
- org.freedesktop.Sdk.Extension.openjdk17
- org.freedesktop.Sdk.Extension.openjdk8
-add-extensions:
- com.valvesoftware.Steam.Utility.gamescope:
- version: stable
- add-ld-path: lib
- no-autodownload: true
- autodelete: false
- directory: utils/gamescope
command: prismlauncher
finish-args:
@@ -26,21 +19,31 @@ finish-args:
# Mod drag&drop
- --filesystem=xdg-download:ro
+cleanup:
+ - /lib/libGLU*
+
modules:
+ # Might be needed by some Controller mods (see https://github.com/isXander/Controlify/issues/31)
+ - shared-modules/libusb/libusb.json
+
+ # Needed for proper Wayland support
+ - libdecor.json
+
- name: prismlauncher
buildsystem: cmake-ninja
+ builddir: true
config-opts:
- -DLauncher_BUILD_PLATFORM=flatpak
- - -DCMAKE_BUILD_TYPE=Debug
+ - -DCMAKE_BUILD_TYPE=RelWithDebInfo
- -DLauncher_QT_VERSION_MAJOR=5
build-options:
env:
JAVA_HOME: /usr/lib/sdk/openjdk17/jvm/openjdk-17
JAVA_COMPILER: /usr/lib/sdk/openjdk17/jvm/openjdk-17/bin/javac
sources:
- - type: dir
- path: ../
- builddir: true
+ - type: dir
+ path: ../
+
- name: openjdk
buildsystem: simple
build-commands:
@@ -49,14 +52,45 @@ modules:
- mv /app/jre /app/jdk/17
- /usr/lib/sdk/openjdk8/install.sh
- mv /app/jre /app/jdk/8
- cleanup: [/jre]
+ cleanup:
+ - /jre
+
+ - name: glfw
+ buildsystem: cmake-ninja
+ config-opts:
+ - -DCMAKE_BUILD_TYPE=RelWithDebInfo
+ - -DBUILD_SHARED_LIBS:BOOL=ON
+ - -DGLFW_USE_WAYLAND=ON
+ sources:
+ - type: git
+ url: https://github.com/glfw/glfw.git
+ commit: 3fa2360720eeba1964df3c0ecf4b5df8648a8e52
+ - type: patch
+ path: patches/0003-Don-t-crash-on-calls-to-focus-or-icon.patch
+ - type: patch
+ path: patches/0005-Add-warning-about-being-an-unofficial-patch.patch
+ - type: patch
+ path: patches/0007-Platform-Prefer-Wayland-over-X11.patch
+ cleanup:
+ - /include
+ - /lib/cmake
+ - /lib/pkgconfig
+
- name: xrandr
buildsystem: autotools
sources:
- type: archive
- url: https://xorg.freedesktop.org/archive/individual/app/xrandr-1.5.1.tar.xz
- sha256: 7bc76daf9d72f8aff885efad04ce06b90488a1a169d118dea8a2b661832e8762
- cleanup: [/share/man, /bin/xkeystone]
+ url: https://xorg.freedesktop.org/archive/individual/app/xrandr-1.5.2.tar.xz
+ sha256: c8bee4790d9058bacc4b6246456c58021db58a87ddda1a9d0139bf5f18f1f240
+ x-checker-data:
+ type: anitya
+ project-id: 14957
+ stable-only: true
+ url-template: https://xorg.freedesktop.org/archive/individual/app/xrandr-$version.tar.xz
+ cleanup:
+ - /share/man
+ - /bin/xkeystone
+
- name: gamemode
buildsystem: meson
config-opts:
@@ -67,19 +101,56 @@ modules:
# post-install is running inside the build dir, we need it from the source though
- install -Dm755 ../data/gamemoderun -t /app/bin
sources:
- - type: git
- url: https://github.com/FeralInteractive/gamemode
- tag: "1.7"
- commit: 4dc99dff76218718763a6b07fc1900fa6d1dafd9
+ - type: archive
+ archive-type: tar-gzip
+ url: https://api.github.com/repos/FeralInteractive/gamemode/tarball/1.7
+ sha256: 57ce73ba605d1cf12f8d13725006a895182308d93eba0f69f285648449641803
+ x-checker-data:
+ type: json
+ url: https://api.github.com/repos/FeralInteractive/gamemode/releases/latest
+ version-query: .tag_name
+ url-query: .tarball_url
+ timestamp-query: .published_at
+ cleanup:
+ - /include
+ - /lib/pkgconfig
+ - /lib/libgamemodeauto.a
+
+ - name: glxinfo
+ buildsystem: meson
+ config-opts:
+ - --bindir=/app/mesa-demos
+ - -Degl=disabled
+ - -Dglut=disabled
+ - -Dosmesa=disabled
+ - -Dvulkan=disabled
+ - -Dwayland=disabled
+ post-install:
+ - mv -v /app/mesa-demos/glxinfo /app/bin
+ sources:
+ - type: archive
+ url: https://archive.mesa3d.org/demos/mesa-demos-9.0.0.tar.xz
+ sha256: 3046a3d26a7b051af7ebdd257a5f23bfeb160cad6ed952329cdff1e9f1ed496b
+ x-checker-data:
+ type: anitya
+ project-id: 16781
+ stable-only: true
+ url-template: https://archive.mesa3d.org/demos/mesa-demos-$version.tar.xz
+ cleanup:
+ - /include
+ - /mesa-demos
+ - /share
+ modules:
+ - shared-modules/glu/glu-9.json
+
- name: enhance
buildsystem: simple
build-commands:
- - mkdir -p /app/utils/gamescope
- install -Dm755 prime-run /app/bin/prime-run
- mv /app/bin/prismlauncher /app/bin/prismrun
- install -Dm755 prismlauncher /app/bin/prismlauncher
sources:
- type: file
- path: ../flatpak/prime-run
+ path: prime-run
- type: file
- path: ../flatpak/prismlauncher
+ path: prismlauncher
diff --git a/flatpak/patches/0003-Don-t-crash-on-calls-to-focus-or-icon.patch b/flatpak/patches/0003-Don-t-crash-on-calls-to-focus-or-icon.patch
new file mode 100644
index 00000000..9130e856
--- /dev/null
+++ b/flatpak/patches/0003-Don-t-crash-on-calls-to-focus-or-icon.patch
@@ -0,0 +1,24 @@
+diff --git a/src/wl_window.c b/src/wl_window.c
+index 52d3b9eb..4ac4eb5d 100644
+--- a/src/wl_window.c
++++ b/src/wl_window.c
+@@ -2117,8 +2117,7 @@ void _glfwSetWindowTitleWayland(_GLFWwindow* window, const char* title)
+ void _glfwSetWindowIconWayland(_GLFWwindow* window,
+ int count, const GLFWimage* images)
+ {
+- _glfwInputError(GLFW_FEATURE_UNAVAILABLE,
+- "Wayland: The platform does not support setting the window icon");
++ fprintf(stderr, "!!! Ignoring Error: Wayland: The platform does not support setting the window icon\n");
+ }
+
+ void _glfwGetWindowPosWayland(_GLFWwindow* window, int* xpos, int* ypos)
+@@ -2361,8 +2360,7 @@ void _glfwRequestWindowAttentionWayland(_GLFWwindow* window)
+
+ void _glfwFocusWindowWayland(_GLFWwindow* window)
+ {
+- _glfwInputError(GLFW_FEATURE_UNAVAILABLE,
+- "Wayland: The platform does not support setting the input focus");
++ fprintf(stderr, "!!! Ignoring Error: Wayland: The platform does not support setting the input focus\n");
+ }
+
+ void _glfwSetWindowMonitorWayland(_GLFWwindow* window,
diff --git a/flatpak/patches/0005-Add-warning-about-being-an-unofficial-patch.patch b/flatpak/patches/0005-Add-warning-about-being-an-unofficial-patch.patch
new file mode 100644
index 00000000..b031d739
--- /dev/null
+++ b/flatpak/patches/0005-Add-warning-about-being-an-unofficial-patch.patch
@@ -0,0 +1,17 @@
+diff --git a/src/init.c b/src/init.c
+index 06dbb3f2..a7c6da86 100644
+--- a/src/init.c
++++ b/src/init.c
+@@ -449,6 +449,12 @@ GLFWAPI int glfwInit(void)
+ _glfw.initialized = GLFW_TRUE;
+
+ glfwDefaultWindowHints();
++
++ fprintf(stderr, "!!! Patched GLFW from https://github.com/Admicos/minecraft-wayland\n"
++ "!!! If any issues with the window, or some issues with rendering, occur, "
++ "first try with the built-in GLFW, and if that solves the issue, report there first.\n"
++ "!!! Use outside Minecraft is untested, and things might break.\n");
++
+ return GLFW_TRUE;
+ }
+
diff --git a/flatpak/patches/0007-Platform-Prefer-Wayland-over-X11.patch b/flatpak/patches/0007-Platform-Prefer-Wayland-over-X11.patch
new file mode 100644
index 00000000..4eeb8130
--- /dev/null
+++ b/flatpak/patches/0007-Platform-Prefer-Wayland-over-X11.patch
@@ -0,0 +1,20 @@
+diff --git a/src/platform.c b/src/platform.c
+index c5966ae7..3e7442f9 100644
+--- a/src/platform.c
++++ b/src/platform.c
+@@ -49,12 +49,12 @@ static const struct
+ #if defined(_GLFW_COCOA)
+ { GLFW_PLATFORM_COCOA, _glfwConnectCocoa },
+ #endif
+-#if defined(_GLFW_X11)
+- { GLFW_PLATFORM_X11, _glfwConnectX11 },
+-#endif
+ #if defined(_GLFW_WAYLAND)
+ { GLFW_PLATFORM_WAYLAND, _glfwConnectWayland },
+ #endif
++#if defined(_GLFW_X11)
++ { GLFW_PLATFORM_X11, _glfwConnectX11 },
++#endif
+ };
+
+ GLFWbool _glfwSelectPlatform(int desiredID, _GLFWplatform* platform)
diff --git a/flatpak/patches/weird_libdecor.patch b/flatpak/patches/weird_libdecor.patch
new file mode 100644
index 00000000..3a400b82
--- /dev/null
+++ b/flatpak/patches/weird_libdecor.patch
@@ -0,0 +1,40 @@
+diff --git a/src/libdecor.c b/src/libdecor.c
+index a9c1106..1aa38b3 100644
+--- a/src/libdecor.c
++++ b/src/libdecor.c
+@@ -1391,22 +1391,32 @@ calculate_priority(const struct libdecor_plugin_description *plugin_description)
+ static bool
+ check_symbol_conflicts(const struct libdecor_plugin_description *plugin_description)
+ {
++ bool ret = true;
+ char * const *symbol;
++ void* main_prog = dlopen(NULL, RTLD_LAZY);
++ if (!main_prog) {
++ fprintf(stderr, "Plugin \"%s\" couldn't check conflicting symbols: \"%s\".\n",
++ plugin_description->description, dlerror());
++ return false;
++ }
++
+
+ symbol = plugin_description->conflicting_symbols;
+ while (*symbol) {
+ dlerror();
+- dlsym (RTLD_DEFAULT, *symbol);
++ dlsym (main_prog, *symbol);
+ if (!dlerror()) {
+ fprintf(stderr, "Plugin \"%s\" uses conflicting symbol \"%s\".\n",
+ plugin_description->description, *symbol);
+- return false;
++ ret = false;
++ break;
+ }
+
+ symbol++;
+ }
+
+- return true;
++ dlclose(main_prog);
++ return ret;
+ }
+
+ static struct plugin_loader *
diff --git a/flatpak/prismlauncher b/flatpak/prismlauncher
index bb876711..039d890d 100644
--- a/flatpak/prismlauncher
+++ b/flatpak/prismlauncher
@@ -5,7 +5,7 @@ for i in {0..9}; do
test -S "$XDG_RUNTIME_DIR"/discord-ipc-"$i" || ln -sf {app/com.discordapp.Discord,"$XDG_RUNTIME_DIR"}/discord-ipc-"$i";
done
-export PATH="${PATH}${PATH:+:}/app/utils/gamescope/bin:/usr/lib/extensions/vulkan/MangoHud/bin"
-export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}${LD_LIBRARY_PATH:+:}/usr/lib/extensions/vulkan/MangoHud/\$LIB/"
+export PATH="${PATH}${PATH:+:}/usr/lib/extensions/vulkan/gamescope/bin:/usr/lib/extensions/vulkan/MangoHud/bin"
+export VK_LAYER_PATH="/usr/lib/extensions/vulkan/share/vulkan/implicit_layer.d/"
exec /app/bin/prismrun "$@"
diff --git a/flatpak/shared-modules b/flatpak/shared-modules
new file mode 160000
+Subproject 45094ca570be383d06df729b6972830ec63bd3d
diff --git a/launcher/BaseVersion.h b/launcher/BaseVersion.h
index ca0e4502..c7cedbe1 100644
--- a/launcher/BaseVersion.h
+++ b/launcher/BaseVersion.h
@@ -15,16 +15,15 @@
#pragma once
-#include <memory>
-#include <QString>
#include <QMetaType>
+#include <QString>
+#include <memory>
/*!
* An abstract base class for versions.
*/
-class BaseVersion
-{
-public:
+class BaseVersion {
+ public:
using Ptr = std::shared_ptr<BaseVersion>;
virtual ~BaseVersion() {}
/*!
@@ -45,14 +44,8 @@ public:
*/
virtual QString typeString() const = 0;
- virtual bool operator<(BaseVersion &a)
- {
- return name() < a.name();
- };
- virtual bool operator>(BaseVersion &a)
- {
- return name() > a.name();
- };
+ virtual bool operator<(BaseVersion& a) { return name() < a.name(); };
+ virtual bool operator>(BaseVersion& a) { return name() > a.name(); };
};
Q_DECLARE_METATYPE(BaseVersion::Ptr)
diff --git a/launcher/MMCZip.cpp b/launcher/MMCZip.cpp
index 1a336375..acd6bf7e 100644
--- a/launcher/MMCZip.cpp
+++ b/launcher/MMCZip.cpp
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
- * PolyMC - Minecraft Launcher
+ * Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ * Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
*
* 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
@@ -33,56 +34,50 @@
* limitations under the License.
*/
+#include "MMCZip.h"
#include <quazip/quazip.h>
#include <quazip/quazipdir.h>
#include <quazip/quazipfile.h>
-#include "MMCZip.h"
#include "FileSystem.h"
#include <QCoreApplication>
#include <QDebug>
+#include <QtConcurrentRun>
+namespace MMCZip {
// ours
-bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained, const FilterFunction filter)
+bool mergeZipFiles(QuaZip* into, QFileInfo from, QSet<QString>& contained, const FilterFunction filter)
{
QuaZip modZip(from.filePath());
modZip.open(QuaZip::mdUnzip);
QuaZipFile fileInsideMod(&modZip);
QuaZipFile zipOutFile(into);
- for (bool more = modZip.goToFirstFile(); more; more = modZip.goToNextFile())
- {
+ for (bool more = modZip.goToFirstFile(); more; more = modZip.goToNextFile()) {
QString filename = modZip.getCurrentFileName();
- if (filter && !filter(filename))
- {
- qDebug() << "Skipping file " << filename << " from "
- << from.fileName() << " - filtered";
+ if (filter && !filter(filename)) {
+ qDebug() << "Skipping file " << filename << " from " << from.fileName() << " - filtered";
continue;
}
- if (contained.contains(filename))
- {
- qDebug() << "Skipping already contained file " << filename << " from "
- << from.fileName();
+ if (contained.contains(filename)) {
+ qDebug() << "Skipping already contained file " << filename << " from " << from.fileName();
continue;
}
contained.insert(filename);
- if (!fileInsideMod.open(QIODevice::ReadOnly))
- {
+ if (!fileInsideMod.open(QIODevice::ReadOnly)) {
qCritical() << "Failed to open " << filename << " from " << from.fileName();
return false;
}
QuaZipNewInfo info_out(fileInsideMod.getActualFileName());
- if (!zipOutFile.open(QIODevice::WriteOnly, info_out))
- {
+ if (!zipOutFile.open(QIODevice::WriteOnly, info_out)) {
qCritical() << "Failed to open " << filename << " in the jar";
fileInsideMod.close();
return false;
}
- if (!JlCompress::copyData(fileInsideMod, zipOutFile))
- {
+ if (!JlCompress::copyData(fileInsideMod, zipOutFile)) {
zipOutFile.close();
fileInsideMod.close();
qCritical() << "Failed to copy data of " << filename << " into the jar";
@@ -94,10 +89,11 @@ bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &containe
return true;
}
-bool MMCZip::compressDirFiles(QuaZip *zip, QString dir, QFileInfoList files, bool followSymlinks)
+bool compressDirFiles(QuaZip* zip, QString dir, QFileInfoList files, bool followSymlinks)
{
QDir directory(dir);
- if (!directory.exists()) return false;
+ if (!directory.exists())
+ return false;
for (auto e : files) {
auto filePath = directory.relativeFilePath(e.absoluteFilePath());
@@ -109,17 +105,18 @@ bool MMCZip::compressDirFiles(QuaZip *zip, QString dir, QFileInfoList files, boo
srcPath = e.canonicalFilePath();
}
}
- if( !JlCompress::compressFile(zip, srcPath, filePath)) return false;
+ if (!JlCompress::compressFile(zip, srcPath, filePath))
+ return false;
}
return true;
}
-bool MMCZip::compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files, bool followSymlinks)
+bool compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files, bool followSymlinks)
{
QuaZip zip(fileCompressed);
QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
- if(!zip.open(QuaZip::mdCreate)) {
+ if (!zip.open(QuaZip::mdCreate)) {
QFile::remove(fileCompressed);
return false;
}
@@ -127,7 +124,7 @@ bool MMCZip::compressDirFiles(QString fileCompressed, QString dir, QFileInfoList
auto result = compressDirFiles(&zip, dir, files, followSymlinks);
zip.close();
- if(zip.getZipError()!=0) {
+ if (zip.getZipError() != 0) {
QFile::remove(fileCompressed);
return false;
}
@@ -136,11 +133,10 @@ bool MMCZip::compressDirFiles(QString fileCompressed, QString dir, QFileInfoList
}
// ours
-bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod*>& mods)
+bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod*>& mods)
{
QuaZip zipOut(targetJarPath);
- if (!zipOut.open(QuaZip::mdCreate))
- {
+ if (!zipOut.open(QuaZip::mdCreate)) {
QFile::remove(targetJarPath);
qCritical() << "Failed to open the minecraft.jar for modding";
return false;
@@ -151,37 +147,29 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const
// Modify the jar
// This needs to be done in reverse-order to ensure we respect the loading order of components
- for (auto i = mods.crbegin(); i != mods.crend(); i++)
- {
+ for (auto i = mods.crbegin(); i != mods.crend(); i++) {
const auto* mod = *i;
// do not merge disabled mods.
if (!mod->enabled())
continue;
- if (mod->type() == ResourceType::ZIPFILE)
- {
- if (!mergeZipFiles(&zipOut, mod->fileinfo(), addedFiles))
- {
+ if (mod->type() == ResourceType::ZIPFILE) {
+ if (!mergeZipFiles(&zipOut, mod->fileinfo(), addedFiles)) {
zipOut.close();
QFile::remove(targetJarPath);
qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar.";
return false;
}
- }
- else if (mod->type() == ResourceType::SINGLEFILE)
- {
+ } else if (mod->type() == ResourceType::SINGLEFILE) {
// FIXME: buggy - does not work with addedFiles
auto filename = mod->fileinfo();
- if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName()))
- {
+ if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName())) {
zipOut.close();
QFile::remove(targetJarPath);
qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar.";
return false;
}
addedFiles.insert(filename.fileName());
- }
- else if (mod->type() == ResourceType::FOLDER)
- {
+ } else if (mod->type() == ResourceType::FOLDER) {
// untested, but seems to be unused / not possible to reach
// FIXME: buggy - does not work with addedFiles
auto filename = mod->fileinfo();
@@ -190,25 +178,21 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const
dir.cdUp();
QString parent_dir = dir.absolutePath();
auto files = QFileInfoList();
- MMCZip::collectFileListRecursively(what_to_zip, nullptr, &files, nullptr);
+ collectFileListRecursively(what_to_zip, nullptr, &files, nullptr);
for (auto e : files) {
if (addedFiles.contains(e.filePath()))
files.removeAll(e);
}
- if (!MMCZip::compressDirFiles(&zipOut, parent_dir, files))
- {
+ if (!compressDirFiles(&zipOut, parent_dir, files)) {
zipOut.close();
QFile::remove(targetJarPath);
qCritical() << "Failed to add" << mod->fileinfo().fileName() << "to the jar.";
return false;
}
- qDebug() << "Adding folder " << filename.fileName() << " from "
- << filename.absoluteFilePath();
- }
- else
- {
+ qDebug() << "Adding folder " << filename.fileName() << " from " << filename.absoluteFilePath();
+ } else {
// Make sure we do not continue launching when something is missing or undefined...
zipOut.close();
QFile::remove(targetJarPath);
@@ -217,8 +201,7 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const
}
}
- if (!mergeZipFiles(&zipOut, QFileInfo(sourceJarPath), addedFiles, [](const QString key){return !key.contains("META-INF");}))
- {
+ if (!mergeZipFiles(&zipOut, QFileInfo(sourceJarPath), addedFiles, [](const QString key) { return !key.contains("META-INF"); })) {
zipOut.close();
QFile::remove(targetJarPath);
qCritical() << "Failed to insert minecraft.jar contents.";
@@ -227,8 +210,7 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const
// Recompress the jar
zipOut.close();
- if (zipOut.getZipError() != 0)
- {
+ if (zipOut.getZipError() != 0) {
QFile::remove(targetJarPath);
qCritical() << "Failed to finalize minecraft.jar!";
return false;
@@ -237,7 +219,7 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const
}
// ours
-QString MMCZip::findFolderOfFileInZip(QuaZip* zip, const QString& what, const QStringList& ignore_paths, const QString& root)
+QString findFolderOfFileInZip(QuaZip* zip, const QString& what, const QStringList& ignore_paths, const QString& root)
{
QuaZipDir rootDir(zip, root);
for (auto&& fileName : rootDir.entryList(QDir::Files)) {
@@ -261,27 +243,23 @@ QString MMCZip::findFolderOfFileInZip(QuaZip* zip, const QString& what, const QS
}
// ours
-bool MMCZip::findFilesInZip(QuaZip * zip, const QString & what, QStringList & result, const QString &root)
+bool findFilesInZip(QuaZip* zip, const QString& what, QStringList& result, const QString& root)
{
QuaZipDir rootDir(zip, root);
- for(auto fileName: rootDir.entryList(QDir::Files))
- {
- if(fileName == what)
- {
+ for (auto fileName : rootDir.entryList(QDir::Files)) {
+ if (fileName == what) {
result.append(root);
return true;
}
}
- for(auto fileName: rootDir.entryList(QDir::Dirs))
- {
+ for (auto fileName : rootDir.entryList(QDir::Dirs)) {
findFilesInZip(zip, what, result, root + fileName);
}
return !result.isEmpty();
}
-
// ours
-std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QString &target)
+std::optional<QStringList> extractSubDir(QuaZip* zip, const QString& subdir, const QString& target)
{
auto target_top_dir = QUrl::fromLocalFile(target);
@@ -289,16 +267,13 @@ std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & su
qDebug() << "Extracting subdir" << subdir << "from" << zip->getZipName() << "to" << target;
auto numEntries = zip->getEntriesCount();
- if(numEntries < 0) {
+ if (numEntries < 0) {
qWarning() << "Failed to enumerate files in archive";
return std::nullopt;
- }
- else if(numEntries == 0) {
+ } else if (numEntries == 0) {
qDebug() << "Extracting empty archives seems odd...";
return extracted;
- }
- else if (!zip->goToFirstFile())
- {
+ } else if (!zip->goToFirstFile()) {
qWarning() << "Failed to seek to first file in zip";
return std::nullopt;
}
@@ -334,7 +309,8 @@ std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & su
}
if (!target_top_dir.isParentOf(QUrl::fromLocalFile(target_file_path))) {
- qWarning() << "Extracting" << relative_file_name << "was cancelled, because it was effectively outside of the target path" << target;
+ qWarning() << "Extracting" << relative_file_name << "was cancelled, because it was effectively outside of the target path"
+ << target;
return std::nullopt;
}
@@ -345,7 +321,8 @@ std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & su
}
extracted.append(target_file_path);
- QFile::setPermissions(target_file_path, QFileDevice::Permission::ReadUser | QFileDevice::Permission::WriteUser | QFileDevice::Permission::ExeUser);
+ QFile::setPermissions(target_file_path,
+ QFileDevice::Permission::ReadUser | QFileDevice::Permission::WriteUser | QFileDevice::Permission::ExeUser);
qDebug() << "Extracted file" << relative_file_name << "to" << target_file_path;
} while (zip->goToNextFile());
@@ -354,66 +331,66 @@ std::optional<QStringList> MMCZip::extractSubDir(QuaZip *zip, const QString & su
}
// ours
-bool MMCZip::extractRelFile(QuaZip *zip, const QString &file, const QString &target)
+bool extractRelFile(QuaZip* zip, const QString& file, const QString& target)
{
return JlCompress::extractFile(zip, file, target);
}
// ours
-std::optional<QStringList> MMCZip::extractDir(QString fileCompressed, QString dir)
+std::optional<QStringList> extractDir(QString fileCompressed, QString dir)
{
QuaZip zip(fileCompressed);
- if (!zip.open(QuaZip::mdUnzip))
- {
+ if (!zip.open(QuaZip::mdUnzip)) {
// check if this is a minimum size empty zip file...
QFileInfo fileInfo(fileCompressed);
- if(fileInfo.size() == 22) {
+ if (fileInfo.size() == 22) {
return QStringList();
}
- qWarning() << "Could not open archive for unzipping:" << fileCompressed << "Error:" << zip.getZipError();;
+ qWarning() << "Could not open archive for unzipping:" << fileCompressed << "Error:" << zip.getZipError();
+ ;
return std::nullopt;
}
- return MMCZip::extractSubDir(&zip, "", dir);
+ return extractSubDir(&zip, "", dir);
}
// ours
-std::optional<QStringList> MMCZip::extractDir(QString fileCompressed, QString subdir, QString dir)
+std::optional<QStringList> extractDir(QString fileCompressed, QString subdir, QString dir)
{
QuaZip zip(fileCompressed);
- if (!zip.open(QuaZip::mdUnzip))
- {
+ if (!zip.open(QuaZip::mdUnzip)) {
// check if this is a minimum size empty zip file...
QFileInfo fileInfo(fileCompressed);
- if(fileInfo.size() == 22) {
+ if (fileInfo.size() == 22) {
return QStringList();
}
- qWarning() << "Could not open archive for unzipping:" << fileCompressed << "Error:" << zip.getZipError();;
+ qWarning() << "Could not open archive for unzipping:" << fileCompressed << "Error:" << zip.getZipError();
+ ;
return std::nullopt;
}
- return MMCZip::extractSubDir(&zip, subdir, dir);
+ return extractSubDir(&zip, subdir, dir);
}
// ours
-bool MMCZip::extractFile(QString fileCompressed, QString file, QString target)
+bool extractFile(QString fileCompressed, QString file, QString target)
{
QuaZip zip(fileCompressed);
- if (!zip.open(QuaZip::mdUnzip))
- {
+ if (!zip.open(QuaZip::mdUnzip)) {
// check if this is a minimum size empty zip file...
QFileInfo fileInfo(fileCompressed);
- if(fileInfo.size() == 22) {
+ if (fileInfo.size() == 22) {
return true;
}
qWarning() << "Could not open archive for unzipping:" << fileCompressed << "Error:" << zip.getZipError();
return false;
}
- return MMCZip::extractRelFile(&zip, file, target);
+ return extractRelFile(&zip, file, target);
}
-bool MMCZip::collectFileListRecursively(const QString& rootDir, const QString& subDir, QFileInfoList *files,
- MMCZip::FilterFunction excludeFilter) {
+bool collectFileListRecursively(const QString& rootDir, const QString& subDir, QFileInfoList* files, FilterFunction excludeFilter)
+{
QDir rootDirectory(rootDir);
- if (!rootDirectory.exists()) return false;
+ if (!rootDirectory.exists())
+