misc/quazip/quazip.h
author unc0rr
Wed, 31 Oct 2012 12:52:53 +0400
branch0.9.18
changeset 7899 468a44b74a3f
parent 7889 57b117d441b9
permissions -rw-r--r--
Merge from default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7889
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
     1
#ifndef QUA_ZIP_H
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
     2
#define QUA_ZIP_H
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
     3
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
     4
/*
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
     5
Copyright (C) 2005-2011 Sergey A. Tachenov
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
     6
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
     7
This program is free software; you can redistribute it and/or modify it
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
     8
under the terms of the GNU Lesser General Public License as published by
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
     9
the Free Software Foundation; either version 2 of the License, or (at
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    10
your option) any later version.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    11
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    12
This program is distributed in the hope that it will be useful, but
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    13
WITHOUT ANY WARRANTY; without even the implied warranty of
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    15
General Public License for more details.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    16
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    17
You should have received a copy of the GNU Lesser General Public License
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    18
along with this program; if not, write to the Free Software Foundation,
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    19
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    20
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    21
See COPYING file for the full LGPL text.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    22
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    23
Original ZIP package is copyrighted by Gilles Vollant, see
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    24
quazip/(un)zip.h files for details, basically it's zlib license.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    25
 **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    26
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    27
#include <QString>
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    28
#include <QTextCodec>
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    29
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    30
#include "zip.h"
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    31
#include "unzip.h"
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    32
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    33
#include "quazip_global.h"
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    34
#include "quazipfileinfo.h"
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    35
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    36
// just in case it will be defined in the later versions of the ZIP/UNZIP
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    37
#ifndef UNZ_OPENERROR
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    38
// define additional error code
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    39
#define UNZ_OPENERROR -1000
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    40
#endif
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    41
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    42
class QuaZipPrivate;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    43
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    44
/// ZIP archive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    45
/** \class QuaZip quazip.h <quazip/quazip.h>
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    46
 * This class implements basic interface to the ZIP archive. It can be
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    47
 * used to read table contents of the ZIP archive and retreiving
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    48
 * information about the files inside it.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    49
 *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    50
 * You can also use this class to open files inside archive by passing
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    51
 * pointer to the instance of this class to the constructor of the
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    52
 * QuaZipFile class. But see QuaZipFile::QuaZipFile(QuaZip*, QObject*)
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    53
 * for the possible pitfalls.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    54
 *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    55
 * This class is indended to provide interface to the ZIP subpackage of
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    56
 * the ZIP/UNZIP package as well as to the UNZIP subpackage. But
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    57
 * currently it supports only UNZIP.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    58
 *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    59
 * The use of this class is simple - just create instance using
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    60
 * constructor, then set ZIP archive file name using setFile() function
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    61
 * (if you did not passed the name to the constructor), then open() and
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    62
 * then use different functions to work with it! Well, if you are
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    63
 * paranoid, you may also wish to call close before destructing the
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    64
 * instance, to check for errors on close.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    65
 *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    66
 * You may also use getUnzFile() and getZipFile() functions to get the
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    67
 * ZIP archive handle and use it with ZIP/UNZIP package API directly.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    68
 *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    69
 * This class supports localized file names inside ZIP archive, but you
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    70
 * have to set up proper codec with setCodec() function. By default,
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    71
 * locale codec will be used, which is probably ok for UNIX systems, but
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    72
 * will almost certainly fail with ZIP archives created in Windows. This
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    73
 * is because Windows ZIP programs have strange habit of using DOS
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    74
 * encoding for file names in ZIP archives. For example, ZIP archive
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    75
 * with cyrillic names created in Windows will have file names in \c
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    76
 * IBM866 encoding instead of \c WINDOWS-1251. I think that calling one
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    77
 * function is not much trouble, but for true platform independency it
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    78
 * would be nice to have some mechanism for file name encoding auto
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    79
 * detection using locale information. Does anyone know a good way to do
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    80
 * it?
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    81
 **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    82
class QUAZIP_EXPORT QuaZip {
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    83
  friend class QuaZipPrivate;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    84
  public:
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    85
    /// Useful constants.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    86
    enum Constants {
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    87
      MAX_FILE_NAME_LENGTH=256 /**< Maximum file name length. Taken from
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    88
                                 \c UNZ_MAXFILENAMEINZIP constant in
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    89
                                 unzip.c. */
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    90
    };
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    91
    /// Open mode of the ZIP file.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    92
    enum Mode {
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    93
      mdNotOpen, ///< ZIP file is not open. This is the initial mode.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    94
      mdUnzip, ///< ZIP file is open for reading files inside it.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    95
      mdCreate, ///< ZIP file was created with open() call.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    96
      mdAppend, /**< ZIP file was opened in append mode. This refers to
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    97
                  * \c APPEND_STATUS_CREATEAFTER mode in ZIP/UNZIP package
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    98
                  * and means that zip is appended to some existing file
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
    99
                  * what is useful when that file contains
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   100
                  * self-extractor code. This is obviously \em not what
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   101
                  * you whant to use to add files to the existing ZIP
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   102
                  * archive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   103
                  **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   104
      mdAdd ///< ZIP file was opened for adding files in the archive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   105
    };
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   106
    /// Case sensitivity for the file names.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   107
    /** This is what you specify when accessing files in the archive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   108
     * Works perfectly fine with any characters thanks to Qt's great
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   109
     * unicode support. This is different from ZIP/UNZIP API, where
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   110
     * only US-ASCII characters was supported.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   111
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   112
    enum CaseSensitivity {
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   113
      csDefault=0, ///< Default for platform. Case sensitive for UNIX, not for Windows.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   114
      csSensitive=1, ///< Case sensitive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   115
      csInsensitive=2 ///< Case insensitive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   116
    };
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   117
  private:
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   118
    QuaZipPrivate *p;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   119
    // not (and will not be) implemented
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   120
    QuaZip(const QuaZip& that);
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   121
    // not (and will not be) implemented
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   122
    QuaZip& operator=(const QuaZip& that);
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   123
  public:
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   124
    /// Constructs QuaZip object.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   125
    /** Call setName() before opening constructed object. */
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   126
    QuaZip();
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   127
    /// Constructs QuaZip object associated with ZIP file \a zipName.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   128
    QuaZip(const QString& zipName);
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   129
    /// Constructs QuaZip object associated with ZIP file represented by \a ioDevice.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   130
    /** The IO device must be seekable, otherwise an error will occur when opening. */
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   131
    QuaZip(QIODevice *ioDevice);
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   132
    /// Destroys QuaZip object.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   133
    /** Calls close() if necessary. */
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   134
    ~QuaZip();
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   135
    /// Opens ZIP file.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   136
    /**
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   137
     * Argument \a mode specifies open mode of the ZIP archive. See Mode
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   138
     * for details. Note that there is zipOpen2() function in the
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   139
     * ZIP/UNZIP API which accepts \a globalcomment argument, but it
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   140
     * does not use it anywhere, so this open() function does not have this
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   141
     * argument. See setComment() if you need to set global comment.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   142
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   143
     * If the ZIP file is accessed via explicitly set QIODevice, then
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   144
     * this device is opened in the necessary mode. If the device was
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   145
     * already opened by some other means, then the behaviour is defined by
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   146
     * the device implementation, but generally it is not a very good
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   147
     * idea. For example, QFile will at least issue a warning.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   148
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   149
     * \return \c true if successful, \c false otherwise.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   150
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   151
     * \note ZIP/UNZIP API open calls do not return error code - they
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   152
     * just return \c NULL indicating an error. But to make things
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   153
     * easier, quazip.h header defines additional error code \c
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   154
     * UNZ_ERROROPEN and getZipError() will return it if the open call
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   155
     * of the ZIP/UNZIP API returns \c NULL.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   156
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   157
     * Argument \a ioApi specifies IO function set for ZIP/UNZIP
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   158
     * package to use. See unzip.h, zip.h and ioapi.h for details. Note
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   159
     * that IO API for QuaZip is different from the original package.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   160
     * The file path argument was changed to be of type \c voidpf, and
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   161
     * QuaZip passes a QIODevice pointer there. This QIODevice is either
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   162
     * set explicitly via setIoDevice() or the QuaZip(QIODevice*)
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   163
     * constructor, or it is created internally when opening the archive
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   164
     * by its file name. The default API (qioapi.cpp) just delegates
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   165
     * everything to the QIODevice API. Not only this allows to use a
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   166
     * QIODevice instead of file name, but also has a nice side effect
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   167
     * of raising the file size limit from 2G to 4G.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   168
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   169
     * In short: just forget about the \a ioApi argument and you'll be
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   170
     * fine.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   171
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   172
    bool open(Mode mode, zlib_filefunc_def *ioApi =NULL);
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   173
    /// Closes ZIP file.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   174
    /** Call getZipError() to determine if the close was successful. The
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   175
     * underlying QIODevice is also closed, regardless of whether it was
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   176
     * set explicitly or not. */
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   177
    void close();
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   178
    /// Sets the codec used to encode/decode file names inside archive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   179
    /** This is necessary to access files in the ZIP archive created
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   180
     * under Windows with non-latin characters in file names. For
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   181
     * example, file names with cyrillic letters will be in \c IBM866
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   182
     * encoding.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   183
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   184
    void setFileNameCodec(QTextCodec *fileNameCodec);
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   185
    /// Sets the codec used to encode/decode file names inside archive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   186
    /** \overload
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   187
     * Equivalent to calling setFileNameCodec(QTextCodec::codecForName(codecName));
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   188
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   189
    void setFileNameCodec(const char *fileNameCodecName);
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   190
    /// Returns the codec used to encode/decode comments inside archive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   191
    QTextCodec* getFileNameCodec() const;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   192
    /// Sets the codec used to encode/decode comments inside archive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   193
    /** This codec defaults to locale codec, which is probably ok.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   194
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   195
    void setCommentCodec(QTextCodec *commentCodec);
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   196
    /// Sets the codec used to encode/decode comments inside archive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   197
    /** \overload
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   198
     * Equivalent to calling setCommentCodec(QTextCodec::codecForName(codecName));
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   199
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   200
    void setCommentCodec(const char *commentCodecName);
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   201
    /// Returns the codec used to encode/decode comments inside archive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   202
    QTextCodec* getCommentCodec() const;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   203
    /// Returns the name of the ZIP file.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   204
    /** Returns null string if no ZIP file name has been set, for
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   205
     * example when the QuaZip instance is set up to use a QIODevice
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   206
     * instead.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   207
     * \sa setZipName(), setIoDevice(), getIoDevice()
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   208
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   209
    QString getZipName() const;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   210
    /// Sets the name of the ZIP file.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   211
    /** Does nothing if the ZIP file is open.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   212
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   213
     * Does not reset error code returned by getZipError().
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   214
     * \sa setIoDevice(), getIoDevice(), getZipName()
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   215
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   216
    void setZipName(const QString& zipName);
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   217
    /// Returns the device representing this ZIP file.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   218
    /** Returns null string if no device has been set explicitly, for
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   219
     * example when opening a ZIP file by name.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   220
     * \sa setIoDevice(), getZipName(), setZipName()
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   221
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   222
    QIODevice *getIoDevice() const;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   223
    /// Sets the device representing the ZIP file.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   224
    /** Does nothing if the ZIP file is open.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   225
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   226
     * Does not reset error code returned by getZipError().
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   227
     * \sa getIoDevice(), getZipName(), setZipName()
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   228
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   229
    void setIoDevice(QIODevice *ioDevice);
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   230
    /// Returns the mode in which ZIP file was opened.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   231
    Mode getMode() const;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   232
    /// Returns \c true if ZIP file is open, \c false otherwise.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   233
    bool isOpen() const;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   234
    /// Returns the error code of the last operation.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   235
    /** Returns \c UNZ_OK if the last operation was successful.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   236
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   237
     * Error code resets to \c UNZ_OK every time you call any function
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   238
     * that accesses something inside ZIP archive, even if it is \c
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   239
     * const (like getEntriesCount()). open() and close() calls reset
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   240
     * error code too. See documentation for the specific functions for
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   241
     * details on error detection.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   242
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   243
    int getZipError() const;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   244
    /// Returns number of the entries in the ZIP central directory.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   245
    /** Returns negative error code in the case of error. The same error
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   246
     * code will be returned by subsequent getZipError() call.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   247
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   248
    int getEntriesCount() const;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   249
    /// Returns global comment in the ZIP file.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   250
    QString getComment() const;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   251
    /// Sets global comment in the ZIP file.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   252
    /** Comment will be written to the archive on close operation.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   253
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   254
     * \sa open()
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   255
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   256
    void setComment(const QString& comment);
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   257
    /// Sets the current file to the first file in the archive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   258
    /** Returns \c true on success, \c false otherwise. Call
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   259
     * getZipError() to get the error code.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   260
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   261
    bool goToFirstFile();
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   262
    /// Sets the current file to the next file in the archive.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   263
    /** Returns \c true on success, \c false otherwise. Call
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   264
     * getZipError() to determine if there was an error.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   265
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   266
     * Should be used only in QuaZip::mdUnzip mode.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   267
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   268
     * \note If the end of file was reached, getZipError() will return
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   269
     * \c UNZ_OK instead of \c UNZ_END_OF_LIST_OF_FILE. This is to make
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   270
     * things like this easier:
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   271
     * \code
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   272
     * for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   273
     *   // do something
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   274
     * }
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   275
     * if(zip.getZipError()==UNZ_OK) {
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   276
     *   // ok, there was no error
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   277
     * }
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   278
     * \endcode
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   279
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   280
    bool goToNextFile();
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   281
    /// Sets current file by its name.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   282
    /** Returns \c true if successful, \c false otherwise. Argument \a
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   283
     * cs specifies case sensitivity of the file name. Call
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   284
     * getZipError() in the case of a failure to get error code.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   285
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   286
     * This is not a wrapper to unzLocateFile() function. That is
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   287
     * because I had to implement locale-specific case-insensitive
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   288
     * comparison.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   289
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   290
     * Here are the differences from the original implementation:
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   291
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   292
     * - If the file was not found, error code is \c UNZ_OK, not \c
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   293
     *   UNZ_END_OF_LIST_OF_FILE (see also goToNextFile()).
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   294
     * - If this function fails, it unsets the current file rather than
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   295
     *   resetting it back to what it was before the call.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   296
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   297
     * If \a fileName is null string then this function unsets the
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   298
     * current file and return \c true. Note that you should close the
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   299
     * file first if it is open! See
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   300
     * QuaZipFile::QuaZipFile(QuaZip*,QObject*) for the details.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   301
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   302
     * Should be used only in QuaZip::mdUnzip mode.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   303
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   304
     * \sa setFileNameCodec(), CaseSensitivity
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   305
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   306
    bool setCurrentFile(const QString& fileName, CaseSensitivity cs =csDefault);
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   307
    /// Returns \c true if the current file has been set.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   308
    bool hasCurrentFile() const;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   309
    /// Retrieves information about the current file.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   310
    /** Fills the structure pointed by \a info. Returns \c true on
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   311
     * success, \c false otherwise. In the latter case structure pointed
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   312
     * by \a info remains untouched. If there was an error,
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   313
     * getZipError() returns error code.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   314
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   315
     * Should be used only in QuaZip::mdUnzip mode.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   316
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   317
     * Does nothing and returns \c false in any of the following cases.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   318
     * - ZIP is not open;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   319
     * - ZIP does not have current file;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   320
     * - \a info is \c NULL;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   321
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   322
     * In all these cases getZipError() returns \c UNZ_OK since there
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   323
     * is no ZIP/UNZIP API call.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   324
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   325
    bool getCurrentFileInfo(QuaZipFileInfo* info)const;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   326
    /// Returns the current file name.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   327
    /** Equivalent to calling getCurrentFileInfo() and then getting \c
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   328
     * name field of the QuaZipFileInfo structure, but faster and more
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   329
     * convenient.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   330
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   331
     * Should be used only in QuaZip::mdUnzip mode.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   332
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   333
    QString getCurrentFileName()const;
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   334
    /// Returns \c unzFile handle.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   335
    /** You can use this handle to directly call UNZIP part of the
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   336
     * ZIP/UNZIP package functions (see unzip.h).
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   337
     *
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   338
     * \warning When using the handle returned by this function, please
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   339
     * keep in mind that QuaZip class is unable to detect any changes
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   340
     * you make in the ZIP file state (e. g. changing current file, or
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   341
     * closing the handle). So please do not do anything with this
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   342
     * handle that is possible to do with the functions of this class.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   343
     * Or at least return the handle in the original state before
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   344
     * calling some another function of this class (including implicit
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   345
     * destructor calls and calls from the QuaZipFile objects that refer
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   346
     * to this QuaZip instance!). So if you have changed the current
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   347
     * file in the ZIP archive - then change it back or you may
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   348
     * experience some strange behavior or even crashes.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   349
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   350
    unzFile getUnzFile();
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   351
    /// Returns \c zipFile handle.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   352
    /** You can use this handle to directly call ZIP part of the
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   353
     * ZIP/UNZIP package functions (see zip.h). Warnings about the
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   354
     * getUnzFile() function also apply to this function.
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   355
     **/
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   356
    zipFile getZipFile();
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   357
};
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   358
57b117d441b9 consistent line endings
nemo
parents: 5752
diff changeset
   359
#endif