From a53f8d506e212f862f54e5a758fb50666ec7c3ba Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Thu, 12 Feb 2015 22:01:20 +0100 Subject: GH-366: Plain and simple modpack export/import/download Also removed the in-source QuaZIP in favour of upstream version --- depends/quazip/CMakeLists.txt | 31 - depends/quazip/JlCompress.cpp | 522 ------------- depends/quazip/JlCompress.h | 125 --- depends/quazip/crypt.h | 135 ---- depends/quazip/ioapi.h | 77 -- depends/quazip/qioapi.cpp | 146 ---- depends/quazip/quaadler32.cpp | 28 - depends/quazip/quaadler32.h | 29 - depends/quazip/quachecksum32.h | 54 -- depends/quazip/quacrc32.cpp | 28 - depends/quazip/quacrc32.h | 26 - depends/quazip/quagzipfile.cpp | 141 ---- depends/quazip/quagzipfile.h | 35 - depends/quazip/quaziodevice.cpp | 283 ------- depends/quazip/quaziodevice.h | 27 - depends/quazip/quazip.cpp | 554 ------------- depends/quazip/quazip.h | 411 ---------- depends/quazip/quazip_global.h | 55 -- depends/quazip/quazipdir.cpp | 507 ------------ depends/quazip/quazipdir.h | 171 ---- depends/quazip/quazipfile.cpp | 488 ------------ depends/quazip/quazipfile.h | 442 ----------- depends/quazip/quazipfileinfo.h | 66 -- depends/quazip/quazipnewinfo.cpp | 51 -- depends/quazip/quazipnewinfo.h | 102 --- depends/quazip/unzip.c | 1603 -------------------------------------- depends/quazip/unzip.h | 356 --------- depends/quazip/zip.c | 1281 ------------------------------ depends/quazip/zip.h | 245 ------ 29 files changed, 8019 deletions(-) delete mode 100644 depends/quazip/CMakeLists.txt delete mode 100644 depends/quazip/JlCompress.cpp delete mode 100644 depends/quazip/JlCompress.h delete mode 100644 depends/quazip/crypt.h delete mode 100644 depends/quazip/ioapi.h delete mode 100644 depends/quazip/qioapi.cpp delete mode 100644 depends/quazip/quaadler32.cpp delete mode 100644 depends/quazip/quaadler32.h delete mode 100644 depends/quazip/quachecksum32.h delete mode 100644 depends/quazip/quacrc32.cpp delete mode 100644 depends/quazip/quacrc32.h delete mode 100644 depends/quazip/quagzipfile.cpp delete mode 100644 depends/quazip/quagzipfile.h delete mode 100644 depends/quazip/quaziodevice.cpp delete mode 100644 depends/quazip/quaziodevice.h delete mode 100644 depends/quazip/quazip.cpp delete mode 100644 depends/quazip/quazip.h delete mode 100644 depends/quazip/quazip_global.h delete mode 100644 depends/quazip/quazipdir.cpp delete mode 100644 depends/quazip/quazipdir.h delete mode 100644 depends/quazip/quazipfile.cpp delete mode 100644 depends/quazip/quazipfile.h delete mode 100644 depends/quazip/quazipfileinfo.h delete mode 100644 depends/quazip/quazipnewinfo.cpp delete mode 100644 depends/quazip/quazipnewinfo.h delete mode 100644 depends/quazip/unzip.c delete mode 100644 depends/quazip/unzip.h delete mode 100644 depends/quazip/zip.c delete mode 100644 depends/quazip/zip.h (limited to 'depends') diff --git a/depends/quazip/CMakeLists.txt b/depends/quazip/CMakeLists.txt deleted file mode 100644 index b5787307..00000000 --- a/depends/quazip/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -project(quazip) - -# Find ZLIB for quazip -# Use system zlib on unix and Qt ZLIB on Windows -if(UNIX) - find_package(ZLIB REQUIRED) -else(UNIX) - get_filename_component(ZLIB_FOUND_DIR "${Qt5Core_DIR}/../../../include/QtZlib" ABSOLUTE) - set(ZLIB_INCLUDE_DIRS ${ZLIB_FOUND_DIR} CACHE PATH "Path to ZLIB headers of Qt") - set(ZLIB_LIBRARIES "") - if(NOT EXISTS "${ZLIB_INCLUDE_DIRS}/zlib.h") - message("Please specify a valid zlib include dir") - endif(NOT EXISTS "${ZLIB_INCLUDE_DIRS}/zlib.h") -endif(UNIX) - -# set all include directories for in and out of source builds -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} - ${ZLIB_INCLUDE_DIRS} -) - -file(GLOB SRCS "*.c" "*.cpp") -file(GLOB PUBLIC_HEADERS "*.h") - -# Static link! -add_definitions(-DQUAZIP_STATIC) - -add_library(quazip STATIC ${SRCS}) -qt5_use_modules(quazip Core) -target_link_libraries(quazip ${ZLIB_LIBRARIES}) diff --git a/depends/quazip/JlCompress.cpp b/depends/quazip/JlCompress.cpp deleted file mode 100644 index a6cf0eaf..00000000 --- a/depends/quazip/JlCompress.cpp +++ /dev/null @@ -1,522 +0,0 @@ -#include "JlCompress.h" -#include - -bool JlCompress::copyData(QIODevice &inFile, QIODevice &outFile) -{ - while (!inFile.atEnd()) { - char buf[4096]; - qint64 readLen = inFile.read(buf, 4096); - if (readLen <= 0) - return false; - if (outFile.write(buf, readLen) != readLen) - return false; - } - return true; -} - -/**OK - * Comprime il file fileName, nell'oggetto zip, con il nome fileDest. - * - * La funzione fallisce se: - * * zip==NULL; - * * l'oggetto zip e stato aperto in una modalita non compatibile con l'aggiunta di file; - * * non e possibile aprire il file d'origine; - * * non e possibile creare il file all'interno dell'oggetto zip; - * * si e rilevato un errore nella copia dei dati; - * * non e stato possibile chiudere il file all'interno dell'oggetto zip; - */ -bool JlCompress::compressFile(QuaZip* zip, QString fileName, QString fileDest) { - // zip: oggetto dove aggiungere il file - // fileName: nome del file reale - // fileDest: nome del file all'interno del file compresso - - // Controllo l'apertura dello zip - if (!zip) return false; - if (zip->getMode()!=QuaZip::mdCreate && - zip->getMode()!=QuaZip::mdAppend && - zip->getMode()!=QuaZip::mdAdd) return false; - - // Apro il file originale - QFile inFile; - inFile.setFileName(fileName); - if(!inFile.open(QIODevice::ReadOnly)) return false; - - // Apro il file risulato - QuaZipFile outFile(zip); - if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(fileDest, inFile.fileName()))) return false; - - // Copio i dati - if (!copyData(inFile, outFile) || outFile.getZipError()!=UNZ_OK) { - return false; - } - - // Chiudo i file - outFile.close(); - if (outFile.getZipError()!=UNZ_OK) return false; - inFile.close(); - - return true; -} - -/**OK - * Comprime la cartella dir nel file fileCompressed, se recursive e true allora - * comprime anche le sotto cartelle. I nomi dei file preceduti dal path creato - * togliendo il pat della cartella origDir al path della cartella dir. - * Se la funzione fallisce restituisce false e cancella il file che si e tentato - * di creare. - * - * La funzione fallisce se: - * * zip==NULL; - * * l'oggetto zip e stato aperto in una modalita non compatibile con l'aggiunta di file; - * * la cartella dir non esiste; - * * la compressione di una sotto cartella fallisce (1); - * * la compressione di un file fallisce; - * (1) La funzione si richiama in maniera ricorsiva per comprimere le sotto cartelle - * dunque gli errori di compressione di una sotto cartella sono gli stessi di questa - * funzione. - */ -bool JlCompress::compressSubDir( QuaZip* parentZip, QString dir, QString parentDir, bool recursive, QSet& added ) -{ - // zip: oggetto dove aggiungere il file - // dir: cartella reale corrente - // origDir: cartella reale originale - // (path(dir)-path(origDir)) = path interno all'oggetto zip - - // Controllo l'apertura dello zip - if (!parentZip ) return false; - if ( parentZip->getMode()!=QuaZip::mdCreate && - parentZip->getMode()!=QuaZip::mdAppend && - parentZip->getMode()!=QuaZip::mdAdd) return false; - - // Controllo la cartella - QDir directory(dir); - if (!directory.exists()) return false; - - // Se comprimo anche le sotto cartelle - if (recursive) { - // Per ogni sotto cartella - QFileInfoList files = directory.entryInfoList(QDir::AllDirs|QDir::NoDotAndDotDot); - Q_FOREACH (QFileInfo file, files) - { - // Comprimo la sotto cartella - if(!compressSubDir( parentZip,file.absoluteFilePath(),parentDir,recursive,added)) return false; - } - } - - // Per ogni file nella cartella - QFileInfoList files = directory.entryInfoList(QDir::Files); - QDir origDirectory( parentDir ); - Q_FOREACH (QFileInfo file, files) - { - // Se non e un file o e il file compresso che sto creando - if(!file.isFile()||file.absoluteFilePath()==parentZip->getZipName()) continue; - - // Creo il nome relativo da usare all'interno del file compresso - QString filename = origDirectory.relativeFilePath(file.absoluteFilePath()); - - // Comprimo il file - if (!compressFile( parentZip,file.absoluteFilePath(),filename)) - return false; - added.insert(filename); - } - - return true; -} - -/**OK - * Estrae il file fileName, contenuto nell'oggetto zip, con il nome fileDest. - * Se la funzione fallisce restituisce false e cancella il file che si e tentato di estrarre. - * - * La funzione fallisce se: - * * zip==NULL; - * * l'oggetto zip e stato aperto in una modalita non compatibile con l'estrazione di file; - * * non e possibile aprire il file all'interno dell'oggetto zip; - * * non e possibile creare il file estratto; - * * si e rilevato un errore nella copia dei dati (1); - * * non e stato possibile chiudere il file all'interno dell'oggetto zip (1); - * - * (1): prima di uscire dalla funzione cancella il file estratto. - */ -bool JlCompress::extractFile(QuaZip* zip, QString fileName, QString fileDest) { - // zip: oggetto dove aggiungere il file - // filename: nome del file reale - // fileincompress: nome del file all'interno del file compresso - - // Controllo l'apertura dello zip - if (!zip) return false; - if (zip->getMode()!=QuaZip::mdUnzip) return false; - - // Apro il file compresso - if (!fileName.isEmpty()) - zip->setCurrentFile(fileName); - QuaZipFile inFile(zip); - if(!inFile.open(QIODevice::ReadOnly) || inFile.getZipError()!=UNZ_OK) return false; - - // Controllo esistenza cartella file risultato - QDir curDir; - if (!curDir.mkpath(QFileInfo(fileDest).absolutePath())) { - return false; - } - - if (QFileInfo(fileDest).isDir()) - return true; - - // Apro il file risultato - QFile outFile; - outFile.setFileName(fileDest); - if(!outFile.open(QIODevice::WriteOnly)) return false; - - // 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; - } - - return true; -} - -/** - * Rimuove i file il cui nome e specificato all'interno di listFile. - * Restituisce true se tutti i file sono stati cancellati correttamente, attenzione - * perche puo restituire false anche se alcuni file non esistevano e si e tentato - * di cancellarli. - */ -bool JlCompress::removeFile(QStringList listFile) { - bool ret = true; - // Per ogni file - for (int i=0; i added; - // Aggiungo i file e le sotto cartelle - if (!compressSubDir(&zip,dir,dir,recursive, added)) - { - QFile::remove(fileCompressed); - return false; - } - - // Chiudo il file zip - zip.close(); - if(zip.getZipError()!=0) { - QFile::remove(fileCompressed); - return false; - } - - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -/**OK - * Estrae il file fileName, contenuto nel file fileCompressed, con il nome fileDest. - * Se fileDest = "" allora il file viene estratto con lo stesso nome con cui e - * stato compresso. - * Se la funzione fallisce cancella il file che si e tentato di estrarre. - * Restituisce il nome assoluto del file estratto. - * - * La funzione fallisce se: - * * non si riesce ad aprire l'oggetto zip; - * * l'estrazione del file fallisce; - * * non si riesce a chiudere l'oggetto zip; - */ -QString JlCompress::extractFile(QString fileCompressed, QString fileName, QString fileDest) { - // Apro lo zip - QuaZip zip(fileCompressed); - if(!zip.open(QuaZip::mdUnzip)) { - return QString(); - } - - // Estraggo il file - if (fileDest.isEmpty()) - fileDest = fileName; - if (!extractFile(&zip,fileName,fileDest)) { - return QString(); - } - - // Chiudo il file zip - zip.close(); - if(zip.getZipError()!=0) { - removeFile(QStringList(fileDest)); - return QString(); - } - return QFileInfo(fileDest).absoluteFilePath(); -} - -/**OK - * Estrae i file specificati in files, contenuti nel file fileCompressed, nella - * cartella dir. La struttura a cartelle del file compresso viene rispettata. - * Se dir = "" allora il file viene estratto nella cartella corrente. - * Se la funzione fallisce cancella i file che si e tentato di estrarre. - * Restituisce i nomi assoluti dei file estratti. - * - * La funzione fallisce se: - * * non si riesce ad aprire l'oggetto zip; - * * l'estrazione di un file fallisce; - * * non si riesce a chiudere l'oggetto zip; - */ -QStringList JlCompress::extractFiles(QString fileCompressed, QStringList files, QString dir) { - // Creo lo zip - QuaZip zip(fileCompressed); - if(!zip.open(QuaZip::mdUnzip)) { - return QStringList(); - } - - // Estraggo i file - QStringList extracted; - for (int i=0; iopen(QuaZip::mdUnzip)) { - delete zip; - return QStringList(); - } - - // Estraggo i nomi dei file - QStringList lst; - QuaZipFileInfo info; - for(bool more=zip->goToFirstFile(); more; more=zip->goToNextFile()) { - if(!zip->getCurrentFileInfo(&info)) { - delete zip; - return QStringList(); - } - lst << info.name; - //info.name.toLocal8Bit().constData() - } - - // Chiudo il file zip - zip->close(); - if(zip->getZipError()!=0) { - delete zip; - return QStringList(); - } - delete zip; - - return lst; -} - diff --git a/depends/quazip/JlCompress.h b/depends/quazip/JlCompress.h deleted file mode 100644 index 3ee8c25a..00000000 --- a/depends/quazip/JlCompress.h +++ /dev/null @@ -1,125 +0,0 @@ -#ifndef JLCOMPRESSFOLDER_H_ -#define JLCOMPRESSFOLDER_H_ - -#include "quazip.h" -#include "quazipfile.h" -#include "quazipfileinfo.h" -#include -#include -#include -#include - -/// 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: - /// 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 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, QSet< QString >& added ); - /// 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); - - /// copy data from inFile to outFile - static bool copyData(QIODevice &inFile, QIODevice &outFile); - /// 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: - /// 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()); - /// Extract a whole archive, with a list of exceptions (prefixes to ignore). - /** - \param fileCompressed The name of the archive. - \param dir The directory to extract to, the current directory if - left empty. - \param exceptions The list of exception prefixes - \return The list of the full paths of the files extracted, empty on failure. - */ - static QStringList extractWithExceptions(QString fileCompressed, QString dir, QStringList exceptions); - /// 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); -}; - -#endif /* JLCOMPRESSFOLDER_H_ */ diff --git a/depends/quazip/crypt.h b/depends/quazip/crypt.h deleted file mode 100644 index 1d6da628..00000000 --- a/depends/quazip/crypt.h +++ /dev/null @@ -1,135 +0,0 @@ -/* crypt.h -- base code for crypt/uncrypt ZIPfile - - - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - - This code is a modified version of crypting code in Infozip distribution - - The encryption/decryption parts of this source code (as opposed to the - non-echoing password parts) were originally written in Europe. The - whole source package can be freely distributed, including from the USA. - (Prior to January 2000, re-export from the US was a violation of US law.) - - This encryption code is a direct transcription of the algorithm from - Roger Schlafly, described by Phil Katz in the file appnote.txt. This - file (appnote.txt) is distributed with the PKZIP program (even in the - version without encryption capabilities). - - If you don't need crypting in your application, just define symbols - NOCRYPT and NOUNCRYPT. - - This code support the "Traditional PKWARE Encryption". - - The new AES encryption added on Zip format by Winzip (see the page - http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong - Encryption is not supported. -*/ - -#include "quazip_global.h" - -#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) - -/*********************************************************************** - * Return the next byte in the pseudo-random sequence - */ -static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab UNUSED) -{ - //(void) pcrc_32_tab; /* avoid "unused parameter" warning */ - unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an - * unpredictable manner on 16-bit systems; not a problem - * with any known compiler so far, though */ - - temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; - return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); -} - -/*********************************************************************** - * Update the encryption keys with the next byte of plain text - */ -static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) -{ - (*(pkeys+0)) = CRC32((*(pkeys+0)), c); - (*(pkeys+1)) += (*(pkeys+0)) & 0xff; - (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; - { - register int keyshift = (int)((*(pkeys+1)) >> 24); - (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); - } - return c; -} - - -/*********************************************************************** - * Initialize the encryption keys and the random header according to - * the given password. - */ -static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) -{ - *(pkeys+0) = 305419896L; - *(pkeys+1) = 591751049L; - *(pkeys+2) = 878082192L; - while (*passwd != '\0') { - update_keys(pkeys,pcrc_32_tab,(int)*passwd); - passwd++; - } -} - -#define zdecode(pkeys,pcrc_32_tab,c) \ - (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) - -#define zencode(pkeys,pcrc_32_tab,c,t) \ - (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) - -#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED - -#define RAND_HEAD_LEN 12 - /* "last resort" source for second part of crypt seed pattern */ -# ifndef ZCR_SEED2 -# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ -# endif - -static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) - const char *passwd; /* password string */ - unsigned char *buf; /* where to write header */ - int bufSize; - unsigned long* pkeys; - const unsigned long* pcrc_32_tab; - unsigned long crcForCrypting; -{ - int n; /* index in random header */ - int t; /* temporary */ - int c; /* random byte */ - unsigned char header[RAND_HEAD_LEN-2]; /* random header */ - static unsigned calls = 0; /* ensure different random header each time */ - - if (bufSize> 7) & 0xff; - header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); - } - /* Encrypt random header (last two bytes is high word of crc) */ - init_keys(passwd, pkeys, pcrc_32_tab); - for (n = 0; n < RAND_HEAD_LEN-2; n++) - { - buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); - } - buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); - buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); - return n; -} - -#endif diff --git a/depends/quazip/ioapi.h b/depends/quazip/ioapi.h deleted file mode 100644 index f4c21809..00000000 --- a/depends/quazip/ioapi.h +++ /dev/null @@ -1,77 +0,0 @@ -/* ioapi.h -- IO base function header for compress/uncompress .zip - files using zlib + zip or unzip API - - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - - Modified by Sergey A. Tachenov to integrate with Qt. -*/ - -#ifndef _ZLIBIOAPI_H -#define _ZLIBIOAPI_H - - -#define ZLIB_FILEFUNC_SEEK_CUR (1) -#define ZLIB_FILEFUNC_SEEK_END (2) -#define ZLIB_FILEFUNC_SEEK_SET (0) - -#define ZLIB_FILEFUNC_MODE_READ (1) -#define ZLIB_FILEFUNC_MODE_WRITE (2) -#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) - -#define ZLIB_FILEFUNC_MODE_EXISTING (4) -#define ZLIB_FILEFUNC_MODE_CREATE (8) - - -#ifndef ZCALLBACK - -#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) -#define ZCALLBACK CALLBACK -#else -#define ZCALLBACK -#endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, voidpf file, int mode)); -typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); -typedef uLong (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); -typedef int (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); -typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); -typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); - -typedef struct zlib_filefunc_def_s -{ - open_file_func zopen_file; - read_file_func zread_file; - write_file_func zwrite_file; - tell_file_func ztell_file; - seek_file_func zseek_file; - close_file_func zclose_file; - testerror_file_func zerror_file; - voidpf opaque; -} zlib_filefunc_def; - - - -void fill_qiodevice_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); - -#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) -#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) -#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) -#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) -#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) -#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) - - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/depends/quazip/qioapi.cpp b/depends/quazip/qioapi.cpp deleted file mode 100644 index f254c34d..00000000 --- a/depends/quazip/qioapi.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* ioapi.c -- IO base function header for compress/uncompress .zip - files using zlib + zip or unzip API - - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - - Modified by Sergey A. Tachenov to integrate with Qt. -*/ - -#include -#include -#include - -#include "zlib.h" -#include "ioapi.h" -#include "quazip_global.h" -#include - - -/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ - -#ifndef SEEK_CUR -#define SEEK_CUR 1 -#endif - -#ifndef SEEK_END -#define SEEK_END 2 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -voidpf ZCALLBACK qiodevice_open_file_func ( - voidpf opaque UNUSED, - voidpf file, - int mode) -{ - QIODevice *iodevice = reinterpret_cast(file); - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - iodevice->open(QIODevice::ReadOnly); - else - if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - iodevice->open(QIODevice::ReadWrite); - else - if (mode & ZLIB_FILEFUNC_MODE_CREATE) - iodevice->open(QIODevice::WriteOnly); - - if (iodevice->isOpen()) { - if (iodevice->isSequential()) { - iodevice->close(); - return NULL; - } else { - return iodevice; - } - } else - return NULL; -} - - -uLong ZCALLBACK qiodevice_read_file_func ( - voidpf opaque UNUSED, - voidpf stream, - void* buf, - uLong size) -{ - uLong ret; - ret = (uLong)((QIODevice*)stream)->read((char*)buf,size); - return ret; -} - - -uLong ZCALLBACK qiodevice_write_file_func ( - voidpf opaque UNUSED, - voidpf stream, - const void* buf, - uLong size) -{ - uLong ret; - ret = (uLong)((QIODevice*)stream)->write((char*)buf,size); - return ret; -} - -uLong ZCALLBACK qiodevice_tell_file_func ( - voidpf opaque UNUSED, - voidpf stream) -{ - uLong ret; - ret = ((QIODevice*)stream)->pos(); - return ret; -} - -int ZCALLBACK qiodevice_seek_file_func ( - voidpf opaque UNUSED, - voidpf stream, - uLong offset, - int origin) -{ - uLong qiodevice_seek_result=0; - int ret; - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - qiodevice_seek_result = ((QIODevice*)stream)->pos() + offset; - break; - case ZLIB_FILEFUNC_SEEK_END : - qiodevice_seek_result = ((QIODevice*)stream)->size() - offset; - break; - case ZLIB_FILEFUNC_SEEK_SET : - qiodevice_seek_result = offset; - break; - default: return -1; - } - ret = !((QIODevice*)stream)->seek(qiodevice_seek_result); - return ret; -} - -int ZCALLBACK qiodevice_close_file_func ( - voidpf opaque UNUSED, - voidpf stream) -{ - ((QIODevice*)stream)->close(); - return 0; -} - -int ZCALLBACK qiodevice_error_file_func ( - voidpf opaque UNUSED, - voidpf stream) -{ - // can't check for error due to the QIODevice API limitation - return 0; -} - -void fill_qiodevice_filefunc ( - zlib_filefunc_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen_file = qiodevice_open_file_func; - pzlib_filefunc_def->zread_file = qiodevice_read_file_func; - pzlib_filefunc_def->zwrite_file = qiodevice_write_file_func; - pzlib_filefunc_def->ztell_file = qiodevice_tell_file_func; - pzlib_filefunc_def->zseek_file = qiodevice_seek_file_func; - pzlib_filefunc_def->zclose_file = qiodevice_close_file_func; - pzlib_filefunc_def->zerror_file = qiodevice_error_file_func; - pzlib_filefunc_def->opaque = NULL; -} diff --git a/depends/quazip/quaadler32.cpp b/depends/quazip/quaadler32.cpp deleted file mode 100644 index 097899f6..00000000 --- a/depends/quazip/quaadler32.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "quaadler32.h" - -#include "zlib.h" - -QuaAdler32::QuaAdler32() -{ - reset(); -} - -quint32 QuaAdler32::calculate(const QByteArray &data) -{ - return adler32( adler32(0L, Z_NULL, 0), (const Bytef*)data.data(), data.size() ); -} - -void QuaAdler32::reset() -{ - checksum = adler32(0L, Z_NULL, 0); -} - -void QuaAdler32::update(const QByteArray &buf) -{ - checksum = adler32( checksum, (const Bytef*)buf.data(), buf.size() ); -} - -quint32 QuaAdler32::value() -{ - return checksum; -} diff --git a/depends/quazip/quaadler32.h b/depends/quazip/quaadler32.h deleted file mode 100644 index c5ac0532..00000000 --- a/depends/quazip/quaadler32.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef QUAADLER32_H -#define QUAADLER32_H - -#include - -#include "quachecksum32.h" - -/// Adler32 checksum -/** \class QuaAdler32 quaadler32.h - * This class wrappers the adler32 function with the QuaChecksum32 interface. - * See QuaChecksum32 for more info. - */ -class QUAZIP_EXPORT QuaAdler32 : public QuaChecksum32 -{ - -public: - QuaAdler32(); - - quint32 calculate(const QByteArray &data); - - void reset(); - void update(const QByteArray &buf); - quint32 value(); - -private: - quint32 checksum; -}; - -#endif //QUAADLER32_H diff --git a/depends/quazip/quachecksum32.h b/depends/quazip/quachecksum32.h deleted file mode 100644 index 773ec2a4..00000000 --- a/depends/quazip/quachecksum32.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef QUACHECKSUM32_H -#define QUACHECKSUM32_H - -#include -#include "quazip_global.h" - -/// Checksum interface. -/** \class QuaChecksum32 quachecksum32.h - * This is an interface for 32 bit checksums. - * Classes implementing this interface can calcunate a certin - * checksum in a single step: - * \code - * QChecksum32 *crc32 = new QuaCrc32(); - * rasoult = crc32->calculate(data); - * \endcode - * or by streaming the data: - * \code - * QChecksum32 *crc32 = new QuaCrc32(); - * while(!fileA.atEnd()) - * crc32->update(fileA.read(bufSize)); - * resoultA = crc32->value(); - * crc32->reset(); - * while(!fileB.atEnd()) - * crc32->update(fileB.read(bufSize)); - * resoultB = crc32->value(); - * \endcode - */ -class QUAZIP_EXPORT QuaChecksum32 -{ - -public: - ///Calculates the checksum for data. - /** \a data source data - * \return data checksum - * - * This function has no efect on the value returned by value(). - */ - virtual quint32 calculate(const QByteArray &data) = 0; - - ///Resets the calculation on a checksun for a stream. - virtual void reset() = 0; - - ///Updates the calculated checksum for the stream - /** \a buf next portion of data from the stream - */ - virtual void update(const QByteArray &buf) = 0; - - ///Value of the checksum calculated for the stream passed throw update(). - /** \return checksum - */ - virtual quint32 value() = 0; -}; - -#endif //QUACHECKSUM32_H diff --git a/depends/quazip/quacrc32.cpp b/depends/quazip/quacrc32.cpp deleted file mode 100644 index 9381f24c..00000000 --- a/depends/quazip/quacrc32.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "quacrc32.h" - -#include "zlib.h" - -QuaCrc32::QuaCrc32() -{ - reset(); -} - -quint32 QuaCrc32::calculate(const QByteArray &data) -{ - return crc32( crc32(0L, Z_NULL, 0), (const Bytef*)data.data(), data.size() ); -} - -void QuaCrc32::reset() -{ - checksum = crc32(0L, Z_NULL, 0); -} - -void QuaCrc32::update(const QByteArray &buf) -{ - checksum = crc32( checksum, (const Bytef*)buf.data(), buf.size() ); -} - -quint32 QuaCrc32::value() -{ - return checksum; -} diff --git a/depends/quazip/quacrc32.h b/depends/quazip/quacrc32.h deleted file mode 100644 index 4c86d566..00000000 --- a/depends/quazip/quacrc32.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef QUACRC32_H -#define QUACRC32_H - -#include "quachecksum32.h" - -///CRC32 checksum -/** \class QuaCrc32 quacrc32.h -* This class wrappers the crc32 function with the QuaChecksum32 interface. -* See QuaChecksum32 for more info. -*/ -class QUAZIP_EXPORT QuaCrc32 : public QuaChecksum32 { - -public: - QuaCrc32(); - - quint32 calculate(const QByteArray &data); - - void reset(); - void update(const QByteArray &buf); - quint32 value(); - -private: - quint32 checksum; -}; - -#endif //QUACRC32_H diff --git a/depends/quazip/quagzipfile.cpp b/depends/quazip/quagzipfile.cpp deleted file mode 100644 index c1c70aad..00000000 --- a/depends/quazip/quagzipfile.cpp +++ /dev/null @@ -1,141 +0,0 @@ -#include - -#include "quagzipfile.h" - -class QuaGzipFilePrivate { - friend class QuaGzipFile; - QString fileName; - gzFile gzd; - inline QuaGzipFilePrivate(): gzd(NULL) {} - inline QuaGzipFilePrivate(const QString &fileName): - fileName(fileName), gzd(NULL) {} - template bool open(FileId id, - QIODevice::OpenMode mode, QString &error); - gzFile open(int fd, const char *modeString); - gzFile open(const QString &name, const char *modeString); -}; - -gzFile QuaGzipFilePrivate::open(const QString &name, const char *modeString) -{ - return gzopen(QFile::encodeName(name).constData(), modeString); -} - -gzFile QuaGzipFilePrivate::open(int fd, const char *modeString) -{ - return gzdopen(fd, modeString); -} - -template -bool QuaGzipFilePrivate::open(FileId id, QIODevice::OpenMode mode, - QString &error) -{ - char modeString[2]; - modeString[0] = modeString[1] = '\0'; - if ((mode & QIODevice::ReadOnly) != 0 - && (mode & QIODevice::WriteOnly) != 0) { - error = QuaGzipFile::trUtf8("Opening gzip for both reading" - " and writing is not supported"); - return false; - } else if ((mode & QIODevice::ReadOnly) != 0) { - modeString[0] = 'r'; - } else if ((mode & QIODevice::WriteOnly) != 0) { - modeString[0] = 'w'; - } else { - error = QuaGzipFile::trUtf8("You can open a gzip either for reading" - " or for writing. Which is it?"); - return false; - } - gzd = open(id, modeString); - if (gzd == NULL) { - error = QuaGzipFile::trUtf8("Could not gzopen() file"); - return false; - } - return true; -} - -QuaGzipFile::QuaGzipFile(): -d(new QuaGzipFilePrivate()) -{ -} - -QuaGzipFile::QuaGzipFile(QObject *parent): -QIODevice(parent), -d(new QuaGzipFilePrivate()) -{ -} - -QuaGzipFile::QuaGzipFile(const QString &fileName, QObject *parent): - QIODevice(parent), -d(new QuaGzipFilePrivate(fileName)) -{ -} - -QuaGzipFile::~QuaGzipFile() -{ - if (isOpen()) { - close(); - } - delete d; -} - -void QuaGzipFile::setFileName(const QString& fileName) -{ - d->fileName = fileName; -} - -QString QuaGzipFile::getFileName() const -{ - return d->fileName; -} - -bool QuaGzipFile::isSequential() const -{ - return true; -} - -bool QuaGzipFile::open(QIODevice::OpenMode mode) -{ - QString error; - if (!d->open(d->fileName, mode, error)) { - setErrorString(error); - return false; - } - return QIODevice::open(mode); -} - -bool QuaGzipFile::open(int fd, QIODevice::OpenMode mode) -{ - QString error; - if (!d->open(fd, mode, error)) { - setErrorString(error); - return false; - } - return QIODevice::open(mode); -} - -bool QuaGzipFile::flush() -{ - return gzflush(d->gzd, Z_SYNC_FLUSH) == Z_OK; -} - -void QuaGzipFile::close() -{ - QIODevice::close(); - gzclose(d->gzd); -} - -qint64 QuaGzipFile::readData(char *data, qint64 maxSize) -{ - return gzread(d->gzd, (voidp)data, (unsigned)maxSize); -} - -qint64 QuaGzipFile::writeData(const char *data, qint64 maxSize) -{ - if (maxSize == 0) - return 0; - int written = gzwrite(d->gzd, (voidp)data, (unsigned)maxSize); - if (written == 0) - return -1; - else - return written; -} diff --git a/depends/quazip/quagzipfile.h b/depends/quazip/quagzipfile.h deleted file mode 100644 index 211ceadb..00000000 --- a/depends/quazip/quagzipfile.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef QUAZIP_QUAGZIPFILE_H -#define QUAZIP_QUAGZIPFILE_H - -#include -#include "quazip_global.h" - -#include - -class QuaGzipFilePrivate; - -class QUAZIP_EXPORT QuaGzipFile: public QIODevice { - Q_OBJECT -public: - QuaGzipFile(); - QuaGzipFile(QObject *parent); - QuaGzipFile(const QString &fileName, QObject *parent = NULL); - virtual ~QuaGzipFile(); - void setFileName(const QString& fileName); - QString getFileName() const; - virtual bool isSequential() const; - virtual bool open(QIODevice::OpenMode mode); - virtual bool open(int fd, QIODevice::OpenMode mode); - virtual bool flush(); - virtual void close(); -protected: - virtual qint64 readData(char *data, qint64 maxSize); - virtual qint64 writeData(const char *data, qint64 maxSize); -private: - // not implemented by design to disable copy - QuaGzipFile(const QuaGzipFile &that); - QuaGzipFile& operator=(const QuaGzipFile &that); - QuaGzipFilePrivate *d; -}; - -#endif // QUAZIP_QUAGZIPFILE_H diff --git a/depends/quazip/quaziodevice.cpp b/depends/quazip/quaziodevice.cpp deleted file mode 100644 index 959ca0e8..00000000 --- a/depends/quazip/quaziodevice.cpp +++ /dev/null @@ -1,283 +0,0 @@ -#include "quaziodevice.h" - -#define QUAZIO_INBUFSIZE 4096 -#define QUAZIO_OUTBUFSIZE 4096 - -class QuaZIODevicePrivate { - friend class QuaZIODevice; - QuaZIODevicePrivate(QIODevice *io); - ~QuaZIODevicePrivate(); - QIODevice *io; - z_stream zins; - z_stream zouts; - char *inBuf; - int inBufPos; - int inBufSize; - char *outBuf; - int outBufPos; - int outBufSize; - bool zBufError; - int doFlush(QString &error); -}; - -QuaZIODevicePrivate::QuaZIODevicePrivate(QIODevice *io): - io(io), - inBuf(NULL), - inBufPos(0), - inBufSize(0), - outBuf(NULL), - outBufPos(0), - outBufSize(0), - zBufError(false) -{ - zins.zalloc = (alloc_func) NULL; - zins.zfree = (free_func) NULL; - zins.opaque = NULL; - zouts.zalloc = (alloc_func) NULL; - zouts.zfree = (free_func) NULL; - zouts.opaque = NULL; - inBuf = new char[QUAZIO_INBUFSIZE]; - outBuf = new char[QUAZIO_OUTBUFSIZE]; -#ifdef QUAZIP_ZIODEVICE_DEBUG_OUTPUT - debug.setFileName("debug.out"); - debug.open(QIODevice::WriteOnly); -#endif -#ifdef QUAZIP_ZIODEVICE_DEBUG_INPUT - indebug.setFileName("debug.in"); - indebug.open(QIODevice::WriteOnly); -#endif -} - -QuaZIODevicePrivate::~QuaZIODevicePrivate() -{ -#ifdef QUAZIP_ZIODEVICE_DEBUG_OUTPUT - debug.close(); -#endif -#ifdef QUAZIP_ZIODEVICE_DEBUG_INPUT - indebug.close(); -#endif - if (inBuf != NULL) - delete[] inBuf; - if (outBuf != NULL) - delete[] outBuf; -} - -int QuaZIODevicePrivate::doFlush(QString &error) -{ - int flushed = 0; - while (outBufPos < outBufSize) { - int more = io->write(outBuf + outBufPos, outBufSize - outBufPos); - if (more == -1) { - error = io->errorString(); - return -1; - } - if (more == 0) - break; - outBufPos += more; - flushed += more; - } - if (outBufPos == outBufSize) { - outBufPos = outBufSize = 0; - } - return flushed; -} - -// #define QUAZIP_ZIODEVICE_DEBUG_OUTPUT -// #define QUAZIP_ZIODEVICE_DEBUG_INPUT -#ifdef QUAZIP_ZIODEVICE_DEBUG_OUTPUT -#include -static QFile debug; -#endif -#ifdef QUAZIP_ZIODEVICE_DEBUG_INPUT -#include -static QFile indebug; -#endif - -QuaZIODevice::QuaZIODevice(QIODevice *io, QObject *parent): - QIODevice(parent), - d(new QuaZIODevicePrivate(io)) -{ - connect(io, SIGNAL(readyRead()), SIGNAL(readyRead())); -} - -QuaZIODevice::~QuaZIODevice() -{ - if (isOpen()) - close(); - delete d; -} - -QIODevice *QuaZIODevice::getIoDevice() const -{ - return d->io; -} - -bool QuaZIODevice::open(QIODevice::OpenMode mode) -{ - if ((mode & QIODevice::ReadOnly) != 0) { - if (inflateInit(&d->zins) != Z_OK) { - setErrorString(d->zins.msg); - return false; - } - } - if ((mode & QIODevice::WriteOnly) != 0) { - if (deflateInit(&d->zouts, Z_DEFAULT_COMPRESSION) != Z_OK) { - setErrorString(d->zouts.msg); - return false; - } - } - return QIODevice::open(mode); -} - -void QuaZIODevice::close() -{ - if ((openMode() & QIODevice::ReadOnly) != 0) { - if (inflateEnd(&d->zins) != Z_OK) { - setErrorString(d->zins.msg); - } - } - if ((openMode() & QIODevice::WriteOnly) != 0) { - flush(); - if (deflateEnd(&d->zouts) != Z_OK) { - setErrorString(d->zouts.msg); - } - } - QIODevice::close(); -} - -qint64 QuaZIODevice::readData(char *data, qint64 maxSize) -{ - int read = 0; - while (read < maxSize) { - if (d->inBufPos == d->inBufSize) { - d->inBufPos = 0; - d->inBufSize = d->io->read(d->inBuf, QUAZIO_INBUFSIZE); - if (d->inBufSize == -1) { - d->inBufSize = 0; - setErrorString(d->io->errorString()); - return -1; - } - if (d->inBufSize == 0) - break; - } - while (read < maxSize && d->inBufPos < d->inBufSize) { - d->zins.next_in = (Bytef *) (d->inBuf + d->inBufPos); - d->zins.avail_in = d->inBufSize - d->inBufPos; - d->zins.next_out = (Bytef *) (data + read); - d->zins.avail_out = (uInt) (maxSize - read); // hope it's less than 2GB - int more = 0; - switch (inflate(&d->zins, Z_SYNC_FLUSH)) { - case Z_OK: - read = (char *) d->zins.next_out - data; - d->inBufPos = (char *) d->zins.next_in - d->inBuf; - break; - case Z_STREAM_END: - read = (char *) d->zins.next_out - data; - d->inBufPos = (char *) d->zins.next_in - d->inBuf; - return read; - case Z_BUF_ERROR: // this should never happen, but just in case - if (!d->zBufError) { - qWarning("Z_BUF_ERROR detected with %d/%d in/out, weird", - d->zins.avail_in, d->zins.avail_out); - d->zBufError = true; - } - memmove(d->inBuf, d->inBuf + d->inBufPos, d->inBufSize - d->inBufPos); - d->inBufSize -= d->inBufPos; - d->inBufPos = 0; - more = d->io->read(d->inBuf + d->inBufSize, QUAZIO_INBUFSIZE - d->inBufSize); - if (more == -1) { - setErrorString(d->io->errorString()); - return -1; - } - if (more == 0) - return read; - d->inBufSize += more; - break; - default: - setErrorString(QString::fromLocal8Bit(d->zins.msg)); - return -1; - } - } - } -#ifdef QUAZIP_ZIODEVICE_DEBUG_INPUT - indebug.write(data, read); -#endif - return read; -} - -qint64 QuaZIODevice::writeData(const char *data, qint64 maxSize) -{ - int written = 0; - QString error; - if (d->doFlush(error) == -1) { - setErrorString(error); - return -1; - } - while (written < maxSize) { - // there is some data waiting in the output buffer - if (d->outBufPos < d->outBufSize) - return written; - d->zouts.next_in = (Bytef *) (data + written); - d->zouts.avail_in = (uInt) (maxSize - written); // hope it's less than 2GB - d->zouts.next_out = (Bytef *) d->outBuf; - d->zouts.avail_out = QUAZIO_OUTBUFSIZE; - switch (deflate(&d->zouts, Z_NO_FLUSH)) { - case Z_OK: - written = (char *) d->zouts.next_in - data; - d->outBufSize = (char *) d->zouts.next_out - d->outBuf; - break; - default: - setErrorString(QString::fromLocal8Bit(d->zouts.msg)); - return -1; - } - if (d->doFlush(error) == -1) { - setErrorString(error); - return -1; - } - } -#ifdef QUAZIP_ZIODEVICE_DEBUG_OUTPUT - debug.write(data, written); -#endif - return written; -} - -bool QuaZIODevice::flush() -{ - QString error; - if (d->doFlush(error) < 0) { - setErrorString(error); - return false; - } - // can't flush buffer, some data is still waiting - if (d->outBufPos < d->outBufSize) - return true; - Bytef c = 0; - d->zouts.next_in = &c; // fake input buffer - d->zouts.avail_in = 0; // of zero size - do { - d->zouts.next_out = (Bytef *) d->outBuf; - d->zouts.avail_out = QUAZIO_OUTBUFSIZE; - switch (deflate(&d->zouts, Z_SYNC_FLUSH)) { - case Z_OK: - d->outBufSize = (char *) d->zouts.next_out - d->outBuf; - if (d->doFlush(error) < 0) { - setErrorString(error); - return false; - } - if (d->outBufPos < d->outBufSize) - return true; - break; - case Z_BUF_ERROR: // nothing to write? - return true; - default: - setErrorString(QString::fromLocal8Bit(d->zouts.msg)); - return false; - } - } while (d->zouts.avail_out == 0); - return true; -} - -bool QuaZIODevice::isSequential() const -{ - return true; -} diff --git a/depends/quazip/quaziodevice.h b/depends/quazip/quaziodevice.h deleted file mode 100644 index b061cd16..00000000 --- a/depends/quazip/quaziodevice.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef QUAZIP_QUAZIODEVICE_H -#define QUAZIP_QUAZIODEVICE_H - -#include -#include "quazip_global.h" - -#include - -class QuaZIODevicePrivate; - -class QUAZIP_EXPORT QuaZIODevice: public QIODevice { - Q_OBJECT -public: - QuaZIODevice(QIODevice *io, QObject *parent = NULL); - ~QuaZIODevice(); - virtual bool flush(); - virtual bool open(QIODevice::OpenMode); - virtual void close(); - QIODevice *getIoDevice() const; - virtual bool isSequential() const; -protected: - virtual qint64 readData(char *data, qint64 maxSize); - virtual qint64 writeData(const char *data, qint64 maxSize); -private: - QuaZIODevicePrivate *d; -}; -#endif // QUAZIP_QUAZIODEVICE_H diff --git a/depends/quazip/quazip.cpp b/depends/quazip/quazip.cpp deleted file mode 100644 index b6fa92f0..00000000 --- a/depends/quazip/quazip.cpp +++ /dev/null @@ -1,554 +0,0 @@ -/* -Copyright (C) 2005-2011 Sergey A. Tachenov - -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at -your option) any later version. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser -General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with this program; if not, write to the Free Software Foundation, -Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -See COPYING file for the full LGPL text. - -Original ZIP package is copyrighted by Gilles Vollant, see -quazip/(un)zip.h files for details, basically it's zlib license. - **/ - -#include -#include - -#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: - /// 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()), - commentCodec(QTextCodec::codecForLocale()), - ioDevice(NULL), - mode(QuaZip::mdNotOpen), - 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()), - commentCodec(QTextCodec::codecForLocale()), - zipName(zipName), - ioDevice(NULL), - mode(QuaZip::mdNotOpen), - 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()), - commentCodec(QTextCodec::codecForLocale()), - ioDevice(ioDevice), - mode(QuaZip::mdNotOpen), - hasCurrentFile_f(false), - zipError(UNZ_OK), - dataDescriptorWritingEnabled(true) {} - /// Returns either a list of file names or a list of QuaZipFileInfo. - template - bool getFileInfoList(QList *result) const; -}; - -QuaZip::QuaZip(): - p(new QuaZipPrivate(this)) -{ -} - -QuaZip::QuaZip(const QString& zipName): - p(new QuaZipPrivate(this, zipName)) -{ -} - -QuaZip::QuaZip(QIODevice *ioDevice): - p(new QuaZipPrivate(this, ioDevice)) -{ -} - -QuaZip::~QuaZip() -{ - if(isOpen()) - close(); - delete p; -} - -bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi) -{ - p->zipError=UNZ_OK; - if(isOpen()) { - qWarning("QuaZip::open(): ZIP already opened"); - return false; - } - QIODevice *ioDevice = p->ioDevice; - if (ioDevice == NULL) { - if (p->zipName.isEmpty()) { - qWarning("QuaZip::open(): set either ZIP file name or IO device first"); - return false; - } else { - ioDevice = new QFile(p->zipName); - } - } - switch(mode) { - case mdUnzip: - p->unzFile_f=unzOpen2(ioDevice, ioApi); - if(p->unzFile_f!=NULL) { - p->mode=mode; - p->ioDevice = ioDevice; - return true; - } else { - p->zipError=UNZ_OPENERROR; - if (!p->zipName.isEmpty()) - delete ioDevice; - return false; - } - case mdCreate: - case mdAppend: - case mdAdd: - p->zipFile_f=zipOpen2(ioDevice, - mode==mdCreate?APPEND_STATUS_CREATE: - mode==mdAppend?APPEND_STATUS_CREATEAFTER: - APPEND_STATUS_ADDINZIP, - NULL, - ioApi); - if(p->zipFile_f!=NULL) { - p->mode=mode; - p->ioDevice = ioDevice; - return true; - } else { - p->zipError=UNZ_OPENERROR; - if (!p->zipName.isEmpty()) - delete ioDevice; - return false; - } - default: - qWarning("QuaZip::open(): unknown mode: %d", (int)mode); - if (!p->zipName.isEmpty()) - delete ioDevice; - return false; - break; - } -} - -void QuaZip::close() -{ - p->zipError=UNZ_OK; - switch(p->mode) { - case mdNotOpen: - qWarning("QuaZip::close(): ZIP is not open"); - return; - case mdUnzip: - p->zipError=unzClose(p->unzFile_f); - break; - case mdCreate: - case mdAppend: - case mdAdd: - p->zipError=zipClose(p->zipFile_f, - p->comment.isNull() ? NULL - : p->commentCodec->fromUnicode(p->comment).constData()); - break; - default: - qWarning("QuaZip::close(): unknown mode: %d", (int)p->mode); - return; - } - // opened by name, need to delete the internal IO device - if (!p->zipName.isEmpty()) { - delete p->ioDevice; - p->ioDevice = NULL; - } - if(p->zipError==UNZ_OK) - p->mode=mdNotOpen; -} - -void QuaZip::setZipName(const QString& zipName) -{ - if(isOpen()) { - qWarning("QuaZip::setZipName(): ZIP is already open!"); - return; - } - p->zipName=zipName; - p->ioDevice = NULL; -} - -void QuaZip::setIoDevice(QIODevice *ioDevice) -{ - if(isOpen()) { - qWarning("QuaZip::setIoDevice(): ZIP is already open!"); - return; - } - p->ioDevice = ioDevice; - p->zipName = QString(); -} - -int QuaZip::getEntriesCount()const -{ - QuaZip *fakeThis=(QuaZip*)this; // non-const - fakeThis->p->zipError=UNZ_OK; - if(p->mode!=mdUnzip) { - qWarning("QuaZip::getEntriesCount(): ZIP is not open in mdUnzip mode"); - return -1; - } - unz_global_info globalInfo; - if((fakeThis->p->zipError=unzGetGlobalInfo(p->unzFile_f, &globalInfo))!=UNZ_OK) - return p->zipError; - return (int)globalInfo.number_entry; -} - -QString QuaZip::getComment()const -{ - QuaZip *fakeThis=(QuaZip*)this; // non-const - fakeThis->p->zipError=UNZ_OK; - if(p->mode!=mdUnzip) { - qWarning("QuaZip::getComment(): ZIP is not open in mdUnzip mode"); - return QString(); - } - unz_global_info globalInfo; - QByteArray comment; - if((fakeThis->p->zipError=unzGetGlobalInfo(p->unzFile_f, &globalInfo))!=UNZ_OK) - return QString(); - comment.resize(globalInfo.size_comment); - if((fakeThis->p->zipError=unzGetGlobalComment(p->unzFile_f, comment.data(), comment.size())) < 0) - return QString(); - fakeThis->p->zipError = UNZ_OK; - return p->commentCodec->toUnicode(comment); -} - -bool QuaZip::setCurrentFile(const QString& fileName, CaseSensitivity cs) -{ - p->zipError=UNZ_OK; - if(p->mode!=mdUnzip) { - qWarning("QuaZip::setCurrentFile(): ZIP is not open in mdUnzip mode"); - return false; - } - if(fileName.isEmpty()) { - p->hasCurrentFile_f=false; - return true; - } - // Unicode-aware reimplementation of the unzLocateFile function - if(p->unzFile_f==NULL) { - p->zipError=UNZ_PARAMERROR; - return false; - } - if(fileName.length()>MAX_FILE_NAME_LENGTH) { - p->zipError=UNZ_PARAMERROR; - return false; - } - bool sens = convertCaseSensitivity(cs) == Qt::CaseSensitive; - QString lower, current; - if(!sens) lower=fileName.toLower(); - p->hasCurrentFile_f=false; - for(bool more=goToFirstFile(); more; more=goToNextFile()) { - current=getCurrentFileName(); - if(current.isEmpty()) return false; - if(sens) { - if(current==fileName) break; - } else { - if(current.toLower()==lower) break; - } - } - return p->hasCurrentFile_f; -} - -bool QuaZip::goToFirstFile() -{ - p->zipError=UNZ_OK; - if(p->mode!=mdUnzip) { - qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode"); - return false; - } - p->zipError=unzGoToFirstFile(p->unzFile_f); - p->hasCurrentFile_f=p->zipError==UNZ_OK; - return p->hasCurrentFile_f; -} - -bool QuaZip::goToNextFile() -{ - p->zipError=UNZ_OK; - if(p->mode!=mdUnzip) { - qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode"); - return false; - } - p->zipError=unzGoToNextFile(p->unzFile_f); - p->hasCurrentFile_f=p->zipError==UNZ_OK; - if(p->zipError==UNZ_END_OF_LIST_OF_FILE) - p->zipError=UNZ_OK; - return p->hasCurrentFile_f; -} - -bool QuaZip::getCurrentFileInfo(QuaZipFileInfo *info)const -{ - QuaZip *fakeThis=(QuaZip*)this; // non-const - fakeThis->p->zipError=UNZ_OK; - if(p->mode!=mdUnzip) { - qWarning("QuaZip::getCurrentFileInfo(): ZIP is not open in mdUnzip mode"); - return false; - } - unz_file_info info_z; - QByteArray fileName; - QByteArray extra; - QByteArray