ckb-next
v0.2.8 at branch master
ckb-next driver for corsair devices
|
ZIP archive. More...
#include <quazip/quazip.h>
Public Types | |
enum | Constants { MAX_FILE_NAME_LENGTH =256 } |
Useful constants. More... | |
enum | Mode { mdNotOpen, mdUnzip, mdCreate, mdAppend, mdAdd } |
Open mode of the ZIP file. More... | |
enum | CaseSensitivity { csDefault =0, csSensitive =1, csInsensitive =2 } |
Case sensitivity for the file names. More... | |
Public Member Functions | |
QuaZip () | |
Constructs QuaZip object. More... | |
QuaZip (const QString &zipName) | |
Constructs QuaZip object associated with ZIP file zipName. More... | |
QuaZip (QIODevice *ioDevice) | |
Constructs QuaZip object associated with ZIP file represented by ioDevice. More... | |
~QuaZip () | |
Destroys QuaZip object. More... | |
bool | open (Mode mode, zlib_filefunc_def *ioApi=NULL) |
Opens ZIP file. More... | |
void | close () |
Closes ZIP file. More... | |
void | setFileNameCodec (QTextCodec *fileNameCodec) |
Sets the codec used to encode/decode file names inside archive. More... | |
void | setFileNameCodec (const char *fileNameCodecName) |
Sets the codec used to encode/decode file names inside archive. More... | |
QTextCodec * | getFileNameCodec () const |
Returns the codec used to encode/decode comments inside archive. More... | |
void | setCommentCodec (QTextCodec *commentCodec) |
Sets the codec used to encode/decode comments inside archive. More... | |
void | setCommentCodec (const char *commentCodecName) |
Sets the codec used to encode/decode comments inside archive. More... | |
QTextCodec * | getCommentCodec () const |
Returns the codec used to encode/decode comments inside archive. More... | |
QString | getZipName () const |
Returns the name of the ZIP file. More... | |
void | setZipName (const QString &zipName) |
Sets the name of the ZIP file. More... | |
QIODevice * | getIoDevice () const |
Returns the device representing this ZIP file. More... | |
void | setIoDevice (QIODevice *ioDevice) |
Sets the device representing the ZIP file. More... | |
Mode | getMode () const |
Returns the mode in which ZIP file was opened. More... | |
bool | isOpen () const |
Returns true if ZIP file is open, false otherwise. More... | |
int | getZipError () const |
Returns the error code of the last operation. More... | |
int | getEntriesCount () const |
Returns number of the entries in the ZIP central directory. More... | |
QString | getComment () const |
Returns global comment in the ZIP file. More... | |
void | setComment (const QString &comment) |
Sets the global comment in the ZIP file. More... | |
bool | goToFirstFile () |
Sets the current file to the first file in the archive. More... | |
bool | goToNextFile () |
Sets the current file to the next file in the archive. More... | |
bool | setCurrentFile (const QString &fileName, CaseSensitivity cs=csDefault) |
Sets current file by its name. More... | |
bool | hasCurrentFile () const |
Returns true if the current file has been set. More... | |
bool | getCurrentFileInfo (QuaZipFileInfo *info) const |
Retrieves information about the current file. More... | |
bool | getCurrentFileInfo (QuaZipFileInfo64 *info) const |
Retrieves information about the current file. More... | |
QString | getCurrentFileName () const |
Returns the current file name. More... | |
unzFile | getUnzFile () |
Returns unzFile handle. More... | |
zipFile | getZipFile () |
Returns zipFile handle. More... | |
void | setDataDescriptorWritingEnabled (bool enabled) |
Changes the data descriptor writing mode. More... | |
bool | isDataDescriptorWritingEnabled () const |
Returns the data descriptor default writing mode. More... | |
QStringList | getFileNameList () const |
Returns a list of files inside the archive. More... | |
QList< QuaZipFileInfo > | getFileInfoList () const |
Returns information list about all files inside the archive. More... | |
QList< QuaZipFileInfo64 > | getFileInfoList64 () const |
Returns information list about all files inside the archive. More... | |
void | setZip64Enabled (bool zip64) |
Enables the zip64 mode. More... | |
bool | isZip64Enabled () const |
Returns whether the zip64 mode is enabled. More... | |
bool | isAutoClose () const |
Returns the auto-close flag. More... | |
void | setAutoClose (bool autoClose) const |
Sets or unsets the auto-close flag. More... | |
Static Public Member Functions | |
static Qt::CaseSensitivity | convertCaseSensitivity (CaseSensitivity cs) |
Returns the actual case sensitivity for the specified QuaZIP one. More... | |
static void | setDefaultFileNameCodec (QTextCodec *codec) |
Sets the default file name codec to use. More... | |
static void | setDefaultFileNameCodec (const char *codecName) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Equivalent to calling setDefltFileNameCodec(QTextCodec::codecForName(codecName)). More... | |
Private Member Functions | |
QuaZip (const QuaZip &that) | |
QuaZip & | operator= (const QuaZip &that) |
Private Attributes | |
QuaZipPrivate * | p |
Friends | |
class | QuaZipPrivate |
This class implements basic interface to the ZIP archive. It can be used to read table contents of the ZIP archive and retreiving information about the files inside it.
You can also use this class to open files inside archive by passing pointer to the instance of this class to the constructor of the QuaZipFile class. But see QuaZipFile::QuaZipFile(QuaZip*, QObject*) for the possible pitfalls.
This class is indended to provide interface to the ZIP subpackage of the ZIP/UNZIP package as well as to the UNZIP subpackage. But currently it supports only UNZIP.
The use of this class is simple - just create instance using constructor, then set ZIP archive file name using setFile() function (if you did not passed the name to the constructor), then open() and then use different functions to work with it! Well, if you are paranoid, you may also wish to call close before destructing the instance, to check for errors on close.
You may also use getUnzFile() and getZipFile() functions to get the ZIP archive handle and use it with ZIP/UNZIP package API directly.
This class supports localized file names inside ZIP archive, but you have to set up proper codec with setCodec() function. By default, locale codec will be used, which is probably ok for UNIX systems, but will almost certainly fail with ZIP archives created in Windows. This is because Windows ZIP programs have strange habit of using DOS encoding for file names in ZIP archives. For example, ZIP archive with cyrillic names created in Windows will have file names in IBM866
encoding instead of WINDOWS-1251
. I think that calling one function is not much trouble, but for true platform independency it would be nice to have some mechanism for file name encoding auto detection using locale information. Does anyone know a good way to do it?
This is what you specify when accessing files in the archive. Works perfectly fine with any characters thanks to Qt's great unicode support. This is different from ZIP/UNZIP API, where only US-ASCII characters was supported.
Enumerator | |
---|---|
csDefault |
Default for platform. Case sensitive for UNIX, not for Windows. |
csSensitive |
Case sensitive. |
csInsensitive |
Case insensitive. |
Definition at line 114 of file quazip.h.
enum QuaZip::Constants |
enum QuaZip::Mode |
Enumerator | |
---|---|
mdNotOpen |
ZIP file is not open. This is the initial mode. |
mdUnzip |
ZIP file is open for reading files inside it. |
mdCreate |
ZIP file was created with open() call. |
mdAppend |
ZIP file was opened in append mode. This refers to |
mdAdd |
ZIP file was opened for adding files in the archive. |
Definition at line 94 of file quazip.h.
|
private |
QuaZip::QuaZip | ( | ) |
QuaZip::QuaZip | ( | const QString & | zipName | ) |
Definition at line 198 of file quazip.cpp.
QuaZip::QuaZip | ( | QIODevice * | ioDevice | ) |
The IO device must be seekable, otherwise an error will occur when opening.
Definition at line 203 of file quazip.cpp.
QuaZip::~QuaZip | ( | ) |
Calls close() if necessary.
Definition at line 208 of file quazip.cpp.
References close(), isOpen(), and p.
void QuaZip::close | ( | ) |
Call getZipError() to determine if the close was successful.
If the file was opened by name, then the underlying QIODevice is closed and deleted.
If the underlying QIODevice was set explicitly using setIoDevice() or the appropriate constructor, then it is closed if the auto-close flag is set (which it is by default). Call setAutoClose() to clear the auto-close flag if this behavior is undesirable.
Since Qt 5.1, the QSaveFile was introduced. It breaks the QIODevice API by making close() private and crashing the application if it is called from the base class where it is public. It is an excellent example of poor design that illustrates why you should never ever break an is-a relationship between the base class and a subclass. QuaZIP works around this bug by checking if the QIODevice is an instance of QSaveFile, using qobject_cast<>, and if it is, calls QSaveFile::commit() instead of close(). It is a really ugly hack, but at least it makes your programs work instead of crashing. Note that if the auto-close flag is cleared, then this is a non-issue, and commit() isn't called.
Definition at line 324 of file quazip.cpp.
References QuaZipPrivate::clearDirectoryMap(), QuaZipPrivate::comment, QuaZipPrivate::commentCodec, QuaZipPrivate::ioDevice, mdAdd, mdAppend, mdCreate, mdNotOpen, mdUnzip, QuaZipPrivate::mode, p, UNZ_OK, unzClose(), zipClose(), QuaZipPrivate::zipError, and QuaZipPrivate::zipName.
Referenced by QuaZipFile::close(), JlCompress::compressDir(), JlCompress::compressFile(), JlCompress::compressFiles(), JlCompress::extractDir(), JlCompress::extractFile(), JlCompress::extractFiles(), JlCompress::getFileList(), QuaZipFile::open(), and ~QuaZip().
|
static |
cs | The value to convert. |
Definition at line 747 of file quazip.cpp.
References csDefault, and csSensitive.
Referenced by QuaZipDir::exists(), and setCurrentFile().
QString QuaZip::getComment | ( | ) | const |
Definition at line 389 of file quazip.cpp.
References QuaZipPrivate::commentCodec, mdUnzip, QuaZipPrivate::mode, p, unz_global_info64_s::size_comment, UNZ_OK, unzGetGlobalComment(), unzGetGlobalInfo64(), and QuaZipPrivate::zipError.
QTextCodec * QuaZip::getCommentCodec | ( | ) | const |
Definition at line 597 of file quazip.cpp.
References QuaZipPrivate::commentCodec, and p.
Referenced by QuaZipFile::open().
bool QuaZip::getCurrentFileInfo | ( | QuaZipFileInfo * | info | ) | const |
Fills the structure pointed by info. Returns true
on success, false
otherwise. In the latter case structure pointed by info remains untouched. If there was an error, getZipError() returns error code.
Should be used only in QuaZip::mdUnzip mode.
Does nothing and returns false
in any of the following cases.
In both cases getZipError() returns UNZ_OK
since there is no ZIP/UNZIP API call.
This overload doesn't support zip64, but will work OK on zip64 archives except that if one of the sizes (compressed or uncompressed) is greater than 0xFFFFFFFFu, it will be set to exactly 0xFFFFFFFFu.
Definition at line 492 of file quazip.cpp.
References QuaZipFileInfo64::toQuaZipFileInfo().
Referenced by JlCompress::extractFile(), QuaZipFile::getFileInfo(), JlCompress::getFileList(), QuaZip_getFileInfo(), and QuaZipDir_getFileInfo().
bool QuaZip::getCurrentFileInfo | ( | QuaZipFileInfo64 * | info | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This function supports zip64. If the archive doesn't use zip64, it is completely equivalent to getCurrentFileInfo(QuaZipFileInfo* info) except for the argument type.
Definition at line 506 of file quazip.cpp.
References QuaZipPrivate::addCurrentFileToDirectoryMap(), QuaZipFileInfo64::comment, QuaZipPrivate::commentCodec, unz_file_info64_s::compressed_size, QuaZipFileInfo64::compressedSize, unz_file_info64_s::compression_method, QuaZipFileInfo64::crc, unz_file_info64_s::crc, QuaZipFileInfo64::dateTime, unz_file_info64_s::disk_num_start, QuaZipFileInfo64::diskNumberStart, unz_file_info64_s::external_fa, QuaZipFileInfo64::externalAttr, QuaZipFileInfo64::extra, QuaZipPrivate::fileNameCodec, unz_file_info64_s::flag, QuaZipFileInfo64::flags, hasCurrentFile(), unz_file_info64_s::internal_fa, QuaZipFileInfo64::internalAttr, isOpen(), mdUnzip, QuaZipFileInfo64::method, QuaZipPrivate::mode, QuaZipFileInfo64::name, p, unz_file_info64_s::size_file_comment, unz_file_info64_s::size_file_extra, unz_file_info64_s::size_filename, tm_unz_s::tm_hour, tm_unz_s::tm_mday, tm_unz_s::tm_min, tm_unz_s::tm_mon, tm_unz_s::tm_sec, tm_unz_s::tm_year, unz_file_info64_s::tmu_date, unz_file_info64_s::uncompressed_size, QuaZipFileInfo64::uncompressedSize, UNZ_OK, unzGetCurrentFileInfo64(), unz_file_info64_s::version, unz_file_info64_s::version_needed, QuaZipFileInfo64::versionCreated, QuaZipFileInfo64::versionNeeded, and QuaZipPrivate::zipError.
QString QuaZip::getCurrentFileName | ( | ) | const |
Equivalent to calling getCurrentFileInfo() and then getting name
field of the QuaZipFileInfo structure, but faster and more convenient.
Should be used only in QuaZip::mdUnzip mode.
Definition at line 551 of file quazip.cpp.
References QuaZipPrivate::addCurrentFileToDirectoryMap(), QuaZipPrivate::fileNameCodec, hasCurrentFile(), isOpen(), MAX_FILE_NAME_LENGTH, mdUnzip, QuaZipPrivate::mode, p, UNZ_OK, unzGetCurrentFileInfo64(), and QuaZipPrivate::zipError.
Referenced by JlCompress::extractDir(), QuaZipFile::getActualFileName(), QuaZipPrivate::getFileInfoList(), QuaZip_getFileInfo(), and setCurrentFile().
int QuaZip::getEntriesCount | ( | ) | const |
Returns negative error code in the case of error. The same error code will be returned by subsequent getZipError() call.
Definition at line 375 of file quazip.cpp.
References mdUnzip, QuaZipPrivate::mode, unz_global_info64_s::number_entry, p, UNZ_OK, unzGetGlobalInfo64(), and QuaZipPrivate::zipError.
QList< QuaZipFileInfo > QuaZip::getFileInfoList | ( | ) | const |
This function doesn't support zip64, but will still work with zip64 archives, converting results using QuaZipFileInfo64::toQuaZipFileInfo(). If all file sizes are below 4 GB, it will work just fine.
Definition at line 729 of file quazip.cpp.
References QuaZipPrivate::getFileInfoList(), and p.
QList< QuaZipFileInfo64 > QuaZip::getFileInfoList64 | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This function supports zip64.
Definition at line 738 of file quazip.cpp.
References QuaZipPrivate::getFileInfoList(), and p.
QTextCodec * QuaZip::getFileNameCodec | ( | ) | const |
Definition at line 582 of file quazip.cpp.
References QuaZipPrivate::fileNameCodec, and p.
Referenced by QuaZipFile::open().
QStringList QuaZip::getFileNameList | ( | ) | const |
Definition at line 720 of file quazip.cpp.
References QuaZipPrivate::getFileInfoList(), and p.
QIODevice * QuaZip::getIoDevice | ( | ) | const |
Returns null string if no device has been set explicitly, for example when opening a ZIP file by name.
Definition at line 607 of file quazip.cpp.
References QuaZipPrivate::ioDevice, p, and QuaZipPrivate::zipName.
QuaZip::Mode QuaZip::getMode | ( | ) | const |
Definition at line 614 of file quazip.cpp.
References QuaZipPrivate::mode, and p.
Referenced by JlCompress::compressFile(), JlCompress::compressSubDir(), QuaZipFile::csize(), JlCompress::extractFile(), QuaZipFile::getFileInfo(), QuaZipFile::open(), and QuaZipFile::usize().
unzFile QuaZip::getUnzFile | ( | ) |
You can use this handle to directly call UNZIP part of the ZIP/UNZIP package functions (see unzip.h).
Definition at line 639 of file quazip.cpp.
References p.
Referenced by QuaZipFile::atEnd(), QuaZipFile::close(), QuaZipFile::csize(), QuaZipFile::open(), QuaZipFile::pos(), QuaZipFile::readData(), and QuaZipFile::usize().
int QuaZip::getZipError | ( | ) | const |
Returns UNZ_OK
if the last operation was successful.
Error code resets to UNZ_OK
every time you call any function that accesses something inside ZIP archive, even if it is const
(like getEntriesCount()). open() and close() calls reset error code too. See documentation for the specific functions for details on error detection.
Definition at line 624 of file quazip.cpp.
References p, and QuaZipPrivate::zipError.
Referenced by QuaZipFile::close(), JlCompress::compressDir(), JlCompress::compressFile(), JlCompress::compressFiles(), JlCompress::extractDir(), JlCompress::extractFile(), JlCompress::extractFiles(), QuaZipFile::getActualFileName(), QuaZipFile::getFileInfo(), JlCompress::getFileList(), and QuaZipFile::open().
zipFile QuaZip::getZipFile | ( | ) |
You can use this handle to directly call ZIP part of the ZIP/UNZIP package functions (see zip.h). Warnings about the getUnzFile() function also apply to this function.
Definition at line 644 of file quazip.cpp.
References p.
Referenced by QuaZipFile::close(), QuaZipFile::open(), and QuaZipFile::writeData().
QString QuaZip::getZipName | ( | ) | const |
Returns null string if no ZIP file name has been set, for example when the QuaZip instance is set up to use a QIODevice instead.
Definition at line 602 of file quazip.cpp.
References p, and QuaZipPrivate::zipName.
Referenced by JlCompress::compressSubDir(), and QuaZipFile::getZipName().
bool QuaZip::goToFirstFile | ( | ) |
Returns true
on success, false
otherwise. Call getZipError() to get the error code.
Definition at line 466 of file quazip.cpp.
References QuaZipPrivate::hasCurrentFile_f, mdUnzip, QuaZipPrivate::mode, p, UNZ_OK, unzGoToFirstFile(), and QuaZipPrivate::zipError.
Referenced by JlCompress::extractDir(), QuaZipPrivate::getFileInfoList(), and JlCompress::getFileList().
bool QuaZip::goToNextFile | ( | ) |
Returns true
on success, false
otherwise. Call getZipError() to determine if there was an error.
Should be used only in QuaZip::mdUnzip mode.
UNZ_OK
instead of UNZ_END_OF_LIST_OF_FILE
. This is to make things like this easier: Definition at line 478 of file quazip.cpp.
References QuaZipPrivate::hasCurrentFile_f, mdUnzip, QuaZipPrivate::mode, p, UNZ_END_OF_LIST_OF_FILE, UNZ_OK, unzGoToNextFile(), and QuaZipPrivate::zipError.
Referenced by JlCompress::extractDir(), QuaZipPrivate::getFileInfoList(), JlCompress::getFileList(), and setCurrentFile().
bool QuaZip::hasCurrentFile | ( | ) | const |
Definition at line 634 of file quazip.cpp.
References QuaZipPrivate::hasCurrentFile_f, and p.
Referenced by getCurrentFileInfo(), getCurrentFileName(), QuaZipPrivate::getFileInfoList(), and QuaZipFile::open().
bool QuaZip::isAutoClose | ( | ) | const |
Definition at line 780 of file quazip.cpp.
References QuaZipPrivate::autoClose, and p.
bool QuaZip::isDataDescriptorWritingEnabled | ( | ) | const |
Definition at line 654 of file quazip.cpp.
References QuaZipPrivate::dataDescriptorWritingEnabled, and p.
Referenced by QuaZipFile::open().
bool QuaZip::isOpen | ( | ) | const |
Definition at line 619 of file quazip.cpp.
References mdNotOpen, QuaZipPrivate::mode, and p.
Referenced by QuaZipFile::close(), getCurrentFileInfo(), getCurrentFileName(), open(), setIoDevice(), setZipName(), and ~QuaZip().
bool QuaZip::isZip64Enabled | ( | ) | const |
true
if and only if the zip64 mode is enabled.Definition at line 775 of file quazip.cpp.
References p, and QuaZipPrivate::zip64.
Referenced by QuaZipFile::open().
bool QuaZip::open | ( | Mode | mode, |
zlib_filefunc_def * | ioApi = NULL |
||
) |
Argument mode specifies open mode of the ZIP archive. See Mode for details. Note that there is zipOpen2() function in the ZIP/UNZIP API which accepts globalcomment argument, but it does not use it anywhere, so this open() function does not have this argument. See setComment() if you need to set global comment.
If the ZIP file is accessed via explicitly set QIODevice, then this device is opened in the necessary mode. If the device was already opened by some other means, then QuaZIP checks if the open mode is compatible to the mode needed for the requested operation. If necessary, seeking is performed to position the device properly.
true
if successful, false
otherwise.NULL
indicating an error. But to make things easier, quazip.h header defines additional error code UNZ_ERROROPEN
and getZipError() will return it if the open call of the ZIP/UNZIP API returns NULL
.Argument ioApi specifies IO function set for ZIP/UNZIP package to use. See unzip.h, zip.h and ioapi.h for details. Note that IO API for QuaZip is different from the original package. The file path argument was changed to be of type voidpf
, and QuaZip passes a QIODevice pointer there. This QIODevice is either set explicitly via setIoDevice() or the QuaZip(QIODevice*) constructor, or it is created internally when opening the archive by its file name. The default API (qioapi.cpp) just delegates everything to the QIODevice API. Not only this allows to use a QIODevice instead of file name, but also has a nice side effect of raising the file size limit from 2G to 4G (in non-zip64 archives).
In short: just forget about the ioApi argument and you'll be fine.
Definition at line 215 of file quazip.cpp.
References APPEND_STATUS_ADDINZIP, APPEND_STATUS_CREATE, APPEND_STATUS_CREATEAFTER, QuaZipPrivate::autoClose, QuaZipPrivate::dataDescriptorWritingEnabled, QuaZipPrivate::ioDevice, isOpen(), mdAdd, mdAppend, mdCreate, mdUnzip, QuaZipPrivate::mode, p, UNZ_AUTO_CLOSE, UNZ_OK, UNZ_OPENERROR, unzClearFlags(), unzClose(), unzOpen2(), unzOpenInternal(), unzSetFlags(), ZIP_AUTO_CLOSE, ZIP_SEQUENTIAL, ZIP_WRITE_DATA_DESCRIPTOR, zipClose(), QuaZipPrivate::zipError, QuaZipPrivate::zipName, zipOpen2(), zipOpen3(), and zipSetFlags().
Referenced by KbFirmware::_fileForBoard(), JlCompress::compressDir(), JlCompress::compressFile(), JlCompress::compressFiles(), JlCompress::extractDir(), JlCompress::extractFile(), JlCompress::extractFiles(), JlCompress::getFileList(), and QuaZipFile::open().
void QuaZip::setAutoClose | ( | bool | autoClose | ) | const |
By default, QuaZIP opens the underlying QIODevice when open() is called, and closes it when close() is called. In some cases, when the device is set explicitly using setIoDevice(), it may be desirable to leave the device open. If the auto-close flag is unset using this method, then the device isn't closed automatically if it was set explicitly.
If it is needed to clear this flag, it is recommended to do so before opening the archive because otherwise QuaZIP may close the device during the open() call if an error is encountered after the device is opened.
If the device was not set explicitly, but rather the setZipName() or the appropriate constructor was used to set the ZIP file name instead, then the auto-close flag has no effect, and the internal device is closed nevertheless because there is no other way to close it.
Definition at line 785 of file quazip.cpp.
References QuaZipPrivate::autoClose, and p.
void QuaZip::setComment | ( | const QString & | comment | ) |
The comment will be written to the archive on close operation. QuaZip makes a distinction between a null QByteArray() comment and an empty "" comment in the QuaZip::mdAdd mode. A null comment is the default and it means "don't change the comment". An empty comment removes the original comment.
Definition at line 629 of file quazip.cpp.
References QuaZipPrivate::comment, and p.
void QuaZip::setCommentCodec | ( | QTextCodec * | commentCodec | ) |
This codec defaults to locale codec, which is probably ok.
Definition at line 587 of file quazip.cpp.
References QuaZipPrivate::commentCodec, and p.
void QuaZip::setCommentCodec | ( | const char * | commentCodecName | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Equivalent to calling setCommentCodec(QTextCodec::codecForName(codecName));
Definition at line 592 of file quazip.cpp.
References QuaZipPrivate::commentCodec, and p.
bool QuaZip::setCurrentFile | ( | const QString & | fileName, |
CaseSensitivity | cs = csDefault |
||
) |
Returns true
if successful, false
otherwise. Argument cs specifies case sensitivity of the file name. Call getZipError() in the case of a failure to get error code.
This is not a wrapper to unzLocateFile() function. That is because I had to implement locale-specific case-insensitive comparison.
Here are the differences from the original implementation:
UNZ_OK
, not UNZ_END_OF_LIST_OF_FILE
(see also goToNextFile()).If fileName is null string then this function unsets the current file and return true
. Note that you should close the file first if it is open! See QuaZipFile::QuaZipFile(QuaZip*,QObject*) for the details.
Should be used only in QuaZip::mdUnzip mode.
Definition at line 408 of file quazip.cpp.
References convertCaseSensitivity(), current, QuaZipPrivate::directoryCaseInsensitive, QuaZipPrivate::directoryCaseSensitive, getCurrentFileName(), QuaZipPrivate::goToFirstUnmappedFile(), goToNextFile(), QuaZipPrivate::hasCurrentFile_f, MAX_FILE_NAME_LENGTH, mdUnzip, QuaZipPrivate::mode, p, unz64_file_pos_s::pos_in_zip_directory, UNZ_OK, UNZ_PARAMERROR, unzGoToFilePos64(), and QuaZipPrivate::zipError.
Referenced by KbFirmware::_fileForBoard(), JlCompress::extractFile(), QuaZipPrivate::getFileInfoList(), and QuaZipFile::open().
void QuaZip::setDataDescriptorWritingEnabled | ( | bool | enabled | ) |
According to the ZIP format specification, a file inside archive may have a data descriptor immediately following the file data. This is reflected by a special flag in the local file header and in the central directory. By default, QuaZIP sets this flag and writes the data descriptor unless both method and level were set to 0, in which case it operates in 1.0-compatible mode and never writes data descriptors.
By setting this flag to false, it is possible to disable data descriptor writing, thus increasing compatibility with archive readers that don't understand this feature of the ZIP file format.
Setting this flag affects all the QuaZipFile instances that are opened after this flag is set.
The data descriptor writing mode is enabled by default.
Note that if the ZIP archive is written into a QIODevice for which QIODevice::isSequential() returns true
, then the data descriptor is mandatory and will be written even if this flag is set to false.
enabled | If true , enable local descriptor writing, disable it otherwise. |
Definition at line 649 of file quazip.cpp.
References QuaZipPrivate::dataDescriptorWritingEnabled, and p.
|
static |
The default codec is used by the constructors, so calling this function won't affect the QuaZip instances already created at that moment.
The codec specified here can be overriden by calling setFileNameCodec(). If neither function is called, QTextCodec::codecForLocale() will be used to decode or encode file names. Use this function with caution if the application uses other libraries that depend on QuaZIP. Those libraries can either call this function by themselves, thus overriding your setting or can rely on the default encoding, thus failing mysteriously if you change it. For these reasons, it isn't recommended to use this function if you are developing a library, not an application. Instead, ask your library users to call it in case they need specific encoding.
In most cases, using setFileNameCodec() instead is the right choice. However, if you depend on third-party code that uses QuaZIP, then the reasons stated above can actually become a reason to use this function in case the third-party code in question fails because it doesn't understand the encoding you need and doesn't provide a way to specify it. This applies to the JlCompress class as well, as it was contributed and doesn't support explicit encoding parameters.
In short: use setFileNameCodec() when you can, resort to setDefaultFileNameCodec() when you don't have access to the QuaZip instance.
codec | The codec to use by default. If NULL, resets to default. |
Definition at line 760 of file quazip.cpp.
References QuaZipPrivate::defaultFileNameCodec.
Referenced by setDefaultFileNameCodec().
|
static |
Definition at line 765 of file quazip.cpp.
References setDefaultFileNameCodec().
void QuaZip::setFileNameCodec | ( | QTextCodec * | fileNameCodec | ) |
This is necessary to access files in the ZIP archive created under Windows with non-latin characters in file names. For example, file names with cyrillic letters will be in IBM866
encoding.
Definition at line 572 of file quazip.cpp.
References QuaZipPrivate::fileNameCodec, and p.
void QuaZip::setFileNameCodec | ( | const char * | fileNameCodecName | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Equivalent to calling setFileNameCodec(QTextCodec::codecForName(codecName));
Definition at line 577 of file quazip.cpp.
References QuaZipPrivate::fileNameCodec, and p.
void QuaZip::setIoDevice | ( | QIODevice * | ioDevice | ) |
Does nothing if the ZIP file is open.
Does not reset error code returned by getZipError().
Definition at line 365 of file quazip.cpp.
References QuaZipPrivate::ioDevice, isOpen(), p, and QuaZipPrivate::zipName.
void QuaZip::setZip64Enabled | ( | bool | zip64 | ) |
zip64 | If true , the zip64 mode is enabled, disabled otherwise. |
Once this is enabled, all new files (until the mode is disabled again) will be created in the zip64 mode, thus enabling the ability to write files larger than 4 GB. By default, the zip64 mode is off due to compatibility reasons.
Note that this does not affect the ability to read zip64 archives in any way.
Definition at line 770 of file quazip.cpp.
References p, and QuaZipPrivate::zip64.
void QuaZip::setZipName | ( | const QString & | zipName | ) |
Does nothing if the ZIP file is open.
Does not reset error code returned by getZipError().
Definition at line 355 of file quazip.cpp.
References QuaZipPrivate::ioDevice, isOpen(), p, and QuaZipPrivate::zipName.
|
friend |
|
private |
Definition at line 129 of file quazip.h.
Referenced by close(), getComment(), getCommentCodec(), getCurrentFileInfo(), getCurrentFileName(), getEntriesCount(), getFileInfoList(), getFileInfoList64(), getFileNameCodec(), getFileNameList(), getIoDevice(), getMode(), getUnzFile(), getZipError(), getZipFile(), getZipName(), goToFirstFile(), goToNextFile(), hasCurrentFile(), isAutoClose(), isDataDescriptorWritingEnabled(), isOpen(), isZip64Enabled(), open(), setAutoClose(), setComment(), setCommentCodec(), setCurrentFile(), setDataDescriptorWritingEnabled(), setFileNameCodec(), setIoDevice(), setZip64Enabled(), setZipName(), and ~QuaZip().