[1050] | 1 | #ifndef JLCOMPRESSFOLDER_H_
|
---|
| 2 | #define JLCOMPRESSFOLDER_H_
|
---|
| 3 |
|
---|
| 4 | /*
|
---|
| 5 | Copyright (C) 2010 Roberto Pompermaier
|
---|
| 6 | Copyright (C) 2005-2016 Sergey A. Tachenov
|
---|
| 7 |
|
---|
| 8 | This file is part of QuaZIP.
|
---|
| 9 |
|
---|
| 10 | QuaZIP is free software: you can redistribute it and/or modify
|
---|
| 11 | it under the terms of the GNU Lesser General Public License as published by
|
---|
| 12 | the Free Software Foundation, either version 2.1 of the License, or
|
---|
| 13 | (at your option) any later version.
|
---|
| 14 |
|
---|
| 15 | QuaZIP is distributed in the hope that it will be useful,
|
---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | GNU Lesser General Public License for more details.
|
---|
| 19 |
|
---|
| 20 | You should have received a copy of the GNU Lesser General Public License
|
---|
| 21 | along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 22 |
|
---|
| 23 | See COPYING file for the full LGPL text.
|
---|
| 24 |
|
---|
| 25 | Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
---|
| 26 | see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | #include "quazip.h"
|
---|
| 30 | #include "quazipfile.h"
|
---|
| 31 | #include "quazipfileinfo.h"
|
---|
| 32 | #include <QString>
|
---|
| 33 | #include <QDir>
|
---|
| 34 | #include <QFileInfo>
|
---|
| 35 | #include <QFile>
|
---|
| 36 |
|
---|
| 37 | /// Utility class for typical operations.
|
---|
| 38 | /**
|
---|
| 39 | This class contains a number of useful static functions to perform
|
---|
| 40 | simple operations, such as mass ZIP packing or extraction.
|
---|
| 41 | */
|
---|
| 42 | class QUAZIP_EXPORT JlCompress {
|
---|
| 43 | private:
|
---|
| 44 | static QStringList extractDir(QuaZip &zip, const QString &dir);
|
---|
| 45 | static QStringList getFileList(QuaZip *zip);
|
---|
| 46 | static QString extractFile(QuaZip &zip, QString fileName, QString fileDest);
|
---|
| 47 | static QStringList extractFiles(QuaZip &zip, const QStringList &files, const QString &dir);
|
---|
| 48 | /// Compress a single file.
|
---|
| 49 | /**
|
---|
| 50 | \param zip Opened zip to compress the file to.
|
---|
| 51 | \param fileName The full path to the source file.
|
---|
| 52 | \param fileDest The full name of the file inside the archive.
|
---|
| 53 | \return true if success, false otherwise.
|
---|
| 54 | */
|
---|
| 55 | static bool compressFile(QuaZip* zip, QString fileName, QString fileDest);
|
---|
| 56 | /// Compress a subdirectory.
|
---|
| 57 | /**
|
---|
| 58 | \param parentZip Opened zip containing the parent directory.
|
---|
| 59 | \param dir The full path to the directory to pack.
|
---|
| 60 | \param parentDir The full path to the directory corresponding to
|
---|
| 61 | the root of the ZIP.
|
---|
| 62 | \param recursive Whether to pack sub-directories as well or only
|
---|
| 63 | files.
|
---|
| 64 | \return true if success, false otherwise.
|
---|
| 65 | */
|
---|
| 66 | static bool compressSubDir(QuaZip* parentZip, QString dir, QString parentDir, bool recursive,
|
---|
| 67 | QDir::Filters filters);
|
---|
| 68 | /// Extract a single file.
|
---|
| 69 | /**
|
---|
| 70 | \param zip The opened zip archive to extract from.
|
---|
| 71 | \param fileName The full name of the file to extract.
|
---|
| 72 | \param fileDest The full path to the destination file.
|
---|
| 73 | \return true if success, false otherwise.
|
---|
| 74 | */
|
---|
| 75 | static bool extractFile(QuaZip* zip, QString fileName, QString fileDest);
|
---|
| 76 | /// Remove some files.
|
---|
| 77 | /**
|
---|
| 78 | \param listFile The list of files to remove.
|
---|
| 79 | \return true if success, false otherwise.
|
---|
| 80 | */
|
---|
| 81 | static bool removeFile(QStringList listFile);
|
---|
| 82 |
|
---|
| 83 | public:
|
---|
| 84 | /// Compress a single file.
|
---|
| 85 | /**
|
---|
| 86 | \param fileCompressed The name of the archive.
|
---|
| 87 | \param file The file to compress.
|
---|
| 88 | \return true if success, false otherwise.
|
---|
| 89 | */
|
---|
| 90 | static bool compressFile(QString fileCompressed, QString file);
|
---|
| 91 | /// Compress a list of files.
|
---|
| 92 | /**
|
---|
| 93 | \param fileCompressed The name of the archive.
|
---|
| 94 | \param files The file list to compress.
|
---|
| 95 | \return true if success, false otherwise.
|
---|
| 96 | */
|
---|
| 97 | static bool compressFiles(QString fileCompressed, QStringList files);
|
---|
| 98 | /// Compress a whole directory.
|
---|
| 99 | /**
|
---|
| 100 | Does not compress hidden files. See compressDir(QString, QString, bool, QDir::Filters).
|
---|
| 101 |
|
---|
| 102 | \param fileCompressed The name of the archive.
|
---|
| 103 | \param dir The directory to compress.
|
---|
| 104 | \param recursive Whether to pack the subdirectories as well, or
|
---|
| 105 | just regular files.
|
---|
| 106 | \return true if success, false otherwise.
|
---|
| 107 | */
|
---|
| 108 | static bool compressDir(QString fileCompressed, QString dir = QString(), bool recursive = true);
|
---|
| 109 | /**
|
---|
| 110 | * @brief Compress a whole directory.
|
---|
| 111 | *
|
---|
| 112 | * Unless filters are specified explicitly, packs
|
---|
| 113 | * only regular non-hidden files (and subdirs, if @c recursive is true).
|
---|
| 114 | * If filters are specified, they are OR-combined with
|
---|
| 115 | * <tt>%QDir::AllDirs|%QDir::NoDotAndDotDot</tt> when searching for dirs
|
---|
| 116 | * and with <tt>QDir::Files</tt> when searching for files.
|
---|
| 117 | *
|
---|
| 118 | * @param fileCompressed path to the resulting archive
|
---|
| 119 | * @param dir path to the directory being compressed
|
---|
| 120 | * @param recursive if true, then the subdirectories are packed as well
|
---|
| 121 | * @param filters what to pack, filters are applied both when searching
|
---|
| 122 | * for subdirs (if packing recursively) and when looking for files to pack
|
---|
| 123 | * @return true on success, false otherwise
|
---|
| 124 | */
|
---|
| 125 | static bool compressDir(QString fileCompressed, QString dir,
|
---|
| 126 | bool recursive, QDir::Filters filters);
|
---|
| 127 |
|
---|
| 128 | public:
|
---|
| 129 | /// Extract a single file.
|
---|
| 130 | /**
|
---|
| 131 | \param fileCompressed The name of the archive.
|
---|
| 132 | \param fileName The file to extract.
|
---|
| 133 | \param fileDest The destination file, assumed to be identical to
|
---|
| 134 | \a file if left empty.
|
---|
| 135 | \return The list of the full paths of the files extracted, empty on failure.
|
---|
| 136 | */
|
---|
| 137 | static QString extractFile(QString fileCompressed, QString fileName, QString fileDest = QString());
|
---|
| 138 | /// Extract a list of files.
|
---|
| 139 | /**
|
---|
| 140 | \param fileCompressed The name of the archive.
|
---|
| 141 | \param files The file list to extract.
|
---|
| 142 | \param dir The directory to put the files to, the current
|
---|
| 143 | directory if left empty.
|
---|
| 144 | \return The list of the full paths of the files extracted, empty on failure.
|
---|
| 145 | */
|
---|
| 146 | static QStringList extractFiles(QString fileCompressed, QStringList files, QString dir = QString());
|
---|
| 147 | /// Extract a whole archive.
|
---|
| 148 | /**
|
---|
| 149 | \param fileCompressed The name of the archive.
|
---|
| 150 | \param dir The directory to extract to, the current directory if
|
---|
| 151 | left empty.
|
---|
| 152 | \return The list of the full paths of the files extracted, empty on failure.
|
---|
| 153 | */
|
---|
| 154 | static QStringList extractDir(QString fileCompressed, QString dir = QString());
|
---|
| 155 | /// Get the file list.
|
---|
| 156 | /**
|
---|
| 157 | \return The list of the files in the archive, or, more precisely, the
|
---|
| 158 | list of the entries, including both files and directories if they
|
---|
| 159 | are present separately.
|
---|
| 160 | */
|
---|
| 161 | static QStringList getFileList(QString fileCompressed);
|
---|
| 162 | /// Extract a single file.
|
---|
| 163 | /**
|
---|
| 164 | \param ioDevice pointer to device with compressed data.
|
---|
| 165 | \param fileName The file to extract.
|
---|
| 166 | \param fileDest The destination file, assumed to be identical to
|
---|
| 167 | \a file if left empty.
|
---|
| 168 | \return The list of the full paths of the files extracted, empty on failure.
|
---|
| 169 | */
|
---|
| 170 | static QString extractFile(QIODevice *ioDevice, QString fileName, QString fileDest = QString());
|
---|
| 171 | /// Extract a list of files.
|
---|
| 172 | /**
|
---|
| 173 | \param ioDevice pointer to device with compressed data.
|
---|
| 174 | \param files The file list to extract.
|
---|
| 175 | \param dir The directory to put the files to, the current
|
---|
| 176 | directory if left empty.
|
---|
| 177 | \return The list of the full paths of the files extracted, empty on failure.
|
---|
| 178 | */
|
---|
| 179 | static QStringList extractFiles(QIODevice *ioDevice, QStringList files, QString dir = QString());
|
---|
| 180 | /// Extract a whole archive.
|
---|
| 181 | /**
|
---|
| 182 | \param ioDevice pointer to device with compressed data.
|
---|
| 183 | \param dir The directory to extract to, the current directory if
|
---|
| 184 | left empty.
|
---|
| 185 | \return The list of the full paths of the files extracted, empty on failure.
|
---|
| 186 | */
|
---|
| 187 | static QStringList extractDir(QIODevice *ioDevice, QString dir = QString());
|
---|
| 188 | /// Get the file list.
|
---|
| 189 | /**
|
---|
| 190 | \return The list of the files in the archive, or, more precisely, the
|
---|
| 191 | list of the entries, including both files and directories if they
|
---|
| 192 | are present separately.
|
---|
| 193 | */
|
---|
| 194 | static QStringList getFileList(QIODevice *ioDevice);
|
---|
| 195 | };
|
---|
| 196 |
|
---|
| 197 | #endif /* JLCOMPRESSFOLDER_H_ */
|
---|