misc/quazip/quazipfile.cpp
author Xeli
Sun, 22 Jan 2012 23:36:36 +0100
changeset 6589 2fa0a274a1e3
parent 5752 ea95ee97c805
child 7889 57b117d441b9
permissions -rw-r--r--
some tweaks to the build process, cmake now generates some vital files, fpc only compiles those files which have been changed since the last time, SDL still does not work
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5752
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     1
/*
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     2
Copyright (C) 2005-2011 Sergey A. Tachenov
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     3
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     4
This program is free software; you can redistribute it and/or modify it
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     5
under the terms of the GNU Lesser General Public License as published by
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     6
the Free Software Foundation; either version 2 of the License, or (at
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     7
your option) any later version.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     8
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
     9
This program is distributed in the hope that it will be useful, but
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    10
WITHOUT ANY WARRANTY; without even the implied warranty of
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    12
General Public License for more details.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    13
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    14
You should have received a copy of the GNU Lesser General Public License
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    15
along with this program; if not, write to the Free Software Foundation,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    16
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    17
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    18
See COPYING file for the full LGPL text.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    19
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    20
Original ZIP package is copyrighted by Gilles Vollant, see
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    21
quazip/(un)zip.h files for details, basically it's zlib license.
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    22
 **/
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    23
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    24
#include "quazipfile.h"
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    25
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    26
using namespace std;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    27
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    28
class QuaZipFilePrivate {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    29
  friend class QuaZipFile;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    30
  private:
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    31
    QuaZipFile *q;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    32
    QuaZip *zip;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    33
    QString fileName;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    34
    QuaZip::CaseSensitivity caseSensitivity;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    35
    bool raw;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    36
    qint64 writePos;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    37
    // these two are for writing raw files
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    38
    ulong uncompressedSize;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    39
    quint32 crc;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    40
    bool internal;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    41
    int zipError;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    42
    inline void resetZipError() const {setZipError(UNZ_OK);}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    43
    // const, but sets zipError!
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    44
    void setZipError(int zipError) const;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    45
    inline QuaZipFilePrivate(QuaZipFile *q):
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    46
      q(q), zip(NULL), internal(true), zipError(UNZ_OK) {}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    47
    inline QuaZipFilePrivate(QuaZipFile *q, const QString &zipName):
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    48
      q(q), internal(true), zipError(UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    49
      {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    50
        zip=new QuaZip(zipName);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    51
      }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    52
    inline QuaZipFilePrivate(QuaZipFile *q, const QString &zipName, const QString &fileName,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    53
        QuaZip::CaseSensitivity cs):
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    54
      q(q), internal(true), zipError(UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    55
      {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    56
        zip=new QuaZip(zipName);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    57
        this->fileName=fileName;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    58
        this->caseSensitivity=cs;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    59
      }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    60
    inline QuaZipFilePrivate(QuaZipFile *q, QuaZip *zip):
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    61
      q(q), zip(zip), internal(false), zipError(UNZ_OK) {}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    62
    inline ~QuaZipFilePrivate()
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    63
    {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    64
      if (internal)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    65
        delete zip;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    66
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    67
};
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    68
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    69
QuaZipFile::QuaZipFile():
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    70
  p(new QuaZipFilePrivate(this))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    71
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    72
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    73
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    74
QuaZipFile::QuaZipFile(QObject *parent):
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    75
  QIODevice(parent),
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    76
  p(new QuaZipFilePrivate(this))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    77
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    78
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    79
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    80
QuaZipFile::QuaZipFile(const QString& zipName, QObject *parent):
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    81
  QIODevice(parent),
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    82
  p(new QuaZipFilePrivate(this, zipName))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    83
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    84
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    85
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    86
QuaZipFile::QuaZipFile(const QString& zipName, const QString& fileName,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    87
    QuaZip::CaseSensitivity cs, QObject *parent):
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    88
  QIODevice(parent),
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    89
  p(new QuaZipFilePrivate(this, zipName, fileName, cs))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    90
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    91
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    92
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    93
QuaZipFile::QuaZipFile(QuaZip *zip, QObject *parent):
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    94
  QIODevice(parent),
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    95
  p(new QuaZipFilePrivate(this, zip))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    96
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    97
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    98
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
    99
QuaZipFile::~QuaZipFile()
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   100
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   101
  if (isOpen())
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   102
    close();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   103
  delete p;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   104
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   105
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   106
QString QuaZipFile::getZipName() const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   107
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   108
  return p->zip==NULL ? QString() : p->zip->getZipName();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   109
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   110
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   111
QString QuaZipFile::getActualFileName()const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   112
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   113
  p->setZipError(UNZ_OK);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   114
  if (p->zip == NULL || (openMode() & WriteOnly))
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   115
    return QString();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   116
  QString name=p->zip->getCurrentFileName();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   117
  if(name.isNull())
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   118
    p->setZipError(p->zip->getZipError());
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   119
  return name;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   120
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   121
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   122
void QuaZipFile::setZipName(const QString& zipName)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   123
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   124
  if(isOpen()) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   125
    qWarning("QuaZipFile::setZipName(): file is already open - can not set ZIP name");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   126
    return;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   127
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   128
  if(p->zip!=NULL && p->internal)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   129
    delete p->zip;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   130
  p->zip=new QuaZip(zipName);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   131
  p->internal=true;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   132
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   133
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   134
void QuaZipFile::setZip(QuaZip *zip)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   135
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   136
  if(isOpen()) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   137
    qWarning("QuaZipFile::setZip(): file is already open - can not set ZIP");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   138
    return;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   139
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   140
  if(p->zip!=NULL && p->internal)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   141
    delete p->zip;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   142
  p->zip=zip;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   143
  p->fileName=QString();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   144
  p->internal=false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   145
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   146
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   147
void QuaZipFile::setFileName(const QString& fileName, QuaZip::CaseSensitivity cs)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   148
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   149
  if(p->zip==NULL) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   150
    qWarning("QuaZipFile::setFileName(): call setZipName() first");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   151
    return;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   152
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   153
  if(!p->internal) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   154
    qWarning("QuaZipFile::setFileName(): should not be used when not using internal QuaZip");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   155
    return;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   156
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   157
  if(isOpen()) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   158
    qWarning("QuaZipFile::setFileName(): can not set file name for already opened file");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   159
    return;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   160
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   161
  p->fileName=fileName;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   162
  p->caseSensitivity=cs;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   163
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   164
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   165
void QuaZipFilePrivate::setZipError(int zipError) const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   166
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   167
  QuaZipFilePrivate *fakeThis = const_cast<QuaZipFilePrivate*>(this); // non-const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   168
  fakeThis->zipError=zipError;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   169
  if(zipError==UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   170
    q->setErrorString(QString());
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   171
  else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   172
    q->setErrorString(q->tr("ZIP/UNZIP API error %1").arg(zipError));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   173
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   174
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   175
bool QuaZipFile::open(OpenMode mode)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   176
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   177
  return open(mode, NULL);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   178
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   179
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   180
bool QuaZipFile::open(OpenMode mode, int *method, int *level, bool raw, const char *password)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   181
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   182
  p->resetZipError();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   183
  if(isOpen()) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   184
    qWarning("QuaZipFile::open(): already opened");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   185
    return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   186
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   187
  if(mode&Unbuffered) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   188
    qWarning("QuaZipFile::open(): Unbuffered mode is not supported");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   189
    return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   190
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   191
  if((mode&ReadOnly)&&!(mode&WriteOnly)) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   192
    if(p->internal) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   193
      if(!p->zip->open(QuaZip::mdUnzip)) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   194
        p->setZipError(p->zip->getZipError());
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   195
        return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   196
      }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   197
      if(!p->zip->setCurrentFile(p->fileName, p->caseSensitivity)) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   198
        p->setZipError(p->zip->getZipError());
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   199
        p->zip->close();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   200
        return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   201
      }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   202
    } else {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   203
      if(p->zip==NULL) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   204
        qWarning("QuaZipFile::open(): zip is NULL");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   205
        return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   206
      }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   207
      if(p->zip->getMode()!=QuaZip::mdUnzip) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   208
        qWarning("QuaZipFile::open(): file open mode %d incompatible with ZIP open mode %d",
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   209
            (int)mode, (int)p->zip->getMode());
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   210
        return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   211
      }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   212
      if(!p->zip->hasCurrentFile()) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   213
        qWarning("QuaZipFile::open(): zip does not have current file");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   214
        return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   215
      }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   216
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   217
    p->setZipError(unzOpenCurrentFile3(p->zip->getUnzFile(), method, level, (int)raw, password));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   218
    if(p->zipError==UNZ_OK) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   219
      setOpenMode(mode);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   220
      p->raw=raw;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   221
      return true;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   222
    } else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   223
      return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   224
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   225
  qWarning("QuaZipFile::open(): open mode %d not supported by this function", (int)mode);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   226
  return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   227
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   228
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   229
bool QuaZipFile::open(OpenMode mode, const QuaZipNewInfo& info,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   230
    const char *password, quint32 crc,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   231
    int method, int level, bool raw,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   232
    int windowBits, int memLevel, int strategy)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   233
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   234
  zip_fileinfo info_z;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   235
  p->resetZipError();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   236
  if(isOpen()) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   237
    qWarning("QuaZipFile::open(): already opened");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   238
    return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   239
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   240
  if((mode&WriteOnly)&&!(mode&ReadOnly)) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   241
    if(p->internal) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   242
      qWarning("QuaZipFile::open(): write mode is incompatible with internal QuaZip approach");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   243
      return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   244
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   245
    if(p->zip==NULL) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   246
      qWarning("QuaZipFile::open(): zip is NULL");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   247
      return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   248
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   249
    if(p->zip->getMode()!=QuaZip::mdCreate&&p->zip->getMode()!=QuaZip::mdAppend&&p->zip->getMode()!=QuaZip::mdAdd) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   250
      qWarning("QuaZipFile::open(): file open mode %d incompatible with ZIP open mode %d",
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   251
          (int)mode, (int)p->zip->getMode());
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   252
      return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   253
    }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   254
    info_z.tmz_date.tm_year=info.dateTime.date().year();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   255
    info_z.tmz_date.tm_mon=info.dateTime.date().month() - 1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   256
    info_z.tmz_date.tm_mday=info.dateTime.date().day();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   257
    info_z.tmz_date.tm_hour=info.dateTime.time().hour();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   258
    info_z.tmz_date.tm_min=info.dateTime.time().minute();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   259
    info_z.tmz_date.tm_sec=info.dateTime.time().second();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   260
    info_z.dosDate = 0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   261
    info_z.internal_fa=(uLong)info.internalAttr;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   262
    info_z.external_fa=(uLong)info.externalAttr;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   263
    p->setZipError(zipOpenNewFileInZip3(p->zip->getZipFile(),
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   264
          p->zip->getFileNameCodec()->fromUnicode(info.name).constData(), &info_z,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   265
          info.extraLocal.constData(), info.extraLocal.length(),
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   266
          info.extraGlobal.constData(), info.extraGlobal.length(),
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   267
          p->zip->getCommentCodec()->fromUnicode(info.comment).constData(),
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   268
          method, level, (int)raw,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   269
          windowBits, memLevel, strategy,
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   270
          password, (uLong)crc));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   271
    if(p->zipError==UNZ_OK) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   272
      p->writePos=0;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   273
      setOpenMode(mode);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   274
      p->raw=raw;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   275
      if(raw) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   276
        p->crc=crc;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   277
        p->uncompressedSize=info.uncompressedSize;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   278
      }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   279
      return true;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   280
    } else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   281
      return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   282
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   283
  qWarning("QuaZipFile::open(): open mode %d not supported by this function", (int)mode);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   284
  return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   285
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   286
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   287
bool QuaZipFile::isSequential()const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   288
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   289
  return true;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   290
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   291
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   292
qint64 QuaZipFile::pos()const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   293
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   294
  if(p->zip==NULL) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   295
    qWarning("QuaZipFile::pos(): call setZipName() or setZip() first");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   296
    return -1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   297
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   298
  if(!isOpen()) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   299
    qWarning("QuaZipFile::pos(): file is not open");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   300
    return -1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   301
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   302
  if(openMode()&ReadOnly)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   303
    return unztell(p->zip->getUnzFile());
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   304
  else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   305
    return p->writePos;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   306
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   307
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   308
bool QuaZipFile::atEnd()const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   309
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   310
  if(p->zip==NULL) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   311
    qWarning("QuaZipFile::atEnd(): call setZipName() or setZip() first");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   312
    return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   313
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   314
  if(!isOpen()) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   315
    qWarning("QuaZipFile::atEnd(): file is not open");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   316
    return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   317
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   318
  if(openMode()&ReadOnly)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   319
    return unzeof(p->zip->getUnzFile())==1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   320
  else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   321
    return true;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   322
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   323
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   324
qint64 QuaZipFile::size()const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   325
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   326
  if(!isOpen()) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   327
    qWarning("QuaZipFile::atEnd(): file is not open");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   328
    return -1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   329
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   330
  if(openMode()&ReadOnly)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   331
    return p->raw?csize():usize();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   332
  else
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   333
    return p->writePos;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   334
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   335
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   336
qint64 QuaZipFile::csize()const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   337
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   338
  unz_file_info info_z;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   339
  p->setZipError(UNZ_OK);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   340
  if(p->zip==NULL||p->zip->getMode()!=QuaZip::mdUnzip) return -1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   341
  p->setZipError(unzGetCurrentFileInfo(p->zip->getUnzFile(), &info_z, NULL, 0, NULL, 0, NULL, 0));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   342
  if(p->zipError!=UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   343
    return -1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   344
  return info_z.compressed_size;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   345
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   346
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   347
qint64 QuaZipFile::usize()const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   348
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   349
  unz_file_info info_z;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   350
  p->setZipError(UNZ_OK);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   351
  if(p->zip==NULL||p->zip->getMode()!=QuaZip::mdUnzip) return -1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   352
  p->setZipError(unzGetCurrentFileInfo(p->zip->getUnzFile(), &info_z, NULL, 0, NULL, 0, NULL, 0));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   353
  if(p->zipError!=UNZ_OK)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   354
    return -1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   355
  return info_z.uncompressed_size;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   356
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   357
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   358
bool QuaZipFile::getFileInfo(QuaZipFileInfo *info)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   359
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   360
  if(p->zip==NULL||p->zip->getMode()!=QuaZip::mdUnzip) return false;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   361
  p->zip->getCurrentFileInfo(info);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   362
  p->setZipError(p->zip->getZipError());
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   363
  return p->zipError==UNZ_OK;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   364
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   365
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   366
void QuaZipFile::close()
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   367
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   368
  p->resetZipError();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   369
  if(p->zip==NULL||!p->zip->isOpen()) return;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   370
  if(!isOpen()) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   371
    qWarning("QuaZipFile::close(): file isn't open");
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   372
    return;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   373
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   374
  if(openMode()&ReadOnly)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   375
    p->setZipError(unzCloseCurrentFile(p->zip->getUnzFile()));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   376
  else if(openMode()&WriteOnly)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   377
    if(isRaw()) p->setZipError(zipCloseFileInZipRaw(p->zip->getZipFile(), p->uncompressedSize, p->crc));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   378
    else p->setZipError(zipCloseFileInZip(p->zip->getZipFile()));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   379
  else {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   380
    qWarning("Wrong open mode: %d", (int)openMode());
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   381
    return;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   382
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   383
  if(p->zipError==UNZ_OK) setOpenMode(QIODevice::NotOpen);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   384
  else return;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   385
  if(p->internal) {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   386
    p->zip->close();
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   387
    p->setZipError(p->zip->getZipError());
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   388
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   389
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   390
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   391
qint64 QuaZipFile::readData(char *data, qint64 maxSize)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   392
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   393
  p->setZipError(UNZ_OK);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   394
  qint64 bytesRead=unzReadCurrentFile(p->zip->getUnzFile(), data, (unsigned)maxSize);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   395
  if(bytesRead<0) p->setZipError((int)bytesRead);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   396
  return bytesRead;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   397
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   398
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   399
qint64 QuaZipFile::writeData(const char* data, qint64 maxSize)
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   400
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   401
  p->setZipError(ZIP_OK);
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   402
  p->setZipError(zipWriteInFileInZip(p->zip->getZipFile(), data, (uint)maxSize));
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   403
  if(p->zipError!=ZIP_OK) return -1;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   404
  else {
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   405
    p->writePos+=maxSize;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   406
    return maxSize;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   407
  }
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   408
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   409
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   410
QString QuaZipFile::getFileName() const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   411
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   412
  return p->fileName;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   413
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   414
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   415
QuaZip::CaseSensitivity QuaZipFile::getCaseSensitivity() const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   416
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   417
  return p->caseSensitivity;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   418
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   419
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   420
bool QuaZipFile::isRaw() const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   421
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   422
  return p->raw;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   423
}
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   424
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   425
int QuaZipFile::getZipError() const
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   426
{
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   427
  return p->zipError;
ea95ee97c805 Add QuaZIP library to build system
unc0rr
parents:
diff changeset
   428
}