diff options
author | Sefa Eyeoglu <contact@scrumplex.net> | 2022-01-28 12:37:22 +0100 |
---|---|---|
committer | Sefa Eyeoglu <contact@scrumplex.net> | 2022-01-31 21:40:59 +0100 |
commit | a8089b76c0e7961e31b96cdd203e3c345183645b (patch) | |
tree | 973a74a6d2cfe0222e1dddcdbf6c706e7794d0e0 /launcher/MMCZip.cpp | |
parent | 71516e6c728a6b7429c04f297f6b0f3710bfa3c3 (diff) | |
download | PrismLauncher-a8089b76c0e7961e31b96cdd203e3c345183645b.tar.gz PrismLauncher-a8089b76c0e7961e31b96cdd203e3c345183645b.tar.bz2 PrismLauncher-a8089b76c0e7961e31b96cdd203e3c345183645b.zip |
fix: bring back instance exports
Diffstat (limited to 'launcher/MMCZip.cpp')
-rw-r--r-- | launcher/MMCZip.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/launcher/MMCZip.cpp b/launcher/MMCZip.cpp index 9b8b7908..90e586d8 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; +} |