2
* zip.cpp - zip/unzip files
3
* Copyright (C) 2003 Justin Karneges
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
#include<qstringlist.h>
27
#include"minizip/unzip.h"
39
UnZip::UnZip(const QString &name)
52
void UnZip::setName(const QString &name)
57
const QString & UnZip::name() const
66
d->uf = unzOpen(QFile::encodeName(d->name).data());
83
const QStringList & UnZip::list() const
91
int err = unzGetGlobalInfo(d->uf, &gi);
96
for(int n = 0; n < (int)gi.number_entry; ++n) {
97
char filename_inzip[256];
98
unz_file_info file_info;
99
int err = unzGetCurrentFileInfo(d->uf, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0);
105
if((n+1) < (int)gi.number_entry) {
106
err = unzGoToNextFile(d->uf);
117
bool UnZip::readFile(const QString &fname, QByteArray *buf, int max)
119
int err = unzLocateFile(d->uf, QFile::encodeName(fname).data(), 0);
123
char filename_inzip[256];
124
unz_file_info file_info;
125
err = unzGetCurrentFileInfo(d->uf, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0);
129
err = unzOpenCurrentFile(d->uf);
134
QByteArray chunk(16384);
136
err = unzReadCurrentFile(d->uf, chunk.data(), chunk.size());
138
unzCloseCurrentFile(d->uf);
144
int oldsize = a.size();
145
if(max > 0 && oldsize + err > max)
147
a.resize(oldsize + err);
148
memcpy(a.data() + oldsize, chunk.data(), err);
150
if(max > 0 && (int)a.size() >= max)
154
err = unzCloseCurrentFile(d->uf);