31 while (!inFile.atEnd()) {
33 qint64 readLen = inFile.read(buf, 4096);
36 if (outFile.write(buf, readLen) != readLen)
59 if (!zip)
return false;
66 inFile.setFileName(fileName);
67 if(!inFile.open(QIODevice::ReadOnly))
return false;
71 if(!outFile.
open(QIODevice::WriteOnly,
QuaZipNewInfo(fileDest, inFile.fileName())))
return false;
110 if (!zip)
return false;
117 if (!directory.exists())
return false;
119 QDir origDirectory(origDir);
120 if (dir != origDir) {
122 if (!dirZipFile.
open(QIODevice::WriteOnly,
123 QuaZipNewInfo(origDirectory.relativeFilePath(dir) +
"/", dir), 0, 0, 0)) {
133 QFileInfoList files = directory.entryInfoList(QDir::AllDirs|QDir::NoDotAndDotDot);
134 Q_FOREACH (QFileInfo file, files) {
136 if(!
compressSubDir(zip,file.absoluteFilePath(),origDir,recursive))
return false;
141 QFileInfoList files = directory.entryInfoList(QDir::Files);
142 Q_FOREACH (QFileInfo file, files) {
144 if(!file.isFile()||file.absoluteFilePath()==zip->
getZipName())
continue;
147 QString filename = origDirectory.relativeFilePath(file.absoluteFilePath());
150 if (!
compressFile(zip,file.absoluteFilePath(),filename))
return false;
176 if (!zip)
return false;
180 if (!fileName.isEmpty())
187 if (fileDest.endsWith(
'/')) {
188 if (!curDir.mkpath(fileDest)) {
192 if (!curDir.mkpath(QFileInfo(fileDest).absolutePath())) {
202 if (fileDest.endsWith(
'/') && QFileInfo(fileDest).isDir()) {
204 QFile(fileDest).setPermissions(srcPerm);
211 outFile.setFileName(fileDest);
212 if(!outFile.open(QIODevice::WriteOnly))
return false;
230 outFile.setPermissions(srcPerm);
244 for (
int i=0; i<listFile.count(); i++) {
246 ret = ret && QFile::remove(listFile.at(i));
265 QuaZip zip(fileCompressed);
266 QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
268 QFile::remove(fileCompressed);
273 if (!
compressFile(&zip,file,QFileInfo(file).fileName())) {
274 QFile::remove(fileCompressed);
281 QFile::remove(fileCompressed);
300 QuaZip zip(fileCompressed);
301 QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
303 QFile::remove(fileCompressed);
309 Q_FOREACH (QString file, files) {
311 if (!info.exists() || !
compressFile(&zip,file,info.fileName())) {
312 QFile::remove(fileCompressed);
320 QFile::remove(fileCompressed);
340 QuaZip zip(fileCompressed);
341 QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
343 QFile::remove(fileCompressed);
349 QFile::remove(fileCompressed);
356 QFile::remove(fileCompressed);
379 QuaZip zip(fileCompressed);
385 if (fileDest.isEmpty())
397 return QFileInfo(fileDest).absoluteFilePath();
414 QuaZip zip(fileCompressed);
416 return QStringList();
420 QStringList extracted;
421 for (
int i=0; i<files.count(); i++) {
422 QString absPath = QDir(dir).absoluteFilePath(files.at(i));
425 return QStringList();
427 extracted.append(absPath);
434 return QStringList();
453 QuaZip zip(fileCompressed);
455 return QStringList();
459 QStringList extracted;
461 return QStringList();
465 QString absFilePath = directory.absoluteFilePath(name);
468 return QStringList();
470 extracted.append(absFilePath);
477 return QStringList();
494 QuaZip* zip =
new QuaZip(QFileInfo(fileCompressed).absoluteFilePath());
497 return QStringList();
506 return QStringList();
516 return QStringList();
static QStringList extractDir(QString fileCompressed, QString dir=QString())
Extract a whole archive.
static bool compressFile(QuaZip *zip, QString fileName, QString fileDest)
Compress a single file.
bool goToFirstFile()
Sets the current file to the first file in the archive.
QString getCurrentFileName() const
Returns the current file name.
Information about a file to be created.
static bool compressSubDir(QuaZip *parentZip, QString dir, QString parentDir, bool recursive=true)
Compress a subdirectory.
ZIP file was opened for adding files in the archive.
Mode getMode() const
Returns the mode in which ZIP file was opened.
ZIP file was created with open() call.
virtual void close()
Closes the file.
int getZipError() const
Returns the error code of the last operation.
static bool compressDir(QString fileCompressed, QString dir=QString(), bool recursive=true)
Compress a whole directory.
static bool removeFile(QStringList listFile)
Remove some files.
int getZipError() const
Returns the error code returned by the last ZIP/UNZIP API call.
QFile::Permissions getPermissions() const
Get the file permissions.
QString getZipName() const
Returns the name of the ZIP file.
bool goToNextFile()
Sets the current file to the next file in the archive.
static QStringList getFileList(QString fileCompressed)
Get the file list.
Information about a file inside archive (with zip64 support).
static bool extractFile(QuaZip *zip, QString fileName, QString fileDest)
Extract a single file.
bool setCurrentFile(const QString &fileName, CaseSensitivity cs=csDefault)
Sets current file by its name.
ZIP file is open for reading files inside it.
void close()
Closes ZIP file.
static QStringList extractFiles(QString fileCompressed, QStringList files, QString dir=QString())
Extract a list of files.
A file inside ZIP archive.
static bool copyData(QIODevice &inFile, QIODevice &outFile)
virtual bool open(OpenMode mode)
Opens a file for reading.
ZIP file was opened in append mode.
bool open(Mode mode, zlib_filefunc_def *ioApi=NULL)
Opens ZIP file.
static bool compressFiles(QString fileCompressed, QStringList files)
Compress a list of files.
bool getCurrentFileInfo(QuaZipFileInfo *info) const
Retrieves information about the current file.