AbZip
1.5
|
Inherits QObject.
Public Member Functions | |
AbZip (QObject *parent=0) | |
Constructs the default AbZip object. You must use setZipFileName() before calling any other member functions. | |
AbZip (const QString &zipName, QObject *parent=0) | |
Constructs a AbZip for a specified Archive name. | |
AbZip (QIODevice *ioDevice, QObject *parent=0) | |
Constructs a AbZip for a given QIODevice. | |
virtual | ~AbZip () |
Destroys the AbZip and closes the archive. Central Directory changes are save at when close() is called. | |
bool | open (Mode mode=modeOpenRead, ZipOptions options=None) |
Opens the archive for either reading or writing. Note: If you don't call open() before calling one of the main add or extract functions, then AbZip will automatically open the archive in the required mode. (e.g If you call addDirectory() then it opens in modeOpenWrite, or if you call extractAll() and the archive is not already open, then it will be open with modeOpenRead. This mode will remain untill you call close(). More... | |
void | close () |
Closes the archive if open. If any file delete operations are pending, then these are commited at this point. More... | |
bool | isOpen () |
Checks if the archive is open or not. More... | |
bool | addFile (const QString &file, const QString &root, ZipOptions options=AddRelativePaths, int level=-1) |
Adds the specified file to the archive. If the file already exists and has the same last modified date, then the file will not be added. If SkipExistingFiles option is specified, then existing files will not be overwritten even if they are older. If AddReplaceFiles option is specified, then the file will be added even if it is older then the existing file. More... | |
bool | addFile (const QString &file, ZipOptions options=AddRelativePaths, int level=-1) |
Adds the specified file to the archive. If the file already exists and has the same last modified date, then the file will not be added. If SkipExistingFiles option is specified, then existing files will not be overwritten even if they are older. If AddReplaceFiles option is specified, then the file will be added even if it is older then the existing file. More... | |
bool | addDirectory (const QString &srcPath, const QString &root, ZipOptions options=AddRelativePaths, int level=-1) |
Add all files in a directory to the archive. You can set filters to only add files that match a specified mask (See setNameFilters() ). By specifying the Recursive option, you can add all files from all sub folders. More... | |
bool | addDirectory (const QString &srcPath, ZipOptions options=AddRelativePaths, int level=-1) |
Add all files in a directory to the archive. You can set filters to only add files that match a specified mask (See setNameFilters() ). By specifying the Recursive option, you can add all fiels from all sub folders. See options for further. More... | |
bool | extractAll (const QString &destPath, ZipOptions options=ExtractPaths) |
Extract all files from the archive to a specified destination path If ContinueOnError option is not specified, then the operation will stop if any errors are encountered. More... | |
bool | extractAll (const QString &destPath, const QString &fromRoot, ZipOptions options=ExtractPaths) |
Extract all files from the specified root archive folder to a specified destination path. If ContinueOnError option is not specified, then the operation will stop if any errors are encountered. More... | |
bool | extractFile (const QString &filename, const QString &destPath, ZipOptions options=ExtractPaths) |
Extract the specified file from the archive to a specified destination folder. More... | |
bool | extractFiles (const QStringList &listFiles, const QString &destPath, ZipOptions options=ExtractPaths) |
Extract all files from the specified listFiles and save them to the destination folder. If ContinueOnError option is not specified, then the operation will stop if any errors are encountered. More... | |
bool | deleteFile (const QString &filename, ZipOptions options=AbZip::None) |
Delete the specified file from the archive. Note: The file data is only removed from the archive when you call close() More... | |
bool | renameFile (const QString &oldFilename, const QString &newFilename, AbZip::ZipOptions options=AbZip::None) |
Rename the specified file to a new name in the archive. If teh new file name exists, then this function will return false . More... | |
bool | checkIntegrity () |
This function performs a full integrity check of the archive file. Including badly formed Central Directories, mismating local headers and corrupted file data. This function is the equivalent to calling extractAll( "", AbZip::VerifyOnly );. More... | |
bool | repairArchive () |
This function will attempt to repair a broken archive. This normally involves rebuilding the Central Directory by reading the file from the start and locating each LocalHeader and creating new Central Directory Header entry for it. This function will make a copy of the old archive prior to repair. Note: The process of recovering a damages Central Directory is performed automatically. More... | |
QList< ZipFileInfo > | findFile (const QString &filename, ZipOptions options=Recursive) |
This searches the archive for a matching file spec. If found, then a ZipFileInfo structure is filled containing the zip file information about that file. More... | |
QList< ZipFileInfo > | findFile (const QString &filename, const QString &root, ZipOptions options=Recursive) |
This searches the archive for a matching file spec. If found, then a ZipFileInfo structure is filled containing the zip file information about that file. More... | |
void | setNameFilters (const QStringList &nameFilters) |
This allows you to set specific name filters when adding, extractinmg or searching for files. Each name filter is a wildcard filter that understands * and ? wildcards. (See QRegExp wildcard matching.) More... | |
void | clearNameFilters () |
Clears and previously set name filters. More... | |
void | setPassword (const QString &password) |
If a password is set during an add operation, then the file will be encrypted. If you extracting an existing encrypted file, then you must call this function to set the password for decryption. More... | |
void | clearPassword () |
Clears a previously set encryption/decryption password. More... | |
int | errorCode () const |
All functions return either true for success or false if an error occurred. Call this function to retrieve the last known error code. Note: Errors are accumilative whilst the archive is open, call clearErrors() to reset the error code, count and message. More... | |
int | errorCount () const |
On multiple file operations (e.g. addDirectory() or extractAll() ) and the option ContinueOnError has been set, then this will return the total number of errors that occurred. Note: Errors are accumilative whilst the archive is open, call clearErrors() to reset the error code, count and message. More... | |
const QString & | errorString () const |
Returns a human-readable description of the last error that occurred. On operations that perform multiple tasks, then multiple error messsages are returned separated by a new line character. Note: Errors are accumilative whilst the archive is open, call clearErrors() to reset the error code, count and message. More... | |
void | clearErrors () |
This resets the error code, error count and last error message. | |
bool | setComment (const QString &comment) |
Call this function to add your own comment stored in the archives central directory. More... | |
QString | getComment () const |
Gets any comment that may be present in the archives central directory. This is also returned with getInfo() More... | |
ZipInfo | getInfo () const |
This function will return core information about the archive (e.g. Comment, Total compressed size, total uncompressed size, file count, version, total files added, extracted and deleted) More... | |
void | setZipFileName (const QString &name) |
enum AbZip::Mode |
enum AbZip::ErrorCode |
Error codes. For all errors other than Ok, call errorString() to retrieve the error message.
Enumerator | |
---|---|
Ok |
No Error. |
GeneralError |
General error message. |
CreateDirError |
Failed to create a new folder. |
OpenFileError |
Unable to open the archive file or the file being added. |
CreateFileError |
Unable to create a temporary file for extraction. |
InvalidArchive |
Unable to read the Central Directory form the archive file. It's either correcpt or not a valid Zip file. |
SeekError |
Failed to locate Local File Header in the zip file. Most likely a corrupt Central Directory record. |
OpenInReadOnly |
The Archive is open in Read mode and you are trying to perform a write action. Close and re-open for writing. |
FileExists |
The file to be extracted already exists and you have specified the AbZip::DontOverwrite option. |
ExtractFailed |
An error occurred extracting the file data from the archive. See errorString() for more information. |
AddFileFailed |
A error occurred compressing and adding the data to the archive. See errorString() for more information. |
CopyError |
An error occurred copying the temporary extracted file to the destination folder. |
SetModTimeFailed |
Unable to set the last modified time for the extracted file to that stored in the archive. |
InvalidCompressor |
The decompression method required to extract the file is not supported by this library. |
InvalidEncryption |
The decryption method required to extract the file is not supported by this library. |
DeleteError |
An error occurred writing to a temp archive while deleting files from the current archive. |
Corrupted |
Corrupt data found during extraction. CRC or AES validation failed. |
InvalidPassword |
Invalid password specified for decryption. |
InvalidAesData |
Invalid WinZip AES extra data specified. |
FileNotFound |
The file to be added or extracted was not found. |
WriteFailed |
An error occurred writing the Central Directory to file. |
HeaderIntegrityError |
The Central Directory Header file does not match the Local File Header. |
CentralDirError |
An error has occurred in reading the Central Directory. |
enum AbZip::Option |
Archive options.
Enumerator | |
---|---|
VerifyOnly |
Used to verity the integrity of the archive. This is only valis on all 'extract' function calls See also checkIntegrity(). |
CaseSensitive |
When searching for files in the archive or to add to the archive, use Case Sensitive matching. |
Recursive |
When searching or adding directories, recurse into all sub folders. |
DontOverwrite |
If specified, existing local files will not be overwritten. |
IgnoreFolders |
Ignore folders when searching the archive. |
IgnoreFiles |
Ignore files when searching the archive. |
BackupExisting |
If set and the open mode modeCreateNew is used, then if the archive exists it will be rename with an incremental number added to the file name (e.g. 'file.zip' becomes 'file (1).zip' and a new 'file.zip' created) |
ExtractPaths |
Recreate the relative path from the archive when extracting files. |
AddRelativePaths |
Add files including relative paths. |
AddAbsolutePaths |
Add files to the archive and store using the files absolute path. |
AddIgnorePaths |
All files are put in the root of the archive file. This is not a good options to use as you may get files with the same name being added and if SkipExistingFiles is not set then the original file will be overwritten! |
AddReplaceFiles |
Always add and replace files that exists and ignore if different. |
SkipExistingFiles |
Don't overwrite any files of the same file name and location in archive. |
ContinueOnError |
On operations that add or extract multiple files, then continue if an error occures. |
IgnoreStoreOnlyChecks |
AbZip will detect any files that it thinks should not be compressed and store them raw (e.g. files that are already compressed). If you want to ignore this feature, then specify this option. |
useBZip2Compression |
For the use of BZip2 compression over the default Deflate compression. BZip2 give a much higher compression ratio but takes longer. |
useAESEncryption |
Use WinZip AES strong encryption over the default crc encryption. |
useLzmaCompression |
Use Lzma compression over the default. WARNING: This compression method is not yet compatible with other arching software. If you need higher compression levels and compatibilty then use BZip2. |
SortByName |
findFile(): Sort by file name |
SortByTime |
findFile(): Sort by last modified date/time |
SortByCompressedSize |
findFile(): Sort by compresses size |
SortByUncompressedSize |
findFile(): Sort by uncompressed size |
SortByType |
findFile(): Sort by file type |
SortReversed |
findFile(): Reverse the sort order |
bool AbZip::open | ( | Mode | mode = modeOpenRead , |
ZipOptions | options = None |
||
) |
Opens the archive for either reading or writing. Note: If you don't call open() before calling one of the main add or extract functions, then AbZip will automatically open the archive in the required mode. (e.g If you call addDirectory() then it opens in modeOpenWrite, or if you call extractAll() and the archive is not already open, then it will be open with modeOpenRead. This mode will remain untill you call close().
mode | The open mode for the archive (Default: modeOpenRead) |
options | This is either None (default) or use BackupExisting with modeCreateNew |
true
if successful otherwise false
. See errorCode() and errorString() for information on the errorvoid AbZip::close | ( | ) |
Closes the archive if open. If any file delete operations are pending, then these are commited at this point.
bool AbZip::isOpen | ( | ) |
Checks if the archive is open or not.
true
if the archive is open, else false
bool AbZip::addFile | ( | const QString & | file, |
const QString & | root, | ||
ZipOptions | options = AddRelativePaths , |
||
int | level = -1 |
||
) |
Adds the specified file to the archive. If the file already exists and has the same last modified date, then the file will not be added. If SkipExistingFiles option is specified, then existing files will not be overwritten even if they are older. If AddReplaceFiles option is specified, then the file will be added even if it is older then the existing file.
file | The full path and file name for the file to be added. |
root | (optional) The directory in the archive to store this file. |
options | Options to apply during adding. |
level | (optional) The level to use for compression from 0 = no compression to 9 high compression but slower (default is 8). |
true
if successful otherwise false
. See errorCode() and errorString() for information on the errorReferenced by clearNameFilters().
bool AbZip::addFile | ( | const QString & | file, |
ZipOptions | options = AddRelativePaths , |
||
int | level = -1 |
||
) |
Adds the specified file to the archive. If the file already exists and has the same last modified date, then the file will not be added. If SkipExistingFiles option is specified, then existing files will not be overwritten even if they are older. If AddReplaceFiles option is specified, then the file will be added even if it is older then the existing file.
file | The full path and file name for the file to be added. |
options | Options to apply during adding. |
level | (optional) The level to use for compression from 0 = no compression to 9 high compression but slower (default is 8). |
true
if successful otherwise false
. See errorCode() and errorString() for information on the errorbool AbZip::addDirectory | ( | const QString & | srcPath, |
const QString & | root, | ||
ZipOptions | options = AddRelativePaths , |
||
int | level = -1 |
||
) |
Add all files in a directory to the archive. You can set filters to only add files that match a specified mask (See setNameFilters() ). By specifying the Recursive option, you can add all files from all sub folders.
srcPath | The full path to the folder to add files |
root | Use this as the root folder when adding to the archive. e.g. If root is 'backup/files' and we are adding 'c:/folder1/folder2/file1 .txt' and 'c:/folder1/folder2/folder3/file2 .txt' then
|
options | Options to apply during adding. |
level | (optional) The level to use for compression from 0 = no compression to 9 high compression but slower (default is 8). |
true
if successful otherwise false
. See errorCode() and errorString() for information on the errorReferenced by clearNameFilters().
bool AbZip::addDirectory | ( | const QString & | srcPath, |
ZipOptions | options = AddRelativePaths , |
||
int | level = -1 |
||
) |
Add all files in a directory to the archive. You can set filters to only add files that match a specified mask (See setNameFilters() ). By specifying the Recursive option, you can add all fiels from all sub folders. See options for further.
srcPath | The full path to the folder to add files |
options | Options to apply during adding. |
level | (optional) The level to use for compression from 0 = no compression to 9 high compression but slower (default is 8). |
true
if successful otherwise false
. See errorCode() and errorString() for information on the errorbool AbZip::extractAll | ( | const QString & | destPath, |
ZipOptions | options = ExtractPaths |
||
) |
Extract all files from the archive to a specified destination path If ContinueOnError option is not specified, then the operation will stop if any errors are encountered.
destPath | The full path name to where to extract the files |
options | Options use for extracting |
true
if successful otherwise false
. See errorCode() and errorString() for information on the errorReferenced by renameFile().
bool AbZip::extractAll | ( | const QString & | destPath, |
const QString & | fromRoot, | ||
ZipOptions | options = ExtractPaths |
||
) |
Extract all files from the specified root archive folder to a specified destination path. If ContinueOnError option is not specified, then the operation will stop if any errors are encountered.
destPath | The full path name to where to extract the files |
fromRoot | Extract all file from this root folder within the archive |
options | Options use for extracting |
true
if successful otherwise false
. See errorCode() and errorString() for information on the error bool AbZip::extractFile | ( | const QString & | filename, |
const QString & | destPath, | ||
ZipOptions | options = ExtractPaths |
||
) |
Extract the specified file from the archive to a specified destination folder.
filename | This is the full path and filename of the file to extract. |
destPath | The full path name to where to extract the file. |
options | Options use for extracting |
true
if successful otherwise false
. See errorCode() and errorString() for information on the errorbool AbZip::extractFiles | ( | const QStringList & | listFiles, |
const QString & | destPath, | ||
ZipOptions | options = ExtractPaths |
||
) |
Extract all files from the specified listFiles and save them to the destination folder. If ContinueOnError option is not specified, then the operation will stop if any errors are encountered.
listFiles | A QstringList containing all the files to extract |
destPath | The full path name to where to extract the file. |
options | Options use for extracting |
true
if successful otherwise false
. See errorCode() and errorString() for information on the errorReferences ContinueOnError.
bool AbZip::deleteFile | ( | const QString & | filename, |
ZipOptions | options = AbZip::None |
||
) |
Delete the specified file from the archive. Note: The file data is only removed from the archive when you call close()
filename | The full path and filename to the file within the archive to be deleted. Wildcard specifications can be used to delete all files matching a wildcard spec. (e.g. "*.pdf" will delete all files in the archive with a '.pdf' file extention) |
options | Options use for extracting |
true
if successful otherwise false
. See errorCode() and errorString() for information on the errorbool AbZip::renameFile | ( | const QString & | oldFilename, |
const QString & | newFilename, | ||
AbZip::ZipOptions | options = AbZip::None |
||
) |
Rename the specified file to a new name in the archive. If teh new file name exists, then this function will return false
.
oldFilename | The full path and filename to the old file within the archive. |
newFilename | The full path and filename to the new file name. |
options | Options use for extracting |
true
if successful otherwise false
. See errorCode() and errorString() for information on the error References extractAll().
bool AbZip::checkIntegrity | ( | ) |
This function performs a full integrity check of the archive file. Including badly formed Central Directories, mismating local headers and corrupted file data. This function is the equivalent to calling extractAll( "", AbZip::VerifyOnly );.
true
if successful otherwise false
. See errorCode() and errorString() for information on the error bool AbZip::repairArchive | ( | ) |
This function will attempt to repair a broken archive. This normally involves rebuilding the Central Directory by reading the file from the start and locating each LocalHeader and creating new Central Directory Header entry for it. This function will make a copy of the old archive prior to repair. Note: The process of recovering a damages Central Directory is performed automatically.
true
if successful otherwise false
. See errorCode() and errorString() for information on the error QList< ZipFileInfo > AbZip::findFile | ( | const QString & | filename, |
ZipOptions | options = Recursive |
||
) |
This searches the archive for a matching file spec. If found, then a ZipFileInfo structure is filled containing the zip file information about that file.
filename | The filename to search for. Filename wildcards can be used (e.g. '*.pdf' or 'accounts ) |
options | Options use for the search (e.g. Recursive, CaseSensitive ) |
QList< ZipFileInfo > AbZip::findFile | ( | const QString & | filename, |
const QString & | root, | ||
ZipOptions | options = Recursive |
||
) |
This searches the archive for a matching file spec. If found, then a ZipFileInfo structure is filled containing the zip file information about that file.
filename | The filename to search for. Filename wildcards can be used (e.g. '*.pdf' or 'accounts ) |
root | This is the archive folder to search from. |
options | Options use for the search (e.g. Recursive, CaseSensitive ) |
void AbZip::setNameFilters | ( | const QStringList & | nameFilters | ) |
This allows you to set specific name filters when adding, extractinmg or searching for files. Each name filter is a wildcard filter that understands * and ? wildcards. (See QRegExp wildcard matching.)
nameFilters | A QStringList containing one or more name filters (e.g. QStringList() << "*.pdf" << "*.doc" ) |
void AbZip::clearNameFilters | ( | ) |
Clears and previously set name filters.
References addDirectory(), and addFile().
void AbZip::setPassword | ( | const QString & | password | ) |
If a password is set during an add operation, then the file will be encrypted. If you extracting an existing encrypted file, then you must call this function to set the password for decryption.
Note: The default encryption uses the standard PKWARE encryption which is considered weak by todays standards and its use is recommended only for situations with low security needs or for compatibility with older .ZIP applications. For higher security situations it's recommended that you use the option useAESEncryption.
password | The password use for encryption |
void AbZip::clearPassword | ( | ) |
Clears a previously set encryption/decryption password.
int AbZip::errorCode | ( | ) | const |
All functions return either true for success or false if an error occurred. Call this function to retrieve the last known error code. Note: Errors are accumilative whilst the archive is open, call clearErrors() to reset the error code, count and message.
int AbZip::errorCount | ( | ) | const |
On multiple file operations (e.g. addDirectory() or extractAll() ) and the option ContinueOnError has been set, then this will return the total number of errors that occurred. Note: Errors are accumilative whilst the archive is open, call clearErrors() to reset the error code, count and message.
const QString & AbZip::errorString | ( | ) | const |
Returns a human-readable description of the last error that occurred. On operations that perform multiple tasks, then multiple error messsages are returned separated by a new line character. Note: Errors are accumilative whilst the archive is open, call clearErrors() to reset the error code, count and message.
bool AbZip::setComment | ( | const QString & | comment | ) |
Call this function to add your own comment stored in the archives central directory.
comment | The comment to add to the archive. |
true
if successful otherwise false
. See errorCode() and errorString() for information on the error QString AbZip::getComment | ( | ) | const |
ZipInfo AbZip::getInfo | ( | ) | const |