00001 #ifndef QUA_ZIP_H 00002 #define QUA_ZIP_H 00003 00004 /* 00005 -- A kind of "standard" GPL license statement -- 00006 QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package 00007 Copyright (C) 2005-2007 Sergey A. Tachenov 00008 00009 This program is free software; you can redistribute it and/or modify it 00010 under the terms of the GNU General Public License as published by the 00011 Free Software Foundation; either version 2 of the License, or (at your 00012 option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, but 00015 WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 00017 Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License along 00020 with this program; if not, write to the Free Software Foundation, Inc., 00021 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 -- A kind of "standard" GPL license statement ends here -- 00024 00025 See COPYING file for GPL. 00026 00027 You are also permitted to use QuaZIP under the terms of LGPL (see 00028 COPYING.LGPL). You are free to choose either license, but please note 00029 that QuaZIP makes use of Qt, which is not licensed under LGPL. So if 00030 you are using Open Source edition of Qt, you therefore MUST use GPL for 00031 your code based on QuaZIP, since it would be also based on Qt in this 00032 case. If you are Qt commercial license owner, then you are free to use 00033 QuaZIP as long as you respect either GPL or LGPL for QuaZIP code. 00034 **/ 00035 00036 #include <QString> 00037 #include <QTextCodec> 00038 00039 #include "zip.h" 00040 #include "unzip.h" 00041 00042 #include "quazipfileinfo.h" 00043 00044 // just in case it will be defined in the later versions of the ZIP/UNZIP 00045 #ifndef UNZ_OPENERROR 00046 // define additional error code 00047 #define UNZ_OPENERROR -1000 00048 #endif 00049 00051 00088 class QuaZip { 00089 public: 00091 enum Constants { 00092 MAX_FILE_NAME_LENGTH=256 00095 }; 00097 enum Mode { 00098 mdNotOpen, 00099 mdUnzip, 00100 mdCreate, 00101 mdAppend, 00109 mdAdd 00110 }; 00112 00117 enum CaseSensitivity { 00118 csDefault=0, 00119 csSensitive=1, 00120 csInsensitive=2 00121 }; 00122 private: 00123 QTextCodec *fileNameCodec, *commentCodec; 00124 QString zipName; 00125 QString comment; 00126 Mode mode; 00127 union { 00128 unzFile unzFile_f; 00129 zipFile zipFile_f; 00130 }; 00131 bool hasCurrentFile_f; 00132 int zipError; 00133 // not (and will not be) implemented 00134 QuaZip(const QuaZip& that); 00135 // not (and will not be) implemented 00136 QuaZip& operator=(const QuaZip& that); 00137 public: 00139 00140 QuaZip(); 00142 QuaZip(const QString& zipName); 00144 00145 ~QuaZip(); 00147 00173 bool open(Mode mode, zlib_filefunc_def *ioApi =NULL); 00175 00176 void close(); 00178 00183 void setFileNameCodec(QTextCodec *fileNameCodec) 00184 {this->fileNameCodec=fileNameCodec;} 00186 00189 void setFileNameCodec(const char *fileNameCodecName) 00190 {fileNameCodec=QTextCodec::codecForName(fileNameCodecName);} 00192 QTextCodec* getFileNameCodec()const {return fileNameCodec;} 00194 00196 void setCommentCodec(QTextCodec *commentCodec) 00197 {this->commentCodec=commentCodec;} 00199 00202 void setCommentCodec(const char *commentCodecName) 00203 {commentCodec=QTextCodec::codecForName(commentCodecName);} 00205 QTextCodec* getCommentCodec()const {return commentCodec;} 00207 00210 QString getZipName()const {return zipName;} 00212 00216 void setZipName(const QString& zipName); 00218 Mode getMode()const {return mode;} 00220 bool isOpen()const {return mode!=mdNotOpen;} 00222 00230 int getZipError()const {return zipError;} 00232 00235 int getEntriesCount()const; 00237 QString getComment()const; 00239 00243 void setComment(const QString& comment) {this->comment=comment;} 00245 00248 bool goToFirstFile(); 00250 00267 bool goToNextFile(); 00269 00293 bool setCurrentFile(const QString& fileName, CaseSensitivity cs =csDefault); 00295 bool hasCurrentFile()const {return hasCurrentFile_f;} 00297 00312 bool getCurrentFileInfo(QuaZipFileInfo* info)const; 00314 00320 QString getCurrentFileName()const; 00322 00337 unzFile getUnzFile() {return unzFile_f;} 00339 00343 zipFile getZipFile() {return zipFile_f;} 00344 }; 00345 00346 #endif