Permalink
Browse files

Updated QuaZip to 0.4.4

  • Loading branch information...
1 parent 1d058b0 commit b749c5e42b781bb637400796a05806228e1b69f7 @nikola-kocic committed Jan 14, 2012
Showing with 189 additions and 25 deletions.
  1. +22 −12 quazip/JlCompress.cpp
  2. +84 −2 quazip/JlCompress.h
  3. +8 −5 quazip/qioapi.cpp
  4. +31 −4 quazip/quazip.cpp
  5. +43 −2 quazip/quazipfile.cpp
  6. +1 −0 quazip/zip.c
View
@@ -147,7 +147,13 @@ bool JlCompress::extractFile(QuaZip* zip, QString fileName, QString fileDest) {
if(!inFile.open(QIODevice::ReadOnly) || inFile.getZipError()!=UNZ_OK) return false;
// Controllo esistenza cartella file risultato
- QDir().mkpath(QFileInfo(fileDest).absolutePath());
+ QDir curDir;
+ if (!curDir.mkpath(QFileInfo(fileDest).absolutePath())) {
+ return false;
+ }
+
+ if (QFileInfo(fileDest).isDir())
+ return true;
// Apro il file risultato
QFile outFile;
@@ -156,17 +162,18 @@ bool JlCompress::extractFile(QuaZip* zip, QString fileName, QString fileDest) {
// Copio i dati
if (!copyData(inFile, outFile) || inFile.getZipError()!=UNZ_OK) {
+ outFile.close();
removeFile(QStringList(fileDest));
return false;
}
+ outFile.close();
// Chiudo i file
inFile.close();
if (inFile.getZipError()!=UNZ_OK) {
removeFile(QStringList(fileDest));
return false;
}
- outFile.close();
return true;
}
@@ -293,7 +300,7 @@ bool JlCompress::compressDir(QString fileCompressed, QString dir, bool recursive
}
// Aggiungo i file e le sotto cartelle
- if (!compressSubDir(zip,dir,dir,recursive)<0) {
+ if (!compressSubDir(zip,dir,dir,recursive)) {
delete zip;
QFile::remove(fileCompressed);
return false;
@@ -372,25 +379,27 @@ QStringList JlCompress::extractFiles(QString fileCompressed, QStringList files,
}
// Estraggo i file
+ QStringList extracted;
for (int i=0; i<files.count(); i++) {
- if (!extractFile(zip, files.at(i), QDir(dir).absoluteFilePath(files.at(i)))) {
+ QString absPath = QDir(dir).absoluteFilePath(files.at(i));
+ if (!extractFile(zip, files.at(i), absPath)) {
delete zip;
- removeFile(files);
+ removeFile(extracted);
return QStringList();
}
- files[i] = QDir(dir).absoluteFilePath(files.at(i));
+ extracted.append(absPath);
}
// Chiudo il file zip
zip->close();
if(zip->getZipError()!=0) {
delete zip;
- removeFile(files);
+ removeFile(extracted);
return QStringList();
}
delete zip;
- return files;
+ return extracted;
}
/**OK
@@ -416,26 +425,27 @@ QStringList JlCompress::extractDir(QString fileCompressed, QString dir) {
QStringList lst = getFileList(fileCompressed);
QDir directory(dir);
+ QStringList extracted;
for (int i=0; i<lst.count(); i++) {
QString absFilePath = directory.absoluteFilePath(lst.at(i));
if (!extractFile(zip, lst.at(i), absFilePath)) {
delete zip;
- removeFile(lst);
+ removeFile(extracted);
return QStringList();
}
- lst[i] = absFilePath;
+ extracted.append(absFilePath);
}
// Chiudo il file zip
zip->close();
if(zip->getZipError()!=0) {
delete zip;
- removeFile(lst);
+ removeFile(extracted);
return QStringList();
}
delete zip;
- return lst;
+ return extracted;
}
/**OK
View
@@ -9,23 +9,105 @@
#include <QFileInfo>
#include <QFile>
+/// Utility class for typical operations.
+/**
+ This class contains a number of useful static functions to perform
+ simple operations, such as mass ZIP packing or extraction.
+ */
class QUAZIP_EXPORT JlCompress {
private:
+ /// Compress a single file.
+ /**
+ \param zip Opened zip to compress the file to.
+ \param fileName The full path to the source file.
+ \param fileDest The full name of the file inside the archive.
+ \return true if success, false otherwise.
+ */
static bool compressFile(QuaZip* zip, QString fileName, QString fileDest);
+ /// Compress a subdirectory.
+ /**
+ \param parentZip Opened zip containing the parent directory.
+ \param dir The full path to the directory to pack.
+ \param parentDir The full path to the directory corresponding to
+ the root of the ZIP.
+ \param recursive Whether to pack sub-directories as well or only
+ files.
+ \return true if success, false otherwise.
+ */
static bool compressSubDir(QuaZip* parentZip, QString dir, QString parentDir, bool recursive = true);
+ /// Extract a single file.
+ /**
+ \param zip The opened zip archive to extract from.
+ \param fileName The full name of the file to extract.
+ \param fileDest The full path to the destination file.
+ \return true if success, false otherwise.
+ */
static bool extractFile(QuaZip* zip, QString fileName, QString fileDest);
-
+ /// Remove some files.
+ /**
+ \param listFile The list of files to remove.
+ \return true if success, false otherwise.
+ */
static bool removeFile(QStringList listFile);
public:
+ /// Compress a single file.
+ /**
+ \param fileCompressed The name of the archive.
+ \param file The file to compress.
+ \return true if success, false otherwise.
+ */
static bool compressFile(QString fileCompressed, QString file);
+ /// Compress a list of files.
+ /**
+ \param fileCompressed The name of the archive.
+ \param files The file list to compress.
+ \return true if success, false otherwise.
+ */
static bool compressFiles(QString fileCompressed, QStringList files);
+ /// Compress a whole directory.
+ /**
+ \param fileCompressed The name of the archive.
+ \param dir The directory to compress.
+ \param recursive Whether to pack the subdirectories as well, or
+ just regular files.
+ \return true if success, false otherwise.
+ */
static bool compressDir(QString fileCompressed, QString dir = QString(), bool recursive = true);
public:
- static QString extractFile(QString fileCompressed, QString file, QString fileDest = QString());
+ /// Extract a single file.
+ /**
+ \param fileCompressed The name of the archive.
+ \param fileName The file to extract.
+ \param fileDest The destination file, assumed to be identical to
+ \a file if left empty.
+ \return The list of the full paths of the files extracted, empty on failure.
+ */
+ static QString extractFile(QString fileCompressed, QString fileName, QString fileDest = QString());
+ /// Extract a list of files.
+ /**
+ \param fileCompressed The name of the archive.
+ \param files The file list to extract.
+ \param dir The directory to put the files to, the current
+ directory if left empty.
+ \return The list of the full paths of the files extracted, empty on failure.
+ */
static QStringList extractFiles(QString fileCompressed, QStringList files, QString dir = QString());
+ /// Extract a whole archive.
+ /**
+ \param fileCompressed The name of the archive.
+ \param dir The directory to extract to, the current directory if
+ left empty.
+ \return The list of the full paths of the files extracted, empty on failure.
+ */
static QStringList extractDir(QString fileCompressed, QString dir = QString());
+ /// Get the file list.
+ /**
+ \return The list of the files in the archive, or, more precisely, the
+ list of the entries, including both files and directories if they
+ are present separately.
+ */
static QStringList getFileList(QString fileCompressed);
};
View
@@ -38,8 +38,6 @@ voidpf ZCALLBACK qiodevice_open_file_func (
int mode)
{
QIODevice *iodevice = reinterpret_cast<QIODevice*>(file);
- if(iodevice->isSequential())
- return NULL;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
iodevice->open(QIODevice::ReadOnly);
else
@@ -49,9 +47,14 @@ voidpf ZCALLBACK qiodevice_open_file_func (
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
iodevice->open(QIODevice::WriteOnly);
- if(iodevice->isOpen())
- return iodevice;
- else
+ if (iodevice->isOpen()) {
+ if (iodevice->isSequential()) {
+ iodevice->close();
+ return NULL;
+ } else {
+ return iodevice;
+ }
+ } else
return NULL;
}
View
@@ -26,22 +26,44 @@ quazip/(un)zip.h files for details, basically it's zlib license.
#include "quazip.h"
+/// All the internal stuff for the QuaZip class.
+/**
+ \internal
+
+ This class keeps all the private stuff for the QuaZip class so it can
+ be changed without breaking binary compatibility, according to the
+ Pimpl idiom.
+ */
class QuaZipPrivate {
friend class QuaZip;
private:
- QuaZip *q;
- QTextCodec *fileNameCodec, *commentCodec;
+ /// The pointer to the corresponding QuaZip instance.
+ QuaZip *q;
+ /// The codec for file names.
+ QTextCodec *fileNameCodec;
+ /// The codec for comments.
+ QTextCodec *commentCodec;
+ /// The archive file name.
QString zipName;
+ /// The device to access the archive.
QIODevice *ioDevice;
+ /// The global comment.
QString comment;
+ /// The open mode.
QuaZip::Mode mode;
union {
+ /// The internal handle for UNZIP modes.
unzFile unzFile_f;
+ /// The internal handle for ZIP modes.
zipFile zipFile_f;
};
+ /// Whether a current file is set.
bool hasCurrentFile_f;
+ /// The last error.
int zipError;
+ /// Whether \ref QuaZip::setDataDescriptorWritingEnabled() "the data descriptor writing mode" is enabled.
bool dataDescriptorWritingEnabled;
+ /// The constructor for the corresponding QuaZip constructor.
inline QuaZipPrivate(QuaZip *q):
q(q),
fileNameCodec(QTextCodec::codecForLocale()),
@@ -51,6 +73,7 @@ class QuaZipPrivate {
hasCurrentFile_f(false),
zipError(UNZ_OK),
dataDescriptorWritingEnabled(true) {}
+ /// The constructor for the corresponding QuaZip constructor.
inline QuaZipPrivate(QuaZip *q, const QString &zipName):
q(q),
fileNameCodec(QTextCodec::codecForLocale()),
@@ -61,6 +84,7 @@ class QuaZipPrivate {
hasCurrentFile_f(false),
zipError(UNZ_OK),
dataDescriptorWritingEnabled(true) {}
+ /// The constructor for the corresponding QuaZip constructor.
inline QuaZipPrivate(QuaZip *q, QIODevice *ioDevice):
q(q),
fileNameCodec(QTextCodec::codecForLocale()),
@@ -70,6 +94,7 @@ class QuaZipPrivate {
hasCurrentFile_f(false),
zipError(UNZ_OK),
dataDescriptorWritingEnabled(true) {}
+ /// Returns either a list of file names or a list of QuaZipFileInfo.
template<typename TFileInfo>
bool getFileInfoList(QList<TFileInfo> *result) const;
};
@@ -173,8 +198,10 @@ void QuaZip::close()
return;
}
// opened by name, need to delete the internal IO device
- if (!p->zipName.isEmpty())
- delete p->ioDevice;
+ if (!p->zipName.isEmpty()) {
+ delete p->ioDevice;
+ p->ioDevice = NULL;
+ }
if(p->zipError==UNZ_OK)
p->mode=mdNotOpen;
}
Oops, something went wrong.

0 comments on commit b749c5e

Please sign in to comment.