diff options
| author | Petr Mrázek <peterix@gmail.com> | 2013-08-17 13:40:51 +0200 |
|---|---|---|
| committer | Petr Mrázek <peterix@gmail.com> | 2013-08-17 13:40:51 +0200 |
| commit | 253067c782955380bbf66ac0475dc954375b1ff4 (patch) | |
| tree | ca97e231fd3a764256d95b5fc8d08fc25ff72161 /quazip | |
| parent | 77e80665422c4e97e2286418ab55e20c4030023b (diff) | |
| download | PrismLauncher-253067c782955380bbf66ac0475dc954375b1ff4.tar.gz PrismLauncher-253067c782955380bbf66ac0475dc954375b1ff4.tar.bz2 PrismLauncher-253067c782955380bbf66ac0475dc954375b1ff4.zip | |
Move all the things (YES. Move them.)
Also, implemented some basic modlist logic, to be wired up.
Diffstat (limited to 'quazip')
| -rw-r--r-- | quazip/CMakeLists.txt | 28 | ||||
| -rw-r--r-- | quazip/JlCompress.cpp | 516 | ||||
| -rw-r--r-- | quazip/JlCompress.h | 123 | ||||
| -rw-r--r-- | quazip/crypt.h | 135 | ||||
| -rw-r--r-- | quazip/ioapi.h | 77 | ||||
| -rw-r--r-- | quazip/qioapi.cpp | 146 | ||||
| -rw-r--r-- | quazip/quaadler32.cpp | 28 | ||||
| -rw-r--r-- | quazip/quaadler32.h | 29 | ||||
| -rw-r--r-- | quazip/quachecksum32.h | 54 | ||||
| -rw-r--r-- | quazip/quacrc32.cpp | 28 | ||||
| -rw-r--r-- | quazip/quacrc32.h | 26 | ||||
| -rw-r--r-- | quazip/quagzipfile.cpp | 141 | ||||
| -rw-r--r-- | quazip/quagzipfile.h | 35 | ||||
| -rw-r--r-- | quazip/quaziodevice.cpp | 283 | ||||
| -rw-r--r-- | quazip/quaziodevice.h | 27 | ||||
| -rw-r--r-- | quazip/quazip.cpp | 554 | ||||
| -rw-r--r-- | quazip/quazip.h | 411 | ||||
| -rw-r--r-- | quazip/quazip_global.h | 55 | ||||
| -rw-r--r-- | quazip/quazipdir.cpp | 507 | ||||
| -rw-r--r-- | quazip/quazipdir.h | 171 | ||||
| -rw-r--r-- | quazip/quazipfile.cpp | 488 | ||||
| -rw-r--r-- | quazip/quazipfile.h | 442 | ||||
| -rw-r--r-- | quazip/quazipfileinfo.h | 66 | ||||
| -rw-r--r-- | quazip/quazipnewinfo.cpp | 51 | ||||
| -rw-r--r-- | quazip/quazipnewinfo.h | 102 | ||||
| -rw-r--r-- | quazip/unzip.c | 1603 | ||||
| -rw-r--r-- | quazip/unzip.h | 356 | ||||
| -rw-r--r-- | quazip/zip.c | 1281 | ||||
| -rw-r--r-- | quazip/zip.h | 245 |
29 files changed, 0 insertions, 8008 deletions
diff --git a/quazip/CMakeLists.txt b/quazip/CMakeLists.txt deleted file mode 100644 index b5a391e9..00000000 --- a/quazip/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -project(quazip) - -# set all include directories for in and out of source builds -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} - ${ZLIB_INCLUDE_DIRS} -) - -# include with QT_USE selected library parts -# INCLUDE(${QT_USE_FILE}) - -file(GLOB SRCS "*.c" "*.cpp") -file(GLOB PUBLIC_HEADERS "*.h") - -# Static link! -ADD_DEFINITIONS(-DQUAZIP_STATIC) - -#qt5_wrap_cpp(MOC_SRCS ${PUBLIC_HEADERS}) -#set(SRCS ${SRCS} ${MOC_SRCS}) - -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -add_library(quazip STATIC ${SRCS}) -target_link_libraries(quazip ${ZLIB_LIBRARIES}) - -#install(FILES ${PUBLIC_HEADERS} DESTINATION include/quazip) -#install(TARGETS quazip LIBRARY DESTINATION ${LIB_DESTINATION} ARCHIVE DESTINATION ${LIB_DESTINATION} RUNTIME DESTINATION ${LIB_DESTINATION}) diff --git a/quazip/JlCompress.cpp b/quazip/JlCompress.cpp deleted file mode 100644 index 69832140..00000000 --- a/quazip/JlCompress.cpp +++ /dev/null @@ -1,516 +0,0 @@ -#include "JlCompress.h" -#include <QDebug> - -static bool 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* zip, QString dir, QString origDir, bool recursive) { - // 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 (!zip) return false; - if (zip->getMode()!=QuaZip::mdCreate && - zip->getMode()!=QuaZip::mdAppend && - zip->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(zip,file.absoluteFilePath(),origDir,recursive)) return false; - } - } - - // Per ogni file nella cartella - QFileInfoList files = directory.entryInfoList(QDir::Files); - QDir origDirectory(origDir); - Q_FOREACH (QFileInfo file, files) { - // Se non e un file o e il file compresso che sto creando - if(!file.isFile()||file.absoluteFilePath()==zip->getZipName()) continue; - - // Creo il nome relativo da usare all'interno del file compresso - QString filename = origDirectory.relativeFilePath(file.absoluteFilePath()); - - // Comprimo il file - if (!compressFile(zip,file.absoluteFilePath(),filename)) return false; - } - - 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<listFile.count(); i++) { - // Lo elimino - ret = ret && QFile::remove(listFile.at(i)); - } - return ret; -} - -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -/**OK - * Comprime il file fileName nel file fileCompressed. - * Se la funzione fallisce restituisce false e cancella il file che si e tentato - * di creare. - * - * La funzione fallisce se: - * * non si riesce ad aprire l'oggetto zip; - * * la compressione del file fallisce; - * * non si riesce a chiudere l'oggetto zip; - */ -bool JlCompress::compressFile(QString fileCompressed, QString file) { - // Creo lo zip - QuaZip zip(fileCompressed); - QDir().mkpath(QFileInfo(fileCompressed).absolutePath()); - if(!zip.open(QuaZip::mdCreate)) { - QFile::remove(fileCompressed); - return false; - } - - // Aggiungo il file - if (!compressFile(&zip,file,QFileInfo(file).fileName())) { - QFile::remove(fileCompressed); - return false; - } - - // Chiudo il file zip - zip.close(); - if(zip.getZipError()!=0) { - QFile::remove(fileCompressed); - return false; - } - - return true; -} - -/**OK - * Comprime i file specificati in files nel file fileCompressed. - * Se la funzione fallisce restituisce false e cancella il file che si e tentato - * di creare. - * - * La funzione fallisce se: - * * non si riesce ad aprire l'oggetto zip; - * * la compressione di un file fallisce; - * * non si riesce a chiudere l'oggetto zip; - */ -bool JlCompress::compressFiles(QString fileCompressed, QStringList files) { - // Creo lo zip - QuaZip zip(fileCompressed); - QDir().mkpath(QFileInfo(fileCompressed).absolutePath()); - if(!zip.open(QuaZip::mdCreate)) { - QFile::remove(fileCompressed); - return false; - } - - // Comprimo i file - QFileInfo info; - Q_FOREACH (QString file, files) { - info.setFile(file); - if (!info.exists() || !compressFile(&zip,file,info.fileName())) { - QFile::remove(fileCompressed); - return false; - } - } - - // Chiudo il file zip - zip.close(); - if(zip.getZipError()!=0) { - QFile::remove(fileCompressed); - return false; - } - - return true; -} - -/**OK - * Comprime la cartella dir nel file fileCompressed, se recursive e true allora - * comprime anche le sotto cartelle. - * Se la funzione fallisce restituisce false e cancella il file che si e tentato - * di creare. - * - * La funzione fallisce se: - * * non si riesce ad aprire l'oggetto zip; - * * la compressione di un file fallisce; - * * non si riesce a chiudere l'oggetto zip; - */ -bool JlCompress::compressDir(QString fileCompressed, QString dir, bool recursive) { - // Creo lo zip - QuaZip zip(fileCompressed); - QDir().mkpath(QFileInfo(fileCompressed).absolutePath()); - if(!zip.open(QuaZip::mdCreate)) { - QFile::remove(fileCompressed); - return false; - } - - // Aggiungo i file e le sotto cartelle - if (!compressSubDir(&zip,dir,dir,recursive)) { - 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; i<files.count(); i++) { - QString absPath = QDir(dir).absoluteFilePath(files.at(i)); - if (!extractFile(&zip, files.at(i), absPath)) { - removeFile(extracted); - return QStringList(); - } - extracted.append(absPath); - } - - // Chiudo il file zip - zip.close(); - if(zip.getZipError()!=0) { - removeFile(extracted); - return QStringList(); - } - - return extracted; -} - -QStringList JlCompress::extractWithExceptions(QString fileCompressed, QString dir, QStringList exceptions) -{ - QuaZip zip(fileCompressed); - if(!zip.open(QuaZip::mdUnzip)) - { - return QStringList(); - } - - QDir directory(dir); - QStringList extracted; - if (!zip.goToFirstFile()) - { - return QStringList(); - } - do - { - QString name = zip.getCurrentFileName(); - bool ok = true; - for(auto str: exceptions) - { - if(name.startsWith(str)) - { - ok = false; - break; - } - } - if(!ok) - continue; - QString absFilePath = directory.absoluteFilePath(name); - if (!JlCompress::extractFile(&zip, "", absFilePath)) - { - JlCompress::removeFile(extracted); - return QStringList(); - } - extracted.append(absFilePath); - } while (zip.goToNextFile()); - - zip.close(); - if(zip.getZipError()!=0) - { - JlCompress::removeFile(extracted); - return QStringList(); - } - - return extracted; -} - -/**OK - * Estrae il file fileCompressed nella cartella dir. - * 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; - * * la compressione di un file fallisce; - * * non si riesce a chiudere l'oggetto zip; - */ -QStringList JlCompress::extractDir(QString fileCompressed, QString dir) { - // Apro lo zip - QuaZip zip(fileCompressed); - if(!zip.open(QuaZip::mdUnzip)) { - return QStringList(); - } - - QDir directory(dir); - QStringList extracted; - if (!zip.goToFirstFile()) { - return QStringList(); - } - do { - QString name = zip.getCurrentFileName(); - QString absFilePath = directory.absoluteFilePath(name); - if (!extractFile(&zip, "", absFilePath)) { - removeFile(extracted); - return QStringList(); - } - extracted.append(absFilePath); - } while (zip.goToNextFile()); - - // Chiudo il file zip - zip.close(); - if(zip.getZipError()!=0) { - removeFile(extracted); - return QStringList(); - } - - return extracted; -} - -/**OK - * Restituisce la lista dei file resenti nel file compresso fileCompressed. - * Se la funzione fallisce, restituisce un elenco vuoto. - * - * La funzione fallisce se: - * * non si riesce ad aprire l'oggetto zip; - * * la richiesta di informazioni di un file fallisce; - * * non si riesce a chiudere l'oggetto zip; - */ -QStringList JlCompress::getFileList(QString fileCompressed) { - // Apro lo zip - QuaZip* zip = new QuaZip(QFileInfo(fileCompressed).absoluteFilePath()); - if(!zip->open(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/quazip/JlCompress.h b/quazip/JlCompress.h deleted file mode 100644 index 29d6191f..00000000 --- a/quazip/JlCompress.h +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef JLCOMPRESSFOLDER_H_ -#define JLCOMPRESSFOLDER_H_ - -#include "quazip.h" -#include "quazipfile.h" -#include "quazipfileinfo.h" -#include <QString> -#include <QDir> -#include <QFileInfo> -#include <QFile> - -/// Utility class for typical operations. -/** - This class contains a number of useful static functions to perform - simple operations, such as mass ZIP packing or extraction. - */ -class QUAZIP_EXPORT JlCompress { -private: - /// Compress a single file. - /** - \param zip Opened zip to compress the file to. - \param fileName The full path to the source file. - \param fileDest The full name of the file inside the archive. - \return true if success, false otherwise. - */ - static bool compressFile(QuaZip* zip, QString fileName, QString fileDest); - /// Compress a subdirectory. - /** - \param parentZip Opened zip containing the parent directory. - \param dir The full path to the directory to pack. - \param parentDir The full path to the directory corresponding to - the root of the ZIP. - \param recursive Whether to pack sub-directories as well or only - files. - \return true if success, false otherwise. - */ - static bool compressSubDir(QuaZip* parentZip, QString dir, QString parentDir, bool recursive = true); - /// Extract a single file. - /** - \param zip The opened zip archive to extract from. - \param fileName The full name of the file to extract. - \param fileDest The full path to the destination file. - \return true if success, false otherwise. - */ - static bool extractFile(QuaZip* zip, QString fileName, QString fileDest); - /// Remove some files. - /** - \param listFile The list of files to remove. - \return true if success, false otherwise. - */ - static bool removeFile(QStringList listFile); - -public: - /// Compress a single file. - /** - \param fileCompressed The name of the archive. - \param file The file to compress. - \return true if success, false otherwise. - */ - static bool compressFile(QString fileCompressed, QString file); - /// Compress a list of files. - /** - \param fileCompressed The name of the archive. - \param files The file list to compress. - \return true if success, false otherwise. - */ - static bool compressFiles(QString fileCompressed, QStringList files); - /// Compress a whole directory. - /** - \param fileCompressed The name of the archive. - \param dir The directory to compress. - \param recursive Whether to pack the subdirectories as well, or - just regular files. - \return true if success, false otherwise. - */ - static bool compressDir(QString fileCompressed, QString dir = QString(), bool recursive = true); - -public: - /// 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/quazip/crypt.h b/quazip/crypt.h deleted file mode 100644 index 1d6da628..00000000 --- a/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<RAND_HEAD_LEN) - return 0; - - /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the - * output of rand() to get less predictability, since rand() is - * often poorly implemented. - */ - if (++calls == 1) - { - srand((unsigned)(time(NULL) ^ ZCR_SEED2)); - } - init_keys(passwd, pkeys, pcrc_32_tab); - for (n = 0; n < RAND_HEAD_LEN-2; n++) - { - c = (rand() >> 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/quazip/ioapi.h b/quazip/ioapi.h deleted file mode 100644 index f4c21809..00000000 --- a/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 |
