diff options
author | Petr Mrázek <peterix@gmail.com> | 2013-08-05 03:29:50 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2013-08-05 03:29:50 +0200 |
commit | 183a7351456940d01f14a49112ddeb68ffc4693a (patch) | |
tree | 579aeb0b8670e634de4f083e54b3c826bf548ec9 /quazip | |
parent | 005a010ee6a67191ec24583780310fcf217ff30c (diff) | |
download | MultiMC-183a7351456940d01f14a49112ddeb68ffc4693a.tar MultiMC-183a7351456940d01f14a49112ddeb68ffc4693a.tar.gz MultiMC-183a7351456940d01f14a49112ddeb68ffc4693a.tar.lz MultiMC-183a7351456940d01f14a49112ddeb68ffc4693a.tar.xz MultiMC-183a7351456940d01f14a49112ddeb68ffc4693a.zip |
Runnable 1.6 instances!
Diffstat (limited to 'quazip')
-rw-r--r-- | quazip/JlCompress.cpp | 47 | ||||
-rw-r--r-- | quazip/JlCompress.h | 9 |
2 files changed, 56 insertions, 0 deletions
diff --git a/quazip/JlCompress.cpp b/quazip/JlCompress.cpp index 411645e1..69832140 100644 --- a/quazip/JlCompress.cpp +++ b/quazip/JlCompress.cpp @@ -384,6 +384,53 @@ QStringList JlCompress::extractFiles(QString fileCompressed, QStringList files, return extracted; } +QStringList JlCompress::extractWithExceptions(QString fileCompressed, QString dir, QStringList exceptions) +{ + QuaZip zip(fileCompressed); + if(!zip.open(QuaZip::mdUnzip)) + { + return QStringList(); + } + + QDir directory(dir); + QStringList extracted; + if (!zip.goToFirstFile()) + { + return QStringList(); + } + do + { + QString name = zip.getCurrentFileName(); + bool ok = true; + for(auto str: exceptions) + { + if(name.startsWith(str)) + { + ok = false; + break; + } + } + if(!ok) + continue; + QString absFilePath = directory.absoluteFilePath(name); + if (!JlCompress::extractFile(&zip, "", absFilePath)) + { + JlCompress::removeFile(extracted); + return QStringList(); + } + extracted.append(absFilePath); + } while (zip.goToNextFile()); + + zip.close(); + if(zip.getZipError()!=0) + { + JlCompress::removeFile(extracted); + return QStringList(); + } + + return extracted; +} + /**OK * Estrae il file fileCompressed nella cartella dir. * Se dir = "" allora il file viene estratto nella cartella corrente. diff --git a/quazip/JlCompress.h b/quazip/JlCompress.h index 968f7a89..29d6191f 100644 --- a/quazip/JlCompress.h +++ b/quazip/JlCompress.h @@ -102,6 +102,15 @@ public: \return The list of the full paths of the files extracted, empty on failure. */ static QStringList extractDir(QString fileCompressed, QString dir = QString()); + /// Extract a whole archive, with a list of exceptions (prefixes to ignore). + /** + \param fileCompressed The name of the archive. + \param dir The directory to extract to, the current directory if + left empty. + \param exceptions The list of exception prefixes + \return The list of the full paths of the files extracted, empty on failure. + */ + static QStringList extractWithExceptions(QString fileCompressed, QString dir, QStringList exceptions); /// Get the file list. /** \return The list of the files in the archive, or, more precisely, the |