diff options
author | Sefa Eyeoglu <contact@scrumplex.net> | 2022-01-28 13:26:59 +0100 |
---|---|---|
committer | Sefa Eyeoglu <contact@scrumplex.net> | 2022-01-31 21:40:59 +0100 |
commit | c4cb7ddc4f9c06006d585ba7ff7405ac0cfdbb3c (patch) | |
tree | 86b6868c6f660bda4655fefc4c7958a320e23618 /launcher/MMCZip.cpp | |
parent | a8089b76c0e7961e31b96cdd203e3c345183645b (diff) | |
download | PrismLauncher-c4cb7ddc4f9c06006d585ba7ff7405ac0cfdbb3c.tar.gz PrismLauncher-c4cb7ddc4f9c06006d585ba7ff7405ac0cfdbb3c.tar.bz2 PrismLauncher-c4cb7ddc4f9c06006d585ba7ff7405ac0cfdbb3c.zip |
fix: bring back JAR Folder mods
what is this?
Diffstat (limited to 'launcher/MMCZip.cpp')
-rw-r--r-- | launcher/MMCZip.cpp | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/launcher/MMCZip.cpp b/launcher/MMCZip.cpp index 90e586d8..9d7e4cc2 100644 --- a/launcher/MMCZip.cpp +++ b/launcher/MMCZip.cpp @@ -73,6 +73,39 @@ bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &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<Mod>& 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; -} |