00001 #ifndef QUA_ZIP_H 00002 #define QUA_ZIP_H 00003 00004 /* 00005 * QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package 00006 * Copyright (C) 2005 Sergey A. Tachenov 00007 * 00008 * This program is free software; you can redistribute it and/or modify it 00009 * under the terms of the GNU General Public License as published by the 00010 * Free Software Foundation; either version 2 of the License, or (at your 00011 * option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 00016 * Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License along 00019 * with this program; if not, write to the Free Software Foundation, Inc., 00020 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 **/ 00022 00023 #include <QString> 00024 #include <QTextCodec> 00025 00026 #include "zip.h" 00027 #include "unzip.h" 00028 00029 #include "quazipfileinfo.h" 00030 00031 // just in case it will be defined in the later versions of the ZIP/UNZIP 00032 #ifndef UNZ_OPENERROR 00033 // define additional error code 00034 #define UNZ_OPENERROR -1000 00035 #endif 00036 00038 00075 class QuaZip { 00076 public: 00078 enum Constants { 00079 MAX_FILE_NAME_LENGTH=256 00082 }; 00084 enum Mode { 00085 mdNotOpen, 00086 mdUnzip, 00087 mdCreate, 00088 mdAppend, 00096 mdAdd 00097 }; 00099 00104 enum CaseSensitivity { 00105 csDefault=0, 00106 csSensitive=1, 00107 csInsensitive=2 00108 }; 00109 private: 00110 QTextCodec *fileNameCodec, *commentCodec; 00111 QString zipName; 00112 QString comment; 00113 Mode mode; 00114 union { 00115 unzFile unzFile_f; 00116 zipFile zipFile_f; 00117 }; 00118 bool hasCurrentFile_f; 00119 int zipError; 00120 // not (and will not be) implemented 00121 QuaZip(const QuaZip& that); 00122 // not (and will not be) implemented 00123 QuaZip& operator=(const QuaZip& that); 00124 public: 00126 00127 QuaZip(); 00129 QuaZip(const QString& zipName); 00131 00132 ~QuaZip(); 00134 00160 bool open(Mode mode, zlib_filefunc_def *ioApi =NULL); 00162 00163 void close(); 00165 00170 void setFileNameCodec(QTextCodec *fileNameCodec) 00171 {this->fileNameCodec=fileNameCodec;} 00173 00176 void setFileNameCodec(const char *fileNameCodecName) 00177 {fileNameCodec=QTextCodec::codecForName(fileNameCodecName);} 00179 QTextCodec* getFileNameCodec()const {return fileNameCodec;} 00181 00183 void setCommentCodec(QTextCodec *commentCodec) 00184 {this->commentCodec=commentCodec;} 00186 00189 void setCommentCodec(const char *commentCodecName) 00190 {commentCodec=QTextCodec::codecForName(commentCodecName);} 00192 QTextCodec* getCommentCodec()const {return commentCodec;} 00194 00197 QString getZipName()const {return zipName;} 00199 00203 void setZipName(const QString& zipName); 00205 Mode getMode()const {return mode;} 00207 bool isOpen()const {return mode!=mdNotOpen;} 00209 00217 int getZipError()const {return zipError;} 00219 00222 int getEntriesCount()const; 00224 QString getComment()const; 00226 00230 void setComment(const QString& comment) {this->comment=comment;} 00232 00235 bool goToFirstFile(); 00237 00254 bool goToNextFile(); 00256 00280 bool setCurrentFile(const QString& fileName, CaseSensitivity cs =csDefault); 00282 bool hasCurrentFile()const {return hasCurrentFile_f;} 00284 00299 bool getCurrentFileInfo(QuaZipFileInfo* info)const; 00301 00307 QString getCurrentFileName()const; 00309 00324 unzFile getUnzFile() {return unzFile_f;} 00326 00330 zipFile getZipFile() {return zipFile_f;} 00331 }; 00332 00333 #endif
1.4.6