From efa414c442a77735a5f972b7103e8ce866a6bdd1 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 20 Jan 2022 20:40:56 +0100 Subject: [PATCH 1/8] refactor: initial migration to QuaZip 1.2 Let's move off our custom QuaZip. In the olden times we needed the custom version of QuaZip, as it was basically unmaintained and on SourceForge (eww). But nowadays it's maintained and on GitHub. See new GitHub page: https://github.com/stachenov/quazip --- .gitmodules | 4 - CMakeLists.txt | 3 +- launcher/InstanceImportTask.cpp | 2 +- launcher/MMCZip.cpp | 102 +----------------- launcher/MMCZip.h | 8 +- launcher/minecraft/MinecraftLoadAndCheck.h | 2 +- launcher/minecraft/MinecraftUpdate.h | 2 +- launcher/minecraft/World.cpp | 6 +- launcher/minecraft/launch/ExtractNatives.cpp | 4 +- launcher/minecraft/launch/ModMinecraftJar.cpp | 8 +- launcher/minecraft/mod/LocalModParseTask.cpp | 4 +- .../atlauncher/ATLPackInstallTask.cpp | 2 +- .../modplatform/legacy_ftb/PackInstallTask.h | 4 +- .../technic/SingleZipPackInstallTask.h | 2 +- .../technic/TechnicPackProcessor.cpp | 6 +- launcher/ui/dialogs/ExportInstanceDialog.cpp | 7 +- libraries/classparser/src/classparser.cpp | 2 +- libraries/quazip | 1 - 18 files changed, 39 insertions(+), 130 deletions(-) delete mode 160000 libraries/quazip diff --git a/.gitmodules b/.gitmodules index 6b90601f5..cff268100 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,7 +2,3 @@ path = libraries/libnbtplusplus url = https://github.com/MultiMC/libnbtplusplus.git pushurl = git@github.com:MultiMC/libnbtplusplus.git -[submodule "libraries/quazip"] - path = libraries/quazip - url = https://github.com/PolyMC/quazip.git - pushurl = git@github.com:PolyMC/quazip.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a9511b31..35deff044 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,8 @@ find_package(Qt5Network REQUIRED) find_package(Qt5Test REQUIRED) find_package(Qt5Xml REQUIRED) +find_package(QuaZip-Qt5 REQUIRED) + # The Qt5 cmake files don't provide its install paths, so ask qmake. include(QMakeQuery) query_qmake(QT_INSTALL_PLUGINS QT_PLUGINS_DIR) @@ -249,7 +251,6 @@ add_subdirectory(libraries/hoedown) # markdown parser add_subdirectory(libraries/launcher) # java based launcher part for Minecraft add_subdirectory(libraries/javacheck) # java compatibility checker add_subdirectory(libraries/xz-embedded) # xz compression -add_subdirectory(libraries/quazip) # zip manipulation library add_subdirectory(libraries/rainbow) # Qt extension for colors add_subdirectory(libraries/iconfix) # fork of Qt's QIcon loader add_subdirectory(libraries/LocalPeer) # fork of a library from Qt solutions diff --git a/launcher/InstanceImportTask.cpp b/launcher/InstanceImportTask.cpp index 8cd68d7b4..6e2dd912a 100644 --- a/launcher/InstanceImportTask.cpp +++ b/launcher/InstanceImportTask.cpp @@ -29,7 +29,7 @@ #include "modplatform/flame/FileResolvingTask.h" #include "modplatform/flame/PackManifest.h" #include "Json.h" -#include +#include #include "modplatform/technic/TechnicPackProcessor.h" #include "icons/IconList.h" diff --git a/launcher/MMCZip.cpp b/launcher/MMCZip.cpp index b25c61e75..e1906a0c7 100644 --- a/launcher/MMCZip.cpp +++ b/launcher/MMCZip.cpp @@ -13,17 +13,16 @@ * limitations under the License. */ -#include -#include -#include -#include +#include +#include +#include #include "MMCZip.h" #include "FileSystem.h" #include // ours -bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet &contained, const JlCompress::FilterFunction filter) +bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet &contained, const FilterFunction filter) { QuaZip modZip(from.filePath()); modZip.open(QuaZip::mdUnzip); @@ -74,99 +73,6 @@ bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet &containe return true; } -// ours -bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const QList& mods) -{ - QuaZip zipOut(targetJarPath); - if (!zipOut.open(QuaZip::mdCreate)) - { - QFile::remove(targetJarPath); - qCritical() << "Failed to open the minecraft.jar for modding"; - return false; - } - // Files already added to the jar. - // These files will be skipped. - QSet addedFiles; - - // Modify the jar - QListIterator i(mods); - i.toBack(); - while (i.hasPrevious()) - { - const Mod &mod = i.previous(); - // do not merge disabled mods. - if (!mod.enabled()) - continue; - if (mod.type() == Mod::MOD_ZIPFILE) - { - if (!mergeZipFiles(&zipOut, mod.filename(), addedFiles)) - { - zipOut.close(); - QFile::remove(targetJarPath); - qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar."; - return false; - } - } - else if (mod.type() == Mod::MOD_SINGLEFILE) - { - // FIXME: buggy - does not work with addedFiles - auto filename = mod.filename(); - if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName())) - { - zipOut.close(); - QFile::remove(targetJarPath); - qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar."; - return false; - } - addedFiles.insert(filename.fileName()); - } - else if (mod.type() == Mod::MOD_FOLDER) - { - // FIXME: buggy - does not work with addedFiles - auto filename = mod.filename(); - QString what_to_zip = filename.absoluteFilePath(); - QDir dir(what_to_zip); - dir.cdUp(); - QString parent_dir = dir.absolutePath(); - if (!JlCompress::compressSubDir(&zipOut, what_to_zip, parent_dir, addedFiles)) - { - zipOut.close(); - QFile::remove(targetJarPath); - qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar."; - return false; - } - 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); - qCritical() << "Failed to add unknown mod type" << mod.filename().fileName() << "to the jar."; - return false; - } - } - - 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."; - return false; - } - - // Recompress the jar - zipOut.close(); - if (zipOut.getZipError() != 0) - { - QFile::remove(targetJarPath); - qCritical() << "Failed to finalize minecraft.jar!"; - return false; - } - return true; -} - // ours QString MMCZip::findFolderOfFileInZip(QuaZip * zip, const QString & what, const QString &root) { diff --git a/launcher/MMCZip.h b/launcher/MMCZip.h index 9c47fa11f..5260f8566 100644 --- a/launcher/MMCZip.h +++ b/launcher/MMCZip.h @@ -21,17 +21,21 @@ #include "minecraft/mod/Mod.h" #include -#include +//#include +// TODO: Blocked by https://github.com/stachenov/quazip/pull/141 +// For now, checkout https://github.com/Scrumplex/quazip/tree/expose-jlcompress-fns at ../../quazip +#include <../../quazip/quazip/JlCompress.h> #include namespace MMCZip { + using FilterFunction = std::function; /** * Merge two zip files, using a filter function */ bool mergeZipFiles(QuaZip *into, QFileInfo from, QSet &contained, - const JlCompress::FilterFunction filter = nullptr); + const FilterFunction filter = nullptr); /** * take a source jar, add mods to it, resulting in target jar diff --git a/launcher/minecraft/MinecraftLoadAndCheck.h b/launcher/minecraft/MinecraftLoadAndCheck.h index bfeae46b8..4e673a4bf 100644 --- a/launcher/minecraft/MinecraftLoadAndCheck.h +++ b/launcher/minecraft/MinecraftLoadAndCheck.h @@ -20,7 +20,7 @@ #include #include "tasks/Task.h" -#include +#include #include "QObjectPtr.h" diff --git a/launcher/minecraft/MinecraftUpdate.h b/launcher/minecraft/MinecraftUpdate.h index fadebff9b..a1df4b3f7 100644 --- a/launcher/minecraft/MinecraftUpdate.h +++ b/launcher/minecraft/MinecraftUpdate.h @@ -22,7 +22,7 @@ #include "net/NetJob.h" #include "tasks/Task.h" #include "minecraft/VersionFilterData.h" -#include +#include class MinecraftVersion; class MinecraftInstance; diff --git a/launcher/minecraft/World.cpp b/launcher/minecraft/World.cpp index a2b4dac7a..95892d433 100644 --- a/launcher/minecraft/World.cpp +++ b/launcher/minecraft/World.cpp @@ -26,9 +26,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include diff --git a/launcher/minecraft/launch/ExtractNatives.cpp b/launcher/minecraft/launch/ExtractNatives.cpp index 8cd439b10..744e7ac6a 100644 --- a/launcher/minecraft/launch/ExtractNatives.cpp +++ b/launcher/minecraft/launch/ExtractNatives.cpp @@ -17,8 +17,8 @@ #include #include -#include -#include +#include +#include #include "MMCZip.h" #include "FileSystem.h" #include diff --git a/launcher/minecraft/launch/ModMinecraftJar.cpp b/launcher/minecraft/launch/ModMinecraftJar.cpp index 93de9d59a..c8796f015 100644 --- a/launcher/minecraft/launch/ModMinecraftJar.cpp +++ b/launcher/minecraft/launch/ModMinecraftJar.cpp @@ -42,6 +42,7 @@ void ModMinecraftJar::executeTask() emitFailed(tr("Couldn't remove stale jar file: %1").arg(finalJarPath)); } + /* // create temporary modded jar, if needed auto components = m_inst->getPackProfile(); auto profile = components->getProfile(); @@ -53,12 +54,13 @@ void ModMinecraftJar::executeTask() mainJar->getApplicableFiles(currentSystem, jars, temp1, temp2, temp3, m_inst->getLocalLibraryPath()); auto sourceJarPath = jars[0]; if(!MMCZip::createModdedJar(sourceJarPath, finalJarPath, jarMods)) - { + { */ + // TODO: add back support for modded jar emitFailed(tr("Failed to create the custom Minecraft jar file.")); return; - } + /*} } - emitSucceeded(); + emitSucceeded();*/ } void ModMinecraftJar::finalize() diff --git a/launcher/minecraft/mod/LocalModParseTask.cpp b/launcher/minecraft/mod/LocalModParseTask.cpp index 8ac5885f8..fa3a45386 100644 --- a/launcher/minecraft/mod/LocalModParseTask.cpp +++ b/launcher/minecraft/mod/LocalModParseTask.cpp @@ -4,8 +4,8 @@ #include #include #include -#include -#include +#include +#include #include #include "settings/INIFile.h" diff --git a/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp b/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp index e5db512eb..30a610260 100644 --- a/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp +++ b/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp @@ -19,7 +19,7 @@ #include -#include +#include #include "MMCZip.h" #include "minecraft/OneSixVersionFormat.h" diff --git a/launcher/modplatform/legacy_ftb/PackInstallTask.h b/launcher/modplatform/legacy_ftb/PackInstallTask.h index 305635a1d..6797971c8 100644 --- a/launcher/modplatform/legacy_ftb/PackInstallTask.h +++ b/launcher/modplatform/legacy_ftb/PackInstallTask.h @@ -1,8 +1,8 @@ #pragma once #include "InstanceTask.h" #include "net/NetJob.h" -#include "quazip.h" -#include "quazipdir.h" +#include "QuaZip-Qt5-1.2/quazip/quazip.h" +#include "QuaZip-Qt5-1.2/quazip/quazipdir.h" #include "meta/Index.h" #include "meta/Version.h" #include "meta/VersionList.h" diff --git a/launcher/modplatform/technic/SingleZipPackInstallTask.h b/launcher/modplatform/technic/SingleZipPackInstallTask.h index 74f60941b..585941369 100644 --- a/launcher/modplatform/technic/SingleZipPackInstallTask.h +++ b/launcher/modplatform/technic/SingleZipPackInstallTask.h @@ -18,7 +18,7 @@ #include "InstanceTask.h" #include "net/NetJob.h" -#include "quazip.h" +#include "QuaZip-Qt5-1.2/quazip/quazip.h" #include #include diff --git a/launcher/modplatform/technic/TechnicPackProcessor.cpp b/launcher/modplatform/technic/TechnicPackProcessor.cpp index 52979b7c3..f5c011f5f 100644 --- a/launcher/modplatform/technic/TechnicPackProcessor.cpp +++ b/launcher/modplatform/technic/TechnicPackProcessor.cpp @@ -19,9 +19,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/launcher/ui/dialogs/ExportInstanceDialog.cpp b/launcher/ui/dialogs/ExportInstanceDialog.cpp index 1a1648751..59ae0a765 100644 --- a/launcher/ui/dialogs/ExportInstanceDialog.cpp +++ b/launcher/ui/dialogs/ExportInstanceDialog.cpp @@ -378,6 +378,7 @@ void SaveIcon(InstancePtr m_instance) bool ExportInstanceDialog::doExport() { + /* auto name = FS::RemoveInvalidFilenameChars(m_instance->name()); const QString output = QFileDialog::getSaveFileName( @@ -404,11 +405,11 @@ bool ExportInstanceDialog::doExport() auto & blocked = proxyModel->blockedPaths(); using std::placeholders::_1; if (!JlCompress::compressDir(output, m_instance->instanceRoot(), name, std::bind(&SeparatorPrefixTree<'/'>::covers, blocked, _1))) - { + { */ QMessageBox::warning(this, tr("Error"), tr("Unable to export instance")); return false; - } - return true; + /*} + return true;*/ } void ExportInstanceDialog::done(int result) diff --git a/libraries/classparser/src/classparser.cpp b/libraries/classparser/src/classparser.cpp index 8825ea399..a47d1aada 100644 --- a/libraries/classparser/src/classparser.cpp +++ b/libraries/classparser/src/classparser.cpp @@ -18,7 +18,7 @@ #include "classparser.h" #include -#include +#include #include namespace classparser diff --git a/libraries/quazip b/libraries/quazip deleted file mode 160000 index c9ef32de1..000000000 --- a/libraries/quazip +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c9ef32de19bceb58d236f5c22382698deaec69fd From 3aa809b8c0de48ca241ec567acda31ed1a728540 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 24 Jan 2022 22:55:57 +0100 Subject: [PATCH 2/8] refactor: add in-tree QuaZip --- .gitmodules | 4 +++ CMakeLists.txt | 30 ++++++++++++++----- launcher/CMakeLists.txt | 3 +- launcher/InstanceImportTask.cpp | 5 ++++ launcher/MMCZip.cpp | 7 ++++- launcher/MMCZip.h | 11 +++---- launcher/minecraft/MinecraftLoadAndCheck.h | 5 ++++ launcher/minecraft/MinecraftUpdate.h | 5 ++++ launcher/minecraft/World.cpp | 7 +++++ launcher/minecraft/launch/ExtractNatives.cpp | 6 ++++ launcher/minecraft/mod/LocalModParseTask.cpp | 7 +++++ .../atlauncher/ATLPackInstallTask.cpp | 4 +++ .../modplatform/legacy_ftb/PackInstallTask.h | 7 +++++ .../technic/SingleZipPackInstallTask.h | 4 +++ .../technic/TechnicPackProcessor.cpp | 8 +++++ libraries/classparser/CMakeLists.txt | 2 +- libraries/classparser/src/classparser.cpp | 6 ++++ libraries/quazip | 1 + 18 files changed, 106 insertions(+), 16 deletions(-) create mode 160000 libraries/quazip diff --git a/.gitmodules b/.gitmodules index cff268100..105752070 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,7 @@ path = libraries/libnbtplusplus url = https://github.com/MultiMC/libnbtplusplus.git pushurl = git@github.com:MultiMC/libnbtplusplus.git + +[submodule "libraries/quazip"] + path = libraries/quazip + url = https://github.com/stachenov/quazip.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 35deff044..2ebc0dfdd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,11 @@ set(Launcher_DISCORD_URL "https://discord.gg/Z52pwxWCHP" CACHE STRING "URL for t # Subreddit URL set(Launcher_SUBREDDIT_URL "" CACHE STRING "URL for the subreddit.") +# Builds +set(Launcher_FORCE_BUNDLED_LIBS OFF CACHE BOOL "Prevent using system libraries, if they are available as submodules") +set(Launcher_QT_VERSION_MAJOR "5" CACHE STRING "Major Qt version to build against") + + #### Check the current Git commit and branch include(GetGitRevisionDescription) get_git_head_revision(Launcher_GIT_REFSPEC Launcher_GIT_COMMIT) @@ -96,14 +101,19 @@ add_custom_target(tcversion echo "\\#\\#teamcity[setParameter name=\\'env.LAUNCH ################################ 3rd Party Libs ################################ # Find the required Qt parts -find_package(Qt5Core REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(Qt5Concurrent REQUIRED) -find_package(Qt5Network REQUIRED) -find_package(Qt5Test REQUIRED) -find_package(Qt5Xml REQUIRED) +set(QT_VERSION_MAJOR ${Launcher_QT_VERSION_MAJOR}) +find_package(Qt${QT_VERSION_MAJOR}Core REQUIRED) +find_package(Qt${QT_VERSION_MAJOR}Widgets REQUIRED) +find_package(Qt${QT_VERSION_MAJOR}Concurrent REQUIRED) +find_package(Qt${QT_VERSION_MAJOR}Network REQUIRED) +find_package(Qt${QT_VERSION_MAJOR}Test REQUIRED) +find_package(Qt${QT_VERSION_MAJOR}Xml REQUIRED) -find_package(QuaZip-Qt5 REQUIRED) +if (NOT Launcher_FORCE_BUNDLED_LIBS) + find_package(QuaZip-Qt${QT_VERSION_MAJOR} REQUIRED) +else() + MESSAGE(STATUS "Not looking for QuaZip via find_package") +endif() # The Qt5 cmake files don't provide its install paths, so ask qmake. include(QMakeQuery) @@ -251,6 +261,12 @@ add_subdirectory(libraries/hoedown) # markdown parser add_subdirectory(libraries/launcher) # java based launcher part for Minecraft add_subdirectory(libraries/javacheck) # java compatibility checker add_subdirectory(libraries/xz-embedded) # xz compression +if (NOT QuaZip-Qt${QT_VERSION_MAJOR}_FOUND) + set(QUAZIP_QT_MAJOR_VERSION ${QT_VERSION_MAJOR}) + add_compile_definitions(QUAZIP_USE_SUBMODULE) + MESSAGE(STATUS "Adding QuaZip submodule, with QT_VERSION_MAJOR ${QUAZIP_QT_MAJOR_VERSION}") + add_subdirectory(libraries/quazip) # zip manipulation library +endif() add_subdirectory(libraries/rainbow) # Qt extension for colors add_subdirectory(libraries/iconfix) # fork of Qt's QIcon loader add_subdirectory(libraries/LocalPeer) # fork of a library from Qt solutions diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 0ef27f6bd..c704563bd 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -899,7 +899,6 @@ endif() add_library(Launcher_logic STATIC ${LOGIC_SOURCES} ${LAUNCHER_SOURCES} ${LAUNCHER_UI} ${LAUNCHER_RESOURCES}) target_link_libraries(Launcher_logic systeminfo - Launcher_quazip Launcher_classparser ${NBT_NAME} ${ZLIB_LIBRARIES} @@ -917,7 +916,7 @@ target_link_libraries(Launcher_logic ) target_link_libraries(Launcher_logic Launcher_iconfix - ${QUAZIP_LIBRARIES} + QuaZip::QuaZip hoedown Launcher_rainbow LocalPeer diff --git a/launcher/InstanceImportTask.cpp b/launcher/InstanceImportTask.cpp index 6e2dd912a..8aab91c50 100644 --- a/launcher/InstanceImportTask.cpp +++ b/launcher/InstanceImportTask.cpp @@ -29,7 +29,12 @@ #include "modplatform/flame/FileResolvingTask.h" #include "modplatform/flame/PackManifest.h" #include "Json.h" + +#ifdef QUAZIP_USE_SUBMODULE +#include +#else #include +#endif #include "modplatform/technic/TechnicPackProcessor.h" #include "icons/IconList.h" diff --git a/launcher/MMCZip.cpp b/launcher/MMCZip.cpp index e1906a0c7..74c9b388d 100644 --- a/launcher/MMCZip.cpp +++ b/launcher/MMCZip.cpp @@ -12,10 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#ifdef QUAZIP_USE_SUBMODULE +#include +#include +#include +#else #include #include #include +#endif #include "MMCZip.h" #include "FileSystem.h" diff --git a/launcher/MMCZip.h b/launcher/MMCZip.h index 5260f8566..5983aa37c 100644 --- a/launcher/MMCZip.h +++ b/launcher/MMCZip.h @@ -19,13 +19,14 @@ #include #include #include "minecraft/mod/Mod.h" +#include "nonstd/optional" #include -//#include -// TODO: Blocked by https://github.com/stachenov/quazip/pull/141 -// For now, checkout https://github.com/Scrumplex/quazip/tree/expose-jlcompress-fns at ../../quazip -#include <../../quazip/quazip/JlCompress.h> -#include +#ifdef QUAZIP_USE_SUBMODULE +#include +#else +#include +#endif namespace MMCZip { diff --git a/launcher/minecraft/MinecraftLoadAndCheck.h b/launcher/minecraft/MinecraftLoadAndCheck.h index 4e673a4bf..1aeb79f82 100644 --- a/launcher/minecraft/MinecraftLoadAndCheck.h +++ b/launcher/minecraft/MinecraftLoadAndCheck.h @@ -20,7 +20,12 @@ #include #include "tasks/Task.h" + +#ifdef QUAZIP_USE_SUBMODULE +#include +#else #include +#endif #include "QObjectPtr.h" diff --git a/launcher/minecraft/MinecraftUpdate.h b/launcher/minecraft/MinecraftUpdate.h index a1df4b3f7..36c4310b8 100644 --- a/launcher/minecraft/MinecraftUpdate.h +++ b/launcher/minecraft/MinecraftUpdate.h @@ -22,7 +22,12 @@ #include "net/NetJob.h" #include "tasks/Task.h" #include "minecraft/VersionFilterData.h" + +#ifdef QUAZIP_USE_SUBMODULE +#include +#else #include +#endif class MinecraftVersion; class MinecraftInstance; diff --git a/launcher/minecraft/World.cpp b/launcher/minecraft/World.cpp index 95892d433..8fd77919b 100644 --- a/launcher/minecraft/World.cpp +++ b/launcher/minecraft/World.cpp @@ -26,9 +26,16 @@ #include #include #include + +#ifdef QUAZIP_USE_SUBMODULE +#include +#include +#include +#else #include #include #include +#endif #include diff --git a/launcher/minecraft/launch/ExtractNatives.cpp b/launcher/minecraft/launch/ExtractNatives.cpp index 744e7ac6a..5f13f7301 100644 --- a/launcher/minecraft/launch/ExtractNatives.cpp +++ b/launcher/minecraft/launch/ExtractNatives.cpp @@ -17,8 +17,14 @@ #include #include +#ifdef QUAZIP_USE_SUBMODULE +#include +#include +#else #include #include +#endif + #include "MMCZip.h" #include "FileSystem.h" #include diff --git a/launcher/minecraft/mod/LocalModParseTask.cpp b/launcher/minecraft/mod/LocalModParseTask.cpp index fa3a45386..651b96ac8 100644 --- a/launcher/minecraft/mod/LocalModParseTask.cpp +++ b/launcher/minecraft/mod/LocalModParseTask.cpp @@ -4,8 +4,15 @@ #include #include #include + +#ifdef QUAZIP_USE_SUBMODULE +#include +#include +#else #include #include +#endif + #include #include "settings/INIFile.h" diff --git a/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp b/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp index 30a610260..c4f4b96f1 100644 --- a/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp +++ b/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp @@ -19,7 +19,11 @@ #include +#ifdef QUAZIP_USE_SUBMODULE +#include +#else #include +#endif #include "MMCZip.h" #include "minecraft/OneSixVersionFormat.h" diff --git a/launcher/modplatform/legacy_ftb/PackInstallTask.h b/launcher/modplatform/legacy_ftb/PackInstallTask.h index 6797971c8..2cdfee7a0 100644 --- a/launcher/modplatform/legacy_ftb/PackInstallTask.h +++ b/launcher/modplatform/legacy_ftb/PackInstallTask.h @@ -1,8 +1,15 @@ #pragma once #include "InstanceTask.h" #include "net/NetJob.h" + +#ifdef QUAZIP_USE_SUBMODULE +#include +#include +#else #include "QuaZip-Qt5-1.2/quazip/quazip.h" #include "QuaZip-Qt5-1.2/quazip/quazipdir.h" +#endif + #include "meta/Index.h" #include "meta/Version.h" #include "meta/VersionList.h" diff --git a/launcher/modplatform/technic/SingleZipPackInstallTask.h b/launcher/modplatform/technic/SingleZipPackInstallTask.h index 585941369..d3bdc00be 100644 --- a/launcher/modplatform/technic/SingleZipPackInstallTask.h +++ b/launcher/modplatform/technic/SingleZipPackInstallTask.h @@ -18,7 +18,11 @@ #include "InstanceTask.h" #include "net/NetJob.h" +#ifdef QUAZIP_USE_SUBMODULE +#include +#else #include "QuaZip-Qt5-1.2/quazip/quazip.h" +#endif #include #include diff --git a/launcher/modplatform/technic/TechnicPackProcessor.cpp b/launcher/modplatform/technic/TechnicPackProcessor.cpp index f5c011f5f..a8b4d05b0 100644 --- a/launcher/modplatform/technic/TechnicPackProcessor.cpp +++ b/launcher/modplatform/technic/TechnicPackProcessor.cpp @@ -19,9 +19,17 @@ #include #include #include + +#ifdef QUAZIP_USE_SUBMODULE +#include +#include +#include +#else #include #include #include +#endif + #include #include diff --git a/libraries/classparser/CMakeLists.txt b/libraries/classparser/CMakeLists.txt index c07e871c0..fc510e686 100644 --- a/libraries/classparser/CMakeLists.txt +++ b/libraries/classparser/CMakeLists.txt @@ -38,4 +38,4 @@ add_definitions(-DCLASSPARSER_LIBRARY) add_library(Launcher_classparser STATIC ${CLASSPARSER_SOURCES} ${CLASSPARSER_HEADERS}) target_include_directories(Launcher_classparser PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") -target_link_libraries(Launcher_classparser Launcher_quazip Qt5::Core) +target_link_libraries(Launcher_classparser QuaZip::QuaZip Qt5::Core) diff --git a/libraries/classparser/src/classparser.cpp b/libraries/classparser/src/classparser.cpp index a47d1aada..b7612a416 100644 --- a/libraries/classparser/src/classparser.cpp +++ b/libraries/classparser/src/classparser.cpp @@ -18,7 +18,13 @@ #include "classparser.h" #include + +#ifdef QUAZIP_USE_SUBMODULE +#include +#else #include +#endif + #include namespace classparser diff --git a/libraries/quazip b/libraries/quazip new file mode 160000 index 000000000..09ec1d10c --- /dev/null +++ b/libraries/quazip @@ -0,0 +1 @@ +Subproject commit 09ec1d10c6d627f895109b21728dda000cbfa7d1 From 81c72c2038f35e744e038923105d91add5a0732c Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 24 Jan 2022 23:02:06 +0100 Subject: [PATCH 3/8] refactor: bring back methods that need to be reimplemented --- launcher/MMCZip.cpp | 95 +++++++++++++++++++ launcher/minecraft/launch/ModMinecraftJar.cpp | 8 +- launcher/ui/dialogs/ExportInstanceDialog.cpp | 10 +- 3 files changed, 104 insertions(+), 9 deletions(-) diff --git a/launcher/MMCZip.cpp b/launcher/MMCZip.cpp index 74c9b388d..36562b062 100644 --- a/launcher/MMCZip.cpp +++ b/launcher/MMCZip.cpp @@ -78,6 +78,101 @@ bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet &containe return true; } +// ours +bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const QList& mods) +{ + QuaZip zipOut(targetJarPath); + if (!zipOut.open(QuaZip::mdCreate)) + { + QFile::remove(targetJarPath); + qCritical() << "Failed to open the minecraft.jar for modding"; + return false; + } + // Files already added to the jar. + // These files will be skipped. + QSet addedFiles; + + // Modify the jar + QListIterator i(mods); + i.toBack(); + while (i.hasPrevious()) + { + const Mod &mod = i.previous(); + // do not merge disabled mods. + if (!mod.enabled()) + continue; + if (mod.type() == Mod::MOD_ZIPFILE) + { + if (!mergeZipFiles(&zipOut, mod.filename(), addedFiles)) + { + zipOut.close(); + QFile::remove(targetJarPath); + qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar."; + return false; + } + } + else if (mod.type() == Mod::MOD_SINGLEFILE) + { + // FIXME: buggy - does not work with addedFiles + auto filename = mod.filename(); + if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName())) + { + zipOut.close(); + QFile::remove(targetJarPath); + qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar."; + return false; + } + addedFiles.insert(filename.fileName()); + } + else if (mod.type() == Mod::MOD_FOLDER) + { + // FIXME: buggy - does not work with addedFiles + auto filename = mod.filename(); + QString what_to_zip = filename.absoluteFilePath(); + QDir dir(what_to_zip); + dir.cdUp(); + QString parent_dir = dir.absolutePath(); + return false; + // TODO: implement custom compressSubDir: + if (!JlCompress::compressSubDir(&zipOut, what_to_zip, parent_dir, addedFiles)) + { + zipOut.close(); + QFile::remove(targetJarPath); + qCritical() << "Failed to add" << mod.filename().fileName() << "to the jar."; + return false; + } + 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); + qCritical() << "Failed to add unknown mod type" << mod.filename().fileName() << "to the jar."; + return false; + } + } + + 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."; + return false; + } + + // Recompress the jar + zipOut.close(); + if (zipOut.getZipError() != 0) + { + QFile::remove(targetJarPath); + qCritical() << "Failed to finalize minecraft.jar!"; + return false; + } + return true; +} + // ours QString MMCZip::findFolderOfFileInZip(QuaZip * zip, const QString & what, const QString &root) { diff --git a/launcher/minecraft/launch/ModMinecraftJar.cpp b/launcher/minecraft/launch/ModMinecraftJar.cpp index c8796f015..93de9d59a 100644 --- a/launcher/minecraft/launch/ModMinecraftJar.cpp +++ b/launcher/minecraft/launch/ModMinecraftJar.cpp @@ -42,7 +42,6 @@ void ModMinecraftJar::executeTask() emitFailed(tr("Couldn't remove stale jar file: %1").arg(finalJarPath)); } - /* // create temporary modded jar, if needed auto components = m_inst->getPackProfile(); auto profile = components->getProfile(); @@ -54,13 +53,12 @@ void ModMinecraftJar::executeTask() mainJar->getApplicableFiles(currentSystem, jars, temp1, temp2, temp3, m_inst->getLocalLibraryPath()); auto sourceJarPath = jars[0]; if(!MMCZip::createModdedJar(sourceJarPath, finalJarPath, jarMods)) - { */ - // TODO: add back support for modded jar + { emitFailed(tr("Failed to create the custom Minecraft jar file.")); return; - /*} + } } - emitSucceeded();*/ + emitSucceeded(); } void ModMinecraftJar::finalize() diff --git a/launcher/ui/dialogs/ExportInstanceDialog.cpp b/launcher/ui/dialogs/ExportInstanceDialog.cpp index 59ae0a765..fb9c65426 100644 --- a/launcher/ui/dialogs/ExportInstanceDialog.cpp +++ b/launcher/ui/dialogs/ExportInstanceDialog.cpp @@ -378,7 +378,6 @@ void SaveIcon(InstancePtr m_instance) bool ExportInstanceDialog::doExport() { - /* auto name = FS::RemoveInvalidFilenameChars(m_instance->name()); const QString output = QFileDialog::getSaveFileName( @@ -404,12 +403,15 @@ bool ExportInstanceDialog::doExport() auto & blocked = proxyModel->blockedPaths(); using std::placeholders::_1; + QMessageBox::warning(this, tr("Error"), tr("Unable to export instance")); + return false; + // TODO Reimplement custom compressDir: if (!JlCompress::compressDir(output, m_instance->instanceRoot(), name, std::bind(&SeparatorPrefixTree<'/'>::covers, blocked, _1))) - { */ + { QMessageBox::warning(this, tr("Error"), tr("Unable to export instance")); return false; - /*} - return true;*/ + } + return true; } void ExportInstanceDialog::done(int result) From 0442b80a2c0a7d99fa8b7df5d64c1ddfc676f251 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Tue, 25 Jan 2022 12:53:33 +0100 Subject: [PATCH 4/8] refactor: simpler includes for quazip --- CMakeLists.txt | 1 - launcher/InstanceImportTask.cpp | 5 ----- launcher/MMCZip.cpp | 7 +------ launcher/MMCZip.h | 6 +----- launcher/minecraft/MinecraftLoadAndCheck.h | 5 ----- launcher/minecraft/MinecraftUpdate.h | 5 ----- launcher/minecraft/World.cpp | 7 ------- launcher/minecraft/launch/ExtractNatives.cpp | 6 ------ launcher/minecraft/mod/LocalModParseTask.cpp | 7 ------- launcher/modplatform/atlauncher/ATLPackInstallTask.cpp | 4 ---- launcher/modplatform/legacy_ftb/PackInstallTask.h | 7 ------- launcher/modplatform/technic/SingleZipPackInstallTask.h | 4 ---- launcher/modplatform/technic/TechnicPackProcessor.cpp | 8 -------- libraries/classparser/src/classparser.cpp | 6 ------ 14 files changed, 2 insertions(+), 76 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ebc0dfdd..ab39e83c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,7 +263,6 @@ add_subdirectory(libraries/javacheck) # java compatibility checker add_subdirectory(libraries/xz-embedded) # xz compression if (NOT QuaZip-Qt${QT_VERSION_MAJOR}_FOUND) set(QUAZIP_QT_MAJOR_VERSION ${QT_VERSION_MAJOR}) - add_compile_definitions(QUAZIP_USE_SUBMODULE) MESSAGE(STATUS "Adding QuaZip submodule, with QT_VERSION_MAJOR ${QUAZIP_QT_MAJOR_VERSION}") add_subdirectory(libraries/quazip) # zip manipulation library endif() diff --git a/launcher/InstanceImportTask.cpp b/launcher/InstanceImportTask.cpp index 8aab91c50..ec378538a 100644 --- a/launcher/InstanceImportTask.cpp +++ b/launcher/InstanceImportTask.cpp @@ -29,12 +29,7 @@ #include "modplatform/flame/FileResolvingTask.h" #include "modplatform/flame/PackManifest.h" #include "Json.h" - -#ifdef QUAZIP_USE_SUBMODULE #include -#else -#include -#endif #include "modplatform/technic/TechnicPackProcessor.h" #include "icons/IconList.h" diff --git a/launcher/MMCZip.cpp b/launcher/MMCZip.cpp index 36562b062..9b8b79082 100644 --- a/launcher/MMCZip.cpp +++ b/launcher/MMCZip.cpp @@ -12,15 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifdef QUAZIP_USE_SUBMODULE + #include #include #include -#else -#include -#include -#include -#endif #include "MMCZip.h" #include "FileSystem.h" diff --git a/launcher/MMCZip.h b/launcher/MMCZip.h index 5983aa37c..c8e830ab3 100644 --- a/launcher/MMCZip.h +++ b/launcher/MMCZip.h @@ -19,14 +19,10 @@ #include #include #include "minecraft/mod/Mod.h" -#include "nonstd/optional" #include -#ifdef QUAZIP_USE_SUBMODULE #include -#else -#include -#endif +#include namespace MMCZip { diff --git a/launcher/minecraft/MinecraftLoadAndCheck.h b/launcher/minecraft/MinecraftLoadAndCheck.h index 1aeb79f82..d9af3ace2 100644 --- a/launcher/minecraft/MinecraftLoadAndCheck.h +++ b/launcher/minecraft/MinecraftLoadAndCheck.h @@ -20,12 +20,7 @@ #include #include "tasks/Task.h" - -#ifdef QUAZIP_USE_SUBMODULE #include -#else -#include -#endif #include "QObjectPtr.h" diff --git a/launcher/minecraft/MinecraftUpdate.h b/launcher/minecraft/MinecraftUpdate.h index 36c4310b8..9ebef6569 100644 --- a/launcher/minecraft/MinecraftUpdate.h +++ b/launcher/minecraft/MinecraftUpdate.h @@ -22,12 +22,7 @@ #include "net/NetJob.h" #include "tasks/Task.h" #include "minecraft/VersionFilterData.h" - -#ifdef QUAZIP_USE_SUBMODULE #include -#else -#include -#endif class MinecraftVersion; class MinecraftInstance; diff --git a/launcher/minecraft/World.cpp b/launcher/minecraft/World.cpp index 8fd77919b..2937c116d 100644 --- a/launcher/minecraft/World.cpp +++ b/launcher/minecraft/World.cpp @@ -26,16 +26,9 @@ #include #include #include - -#ifdef QUAZIP_USE_SUBMODULE #include #include #include -#else -#include -#include -#include -#endif #include diff --git a/launcher/minecraft/launch/ExtractNatives.cpp b/launcher/minecraft/launch/ExtractNatives.cpp index 5f13f7301..7d5f41791 100644 --- a/launcher/minecraft/launch/ExtractNatives.cpp +++ b/launcher/minecraft/launch/ExtractNatives.cpp @@ -17,14 +17,8 @@ #include #include -#ifdef QUAZIP_USE_SUBMODULE #include #include -#else -#include -#include -#endif - #include "MMCZip.h" #include "FileSystem.h" #include diff --git a/launcher/minecraft/mod/LocalModParseTask.cpp b/launcher/minecraft/mod/LocalModParseTask.cpp index 651b96ac8..757a21874 100644 --- a/launcher/minecraft/mod/LocalModParseTask.cpp +++ b/launcher/minecraft/mod/LocalModParseTask.cpp @@ -4,15 +4,8 @@ #include #include #include - -#ifdef QUAZIP_USE_SUBMODULE #include #include -#else -#include -#include -#endif - #include #include "settings/INIFile.h" diff --git a/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp b/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp index c4f4b96f1..8de5fc9f5 100644 --- a/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp +++ b/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp @@ -19,11 +19,7 @@ #include -#ifdef QUAZIP_USE_SUBMODULE #include -#else -#include -#endif #include "MMCZip.h" #include "minecraft/OneSixVersionFormat.h" diff --git a/launcher/modplatform/legacy_ftb/PackInstallTask.h b/launcher/modplatform/legacy_ftb/PackInstallTask.h index 2cdfee7a0..a73952209 100644 --- a/launcher/modplatform/legacy_ftb/PackInstallTask.h +++ b/launcher/modplatform/legacy_ftb/PackInstallTask.h @@ -1,15 +1,8 @@ #pragma once #include "InstanceTask.h" #include "net/NetJob.h" - -#ifdef QUAZIP_USE_SUBMODULE #include #include -#else -#include "QuaZip-Qt5-1.2/quazip/quazip.h" -#include "QuaZip-Qt5-1.2/quazip/quazipdir.h" -#endif - #include "meta/Index.h" #include "meta/Version.h" #include "meta/VersionList.h" diff --git a/launcher/modplatform/technic/SingleZipPackInstallTask.h b/launcher/modplatform/technic/SingleZipPackInstallTask.h index d3bdc00be..4d1fcbff0 100644 --- a/launcher/modplatform/technic/SingleZipPackInstallTask.h +++ b/launcher/modplatform/technic/SingleZipPackInstallTask.h @@ -18,11 +18,7 @@ #include "InstanceTask.h" #include "net/NetJob.h" -#ifdef QUAZIP_USE_SUBMODULE #include -#else -#include "QuaZip-Qt5-1.2/quazip/quazip.h" -#endif #include #include diff --git a/launcher/modplatform/technic/TechnicPackProcessor.cpp b/launcher/modplatform/technic/TechnicPackProcessor.cpp index a8b4d05b0..c45061acc 100644 --- a/launcher/modplatform/technic/TechnicPackProcessor.cpp +++ b/launcher/modplatform/technic/TechnicPackProcessor.cpp @@ -19,17 +19,9 @@ #include #include #include - -#ifdef QUAZIP_USE_SUBMODULE #include #include #include -#else -#include -#include -#include -#endif - #include #include diff --git a/libraries/classparser/src/classparser.cpp b/libraries/classparser/src/classparser.cpp index b7612a416..601521f68 100644 --- a/libraries/classparser/src/classparser.cpp +++ b/libraries/classparser/src/classparser.cpp @@ -18,13 +18,7 @@ #include "classparser.h" #include - -#ifdef QUAZIP_USE_SUBMODULE #include -#else -#include -#endif - #include namespace classparser From 88686ef06515e9aacabf0ad0cafdba30ad47c85a Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 27 Jan 2022 12:52:12 +0100 Subject: [PATCH 5/8] refactor: restructure CMake to support future Qt versions --- CMakeLists.txt | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab39e83c2..707268f40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,18 +101,19 @@ add_custom_target(tcversion echo "\\#\\#teamcity[setParameter name=\\'env.LAUNCH ################################ 3rd Party Libs ################################ # Find the required Qt parts -set(QT_VERSION_MAJOR ${Launcher_QT_VERSION_MAJOR}) -find_package(Qt${QT_VERSION_MAJOR}Core REQUIRED) -find_package(Qt${QT_VERSION_MAJOR}Widgets REQUIRED) -find_package(Qt${QT_VERSION_MAJOR}Concurrent REQUIRED) -find_package(Qt${QT_VERSION_MAJOR}Network REQUIRED) -find_package(Qt${QT_VERSION_MAJOR}Test REQUIRED) -find_package(Qt${QT_VERSION_MAJOR}Xml REQUIRED) +if(Launcher_QT_VERSION_MAJOR EQUAL 5) + set(QT_VERSION_MAJOR 5) + find_package(Qt5 REQUIRED COMPONENTS Core Widgets Concurrent Network Test Xml) -if (NOT Launcher_FORCE_BUNDLED_LIBS) - find_package(QuaZip-Qt${QT_VERSION_MAJOR} REQUIRED) + if(NOT Launcher_FORCE_BUNDLED_LIBS) + find_package(QuaZip-Qt5 REQUIRED) + endif() + if (NOT QuaZip-Qt5_FOUND) + set(QUAZIP_QT_MAJOR_VERSION ${QT_VERSION_MAJOR} CACHE STRING "Qt version to use (4, 5 or 6), defaults to ${QT_VERSION_MAJOR}" FORCE) + set(FORCE_BUNDLED_QUAZIP 1) + endif() else() - MESSAGE(STATUS "Not looking for QuaZip via find_package") + message(FATAL_ERROR "Qt version ${Launcher_QT_VERSION_MAJOR} is not supported") endif() # The Qt5 cmake files don't provide its install paths, so ask qmake. @@ -261,9 +262,8 @@ add_subdirectory(libraries/hoedown) # markdown parser add_subdirectory(libraries/launcher) # java based launcher part for Minecraft add_subdirectory(libraries/javacheck) # java compatibility checker add_subdirectory(libraries/xz-embedded) # xz compression -if (NOT QuaZip-Qt${QT_VERSION_MAJOR}_FOUND) - set(QUAZIP_QT_MAJOR_VERSION ${QT_VERSION_MAJOR}) - MESSAGE(STATUS "Adding QuaZip submodule, with QT_VERSION_MAJOR ${QUAZIP_QT_MAJOR_VERSION}") +if (FORCE_BUNDLED_QUAZIP) + message(STATUS "Using bundled QuaZip") add_subdirectory(libraries/quazip) # zip manipulation library endif() add_subdirectory(libraries/rainbow) # Qt extension for colors From 71516e6c728a6b7429c04f297f6b0f3710bfa3c3 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 27 Jan 2022 12:52:58 +0100 Subject: [PATCH 6/8] fix: set Launcher_FORCE_BUNDLED_LIBS=on by default We need to wait for a new QuaZip release to become widely available, until we can turn this off again --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 707268f40..c4e7046aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,8 @@ set(Launcher_DISCORD_URL "https://discord.gg/Z52pwxWCHP" CACHE STRING "URL for t set(Launcher_SUBREDDIT_URL "" CACHE STRING "URL for the subreddit.") # Builds -set(Launcher_FORCE_BUNDLED_LIBS OFF CACHE BOOL "Prevent using system libraries, if they are available as submodules") +# TODO: Launcher_FORCE_BUNDLED_LIBS should be off in the future, but as of QuaZip 1.2, we can't do that yet. +set(Launcher_FORCE_BUNDLED_LIBS ON CACHE BOOL "Prevent using system libraries, if they are available as submodules") set(Launcher_QT_VERSION_MAJOR "5" CACHE STRING "Major Qt version to build against") From a8089b76c0e7961e31b96cdd203e3c345183645b Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Fri, 28 Jan 2022 12:37:22 +0100 Subject: [PATCH 7/8] fix: bring back instance exports --- launcher/MMCZip.cpp | 60 ++++++++++++++++++++ launcher/MMCZip.h | 18 ++++++ launcher/ui/dialogs/ExportInstanceDialog.cpp | 11 ++-- 3 files changed, 85 insertions(+), 4 deletions(-) diff --git a/launcher/MMCZip.cpp b/launcher/MMCZip.cpp index 9b8b79082..90e586d87 100644 --- a/launcher/MMCZip.cpp +++ b/launcher/MMCZip.cpp @@ -311,3 +311,63 @@ bool MMCZip::extractFile(QString fileCompressed, QString file, QString target) } return MMCZip::extractRelFile(&zip, file, target); } + +bool MMCZip::collectFileListRecursively(const QString& rootDir, const QString& subDir, QFileInfoList *files, + MMCZip::FilterFunction excludeFilter) { + QDir rootDirectory(rootDir); + if (!rootDirectory.exists()) return false; + + QDir directory; + if (subDir == nullptr) + directory = rootDirectory; + else + directory = QDir(subDir); + + if (!directory.exists()) return false; // shouldn't ever happen + + // recurse directories + QFileInfoList entries = directory.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Hidden); + for (const auto& e: entries) { + if (!collectFileListRecursively(rootDir, e.filePath(), files, excludeFilter)) + return false; + } + + // collect files + entries = directory.entryInfoList(QDir::Files); + for (const auto& e: entries) { + QString relativeFilePath = rootDirectory.relativeFilePath(e.absoluteFilePath()); + if (excludeFilter && excludeFilter(relativeFilePath)) { + qDebug() << "Skipping file " << relativeFilePath; + continue; + } + + files->append(e.filePath()); // we want the original paths for MMCZip::compressDirFiles + } + return true; +} + +bool MMCZip::compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files) +{ + QuaZip zip(fileCompressed); + QDir().mkpath(QFileInfo(fileCompressed).absolutePath()); + if(!zip.open(QuaZip::mdCreate)) { + QFile::remove(fileCompressed); + return false; + } + + QDir directory(dir); + if (!directory.exists()) return false; + + for (auto e : files) { + auto filePath = directory.relativeFilePath(e.absoluteFilePath()); + if( !JlCompress::compressFile(&zip, e.absoluteFilePath(), filePath)) return false; + } + + zip.close(); + if(zip.getZipError()!=0) { + QFile::remove(fileCompressed); + return false; + } + + return true; +} diff --git a/launcher/MMCZip.h b/launcher/MMCZip.h index c8e830ab3..29ae2a63c 100644 --- a/launcher/MMCZip.h +++ b/launcher/MMCZip.h @@ -90,4 +90,22 @@ namespace MMCZip */ bool extractFile(QString fileCompressed, QString file, QString dir); + /** + * Populate a QFileInfoList with a directory tree recursively, while allowing to excludeFilter what shouldn't be included. + * \param rootDir directory to start off + * \param subDir subdirectory, should be nullptr for first invocation + * \param files resulting list of QFileInfo + * \param excludeFilter function to excludeFilter which files shouldn't be included (returning true means to excude) + * \return true for success or false for failure + */ + bool collectFileListRecursively(const QString &rootDir, const QString &subDir, QFileInfoList *files, FilterFunction excludeFilter); + + /** + * Compress directory, by providing a list of files to compress + * \param fileCompressed target archive file + * \param dir directory that will be compressed (to compress with relative paths) + * \param files list of files to compress + * \return true for success or false for failure + */ + bool compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files); } diff --git a/launcher/ui/dialogs/ExportInstanceDialog.cpp b/launcher/ui/dialogs/ExportInstanceDialog.cpp index fb9c65426..f3bf7abe9 100644 --- a/launcher/ui/dialogs/ExportInstanceDialog.cpp +++ b/launcher/ui/dialogs/ExportInstanceDialog.cpp @@ -403,10 +403,13 @@ bool ExportInstanceDialog::doExport() auto & blocked = proxyModel->blockedPaths(); using std::placeholders::_1; - QMessageBox::warning(this, tr("Error"), tr("Unable to export instance")); - return false; - // TODO Reimplement custom compressDir: - if (!JlCompress::compressDir(output, m_instance->instanceRoot(), name, std::bind(&SeparatorPrefixTree<'/'>::covers, blocked, _1))) + auto files = QFileInfoList(); + if (!MMCZip::collectFileListRecursively(m_instance->instanceRoot(), nullptr, &files, + std::bind(&SeparatorPrefixTree<'/'>::covers, blocked, _1))) { + QMessageBox::warning(this, tr("Error"), tr("Unable to export instance")); + return false; + } + if (!MMCZip::compressDirFiles(output, m_instance->instanceRoot(), files)) { QMessageBox::warning(this, tr("Error"), tr("Unable to export instance")); return false; From c4cb7ddc4f9c06006d585ba7ff7405ac0cfdbb3c Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Fri, 28 Jan 2022 13:26:59 +0100 Subject: [PATCH 8/8] fix: bring back JAR Folder mods what is this? --- launcher/MMCZip.cpp | 72 +++++++++++++++++++++++++++------------------ launcher/MMCZip.h | 27 +++++++++++------ 2 files changed, 61 insertions(+), 38 deletions(-) diff --git a/launcher/MMCZip.cpp b/launcher/MMCZip.cpp index 90e586d87..9d7e4cc2e 100644 --- a/launcher/MMCZip.cpp +++ b/launcher/MMCZip.cpp @@ -73,6 +73,39 @@ bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet &containe return true; } +bool MMCZip::compressDirFiles(QuaZip *zip, QString dir, QFileInfoList files) +{ + QDir directory(dir); + if (!directory.exists()) return false; + + for (auto e : files) { + auto filePath = directory.relativeFilePath(e.absoluteFilePath()); + if( !JlCompress::compressFile(zip, e.absoluteFilePath(), filePath)) return false; + } + + return true; +} + +bool MMCZip::compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files) +{ + QuaZip zip(fileCompressed); + QDir().mkpath(QFileInfo(fileCompressed).absolutePath()); + if(!zip.open(QuaZip::mdCreate)) { + QFile::remove(fileCompressed); + return false; + } + + auto result = compressDirFiles(&zip, dir, files); + + zip.close(); + if(zip.getZipError()!=0) { + QFile::remove(fileCompressed); + return false; + } + + return result; +} + // ours bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const QList& mods) { @@ -121,15 +154,22 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const } else if (mod.type() == Mod::MOD_FOLDER) { + // untested, but seems to be unused / not possible to reach // FIXME: buggy - does not work with addedFiles auto filename = mod.filename(); QString what_to_zip = filename.absoluteFilePath(); QDir dir(what_to_zip); dir.cdUp(); QString parent_dir = dir.absolutePath(); - return false; - // TODO: implement custom compressSubDir: - if (!JlCompress::compressSubDir(&zipOut, what_to_zip, parent_dir, addedFiles)) + auto files = QFileInfoList(); + MMCZip::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)) { zipOut.close(); QFile::remove(targetJarPath); @@ -345,29 +385,3 @@ bool MMCZip::collectFileListRecursively(const QString& rootDir, const QString& s } return true; } - -bool MMCZip::compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files) -{ - QuaZip zip(fileCompressed); - QDir().mkpath(QFileInfo(fileCompressed).absolutePath()); - if(!zip.open(QuaZip::mdCreate)) { - QFile::remove(fileCompressed); - return false; - } - - QDir directory(dir); - if (!directory.exists()) return false; - - for (auto e : files) { - auto filePath = directory.relativeFilePath(e.absoluteFilePath()); - if( !JlCompress::compressFile(&zip, e.absoluteFilePath(), filePath)) return false; - } - - zip.close(); - if(zip.getZipError()!=0) { - QFile::remove(fileCompressed); - return false; - } - - return true; -} diff --git a/launcher/MMCZip.h b/launcher/MMCZip.h index 29ae2a63c..0f7aa254f 100644 --- a/launcher/MMCZip.h +++ b/launcher/MMCZip.h @@ -34,6 +34,24 @@ namespace MMCZip bool mergeZipFiles(QuaZip *into, QFileInfo from, QSet &contained, const FilterFunction filter = nullptr); + /** + * Compress directory, by providing a list of files to compress + * \param zip target archive + * \param dir directory that will be compressed (to compress with relative paths) + * \param files list of files to compress + * \return true for success or false for failure + */ + bool compressDirFiles(QuaZip *zip, QString dir, QFileInfoList files); + + /** + * Compress directory, by providing a list of files to compress + * \param fileCompressed target archive file + * \param dir directory that will be compressed (to compress with relative paths) + * \param files list of files to compress + * \return true for success or false for failure + */ + bool compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files); + /** * take a source jar, add mods to it, resulting in target jar */ @@ -99,13 +117,4 @@ namespace MMCZip * \return true for success or false for failure */ bool collectFileListRecursively(const QString &rootDir, const QString &subDir, QFileInfoList *files, FilterFunction excludeFilter); - - /** - * Compress directory, by providing a list of files to compress - * \param fileCompressed target archive file - * \param dir directory that will be compressed (to compress with relative paths) - * \param files list of files to compress - * \return true for success or false for failure - */ - bool compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files); }