summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/themeeditor/gui/fontdownloader.cpp158
-rw-r--r--utils/themeeditor/gui/fontdownloader.h59
-rw-r--r--utils/themeeditor/gui/fontdownloader.ui87
-rw-r--r--utils/themeeditor/gui/preferencesdialog.cpp32
-rw-r--r--utils/themeeditor/gui/preferencesdialog.h2
-rw-r--r--utils/themeeditor/gui/preferencesdialog.ui100
-rw-r--r--utils/themeeditor/gui/skindocument.h2
-rw-r--r--utils/themeeditor/models/projectmodel.h2
-rw-r--r--utils/themeeditor/models/targetdata.cpp11
-rw-r--r--utils/themeeditor/models/targetdata.h9
-rw-r--r--utils/themeeditor/quazip/LICENSE.GPL341
-rw-r--r--utils/themeeditor/quazip/README.ROCKBOX6
-rw-r--r--utils/themeeditor/quazip/crypt.h133
-rw-r--r--utils/themeeditor/quazip/ioapi.c184
-rw-r--r--utils/themeeditor/quazip/ioapi.h75
-rw-r--r--utils/themeeditor/quazip/quazip.cpp285
-rw-r--r--utils/themeeditor/quazip/quazip.h346
-rw-r--r--utils/themeeditor/quazip/quazipfile.cpp377
-rw-r--r--utils/themeeditor/quazip/quazipfile.h442
-rw-r--r--utils/themeeditor/quazip/quazipfileinfo.h73
-rw-r--r--utils/themeeditor/quazip/quazipnewinfo.cpp59
-rw-r--r--utils/themeeditor/quazip/quazipnewinfo.h109
-rw-r--r--utils/themeeditor/quazip/unzip.c1601
-rw-r--r--utils/themeeditor/quazip/unzip.h354
-rw-r--r--utils/themeeditor/quazip/zip.c1221
-rw-r--r--utils/themeeditor/quazip/zip.h235
-rw-r--r--utils/themeeditor/themeeditor.pro36
-rw-r--r--utils/themeeditor/zlib/zconf.h326
-rw-r--r--utils/themeeditor/zlib/zlib.h1200
29 files changed, 7841 insertions, 24 deletions
diff --git a/utils/themeeditor/gui/fontdownloader.cpp b/utils/themeeditor/gui/fontdownloader.cpp
new file mode 100644
index 0000000000..7aa4cd8d57
--- /dev/null
+++ b/utils/themeeditor/gui/fontdownloader.cpp
@@ -0,0 +1,158 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "fontdownloader.h"
23#include "ui_fontdownloader.h"
24
25#include "quazip.h"
26#include "quazipfile.h"
27#include "quazipfileinfo.h"
28
29#include <QNetworkRequest>
30#include <QNetworkReply>
31#include <QCloseEvent>
32
33#include <QDebug>
34
35FontDownloader::FontDownloader(QWidget *parent, QString path) :
36 QDialog(parent),
37 ui(new Ui::FontDownloader), dir(path), reply(0)
38{
39 ui->setupUi(this);
40
41 manager = new QNetworkAccessManager();
42
43 if(dir.isReadable())
44 {
45 fout.setFileName(dir.absolutePath() + "/fonts.zip");
46 if(fout.open(QFile::WriteOnly))
47 {
48 ui->label->setText(tr("Downloading font pack"));
49
50 QNetworkRequest request;
51 request.setUrl(QUrl("http://download.rockbox.org"
52 "/daily/fonts/rockbox-fonts.zip"));
53 request.setRawHeader("User-Agent", "Rockbox Theme Editor");
54
55 reply = manager->get(request);
56
57 QObject::connect(reply, SIGNAL(readyRead()),
58 this, SLOT(dataReceived()));
59 QObject::connect(reply, SIGNAL(finished()),
60 this, SLOT(finished()));
61 QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
62 this, SLOT(progress(qint64,qint64)));
63 }
64 else
65 {
66 ui->label->setText(tr("Error: Couldn't open archive file"));
67 }
68 }
69 else
70 {
71 ui->label->setText(tr("Error: Fonts directory not readable"));
72 }
73
74}
75
76FontDownloader::~FontDownloader()
77{
78 delete ui;
79 fout.close();
80 manager->deleteLater();
81
82 if(reply)
83 {
84 reply->abort();
85 reply->deleteLater();
86 }
87}
88
89void FontDownloader::cancel()
90{
91 if(reply)
92 {
93 reply->abort();
94 reply->deleteLater();
95 reply = 0;
96 }
97}
98
99void FontDownloader::dataReceived()
100{
101 fout.write(reply->readAll());
102}
103
104void FontDownloader::progress(qint64 bytes, qint64 available)
105{
106 if(available > 0)
107 {
108 ui->progressBar->setMaximum(available);
109 ui->progressBar->setValue(bytes);
110 }
111}
112
113void FontDownloader::finished()
114{
115 fout.close();
116 reply->deleteLater();
117 reply = 0;
118 ui->label->setText(tr("Download complete"));
119
120 /* Extracting the ZIP archive */
121 QuaZip archive(fout.fileName());
122 QuaZipFile zipFile(&archive);
123 archive.open(QuaZip::mdUnzip);
124
125 bool more;
126 for(more = archive.goToFirstFile(); more; more = archive.goToNextFile())
127 {
128 if(archive.getCurrentFileName().split("/").last() == "")
129 continue;
130
131 QFile fontFile(dir.absolutePath() + "/" +
132 archive.getCurrentFileName().split("/").last());
133 fontFile.open(QFile::WriteOnly);
134
135 zipFile.open(QIODevice::ReadOnly);
136 fontFile.write(zipFile.readAll());
137 zipFile.close();
138
139 fontFile.close();
140 }
141
142 archive.close();
143 QFile::remove(dir.absolutePath() + "/fonts.zip");
144
145 hide();
146 this->deleteLater();
147}
148
149void FontDownloader::netError(QNetworkReply::NetworkError code)
150{
151 ui->label->setText(tr("Network error: ") + reply->errorString());
152}
153
154void FontDownloader::closeEvent(QCloseEvent *event)
155{
156 cancel();
157 event->accept();
158}
diff --git a/utils/themeeditor/gui/fontdownloader.h b/utils/themeeditor/gui/fontdownloader.h
new file mode 100644
index 0000000000..acd8ea54b3
--- /dev/null
+++ b/utils/themeeditor/gui/fontdownloader.h
@@ -0,0 +1,59 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef FONTDOWNLOADER_H
23#define FONTDOWNLOADER_H
24
25#include <QDialog>
26#include <QDir>
27#include <QNetworkAccessManager>
28#include <QNetworkReply>
29
30namespace Ui {
31 class FontDownloader;
32}
33
34class FontDownloader : public QDialog {
35 Q_OBJECT
36public:
37 FontDownloader(QWidget *parent, QString dir);
38 virtual ~FontDownloader();
39
40private slots:
41 void cancel();
42
43 void dataReceived();
44 void progress(qint64 bytes, qint64 available);
45 void finished();
46 void netError(QNetworkReply::NetworkError code);
47
48private:
49 void closeEvent(QCloseEvent *event);
50
51 Ui::FontDownloader *ui;
52
53 QNetworkAccessManager* manager;
54 QDir dir;
55 QFile fout;
56 QNetworkReply* reply;
57};
58
59#endif // FONTDOWNLOADER_H
diff --git a/utils/themeeditor/gui/fontdownloader.ui b/utils/themeeditor/gui/fontdownloader.ui
new file mode 100644
index 0000000000..53b69a8be7
--- /dev/null
+++ b/utils/themeeditor/gui/fontdownloader.ui
@@ -0,0 +1,87 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<ui version="4.0">
3 <class>FontDownloader</class>
4 <widget class="QDialog" name="FontDownloader">
5 <property name="windowModality">
6 <enum>Qt::WindowModal</enum>
7 </property>
8 <property name="geometry">
9 <rect>
10 <x>0</x>
11 <y>0</y>
12 <width>400</width>
13 <height>107</height>
14 </rect>
15 </property>
16 <property name="windowTitle">
17 <string>Downloading Font Pack</string>
18 </property>
19 <property name="windowIcon">
20 <iconset resource="../resources.qrc">
21 <normaloff>:/resources/windowicon.png</normaloff>:/resources/windowicon.png</iconset>
22 </property>
23 <property name="sizeGripEnabled">
24 <bool>true</bool>
25 </property>
26 <property name="modal">
27 <bool>true</bool>
28 </property>
29 <layout class="QVBoxLayout" name="verticalLayout">
30 <item>
31 <widget class="QProgressBar" name="progressBar">
32 <property name="value">
33 <number>0</number>
34 </property>
35 </widget>
36 </item>
37 <item>
38 <widget class="QLabel" name="label">
39 <property name="text">
40 <string>Checking Directory</string>
41 </property>
42 </widget>
43 </item>
44 <item>
45 <spacer name="verticalSpacer">
46 <property name="orientation">
47 <enum>Qt::Vertical</enum>
48 </property>
49 <property name="sizeHint" stdset="0">
50 <size>
51 <width>20</width>
52 <height>40</height>
53 </size>
54 </property>
55 </spacer>
56 </item>
57 <item>
58 <layout class="QHBoxLayout" name="horizontalLayout">
59 <item>
60 <spacer name="horizontalSpacer">
61 <property name="orientation">
62 <enum>Qt::Horizontal</enum>
63 </property>
64 <property name="sizeHint" stdset="0">
65 <size>
66 <width>40</width>
67 <height>20</height>
68 </size>
69 </property>
70 </spacer>
71 </item>
72 <item>
73 <widget class="QPushButton" name="cancelButton">
74 <property name="text">
75 <string>Cancel</string>
76 </property>
77 </widget>
78 </item>
79 </layout>
80 </item>
81 </layout>
82 </widget>
83 <resources>
84 <include location="../resources.qrc"/>
85 </resources>
86 <connections/>
87</ui>
diff --git a/utils/themeeditor/gui/preferencesdialog.cpp b/utils/themeeditor/gui/preferencesdialog.cpp
index dbb3249e9f..b8d0a0a6d6 100644
--- a/utils/themeeditor/gui/preferencesdialog.cpp
+++ b/utils/themeeditor/gui/preferencesdialog.cpp
@@ -21,6 +21,7 @@
21 21
22#include "preferencesdialog.h" 22#include "preferencesdialog.h"
23#include "ui_preferencesdialog.h" 23#include "ui_preferencesdialog.h"
24#include "fontdownloader.h"
24 25
25#include <QSettings> 26#include <QSettings>
26#include <QColorDialog> 27#include <QColorDialog>
@@ -124,6 +125,14 @@ void PreferencesDialog::loadRender()
124 false).toBool()); 125 false).toBool());
125 126
126 settings.endGroup(); 127 settings.endGroup();
128
129 settings.beginGroup("TargetData");
130
131 ui->dbBox->setText(settings.value("targetDbPath",
132 QDir::homePath() + "/.targetdb")
133 .toString());
134
135 settings.endGroup();
127} 136}
128 137
129void PreferencesDialog::saveSettings() 138void PreferencesDialog::saveSettings()
@@ -183,6 +192,10 @@ void PreferencesDialog::saveRender()
183 settings.setValue("autoHighlightTree", ui->autoHighlightBox->isChecked()); 192 settings.setValue("autoHighlightTree", ui->autoHighlightBox->isChecked());
184 193
185 settings.endGroup(); 194 settings.endGroup();
195
196 settings.beginGroup("TargetData");
197 settings.setValue("targetDbPath", ui->dbBox->text());
198 settings.endGroup();
186} 199}
187 200
188void PreferencesDialog::setupUI() 201void PreferencesDialog::setupUI()
@@ -203,6 +216,10 @@ void PreferencesDialog::setupUI()
203 216
204 QObject::connect(ui->fontBrowseButton, SIGNAL(clicked()), 217 QObject::connect(ui->fontBrowseButton, SIGNAL(clicked()),
205 this, SLOT(browseFont())); 218 this, SLOT(browseFont()));
219 QObject::connect(ui->browseDB, SIGNAL(clicked()),
220 this, SLOT(browseDB()));
221 QObject::connect(ui->dlFontsButton, SIGNAL(clicked()),
222 this, SLOT(dlFonts()));
206} 223}
207 224
208void PreferencesDialog::colorClicked() 225void PreferencesDialog::colorClicked()
@@ -243,6 +260,21 @@ void PreferencesDialog::browseFont()
243 ui->fontBox->setText(path); 260 ui->fontBox->setText(path);
244} 261}
245 262
263void PreferencesDialog::browseDB()
264{
265 QString path = QFileDialog::getOpenFileName(this, tr("Target DB"),
266 QDir(ui->dbBox->text()).
267 absolutePath(),
268 "All Files (*)");
269 ui->dbBox->setText(path);
270}
271
272void PreferencesDialog::dlFonts()
273{
274 FontDownloader* dl = new FontDownloader(this, ui->fontBox->text());
275 dl->show();
276}
277
246void PreferencesDialog::accept() 278void PreferencesDialog::accept()
247{ 279{
248 saveSettings(); 280 saveSettings();
diff --git a/utils/themeeditor/gui/preferencesdialog.h b/utils/themeeditor/gui/preferencesdialog.h
index cc1d7c75e3..16d239c18f 100644
--- a/utils/themeeditor/gui/preferencesdialog.h
+++ b/utils/themeeditor/gui/preferencesdialog.h
@@ -48,6 +48,8 @@ public slots:
48private slots: 48private slots:
49 void colorClicked(); 49 void colorClicked();
50 void browseFont(); 50 void browseFont();
51 void browseDB();
52 void dlFonts();
51 53
52private: 54private:
53 Ui::PreferencesDialog *ui; 55 Ui::PreferencesDialog *ui;
diff --git a/utils/themeeditor/gui/preferencesdialog.ui b/utils/themeeditor/gui/preferencesdialog.ui
index c455ed0786..824862e025 100644
--- a/utils/themeeditor/gui/preferencesdialog.ui
+++ b/utils/themeeditor/gui/preferencesdialog.ui
@@ -7,7 +7,7 @@
7 <x>0</x> 7 <x>0</x>
8 <y>0</y> 8 <y>0</y>
9 <width>370</width> 9 <width>370</width>
10 <height>370</height> 10 <height>295</height>
11 </rect> 11 </rect>
12 </property> 12 </property>
13 <property name="windowTitle"> 13 <property name="windowTitle">
@@ -24,7 +24,7 @@
24 <enum>QTabWidget::North</enum> 24 <enum>QTabWidget::North</enum>
25 </property> 25 </property>
26 <property name="currentIndex"> 26 <property name="currentIndex">
27 <number>0</number> 27 <number>2</number>
28 </property> 28 </property>
29 <widget class="QWidget" name="tab_2"> 29 <widget class="QWidget" name="tab_2">
30 <attribute name="title"> 30 <attribute name="title">
@@ -32,29 +32,31 @@
32 </attribute> 32 </attribute>
33 <layout class="QVBoxLayout" name="verticalLayout_2"> 33 <layout class="QVBoxLayout" name="verticalLayout_2">
34 <item> 34 <item>
35 <layout class="QHBoxLayout" name="horizontalLayout_7"> 35 <layout class="QFormLayout" name="formLayout">
36 <item> 36 <item row="0" column="0">
37 <widget class="QLabel" name="label_7"> 37 <widget class="QLabel" name="label_7">
38 <property name="text"> 38 <property name="text">
39 <string>Font</string> 39 <string>Font</string>
40 </property> 40 </property>
41 <property name="buddy">
42 <cstring>fontSelect</cstring>
43 </property>
41 </widget> 44 </widget>
42 </item> 45 </item>
43 <item> 46 <item row="0" column="1">
44 <widget class="QFontComboBox" name="fontSelect"/> 47 <widget class="QFontComboBox" name="fontSelect"/>
45 </item> 48 </item>
46 </layout> 49 <item row="1" column="0">
47 </item>
48 <item>
49 <layout class="QHBoxLayout" name="horizontalLayout_8">
50 <item>
51 <widget class="QLabel" name="label_8"> 50 <widget class="QLabel" name="label_8">
52 <property name="text"> 51 <property name="text">
53 <string>Size</string> 52 <string>Size</string>
54 </property> 53 </property>
54 <property name="buddy">
55 <cstring>fontSize</cstring>
56 </property>
55 </widget> 57 </widget>
56 </item> 58 </item>
57 <item> 59 <item row="1" column="1">
58 <widget class="QSpinBox" name="fontSize"> 60 <widget class="QSpinBox" name="fontSize">
59 <property name="value"> 61 <property name="value">
60 <number>12</number> 62 <number>12</number>
@@ -118,7 +120,7 @@
118 </layout> 120 </layout>
119 </item> 121 </item>
120 <item> 122 <item>
121 <layout class="QHBoxLayout" name="horizontalLayout_9"> 123 <layout class="QHBoxLayout" name="horizontalLayout_7">
122 <item> 124 <item>
123 <widget class="QLabel" name="label_9"> 125 <widget class="QLabel" name="label_9">
124 <property name="text"> 126 <property name="text">
@@ -138,6 +140,19 @@
138 </item> 140 </item>
139 </layout> 141 </layout>
140 </item> 142 </item>
143 <item>
144 <spacer name="verticalSpacer_3">
145 <property name="orientation">
146 <enum>Qt::Vertical</enum>
147 </property>
148 <property name="sizeHint" stdset="0">
149 <size>
150 <width>20</width>
151 <height>40</height>
152 </size>
153 </property>
154 </spacer>
155 </item>
141 </layout> 156 </layout>
142 </widget> 157 </widget>
143 <widget class="QWidget" name="prefsGroupsPage1"> 158 <widget class="QWidget" name="prefsGroupsPage1">
@@ -256,6 +271,19 @@
256 </item> 271 </item>
257 </layout> 272 </layout>
258 </item> 273 </item>
274 <item>
275 <spacer name="verticalSpacer_2">
276 <property name="orientation">
277 <enum>Qt::Vertical</enum>
278 </property>
279 <property name="sizeHint" stdset="0">
280 <size>
281 <width>20</width>
282 <height>40</height>
283 </size>
284 </property>
285 </spacer>
286 </item>
259 </layout> 287 </layout>
260 </widget> 288 </widget>
261 <widget class="QWidget" name="tab"> 289 <widget class="QWidget" name="tab">
@@ -301,6 +329,54 @@
301 </item> 329 </item>
302 </layout> 330 </layout>
303 </item> 331 </item>
332 <item>
333 <widget class="QPushButton" name="dlFontsButton">
334 <property name="text">
335 <string>Download Fontpack</string>
336 </property>
337 </widget>
338 </item>
339 <item>
340 <layout class="QHBoxLayout" name="horizontalLayout_11">
341 <item>
342 <widget class="QLabel" name="label_11">
343 <property name="text">
344 <string>Target DB</string>
345 </property>
346 </widget>
347 </item>
348 <item>
349 <widget class="QLineEdit" name="dbBox"/>
350 </item>
351 <item>
352 <widget class="QPushButton" name="browseDB">
353 <property name="text">
354 <string>Browse...</string>
355 </property>
356 </widget>
357 </item>
358 </layout>
359 </item>
360 <item>
361 <widget class="QPushButton" name="pushButton_2">
362 <property name="text">
363 <string>Update Target DB</string>
364 </property>
365 </widget>
366 </item>
367 <item>
368 <spacer name="verticalSpacer">
369 <property name="orientation">
370 <enum>Qt::Vertical</enum>
371 </property>
372 <property name="sizeHint" stdset="0">
373 <size>
374 <width>20</width>
375 <height>40</height>
376 </size>
377 </property>
378 </spacer>
379 </item>
304 </layout> 380 </layout>
305 </widget> 381 </widget>
306 </widget> 382 </widget>
diff --git a/utils/themeeditor/gui/skindocument.h b/utils/themeeditor/gui/skindocument.h
index f7ac2bbc2c..927a5cf9fc 100644
--- a/utils/themeeditor/gui/skindocument.h
+++ b/utils/themeeditor/gui/skindocument.h
@@ -50,7 +50,7 @@ public:
50 "FMS Files (*.fms *.rfms);;" 50 "FMS Files (*.fms *.rfms);;"
51 "All Skin Files (*.wps *.rwps *.sbs " 51 "All Skin Files (*.wps *.rwps *.sbs "
52 "*.rsbs *.fms *.rfms);;" 52 "*.rsbs *.fms *.rfms);;"
53 "All Files (*.*)"); 53 "All Files (*)");
54 } 54 }
55 55
56 SkinDocument(QLabel* statusLabel, ProjectModel* project = 0, 56 SkinDocument(QLabel* statusLabel, ProjectModel* project = 0,
diff --git a/utils/themeeditor/models/projectmodel.h b/utils/themeeditor/models/projectmodel.h
index 4cc531b88f..4afca2837e 100644
--- a/utils/themeeditor/models/projectmodel.h
+++ b/utils/themeeditor/models/projectmodel.h
@@ -35,7 +35,7 @@ public:
35 35
36 static QString fileFilter() 36 static QString fileFilter()
37 { 37 {
38 return QObject::tr("Project Files (*.cfg);;All Files (*.*)"); 38 return QObject::tr("Project Files (*.cfg);;All Files (*)");
39 } 39 }
40 40
41 ProjectModel(QString config, EditorWindow* mainWindow, QObject *parent = 0); 41 ProjectModel(QString config, EditorWindow* mainWindow, QObject *parent = 0);
diff --git a/utils/themeeditor/models/targetdata.cpp b/utils/themeeditor/models/targetdata.cpp
index 70d231988b..b44f1e67b3 100644
--- a/utils/themeeditor/models/targetdata.cpp
+++ b/utils/themeeditor/models/targetdata.cpp
@@ -22,11 +22,17 @@
22#include "targetdata.h" 22#include "targetdata.h"
23 23
24#include <QStringList> 24#include <QStringList>
25#include <QSettings>
25 26
26const QString TargetData::reserved = "{}:#\n"; 27const QString TargetData::reserved = "{}:#\n";
27 28
28TargetData::TargetData(QString file) 29TargetData::TargetData()
29{ 30{
31 QSettings settings;
32 settings.beginGroup("TargetData");
33 QString file = settings.value("targetDbPath", "").toString();
34 settings.endGroup();
35
30 if(!QFile::exists(file)) 36 if(!QFile::exists(file))
31 file = ":/targets/targetdb"; 37 file = ":/targets/targetdb";
32 38
@@ -132,7 +138,8 @@ TargetData::TargetData(QString file)
132 /* Checking for the closing '}' and adding the entry */ 138 /* Checking for the closing '}' and adding the entry */
133 if(require('}', data, cursor)) 139 if(require('}', data, cursor))
134 { 140 {
135 entries.append(Entry(name, size, depth, rSize, rDepth, fm, record)); 141 entries.append(Entry(id, name, size, depth, rSize, rDepth,
142 fm, record));
136 indices.insert(id, index); 143 indices.insert(id, index);
137 index++; 144 index++;
138 } 145 }
diff --git a/utils/themeeditor/models/targetdata.h b/utils/themeeditor/models/targetdata.h
index 09276c5966..89bb78bdc3 100644
--- a/utils/themeeditor/models/targetdata.h
+++ b/utils/themeeditor/models/targetdata.h
@@ -39,7 +39,7 @@ public:
39 None 39 None
40 }; 40 };
41 41
42 TargetData(QString file = ""); 42 TargetData();
43 virtual ~TargetData(); 43 virtual ~TargetData();
44 44
45 int count(){ return indices.count(); } 45 int count(){ return indices.count(); }
@@ -57,11 +57,12 @@ public:
57private: 57private:
58 struct Entry 58 struct Entry
59 { 59 {
60 Entry(QString name, QRect size, ScreenDepth depth, QRect rSize, 60 Entry(QString id, QString name, QRect size, ScreenDepth depth,
61 ScreenDepth rDepth, bool fm, bool record) 61 QRect rSize, ScreenDepth rDepth, bool fm, bool record)
62 : name(name), size(size), depth(depth), rSize(rSize), 62 : id(id), name(name), size(size), depth(depth), rSize(rSize),
63 rDepth(rDepth), fm(fm), record(record){ } 63 rDepth(rDepth), fm(fm), record(record){ }
64 64
65 QString id;
65 QString name; 66 QString name;
66 QRect size; 67 QRect size;
67 ScreenDepth depth; 68 ScreenDepth depth;
diff --git a/utils/themeeditor/quazip/LICENSE.GPL b/utils/themeeditor/quazip/LICENSE.GPL
new file mode 100644
index 0000000000..04a7580109
--- /dev/null
+++ b/utils/themeeditor/quazip/LICENSE.GPL
@@ -0,0 +1,341 @@
1 GNU GENERAL PUBLIC LICENSE
2 Version 2, June 1991
3
4 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6 Everyone is permitted to copy and distribute verbatim copies
7 of this license document, but changing it is not allowed.
8
9 Preamble
10
11 The licenses for most software are designed to take away your
12freedom to share and change it. By contrast, the GNU General Public
13License is intended to guarantee your freedom to share and change free
14software--to make sure the software is free for all its users. This
15General Public License applies to most of the Free Software
16Foundation's software and to any other program whose authors commit to
17using it. (Some other Free Software Foundation software is covered by
18the GNU Library General Public License instead.) You can apply it to
19your programs, too.
20
21 When we speak of free software, we are referring to freedom, not
22price. Our General Public Licenses are designed to make sure that you
23have the freedom to distribute copies of free software (and charge for
24this service if you wish), that you receive source code or can get it
25if you want it, that you can change the software or use pieces of it
26in new free programs; and that you know you can do these things.
27
28 To protect your rights, we need to make restrictions that forbid
29anyone to deny you these rights or to ask you to surrender the rights.
30These restrictions translate to certain responsibilities for you if you
31distribute copies of the software, or if you modify it.
32
33 For example, if you distribute copies of such a program, whether
34gratis or for a fee, you must give the recipients all the rights that
35you have. You must make sure that they, too, receive or can get the
36source code. And you must show them these terms so they know their
37rights.
38
39 We protect your rights with two steps: (1) copyright the software, and
40(2) offer you this license which gives you legal permission to copy,
41distribute and/or modify the software.
42
43 Also, for each author's protection and ours, we want to make certain
44that everyone understands that there is no warranty for this free
45software. If the software is modified by someone else and passed on, we
46want its recipients to know that what they have is not the original, so
47that any problems introduced by others will not reflect on the original
48authors' reputations.
49
50 Finally, any free program is threatened constantly by software
51patents. We wish to avoid the danger that redistributors of a free
52program will individually obtain patent licenses, in effect making the
53program proprietary. To prevent this, we have made it clear that any
54patent must be licensed for everyone's free use or not licensed at all.
55
56 The precise terms and conditions for copying, distribution and
57modification follow.
58
59 GNU GENERAL PUBLIC LICENSE
60 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
62 0. This License applies to any program or other work which contains
63a notice placed by the copyright holder saying it may be distributed
64under the terms of this General Public License. The "Program", below,
65refers to any such program or work, and a "work based on the Program"
66means either the Program or any derivative work under copyright law:
67that is to say, a work containing the Program or a portion of it,
68either verbatim or with modifications and/or translated into another
69language. (Hereinafter, translation is included without limitation in
70the term "modification".) Each licensee is addressed as "you".
71
72Activities other than copying, distribution and modification are not
73covered by this License; they are outside its scope. The act of
74running the Program is not restricted, and the output from the Program
75is covered only if its contents constitute a work based on the
76Program (independent of having been made by running the Program).
77Whether that is true depends on what the Program does.
78
79 1. You may copy and distribute verbatim copies of the Program's
80source code as you receive it, in any medium, provided that you
81conspicuously and appropriately publish on each copy an appropriate
82copyright notice and disclaimer of warranty; keep intact all the
83notices that refer to this License and to the absence of any warranty;
84and give any other recipients of the Program a copy of this License
85along with the Program.
86
87You may charge a fee for the physical act of transferring a copy, and
88you may at your option offer warranty protection in exchange for a fee.
89
90 2. You may modify your copy or copies of the Program or any portion
91of it, thus forming a work based on the Program, and copy and
92distribute such modifications or work under the terms of Section 1
93above, provided that you also meet all of these conditions:
94
95 a) You must cause the modified files to carry prominent notices
96 stating that you changed the files and the date of any change.
97
98 b) You must cause any work that you distribute or publish, that in
99 whole or in part contains or is derived from the Program or any
100 part thereof, to be licensed as a whole at no charge to all third
101 parties under the terms of this License.
102
103 c) If the modified program normally reads commands interactively
104 when run, you must cause it, when started running for such
105 interactive use in the most ordinary way, to print or display an
106 announcement including an appropriate copyright notice and a
107 notice that there is no warranty (or else, saying that you provide
108 a warranty) and that users may redistribute the program under
109 these conditions, and telling the user how to view a copy of this
110 License. (Exception: if the Program itself is interactive but
111 does not normally print such an announcement, your work based on
112 the Program is not required to print an announcement.)
113
114These requirements apply to the modified work as a whole. If
115identifiable sections of that work are not derived from the Program,
116and can be reasonably considered independent and separate works in
117themselves, then this License, and its terms, do not apply to those
118sections when you distribute them as separate works. But when you
119distribute the same sections as part of a whole which is a work based
120on the Program, the distribution of the whole must be on the terms of
121this License, whose permissions for other licensees extend to the
122entire whole, and thus to each and every part regardless of who wrote it.
123
124Thus, it is not the intent of this section to claim rights or contest
125your rights to work written entirely by you; rather, the intent is to
126exercise the right to control the distribution of derivative or
127collective works based on the Program.
128
129In addition, mere aggregation of another work not based on the Program
130with the Program (or with a work based on the Program) on a volume of
131a storage or distribution medium does not bring the other work under
132the scope of this License.
133
134 3. You may copy and distribute the Program (or a work based on it,
135under Section 2) in object code or executable form under the terms of
136Sections 1 and 2 above provided that you also do one of the following:
137
138 a) Accompany it with the complete corresponding machine-readable
139 source code, which must be distributed under the terms of Sections
140 1 and 2 above on a medium customarily used for software interchange; or,
141
142 b) Accompany it with a written offer, valid for at least three
143 years, to give any third party, for a charge no more than your
144 cost of physically performing source distribution, a complete
145 machine-readable copy of the corresponding source code, to be
146 distributed under the terms of Sections 1 and 2 above on a medium
147 customarily used for software interchange; or,
148
149 c) Accompany it with the information you received as to the offer
150 to distribute corresponding source code. (This alternative is
151 allowed only for noncommercial distribution and only if you
152 received the program in object code or executable form with such
153 an offer, in accord with Subsection b above.)
154
155The source code for a work means the preferred form of the work for
156making modifications to it. For an executable work, complete source
157code means all the source code for all modules it contains, plus any
158associated interface definition files, plus the scripts used to
159control compilation and installation of the executable. However, as a
160special exception, the source code distributed need not include
161anything that is normally distributed (in either source or binary
162form) with the major components (compiler, kernel, and so on) of the
163operating system on which the executable runs, unless that component
164itself accompanies the executable.
165
166If distribution of executable or object code is made by offering
167access to copy from a designated place, then offering equivalent
168access to copy the source code from the same place counts as
169distribution of the source code, even though third parties are not
170compelled to copy the source along with the object code.
171
172 4. You may not copy, modify, sublicense, or distribute the Program
173except as expressly provided under this License. Any attempt
174otherwise to copy, modify, sublicense or distribute the Program is
175void, and will automatically terminate your rights under this License.
176However, parties who have received copies, or rights, from you under
177this License will not have their licenses terminated so long as such
178parties remain in full compliance.
179
180 5. You are not required to accept this License, since you have not
181signed it. However, nothing else grants you permission to modify or
182distribute the Program or its derivative works. These actions are
183prohibited by law if you do not accept this License. Therefore, by
184modifying or distributing the Program (or any work based on the
185Program), you indicate your acceptance of this License to do so, and
186all its terms and conditions for copying, distributing or modifying
187the Program or works based on it.
188
189 6. Each time you redistribute the Program (or any work based on the
190Program), the recipient automatically receives a license from the
191original licensor to copy, distribute or modify the Program subject to
192these terms and conditions. You may not impose any further
193restrictions on the recipients' exercise of the rights granted herein.
194You are not responsible for enforcing compliance by third parties to
195this License.
196
197 7. If, as a consequence of a court judgment or allegation of patent
198infringement or for any other reason (not limited to patent issues),
199conditions are imposed on you (whether by court order, agreement or
200otherwise) that contradict the conditions of this License, they do not
201excuse you from the conditions of this License. If you cannot
202distribute so as to satisfy simultaneously your obligations under this
203License and any other pertinent obligations, then as a consequence you
204may not distribute the Program at all. For example, if a patent
205license would not permit royalty-free redistribution of the Program by
206all those who receive copies directly or indirectly through you, then
207the only way you could satisfy both it and this License would be to
208refrain entirely from distribution of the Program.
209
210If any portion of this section is held invalid or unenforceable under
211any particular circumstance, the balance of the section is intended to
212apply and the section as a whole is intended to apply in other
213circumstances.
214
215It is not the purpose of this section to induce you to infringe any
216patents or other property right claims or to contest validity of any
217such claims; this section has the sole purpose of protecting the
218integrity of the free software distribution system, which is
219implemented by public license practices. Many people have made
220generous contributions to the wide range of software distributed
221through that system in reliance on consistent application of that
222system; it is up to the author/donor to decide if he or she is willing
223to distribute software through any other system and a licensee cannot
224impose that choice.
225
226This section is intended to make thoroughly clear what is believed to
227be a consequence of the rest of this License.
228
229 8. If the distribution and/or use of the Program is restricted in
230certain countries either by patents or by copyrighted interfaces, the
231original copyright holder who places the Program under this License
232may add an explicit geographical distribution limitation excluding
233those countries, so that distribution is permitted only in or among
234countries not thus excluded. In such case, this License incorporates
235the limitation as if written in the body of this License.
236
237 9. The Free Software Foundation may publish revised and/or new versions
238of the General Public License from time to time. Such new versions will
239be similar in spirit to the present version, but may differ in detail to
240address new problems or concerns.
241
242Each version is given a distinguishing version number. If the Program
243specifies a version number of this License which applies to it and "any
244later version", you have the option of following the terms and conditions
245either of that version or of any later version published by the Free
246Software Foundation. If the Program does not specify a version number of
247this License, you may choose any version ever published by the Free Software
248Foundation.
249
250 10. If you wish to incorporate parts of the Program into other free
251programs whose distribution conditions are different, write to the author
252to ask for permission. For software which is copyrighted by the Free
253Software Foundation, write to the Free Software Foundation; we sometimes
254make exceptions for this. Our decision will be guided by the two goals
255of preserving the free status of all derivatives of our free software and
256of promoting the sharing and reuse of software generally.
257
258 NO WARRANTY
259
260 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268REPAIR OR CORRECTION.
269
270 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278POSSIBILITY OF SUCH DAMAGES.
279
280 END OF TERMS AND CONDITIONS
281
282 How to Apply These Terms to Your New Programs
283
284 If you develop a new program, and you want it to be of the greatest
285possible use to the public, the best way to achieve this is to make it
286free software which everyone can redistribute and change under these terms.
287
288 To do so, attach the following notices to the program. It is safest
289to attach them to the start of each source file to most effectively
290convey the exclusion of warranty; and each file should have at least
291the "copyright" line and a pointer to where the full notice is found.
292
293 <one line to give the program's name and a brief idea of what it does.>
294 Copyright (C) <year> <name of author>
295
296 This program is free software; you can redistribute it and/or modify
297 it under the terms of the GNU General Public License as published by
298 the Free Software Foundation; either version 2 of the License, or
299 (at your option) any later version.
300
301 This program is distributed in the hope that it will be useful,
302 but WITHOUT ANY WARRANTY; without even the implied warranty of
303 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 GNU General Public License for more details.
305
306 You should have received a copy of the GNU General Public License
307 along with this program; if not, write to the Free Software
308 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
309
310Also add information on how to contact you by electronic and paper mail.
311
312If the program is interactive, make it output a short notice like this
313when it starts in an interactive mode:
314
315 Gnomovision version 69, Copyright (C) year name of author
316 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 This is free software, and you are welcome to redistribute it
318 under certain conditions; type `show c' for details.
319
320The hypothetical commands `show w' and `show c' should show the appropriate
321parts of the General Public License. Of course, the commands you use may
322be called something other than `show w' and `show c'; they could even be
323mouse-clicks or menu items--whatever suits your program.
324
325You should also get your employer (if you work as a programmer) or your
326school, if any, to sign a "copyright disclaimer" for the program, if
327necessary. Here is a sample; alter the names:
328
329 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
332 <signature of Ty Coon>, 1 April 1989
333 Ty Coon, President of Vice
334
335This General Public License does not permit incorporating your program into
336proprietary programs. If your program is a subroutine library, you may
337consider it more useful to permit linking proprietary applications with the
338library. If this is what you want to do, use the GNU Library General
339Public License instead of this License.
340
341-------------------------------------------------------------------------
diff --git a/utils/themeeditor/quazip/README.ROCKBOX b/utils/themeeditor/quazip/README.ROCKBOX
new file mode 100644
index 0000000000..b95f80caee
--- /dev/null
+++ b/utils/themeeditor/quazip/README.ROCKBOX
@@ -0,0 +1,6 @@
1This folder contains the quazip project for ZIP file compression/decompression.
2These files are distributed under the GPL v2 or later.
3The source files have been last synced with the projects release at
4http://sourceforge.net/projects/quazip/ on July 20, 2010
5
6
diff --git a/utils/themeeditor/quazip/crypt.h b/utils/themeeditor/quazip/crypt.h
new file mode 100644
index 0000000000..82748c5715
--- /dev/null
+++ b/utils/themeeditor/quazip/crypt.h
@@ -0,0 +1,133 @@
1/* crypt.h -- base code for crypt/uncrypt ZIPfile
2
3
4 Version 1.01e, February 12th, 2005
5
6 Copyright (C) 1998-2005 Gilles Vollant
7
8 This code is a modified version of crypting code in Infozip distribution
9
10 The encryption/decryption parts of this source code (as opposed to the
11 non-echoing password parts) were originally written in Europe. The
12 whole source package can be freely distributed, including from the USA.
13 (Prior to January 2000, re-export from the US was a violation of US law.)
14
15 This encryption code is a direct transcription of the algorithm from
16 Roger Schlafly, described by Phil Katz in the file appnote.txt. This
17 file (appnote.txt) is distributed with the PKZIP program (even in the
18 version without encryption capabilities).
19
20 If you don't need crypting in your application, just define symbols
21 NOCRYPT and NOUNCRYPT.
22
23 This code support the "Traditional PKWARE Encryption".
24
25 The new AES encryption added on Zip format by Winzip (see the page
26 http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
27 Encryption is not supported.
28*/
29
30#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
31
32/***********************************************************************
33 * Return the next byte in the pseudo-random sequence
34 */
35static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
36{
37 (void) pcrc_32_tab; /* avoid "unused parameter" warning */
38 unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
39 * unpredictable manner on 16-bit systems; not a problem
40 * with any known compiler so far, though */
41
42 temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
43 return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
44}
45
46/***********************************************************************
47 * Update the encryption keys with the next byte of plain text
48 */
49static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
50{
51 (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
52 (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
53 (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
54 {
55 register int keyshift = (int)((*(pkeys+1)) >> 24);
56 (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
57 }
58 return c;
59}
60
61
62/***********************************************************************
63 * Initialize the encryption keys and the random header according to
64 * the given password.
65 */
66static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
67{
68 *(pkeys+0) = 305419896L;
69 *(pkeys+1) = 591751049L;
70 *(pkeys+2) = 878082192L;
71 while (*passwd != '\0') {
72 update_keys(pkeys,pcrc_32_tab,(int)*passwd);
73 passwd++;
74 }
75}
76
77#define zdecode(pkeys,pcrc_32_tab,c) \
78 (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
79
80#define zencode(pkeys,pcrc_32_tab,c,t) \
81 (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
82
83#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
84
85#define RAND_HEAD_LEN 12
86 /* "last resort" source for second part of crypt seed pattern */
87# ifndef ZCR_SEED2
88# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
89# endif
90
91static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
92 const char *passwd; /* password string */
93 unsigned char *buf; /* where to write header */
94 int bufSize;
95 unsigned long* pkeys;
96 const unsigned long* pcrc_32_tab;
97 unsigned long crcForCrypting;
98{
99 int n; /* index in random header */
100 int t; /* temporary */
101 int c; /* random byte */
102 unsigned char header[RAND_HEAD_LEN-2]; /* random header */
103 static unsigned calls = 0; /* ensure different random header each time */
104
105 if (bufSize<RAND_HEAD_LEN)
106 return 0;
107
108 /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
109 * output of rand() to get less predictability, since rand() is
110 * often poorly implemented.
111 */
112 if (++calls == 1)
113 {
114 srand((unsigned)(time(NULL) ^ ZCR_SEED2));
115 }
116 init_keys(passwd, pkeys, pcrc_32_tab);
117 for (n = 0; n < RAND_HEAD_LEN-2; n++)
118 {
119 c = (rand() >> 7) & 0xff;
120 header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
121 }
122 /* Encrypt random header (last two bytes is high word of crc) */
123 init_keys(passwd, pkeys, pcrc_32_tab);
124 for (n = 0; n < RAND_HEAD_LEN-2; n++)
125 {
126 buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
127 }
128 buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
129 buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
130 return n;
131}
132
133#endif
diff --git a/utils/themeeditor/quazip/ioapi.c b/utils/themeeditor/quazip/ioapi.c
new file mode 100644
index 0000000000..cf29a317fd
--- /dev/null
+++ b/utils/themeeditor/quazip/ioapi.c
@@ -0,0 +1,184 @@
1/* ioapi.c -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API
3
4 Version 1.01e, February 12th, 2005
5
6 Copyright (C) 1998-2005 Gilles Vollant
7*/
8
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
13#include "zlib.h"
14#include "ioapi.h"
15
16
17
18/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
19
20#ifndef SEEK_CUR
21#define SEEK_CUR 1
22#endif
23
24#ifndef SEEK_END
25#define SEEK_END 2
26#endif
27
28#ifndef SEEK_SET
29#define SEEK_SET 0
30#endif
31
32voidpf ZCALLBACK fopen_file_func OF((
33 voidpf opaque,
34 const char* filename,
35 int mode));
36
37uLong ZCALLBACK fread_file_func OF((
38 voidpf opaque,
39 voidpf stream,
40 void* buf,
41 uLong size));
42
43uLong ZCALLBACK fwrite_file_func OF((
44 voidpf opaque,
45 voidpf stream,
46 const void* buf,
47 uLong size));
48
49long ZCALLBACK ftell_file_func OF((
50 voidpf opaque,
51 voidpf stream));
52
53long ZCALLBACK fseek_file_func OF((
54 voidpf opaque,
55 voidpf stream,
56 uLong offset,
57 int origin));
58
59int ZCALLBACK fclose_file_func OF((
60 voidpf opaque,
61 voidpf stream));
62
63int ZCALLBACK ferror_file_func OF((
64 voidpf opaque,
65 voidpf stream));
66
67
68voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
69 voidpf opaque;
70 const char* filename;
71 int mode;
72{
73 (void) opaque; /* avoid "unused parameter" warning */
74 FILE* file = NULL;
75 const char* mode_fopen = NULL;
76 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
77 mode_fopen = "rb";
78 else
79 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
80 mode_fopen = "r+b";
81 else
82 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
83 mode_fopen = "wb";
84
85 if ((filename!=NULL) && (mode_fopen != NULL))
86 file = fopen(filename, mode_fopen);
87 return file;
88}
89
90
91uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
92 voidpf opaque;
93 voidpf stream;
94 void* buf;
95 uLong size;
96{
97 (void) opaque; /* avoid "unused parameter" warning */
98 uLong ret;
99 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
100 return ret;
101}
102
103
104uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
105 voidpf opaque;
106 voidpf stream;
107 const void* buf;
108 uLong size;
109{
110 (void) opaque; /* avoid "unused parameter" warning */
111 uLong ret;
112 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
113 return ret;
114}
115
116long ZCALLBACK ftell_file_func (opaque, stream)
117 voidpf opaque;
118 voidpf stream;
119{
120 (void) opaque; /* avoid "unused parameter" warning */
121 long ret;
122 ret = ftell((FILE *)stream);
123 return ret;
124}
125
126long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
127 voidpf opaque;
128 voidpf stream;
129 uLong offset;
130 int origin;
131{
132 (void) opaque; /* avoid "unused parameter" warning */
133 int fseek_origin=0;
134 long ret;
135 switch (origin)
136 {
137 case ZLIB_FILEFUNC_SEEK_CUR :
138 fseek_origin = SEEK_CUR;
139 break;
140 case ZLIB_FILEFUNC_SEEK_END :
141 fseek_origin = SEEK_END;
142 break;
143 case ZLIB_FILEFUNC_SEEK_SET :
144 fseek_origin = SEEK_SET;
145 break;
146 default: return -1;
147 }
148 ret = 0;
149 fseek((FILE *)stream, offset, fseek_origin);
150 return ret;
151}
152
153int ZCALLBACK fclose_file_func (opaque, stream)
154 voidpf opaque;
155 voidpf stream;
156{
157 (void) opaque; /* avoid "unused parameter" warning */
158 int ret;
159 ret = fclose((FILE *)stream);
160 return ret;
161}
162
163int ZCALLBACK ferror_file_func (opaque, stream)
164 voidpf opaque;
165 voidpf stream;
166{
167 (void) opaque; /* avoid "unused parameter" warning */
168 int ret;
169 ret = ferror((FILE *)stream);
170 return ret;
171}
172
173void fill_fopen_filefunc (pzlib_filefunc_def)
174 zlib_filefunc_def* pzlib_filefunc_def;
175{
176 pzlib_filefunc_def->zopen_file = fopen_file_func;
177 pzlib_filefunc_def->zread_file = fread_file_func;
178 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
179 pzlib_filefunc_def->ztell_file = ftell_file_func;
180 pzlib_filefunc_def->zseek_file = fseek_file_func;
181 pzlib_filefunc_def->zclose_file = fclose_file_func;
182 pzlib_filefunc_def->zerror_file = ferror_file_func;
183 pzlib_filefunc_def->opaque = NULL;
184}
diff --git a/utils/themeeditor/quazip/ioapi.h b/utils/themeeditor/quazip/ioapi.h
new file mode 100644
index 0000000000..7d457baab3
--- /dev/null
+++ b/utils/themeeditor/quazip/ioapi.h
@@ -0,0 +1,75 @@
1/* ioapi.h -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API
3
4 Version 1.01e, February 12th, 2005
5
6 Copyright (C) 1998-2005 Gilles Vollant
7*/
8
9#ifndef _ZLIBIOAPI_H
10#define _ZLIBIOAPI_H
11
12
13#define ZLIB_FILEFUNC_SEEK_CUR (1)
14#define ZLIB_FILEFUNC_SEEK_END (2)
15#define ZLIB_FILEFUNC_SEEK_SET (0)
16
17#define ZLIB_FILEFUNC_MODE_READ (1)
18#define ZLIB_FILEFUNC_MODE_WRITE (2)
19#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
20
21#define ZLIB_FILEFUNC_MODE_EXISTING (4)
22#define ZLIB_FILEFUNC_MODE_CREATE (8)
23
24
25#ifndef ZCALLBACK
26
27#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
28#define ZCALLBACK CALLBACK
29#else
30#define ZCALLBACK
31#endif
32#endif
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
39typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
40typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
41typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
42typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
43typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
44typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
45
46typedef struct zlib_filefunc_def_s
47{
48 open_file_func zopen_file;
49 read_file_func zread_file;
50 write_file_func zwrite_file;
51 tell_file_func ztell_file;
52 seek_file_func zseek_file;
53 close_file_func zclose_file;
54 testerror_file_func zerror_file;
55 voidpf opaque;
56} zlib_filefunc_def;
57
58
59
60void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
61
62#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
63#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
64#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
65#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
66#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
67#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
68
69
70#ifdef __cplusplus
71}
72#endif
73
74#endif
75
diff --git a/utils/themeeditor/quazip/quazip.cpp b/utils/themeeditor/quazip/quazip.cpp
new file mode 100644
index 0000000000..3f7314a433
--- /dev/null
+++ b/utils/themeeditor/quazip/quazip.cpp
@@ -0,0 +1,285 @@
1/*
2-- A kind of "standard" GPL license statement --
3QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
4Copyright (C) 2005-2007 Sergey A. Tachenov
5
6This program is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2 of the License, or (at your
9option) any later version.
10
11This program is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14Public License for more details.
15
16You should have received a copy of the GNU General Public License along
17with this program; if not, write to the Free Software Foundation, Inc.,
1859 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20-- A kind of "standard" GPL license statement ends here --
21
22See COPYING file for GPL.
23
24You are also permitted to use QuaZIP under the terms of LGPL (see
25COPYING.LGPL). You are free to choose either license, but please note
26that QuaZIP makes use of Qt, which is not licensed under LGPL. So if
27you are using Open Source edition of Qt, you therefore MUST use GPL for
28your code based on QuaZIP, since it would be also based on Qt in this
29case. If you are Qt commercial license owner, then you are free to use
30QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
31 **/
32
33#include <QFile>
34
35#include "quazip.h"
36
37QuaZip::QuaZip():
38 fileNameCodec(QTextCodec::codecForLocale()),
39 commentCodec(QTextCodec::codecForLocale()),
40 mode(mdNotOpen), hasCurrentFile_f(false), zipError(UNZ_OK)
41{
42}
43
44QuaZip::QuaZip(const QString& zipName):
45 fileNameCodec(QTextCodec::codecForLocale()),
46 commentCodec(QTextCodec::codecForLocale()),
47 zipName(zipName),
48 mode(mdNotOpen), hasCurrentFile_f(false), zipError(UNZ_OK)
49{
50}
51
52QuaZip::~QuaZip()
53{
54 if(isOpen()) close();
55}
56
57bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
58{
59 zipError=UNZ_OK;
60 if(isOpen()) {
61 qWarning("QuaZip::open(): ZIP already opened");
62 return false;
63 }
64 switch(mode) {
65 case mdUnzip:
66 unzFile_f=unzOpen2(QFile::encodeName(zipName).constData(), ioApi);
67 if(unzFile_f!=NULL) {
68 this->mode=mode;
69 return true;
70 } else {
71 zipError=UNZ_OPENERROR;
72 return false;
73 }
74 case mdCreate:
75 case mdAppend:
76 case mdAdd:
77 zipFile_f=zipOpen2(QFile::encodeName(zipName).constData(),
78 mode==mdCreate?APPEND_STATUS_CREATE:
79 mode==mdAppend?APPEND_STATUS_CREATEAFTER:
80 APPEND_STATUS_ADDINZIP,
81 NULL,
82 ioApi);
83 if(zipFile_f!=NULL) {
84 this->mode=mode;
85 return true;
86 } else {
87 zipError=UNZ_OPENERROR;
88 return false;
89 }
90 default:
91 qWarning("QuaZip::open(): unknown mode: %d", (int)mode);
92 return false;
93 break;
94 }
95}
96
97void QuaZip::close()
98{
99 zipError=UNZ_OK;
100 switch(mode) {
101 case mdNotOpen:
102 qWarning("QuaZip::close(): ZIP is not open");
103 return;
104 case mdUnzip:
105 zipError=unzClose(unzFile_f);
106 break;
107 case mdCreate:
108 case mdAppend:
109 case mdAdd:
110 zipError=zipClose(zipFile_f, commentCodec->fromUnicode(comment).constData());
111 break;
112 default:
113 qWarning("QuaZip::close(): unknown mode: %d", (int)mode);
114 return;
115 }
116 if(zipError==UNZ_OK) mode=mdNotOpen;
117}
118
119void QuaZip::setZipName(const QString& zipName)
120{
121 if(isOpen()) {
122 qWarning("QuaZip::setZipName(): ZIP is already open!");
123 return;
124 }
125 this->zipName=zipName;
126}
127
128int QuaZip::getEntriesCount()const
129{
130 QuaZip *fakeThis=(QuaZip*)this; // non-const
131 fakeThis->zipError=UNZ_OK;
132 if(mode!=mdUnzip) {
133 qWarning("QuaZip::getEntriesCount(): ZIP is not open in mdUnzip mode");
134 return -1;
135 }
136 unz_global_info globalInfo;
137 if((fakeThis->zipError=unzGetGlobalInfo(unzFile_f, &globalInfo))!=UNZ_OK)
138 return zipError;
139 return (int)globalInfo.number_entry;
140}
141
142QString QuaZip::getComment()const
143{
144 QuaZip *fakeThis=(QuaZip*)this; // non-const
145 fakeThis->zipError=UNZ_OK;
146 if(mode!=mdUnzip) {
147 qWarning("QuaZip::getComment(): ZIP is not open in mdUnzip mode");
148 return QString();
149 }
150 unz_global_info globalInfo;
151 QByteArray comment;
152 if((fakeThis->zipError=unzGetGlobalInfo(unzFile_f, &globalInfo))!=UNZ_OK)
153 return QString();
154 comment.resize(globalInfo.size_comment);
155 if((fakeThis->zipError=unzGetGlobalComment(unzFile_f, comment.data(), comment.size()))!=UNZ_OK)
156 return QString();
157 return commentCodec->toUnicode(comment);
158}
159
160bool QuaZip::setCurrentFile(const QString& fileName, CaseSensitivity cs)
161{
162 zipError=UNZ_OK;
163 if(mode!=mdUnzip) {
164 qWarning("QuaZip::setCurrentFile(): ZIP is not open in mdUnzip mode");
165 return false;
166 }
167 if(fileName.isNull()) {
168 hasCurrentFile_f=false;
169 return true;
170 }
171 // Unicode-aware reimplementation of the unzLocateFile function
172 if(unzFile_f==NULL) {
173 zipError=UNZ_PARAMERROR;
174 return false;
175 }
176 if(fileName.length()>MAX_FILE_NAME_LENGTH) {
177 zipError=UNZ_PARAMERROR;
178 return false;
179 }
180 bool sens;
181 if(cs==csDefault) {
182#ifdef Q_WS_WIN
183 sens=false;
184#else
185 sens=true;
186#endif
187 } else sens=cs==csSensitive;
188 QString lower, current;
189 if(!sens) lower=fileName.toLower();
190 hasCurrentFile_f=false;
191 for(bool more=goToFirstFile(); more; more=goToNextFile()) {
192 current=getCurrentFileName();
193 if(current.isNull()) return false;
194 if(sens) {
195 if(current==fileName) break;
196 } else {
197 if(current.toLower()==lower) break;
198 }
199 }
200 return hasCurrentFile_f;
201}
202
203bool QuaZip::goToFirstFile()
204{
205 zipError=UNZ_OK;
206 if(mode!=mdUnzip) {
207 qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode");
208 return false;
209 }
210 zipError=unzGoToFirstFile(unzFile_f);
211 hasCurrentFile_f=zipError==UNZ_OK;
212 return hasCurrentFile_f;
213}
214
215bool QuaZip::goToNextFile()
216{
217 zipError=UNZ_OK;
218 if(mode!=mdUnzip) {
219 qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode");
220 return false;
221 }
222 zipError=unzGoToNextFile(unzFile_f);
223 hasCurrentFile_f=zipError==UNZ_OK;
224 if(zipError==UNZ_END_OF_LIST_OF_FILE) zipError=UNZ_OK;
225 return hasCurrentFile_f;
226}
227
228bool QuaZip::getCurrentFileInfo(QuaZipFileInfo *info)const
229{
230 QuaZip *fakeThis=(QuaZip*)this; // non-const
231 fakeThis->zipError=UNZ_OK;
232 if(mode!=mdUnzip) {
233 qWarning("QuaZip::getCurrentFileInfo(): ZIP is not open in mdUnzip mode");
234 return false;
235 }
236 unz_file_info info_z;
237 QByteArray fileName;
238 QByteArray extra;
239 QByteArray comment;
240 if(info==NULL) return false;
241 if(!isOpen()||!hasCurrentFile()) return false;
242 if((fakeThis->zipError=unzGetCurrentFileInfo(unzFile_f, &info_z, NULL, 0, NULL, 0, NULL, 0))!=UNZ_OK)
243 return false;
244 fileName.resize(info_z.size_filename);
245 extra.resize(info_z.size_file_extra);
246 comment.resize(info_z.size_file_comment);
247 if((fakeThis->zipError=unzGetCurrentFileInfo(unzFile_f, NULL,
248 fileName.data(), fileName.size(),
249 extra.data(), extra.size(),
250 comment.data(), comment.size()))!=UNZ_OK)
251 return false;
252 info->versionCreated=info_z.version;
253 info->versionNeeded=info_z.version_needed;
254 info->flags=info_z.flag;
255 info->method=info_z.compression_method;
256 info->crc=info_z.crc;
257 info->compressedSize=info_z.compressed_size;
258 info->uncompressedSize=info_z.uncompressed_size;
259 info->diskNumberStart=info_z.disk_num_start;
260 info->internalAttr=info_z.internal_fa;
261 info->externalAttr=info_z.external_fa;
262 info->name=fileNameCodec->toUnicode(fileName);
263 info->comment=commentCodec->toUnicode(comment);
264 info->extra=extra;
265 info->dateTime=QDateTime(
266 QDate(info_z.tmu_date.tm_year, info_z.tmu_date.tm_mon+1, info_z.tmu_date.tm_mday),
267 QTime(info_z.tmu_date.tm_hour, info_z.tmu_date.tm_min, info_z.tmu_date.tm_sec));
268 return true;
269}
270
271QString QuaZip::getCurrentFileName()const
272{
273 QuaZip *fakeThis=(QuaZip*)this; // non-const
274 fakeThis->zipError=UNZ_OK;
275 if(mode!=mdUnzip) {
276 qWarning("QuaZip::getCurrentFileName(): ZIP is not open in mdUnzip mode");
277 return QString();
278 }
279 if(!isOpen()||!hasCurrentFile()) return QString();
280 QByteArray fileName(MAX_FILE_NAME_LENGTH, 0);
281 if((fakeThis->zipError=unzGetCurrentFileInfo(unzFile_f, NULL, fileName.data(), fileName.size(),
282 NULL, 0, NULL, 0))!=UNZ_OK)
283 return QString();
284 return fileNameCodec->toUnicode(fileName.constData());
285}
diff --git a/utils/themeeditor/quazip/quazip.h b/utils/themeeditor/quazip/quazip.h
new file mode 100644
index 0000000000..ced1ea0f1a
--- /dev/null
+++ b/utils/themeeditor/quazip/quazip.h
@@ -0,0 +1,346 @@
1#ifndef QUA_ZIP_H
2#define QUA_ZIP_H
3
4/*
5-- A kind of "standard" GPL license statement --
6QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
7Copyright (C) 2005-2007 Sergey A. Tachenov
8
9This program is free software; you can redistribute it and/or modify it
10under the terms of the GNU General Public License as published by the
11Free Software Foundation; either version 2 of the License, or (at your
12option) any later version.
13
14This program is distributed in the hope that it will be useful, but
15WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17Public License for more details.
18
19You should have received a copy of the GNU General Public License along
20with this program; if not, write to the Free Software Foundation, Inc.,
2159 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23-- A kind of "standard" GPL license statement ends here --
24
25See COPYING file for GPL.
26
27You are also permitted to use QuaZIP under the terms of LGPL (see
28COPYING.LGPL). You are free to choose either license, but please note
29that QuaZIP makes use of Qt, which is not licensed under LGPL. So if
30you are using Open Source edition of Qt, you therefore MUST use GPL for
31your code based on QuaZIP, since it would be also based on Qt in this
32case. If you are Qt commercial license owner, then you are free to use
33QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
34 **/
35
36#include <QString>
37#include <QTextCodec>
38
39#include "zip.h"
40#include "unzip.h"
41
42#include "quazipfileinfo.h"
43
44// just in case it will be defined in the later versions of the ZIP/UNZIP
45#ifndef UNZ_OPENERROR
46// define additional error code
47#define UNZ_OPENERROR -1000
48#endif
49
50/// ZIP archive.
51/** \class QuaZip quazip.h <quazip/quazip.h>
52 * This class implements basic interface to the ZIP archive. It can be
53 * used to read table contents of the ZIP archive and retreiving
54 * information about the files inside it.
55 *
56 * You can also use this class to open files inside archive by passing
57 * pointer to the instance of this class to the constructor of the
58 * QuaZipFile class. But see QuaZipFile::QuaZipFile(QuaZip*, QObject*)
59 * for the possible pitfalls.
60 *
61 * This class is indended to provide interface to the ZIP subpackage of
62 * the ZIP/UNZIP package as well as to the UNZIP subpackage. But
63 * currently it supports only UNZIP.
64 *
65 * The use of this class is simple - just create instance using
66 * constructor, then set ZIP archive file name using setFile() function
67 * (if you did not passed the name to the constructor), then open() and
68 * then use different functions to work with it! Well, if you are
69 * paranoid, you may also wish to call close before destructing the
70 * instance, to check for errors on close.
71 *
72 * You may also use getUnzFile() and getZipFile() functions to get the
73 * ZIP archive handle and use it with ZIP/UNZIP package API directly.
74 *
75 * This class supports localized file names inside ZIP archive, but you
76 * have to set up proper codec with setCodec() function. By default,
77 * locale codec will be used, which is probably ok for UNIX systems, but
78 * will almost certainly fail with ZIP archives created in Windows. This
79 * is because Windows ZIP programs have strange habit of using DOS
80 * encoding for file names in ZIP archives. For example, ZIP archive
81 * with cyrillic names created in Windows will have file names in \c
82 * IBM866 encoding instead of \c WINDOWS-1251. I think that calling one
83 * function is not much trouble, but for true platform independency it
84 * would be nice to have some mechanism for file name encoding auto
85 * detection using locale information. Does anyone know a good way to do
86 * it?
87 **/
88class QuaZip {
89 public:
90 /// Useful constants.
91 enum Constants {
92 MAX_FILE_NAME_LENGTH=256 /**< Maximum file name length. Taken from
93 \c UNZ_MAXFILENAMEINZIP constant in
94 unzip.c. */
95 };
96 /// Open mode of the ZIP file.
97 enum Mode {
98 mdNotOpen, ///< ZIP file is not open. This is the initial mode.
99 mdUnzip, ///< ZIP file is open for reading files inside it.
100 mdCreate, ///< ZIP file was created with open() call.
101 mdAppend, /**< ZIP file was opened in append mode. This refers to
102 * \c APPEND_STATUS_CREATEAFTER mode in ZIP/UNZIP package
103 * and means that zip is appended to some existing file
104 * what is useful when that file contains
105 * self-extractor code. This is obviously \em not what
106 * you whant to use to add files to the existing ZIP
107 * archive.
108 **/
109 mdAdd ///< ZIP file was opened for adding files in the archive.
110 };
111 /// Case sensitivity for the file names.
112 /** This is what you specify when accessing files in the archive.
113 * Works perfectly fine with any characters thanks to Qt's great
114 * unicode support. This is different from ZIP/UNZIP API, where
115 * only US-ASCII characters was supported.
116 **/
117 enum CaseSensitivity {
118 csDefault=0, ///< Default for platform. Case sensitive for UNIX, not for Windows.
119 csSensitive=1, ///< Case sensitive.
120 csInsensitive=2 ///< Case insensitive.
121 };
122 private:
123 QTextCodec *fileNameCodec, *commentCodec;
124 QString zipName;
125 QString comment;
126 Mode mode;
127 union {
128 unzFile unzFile_f;
129 zipFile zipFile_f;
130 };
131 bool hasCurrentFile_f;
132 int zipError;
133 // not (and will not be) implemented
134 QuaZip(const QuaZip& that);
135 // not (and will not be) implemented
136 QuaZip& operator=(const QuaZip& that);
137 public:
138 /// Constructs QuaZip object.
139 /** Call setName() before opening constructed object. */
140 QuaZip();
141 /// Constructs QuaZip object associated with ZIP file \a zipName.
142 QuaZip(const QString& zipName);
143 /// Destroys QuaZip object.
144 /** Calls close() if necessary. */
145 ~QuaZip();
146 /// Opens ZIP file.
147 /** Argument \a ioApi specifies IO function set for ZIP/UNZIP
148 * package to use. See unzip.h, zip.h and ioapi.h for details. By
149 * passing NULL (the default) you just tell package to use the
150 * default API which works just fine on UNIX platforms. I have tried
151 * it on win32-g++ platform too and it seems it works fine there
152 * too, so I see no reason to use win32 IO API included in original
153 * ZIP/UNZIP package.
154 *
155 * ZIP archive file name will be converted to 8-bit encoding using
156 * Qt's QFile::encodeName() function before passing it to the
157 * ZIP/UNZIP package API.
158 *
159 * Returns \c true if successful, \c false otherwise.
160 *
161 * Argument \a mode specifies open mode of the ZIP archive. See Mode
162 * for details. Note that there is zipOpen2() function in the
163 * ZIP/UNZIP API which accepts \a globalcomment argument, but it
164 * does not use it anywhere, so this open() function does not have this
165 * argument. See setComment() if you need to set global comment.
166 *
167 * \note ZIP/UNZIP API open calls do not return error code - they
168 * just return \c NULL indicating an error. But to make things
169 * easier, quazip.h header defines additional error code \c
170 * UNZ_ERROROPEN and getZipError() will return it if the open call
171 * of the ZIP/UNZIP API returns \c NULL.
172 **/
173 bool open(Mode mode, zlib_filefunc_def *ioApi =NULL);
174 /// Closes ZIP file.
175 /** Call getZipError() to determine if the close was successful. */
176 void close();
177 /// Sets the codec used to encode/decode file names inside archive.
178 /** This is necessary to access files in the ZIP archive created
179 * under Windows with non-latin characters in file names. For
180 * example, file names with cyrillic letters will be in \c IBM866
181 * encoding.
182 **/
183 void setFileNameCodec(QTextCodec *fileNameCodec)
184 {this->fileNameCodec=fileNameCodec;}
185 /// Sets the codec used to encode/decode file names inside archive.
186 /** \overload
187 * Equivalent to calling setFileNameCodec(QTextCodec::codecForName(codecName));
188 **/
189 void setFileNameCodec(const char *fileNameCodecName)
190 {fileNameCodec=QTextCodec::codecForName(fileNameCodecName);}
191 /// Returns the codec used to encode/decode comments inside archive.
192 QTextCodec* getFileNameCodec()const {return fileNameCodec;}
193 /// Sets the codec used to encode/decode comments inside archive.
194 /** This codec defaults to locale codec, which is probably ok.
195 **/
196 void setCommentCodec(QTextCodec *commentCodec)
197 {this->commentCodec=commentCodec;}
198 /// Sets the codec used to encode/decode comments inside archive.
199 /** \overload
200 * Equivalent to calling setCommentCodec(QTextCodec::codecForName(codecName));
201 **/
202 void setCommentCodec(const char *commentCodecName)
203 {commentCodec=QTextCodec::codecForName(commentCodecName);}
204 /// Returns the codec used to encode/decode comments inside archive.
205 QTextCodec* getCommentCodec()const {return commentCodec;}
206 /// Returns the name of the ZIP file.
207 /** Returns null string if no ZIP file name has been set.
208 * \sa setZipName()
209 **/
210 QString getZipName()const {return zipName;}
211 /// Sets the name of the ZIP file.
212 /** Does nothing if the ZIP file is open.
213 *
214 * Does not reset error code returned by getZipError().
215 **/
216 void setZipName(const QString& zipName);
217 /// Returns the mode in which ZIP file was opened.
218 Mode getMode()const {return mode;}
219 /// Returns \c true if ZIP file is open, \c false otherwise.
220 bool isOpen()const {return mode!=mdNotOpen;}
221 /// Returns the error code of the last operation.
222 /** Returns \c UNZ_OK if the last operation was successful.
223 *
224 * Error code resets to \c UNZ_OK every time you call any function
225 * that accesses something inside ZIP archive, even if it is \c
226 * const (like getEntriesCount()). open() and close() calls reset
227 * error code too. See documentation for the specific functions for
228 * details on error detection.
229 **/
230 int getZipError()const {return zipError;}
231 /// Returns number of the entries in the ZIP central directory.
232 /** Returns negative error code in the case of error. The same error
233 * code will be returned by subsequent getZipError() call.
234 **/
235 int getEntriesCount()const;
236 /// Returns global comment in the ZIP file.
237 QString getComment()const;
238 /// Sets global comment in the ZIP file.
239 /** Comment will be written to the archive on close operation.
240 *
241 * \sa open()
242 **/
243 void setComment(const QString& comment) {this->comment=comment;}
244 /// Sets the current file to the first file in the archive.
245 /** Returns \c true on success, \c false otherwise. Call
246 * getZipError() to get the error code.
247 **/
248 bool goToFirstFile();
249 /// Sets the current file to the next file in the archive.
250 /** Returns \c true on success, \c false otherwise. Call
251 * getZipError() to determine if there was an error.
252 *
253 * Should be used only in QuaZip::mdUnzip mode.
254 *
255 * \note If the end of file was reached, getZipError() will return
256 * \c UNZ_OK instead of \c UNZ_END_OF_LIST_OF_FILE. This is to make
257 * things like this easier:
258 * \code
259 * for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
260 * // do something
261 * }
262 * if(zip.getZipError()==UNZ_OK) {
263 * // ok, there was no error
264 * }
265 * \endcode
266 **/
267 bool goToNextFile();
268 /// Sets current file by its name.
269 /** Returns \c true if successful, \c false otherwise. Argument \a
270 * cs specifies case sensitivity of the file name. Call
271 * getZipError() in the case of a failure to get error code.
272 *
273 * This is not a wrapper to unzLocateFile() function. That is
274 * because I had to implement locale-specific case-insensitive
275 * comparison.
276 *
277 * Here are the differences from the original implementation:
278 *
279 * - If the file was not found, error code is \c UNZ_OK, not \c
280 * UNZ_END_OF_LIST_OF_FILE (see also goToNextFile()).
281 * - If this function fails, it unsets the current file rather than
282 * resetting it back to what it was before the call.
283 *
284 * If \a fileName is null string then this function unsets the
285 * current file and return \c true. Note that you should close the
286 * file first if it is open! See
287 * QuaZipFile::QuaZipFile(QuaZip*,QObject*) for the details.
288 *
289 * Should be used only in QuaZip::mdUnzip mode.
290 *
291 * \sa setFileNameCodec(), CaseSensitivity
292 **/
293 bool setCurrentFile(const QString& fileName, CaseSensitivity cs =csDefault);
294 /// Returns \c true if the current file has been set.
295 bool hasCurrentFile()const {return hasCurrentFile_f;}
296 /// Retrieves information about the current file.
297 /** Fills the structure pointed by \a info. Returns \c true on
298 * success, \c false otherwise. In the latter case structure pointed
299 * by \a info remains untouched. If there was an error,
300 * getZipError() returns error code.
301 *
302 * Should be used only in QuaZip::mdUnzip mode.
303 *
304 * Does nothing and returns \c false in any of the following cases.
305 * - ZIP is not open;
306 * - ZIP does not have current file;
307 * - \a info is \c NULL;
308 *
309 * In all these cases getZipError() returns \c UNZ_OK since there
310 * is no ZIP/UNZIP API call.
311 **/
312 bool getCurrentFileInfo(QuaZipFileInfo* info)const;
313 /// Returns the current file name.
314 /** Equivalent to calling getCurrentFileInfo() and then getting \c
315 * name field of the QuaZipFileInfo structure, but faster and more
316 * convenient.
317 *
318 * Should be used only in QuaZip::mdUnzip mode.
319 **/
320 QString getCurrentFileName()const;
321 /// Returns \c unzFile handle.
322 /** You can use this handle to directly call UNZIP part of the
323 * ZIP/UNZIP package functions (see unzip.h).
324 *
325 * \warning When using the handle returned by this function, please
326 * keep in mind that QuaZip class is unable to detect any changes
327 * you make in the ZIP file state (e. g. changing current file, or
328 * closing the handle). So please do not do anything with this
329 * handle that is possible to do with the functions of this class.
330 * Or at least return the handle in the original state before
331 * calling some another function of this class (including implicit
332 * destructor calls and calls from the QuaZipFile objects that refer
333 * to this QuaZip instance!). So if you have changed the current
334 * file in the ZIP archive - then change it back or you may
335 * experience some strange behavior or even crashes.
336 **/
337 unzFile getUnzFile() {return unzFile_f;}
338 /// Returns \c zipFile handle.
339 /** You can use this handle to directly call ZIP part of the
340 * ZIP/UNZIP package functions (see zip.h). Warnings about the
341 * getUnzFile() function also apply to this function.
342 **/
343 zipFile getZipFile() {return zipFile_f;}
344};
345
346#endif
diff --git a/utils/themeeditor/quazip/quazipfile.cpp b/utils/themeeditor/quazip/quazipfile.cpp
new file mode 100644
index 0000000000..0399d1dbd0
--- /dev/null
+++ b/utils/themeeditor/quazip/quazipfile.cpp
@@ -0,0 +1,377 @@
1/*
2-- A kind of "standard" GPL license statement --
3QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
4Copyright (C) 2005-2007 Sergey A. Tachenov
5
6This program is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2 of the License, or (at your
9option) any later version.
10
11This program is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14Public License for more details.
15
16You should have received a copy of the GNU General Public License along
17with this program; if not, write to the Free Software Foundation, Inc.,
1859 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20-- A kind of "standard" GPL license statement ends here --
21
22See COPYING file for GPL.
23
24You are also permitted to use QuaZIP under the terms of LGPL (see
25COPYING.LGPL). You are free to choose either license, but please note
26that QuaZIP makes use of Qt, which is not licensed under LGPL. So if
27you are using Open Source edition of Qt, you therefore MUST use GPL for
28your code based on QuaZIP, since it would be also based on Qt in this
29case. If you are Qt commercial license owner, then you are free to use
30QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
31 **/
32
33#include "quazipfile.h"
34
35using namespace std;
36
37QuaZipFile::QuaZipFile():
38 zip(NULL), internal(true), zipError(UNZ_OK)
39{
40}
41
42QuaZipFile::QuaZipFile(QObject *parent):
43 QIODevice(parent), zip(NULL), internal(true), zipError(UNZ_OK)
44{
45}
46
47QuaZipFile::QuaZipFile(const QString& zipName, QObject *parent):
48 QIODevice(parent), internal(true), zipError(UNZ_OK)
49{
50 zip=new QuaZip(zipName);
51 Q_CHECK_PTR(zip);
52}
53
54QuaZipFile::QuaZipFile(const QString& zipName, const QString& fileName,
55 QuaZip::CaseSensitivity cs, QObject *parent):
56 QIODevice(parent), internal(true), zipError(UNZ_OK)
57{
58 zip=new QuaZip(zipName);
59 Q_CHECK_PTR(zip);
60 this->fileName=fileName;
61 this->caseSensitivity=cs;
62}
63
64QuaZipFile::QuaZipFile(QuaZip *zip, QObject *parent):
65 QIODevice(parent),
66 zip(zip), internal(false),
67 zipError(UNZ_OK)
68{
69}
70
71QuaZipFile::~QuaZipFile()
72{
73 if(isOpen()) close();
74 if(internal) delete zip;
75}
76
77QString QuaZipFile::getZipName()const
78{
79 return zip==NULL?QString():zip->getZipName();
80}
81
82QString QuaZipFile::getActualFileName()const
83{
84 setZipError(UNZ_OK);
85 if(zip==NULL||(openMode()&WriteOnly)) return QString();
86 QString name=zip->getCurrentFileName();
87 if(name.isNull())
88 setZipError(zip->getZipError());
89 return name;
90}
91
92void QuaZipFile::setZipName(const QString& zipName)
93{
94 if(isOpen()) {
95 qWarning("QuaZipFile::setZipName(): file is already open - can not set ZIP name");
96 return;
97 }
98 if(zip!=NULL&&internal) delete zip;
99 zip=new QuaZip(zipName);
100 Q_CHECK_PTR(zip);
101 internal=true;
102}
103
104void QuaZipFile::setZip(QuaZip *zip)
105{
106 if(isOpen()) {
107 qWarning("QuaZipFile::setZip(): file is already open - can not set ZIP");
108 return;
109 }
110 if(this->zip!=NULL&&internal) delete this->zip;
111 this->zip=zip;
112 this->fileName=QString();
113 internal=false;
114}
115
116void QuaZipFile::setFileName(const QString& fileName, QuaZip::CaseSensitivity cs)
117{
118 if(zip==NULL) {
119 qWarning("QuaZipFile::setFileName(): call setZipName() first");
120 return;
121 }
122 if(!internal) {
123 qWarning("QuaZipFile::setFileName(): should not be used when not using internal QuaZip");
124 return;
125 }
126 if(isOpen()) {
127 qWarning("QuaZipFile::setFileName(): can not set file name for already opened file");
128 return;
129 }
130 this->fileName=fileName;
131 this->caseSensitivity=cs;
132}
133
134void QuaZipFile::setZipError(int zipError)const
135{
136 QuaZipFile *fakeThis=(QuaZipFile*)this; // non-const
137 fakeThis->zipError=zipError;
138 if(zipError==UNZ_OK)
139 fakeThis->setErrorString(QString());
140 else
141 fakeThis->setErrorString(tr("ZIP/UNZIP API error %1").arg(zipError));
142}
143
144bool QuaZipFile::open(OpenMode mode)
145{
146 return open(mode, NULL);
147}
148
149bool QuaZipFile::open(OpenMode mode, int *method, int *level, bool raw, const char *password)
150{
151 resetZipError();
152 if(isOpen()) {
153 qWarning("QuaZipFile::open(): already opened");
154 return false;
155 }
156 if(mode&Unbuffered) {
157 qWarning("QuaZipFile::open(): Unbuffered mode is not supported");
158 return false;
159 }
160 if((mode&ReadOnly)&&!(mode&WriteOnly)) {
161 if(internal) {
162 if(!zip->open(QuaZip::mdUnzip)) {
163 setZipError(zip->getZipError());
164 return false;
165 }
166 if(!zip->setCurrentFile(fileName, caseSensitivity)) {
167 setZipError(zip->getZipError());
168 zip->close();
169 return false;
170 }
171 } else {
172 if(zip==NULL) {
173 qWarning("QuaZipFile::open(): zip is NULL");
174 return false;
175 }
176 if(zip->getMode()!=QuaZip::mdUnzip) {
177 qWarning("QuaZipFile::open(): file open mode %d incompatible with ZIP open mode %d",
178 (int)mode, (int)zip->getMode());
179 return false;
180 }
181 if(!zip->hasCurrentFile()) {
182 qWarning("QuaZipFile::open(): zip does not have current file");
183 return false;
184 }
185 }
186 setZipError(unzOpenCurrentFile3(zip->getUnzFile(), method, level, (int)raw, password));
187 if(zipError==UNZ_OK) {
188 setOpenMode(mode);
189 this->raw=raw;
190 return true;
191 } else
192 return false;
193 }
194 qWarning("QuaZipFile::open(): open mode %d not supported by this function", (int)mode);
195 return false;
196}
197
198bool QuaZipFile::open(OpenMode mode, const QuaZipNewInfo& info,
199 const char *password, quint32 crc,
200 int method, int level, bool raw,
201 int windowBits, int memLevel, int strategy)
202{
203 zip_fileinfo info_z;
204 resetZipError();
205 if(isOpen()) {
206 qWarning("QuaZipFile::open(): already opened");
207 return false;
208 }
209 if((mode&WriteOnly)&&!(mode&ReadOnly)) {
210 if(internal) {
211 qWarning("QuaZipFile::open(): write mode is incompatible with internal QuaZip approach");
212 return false;
213 }
214 if(zip==NULL) {
215 qWarning("QuaZipFile::open(): zip is NULL");
216 return false;
217 }
218 if(zip->getMode()!=QuaZip::mdCreate&&zip->getMode()!=QuaZip::mdAppend&&zip->getMode()!=QuaZip::mdAdd) {
219 qWarning("QuaZipFile::open(): file open mode %d incompatible with ZIP open mode %d",
220 (int)mode, (int)zip->getMode());
221 return false;
222 }
223 info_z.tmz_date.tm_year=info.dateTime.date().year();
224 info_z.tmz_date.tm_mon=info.dateTime.date().month() - 1;
225 info_z.tmz_date.tm_mday=info.dateTime.date().day();
226 info_z.tmz_date.tm_hour=info.dateTime.time().hour();
227 info_z.tmz_date.tm_min=info.dateTime.time().minute();
228 info_z.tmz_date.tm_sec=info.dateTime.time().second();
229 info_z.dosDate = 0;
230 info_z.internal_fa=(uLong)info.internalAttr;
231 info_z.external_fa=(uLong)info.externalAttr;
232 setZipError(zipOpenNewFileInZip3(zip->getZipFile(),
233 zip->getFileNameCodec()->fromUnicode(info.name).constData(), &info_z,
234 info.extraLocal.constData(), info.extraLocal.length(),
235 info.extraGlobal.constData(), info.extraGlobal.length(),
236 zip->getCommentCodec()->fromUnicode(info.comment).constData(),
237 method, level, (int)raw,
238 windowBits, memLevel, strategy,
239 password, (uLong)crc));
240 if(zipError==UNZ_OK) {
241 writePos=0;
242 setOpenMode(mode);
243 this->raw=raw;
244 if(raw) {
245 this->crc=crc;
246 this->uncompressedSize=info.uncompressedSize;
247 }
248 return true;
249 } else
250 return false;
251 }
252 qWarning("QuaZipFile::open(): open mode %d not supported by this function", (int)mode);
253 return false;
254}
255
256bool QuaZipFile::isSequential()const
257{
258 return true;
259}
260
261qint64 QuaZipFile::pos()const
262{
263 if(zip==NULL) {
264 qWarning("QuaZipFile::pos(): call setZipName() or setZip() first");
265 return -1;
266 }
267 if(!isOpen()) {
268 qWarning("QuaZipFile::pos(): file is not open");
269 return -1;
270 }
271 if(openMode()&ReadOnly)
272 return unztell(zip->getUnzFile());
273 else
274 return writePos;
275}
276
277bool QuaZipFile::atEnd()const
278{
279 if(zip==NULL) {
280 qWarning("QuaZipFile::atEnd(): call setZipName() or setZip() first");
281 return false;
282 }
283 if(!isOpen()) {
284 qWarning("QuaZipFile::atEnd(): file is not open");
285 return false;
286 }
287 if(openMode()&ReadOnly)
288 return unzeof(zip->getUnzFile())==1;
289 else
290 return true;
291}
292
293qint64 QuaZipFile::size()const
294{
295 if(!isOpen()) {
296 qWarning("QuaZipFile::atEnd(): file is not open");
297 return -1;
298 }
299 if(openMode()&ReadOnly)
300 return raw?csize():usize();
301 else
302 return writePos;
303}
304
305qint64 QuaZipFile::csize()const
306{
307 unz_file_info info_z;
308 setZipError(UNZ_OK);
309 if(zip==NULL||zip->getMode()!=QuaZip::mdUnzip) return -1;
310 setZipError(unzGetCurrentFileInfo(zip->getUnzFile(), &info_z, NULL, 0, NULL, 0, NULL, 0));
311 if(zipError!=UNZ_OK)
312 return -1;
313 return info_z.compressed_size;
314}
315
316qint64 QuaZipFile::usize()const
317{
318 unz_file_info info_z;
319 setZipError(UNZ_OK);
320 if(zip==NULL||zip->getMode()!=QuaZip::mdUnzip) return -1;
321 setZipError(unzGetCurrentFileInfo(zip->getUnzFile(), &info_z, NULL, 0, NULL, 0, NULL, 0));
322 if(zipError!=UNZ_OK)
323 return -1;
324 return info_z.uncompressed_size;
325}
326
327bool QuaZipFile::getFileInfo(QuaZipFileInfo *info)
328{
329 if(zip==NULL||zip->getMode()!=QuaZip::mdUnzip) return false;
330 zip->getCurrentFileInfo(info);
331 setZipError(zip->getZipError());
332 return zipError==UNZ_OK;
333}
334
335void QuaZipFile::close()
336{
337 resetZipError();
338 if(zip==NULL||!zip->isOpen()) return;
339 if(!isOpen()) {
340 qWarning("QuaZipFile::close(): file isn't open");
341 return;
342 }
343 if(openMode()&ReadOnly)
344 setZipError(unzCloseCurrentFile(zip->getUnzFile()));
345 else if(openMode()&WriteOnly)
346 if(isRaw()) setZipError(zipCloseFileInZipRaw(zip->getZipFile(), uncompressedSize, crc));
347 else setZipError(zipCloseFileInZip(zip->getZipFile()));
348 else {
349 qWarning("Wrong open mode: %d", (int)openMode());
350 return;
351 }
352 if(zipError==UNZ_OK) setOpenMode(QIODevice::NotOpen);
353 else return;
354 if(internal) {
355 zip->close();
356 setZipError(zip->getZipError());
357 }
358}
359
360qint64 QuaZipFile::readData(char *data, qint64 maxSize)
361{
362 setZipError(UNZ_OK);
363 qint64 bytesRead=unzReadCurrentFile(zip->getUnzFile(), data, (unsigned)maxSize);
364 if(bytesRead<0) setZipError((int)bytesRead);
365 return bytesRead;
366}
367
368qint64 QuaZipFile::writeData(const char* data, qint64 maxSize)
369{
370 setZipError(ZIP_OK);
371 setZipError(zipWriteInFileInZip(zip->getZipFile(), data, (uint)maxSize));
372 if(zipError!=ZIP_OK) return -1;
373 else {
374 writePos+=maxSize;
375 return maxSize;
376 }
377}
diff --git a/utils/themeeditor/quazip/quazipfile.h b/utils/themeeditor/quazip/quazipfile.h
new file mode 100644
index 0000000000..09af5bceca
--- /dev/null
+++ b/utils/themeeditor/quazip/quazipfile.h
@@ -0,0 +1,442 @@
1#ifndef QUA_ZIPFILE_H
2#define QUA_ZIPFILE_H
3
4/*
5-- A kind of "standard" GPL license statement --
6QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
7Copyright (C) 2005-2008 Sergey A. Tachenov
8
9This program is free software; you can redistribute it and/or modify it
10under the terms of the GNU General Public License as published by the
11Free Software Foundation; either version 2 of the License, or (at your
12option) any later version.
13
14This program is distributed in the hope that it will be useful, but
15WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17Public License for more details.
18
19You should have received a copy of the GNU General Public License along
20with this program; if not, write to the Free Software Foundation, Inc.,
2159 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23-- A kind of "standard" GPL license statement ends here --
24
25See COPYING file for GPL.
26
27You are also permitted to use QuaZIP under the terms of LGPL (see
28COPYING.LGPL). You are free to choose either license, but please note
29that QuaZIP makes use of Qt, which is not licensed under LGPL. So if
30you are using Open Source edition of Qt, you therefore MUST use GPL for
31your code based on QuaZIP, since it would be also based on Qt in this
32case. If you are Qt commercial license owner, then you are free to use
33QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
34 **/
35
36#include <QIODevice>
37
38#include "quazip.h"
39#include "quazipnewinfo.h"
40
41/// A file inside ZIP archive.
42/** \class QuaZipFile quazipfile.h <quazip/quazipfile.h>
43 * This is the most interesting class. Not only it provides C++
44 * interface to the ZIP/UNZIP package, but also integrates it with Qt by
45 * subclassing QIODevice. This makes possible to access files inside ZIP
46 * archive using QTextStream or QDataStream, for example. Actually, this
47 * is the main purpose of the whole QuaZIP library.
48 *
49 * You can either use existing QuaZip instance to create instance of
50 * this class or pass ZIP archive file name to this class, in which case
51 * it will create internal QuaZip object. See constructors' descriptions
52 * for details. Writing is only possible with the existing instance.
53 *
54 * \section quazipfile-sequential Sequential or random-access?
55 *
56 * At the first thought, QuaZipFile has fixed size, the start and the
57 * end and should be therefore considered random-access device. But
58 * there is one major obstacle to making it random-access: ZIP/UNZIP API
59 * does not support seek() operation and the only way to implement it is
60 * through reopening the file and re-reading to the required position,
61 * but this is prohibitely slow.
62 *
63 * Therefore, QuaZipFile is considered to be a sequential device. This
64 * has advantage of availability of the ungetChar() operation (QIODevice
65 * does not implement it properly for non-sequential devices unless they
66 * support seek()). Disadvantage is a somewhat strange behaviour of the
67 * size() and pos() functions. This should be kept in mind while using
68 * this class.
69 *
70 **/
71class QuaZipFile: public QIODevice {
72 Q_OBJECT
73 private:
74 QuaZip *zip;
75 QString fileName;
76 QuaZip::CaseSensitivity caseSensitivity;
77 bool raw;
78 qint64 writePos;
79 // these two are for writing raw files
80 ulong uncompressedSize;
81 quint32 crc;
82 bool internal;
83 int zipError;
84 // these are not supported nor implemented
85 QuaZipFile(const QuaZipFile& that);
86 QuaZipFile& operator=(const QuaZipFile& that);
87 void resetZipError()const {setZipError(UNZ_OK);}
88 // const, but sets zipError!
89 void setZipError(int zipError)const;
90 protected:
91 /// Implementation of the QIODevice::readData().
92 qint64 readData(char *data, qint64 maxSize);
93 /// Implementation of the QIODevice::writeData().
94 qint64 writeData(const char *data, qint64 maxSize);
95 public:
96 /// Constructs a QuaZipFile instance.
97 /** You should use setZipName() and setFileName() or setZip() before
98 * trying to call open() on the constructed object.
99 **/
100 QuaZipFile();
101 /// Constructs a QuaZipFile instance.
102 /** \a parent argument specifies this object's parent object.
103 *
104 * You should use setZipName() and setFileName() or setZip() before
105 * trying to call open() on the constructed object.
106 **/
107 QuaZipFile(QObject *parent);
108 /// Constructs a QuaZipFile instance.
109 /** \a parent argument specifies this object's parent object and \a
110 * zipName specifies ZIP archive file name.
111 *
112 * You should use setFileName() before trying to call open() on the
113 * constructed object.
114 *
115 * QuaZipFile constructed by this constructor can be used for read
116 * only access. Use QuaZipFile(QuaZip*,QObject*) for writing.
117 **/
118 QuaZipFile(const QString& zipName, QObject *parent =NULL);
119 /// Constructs a QuaZipFile instance.
120 /** \a parent argument specifies this object's parent object, \a
121 * zipName specifies ZIP archive file name and \a fileName and \a cs
122 * specify a name of the file to open inside archive.
123 *
124 * QuaZipFile constructed by this constructor can be used for read
125 * only access. Use QuaZipFile(QuaZip*,QObject*) for writing.
126 *
127 * \sa QuaZip::setCurrentFile()
128 **/
129 QuaZipFile(const QString& zipName, const QString& fileName,
130 QuaZip::CaseSensitivity cs =QuaZip::csDefault, QObject *parent =NULL);
131 /// Constructs a QuaZipFile instance.
132 /** \a parent argument specifies this object's parent object.
133 *
134 * \a zip is the pointer to the existing QuaZip object. This
135 * QuaZipFile object then can be used to read current file in the
136 * \a zip or to write to the file inside it.
137 *
138 * \warning Using this constructor for reading current file can be
139 * tricky. Let's take the following example:
140 * \code
141 * QuaZip zip("archive.zip");
142 * zip.open(QuaZip::mdUnzip);
143 * zip.setCurrentFile("file-in-archive");
144 * QuaZipFile file(&zip);
145 * file.open(QIODevice::ReadOnly);
146 * // ok, now we can read from the file
147 * file.read(somewhere, some);
148 * zip.setCurrentFile("another-file-in-archive"); // oops...
149 * QuaZipFile anotherFile(&zip);
150 * anotherFile.open(QIODevice::ReadOnly);
151 * anotherFile.read(somewhere, some); // this is still ok...
152 * file.read(somewhere, some); // and this is NOT
153 * \endcode
154 * So, what exactly happens here? When we change current file in the
155 * \c zip archive, \c file that references it becomes invalid
156 * (actually, as far as I understand ZIP/UNZIP sources, it becomes
157 * closed, but QuaZipFile has no means to detect it).
158 *
159 * Summary: do not close \c zip object or change its current file as
160 * long as QuaZipFile is open. Even better - use another constructors
161 * which create internal QuaZip instances, one per object, and
162 * therefore do not cause unnecessary trouble. This constructor may
163 * be useful, though, if you already have a QuaZip instance and do
164 * not want to access several files at once. Good example:
165 * \code
166 * QuaZip zip("archive.zip");
167 * zip.open(QuaZip::mdUnzip);
168 * // first, we need some information about archive itself
169 * QByteArray comment=zip.getComment();
170 * // and now we are going to access files inside it
171 * QuaZipFile file(&zip);
172 * for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
173 * file.open(QIODevice::ReadOnly);
174 * // do something cool with file here
175 * file.close(); // do not forget to close!
176 * }
177 * zip.close();
178 * \endcode
179 **/
180 QuaZipFile(QuaZip *zip, QObject *parent =NULL);
181 /// Destroys a QuaZipFile instance.
182 /** Closes file if open, destructs internal QuaZip object (if it
183 * exists and \em is internal, of course).
184 **/
185 virtual ~QuaZipFile();
186 /// Returns the ZIP archive file name.
187 /** If this object was created by passing QuaZip pointer to the
188 * constructor, this function will return that QuaZip's file name
189 * (or null string if that object does not have file name yet).
190 *
191 * Otherwise, returns associated ZIP archive file name or null
192 * string if there are no name set yet.
193 *
194 * \sa setZipName() getFileName()
195 **/
196 QString getZipName()const;
197 /// Returns a pointer to the associated QuaZip object.
198 /** Returns \c NULL if there is no associated QuaZip or it is
199 * internal (so you will not mess with it).
200 **/
201 QuaZip* getZip()const;
202 /// Returns file name.
203 /** This function returns file name you passed to this object either
204 * by using
205 * QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*)
206 * or by calling setFileName(). Real name of the file may differ in
207 * case if you used case-insensitivity.
208 *
209 * Returns null string if there is no file name set yet. This is the
210 * case when this QuaZipFile operates on the existing QuaZip object
211 * (constructor QuaZipFile(QuaZip*,QObject*) or setZip() was used).
212 *
213 * \sa getActualFileName
214 **/
215 QString getFileName()const {return fileName;}
216 /// Returns case sensitivity of the file name.
217 /** This function returns case sensitivity argument you passed to
218 * this object either by using
219 * QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*)
220 * or by calling setFileName().
221 *
222 * Returns unpredictable value if getFileName() returns null string
223 * (this is the case when you did not used setFileName() or
224 * constructor above).
225 *
226 * \sa getFileName
227 **/
228 QuaZip::CaseSensitivity getCaseSensitivity()const {return caseSensitivity;}
229 /// Returns the actual file name in the archive.
230 /** This is \em not a ZIP archive file name, but a name of file inside
231 * archive. It is not necessary the same name that you have passed
232 * to the
233 * QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*),
234 * setFileName() or QuaZip::setCurrentFile() - this is the real file
235 * name inside archive, so it may differ in case if the file name
236 * search was case-insensitive.
237 *
238 * Equivalent to calling getCurrentFileName() on the associated
239 * QuaZip object. Returns null string if there is no associated
240 * QuaZip object or if it does not have a current file yet. And this
241 * is the case if you called setFileName() but did not open the
242 * file yet. So this is perfectly fine:
243 * \code
244 * QuaZipFile file("somezip.zip");
245 * file.setFileName("somefile");
246 * QString name=file.getName(); // name=="somefile"
247 * QString actual=file.getActualFileName(); // actual is null string
248 * file.open(QIODevice::ReadOnly);
249 * QString actual=file.getActualFileName(); // actual can be "SoMeFiLe" on Windows
250 * \endcode
251 *
252 * \sa getZipName(), getFileName(), QuaZip::CaseSensitivity
253 **/
254 QString getActualFileName()const;
255 /// Sets the ZIP archive file name.
256 /** Automatically creates internal QuaZip object and destroys
257 * previously created internal QuaZip object, if any.
258 *
259 * Will do nothing if this file is already open. You must close() it
260 * first.
261 **/
262 void setZipName(const QString& zipName);
263 /// Returns \c true if the file was opened in raw mode.
264 /** If the file is not open, the returned value is undefined.
265 *
266 * \sa open(OpenMode,int*,int*,bool,const char*)
267 **/
268 bool isRaw()const {return raw;}
269 /// Binds to the existing QuaZip instance.
270 /** This function destroys internal QuaZip object, if any, and makes
271 * this QuaZipFile to use current file in the \a zip object for any
272 * further operations. See QuaZipFile(QuaZip*,QObject*) for the
273 * possible pitfalls.
274 *
275 * Will do nothing if the file is currently open. You must close()
276 * it first.
277 **/
278 void setZip(QuaZip *zip);
279 /// Sets the file name.
280 /** Will do nothing if at least one of the following conditions is
281 * met:
282 * - ZIP name has not been set yet (getZipName() returns null
283 * string).
284 * - This QuaZipFile is associated with external QuaZip. In this
285 * case you should call that QuaZip's setCurrentFile() function
286 * instead!
287 * - File is already open so setting the name is meaningless.
288 *
289 * \sa QuaZip::setCurrentFile
290 **/
291 void setFileName(const QString& fileName, QuaZip::CaseSensitivity cs =QuaZip::csDefault);
292 /// Opens a file for reading.
293 /** Returns \c true on success, \c false otherwise.
294 * Call getZipError() to get error code.
295 *
296 * \note Since ZIP/UNZIP API provides buffered reading only,
297 * QuaZipFile does not support unbuffered reading. So do not pass
298 * QIODevice::Unbuffered flag in \a mode, or open will fail.
299 **/
300 virtual bool open(OpenMode mode);
301 /// Opens a file for reading.
302 /** \overload
303 * Argument \a password specifies a password to decrypt the file. If
304 * it is NULL then this function behaves just like open(OpenMode).
305 **/
306 bool open(OpenMode mode, const char *password)
307 {return open(mode, NULL, NULL, false, password);}
308 /// Opens a file for reading.
309 /** \overload
310 * Argument \a password specifies a password to decrypt the file.
311 *
312 * An integers pointed by \a method and \a level will receive codes
313 * of the compression method and level used. See unzip.h.
314 *
315 * If raw is \c true then no decompression is performed.
316 *
317 * \a method should not be \c NULL. \a level can be \c NULL if you
318 * don't want to know the compression level.
319 **/
320 bool open(OpenMode mode, int *method, int *level, bool raw, const char *password =NULL);
321 /// Opens a file for writing.
322 /** \a info argument specifies information about file. It should at
323 * least specify a correct file name. Also, it is a good idea to
324 * specify correct timestamp (by default, current time will be
325 * used). See QuaZipNewInfo.
326 *
327 * Arguments \a password and \a crc provide necessary information
328 * for crypting. Note that you should specify both of them if you
329 * need crypting. If you do not, pass \c NULL as password, but you
330 * still need to specify \a crc if you are going to use raw mode
331 * (see below).
332 *
333 * Arguments \a method and \a level specify compression method and
334 * level.
335 *
336 * If \a raw is \c true, no compression is performed. In this case,
337 * \a crc and uncompressedSize field of the \a info are required.
338 *
339 * Arguments \a windowBits, \a memLevel, \a strategy provide zlib
340 * algorithms tuning. See deflateInit2() in zlib.
341 **/
342 bool open(OpenMode mode, const QuaZipNewInfo& info,
343 const char *password =NULL, quint32 crc =0,
344 int method =Z_DEFLATED, int level =Z_DEFAULT_COMPRESSION, bool raw =false,
345 int windowBits =-MAX_WBITS, int memLevel =DEF_MEM_LEVEL, int strategy =Z_DEFAULT_STRATEGY);
346 /// Returns \c true, but \ref quazipfile-sequential "beware"!
347 virtual bool isSequential()const;
348 /// Returns current position in the file.
349 /** Implementation of the QIODevice::pos(). When reading, this
350 * function is a wrapper to the ZIP/UNZIP unztell(), therefore it is
351 * unable to keep track of the ungetChar() calls (which is
352 * non-virtual and therefore is dangerous to reimplement). So if you
353 * are using ungetChar() feature of the QIODevice, this function
354 * reports incorrect value until you get back characters which you
355 * ungot.
356 *
357 * When writing, pos() returns number of bytes already written
358 * (uncompressed unless you use raw mode).
359 *
360 * \note Although
361 * \ref quazipfile-sequential "QuaZipFile is a sequential device"
362 * and therefore pos() should always return zero, it does not,
363 * because it would be misguiding. Keep this in mind.
364 *
365 * This function returns -1 if the file or archive is not open.
366 *
367 * Error code returned by getZipError() is not affected by this
368 * function call.
369 **/
370 virtual qint64 pos()const;
371 /// Returns \c true if the end of file was reached.
372 /** This function returns \c false in the case of error. This means
373 * that you called this function on either not open file, or a file
374 * in the not open archive or even on a QuaZipFile instance that
375 * does not even have QuaZip instance associated. Do not do that
376 * because there is no means to determine whether \c false is
377 * returned because of error or because end of file was reached.
378 * Well, on the other side you may interpret \c false return value
379 * as "there is no file open to check for end of file and there is
380 * no end of file therefore".
381 *
382 * When writing, this function always returns \c true (because you
383 * are always writing to the end of file).
384 *
385 * Error code returned by getZipError() is not affected by this
386 * function call.
387 **/
388 virtual bool atEnd()const;
389 /// Returns file size.
390 /** This function returns csize() if the file is open for reading in
391 * raw mode, usize() if it is open for reading in normal mode and
392 * pos() if it is open for writing.
393 *
394 * Returns -1 on error, call getZipError() to get error code.
395 *
396 * \note This function returns file size despite that
397 * \ref quazipfile-sequential "QuaZipFile is considered to be sequential device",
398 * for which size() should return bytesAvailable() instead. But its
399 * name would be very misguiding otherwise, so just keep in mind
400 * this inconsistence.
401 **/
402 virtual qint64 size()const;
403 /// Returns compressed file size.
404 /** Equivalent to calling getFileInfo() and then getting
405 * compressedSize field, but more convenient and faster.
406 *
407 * File must be open for reading before calling this function.
408 *
409 * Returns -1 on error, call getZipError() to get error code.
410 **/
411 qint64 csize()const;
412 /// Returns uncompressed file size.
413 /** Equivalent to calling getFileInfo() and then getting
414 * uncompressedSize field, but more convenient and faster. See
415 * getFileInfo() for a warning.
416 *
417 * File must be open for reading before calling this function.
418 *
419 * Returns -1 on error, call getZipError() to get error code.
420 **/
421 qint64 usize()const;
422 /// Gets information about current file.
423 /** This function does the same thing as calling
424 * QuaZip::getCurrentFileInfo() on the associated QuaZip object,
425 * but you can not call getCurrentFileInfo() if the associated
426 * QuaZip is internal (because you do not have access to it), while
427 * you still can call this function in that case.
428 *
429 * File must be open for reading before calling this function.
430 *
431 * Returns \c false in the case of an error.
432 **/
433 bool getFileInfo(QuaZipFileInfo *info);
434 /// Closes the file.
435 /** Call getZipError() to determine if the close was successful.
436 **/
437 virtual void close();
438 /// Returns the error code returned by the last ZIP/UNZIP API call.
439 int getZipError()const {return zipError;}
440};
441
442#endif
diff --git a/utils/themeeditor/quazip/quazipfileinfo.h b/utils/themeeditor/quazip/quazipfileinfo.h
new file mode 100644
index 0000000000..3216d776d5
--- /dev/null
+++ b/utils/themeeditor/quazip/quazipfileinfo.h
@@ -0,0 +1,73 @@
1#ifndef QUA_ZIPFILEINFO_H
2#define QUA_ZIPFILEINFO_H
3
4/*
5-- A kind of "standard" GPL license statement --
6QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
7Copyright (C) 2005-2007 Sergey A. Tachenov
8
9This program is free software; you can redistribute it and/or modify it
10under the terms of the GNU General Public License as published by the
11Free Software Foundation; either version 2 of the License, or (at your
12option) any later version.
13
14This program is distributed in the hope that it will be useful, but
15WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17Public License for more details.
18
19You should have received a copy of the GNU General Public License along
20with this program; if not, write to the Free Software Foundation, Inc.,
2159 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23-- A kind of "standard" GPL license statement ends here --
24
25See COPYING file for GPL.
26
27You are also permitted to use QuaZIP under the terms of LGPL (see
28COPYING.LGPL). You are free to choose either license, but please note
29that QuaZIP makes use of Qt, which is not licensed under LGPL. So if
30you are using Open Source edition of Qt, you therefore MUST use GPL for
31your code based on QuaZIP, since it would be also based on Qt in this
32case. If you are Qt commercial license owner, then you are free to use
33QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
34 **/
35
36#include <QByteArray>
37#include <QDateTime>
38
39/// Information about a file inside archive.
40/** Call QuaZip::getCurrentFileInfo() or QuaZipFile::getFileInfo() to
41 * fill this structure. */
42struct QuaZipFileInfo {
43 /// File name.
44 QString name;
45 /// Version created by.
46 quint16 versionCreated;
47 /// Version needed to extract.
48 quint16 versionNeeded;
49 /// General purpose flags.
50 quint16 flags;
51 /// Compression method.
52 quint16 method;
53 /// Last modification date and time.
54 QDateTime dateTime;
55 /// CRC.
56 quint32 crc;
57 /// Compressed file size.
58 quint32 compressedSize;
59 /// Uncompressed file size.
60 quint32 uncompressedSize;
61 /// Disk number start.
62 quint16 diskNumberStart;
63 /// Internal file attributes.
64 quint16 internalAttr;
65 /// External file attributes.
66 quint32 externalAttr;
67 /// Comment.
68 QString comment;
69 /// Extra field.
70 QByteArray extra;
71};
72
73#endif
diff --git a/utils/themeeditor/quazip/quazipnewinfo.cpp b/utils/themeeditor/quazip/quazipnewinfo.cpp
new file mode 100644
index 0000000000..17571f2fc8
--- /dev/null
+++ b/utils/themeeditor/quazip/quazipnewinfo.cpp
@@ -0,0 +1,59 @@
1/* -- A kind of "standard" GPL license statement --
2QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
3Copyright (C) 2005-2007 Sergey A. Tachenov
4
5This program is free software; you can redistribute it and/or modify it
6under the terms of the GNU General Public License as published by the
7Free Software Foundation; either version 2 of the License, or (at your
8option) any later version.
9
10This program is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13Public License for more details.
14
15You should have received a copy of the GNU General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1759 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19-- A kind of "standard" GPL license statement ends here --
20
21See COPYING file for GPL.
22
23You are also permitted to use QuaZIP under the terms of LGPL (see
24COPYING.LGPL). You are free to choose either license, but please note
25that QuaZIP makes use of Qt, which is not licensed under LGPL. So if
26you are using Open Source edition of Qt, you therefore MUST use GPL for
27your code based on QuaZIP, since it would be also based on Qt in this
28case. If you are Qt commercial license owner, then you are free to use
29QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
30*/
31
32#include <QFileInfo>
33
34#include "quazipnewinfo.h"
35
36
37QuaZipNewInfo::QuaZipNewInfo(const QString& name):
38 name(name), dateTime(QDateTime::currentDateTime()), internalAttr(0), externalAttr(0)
39{
40}
41
42QuaZipNewInfo::QuaZipNewInfo(const QString& name, const QString& file):
43 name(name), internalAttr(0), externalAttr(0)
44{
45 QFileInfo info(file);
46 QDateTime lm = info.lastModified();
47 if (!info.exists())
48 dateTime = QDateTime::currentDateTime();
49 else
50 dateTime = lm;
51}
52
53void QuaZipNewInfo::setFileDateTime(const QString& file)
54{
55 QFileInfo info(file);
56 QDateTime lm = info.lastModified();
57 if (info.exists())
58 dateTime = lm;
59}
diff --git a/utils/themeeditor/quazip/quazipnewinfo.h b/utils/themeeditor/quazip/quazipnewinfo.h
new file mode 100644
index 0000000000..93ff1a2fc0
--- /dev/null
+++ b/utils/themeeditor/quazip/quazipnewinfo.h
@@ -0,0 +1,109 @@
1#ifndef QUA_ZIPNEWINFO_H
2#define QUA_ZIPNEWINFO_H
3
4/*
5-- A kind of "standard" GPL license statement --
6QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
7Copyright (C) 2005-2007 Sergey A. Tachenov
8
9This program is free software; you can redistribute it and/or modify it
10under the terms of the GNU General Public License as published by the
11Free Software Foundation; either version 2 of the License, or (at your
12option) any later version.
13
14This program is distributed in the hope that it will be useful, but
15WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17Public License for more details.
18
19You should have received a copy of the GNU General Public License along
20with this program; if not, write to the Free Software Foundation, Inc.,
2159 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23-- A kind of "standard" GPL license statement ends here --
24
25See COPYING file for GPL.
26
27You are also permitted to use QuaZIP under the terms of LGPL (see
28COPYING.LGPL). You are free to choose either license, but please note
29that QuaZIP makes use of Qt, which is not licensed under LGPL. So if
30you are using Open Source edition of Qt, you therefore MUST use GPL for
31your code based on QuaZIP, since it would be also based on Qt in this
32case. If you are Qt commercial license owner, then you are free to use
33QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
34 **/
35
36#include <QDateTime>
37#include <QString>
38
39/// Information about a file to be created.
40/** This structure holds information about a file to be created inside
41 * ZIP archive. At least name should be set to something correct before
42 * passing this structure to
43 * QuaZipFile::open(OpenMode,const QuaZipNewInfo&,int,int,bool).
44 **/
45struct QuaZipNewInfo {
46 /// File name.
47 /** This field holds file name inside archive, including path relative
48 * to archive root.
49 **/
50 QString name;
51 /// File timestamp.
52 /** This is the last file modification date and time. Will be stored
53 * in the archive central directory. It is a good practice to set it
54 * to the source file timestamp instead of archive creating time. Use
55 * setFileDateTime() or QuaZipNewInfo(const QString&, const QString&).
56 **/
57 QDateTime dateTime;
58 /// File internal attributes.
59 quint16 internalAttr;
60 /// File external attributes.
61 quint32 externalAttr;
62 /// File comment.
63 /** Will be encoded using QuaZip::getCommentCodec().
64 **/
65 QString comment;
66 /// File local extra field.
67 QByteArray extraLocal;
68 /// File global extra field.
69 QByteArray extraGlobal;
70 /// Uncompressed file size.
71 /** This is only needed if you are using raw file zipping mode, i. e.
72 * adding precompressed file in the zip archive.
73 **/
74 ulong uncompressedSize;
75 /// Constructs QuaZipNewInfo instance.
76 /** Initializes name with \a name, dateTime with current date and
77 * time. Attributes are initialized with zeros, comment and extra
78 * field with null values.
79 **/
80 QuaZipNewInfo(const QString& name);
81 /// Constructs QuaZipNewInfo instance.
82 /** Initializes name with \a name and dateTime with timestamp of the
83 * file named \a file. If the \a file does not exists or its timestamp
84 * is inaccessible (e. g. you do not have read permission for the
85 * directory file in), uses current date and time. Attributes are
86 * initialized with zeros, comment and extra field with null values.
87 *
88 * \sa setFileDateTime()
89 **/
90 QuaZipNewInfo(const QString& name, const QString& file);
91 /// Sets the file timestamp from the existing file.
92 /** Use this function to set the file timestamp from the existing
93 * file. Use it like this:
94 * \code
95 * QuaZipFile zipFile(&zip);
96 * QFile file("file-to-add");
97 * file.open(QIODevice::ReadOnly);
98 * QuaZipNewInfo info("file-name-in-archive");
99 * info.setFileDateTime("file-to-add"); // take the timestamp from file
100 * zipFile.open(QIODevice::WriteOnly, info);
101 * \endcode
102 *
103 * This function does not change dateTime if some error occured (e. g.
104 * file is inaccessible).
105 **/
106 void setFileDateTime(const QString& file);
107};
108
109#endif
diff --git a/utils/themeeditor/quazip/unzip.c b/utils/themeeditor/quazip/unzip.c
new file mode 100644
index 0000000000..ace7a08837
--- /dev/null
+++ b/utils/themeeditor/quazip/unzip.c
@@ -0,0 +1,1601 @@
1/* unzip.c -- IO for uncompress .zip files using zlib
2 Version 1.01e, February 12th, 2005
3
4 Copyright (C) 1998-2005 Gilles Vollant
5
6 Read unzip.h for more info
7*/
8
9/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
10compatibility with older software. The following is from the original crypt.c. Code
11woven in by Terry Thorsen 1/2003.
12*/
13/*
14 Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
15
16 See the accompanying file LICENSE, version 2000-Apr-09 or later
17 (the contents of which are also included in zip.h) for terms of use.
18 If, for some reason, all these files are missing, the Info-ZIP license
19 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
20*/
21/*
22 crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
23
24 The encryption/decryption parts of this source code (as opposed to the
25 non-echoing password parts) were originally written in Europe. The
26 whole source package can be freely distributed, including from the USA.
27 (Prior to January 2000, re-export from the US was a violation of US law.)
28 */
29
30/*
31 This encryption code is a direct transcription of the algorithm from
32 Roger Schlafly, described by Phil Katz in the file appnote.txt. This
33 file (appnote.txt) is distributed with the PKZIP program (even in the
34 version without encryption capabilities).
35 */
36
37
38#include <stdio.h>
39#include <stdlib.h>
40#include <string.h>
41#include "zlib.h"
42#include "unzip.h"
43
44#ifdef STDC
45# include <stddef.h>
46# include <string.h>
47# include <stdlib.h>
48#endif
49#ifdef NO_ERRNO_H
50 extern int errno;
51#else
52# include <errno.h>
53#endif
54
55
56#ifndef local
57# define local static
58#endif
59/* compile with -Dlocal if your debugger can't find static symbols */
60
61
62#ifndef CASESENSITIVITYDEFAULT_NO
63# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
64# define CASESENSITIVITYDEFAULT_NO
65# endif
66#endif
67
68
69#ifndef UNZ_BUFSIZE
70#define UNZ_BUFSIZE (16384)
71#endif
72
73#ifndef UNZ_MAXFILENAMEINZIP
74#define UNZ_MAXFILENAMEINZIP (256)
75#endif
76
77#ifndef ALLOC
78# define ALLOC(size) (malloc(size))
79#endif
80#ifndef TRYFREE
81# define TRYFREE(p) {if (p) free(p);}
82#endif
83
84#define SIZECENTRALDIRITEM (0x2e)
85#define SIZEZIPLOCALHEADER (0x1e)
86
87
88
89
90const char unz_copyright[] =
91 " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
92
93/* unz_file_info_interntal contain internal info about a file in zipfile*/
94typedef struct unz_file_info_internal_s
95{
96 uLong offset_curfile;/* relative offset of local header 4 bytes */
97} unz_file_info_internal;
98
99
100/* file_in_zip_read_info_s contain internal information about a file in zipfile,
101 when reading and decompress it */
102typedef struct
103{
104 char *read_buffer; /* internal buffer for compressed data */
105 z_stream stream; /* zLib stream structure for inflate */
106
107 uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
108 uLong stream_initialised; /* flag set if stream structure is initialised*/
109
110 uLong offset_local_extrafield;/* offset of the local extra field */
111 uInt size_local_extrafield;/* size of the local extra field */
112 uLong pos_local_extrafield; /* position in the local extra field in read*/
113
114 uLong crc32; /* crc32 of all data uncompressed */
115 uLong crc32_wait; /* crc32 we must obtain after decompress all */
116 uLong rest_read_compressed; /* number of byte to be decompressed */
117 uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
118 zlib_filefunc_def z_filefunc;
119 voidpf filestream; /* io structore of the zipfile */
120 uLong compression_method; /* compression method (0==store) */
121 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
122 int raw;
123} file_in_zip_read_info_s;
124
125
126/* unz_s contain internal information about the zipfile
127*/
128typedef struct
129{
130 zlib_filefunc_def z_filefunc;
131 voidpf filestream; /* io structore of the zipfile */
132 unz_global_info gi; /* public global information */
133 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
134 uLong num_file; /* number of the current file in the zipfile*/
135 uLong pos_in_central_dir; /* pos of the current file in the central dir*/
136 uLong current_file_ok; /* flag about the usability of the current file*/
137 uLong central_pos; /* position of the beginning of the central dir*/
138
139 uLong size_central_dir; /* size of the central directory */
140 uLong offset_central_dir; /* offset of start of central directory with
141 respect to the starting disk number */
142
143 unz_file_info cur_file_info; /* public info about the current file in zip*/
144 unz_file_info_internal cur_file_info_internal; /* private info about it*/
145 file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
146 file if we are decompressing it */
147 int encrypted;
148# ifndef NOUNCRYPT
149 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
150 const unsigned long* pcrc_32_tab;
151# endif
152} unz_s;
153
154
155#ifndef NOUNCRYPT
156#include "crypt.h"
157#endif
158
159/* ===========================================================================
160 Read a byte from a gz_stream; update next_in and avail_in. Return EOF
161 for end of file.
162 IN assertion: the stream s has been sucessfully opened for reading.
163*/
164
165
166local int unzlocal_getByte OF((
167 const zlib_filefunc_def* pzlib_filefunc_def,
168 voidpf filestream,
169 int *pi));
170
171local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
172 const zlib_filefunc_def* pzlib_filefunc_def;
173 voidpf filestream;
174 int *pi;
175{
176 unsigned char c;
177 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
178 if (err==1)
179 {
180 *pi = (int)c;
181 return UNZ_OK;
182 }
183 else
184 {
185 if (ZERROR(*pzlib_filefunc_def,filestream))
186 return UNZ_ERRNO;
187 else
188 return UNZ_EOF;
189 }
190}
191
192
193/* ===========================================================================
194 Reads a long in LSB order from the given gz_stream. Sets
195*/
196local int unzlocal_getShort OF((
197 const zlib_filefunc_def* pzlib_filefunc_def,
198 voidpf filestream,
199 uLong *pX));
200
201local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
202 const zlib_filefunc_def* pzlib_filefunc_def;
203 voidpf filestream;
204 uLong *pX;
205{
206 uLong x ;
207 int i;
208 int err;
209
210 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
211 x = (uLong)i;
212
213 if (err==UNZ_OK)
214 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
215 x += ((uLong)i)<<8;
216
217 if (err==UNZ_OK)
218 *pX = x;
219 else
220 *pX = 0;
221 return err;
222}
223
224local int unzlocal_getLong OF((
225 const zlib_filefunc_def* pzlib_filefunc_def,
226 voidpf filestream,
227 uLong *pX));
228
229local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
230 const zlib_filefunc_def* pzlib_filefunc_def;
231 voidpf filestream;
232 uLong *pX;
233{
234 uLong x ;
235 int i;
236 int err;
237
238 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
239 x = (uLong)i;
240
241 if (err==UNZ_OK)
242 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
243 x += ((uLong)i)<<8;
244
245 if (err==UNZ_OK)
246 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
247 x += ((uLong)i)<<16;
248
249 if (err==UNZ_OK)
250 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
251 x += ((uLong)i)<<24;
252
253 if (err==UNZ_OK)
254 *pX = x;
255 else
256 *pX = 0;
257 return err;
258}
259
260
261/* My own strcmpi / strcasecmp */
262local int strcmpcasenosensitive_internal (fileName1,fileName2)
263 const char* fileName1;
264 const char* fileName2;
265{
266 for (;;)
267 {
268 char c1=*(fileName1++);
269 char c2=*(fileName2++);
270 if ((c1>='a') && (c1<='z'))
271 c1 -= 0x20;
272 if ((c2>='a') && (c2<='z'))
273 c2 -= 0x20;
274 if (c1=='\0')
275 return ((c2=='\0') ? 0 : -1);
276 if (c2=='\0')
277 return 1;
278 if (c1<c2)
279 return -1;
280 if (c1>c2)
281 return 1;
282 }
283}
284
285
286#ifdef CASESENSITIVITYDEFAULT_NO
287#define CASESENSITIVITYDEFAULTVALUE 2
288#else
289#define CASESENSITIVITYDEFAULTVALUE 1
290#endif
291
292#ifndef STRCMPCASENOSENTIVEFUNCTION
293#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
294#endif
295
296/*
297 Compare two filename (fileName1,fileName2).
298 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
299 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
300 or strcasecmp)
301 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
302 (like 1 on Unix, 2 on Windows)
303
304*/
305extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)
306 const char* fileName1;
307 const char* fileName2;
308 int iCaseSensitivity;
309{
310 if (iCaseSensitivity==0)
311 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
312
313 if (iCaseSensitivity==1)
314 return strcmp(fileName1,fileName2);
315
316 return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
317}
318
319#ifndef BUFREADCOMMENT
320#define BUFREADCOMMENT (0x400)
321#endif
322
323/*
324 Locate the Central directory of a zipfile (at the end, just before
325 the global comment)
326*/
327local uLong unzlocal_SearchCentralDir OF((
328 const zlib_filefunc_def* pzlib_filefunc_def,
329 voidpf filestream));
330
331local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
332 const zlib_filefunc_def* pzlib_filefunc_def;
333 voidpf filestream;
334{
335 unsigned char* buf;
336 uLong uSizeFile;
337 uLong uBackRead;
338 uLong uMaxBack=0xffff; /* maximum size of global comment */
339 uLong uPosFound=0;
340
341 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
342 return 0;
343
344
345 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
346
347 if (uMaxBack>uSizeFile)
348 uMaxBack = uSizeFile;
349
350 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
351 if (buf==NULL)
352 return 0;
353
354 uBackRead = 4;
355 while (uBackRead<uMaxBack)
356 {
357 uLong uReadSize,uReadPos ;
358 int i;
359 if (uBackRead+BUFREADCOMMENT>uMaxBack)
360 uBackRead = uMaxBack;
361 else
362 uBackRead+=BUFREADCOMMENT;
363 uReadPos = uSizeFile-uBackRead ;
364
365 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
366 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
367 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
368 break;
369
370 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
371 break;
372
373 for (i=(int)uReadSize-3; (i--)>0;)
374 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
375 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
376 {
377 uPosFound = uReadPos+i;
378 break;
379 }
380
381 if (uPosFound!=0)
382 break;
383 }
384 TRYFREE(buf);
385 return uPosFound;
386}
387
388/*
389 Open a Zip file. path contain the full pathname (by example,
390 on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
391 "zlib/zlib114.zip".
392 If the zipfile cannot be opened (file doesn't exist or in not valid), the
393 return value is NULL.
394 Else, the return value is a unzFile Handle, usable with other function
395 of this unzip package.
396*/
397extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
398 const char *path;
399 zlib_filefunc_def* pzlib_filefunc_def;
400{
401 unz_s us;
402 unz_s *s;
403 uLong central_pos,uL;
404
405 uLong number_disk; /* number of the current dist, used for
406 spaning ZIP, unsupported, always 0*/
407 uLong number_disk_with_CD; /* number the the disk with central dir, used
408 for spaning ZIP, unsupported, always 0*/
409 uLong number_entry_CD; /* total number of entries in
410 the central dir
411 (same than number_entry on nospan) */
412
413 int err=UNZ_OK;
414
415 if (unz_copyright[0]!=' ')
416 return NULL;
417
418 if (pzlib_filefunc_def==NULL)
419 fill_fopen_filefunc(&us.z_filefunc);
420 else
421 us.z_filefunc = *pzlib_filefunc_def;
422
423 us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque,
424 path,
425 ZLIB_FILEFUNC_MODE_READ |
426 ZLIB_FILEFUNC_MODE_EXISTING);
427 if (us.filestream==NULL)
428 return NULL;
429
430 central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream);
431 if (central_pos==0)
432 err=UNZ_ERRNO;
433
434 if (ZSEEK(us.z_filefunc, us.filestream,
435 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
436 err=UNZ_ERRNO;
437
438 /* the signature, already checked */
439 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
440 err=UNZ_ERRNO;
441
442 /* number of this disk */
443 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
444 err=UNZ_ERRNO;
445
446 /* number of the disk with the start of the central directory */
447 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
448 err=UNZ_ERRNO;
449
450 /* total number of entries in the central dir on this disk */
451 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
452 err=UNZ_ERRNO;
453
454 /* total number of entries in the central dir */
455 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
456 err=UNZ_ERRNO;
457
458 if ((number_entry_CD!=us.gi.number_entry) ||
459 (number_disk_with_CD!=0) ||
460 (number_disk!=0))
461 err=UNZ_BADZIPFILE;
462
463 /* size of the central directory */
464 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
465 err=UNZ_ERRNO;
466
467 /* offset of start of central directory with respect to the
468 starting disk number */
469 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
470 err=UNZ_ERRNO;
471
472 /* zipfile comment length */
473 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
474 err=UNZ_ERRNO;
475
476 if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
477 (err==UNZ_OK))
478 err=UNZ_BADZIPFILE;
479
480 if (err!=UNZ_OK)
481 {
482 ZCLOSE(us.z_filefunc, us.filestream);
483 return NULL;
484 }
485
486 us.byte_before_the_zipfile = central_pos -
487 (us.offset_central_dir+us.size_central_dir);
488 us.central_pos = central_pos;
489 us.pfile_in_zip_read = NULL;
490 us.encrypted = 0;
491
492
493 s=(unz_s*)ALLOC(sizeof(unz_s));
494 *s=us;
495 unzGoToFirstFile((unzFile)s);
496 return (unzFile)s;
497}
498
499
500extern unzFile ZEXPORT unzOpen (path)
501 const char *path;
502{
503 return unzOpen2(path, NULL);
504}
505
506/*
507 Close a ZipFile opened with unzipOpen.
508 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
509 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
510 return UNZ_OK if there is no problem. */
511extern int ZEXPORT unzClose (file)
512 unzFile file;
513{
514 unz_s* s;
515 if (file==NULL)
516 return UNZ_PARAMERROR;
517 s=(unz_s*)file;
518
519 if (s->pfile_in_zip_read!=NULL)
520 unzCloseCurrentFile(file);
521
522 ZCLOSE(s->z_filefunc, s->filestream);
523 TRYFREE(s);
524 return UNZ_OK;
525}
526
527
528/*
529 Write info about the ZipFile in the *pglobal_info structure.
530 No preparation of the structure is needed
531 return UNZ_OK if there is no problem. */
532extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info)
533 unzFile file;
534 unz_global_info *pglobal_info;
535{
536 unz_s* s;
537 if (file==NULL)
538 return UNZ_PARAMERROR;
539 s=(unz_s*)file;
540 *pglobal_info=s->gi;
541 return UNZ_OK;
542}
543
544
545/*
546 Translate date/time from Dos format to tm_unz (readable more easilty)
547*/
548local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
549 uLong ulDosDate;
550 tm_unz* ptm;
551{
552 uLong uDate;
553 uDate = (uLong)(ulDosDate>>16);
554 ptm->tm_mday = (uInt)(uDate&0x1f) ;
555 ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
556 ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
557
558 ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
559 ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ;
560 ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ;
561}
562
563/*
564 Get Info about the current file in the zipfile, with internal only info
565*/
566local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
567 unz_file_info *pfile_info,
568 unz_file_info_internal
569 *pfile_info_internal,
570 char *szFileName,
571 uLong fileNameBufferSize,
572 void *extraField,
573 uLong extraFieldBufferSize,
574 char *szComment,
575 uLong commentBufferSize));
576
577local int unzlocal_GetCurrentFileInfoInternal (file,
578 pfile_info,
579 pfile_info_internal,
580 szFileName, fileNameBufferSize,
581 extraField, extraFieldBufferSize,
582 szComment, commentBufferSize)
583 unzFile file;
584 unz_file_info *pfile_info;
585 unz_file_info_internal *pfile_info_internal;
586 char *szFileName;
587 uLong fileNameBufferSize;
588 void *extraField;
589 uLong extraFieldBufferSize;
590 char *szComment;
591 uLong commentBufferSize;
592{
593 unz_s* s;
594 unz_file_info file_info;
595 unz_file_info_internal file_info_internal;
596 int err=UNZ_OK;
597 uLong uMagic;
598 long lSeek=0;
599
600 if (file==NULL)
601 return UNZ_PARAMERROR;
602 s=(unz_s*)file;
603 if (ZSEEK(s->z_filefunc, s->filestream,
604 s->pos_in_central_dir+s->byte_before_the_zipfile,
605 ZLIB_FILEFUNC_SEEK_SET)!=0)
606 err=UNZ_ERRNO;
607
608
609 /* we check the magic */
610 if (err==UNZ_OK) {
611 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
612 err=UNZ_ERRNO;
613 else if (uMagic!=0x02014b50)
614 err=UNZ_BADZIPFILE;
615 }
616
617 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
618 err=UNZ_ERRNO;
619
620 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
621 err=UNZ_ERRNO;
622
623 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
624 err=UNZ_ERRNO;
625
626 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
627 err=UNZ_ERRNO;
628
629 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
630 err=UNZ_ERRNO;
631
632 unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
633
634 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
635 err=UNZ_ERRNO;
636
637 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
638 err=UNZ_ERRNO;
639
640 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
641 err=UNZ_ERRNO;
642
643 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
644 err=UNZ_ERRNO;
645
646 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
647 err=UNZ_ERRNO;
648
649 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
650 err=UNZ_ERRNO;
651
652 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
653 err=UNZ_ERRNO;
654
655 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
656 err=UNZ_ERRNO;
657
658 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
659 err=UNZ_ERRNO;
660
661 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
662 err=UNZ_ERRNO;
663
664 lSeek+=file_info.size_filename;
665 if ((err==UNZ_OK) && (szFileName!=NULL))
666 {
667 uLong uSizeRead ;
668 if (file_info.size_filename<fileNameBufferSize)
669 {
670 *(szFileName+file_info.size_filename)='\0';
671 uSizeRead = file_info.size_filename;
672 }
673 else
674 uSizeRead = fileNameBufferSize;
675
676 if ((file_info.size_filename>0) && (fileNameBufferSize>0))
677 if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
678 err=UNZ_ERRNO;
679 lSeek -= uSizeRead;
680 }
681
682
683 if ((err==UNZ_OK) && (extraField!=NULL))
684 {
685 uLong uSizeRead ;
686 if (file_info.size_file_extra<extraFieldBufferSize)
687 uSizeRead = file_info.size_file_extra;
688 else
689 uSizeRead = extraFieldBufferSize;
690
691 if (lSeek!=0) {
692 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
693 lSeek=0;
694 else
695 err=UNZ_ERRNO;
696 }
697 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
698 if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)
699 err=UNZ_ERRNO;
700 lSeek += file_info.size_file_extra - uSizeRead;
701 }
702 else
703 lSeek+=file_info.size_file_extra;
704
705
706 if ((err==UNZ_OK) && (szComment!=NULL))
707 {
708 uLong uSizeRead ;
709 if (file_info.size_file_comment<commentBufferSize)
710 {
711 *(szComment+file_info.size_file_comment)='\0';
712 uSizeRead = file_info.size_file_comment;
713 }
714 else
715 uSizeRead = commentBufferSize;
716
717 if (lSeek!=0) {
718 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
719 lSeek=0;
720 else
721 err=UNZ_ERRNO;
722 }
723 if ((file_info.size_file_comment>0) && (commentBufferSize>0))
724 if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
725 err=UNZ_ERRNO;
726 lSeek+=file_info.size_file_comment - uSizeRead;
727 }
728 else
729 lSeek+=file_info.size_file_comment;
730
731 if ((err==UNZ_OK) && (pfile_info!=NULL))
732 *pfile_info=file_info;
733
734 if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
735 *pfile_info_internal=file_info_internal;
736
737 return err;
738}
739
740
741
742/*
743 Write info about the ZipFile in the *pglobal_info structure.
744 No preparation of the structure is needed
745 return UNZ_OK if there is no problem.
746*/
747extern int ZEXPORT unzGetCurrentFileInfo (file,
748 pfile_info,
749 szFileName, fileNameBufferSize,
750 extraField, extraFieldBufferSize,
751 szComment, commentBufferSize)
752 unzFile file;
753 unz_file_info *pfile_info;
754 char *szFileName;
755 uLong fileNameBufferSize;
756 void *extraField;
757 uLong extraFieldBufferSize;
758 char *szComment;
759 uLong commentBufferSize;
760{
761 return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
762 szFileName,fileNameBufferSize,
763 extraField,extraFieldBufferSize,
764 szComment,commentBufferSize);
765}
766
767/*
768 Set the current file of the zipfile to the first file.
769 return UNZ_OK if there is no problem
770*/
771extern int ZEXPORT unzGoToFirstFile (file)
772 unzFile file;
773{
774 int err=UNZ_OK;
775 unz_s* s;
776 if (file==NULL)
777 return UNZ_PARAMERROR;
778 s=(unz_s*)file;
779 s->pos_in_central_dir=s->offset_central_dir;
780 s->num_file=0;
781 err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
782 &s->cur_file_info_internal,
783 NULL,0,NULL,0,NULL,0);
784 s->current_file_ok = (err == UNZ_OK);
785 return err;
786}
787
788/*
789 Set the current file of the zipfile to the next file.
790 return UNZ_OK if there is no problem
791 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
792*/
793extern int ZEXPORT unzGoToNextFile (file)
794 unzFile file;
795{
796 unz_s* s;
797 int err;
798
799 if (file==NULL)
800 return UNZ_PARAMERROR;
801 s=(unz_s*)file;
802 if (!s->current_file_ok)
803 return UNZ_END_OF_LIST_OF_FILE;
804 if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
805 if (s->num_file+1==s->gi.number_entry)
806 return UNZ_END_OF_LIST_OF_FILE;
807
808 s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
809 s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
810 s->num_file++;
811 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
812 &s->cur_file_info_internal,
813 NULL,0,NULL,0,NULL,0);
814 s->current_file_ok = (err == UNZ_OK);
815 return err;
816}
817
818
819/*
820 Try locate the file szFileName in the zipfile.
821 For the iCaseSensitivity signification, see unzipStringFileNameCompare
822
823 return value :
824 UNZ_OK if the file is found. It becomes the current file.
825 UNZ_END_OF_LIST_OF_FILE if the file is not found
826*/
827extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
828 unzFile file;
829 const char *szFileName;
830 int iCaseSensitivity;
831{
832 unz_s* s;
833 int err;
834
835 /* We remember the 'current' position in the file so that we can jump
836 * back there if we fail.
837 */
838 unz_file_info cur_file_infoSaved;
839 unz_file_info_internal cur_file_info_internalSaved;
840 uLong num_fileSaved;
841 uLong pos_in_central_dirSaved;
842
843
844 if (file==NULL)
845 return UNZ_PARAMERROR;
846
847 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
848 return UNZ_PARAMERROR;
849
850 s=(unz_s*)file;
851 if (!s->current_file_ok)
852 return UNZ_END_OF_LIST_OF_FILE;
853
854 /* Save the current state */
855 num_fileSaved = s->num_file;
856 pos_in_central_dirSaved = s->pos_in_central_dir;
857 cur_file_infoSaved = s->cur_file_info;
858 cur_file_info_internalSaved = s->cur_file_info_internal;
859
860 err = unzGoToFirstFile(file);
861
862 while (err == UNZ_OK)
863 {
864 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
865 err = unzGetCurrentFileInfo(file,NULL,
866 szCurrentFileName,sizeof(szCurrentFileName)-1,
867 NULL,0,NULL,0);
868 if (err == UNZ_OK)
869 {
870 if (unzStringFileNameCompare(szCurrentFileName,
871 szFileName,iCaseSensitivity)==0)
872 return UNZ_OK;
873 err = unzGoToNextFile(file);
874 }
875 }
876
877 /* We failed, so restore the state of the 'current file' to where we
878 * were.
879 */
880 s->num_file = num_fileSaved ;
881 s->pos_in_central_dir = pos_in_central_dirSaved ;
882 s->cur_file_info = cur_file_infoSaved;
883 s->cur_file_info_internal = cur_file_info_internalSaved;
884 return err;
885}
886
887
888/*
889///////////////////////////////////////////
890// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
891// I need random access
892//
893// Further optimization could be realized by adding an ability
894// to cache the directory in memory. The goal being a single
895// comprehensive file read to put the file I need in a memory.
896*/
897
898/*
899typedef struct unz_file_pos_s
900{
901 uLong pos_in_zip_directory; // offset in file
902 uLong num_of_file; // # of file
903} unz_file_pos;
904*/
905
906extern int ZEXPORT unzGetFilePos(file, file_pos)
907 unzFile file;
908 unz_file_pos* file_pos;
909{
910 unz_s* s;
911
912 if (file==NULL || file_pos==NULL)
913 return UNZ_PARAMERROR;
914 s=(unz_s*)file;
915 if (!s->current_file_ok)
916 return UNZ_END_OF_LIST_OF_FILE;
917
918 file_pos->pos_in_zip_directory = s->pos_in_central_dir;
919 file_pos->num_of_file = s->num_file;
920
921 return UNZ_OK;
922}
923
924extern int ZEXPORT unzGoToFilePos(file, file_pos)
925 unzFile file;
926 unz_file_pos* file_pos;
927{
928 unz_s* s;
929 int err;
930
931 if (file==NULL || file_pos==NULL)
932 return UNZ_PARAMERROR;
933 s=(unz_s*)file;
934
935 /* jump to the right spot */
936 s->pos_in_central_dir = file_pos->pos_in_zip_directory;
937 s->num_file = file_pos->num_of_file;
938
939 /* set the current file */
940 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
941 &s->cur_file_info_internal,
942 NULL,0,NULL,0,NULL,0);
943 /* return results */
944 s->current_file_ok = (err == UNZ_OK);
945 return err;
946}
947
948/*
949// Unzip Helper Functions - should be here?
950///////////////////////////////////////////
951*/
952
953/*
954 Read the local header of the current zipfile
955 Check the coherency of the local header and info in the end of central
956 directory about this file
957 store in *piSizeVar the size of extra info in local header
958 (filename and size of extra field data)
959*/
960local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
961 poffset_local_extrafield,
962 psize_local_extrafield)
963 unz_s* s;
964 uInt* piSizeVar;
965 uLong *poffset_local_extrafield;
966 uInt *psize_local_extrafield;
967{
968 uLong uMagic,uData,uFlags;
969 uLong size_filename;
970 uLong size_extra_field;
971 int err=UNZ_OK;
972
973 *piSizeVar = 0;
974 *poffset_local_extrafield = 0;
975 *psize_local_extrafield = 0;
976
977 if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
978 s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
979 return UNZ_ERRNO;
980
981
982 if (err==UNZ_OK) {
983 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
984 err=UNZ_ERRNO;
985 else if (uMagic!=0x04034b50)
986 err=UNZ_BADZIPFILE;
987 }
988
989 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
990 err=UNZ_ERRNO;
991/*
992 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
993 err=UNZ_BADZIPFILE;
994*/
995 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
996 err=UNZ_ERRNO;
997
998 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
999 err=UNZ_ERRNO;
1000 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
1001 err=UNZ_BADZIPFILE;
1002
1003 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
1004 (s->cur_file_info.compression_method!=Z_DEFLATED))
1005 err=UNZ_BADZIPFILE;
1006
1007 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
1008 err=UNZ_ERRNO;
1009
1010 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
1011 err=UNZ_ERRNO;
1012 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
1013 ((uFlags & 8)==0))
1014 err=UNZ_BADZIPFILE;
1015
1016 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
1017 err=UNZ_ERRNO;
1018 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
1019 ((uFlags & 8)==0))
1020 err=UNZ_BADZIPFILE;
1021
1022 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
1023 err=UNZ_ERRNO;
1024 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
1025 ((uFlags & 8)==0))
1026 err=UNZ_BADZIPFILE;
1027
1028
1029 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1030 err=UNZ_ERRNO;
1031 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1032 err=UNZ_BADZIPFILE;
1033
1034 *piSizeVar += (uInt)size_filename;
1035
1036 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
1037 err=UNZ_ERRNO;
1038 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
1039 SIZEZIPLOCALHEADER + size_filename;
1040 *psize_local_extrafield = (uInt)size_extra_field;
1041
1042 *piSizeVar += (uInt)size_extra_field;
1043
1044 return err;
1045}
1046
1047/*
1048 Open for reading data the current file in the zipfile.
1049 If there is no error and the file is opened, the return value is UNZ_OK.
1050*/
1051extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1052 unzFile file;
1053 int* method;
1054 int* level;
1055 int raw;
1056 const char* password;
1057{
1058 int err=UNZ_OK;
1059 uInt iSizeVar;
1060 unz_s* s;
1061 file_in_zip_read_info_s* pfile_in_zip_read_info;
1062 uLong offset_local_extrafield; /* offset of the local extra field */
1063 uInt size_local_extrafield; /* size of the local extra field */
1064# ifndef NOUNCRYPT
1065 char source[12];
1066# else
1067 if (password != NULL)
1068 return UNZ_PARAMERROR;
1069# endif
1070
1071 if (file==NULL)
1072 return UNZ_PARAMERROR;
1073 s=(unz_s*)file;
1074 if (!s->current_file_ok)
1075 return UNZ_PARAMERROR;
1076
1077 if (s->pfile_in_zip_read != NULL)
1078 unzCloseCurrentFile(file);
1079
1080 if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
1081 &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1082 return UNZ_BADZIPFILE;
1083
1084 pfile_in_zip_read_info = (file_in_zip_read_info_s*)
1085 ALLOC(sizeof(file_in_zip_read_info_s));
1086 if (pfile_in_zip_read_info==NULL)
1087 return UNZ_INTERNALERROR;
1088
1089 pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
1090 pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
1091 pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
1092 pfile_in_zip_read_info->pos_local_extrafield=0;
1093 pfile_in_zip_read_info->raw=raw;
1094
1095 if (pfile_in_zip_read_info->read_buffer==NULL)
1096 {
1097 TRYFREE(pfile_in_zip_read_info);
1098 return UNZ_INTERNALERROR;
1099 }
1100
1101 pfile_in_zip_read_info->stream_initialised=0;
1102
1103 if (method!=NULL)
1104 *method = (int)s->cur_file_info.compression_method;
1105
1106 if (level!=NULL)
1107 {
1108 *level = 6;
1109 switch (s->cur_file_info.flag & 0x06)
1110 {
1111 case 6 : *level = 1; break;
1112 case 4 : *level = 2; break;
1113 case 2 : *level = 9; break;
1114 }
1115 }
1116
1117 if ((s->cur_file_info.compression_method!=0) &&
1118 (s->cur_file_info.compression_method!=Z_DEFLATED))
1119 err=UNZ_BADZIPFILE;
1120
1121 pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
1122 pfile_in_zip_read_info->crc32=0;
1123 pfile_in_zip_read_info->compression_method =
1124 s->cur_file_info.compression_method;
1125 pfile_in_zip_read_info->filestream=s->filestream;
1126 pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
1127 pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
1128
1129 pfile_in_zip_read_info->stream.total_out = 0;
1130
1131 if ((s->cur_file_info.compression_method==Z_DEFLATED) &&
1132 (!raw))
1133 {
1134 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1135 pfile_in_zip_read_info->stream.zfree = (free_func)0;
1136 pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1137 pfile_in_zip_read_info->stream.next_in = (voidpf)0;
1138 pfile_in_zip_read_info->stream.avail_in = 0;
1139
1140 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1141 if (err == Z_OK)
1142 pfile_in_zip_read_info->stream_initialised=1;
1143 else
1144 {
1145 TRYFREE(pfile_in_zip_read_info);
1146 return err;
1147 }
1148 /* windowBits is passed < 0 to tell that there is no zlib header.
1149 * Note that in this case inflate *requires* an extra "dummy" byte
1150 * after the compressed stream in order to complete decompression and
1151 * return Z_STREAM_END.
1152 * In unzip, i don't wait absolutely Z_STREAM_END because I known the
1153 * size of both compressed and uncompressed data
1154 */
1155 }
1156 pfile_in_zip_read_info->rest_read_compressed =
1157 s->cur_file_info.compressed_size ;
1158 pfile_in_zip_read_info->rest_read_uncompressed =
1159 s->cur_file_info.uncompressed_size ;
1160
1161
1162 pfile_in_zip_read_info->pos_in_zipfile =
1163 s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
1164 iSizeVar;
1165
1166 pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1167
1168 s->pfile_in_zip_read = pfile_in_zip_read_info;
1169
1170# ifndef NOUNCRYPT
1171 if (password != NULL)
1172 {
1173 int i;
1174 s->pcrc_32_tab = get_crc_table();
1175 init_keys(password,s->keys,s->pcrc_32_tab);
1176 if (ZSEEK(s->z_filefunc, s->filestream,
1177 s->pfile_in_zip_read->pos_in_zipfile +
1178 s->pfile_in_zip_read->byte_before_the_zipfile,
1179 SEEK_SET)!=0)
1180 return UNZ_INTERNALERROR;
1181 if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12)
1182 return UNZ_INTERNALERROR;
1183
1184 for (i = 0; i<12; i++)
1185 zdecode(s->keys,s->pcrc_32_tab,source[i]);
1186
1187 s->pfile_in_zip_read->pos_in_zipfile+=12;
1188 s->encrypted=1;
1189 }
1190# endif
1191
1192
1193 return UNZ_OK;
1194}
1195
1196extern int ZEXPORT unzOpenCurrentFile (file)
1197 unzFile file;
1198{
1199 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1200}
1201
1202extern int ZEXPORT unzOpenCurrentFilePassword (file, password)
1203 unzFile file;
1204 const char* password;
1205{
1206 return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1207}
1208
1209extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
1210 unzFile file;
1211 int* method;
1212 int* level;
1213 int raw;
1214{
1215 return unzOpenCurrentFile3(file, method, level, raw, NULL);
1216}
1217
1218/*
1219 Read bytes from the current file.
1220 buf contain buffer where data must be copied
1221 len the size of buf.
1222
1223 return the number of byte copied if somes bytes are copied
1224 return 0 if the end of file was reached
1225 return <0 with error code if there is an error
1226 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
1227*/
1228extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1229 unzFile file;
1230 voidp buf;
1231 unsigned len;
1232{
1233 int err=UNZ_OK;
1234 uInt iRead = 0;
1235 unz_s* s;
1236 file_in_zip_read_info_s* pfile_in_zip_read_info;
1237 if (file==NULL)
1238 return UNZ_PARAMERROR;
1239 s=(unz_s*)file;
1240 pfile_in_zip_read_info=s->pfile_in_zip_read;
1241
1242 if (pfile_in_zip_read_info==NULL)
1243 return UNZ_PARAMERROR;
1244
1245
1246 if ((pfile_in_zip_read_info->read_buffer == NULL))
1247 return UNZ_END_OF_LIST_OF_FILE;
1248 if (len==0)
1249 return 0;
1250
1251 pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
1252
1253 pfile_in_zip_read_info->stream.avail_out = (uInt)len;
1254
1255 if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
1256 (!(pfile_in_zip_read_info->raw)))
1257 pfile_in_zip_read_info->stream.avail_out =
1258 (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1259
1260 if ((len>pfile_in_zip_read_info->rest_read_compressed+
1261 pfile_in_zip_read_info->stream.avail_in) &&
1262 (pfile_in_zip_read_info->raw))
1263 pfile_in_zip_read_info->stream.avail_out =
1264 (uInt)pfile_in_zip_read_info->rest_read_compressed+
1265 pfile_in_zip_read_info->stream.avail_in;
1266
1267 while (pfile_in_zip_read_info->stream.avail_out>0)
1268 {
1269 if ((pfile_in_zip_read_info->stream.avail_in==0) &&
1270 (pfile_in_zip_read_info->rest_read_compressed>0))
1271 {
1272 uInt uReadThis = UNZ_BUFSIZE;
1273 if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
1274 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
1275 if (uReadThis == 0)
1276 return UNZ_EOF;
1277 if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
1278 pfile_in_zip_read_info->filestream,
1279 pfile_in_zip_read_info->pos_in_zipfile +
1280 pfile_in_zip_read_info->byte_before_the_zipfile,
1281 ZLIB_FILEFUNC_SEEK_SET)!=0)
1282 return UNZ_ERRNO;
1283 if (ZREAD(pfile_in_zip_read_info->z_filefunc,
1284 pfile_in_zip_read_info->filestream,
1285 pfile_in_zip_read_info->read_buffer,
1286 uReadThis)!=uReadThis)
1287 return UNZ_ERRNO;
1288
1289
1290# ifndef NOUNCRYPT
1291 if(s->encrypted)
1292 {
1293 uInt i;
1294 for(i=0;i<uReadThis;i++)
1295 pfile_in_zip_read_info->read_buffer[i] =
1296 zdecode(s->keys,s->pcrc_32_tab,
1297 pfile_in_zip_read_info->read_buffer[i]);
1298 }
1299# endif
1300
1301
1302 pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
1303
1304 pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
1305
1306 pfile_in_zip_read_info->stream.next_in =
1307 (Bytef*)pfile_in_zip_read_info->read_buffer;
1308 pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
1309 }
1310
1311 if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
1312 {
1313 uInt uDoCopy,i ;
1314
1315 if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
1316 (pfile_in_zip_read_info->rest_read_compressed == 0))
1317 return (iRead==0) ? UNZ_EOF : iRead;
1318
1319 if (pfile_in_zip_read_info->stream.avail_out <
1320 pfile_in_zip_read_info->stream.avail_in)
1321 uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
1322 else
1323 uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
1324
1325 for (i=0;i<uDoCopy;i++)
1326 *(pfile_in_zip_read_info->stream.next_out+i) =
1327 *(pfile_in_zip_read_info->stream.next_in+i);
1328
1329 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
1330 pfile_in_zip_read_info->stream.next_out,
1331 uDoCopy);
1332 pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
1333 pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
1334 pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
1335 pfile_in_zip_read_info->stream.next_out += uDoCopy;
1336 pfile_in_zip_read_info->stream.next_in += uDoCopy;
1337 pfile_in_zip_read_info->stream.total_out += uDoCopy;
1338 iRead += uDoCopy;
1339 }
1340 else
1341 {
1342 uLong uTotalOutBefore,uTotalOutAfter;
1343 const Bytef *bufBefore;
1344 uLong uOutThis;
1345 int flush=Z_SYNC_FLUSH;
1346
1347 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
1348 bufBefore = pfile_in_zip_read_info->stream.next_out;
1349
1350 /*
1351 if ((pfile_in_zip_read_info->rest_read_uncompressed ==
1352 pfile_in_zip_read_info->stream.avail_out) &&
1353 (pfile_in_zip_read_info->rest_read_compressed == 0))
1354 flush = Z_FINISH;
1355 */
1356 err=inflate(&pfile_in_zip_read_info->stream,flush);
1357
1358 if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
1359 err = Z_DATA_ERROR;
1360
1361 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1362 uOutThis = uTotalOutAfter-uTotalOutBefore;
1363
1364 pfile_in_zip_read_info->crc32 =
1365 crc32(pfile_in_zip_read_info->crc32,bufBefore,
1366 (uInt)(uOutThis));
1367
1368 pfile_in_zip_read_info->rest_read_uncompressed -=
1369 uOutThis;
1370
1371 iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
1372
1373 if (err==Z_STREAM_END)
1374 return (iRead==0) ? UNZ_EOF : iRead;
1375 if (err!=Z_OK)
1376 break;
1377 }
1378 }
1379
1380 if (err==Z_OK)
1381 return iRead;
1382 return err;
1383}
1384
1385
1386/*
1387 Give the current position in uncompressed data
1388*/
1389extern z_off_t ZEXPORT unztell (file)
1390 unzFile file;
1391{
1392 unz_s* s;
1393 file_in_zip_read_info_s* pfile_in_zip_read_info;
1394 if (file==NULL)
1395 return UNZ_PARAMERROR;
1396 s=(unz_s*)file;
1397 pfile_in_zip_read_info=s->pfile_in_zip_read;
1398
1399 if (pfile_in_zip_read_info==NULL)
1400 return UNZ_PARAMERROR;
1401
1402 return (z_off_t)pfile_in_zip_read_info->stream.total_out;
1403}
1404
1405
1406/*
1407 return 1 if the end of file was reached, 0 elsewhere
1408*/
1409extern int ZEXPORT unzeof (file)
1410 unzFile file;
1411{
1412 unz_s* s;
1413 file_in_zip_read_info_s* pfile_in_zip_read_info;
1414 if (file==NULL)
1415 return UNZ_PARAMERROR;
1416 s=(unz_s*)file;
1417 pfile_in_zip_read_info=s->pfile_in_zip_read;
1418
1419 if (pfile_in_zip_read_info==NULL)
1420 return UNZ_PARAMERROR;
1421
1422 if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
1423 return 1;
1424 else
1425 return 0;
1426}
1427
1428
1429
1430/*
1431 Read extra field from the current file (opened by unzOpenCurrentFile)
1432 This is the local-header version of the extra field (sometimes, there is
1433 more info in the local-header version than in the central-header)
1434
1435 if buf==NULL, it return the size of the local extra field that can be read
1436
1437 if buf!=NULL, len is the size of the buffer, the extra header is copied in
1438 buf.
1439 the return value is the number of bytes copied in buf, or (if <0)
1440 the error code
1441*/
1442extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
1443 unzFile file;
1444 voidp buf;
1445 unsigned len;
1446{
1447 unz_s* s;
1448 file_in_zip_read_info_s* pfile_in_zip_read_info;
1449 uInt read_now;
1450 uLong size_to_read;
1451
1452 if (file==NULL)
1453 return UNZ_PARAMERROR;
1454 s=(unz_s*)file;
1455 pfile_in_zip_read_info=s->pfile_in_zip_read;
1456
1457 if (pfile_in_zip_read_info==NULL)
1458 return UNZ_PARAMERROR;
1459
1460 size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
1461 pfile_in_zip_read_info->pos_local_extrafield);
1462
1463 if (buf==NULL)
1464 return (int)size_to_read;
1465
1466 if (len>size_to_read)
1467 read_now = (uInt)size_to_read;
1468 else
1469 read_now = (uInt)len ;
1470
1471 if (read_now==0)
1472 return 0;
1473
1474 if (ZSEEK(pfile_in_zip_read_info->z_filefunc,
1475 pfile_in_zip_read_info->filestream,
1476 pfile_in_zip_read_info->offset_local_extrafield +
1477 pfile_in_zip_read_info->pos_local_extrafield,
1478 ZLIB_FILEFUNC_SEEK_SET)!=0)
1479 return UNZ_ERRNO;
1480
1481 if (ZREAD(pfile_in_zip_read_info->z_filefunc,
1482 pfile_in_zip_read_info->filestream,
1483 buf,read_now)!=read_now)
1484 return UNZ_ERRNO;
1485
1486 return (int)read_now;
1487}
1488
1489/*
1490 Close the file in zip opened with unzipOpenCurrentFile
1491 Return UNZ_CRCERROR if all the file was read but the CRC is not good
1492*/
1493extern int ZEXPORT unzCloseCurrentFile (file)
1494 unzFile file;
1495{
1496 int err=UNZ_OK;
1497
1498 unz_s* s;
1499 file_in_zip_read_info_s* pfile_in_zip_read_info;
1500 if (file==NULL)
1501 return UNZ_PARAMERROR;
1502 s=(unz_s*)file;
1503 pfile_in_zip_read_info=s->pfile_in_zip_read;
1504
1505 if (pfile_in_zip_read_info==NULL)
1506 return UNZ_PARAMERROR;
1507
1508
1509 if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
1510 (!pfile_in_zip_read_info->raw))
1511 {
1512 if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
1513 err=UNZ_CRCERROR;
1514 }
1515
1516
1517 TRYFREE(pfile_in_zip_read_info->read_buffer);
1518 pfile_in_zip_read_info->read_buffer = NULL;
1519 if (pfile_in_zip_read_info->stream_initialised)
1520 inflateEnd(&pfile_in_zip_read_info->stream);
1521
1522 pfile_in_zip_read_info->stream_initialised = 0;
1523 TRYFREE(pfile_in_zip_read_info);
1524
1525 s->pfile_in_zip_read=NULL;
1526
1527 return err;
1528}
1529
1530
1531/*
1532 Get the global comment string of the ZipFile, in the szComment buffer.
1533 uSizeBuf is the size of the szComment buffer.
1534 return the number of byte copied or an error code <0
1535*/
1536extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
1537 unzFile file;
1538 char *szComment;
1539 uLong uSizeBuf;
1540{
1541 unz_s* s;
1542 uLong uReadThis ;
1543 if (file==NULL)
1544 return UNZ_PARAMERROR;
1545 s=(unz_s*)file;
1546
1547 uReadThis = uSizeBuf;
1548 if (uReadThis>s->gi.size_comment)
1549 uReadThis = s->gi.size_comment;
1550
1551 if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
1552 return UNZ_ERRNO;
1553
1554 if (uReadThis>0)
1555 {
1556 *szComment='\0';
1557 if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
1558 return UNZ_ERRNO;
1559 }
1560
1561 if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
1562 *(szComment+s->gi.size_comment)='\0';
1563 return (int)uReadThis;
1564}
1565
1566/* Additions by RX '2004 */
1567extern uLong ZEXPORT unzGetOffset (file)
1568 unzFile file;
1569{
1570 unz_s* s;
1571
1572 if (file==NULL)
1573 return UNZ_PARAMERROR;
1574 s=(unz_s*)file;
1575 if (!s->current_file_ok)
1576 return 0;
1577 if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
1578 if (s->num_file==s->gi.number_entry)
1579 return 0;
1580 return s->pos_in_central_dir;
1581}
1582
1583extern int ZEXPORT unzSetOffset (file, pos)
1584 unzFile file;
1585 uLong pos;
1586{
1587 unz_s* s;
1588 int err;
1589
1590 if (file==NULL)
1591 return UNZ_PARAMERROR;
1592 s=(unz_s*)file;
1593
1594 s->pos_in_central_dir = pos;
1595 s->num_file = s->gi.number_entry; /* hack */
1596 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1597 &s->cur_file_info_internal,
1598 NULL,0,NULL,0,NULL,0);
1599 s->current_file_ok = (err == UNZ_OK);
1600 return err;
1601}
diff --git a/utils/themeeditor/quazip/unzip.h b/utils/themeeditor/quazip/unzip.h
new file mode 100644
index 0000000000..b247937c80
--- /dev/null
+++ b/utils/themeeditor/quazip/unzip.h
@@ -0,0 +1,354 @@
1/* unzip.h -- IO for uncompress .zip files using zlib
2 Version 1.01e, February 12th, 2005
3
4 Copyright (C) 1998-2005 Gilles Vollant
5
6 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
7 WinZip, InfoZip tools and compatible.
8
9 Multi volume ZipFile (span) are not supported.
10 Encryption compatible with pkzip 2.04g only supported
11 Old compressions used by old PKZip 1.x are not supported
12
13
14 I WAIT FEEDBACK at mail info@winimage.com
15 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
16
17 Condition of use and distribution are the same than zlib :
18
19 This software is provided 'as-is', without any express or implied
20 warranty. In no event will the authors be held liable for any damages
21 arising from the use of this software.
22
23 Permission is granted to anyone to use this software for any purpose,
24 including commercial applications, and to alter it and redistribute it
25 freely, subject to the following restrictions:
26
27 1. The origin of this software must not be misrepresented; you must not
28 claim that you wrote the original software. If you use this software
29 in a product, an acknowledgment in the product documentation would be
30 appreciated but is not required.
31 2. Altered source versions must be plainly marked as such, and must not be
32 misrepresented as being the original software.
33 3. This notice may not be removed or altered from any source distribution.
34
35
36*/
37
38/* for more info about .ZIP format, see
39 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
40 http://www.info-zip.org/pub/infozip/doc/
41 PkWare has also a specification at :
42 ftp://ftp.pkware.com/probdesc.zip
43*/
44
45#ifndef _unz_H
46#define _unz_H
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52#ifndef _ZLIB_H
53#include "zlib.h"
54#endif
55
56#ifndef _ZLIBIOAPI_H
57#include "ioapi.h"
58#endif
59
60#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
61/* like the STRICT of WIN32, we define a pointer that cannot be converted
62 from (void*) without cast */
63typedef struct TagunzFile__ { int unused; } unzFile__;
64typedef unzFile__ *unzFile;
65#else
66typedef voidp unzFile;
67#endif
68
69
70#define UNZ_OK (0)
71#define UNZ_END_OF_LIST_OF_FILE (-100)
72#define UNZ_ERRNO (Z_ERRNO)
73#define UNZ_EOF (0)
74#define UNZ_PARAMERROR (-102)
75#define UNZ_BADZIPFILE (-103)
76#define UNZ_INTERNALERROR (-104)
77#define UNZ_CRCERROR (-105)
78
79/* tm_unz contain date/time info */
80typedef struct tm_unz_s
81{
82 uInt tm_sec; /* seconds after the minute - [0,59] */
83 uInt tm_min; /* minutes after the hour - [0,59] */
84 uInt tm_hour; /* hours since midnight - [0,23] */
85 uInt tm_mday; /* day of the month - [1,31] */
86 uInt tm_mon; /* months since January - [0,11] */
87 uInt tm_year; /* years - [1980..2044] */
88} tm_unz;
89
90/* unz_global_info structure contain global data about the ZIPfile
91 These data comes from the end of central dir */
92typedef struct unz_global_info_s
93{
94 uLong number_entry; /* total number of entries in
95 the central dir on this disk */
96 uLong size_comment; /* size of the global comment of the zipfile */
97} unz_global_info;
98
99
100/* unz_file_info contain information about a file in the zipfile */
101typedef struct unz_file_info_s
102{
103 uLong version; /* version made by 2 bytes */
104 uLong version_needed; /* version needed to extract 2 bytes */
105 uLong flag; /* general purpose bit flag 2 bytes */
106 uLong compression_method; /* compression method 2 bytes */
107 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
108 uLong crc; /* crc-32 4 bytes */
109 uLong compressed_size; /* compressed size 4 bytes */
110 uLong uncompressed_size; /* uncompressed size 4 bytes */
111 uLong size_filename; /* filename length 2 bytes */
112 uLong size_file_extra; /* extra field length 2 bytes */
113 uLong size_file_comment; /* file comment length 2 bytes */
114
115 uLong disk_num_start; /* disk number start 2 bytes */
116 uLong internal_fa; /* internal file attributes 2 bytes */
117 uLong external_fa; /* external file attributes 4 bytes */
118
119 tm_unz tmu_date;
120} unz_file_info;
121
122extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
123 const char* fileName2,
124 int iCaseSensitivity));
125/*
126 Compare two filename (fileName1,fileName2).
127 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
128 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
129 or strcasecmp)
130 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
131 (like 1 on Unix, 2 on Windows)
132*/
133
134
135extern unzFile ZEXPORT unzOpen OF((const char *path));
136/*
137 Open a Zip file. path contain the full pathname (by example,
138 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
139 "zlib/zlib113.zip".
140 If the zipfile cannot be opened (file don't exist or in not valid), the
141 return value is NULL.
142 Else, the return value is a unzFile Handle, usable with other function
143 of this unzip package.
144*/
145
146extern unzFile ZEXPORT unzOpen2 OF((const char *path,
147 zlib_filefunc_def* pzlib_filefunc_def));
148/*
149 Open a Zip file, like unzOpen, but provide a set of file low level API
150 for read/write the zip file (see ioapi.h)
151*/
152
153extern int ZEXPORT unzClose OF((unzFile file));
154/*
155 Close a ZipFile opened with unzipOpen.
156 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
157 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
158 return UNZ_OK if there is no problem. */
159
160extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
161 unz_global_info *pglobal_info));
162/*
163 Write info about the ZipFile in the *pglobal_info structure.
164 No preparation of the structure is needed
165 return UNZ_OK if there is no problem. */
166
167
168extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
169 char *szComment,
170 uLong uSizeBuf));
171/*
172 Get the global comment string of the ZipFile, in the szComment buffer.
173 uSizeBuf is the size of the szComment buffer.
174 return the number of byte copied or an error code <0
175*/
176
177
178/***************************************************************************/
179/* Unzip package allow you browse the directory of the zipfile */
180
181extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
182/*
183 Set the current file of the zipfile to the first file.
184 return UNZ_OK if there is no problem
185*/
186
187extern int ZEXPORT unzGoToNextFile OF((unzFile file));
188/*
189 Set the current file of the zipfile to the next file.
190 return UNZ_OK if there is no problem
191 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
192*/
193
194extern int ZEXPORT unzLocateFile OF((unzFile file,
195 const char *szFileName,
196 int iCaseSensitivity));
197/*
198 Try locate the file szFileName in the zipfile.
199 For the iCaseSensitivity signification, see unzStringFileNameCompare
200
201 return value :
202 UNZ_OK if the file is found. It becomes the current file.
203 UNZ_END_OF_LIST_OF_FILE if the file is not found
204*/
205
206
207/* ****************************************** */
208/* Ryan supplied functions */
209/* unz_file_info contain information about a file in the zipfile */
210typedef struct unz_file_pos_s
211{
212 uLong pos_in_zip_directory; /* offset in zip file directory */
213 uLong num_of_file; /* # of file */
214} unz_file_pos;
215
216extern int ZEXPORT unzGetFilePos(
217 unzFile file,
218 unz_file_pos* file_pos);
219
220extern int ZEXPORT unzGoToFilePos(
221 unzFile file,
222 unz_file_pos* file_pos);
223
224/* ****************************************** */
225
226extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
227 unz_file_info *pfile_info,
228 char *szFileName,
229 uLong fileNameBufferSize,
230 void *extraField,
231 uLong extraFieldBufferSize,
232 char *szComment,
233 uLong commentBufferSize));
234/*
235 Get Info about the current file
236 if pfile_info!=NULL, the *pfile_info structure will contain somes info about
237 the current file
238 if szFileName!=NULL, the filemane string will be copied in szFileName
239 (fileNameBufferSize is the size of the buffer)
240 if extraField!=NULL, the extra field information will be copied in extraField
241 (extraFieldBufferSize is the size of the buffer).
242 This is the Central-header version of the extra field
243 if szComment!=NULL, the comment string of the file will be copied in szComment
244 (commentBufferSize is the size of the buffer)
245*/
246
247/***************************************************************************/
248/* for reading the content of the current zipfile, you can open it, read data
249 from it, and close it (you can close it before reading all the file)
250 */
251
252extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
253/*
254 Open for reading data the current file in the zipfile.
255 If there is no error, the return value is UNZ_OK.
256*/
257
258extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
259 const char* password));
260/*
261 Open for reading data the current file in the zipfile.
262 password is a crypting password
263 If there is no error, the return value is UNZ_OK.
264*/
265
266extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
267 int* method,
268 int* level,
269 int raw));
270/*
271 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
272 if raw==1
273 *method will receive method of compression, *level will receive level of
274 compression
275 note : you can set level parameter as NULL (if you did not want known level,
276 but you CANNOT set method parameter as NULL
277*/
278
279extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
280 int* method,
281 int* level,
282 int raw,
283 const char* password));
284/*
285 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
286 if raw==1
287 *method will receive method of compression, *level will receive level of
288 compression
289 note : you can set level parameter as NULL (if you did not want known level,
290 but you CANNOT set method parameter as NULL
291*/
292
293
294extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
295/*
296 Close the file in zip opened with unzOpenCurrentFile
297 Return UNZ_CRCERROR if all the file was read but the CRC is not good
298*/
299
300extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
301 voidp buf,
302 unsigned len));
303/*
304 Read bytes from the current file (opened by unzOpenCurrentFile)
305 buf contain buffer where data must be copied
306 len the size of buf.
307
308 return the number of byte copied if somes bytes are copied
309 return 0 if the end of file was reached
310 return <0 with error code if there is an error
311 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
312*/
313
314extern z_off_t ZEXPORT unztell OF((unzFile file));
315/*
316 Give the current position in uncompressed data
317*/
318
319extern int ZEXPORT unzeof OF((unzFile file));
320/*
321 return 1 if the end of file was reached, 0 elsewhere
322*/
323
324extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
325 voidp buf,
326 unsigned len));
327/*
328 Read extra field from the current file (opened by unzOpenCurrentFile)
329 This is the local-header version of the extra field (sometimes, there is
330 more info in the local-header version than in the central-header)
331
332 if buf==NULL, it return the size of the local extra field
333
334 if buf!=NULL, len is the size of the buffer, the extra header is copied in
335 buf.
336 the return value is the number of bytes copied in buf, or (if <0)
337 the error code
338*/
339
340/***************************************************************************/
341
342/* Get the current file offset */
343extern uLong ZEXPORT unzGetOffset (unzFile file);
344
345/* Set the current file offset */
346extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
347
348
349
350#ifdef __cplusplus
351}
352#endif
353
354#endif /* _unz_H */
diff --git a/utils/themeeditor/quazip/zip.c b/utils/themeeditor/quazip/zip.c
new file mode 100644
index 0000000000..13463fe336
--- /dev/null
+++ b/utils/themeeditor/quazip/zip.c
@@ -0,0 +1,1221 @@
1/* zip.c -- IO on .zip files using zlib
2 Version 1.01e, February 12th, 2005
3
4 27 Dec 2004 Rolf Kalbermatter
5 Modification to zipOpen2 to support globalComment retrieval.
6
7 Copyright (C) 1998-2005 Gilles Vollant
8
9 Read zip.h for more info
10*/
11
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16#include <time.h>
17#include "zlib.h"
18#include "zip.h"
19
20#ifdef STDC
21# include <stddef.h>
22# include <string.h>
23# include <stdlib.h>
24#endif
25#ifdef NO_ERRNO_H
26 extern int errno;
27#else
28# include <errno.h>
29#endif
30
31
32#ifndef local
33# define local static
34#endif
35/* compile with -Dlocal if your debugger can't find static symbols */
36
37#ifndef VERSIONMADEBY
38# define VERSIONMADEBY (0x0) /* platform depedent */
39#endif
40
41#ifndef Z_BUFSIZE
42#define Z_BUFSIZE (16384)
43#endif
44
45#ifndef Z_MAXFILENAMEINZIP
46#define Z_MAXFILENAMEINZIP (256)
47#endif
48
49#ifndef ALLOC
50# define ALLOC(size) (malloc(size))
51#endif
52#ifndef TRYFREE
53# define TRYFREE(p) {if (p) free(p);}
54#endif
55
56/*
57#define SIZECENTRALDIRITEM (0x2e)
58#define SIZEZIPLOCALHEADER (0x1e)
59*/
60
61/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
62
63#ifndef SEEK_CUR
64#define SEEK_CUR 1
65#endif
66
67#ifndef SEEK_END
68#define SEEK_END 2
69#endif
70
71#ifndef SEEK_SET
72#define SEEK_SET 0
73#endif
74
75#ifndef DEF_MEM_LEVEL
76#if MAX_MEM_LEVEL >= 8
77# define DEF_MEM_LEVEL 8
78#else
79# define DEF_MEM_LEVEL MAX_MEM_LEVEL
80#endif
81#endif
82const char zip_copyright[] =
83 " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
84
85
86#define SIZEDATA_INDATABLOCK (4096-(4*4))
87
88#define LOCALHEADERMAGIC (0x04034b50)
89#define CENTRALHEADERMAGIC (0x02014b50)
90#define ENDHEADERMAGIC (0x06054b50)
91
92#define FLAG_LOCALHEADER_OFFSET (0x06)
93#define CRC_LOCALHEADER_OFFSET (0x0e)
94
95#define SIZECENTRALHEADER (0x2e) /* 46 */
96
97typedef struct linkedlist_datablock_internal_s
98{
99 struct linkedlist_datablock_internal_s* next_datablock;
100 uLong avail_in_this_block;
101 uLong filled_in_this_block;
102 uLong unused; /* for future use and alignement */
103 unsigned char data[SIZEDATA_INDATABLOCK];
104} linkedlist_datablock_internal;
105
106typedef struct linkedlist_data_s
107{
108 linkedlist_datablock_internal* first_block;
109 linkedlist_datablock_internal* last_block;
110} linkedlist_data;
111
112
113typedef struct
114{
115 z_stream stream; /* zLib stream structure for inflate */
116 int stream_initialised; /* 1 is stream is initialised */
117 uInt pos_in_buffered_data; /* last written byte in buffered_data */
118
119 uLong pos_local_header; /* offset of the local header of the file
120 currenty writing */
121 char* central_header; /* central header data for the current file */
122 uLong size_centralheader; /* size of the central header for cur file */
123 uLong flag; /* flag of the file currently writing */
124
125 int method; /* compression method of file currenty wr.*/
126 int raw; /* 1 for directly writing raw data */
127 Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
128 uLong dosDate;
129 uLong crc32;
130 int encrypt;
131#ifndef NOCRYPT
132 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
133 const unsigned long* pcrc_32_tab;
134 int crypt_header_size;
135#endif
136} curfile_info;
137
138typedef struct
139{
140 zlib_filefunc_def z_filefunc;
141 voidpf filestream; /* io structore of the zipfile */
142 linkedlist_data central_dir;/* datablock with central dir in construction*/
143 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
144 curfile_info ci; /* info on the file curretly writing */
145
146 uLong begin_pos; /* position of the beginning of the zipfile */
147 uLong add_position_when_writting_offset;
148 uLong number_entry;
149#ifndef NO_ADDFILEINEXISTINGZIP
150 char *globalcomment;
151#endif
152} zip_internal;
153
154
155
156#ifndef NOCRYPT
157#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
158#include "crypt.h"
159#endif
160
161local linkedlist_datablock_internal* allocate_new_datablock()
162{
163 linkedlist_datablock_internal* ldi;
164 ldi = (linkedlist_datablock_internal*)
165 ALLOC(sizeof(linkedlist_datablock_internal));
166 if (ldi!=NULL)
167 {
168 ldi->next_datablock = NULL ;
169 ldi->filled_in_this_block = 0 ;
170 ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;
171 }
172 return ldi;
173}
174
175local void free_datablock(ldi)
176 linkedlist_datablock_internal* ldi;
177{
178 while (ldi!=NULL)
179 {
180 linkedlist_datablock_internal* ldinext = ldi->next_datablock;
181 TRYFREE(ldi);
182 ldi = ldinext;
183 }
184}
185
186local void init_linkedlist(ll)
187 linkedlist_data* ll;
188{
189 ll->first_block = ll->last_block = NULL;
190}
191
192#if 0 // unused
193local void free_linkedlist(ll)
194 linkedlist_data* ll;
195{
196 free_datablock(ll->first_block);
197 ll->first_block = ll->last_block = NULL;
198}
199#endif
200
201local int add_data_in_datablock(ll,buf,len)
202 linkedlist_data* ll;
203 const void* buf;
204 uLong len;
205{
206 linkedlist_datablock_internal* ldi;
207 const unsigned char* from_copy;
208
209 if (ll==NULL)
210 return ZIP_INTERNALERROR;
211
212 if (ll->last_block == NULL)
213 {
214 ll->first_block = ll->last_block = allocate_new_datablock();
215 if (ll->first_block == NULL)
216 return ZIP_INTERNALERROR;
217 }
218
219 ldi = ll->last_block;
220 from_copy = (unsigned char*)buf;
221
222 while (len>0)
223 {
224 uInt copy_this;
225 uInt i;
226 unsigned char* to_copy;
227
228 if (ldi->avail_in_this_block==0)
229 {
230 ldi->next_datablock = allocate_new_datablock();
231 if (ldi->next_datablock == NULL)
232 return ZIP_INTERNALERROR;
233 ldi = ldi->next_datablock ;
234 ll->last_block = ldi;
235 }
236
237 if (ldi->avail_in_this_block < len)
238 copy_this = (uInt)ldi->avail_in_this_block;
239 else
240 copy_this = (uInt)len;
241
242 to_copy = &(ldi->data[ldi->filled_in_this_block]);
243
244 for (i=0;i<copy_this;i++)
245 *(to_copy+i)=*(from_copy+i);
246
247 ldi->filled_in_this_block += copy_this;
248 ldi->avail_in_this_block -= copy_this;
249 from_copy += copy_this ;
250 len -= copy_this;
251 }
252 return ZIP_OK;
253}
254
255
256
257/****************************************************************************/
258
259#ifndef NO_ADDFILEINEXISTINGZIP
260/* ===========================================================================
261 Inputs a long in LSB order to the given file
262 nbByte == 1, 2 or 4 (byte, short or long)
263*/
264
265local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def,
266 voidpf filestream, uLong x, int nbByte));
267local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte)
268 const zlib_filefunc_def* pzlib_filefunc_def;
269 voidpf filestream;
270 uLong x;
271 int nbByte;
272{
273 unsigned char buf[4];
274 int n;
275 for (n = 0; n < nbByte; n++)
276 {
277 buf[n] = (unsigned char)(x & 0xff);
278 x >>= 8;
279 }
280 if (x != 0)
281 { /* data overflow - hack for ZIP64 (X Roche) */
282 for (n = 0; n < nbByte; n++)
283 {
284 buf[n] = 0xff;
285 }
286 }
287
288 if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
289 return ZIP_ERRNO;
290 else
291 return ZIP_OK;
292}
293
294local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte));
295local void ziplocal_putValue_inmemory (dest, x, nbByte)
296 void* dest;
297 uLong x;
298 int nbByte;
299{
300 unsigned char* buf=(unsigned char*)dest;
301 int n;
302 for (n = 0; n < nbByte; n++) {
303 buf[n] = (unsigned char)(x & 0xff);
304 x >>= 8;
305 }
306
307 if (x != 0)
308 { /* data overflow - hack for ZIP64 */
309 for (n = 0; n < nbByte; n++)
310 {
311 buf[n] = 0xff;
312 }
313 }
314}
315
316/****************************************************************************/
317
318
319local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)
320 const tm_zip* ptm;
321 uLong dosDate;
322{
323 (void) dosDate; /* avoid "unused parameter" warning */
324 uLong year = (uLong)ptm->tm_year;
325 if (year>1980)
326 year-=1980;
327 else if (year>80)
328 year-=80;
329 return
330 (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
331 ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
332}
333
334
335/****************************************************************************/
336
337local int ziplocal_getByte OF((
338 const zlib_filefunc_def* pzlib_filefunc_def,
339 voidpf filestream,
340 int *pi));
341
342local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi)
343 const zlib_filefunc_def* pzlib_filefunc_def;
344 voidpf filestream;
345 int *pi;
346{
347 unsigned char c;
348 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1);
349 if (err==1)
350 {
351 *pi = (int)c;
352 return ZIP_OK;
353 }
354 else
355 {
356 if (ZERROR(*pzlib_filefunc_def,filestream))
357 return ZIP_ERRNO;
358 else
359 return ZIP_EOF;
360 }
361}
362
363
364/* ===========================================================================
365 Reads a long in LSB order from the given gz_stream. Sets
366*/
367local int ziplocal_getShort OF((
368 const zlib_filefunc_def* pzlib_filefunc_def,
369 voidpf filestream,
370 uLong *pX));
371
372local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX)
373 const zlib_filefunc_def* pzlib_filefunc_def;
374 voidpf filestream;
375 uLong *pX;
376{
377 uLong x ;
378 int i;
379 int err;
380
381 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
382 x = (uLong)i;
383
384 if (err==ZIP_OK)
385 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
386 x += ((uLong)i)<<8;
387
388 if (err==ZIP_OK)
389 *pX = x;
390 else
391 *pX = 0;
392 return err;
393}
394
395local int ziplocal_getLong OF((
396 const zlib_filefunc_def* pzlib_filefunc_def,
397 voidpf filestream,
398 uLong *pX));
399
400local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX)
401 const zlib_filefunc_def* pzlib_filefunc_def;
402 voidpf filestream;
403 uLong *pX;
404{
405 uLong x ;
406 int i;
407 int err;
408
409 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
410 x = (uLong)i;
411
412 if (err==ZIP_OK)
413 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
414 x += ((uLong)i)<<8;
415
416 if (err==ZIP_OK)
417 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
418 x += ((uLong)i)<<16;
419
420 if (err==ZIP_OK)
421 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
422 x += ((uLong)i)<<24;
423
424 if (err==ZIP_OK)
425 *pX = x;
426 else
427 *pX = 0;
428 return err;
429}
430
431#ifndef BUFREADCOMMENT
432#define BUFREADCOMMENT (0x400)
433#endif
434/*
435 Locate the Central directory of a zipfile (at the end, just before
436 the global comment)
437*/
438local uLong ziplocal_SearchCentralDir OF((
439 const zlib_filefunc_def* pzlib_filefunc_def,
440 voidpf filestream));
441
442local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream)
443 const zlib_filefunc_def* pzlib_filefunc_def;
444 voidpf filestream;
445{
446 unsigned char* buf;
447 uLong uSizeFile;
448 uLong uBackRead;
449 uLong uMaxBack=0xffff; /* maximum size of global comment */
450 uLong uPosFound=0;
451
452 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
453 return 0;
454
455
456 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
457
458 if (uMaxBack>uSizeFile)
459 uMaxBack = uSizeFile;
460
461 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
462 if (buf==NULL)
463 return 0;
464
465 uBackRead = 4;
466 while (uBackRead<uMaxBack)
467 {
468 uLong uReadSize,uReadPos ;
469 int i;
470 if (uBackRead+BUFREADCOMMENT>uMaxBack)
471 uBackRead = uMaxBack;
472 else
473 uBackRead+=BUFREADCOMMENT;
474 uReadPos = uSizeFile-uBackRead ;
475
476 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
477 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
478 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
479 break;
480
481 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
482 break;
483
484 for (i=(int)uReadSize-3; (i--)>0;)
485 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
486 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
487 {
488 uPosFound = uReadPos+i;
489 break;
490 }
491
492 if (uPosFound!=0)
493 break;
494 }
495 TRYFREE(buf);
496 return uPosFound;
497}
498#endif /* !NO_ADDFILEINEXISTINGZIP*/
499
500/************************************************************/
501extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def)
502 const char *pathname;
503 int append;
504 zipcharpc* globalcomment;
505 zlib_filefunc_def* pzlib_filefunc_def;
506{
507 zip_internal ziinit;
508 zip_internal* zi;
509 int err=ZIP_OK;
510
511
512 if (pzlib_filefunc_def==NULL)
513 fill_fopen_filefunc(&ziinit.z_filefunc);
514 else
515 ziinit.z_filefunc = *pzlib_filefunc_def;
516
517 ziinit.filestream = (*(ziinit.z_filefunc.zopen_file))
518 (ziinit.z_filefunc.opaque,
519 pathname,
520 (append == APPEND_STATUS_CREATE) ?
521 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
522 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
523
524 if (ziinit.filestream == NULL)
525 return NULL;
526 ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream);
527 ziinit.in_opened_file_inzip = 0;
528 ziinit.ci.stream_initialised = 0;
529 ziinit.number_entry = 0;
530 ziinit.add_position_when_writting_offset = 0;
531 init_linkedlist(&(ziinit.central_dir));
532
533
534 zi = (zip_internal*)ALLOC(sizeof(zip_internal));
535 if (zi==NULL)
536 {
537 ZCLOSE(ziinit.z_filefunc,ziinit.filestream);
538 return NULL;
539 }
540
541 /* now we add file in a zipfile */
542# ifndef NO_ADDFILEINEXISTINGZIP
543 ziinit.globalcomment = NULL;
544 if (append == APPEND_STATUS_ADDINZIP)
545 {
546 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
547
548 uLong size_central_dir; /* size of the central directory */
549 uLong offset_central_dir; /* offset of start of central directory */
550 uLong central_pos,uL;
551
552 uLong number_disk; /* number of the current dist, used for
553 spaning ZIP, unsupported, always 0*/
554 uLong number_disk_with_CD; /* number the the disk with central dir, used
555 for spaning ZIP, unsupported, always 0*/
556 uLong number_entry;
557 uLong number_entry_CD; /* total number of entries in
558 the central dir
559 (same than number_entry on nospan) */
560 uLong size_comment;
561
562 central_pos = ziplocal_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream);
563 if (central_pos==0)
564 err=ZIP_ERRNO;
565
566 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
567 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
568 err=ZIP_ERRNO;
569
570 /* the signature, already checked */
571 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&uL)!=ZIP_OK)
572 err=ZIP_ERRNO;
573
574 /* number of this disk */
575 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk)!=ZIP_OK)
576 err=ZIP_ERRNO;
577
578 /* number of the disk with the start of the central directory */
579 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk_with_CD)!=ZIP_OK)
580 err=ZIP_ERRNO;
581
582 /* total number of entries in the central dir on this disk */
583 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry)!=ZIP_OK)
584 err=ZIP_ERRNO;
585
586 /* total number of entries in the central dir */
587 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry_CD)!=ZIP_OK)
588 err=ZIP_ERRNO;
589
590 if ((number_entry_CD!=number_entry) ||
591 (number_disk_with_CD!=0) ||
592 (number_disk!=0))
593 err=ZIP_BADZIPFILE;
594
595 /* size of the central directory */
596 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&size_central_dir)!=ZIP_OK)
597 err=ZIP_ERRNO;
598
599 /* offset of start of central directory with respect to the
600 starting disk number */
601 if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK)
602 err=ZIP_ERRNO;
603
604 /* zipfile global comment length */
605 if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK)
606 err=ZIP_ERRNO;
607
608 if ((central_pos<offset_central_dir+size_central_dir) &&
609 (err==ZIP_OK))
610 err=ZIP_BADZIPFILE;
611
612 if (err!=ZIP_OK)
613 {
614 ZCLOSE(ziinit.z_filefunc, ziinit.filestream);
615 return NULL;
616 }
617
618 if (size_comment>0)
619 {
620 ziinit.globalcomment = ALLOC(size_comment+1);
621 if (ziinit.globalcomment)
622 {
623 size_comment = ZREAD(ziinit.z_filefunc, ziinit.filestream,ziinit.globalcomment,size_comment);
624 ziinit.globalcomment[size_comment]=0;
625 }
626 }
627
628 byte_before_the_zipfile = central_pos -
629 (offset_central_dir+size_central_dir);
630 ziinit.add_position_when_writting_offset = byte_before_the_zipfile;
631
632 {
633 uLong size_central_dir_to_read = size_central_dir;
634 size_t buf_size = SIZEDATA_INDATABLOCK;
635 void* buf_read = (void*)ALLOC(buf_size);
636 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
637 offset_central_dir + byte_before_the_zipfile,
638 ZLIB_FILEFUNC_SEEK_SET) != 0)
639 err=ZIP_ERRNO;
640
641 while ((size_central_dir_to_read>0) && (err==ZIP_OK))
642 {
643 uLong read_this = SIZEDATA_INDATABLOCK;
644 if (read_this > size_central_dir_to_read)
645 read_this = size_central_dir_to_read;
646 if (ZREAD(ziinit.z_filefunc, ziinit.filestream,buf_read,read_this) != read_this)
647 err=ZIP_ERRNO;
648
649 if (err==ZIP_OK)
650 err = add_data_in_datablock(&ziinit.central_dir,buf_read,
651 (uLong)read_this);
652 size_central_dir_to_read-=read_this;
653 }
654 TRYFREE(buf_read);
655 }
656 ziinit.begin_pos = byte_before_the_zipfile;
657 ziinit.number_entry = number_entry_CD;
658
659 if (ZSEEK(ziinit.z_filefunc, ziinit.filestream,
660 offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
661 err=ZIP_ERRNO;
662 }
663
664 if (globalcomment)
665 {
666 *globalcomment = ziinit.globalcomment;
667 }
668# endif /* !NO_ADDFILEINEXISTINGZIP*/
669
670 if (err != ZIP_OK)
671 {
672# ifndef NO_ADDFILEINEXISTINGZIP
673 TRYFREE(ziinit.globalcomment);
674# endif /* !NO_ADDFILEINEXISTINGZIP*/
675 TRYFREE(zi);
676 return NULL;
677 }
678 else
679 {
680 *zi = ziinit;
681 return (zipFile)zi;
682 }
683}
684
685extern zipFile ZEXPORT zipOpen (pathname, append)
686 const char *pathname;
687 int append;
688{
689 return zipOpen2(pathname,append,NULL,NULL);
690}
691
692extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
693 extrafield_local, size_extrafield_local,
694 extrafield_global, size_extrafield_global,
695 comment, method, level, raw,
696 windowBits, memLevel, strategy,
697 password, crcForCrypting)
698 zipFile file;
699 const char* filename;
700 const zip_fileinfo* zipfi;
701 const void* extrafield_local;
702 uInt size_extrafield_local;
703 const void* extrafield_global;
704 uInt size_extrafield_global;
705 const char* comment;
706 int method;
707 int level;
708 int raw;
709 int windowBits;
710 int memLevel;
711 int strategy;
712 const char* password;
713 uLong crcForCrypting;
714{
715 zip_internal* zi;
716 uInt size_filename;
717 uInt size_comment;
718 uInt i;
719 int err = ZIP_OK;
720
721# ifdef NOCRYPT
722 if (password != NULL)
723 return ZIP_PARAMERROR;
724# endif
725
726 if (file == NULL)
727 return ZIP_PARAMERROR;
728 if ((method!=0) && (method!=Z_DEFLATED))
729 return ZIP_PARAMERROR;
730
731 zi = (zip_internal*)file;
732
733 if (zi->in_opened_file_inzip == 1)
734 {
735 err = zipCloseFileInZip (file);
736 if (err != ZIP_OK)
737 return err;
738 }
739
740
741 if (filename==NULL)
742 filename="-";
743
744 if (comment==NULL)
745 size_comment = 0;
746 else
747 size_comment = (uInt)strlen(comment);
748
749 size_filename = (uInt)strlen(filename);
750
751 if (zipfi == NULL)
752 zi->ci.dosDate = 0;
753 else
754 {
755 if (zipfi->dosDate != 0)
756 zi->ci.dosDate = zipfi->dosDate;
757 else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate);
758 }
759
760 zi->ci.flag = 0;
761 if ((level==8) || (level==9))
762 zi->ci.flag |= 2;
763 if ((level==2))
764 zi->ci.flag |= 4;
765 if ((level==1))
766 zi->ci.flag |= 6;
767 if (password != NULL)
768 zi->ci.flag |= 1;
769
770 zi->ci.crc32 = 0;
771 zi->ci.method = method;
772 zi->ci.encrypt = 0;
773 zi->ci.stream_initialised = 0;
774 zi->ci.pos_in_buffered_data = 0;
775 zi->ci.raw = raw;
776 zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ;
777 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename +
778 size_extrafield_global + size_comment;
779 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader);
780
781 ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
782 /* version info */
783 ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2);
784 ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);
785 ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
786 ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
787 ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
788 ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
789 ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
790 ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
791 ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
792 ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
793 ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
794 ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
795
796 if (zipfi==NULL)
797 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
798 else
799 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
800
801 if (zipfi==NULL)
802 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
803 else
804 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
805
806 ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4);
807
808 for (i=0;i<size_filename;i++)
809 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
810
811 for (i=0;i<size_extrafield_global;i++)
812 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =
813 *(((const char*)extrafield_global)+i);
814
815 for (i=0;i<size_comment;i++)
816 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
817 size_extrafield_global+i) = *(comment+i);
818 if (zi->ci.central_header == NULL)
819 return ZIP_INTERNALERROR;
820
821 /* write the local header */
822 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4);
823
824 if (err==ZIP_OK)
825 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */
826 if (err==ZIP_OK)
827 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
828
829 if (err==ZIP_OK)
830 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
831
832 if (err==ZIP_OK)
833 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
834
835 if (err==ZIP_OK)
836 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
837 if (err==ZIP_OK)
838 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
839 if (err==ZIP_OK)
840 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
841
842 if (err==ZIP_OK)
843 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
844
845 if (err==ZIP_OK)
846 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2);
847
848 if ((err==ZIP_OK) && (size_filename>0))
849 if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
850 err = ZIP_ERRNO;
851
852 if ((err==ZIP_OK) && (size_extrafield_local>0))
853 if (ZWRITE(zi->z_filefunc,zi->filestream,extrafield_local,size_extrafield_local)
854 !=size_extrafield_local)
855 err = ZIP_ERRNO;
856
857 zi->ci.stream.avail_in = (uInt)0;
858 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
859 zi->ci.stream.next_out = zi->ci.buffered_data;
860 zi->ci.stream.total_in = 0;
861 zi->ci.stream.total_out = 0;
862
863 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
864 {
865 zi->ci.stream.zalloc = (alloc_func)0;
866 zi->ci.stream.zfree = (free_func)0;
867 zi->ci.stream.opaque = (voidpf)0;
868
869 if (windowBits>0)
870 windowBits = -windowBits;
871
872 err = deflateInit2(&zi->ci.stream, level,
873 Z_DEFLATED, windowBits, memLevel, strategy);
874
875 if (err==Z_OK)
876 zi->ci.stream_initialised = 1;
877 }
878# ifndef NOCRYPT
879 zi->ci.crypt_header_size = 0;
880 if ((err==Z_OK) && (password != NULL))
881 {
882 unsigned char bufHead[RAND_HEAD_LEN];
883 unsigned int sizeHead;
884 zi->ci.encrypt = 1;
885 zi->ci.pcrc_32_tab = get_crc_table();
886 /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
887
888 sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
889 zi->ci.crypt_header_size = sizeHead;
890
891 if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
892 err = ZIP_ERRNO;
893 }
894# endif
895
896 if (err==Z_OK)
897 zi->in_opened_file_inzip = 1;
898 return err;
899}
900
901extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi,
902 extrafield_local, size_extrafield_local,
903 extrafield_global, size_extrafield_global,
904 comment, method, level, raw)
905 zipFile file;
906 const char* filename;
907 const zip_fileinfo* zipfi;
908 const void* extrafield_local;
909 uInt size_extrafield_local;
910 const void* extrafield_global;
911 uInt size_extrafield_global;
912 const char* comment;
913 int method;
914 int level;
915 int raw;
916{
917 return zipOpenNewFileInZip3 (file, filename, zipfi,
918 extrafield_local, size_extrafield_local,
919 extrafield_global, size_extrafield_global,
920 comment, method, level, raw,
921 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
922 NULL, 0);
923}
924
925extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
926 extrafield_local, size_extrafield_local,
927 extrafield_global, size_extrafield_global,
928 comment, method, level)
929 zipFile file;
930 const char* filename;
931 const zip_fileinfo* zipfi;
932 const void* extrafield_local;
933 uInt size_extrafield_local;
934 const void* extrafield_global;
935 uInt size_extrafield_global;
936 const char* comment;
937 int method;
938 int level;
939{
940 return zipOpenNewFileInZip2 (file, filename, zipfi,
941 extrafield_local, size_extrafield_local,
942 extrafield_global, size_extrafield_global,
943 comment, method, level, 0);
944}
945
946local int zipFlushWriteBuffer(zi)
947 zip_internal* zi;
948{
949 int err=ZIP_OK;
950
951 if (zi->ci.encrypt != 0)
952 {
953#ifndef NOCRYPT
954 uInt i;
955 int t;
956 for (i=0;i<zi->ci.pos_in_buffered_data;i++)
957 zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab,
958 zi->ci.buffered_data[i],t);
959#endif
960 }
961 if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data)
962 !=zi->ci.pos_in_buffered_data)
963 err = ZIP_ERRNO;
964 zi->ci.pos_in_buffered_data = 0;
965 return err;
966}
967
968extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
969 zipFile file;
970 const void* buf;
971 unsigned len;
972{
973 zip_internal* zi;
974 int err=ZIP_OK;
975
976 if (file == NULL)
977 return ZIP_PARAMERROR;
978 zi = (zip_internal*)file;
979
980 if (zi->in_opened_file_inzip == 0)
981 return ZIP_PARAMERROR;
982
983 zi->ci.stream.next_in = (void*)buf;
984 zi->ci.stream.avail_in = len;
985 zi->ci.crc32 = crc32(zi->ci.crc32,buf,len);
986
987 while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
988 {
989 if (zi->ci.stream.avail_out == 0)
990 {
991 if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)
992 err = ZIP_ERRNO;
993 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
994 zi->ci.stream.next_out = zi->ci.buffered_data;
995 }
996
997
998 if(err != ZIP_OK)
999 break;
1000
1001 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1002 {
1003 uLong uTotalOutBefore = zi->ci.stream.total_out;
1004 err=deflate(&zi->ci.stream, Z_NO_FLUSH);
1005 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
1006
1007 }
1008 else
1009 {
1010 uInt copy_this,i;
1011 if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
1012 copy_this = zi->ci.stream.avail_in;
1013 else
1014 copy_this = zi->ci.stream.avail_out;
1015 for (i=0;i<copy_this;i++)
1016 *(((char*)zi->ci.stream.next_out)+i) =
1017 *(((const char*)zi->ci.stream.next_in)+i);
1018 {
1019 zi->ci.stream.avail_in -= copy_this;
1020 zi->ci.stream.avail_out-= copy_this;
1021 zi->ci.stream.next_in+= copy_this;
1022 zi->ci.stream.next_out+= copy_this;
1023 zi->ci.stream.total_in+= copy_this;
1024 zi->ci.stream.total_out+= copy_this;
1025 zi->ci.pos_in_buffered_data += copy_this;
1026 }
1027 }
1028 }
1029
1030 return err;
1031}
1032
1033extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32)
1034 zipFile file;
1035 uLong uncompressed_size;
1036 uLong crc32;
1037{
1038 zip_internal* zi;
1039 uLong compressed_size;
1040 int err=ZIP_OK;
1041
1042 if (file == NULL)
1043 return ZIP_PARAMERROR;
1044 zi = (zip_internal*)file;
1045
1046 if (zi->in_opened_file_inzip == 0)
1047 return ZIP_PARAMERROR;
1048 zi->ci.stream.avail_in = 0;
1049
1050 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1051 while (err==ZIP_OK)
1052 {
1053 uLong uTotalOutBefore;
1054 if (zi->ci.stream.avail_out == 0)
1055 {
1056 if (zipFlushWriteBuffer(zi) == ZIP_ERRNO)
1057 err = ZIP_ERRNO;
1058 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1059 zi->ci.stream.next_out = zi->ci.buffered_data;
1060 }
1061 uTotalOutBefore = zi->ci.stream.total_out;
1062 err=deflate(&zi->ci.stream, Z_FINISH);
1063 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
1064 }
1065
1066 if (err==Z_STREAM_END)
1067 err=ZIP_OK; /* this is normal */
1068
1069 if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
1070 if (zipFlushWriteBuffer(zi)==ZIP_ERRNO)
1071 err = ZIP_ERRNO;
1072
1073 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1074 {
1075 err=deflateEnd(&zi->ci.stream);
1076 zi->ci.stream_initialised = 0;
1077 }
1078
1079 if (!zi->ci.raw)
1080 {
1081 crc32 = (uLong)zi->ci.crc32;
1082 uncompressed_size = (uLong)zi->ci.stream.total_in;
1083 }
1084 compressed_size = (uLong)zi->ci.stream.total_out;
1085# ifndef NOCRYPT
1086 compressed_size += zi->ci.crypt_header_size;
1087# endif
1088
1089 ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
1090 ziplocal_putValue_inmemory(zi->ci.central_header+20,
1091 compressed_size,4); /*compr size*/
1092 if (zi->ci.stream.data_type == Z_ASCII)
1093 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
1094 ziplocal_putValue_inmemory(zi->ci.central_header+24,
1095 uncompressed_size,4); /*uncompr size*/
1096
1097 if (err==ZIP_OK)
1098 err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header,
1099 (uLong)zi->ci.size_centralheader);
1100 free(zi->ci.central_header);
1101
1102 if (err==ZIP_OK)
1103 {
1104 long cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);
1105 if (ZSEEK(zi->z_filefunc,zi->filestream,
1106 zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
1107 err = ZIP_ERRNO;
1108
1109 if (err==ZIP_OK)
1110 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
1111
1112 if (err==ZIP_OK) /* compressed size, unknown */
1113 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
1114
1115 if (err==ZIP_OK) /* uncompressed size, unknown */
1116 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
1117
1118 if (ZSEEK(zi->z_filefunc,zi->filestream,
1119 cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
1120 err = ZIP_ERRNO;
1121 }
1122
1123 zi->number_entry ++;
1124 zi->in_opened_file_inzip = 0;
1125
1126 return err;
1127}
1128
1129extern int ZEXPORT zipCloseFileInZip (file)
1130 zipFile file;
1131{
1132 return zipCloseFileInZipRaw (file,0,0);
1133}
1134
1135extern int ZEXPORT zipClose (file, global_comment)
1136 zipFile file;
1137 const char* global_comment;
1138{
1139 zip_internal* zi;
1140 int err = 0;
1141 uLong size_centraldir = 0;
1142 uLong centraldir_pos_inzip;
1143 uInt size_global_comment;
1144 if (file == NULL)
1145 return ZIP_PARAMERROR;
1146 zi = (zip_internal*)file;
1147
1148 if (zi->in_opened_file_inzip == 1)
1149 {
1150 err = zipCloseFileInZip (file);
1151 }
1152
1153#ifndef NO_ADDFILEINEXISTINGZIP
1154 if (global_comment==NULL)
1155 global_comment = zi->globalcomment;
1156#endif
1157 if (global_comment==NULL)
1158 size_global_comment = 0;
1159 else
1160 size_global_comment = (uInt)strlen(global_comment);
1161
1162 centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);
1163 if (err==ZIP_OK)
1164 {
1165 linkedlist_datablock_internal* ldi = zi->central_dir.first_block ;
1166 while (ldi!=NULL)
1167 {
1168 if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
1169 if (ZWRITE(zi->z_filefunc,zi->filestream,
1170 ldi->data,ldi->filled_in_this_block)
1171 !=ldi->filled_in_this_block )
1172 err = ZIP_ERRNO;
1173
1174 size_centraldir += ldi->filled_in_this_block;
1175 ldi = ldi->next_datablock;
1176 }
1177 }
1178 free_datablock(zi->central_dir.first_block);
1179
1180 if (err==ZIP_OK) /* Magic End */
1181 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
1182
1183 if (err==ZIP_OK) /* number of this disk */
1184 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
1185
1186 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1187 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
1188
1189 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
1190 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
1191
1192 if (err==ZIP_OK) /* total number of entries in the central dir */
1193 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
1194
1195 if (err==ZIP_OK) /* size of the central directory */
1196 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
1197
1198 if (err==ZIP_OK) /* offset of start of central directory with respect to the
1199 starting disk number */
1200 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,
1201 (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);
1202
1203 if (err==ZIP_OK) /* zipfile comment length */
1204 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
1205
1206 if ((err==ZIP_OK) && (size_global_comment>0))
1207 if (ZWRITE(zi->z_filefunc,zi->filestream,
1208 global_comment,size_global_comment) != size_global_comment)
1209 err = ZIP_ERRNO;
1210
1211 if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0)
1212 if (err == ZIP_OK)
1213 err = ZIP_ERRNO;
1214
1215#ifndef NO_ADDFILEINEXISTINGZIP
1216 TRYFREE(zi->globalcomment);
1217#endif
1218 TRYFREE(zi);
1219
1220 return err;
1221}
diff --git a/utils/themeeditor/quazip/zip.h b/utils/themeeditor/quazip/zip.h
new file mode 100644
index 0000000000..acacce83b9
--- /dev/null
+++ b/utils/themeeditor/quazip/zip.h
@@ -0,0 +1,235 @@
1/* zip.h -- IO for compress .zip files using zlib
2 Version 1.01e, February 12th, 2005
3
4 Copyright (C) 1998-2005 Gilles Vollant
5
6 This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
7 WinZip, InfoZip tools and compatible.
8 Multi volume ZipFile (span) are not supported.
9 Encryption compatible with pkzip 2.04g only supported
10 Old compressions used by old PKZip 1.x are not supported
11
12 For uncompress .zip file, look at unzip.h
13
14
15 I WAIT FEEDBACK at mail info@winimage.com
16 Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
17
18 Condition of use and distribution are the same than zlib :
19
20 This software is provided 'as-is', without any express or implied
21 warranty. In no event will the authors be held liable for any damages
22 arising from the use of this software.
23
24 Permission is granted to anyone to use this software for any purpose,
25 including commercial applications, and to alter it and redistribute it
26 freely, subject to the following restrictions:
27
28 1. The origin of this software must not be misrepresented; you must not
29 claim that you wrote the original software. If you use this software
30 in a product, an acknowledgment in the product documentation would be
31 appreciated but is not required.
32 2. Altered source versions must be plainly marked as such, and must not be
33 misrepresented as being the original software.
34 3. This notice may not be removed or altered from any source distribution.
35
36
37*/
38
39/* for more info about .ZIP format, see
40 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
41 http://www.info-zip.org/pub/infozip/doc/
42 PkWare has also a specification at :
43 ftp://ftp.pkware.com/probdesc.zip
44*/
45
46#ifndef _zip_H
47#define _zip_H
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53#ifndef _ZLIB_H
54#include "zlib.h"
55#endif
56
57#ifndef _ZLIBIOAPI_H
58#include "ioapi.h"
59#endif
60
61#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
62/* like the STRICT of WIN32, we define a pointer that cannot be converted
63 from (void*) without cast */
64typedef struct TagzipFile__ { int unused; } zipFile__;
65typedef zipFile__ *zipFile;
66#else
67typedef voidp zipFile;
68#endif
69
70#define ZIP_OK (0)
71#define ZIP_EOF (0)
72#define ZIP_ERRNO (Z_ERRNO)
73#define ZIP_PARAMERROR (-102)
74#define ZIP_BADZIPFILE (-103)
75#define ZIP_INTERNALERROR (-104)
76
77#ifndef DEF_MEM_LEVEL
78# if MAX_MEM_LEVEL >= 8
79# define DEF_MEM_LEVEL 8
80# else
81# define DEF_MEM_LEVEL MAX_MEM_LEVEL
82# endif
83#endif
84/* default memLevel */
85
86/* tm_zip contain date/time info */
87typedef struct tm_zip_s
88{
89 uInt tm_sec; /* seconds after the minute - [0,59] */
90 uInt tm_min; /* minutes after the hour - [0,59] */
91 uInt tm_hour; /* hours since midnight - [0,23] */
92 uInt tm_mday; /* day of the month - [1,31] */
93 uInt tm_mon; /* months since January - [0,11] */
94 uInt tm_year; /* years - [1980..2044] */
95} tm_zip;
96
97typedef struct
98{
99 tm_zip tmz_date; /* date in understandable format */
100 uLong dosDate; /* if dos_date == 0, tmu_date is used */
101/* uLong flag; */ /* general purpose bit flag 2 bytes */
102
103 uLong internal_fa; /* internal file attributes 2 bytes */
104 uLong external_fa; /* external file attributes 4 bytes */
105} zip_fileinfo;
106
107typedef const char* zipcharpc;
108
109
110#define APPEND_STATUS_CREATE (0)
111#define APPEND_STATUS_CREATEAFTER (1)
112#define APPEND_STATUS_ADDINZIP (2)
113
114extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
115/*
116 Create a zipfile.
117 pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
118 an Unix computer "zlib/zlib113.zip".
119 if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
120 will be created at the end of the file.
121 (useful if the file contain a self extractor code)
122 if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
123 add files in existing zip (be sure you don't add file that doesn't exist)
124 If the zipfile cannot be opened, the return value is NULL.
125 Else, the return value is a zipFile Handle, usable with other function
126 of this zip package.
127*/
128
129/* Note : there is no delete function into a zipfile.
130 If you want delete file into a zipfile, you must open a zipfile, and create another
131 Of couse, you can use RAW reading and writing to copy the file you did not want delte
132*/
133
134extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
135 int append,
136 zipcharpc* globalcomment,
137 zlib_filefunc_def* pzlib_filefunc_def));
138
139extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
140 const char* filename,
141 const zip_fileinfo* zipfi,
142 const void* extrafield_local,
143 uInt size_extrafield_local,
144 const void* extrafield_global,
145 uInt size_extrafield_global,
146 const char* comment,
147 int method,
148 int level));
149/*
150 Open a file in the ZIP for writing.
151 filename : the filename in zip (if NULL, '-' without quote will be used
152 *zipfi contain supplemental information
153 if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
154 contains the extrafield data the the local header
155 if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
156 contains the extrafield data the the local header
157 if comment != NULL, comment contain the comment string
158 method contain the compression method (0 for store, Z_DEFLATED for deflate)
159 level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
160*/
161
162
163extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
164 const char* filename,
165 const zip_fileinfo* zipfi,
166 const void* extrafield_local,
167 uInt size_extrafield_local,
168 const void* extrafield_global,
169 uInt size_extrafield_global,
170 const char* comment,
171 int method,
172 int level,
173 int raw));
174
175/*
176 Same than zipOpenNewFileInZip, except if raw=1, we write raw file
177 */
178
179extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
180 const char* filename,
181 const zip_fileinfo* zipfi,
182 const void* extrafield_local,
183 uInt size_extrafield_local,
184 const void* extrafield_global,
185 uInt size_extrafield_global,
186 const char* comment,
187 int method,
188 int level,
189 int raw,
190 int windowBits,
191 int memLevel,
192 int strategy,
193 const char* password,
194 uLong crcForCtypting));
195
196/*
197 Same than zipOpenNewFileInZip2, except
198 windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
199 password : crypting password (NULL for no crypting)
200 crcForCtypting : crc of file to compress (needed for crypting)
201 */
202
203
204extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
205 const void* buf,
206 unsigned len));
207/*
208 Write data in the zipfile
209*/
210
211extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
212/*
213 Close the current file in the zipfile
214*/
215
216extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
217 uLong uncompressed_size,
218 uLong crc32));
219/*
220 Close the current file in the zipfile, for fiel opened with
221 parameter raw=1 in zipOpenNewFileInZip2
222 uncompressed_size and crc32 are value for the uncompressed size
223*/
224
225extern int ZEXPORT zipClose OF((zipFile file,
226 const char* global_comment));
227/*
228 Close the zipfile
229*/
230
231#ifdef __cplusplus
232}
233#endif
234
235#endif /* _zip_H */
diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro
index 48c9f8c24d..42031ff9fa 100644
--- a/utils/themeeditor/themeeditor.pro
+++ b/utils/themeeditor/themeeditor.pro
@@ -1,7 +1,13 @@
1QT += network
2
1# Enabling profiling 3# Enabling profiling
2QMAKE_CXXFLAGS_DEBUG += -pg 4QMAKE_CXXFLAGS_DEBUG += -pg
3QMAKE_LFLAGS_DEBUG += -pg 5QMAKE_LFLAGS_DEBUG += -pg
4 6
7# Adding zlib dependency for QuaZip
8LIBS += -lz
9INCLUDEPATH += zlib
10
5# build in a separate folder. 11# build in a separate folder.
6MYBUILDDIR = $$OUT_PWD/build/ 12MYBUILDDIR = $$OUT_PWD/build/
7OBJECTS_DIR = $$MYBUILDDIR/o 13OBJECTS_DIR = $$MYBUILDDIR/o
@@ -15,6 +21,7 @@ RBBASE_DIR = $$replace(RBBASE_DIR,/utils/themeeditor,)
15INCLUDEPATH += gui 21INCLUDEPATH += gui
16INCLUDEPATH += models 22INCLUDEPATH += models
17INCLUDEPATH += graphics 23INCLUDEPATH += graphics
24INCLUDEPATH += quazip
18 25
19# Stuff for the parse lib 26# Stuff for the parse lib
20libskin_parser.commands = @$(MAKE) \ 27libskin_parser.commands = @$(MAKE) \
@@ -56,7 +63,18 @@ HEADERS += models/parsetreemodel.h \
56 gui/skintimer.h \ 63 gui/skintimer.h \
57 graphics/rbtoucharea.h \ 64 graphics/rbtoucharea.h \
58 gui/newprojectdialog.h \ 65 gui/newprojectdialog.h \
59 models/targetdata.h 66 models/targetdata.h \
67 quazip/zip.h \
68 quazip/unzip.h \
69 quazip/quazipnewinfo.h \
70 quazip/quazipfileinfo.h \
71 quazip/quazipfile.h \
72 quazip/quazip.h \
73 quazip/ioapi.h \
74 quazip/crypt.h \
75 zlib/zlib.h \
76 zlib/zconf.h \
77 gui/fontdownloader.h
60SOURCES += main.cpp \ 78SOURCES += main.cpp \
61 models/parsetreemodel.cpp \ 79 models/parsetreemodel.cpp \
62 models/parsetreenode.cpp \ 80 models/parsetreenode.cpp \
@@ -83,7 +101,14 @@ SOURCES += main.cpp \
83 gui/skintimer.cpp \ 101 gui/skintimer.cpp \
84 graphics/rbtoucharea.cpp \ 102 graphics/rbtoucharea.cpp \
85 gui/newprojectdialog.cpp \ 103 gui/newprojectdialog.cpp \
86 models/targetdata.cpp 104 models/targetdata.cpp \
105 quazip/zip.c \
106 quazip/unzip.c \
107 quazip/quazipnewinfo.cpp \
108 quazip/quazipfile.cpp \
109 quazip/quazip.cpp \
110 quazip/ioapi.c \
111 gui/fontdownloader.cpp
87OTHER_FILES += README \ 112OTHER_FILES += README \
88 resources/windowicon.png \ 113 resources/windowicon.png \
89 resources/appicon.xcf \ 114 resources/appicon.xcf \
@@ -105,14 +130,17 @@ OTHER_FILES += README \
105 resources/lines.png \ 130 resources/lines.png \
106 resources/cursor.xcf \ 131 resources/cursor.xcf \
107 resources/cursor.png \ 132 resources/cursor.png \
108 resources/targetdb 133 resources/targetdb \
134 quazip/README.ROCKBOX \
135 quazip/LICENSE.GPL
109FORMS += gui/editorwindow.ui \ 136FORMS += gui/editorwindow.ui \
110 gui/preferencesdialog.ui \ 137 gui/preferencesdialog.ui \
111 gui/configdocument.ui \ 138 gui/configdocument.ui \
112 gui/skinviewer.ui \ 139 gui/skinviewer.ui \
113 gui/findreplacedialog.ui \ 140 gui/findreplacedialog.ui \
114 gui/skintimer.ui \ 141 gui/skintimer.ui \
115 gui/newprojectdialog.ui 142 gui/newprojectdialog.ui \
143 gui/fontdownloader.ui
116RESOURCES += resources.qrc 144RESOURCES += resources.qrc
117win32:RC_FILE = themeeditor.rc 145win32:RC_FILE = themeeditor.rc
118macx { 146macx {
diff --git a/utils/themeeditor/zlib/zconf.h b/utils/themeeditor/zlib/zconf.h
new file mode 100644
index 0000000000..3c21403fce
--- /dev/null
+++ b/utils/themeeditor/zlib/zconf.h
@@ -0,0 +1,326 @@
1/* zconf.h -- configuration of the zlib compression library
2 * Copyright (C) 1995-2004 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#ifndef ZCONF_H
9#define ZCONF_H
10
11/*
12 * If you *really* need a unique prefix for all types and library functions,
13 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
14 */
15#ifdef Z_PREFIX
16# define deflateInit_ z_deflateInit_
17# define deflate z_deflate
18# define deflateEnd z_deflateEnd
19# define inflateInit_ z_inflateInit_
20# define inflate z_inflate
21# define inflateEnd z_inflateEnd
22# define deflateInit2_ z_deflateInit2_
23# define deflateSetDictionary z_deflateSetDictionary
24# define deflateCopy z_deflateCopy
25# define deflateReset z_deflateReset
26# define deflateParams z_deflateParams
27# define deflateBound z_deflateBound
28# define deflatePrime z_deflatePrime
29# define inflateInit2_ z_inflateInit2_
30# define inflateSetDictionary z_inflateSetDictionary
31# define inflateSync z_inflateSync
32# define inflateSyncPoint z_inflateSyncPoint
33# define inflateCopy z_inflateCopy
34# define inflateReset z_inflateReset
35# define inflateBack z_inflateBack
36# define inflateBackEnd z_inflateBackEnd
37# define compress z_compress
38# define compress2 z_compress2
39# define compressBound z_compressBound
40# define uncompress z_uncompress
41# define adler32 z_adler32
42# define crc32 z_crc32
43# define get_crc_table z_get_crc_table
44# define zError z_zError
45
46# define Byte z_Byte
47# define uInt z_uInt
48# define uLong z_uLong
49# define Bytef z_Bytef
50# define charf z_charf
51# define intf z_intf
52# define uIntf z_uIntf
53# define uLongf z_uLongf
54# define voidpf z_voidpf
55# define voidp z_voidp
56#endif
57
58#if defined(__MSDOS__) && !defined(MSDOS)
59# define MSDOS
60#endif
61#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
62# define OS2
63#endif
64#if defined(_WINDOWS) && !defined(WINDOWS)
65# define WINDOWS
66#endif
67#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
68# define WIN32
69#endif
70#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
71# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
72# ifndef SYS16BIT
73# define SYS16BIT
74# endif
75# endif
76#endif
77
78/*
79 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
80 * than 64k bytes at a time (needed on systems with 16-bit int).
81 */
82#ifdef SYS16BIT
83# define MAXSEG_64K
84#endif
85#ifdef MSDOS
86# define UNALIGNED_OK
87#endif
88
89#ifdef __STDC_VERSION__
90# ifndef STDC
91# define STDC
92# endif
93# if __STDC_VERSION__ >= 199901L
94# ifndef STDC99
95# define STDC99
96# endif
97# endif
98#endif
99#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
100# define STDC
101#endif
102#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
103# define STDC
104#endif
105#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
106# define STDC
107#endif
108#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
109# define STDC
110#endif
111
112#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
113# define STDC
114#endif
115
116#ifndef STDC
117# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
118# define const /* note: need a more gentle solution here */
119# endif
120#endif
121
122/* Some Mac compilers merge all .h files incorrectly: */
123#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
124# define NO_DUMMY_DECL
125#endif
126
127/* Maximum value for memLevel in deflateInit2 */
128#ifndef MAX_MEM_LEVEL
129# ifdef MAXSEG_64K
130# define MAX_MEM_LEVEL 8
131# else
132# define MAX_MEM_LEVEL 9
133# endif
134#endif
135
136/* Maximum value for windowBits in deflateInit2 and inflateInit2.
137 * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
138 * created by gzip. (Files created by minigzip can still be extracted by
139 * gzip.)
140 */
141#ifndef MAX_WBITS
142# define MAX_WBITS 15 /* 32K LZ77 window */
143#endif
144
145/* The memory requirements for deflate are (in bytes):
146 (1 << (windowBits+2)) + (1 << (memLevel+9))
147 that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
148 plus a few kilobytes for small objects. For example, if you want to reduce
149 the default memory requirements from 256K to 128K, compile with
150 make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
151 Of course this will generally degrade compression (there's no free lunch).
152
153 The memory requirements for inflate are (in bytes) 1 << windowBits
154 that is, 32K for windowBits=15 (default value) plus a few kilobytes
155 for small objects.
156*/
157
158 /* Type declarations */
159
160#ifndef OF /* function prototypes */
161# ifdef STDC
162# define OF(args) args
163# else
164# define OF(args) ()
165# endif
166#endif
167
168/* The following definitions for FAR are needed only for MSDOS mixed
169 * model programming (small or medium model with some far allocations).
170 * This was tested only with MSC; for other MSDOS compilers you may have
171 * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
172 * just define FAR to be empty.
173 */
174#ifdef SYS16BIT
175# if defined(M_I86SM) || defined(M_I86MM)
176 /* MSC small or medium model */
177# define SMALL_MEDIUM
178# ifdef _MSC_VER
179# define FAR _far
180# else
181# define FAR far
182# endif
183# endif
184# if (defined(__SMALL__) || defined(__MEDIUM__))
185 /* Turbo C small or medium model */
186# define SMALL_MEDIUM
187# ifdef __BORLANDC__
188# define FAR _far
189# else
190# define FAR far
191# endif
192# endif
193#endif
194
195#if defined(WINDOWS) || defined(WIN32)
196 /* If building or using zlib as a DLL, define ZLIB_DLL.
197 * This is not mandatory, but it offers a little performance increase.
198 */
199# ifdef ZLIB_DLL
200# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
201# ifdef ZLIB_INTERNAL
202# define ZEXTERN extern __declspec(dllexport)
203# else
204# define ZEXTERN extern __declspec(dllimport)
205# endif
206# endif
207# endif /* ZLIB_DLL */
208 /* If building or using zlib with the WINAPI/WINAPIV calling convention,
209 * define ZLIB_WINAPI.
210 * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
211 */
212# ifdef ZLIB_WINAPI
213# ifdef FAR
214# undef FAR
215# endif
216# include <windows.h>
217 /* No need for _export, use ZLIB.DEF instead. */
218 /* For complete Windows compatibility, use WINAPI, not __stdcall. */
219# define ZEXPORT WINAPI
220# ifdef WIN32
221# define ZEXPORTVA WINAPIV
222# else
223# define ZEXPORTVA FAR CDECL
224# endif
225# endif
226#endif
227
228#if defined (__BEOS__)
229# ifdef ZLIB_DLL
230# ifdef ZLIB_INTERNAL
231# define ZEXPORT __declspec(dllexport)
232# define ZEXPORTVA __declspec(dllexport)
233# else
234# define ZEXPORT __declspec(dllimport)
235# define ZEXPORTVA __declspec(dllimport)
236# endif
237# endif
238#endif
239
240#ifndef ZEXTERN
241# define ZEXTERN extern
242#endif
243#ifndef ZEXPORT
244# define ZEXPORT
245#endif
246#ifndef ZEXPORTVA
247# define ZEXPORTVA
248#endif
249
250#ifndef FAR
251# define FAR
252#endif
253
254#if !defined(__MACTYPES__)
255typedef unsigned char Byte; /* 8 bits */
256#endif
257typedef unsigned int uInt; /* 16 bits or more */
258typedef unsigned long uLong; /* 32 bits or more */
259
260#ifdef SMALL_MEDIUM
261 /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
262# define Bytef Byte FAR
263#else
264 typedef Byte FAR Bytef;
265#endif
266typedef char FAR charf;
267typedef int FAR intf;
268typedef uInt FAR uIntf;
269typedef uLong FAR uLongf;
270
271#ifdef STDC
272 typedef void const *voidpc;
273 typedef void FAR *voidpf;
274 typedef void *voidp;
275#else
276 typedef Byte const *voidpc;
277 typedef Byte FAR *voidpf;
278 typedef Byte *voidp;
279#endif
280
281#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
282# include <sys/types.h> /* for off_t */
283# include <unistd.h> /* for SEEK_* and off_t */
284# ifdef VMS
285# include <unixio.h> /* for off_t */
286# endif
287# define z_off_t off_t
288#endif
289#ifndef SEEK_SET
290# define SEEK_SET 0 /* Seek from beginning of file. */
291# define SEEK_CUR 1 /* Seek from current position. */
292# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
293#endif
294#ifndef z_off_t
295# define z_off_t long
296#endif
297
298#if defined(__OS400__)
299# define NO_vsnprintf
300#endif
301
302#if defined(__MVS__)
303# define NO_vsnprintf
304# ifdef FAR
305# undef FAR
306# endif
307#endif
308
309/* MVS linker does not support external names larger than 8 bytes */
310#if defined(__MVS__)
311# pragma map(deflateInit_,"DEIN")
312# pragma map(deflateInit2_,"DEIN2")
313# pragma map(deflateEnd,"DEEND")
314# pragma map(deflateBound,"DEBND")
315# pragma map(inflateInit_,"ININ")
316# pragma map(inflateInit2_,"ININ2")
317# pragma map(inflateEnd,"INEND")
318# pragma map(inflateSync,"INSY")
319# pragma map(inflateSetDictionary,"INSEDI")
320# pragma map(compressBound,"CMBND")
321# pragma map(inflate_table,"INTABL")
322# pragma map(inflate_fast,"INFA")
323# pragma map(inflate_copyright,"INCOPY")
324#endif
325
326#endif /* ZCONF_H */
diff --git a/utils/themeeditor/zlib/zlib.h b/utils/themeeditor/zlib/zlib.h
new file mode 100644
index 0000000000..b4ddd34395
--- /dev/null
+++ b/utils/themeeditor/zlib/zlib.h
@@ -0,0 +1,1200 @@
1/* zlib.h -- interface of the 'zlib' general purpose compression library
2 version 1.2.2, October 3rd, 2004
3
4 Copyright (C) 1995-2004 Jean-loup Gailly and Mark Adler
5
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
9
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
13
14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution.
21
22 Jean-loup Gailly Mark Adler
23 jloup@gzip.org madler@alumni.caltech.edu
24
25
26 The data format used by the zlib library is described by RFCs (Request for
27 Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
28 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
29*/
30
31#ifndef ZLIB_H
32#define ZLIB_H
33
34#include "zconf.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#define ZLIB_VERSION "1.2.2"
41#define ZLIB_VERNUM 0x1220
42
43/*
44 The 'zlib' compression library provides in-memory compression and
45 decompression functions, including integrity checks of the uncompressed
46 data. This version of the library supports only one compression method
47 (deflation) but other algorithms will be added later and will have the same
48 stream interface.
49
50 Compression can be done in a single step if the buffers are large
51 enough (for example if an input file is mmap'ed), or can be done by
52 repeated calls of the compression function. In the latter case, the
53 application must provide more input and/or consume the output
54 (providing more output space) before each call.
55
56 The compressed data format used by default by the in-memory functions is
57 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
58 around a deflate stream, which is itself documented in RFC 1951.
59
60 The library also supports reading and writing files in gzip (.gz) format
61 with an interface similar to that of stdio using the functions that start
62 with "gz". The gzip format is different from the zlib format. gzip is a
63 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
64
65 This library can optionally read and write gzip streams in memory as well.
66
67 The zlib format was designed to be compact and fast for use in memory
68 and on communications channels. The gzip format was designed for single-
69 file compression on file systems, has a larger header than zlib to maintain
70 directory information, and uses a different, slower check method than zlib.
71
72 The library does not install any signal handler. The decoder checks
73 the consistency of the compressed data, so the library should never
74 crash even in case of corrupted input.
75*/
76
77typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
78typedef void (*free_func) OF((voidpf opaque, voidpf address));
79
80struct internal_state;
81
82typedef struct z_stream_s {
83 Bytef *next_in; /* next input byte */
84 uInt avail_in; /* number of bytes available at next_in */
85 uLong total_in; /* total nb of input bytes read so far */
86
87 Bytef *next_out; /* next output byte should be put there */
88 uInt avail_out; /* remaining free space at next_out */
89 uLong total_out; /* total nb of bytes output so far */
90
91 char *msg; /* last error message, NULL if no error */
92 struct internal_state FAR *state; /* not visible by applications */
93
94 alloc_func zalloc; /* used to allocate the internal state */
95 free_func zfree; /* used to free the internal state */
96 voidpf opaque; /* private data object passed to zalloc and zfree */
97
98 int data_type; /* best guess about the data type: ascii or binary */
99 uLong adler; /* adler32 value of the uncompressed data */
100 uLong reserved; /* reserved for future use */
101} z_stream;
102
103typedef z_stream FAR *z_streamp;
104
105/*
106 The application must update next_in and avail_in when avail_in has
107 dropped to zero. It must update next_out and avail_out when avail_out
108 has dropped to zero. The application must initialize zalloc, zfree and
109 opaque before calling the init function. All other fields are set by the
110 compression library and must not be updated by the application.
111
112 The opaque value provided by the application will be passed as the first
113 parameter for calls of zalloc and zfree. This can be useful for custom
114 memory management. The compression library attaches no meaning to the
115 opaque value.
116
117 zalloc must return Z_NULL if there is not enough memory for the object.
118 If zlib is used in a multi-threaded application, zalloc and zfree must be
119 thread safe.
120
121 On 16-bit systems, the functions zalloc and zfree must be able to allocate
122 exactly 65536 bytes, but will not be required to allocate more than this
123 if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
124 pointers returned by zalloc for objects of exactly 65536 bytes *must*
125 have their offset normalized to zero. The default allocation function
126 provided by this library ensures this (see zutil.c). To reduce memory
127 requirements and avoid any allocation of 64K objects, at the expense of
128 compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
129
130 The fields total_in and total_out can be used for statistics or
131 progress reports. After compression, total_in holds the total size of
132 the uncompressed data and may be saved for use in the decompressor
133 (particularly if the decompressor wants to decompress everything in
134 a single step).
135*/
136
137 /* constants */
138
139#define Z_NO_FLUSH 0
140#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
141#define Z_SYNC_FLUSH 2
142#define Z_FULL_FLUSH 3
143#define Z_FINISH 4
144#define Z_BLOCK 5
145/* Allowed flush values; see deflate() and inflate() below for details */
146
147#define Z_OK 0
148#define Z_STREAM_END 1
149#define Z_NEED_DICT 2
150#define Z_ERRNO (-1)
151#define Z_STREAM_ERROR (-2)
152#define Z_DATA_ERROR (-3)
153#define Z_MEM_ERROR (-4)
154#define Z_BUF_ERROR (-5)
155#define Z_VERSION_ERROR (-6)
156/* Return codes for the compression/decompression functions. Negative
157 * values are errors, positive values are used for special but normal events.
158 */
159
160#define Z_NO_COMPRESSION 0
161#define Z_BEST_SPEED 1
162#define Z_BEST_COMPRESSION 9
163#define Z_DEFAULT_COMPRESSION (-1)
164/* compression levels */
165
166#define Z_FILTERED 1
167#define Z_HUFFMAN_ONLY 2
168#define Z_RLE 3
169#define Z_DEFAULT_STRATEGY 0
170/* compression strategy; see deflateInit2() below for details */
171
172#define Z_BINARY 0
173#define Z_ASCII 1
174#define Z_UNKNOWN 2
175/* Possible values of the data_type field (though see inflate()) */
176
177#define Z_DEFLATED 8
178/* The deflate compression method (the only one supported in this version) */
179
180#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
181
182#define zlib_version zlibVersion()
183/* for compatibility with versions < 1.0.2 */
184
185 /* basic functions */
186
187ZEXTERN const char * ZEXPORT zlibVersion OF((void));
188/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
189 If the first character differs, the library code actually used is
190 not compatible with the zlib.h header file used by the application.
191 This check is automatically made by deflateInit and inflateInit.
192 */
193
194/*
195ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
196
197 Initializes the internal stream state for compression. The fields
198 zalloc, zfree and opaque must be initialized before by the caller.
199 If zalloc and zfree are set to Z_NULL, deflateInit updates them to
200 use default allocation functions.
201
202 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
203 1 gives best speed, 9 gives best compression, 0 gives no compression at
204 all (the input data is simply copied a block at a time).
205 Z_DEFAULT_COMPRESSION requests a default compromise between speed and
206 compression (currently equivalent to level 6).
207
208 deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
209 enough memory, Z_STREAM_ERROR if level is not a valid compression level,
210 Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
211 with the version assumed by the caller (ZLIB_VERSION).
212 msg is set to null if there is no error message. deflateInit does not
213 perform any compression: this will be done by deflate().
214*/
215
216
217ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
218/*
219 deflate compresses as much data as possible, and stops when the input
220 buffer becomes empty or the output buffer becomes full. It may introduce some
221 output latency (reading input without producing any output) except when
222 forced to flush.
223
224 The detailed semantics are as follows. deflate performs one or both of the
225 following actions:
226
227 - Compress more input starting at next_in and update next_in and avail_in
228 accordingly. If not all input can be processed (because there is not
229 enough room in the output buffer), next_in and avail_in are updated and
230 processing will resume at this point for the next call of deflate().
231
232 - Provide more output starting at next_out and update next_out and avail_out
233 accordingly. This action is forced if the parameter flush is non zero.
234 Forcing flush frequently degrades the compression ratio, so this parameter
235 should be set only when necessary (in interactive applications).
236 Some output may be provided even if flush is not set.
237
238 Before the call of deflate(), the application should ensure that at least
239 one of the actions is possible, by providing more input and/or consuming
240 more output, and updating avail_in or avail_out accordingly; avail_out
241 should never be zero before the call. The application can consume the
242 compressed output when it wants, for example when the output buffer is full
243 (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
244 and with zero avail_out, it must be called again after making room in the
245 output buffer because there might be more output pending.
246
247 If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
248 flushed to the output buffer and the output is aligned on a byte boundary, so
249 that the decompressor can get all input data available so far. (In particular
250 avail_in is zero after the call if enough output space has been provided
251 before the call.) Flushing may degrade compression for some compression
252 algorithms and so it should be used only when necessary.
253
254 If flush is set to Z_FULL_FLUSH, all output is flushed as with
255 Z_SYNC_FLUSH, and the compression state is reset so that decompression can
256 restart from this point if previous compressed data has been damaged or if
257 random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
258 the compression.
259
260 If deflate returns with avail_out == 0, this function must be called again
261 with the same value of the flush parameter and more output space (updated
262 avail_out), until the flush is complete (deflate returns with non-zero
263 avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
264 avail_out is greater than six to avoid repeated flush markers due to
265 avail_out == 0 on return.
266
267 If the parameter flush is set to Z_FINISH, pending input is processed,
268 pending output is flushed and deflate returns with Z_STREAM_END if there
269 was enough output space; if deflate returns with Z_OK, this function must be
270 called again with Z_FINISH and more output space (updated avail_out) but no
271 more input data, until it returns with Z_STREAM_END or an error. After
272 deflate has returned Z_STREAM_END, the only possible operations on the
273 stream are deflateReset or deflateEnd.
274
275 Z_FINISH can be used immediately after deflateInit if all the compression
276 is to be done in a single step. In this case, avail_out must be at least
277 the value returned by deflateBound (see below). If deflate does not return
278 Z_STREAM_END, then it must be called again as described above.
279
280 deflate() sets strm->adler to the adler32 checksum of all input read
281 so far (that is, total_in bytes).
282
283 deflate() may update data_type if it can make a good guess about
284 the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
285 binary. This field is only for information purposes and does not affect
286 the compression algorithm in any manner.
287
288 deflate() returns Z_OK if some progress has been made (more input
289 processed or more output produced), Z_STREAM_END if all input has been
290 consumed and all output has been produced (only when flush is set to
291 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
292 if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
293 (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
294 fatal, and deflate() can be called again with more input and more output
295 space to continue compressing.
296*/
297
298
299ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
300/*
301 All dynamically allocated data structures for this stream are freed.
302 This function discards any unprocessed input and does not flush any
303 pending output.
304
305 deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
306 stream state was inconsistent, Z_DATA_ERROR if the stream was freed
307 prematurely (some input or output was discarded). In the error case,
308 msg may be set but then points to a static string (which must not be
309 deallocated).
310*/
311
312
313/*
314ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
315
316 Initializes the internal stream state for decompression. The fields
317 next_in, avail_in, zalloc, zfree and opaque must be initialized before by
318 the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
319 value depends on the compression method), inflateInit determines the
320 compression method from the zlib header and allocates all data structures
321 accordingly; otherwise the allocation will be deferred to the first call of
322 inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
323 use default allocation functions.
324
325 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
326 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
327 version assumed by the caller. msg is set to null if there is no error
328 message. inflateInit does not perform any decompression apart from reading
329 the zlib header if present: this will be done by inflate(). (So next_in and
330 avail_in may be modified, but next_out and avail_out are unchanged.)
331*/
332
333
334ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
335/*
336 inflate decompresses as much data as possible, and stops when the input
337 buffer becomes empty or the output buffer becomes full. It may introduce
338 some output latency (reading input without producing any output) except when
339 forced to flush.
340
341 The detailed semantics are as follows. inflate performs one or both of the
342 following actions:
343
344 - Decompress more input starting at next_in and update next_in and avail_in
345 accordingly. If not all input can be processed (because there is not
346 enough room in the output buffer), next_in is updated and processing
347 will resume at this point for the next call of inflate().
348
349 - Provide more output starting at next_out and update next_out and avail_out
350 accordingly. inflate() provides as much output as possible, until there
351 is no more input data or no more space in the output buffer (see below
352 about the flush parameter).
353
354 Before the call of inflate(), the application should ensure that at least
355 one of the actions is possible, by providing more input and/or consuming
356 more output, and updating the next_* and avail_* values accordingly.
357 The application can consume the uncompressed output when it wants, for
358 example when the output buffer is full (avail_out == 0), or after each
359 call of inflate(). If inflate returns Z_OK and with zero avail_out, it
360 must be called again after making room in the output buffer because there
361 might be more output pending.
362
363 The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
364 Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
365 output as possible to the output buffer. Z_BLOCK requests that inflate() stop
366 if and when it get to the next deflate block boundary. When decoding the zlib
367 or gzip format, this will cause inflate() to return immediately after the
368 header and before the first block. When doing a raw inflate, inflate() will
369 go ahead and process the first block, and will return when it gets to the end
370 of that block, or when it runs out of data.
371
372 The Z_BLOCK option assists in appending to or combining deflate streams.
373 Also to assist in this, on return inflate() will set strm->data_type to the
374 number of unused bits in the last byte taken from strm->next_in, plus 64
375 if inflate() is currently decoding the last block in the deflate stream,
376 plus 128 if inflate() returned immediately after decoding an end-of-block
377 code or decoding the complete header up to just before the first byte of the
378 deflate stream. The end-of-block will not be indicated until all of the
379 uncompressed data from that block has been written to strm->next_out. The
380 number of unused bits may in general be greater than seven, except when
381 bit 7 of data_type is set, in which case the number of unused bits will be
382 less than eight.
383
384 inflate() should normally be called until it returns Z_STREAM_END or an
385 error. However if all decompression is to be performed in a single step
386 (a single call of inflate), the parameter flush should be set to
387 Z_FINISH. In this case all pending input is processed and all pending
388 output is flushed; avail_out must be large enough to hold all the
389 uncompressed data. (The size of the uncompressed data may have been saved
390 by the compressor for this purpose.) The next operation on this stream must
391 be inflateEnd to deallocate the decompression state. The use of Z_FINISH
392 is never required, but can be used to inform inflate that a faster approach
393 may be used for the single inflate() call.
394
395 In this implementation, inflate() always flushes as much output as
396 possible to the output buffer, and always uses the faster approach on the
397 first call. So the only effect of the flush parameter in this implementation
398 is on the return value of inflate(), as noted below, or when it returns early
399 because Z_BLOCK is used.
400
401 If a preset dictionary is needed after this call (see inflateSetDictionary
402 below), inflate sets strm->adler to the adler32 checksum of the dictionary
403 chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
404 strm->adler to the adler32 checksum of all output produced so far (that is,
405 total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
406 below. At the end of the stream, inflate() checks that its computed adler32
407 checksum is equal to that saved by the compressor and returns Z_STREAM_END
408 only if the checksum is correct.
409
410 inflate() will decompress and check either zlib-wrapped or gzip-wrapped
411 deflate data. The header type is detected automatically. Any information
412 contained in the gzip header is not retained, so applications that need that
413 information should instead use raw inflate, see inflateInit2() below, or
414 inflateBack() and perform their own processing of the gzip header and
415 trailer.
416
417 inflate() returns Z_OK if some progress has been made (more input processed
418 or more output produced), Z_STREAM_END if the end of the compressed data has
419 been reached and all uncompressed output has been produced, Z_NEED_DICT if a
420 preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
421 corrupted (input stream not conforming to the zlib format or incorrect check
422 value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
423 if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
424 Z_BUF_ERROR if no progress is possible or if there was not enough room in the
425 output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
426 inflate() can be called again with more input and more output space to
427 continue decompressing. If Z_DATA_ERROR is returned, the application may then
428 call inflateSync() to look for a good compression block if a partial recovery
429 of the data is desired.
430*/
431
432
433ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
434/*
435 All dynamically allocated data structures for this stream are freed.
436 This function discards any unprocessed input and does not flush any
437 pending output.
438
439 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
440 was inconsistent. In the error case, msg may be set but then points to a
441 static string (which must not be deallocated).
442*/
443
444 /* Advanced functions */
445
446/*
447 The following functions are needed only in some special applications.
448*/
449
450/*
451ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
452 int level,
453 int method,
454 int windowBits,
455 int memLevel,
456 int strategy));
457
458 This is another version of deflateInit with more compression options. The
459 fields next_in, zalloc, zfree and opaque must be initialized before by
460 the caller.
461
462 The method parameter is the compression method. It must be Z_DEFLATED in
463 this version of the library.
464
465 The windowBits parameter is the base two logarithm of the window size
466 (the size of the history buffer). It should be in the range 8..15 for this
467 version of the library. Larger values of this parameter result in better
468 compression at the expense of memory usage. The default value is 15 if
469 deflateInit is used instead.
470
471 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
472 determines the window size. deflate() will then generate raw deflate data
473 with no zlib header or trailer, and will not compute an adler32 check value.
474
475 windowBits can also be greater than 15 for optional gzip encoding. Add
476 16 to windowBits to write a simple gzip header and trailer around the
477 compressed data instead of a zlib wrapper. The gzip header will have no
478 file name, no extra data, no comment, no modification time (set to zero),
479 no header crc, and the operating system will be set to 255 (unknown). If a
480 gzip stream is being written, strm->adler is a crc32 instead of an adler32.
481
482 The memLevel parameter specifies how much memory should be allocated
483 for the internal compression state. memLevel=1 uses minimum memory but
484 is slow and reduces compression ratio; memLevel=9 uses maximum memory
485 for optimal speed. The default value is 8. See zconf.h for total memory
486 usage as a function of windowBits and memLevel.
487
488 The strategy parameter is used to tune the compression algorithm. Use the
489 value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
490 filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
491 string match), or Z_RLE to limit match distances to one (run-length
492 encoding). Filtered data consists mostly of small values with a somewhat
493 random distribution. In this case, the compression algorithm is tuned to
494 compress them better. The effect of Z_FILTERED is to force more Huffman
495 coding and less string matching; it is somewhat intermediate between
496 Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
497 Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
498 parameter only affects the compression ratio but not the correctness of the
499 compressed output even if it is not set appropriately.
500
501 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
502 memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
503 method). msg is set to null if there is no error message. deflateInit2 does
504 not perform any compression: this will be done by deflate().
505*/
506
507ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
508 const Bytef *dictionary,
509 uInt dictLength));
510/*
511 Initializes the compression dictionary from the given byte sequence
512 without producing any compressed output. This function must be called
513 immediately after deflateInit, deflateInit2 or deflateReset, before any
514 call of deflate. The compressor and decompressor must use exactly the same
515 dictionary (see inflateSetDictionary).
516
517 The dictionary should consist of strings (byte sequences) that are likely
518 to be encountered later in the data to be compressed, with the most commonly
519 used strings preferably put towards the end of the dictionary. Using a
520 dictionary is most useful when the data to be compressed is short and can be
521 predicted with good accuracy; the data can then be compressed better than
522 with the default empty dictionary.
523
524 Depending on the size of the compression data structures selected by
525 deflateInit or deflateInit2, a part of the dictionary may in effect be
526 discarded, for example if the dictionary is larger than the window size in
527 deflate or deflate2. Thus the strings most likely to be useful should be
528 put at the end of the dictionary, not at the front.
529
530 Upon return of this function, strm->adler is set to the adler32 value
531 of the dictionary; the decompressor may later use this value to determine
532 which dictionary has been used by the compressor. (The adler32 value
533 applies to the whole dictionary even if only a subset of the dictionary is
534 actually used by the compressor.) If a raw deflate was requested, then the
535 adler32 value is not computed and strm->adler is not set.
536
537 deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
538 parameter is invalid (such as NULL dictionary) or the stream state is
539 inconsistent (for example if deflate has already been called for this stream
540 or if the compression method is bsort). deflateSetDictionary does not
541 perform any compression: this will be done by deflate().
542*/
543
544ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
545 z_streamp source));
546/*
547 Sets the destination stream as a complete copy of the source stream.
548
549 This function can be useful when several compression strategies will be
550 tried, for example when there are several ways of pre-processing the input
551 data with a filter. The streams that will be discarded should then be freed
552 by calling deflateEnd. Note that deflateCopy duplicates the internal
553 compression state which can be quite large, so this strategy is slow and
554 can consume lots of memory.
555
556 deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
557 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
558 (such as zalloc being NULL). msg is left unchanged in both source and
559 destination.
560*/
561
562ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
563/*
564 This function is equivalent to deflateEnd followed by deflateInit,
565 but does not free and reallocate all the internal compression state.
566 The stream will keep the same compression level and any other attributes
567 that may have been set by deflateInit2.
568
569 deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
570 stream state was inconsistent (such as zalloc or state being NULL).
571*/
572
573ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
574 int level,
575 int strategy));
576/*
577 Dynamically update the compression level and compression strategy. The
578 interpretation of level and strategy is as in deflateInit2. This can be
579 used to switch between compression and straight copy of the input data, or
580 to switch to a different kind of input data requiring a different
581 strategy. If the compression level is changed, the input available so far
582 is compressed with the old level (and may be flushed); the new level will
583 take effect only at the next call of deflate().
584
585 Before the call of deflateParams, the stream state must be set as for
586 a call of deflate(), since the currently available input may have to
587 be compressed and flushed. In particular, strm->avail_out must be non-zero.
588
589 deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
590 stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
591 if strm->avail_out was zero.
592*/
593
594ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
595 uLong sourceLen));
596/*
597 deflateBound() returns an upper bound on the compressed size after
598 deflation of sourceLen bytes. It must be called after deflateInit()
599 or deflateInit2(). This would be used to allocate an output buffer
600 for deflation in a single pass, and so would be called before deflate().
601*/
602
603ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
604 int bits,
605 int value));
606/*
607 deflatePrime() inserts bits in the deflate output stream. The intent
608 is that this function is used to start off the deflate output with the
609 bits leftover from a previous deflate stream when appending to it. As such,
610 this function can only be used for raw deflate, and must be used before the
611 first deflate() call after a deflateInit2() or deflateReset(). bits must be
612 less than or equal to 16, and that many of the least significant bits of
613 value will be inserted in the output.
614
615 deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
616 stream state was inconsistent.
617*/
618
619/*
620ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
621 int windowBits));
622
623 This is another version of inflateInit with an extra parameter. The
624 fields next_in, avail_in, zalloc, zfree and opaque must be initialized
625 before by the caller.
626
627 The windowBits parameter is the base two logarithm of the maximum window
628 size (the size of the history buffer). It should be in the range 8..15 for
629 this version of the library. The default value is 15 if inflateInit is used
630 instead. windowBits must be greater than or equal to the windowBits value
631 provided to deflateInit2() while compressing, or it must be equal to 15 if
632 deflateInit2() was not used. If a compressed stream with a larger window
633 size is given as input, inflate() will return with the error code
634 Z_DATA_ERROR instead of trying to allocate a larger window.
635
636 windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
637 determines the window size. inflate() will then process raw deflate data,
638 not looking for a zlib or gzip header, not generating a check value, and not
639 looking for any check values for comparison at the end of the stream. This
640 is for use with other formats that use the deflate compressed data format
641 such as zip. Those formats provide their own check values. If a custom
642 format is developed using the raw deflate format for compressed data, it is
643 recommended that a check value such as an adler32 or a crc32 be applied to
644 the uncompressed data as is done in the zlib, gzip, and zip formats. For
645 most applications, the zlib format should be used as is. Note that comments
646 above on the use in deflateInit2() applies to the magnitude of windowBits.
647
648 windowBits can also be greater than 15 for optional gzip decoding. Add
649 32 to windowBits to enable zlib and gzip decoding with automatic header
650 detection, or add 16 to decode only the gzip format (the zlib format will
651 return a Z_DATA_ERROR. If a gzip stream is being decoded, strm->adler is
652 a crc32 instead of an adler32.
653
654 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
655 memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
656 memLevel). msg is set to null if there is no error message. inflateInit2
657 does not perform any decompression apart from reading the zlib header if
658 present: this will be done by inflate(). (So next_in and avail_in may be
659 modified, but next_out and avail_out are unchanged.)
660*/
661
662ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
663 const Bytef *dictionary,
664 uInt dictLength));
665/*
666 Initializes the decompression dictionary from the given uncompressed byte
667 sequence. This function must be called immediately after a call of inflate
668 if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
669 can be determined from the adler32 value returned by this call of
670 inflate. The compressor and decompressor must use exactly the same
671 dictionary (see deflateSetDictionary).
672
673 inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
674 parameter is invalid (such as NULL dictionary) or the stream state is
675 inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
676 expected one (incorrect adler32 value). inflateSetDictionary does not
677 perform any decompression: this will be done by subsequent calls of
678 inflate().
679*/
680
681ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
682/*
683 Skips invalid compressed data until a full flush point (see above the
684 description of deflate with Z_FULL_FLUSH) can be found, or until all
685 available input is skipped. No output is provided.
686
687 inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
688 if no more input was provided, Z_DATA_ERROR if no flush point has been found,
689 or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
690 case, the application may save the current current value of total_in which
691 indicates where valid compressed data was found. In the error case, the
692 application may repeatedly call inflateSync, providing more input each time,
693 until success or end of the input data.
694*/
695
696ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
697 z_streamp source));
698/*
699 Sets the destination stream as a complete copy of the source stream.
700
701 This function can be useful when randomly accessing a large stream. The
702 first pass through the stream can periodically record the inflate state,
703 allowing restarting inflate at those points when randomly accessing the
704 stream.
705
706 inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
707 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
708 (such as zalloc being NULL). msg is left unchanged in both source and
709 destination.
710*/
711
712ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
713/*
714 This function is equivalent to inflateEnd followed by inflateInit,
715 but does not free and reallocate all the internal decompression state.
716 The stream will keep attributes that may have been set by inflateInit2.
717
718 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
719 stream state was inconsistent (such as zalloc or state being NULL).
720*/
721
722/*
723ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits,
724 unsigned char FAR *window));
725
726 Initialize the internal stream state for decompression using inflateBack()
727 calls. The fields zalloc, zfree and opaque in strm must be initialized
728 before the call. If zalloc and zfree are Z_NULL, then the default library-
729 derived memory allocation routines are used. windowBits is the base two
730 logarithm of the window size, in the range 8..15. window is a caller
731 supplied buffer of that size. Except for special applications where it is
732 assured that deflate was used with small window sizes, windowBits must be 15
733 and a 32K byte window must be supplied to be able to decompress general
734 deflate streams.
735
736 See inflateBack() for the usage of these routines.
737
738 inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
739 the paramaters are invalid, Z_MEM_ERROR if the internal state could not
740 be allocated, or Z_VERSION_ERROR if the version of the library does not
741 match the version of the header file.
742*/
743
744typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
745typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
746
747ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm,
748 in_func in, void FAR *in_desc,
749 out_func out, void FAR *out_desc));
750/*
751 inflateBack() does a raw inflate with a single call using a call-back
752 interface for input and output. This is more efficient than inflate() for
753 file i/o applications in that it avoids copying between the output and the
754 sliding window by simply making the window itself the output buffer. This
755 function trusts the application to not change the output buffer passed by
756 the output function, at least until inflateBack() returns.
757
758 inflateBackInit() must be called first to allocate the internal state
759 and to initialize the state with the user-provided window buffer.
760 inflateBack() may then be used multiple times to inflate a complete, raw
761 deflate stream with each call. inflateBackEnd() is then called to free
762 the allocated state.
763
764 A raw deflate stream is one with no zlib or gzip header or trailer.
765 This routine would normally be used in a utility that reads zip or gzip
766 files and writes out uncompressed files. The utility would decode the
767 header and process the trailer on its own, hence this routine expects
768 only the raw deflate stream to decompress. This is different from the
769 normal behavior of inflate(), which expects either a zlib or gzip header and
770 trailer around the deflate stream.
771
772 inflateBack() uses two subroutines supplied by the caller that are then
773 called by inflateBack() for input and output. inflateBack() calls those
774 routines until it reads a complete deflate stream and writes out all of the
775 uncompressed data, or until it encounters an error. The function's
776 parameters and return types are defined above in the in_func and out_func
777 typedefs. inflateBack() will call in(in_desc, &buf) which should return the
778 number of bytes of provided input, and a pointer to that input in buf. If
779 there is no input available, in() must return zero--buf is ignored in that
780 case--and inflateBack() will return a buffer error. inflateBack() will call
781 out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out()
782 should return zero on success, or non-zero on failure. If out() returns
783 non-zero, inflateBack() will return with an error. Neither in() nor out()
784 are permitted to change the contents of the window provided to
785 inflateBackInit(), which is also the buffer that out() uses to write from.
786 The length written by out() will be at most the window size. Any non-zero
787 amount of input may be provided by in().
788
789 For convenience, inflateBack() can be provided input on the first call by
790 setting strm->next_in and strm->avail_in. If that input is exhausted, then
791 in() will be called. Therefore strm->next_in must be initialized before
792 calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called
793 immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
794 must also be initialized, and then if strm->avail_in is not zero, input will
795 initially be taken from strm->next_in[0 .. strm->avail_in - 1].
796
797 The in_desc and out_desc parameters of inflateBack() is passed as the
798 first parameter of in() and out() respectively when they are called. These
799 descriptors can be optionally used to pass any information that the caller-
800 supplied in() and out() functions need to do their job.
801
802 On return, inflateBack() will set strm->next_in and strm->avail_in to
803 pass back any unused input that was provided by the last in() call. The
804 return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
805 if in() or out() returned an error, Z_DATA_ERROR if there was a format
806 error in the deflate stream (in which case strm->msg is set to indicate the
807 nature of the error), or Z_STREAM_ERROR if the stream was not properly
808 initialized. In the case of Z_BUF_ERROR, an input or output error can be
809 distinguished using strm->next_in which will be Z_NULL only if in() returned
810 an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to
811 out() returning non-zero. (in() will always be called before out(), so
812 strm->next_in is assured to be defined if out() returns non-zero.) Note
813 that inflateBack() cannot return Z_OK.
814*/
815
816ZEXTERN int ZEXPORT inflateBackEnd OF((z_stream FAR *strm));
817/*
818 All memory allocated by inflateBackInit() is freed.
819
820 inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
821 state was inconsistent.
822*/
823
824ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
825/* Return flags indicating compile-time options.
826
827 Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
828 1.0: size of uInt
829 3.2: size of uLong
830 5.4: size of voidpf (pointer)
831 7.6: size of z_off_t
832
833 Compiler, assembler, and debug options:
834 8: DEBUG
835 9: ASMV or ASMINF -- use ASM code
836 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
837 11: 0 (reserved)
838
839 One-time table building (smaller code, but not thread-safe if true):
840 12: BUILDFIXED -- build static block decoding tables when needed
841 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
842 14,15: 0 (reserved)
843
844 Library content (indicates missing functionality):
845 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
846 deflate code when not needed)
847 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
848 and decode gzip streams (to avoid linking crc code)
849 18-19: 0 (reserved)
850
851 Operation variations (changes in library functionality):
852 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
853 21: FASTEST -- deflate algorithm with only one, lowest compression level
854 22,23: 0 (reserved)
855
856 The sprintf variant used by gzprintf (zero is best):
857 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
858 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
859 26: 0 = returns value, 1 = void -- 1 means inferred string length returned
860
861 Remainder:
862 27-31: 0 (reserved)
863 */
864
865
866 /* utility functions */
867
868/*
869 The following utility functions are implemented on top of the
870 basic stream-oriented functions. To simplify the interface, some
871 default options are assumed (compression level and memory usage,
872 standard memory allocation functions). The source code of these
873 utility functions can easily be modified if you need special options.
874*/
875
876ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
877 const Bytef *source, uLong sourceLen));
878/*
879 Compresses the source buffer into the destination buffer. sourceLen is
880 the byte length of the source buffer. Upon entry, destLen is the total
881 size of the destination buffer, which must be at least the value returned
882 by compressBound(sourceLen). Upon exit, destLen is the actual size of the
883 compressed buffer.
884 This function can be used to compress a whole file at once if the
885 input file is mmap'ed.
886 compress returns Z_OK if success, Z_MEM_ERROR if there was not
887 enough memory, Z_BUF_ERROR if there was not enough room in the output
888 buffer.
889*/
890
891ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
892 const Bytef *source, uLong sourceLen,
893 int level));
894/*
895 Compresses the source buffer into the destination buffer. The level
896 parameter has the same meaning as in deflateInit. sourceLen is the byte
897 length of the source buffer. Upon entry, destLen is the total size of the
898 destination buffer, which must be at least the value returned by
899 compressBound(sourceLen). Upon exit, destLen is the actual size of the
900 compressed buffer.
901
902 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
903 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
904 Z_STREAM_ERROR if the level parameter is invalid.
905*/
906
907ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
908/*
909 compressBound() returns an upper bound on the compressed size after
910 compress() or compress2() on sourceLen bytes. It would be used before
911 a compress() or compress2() call to allocate the destination buffer.
912*/
913
914ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
915 const Bytef *source, uLong sourceLen));
916/*
917 Decompresses the source buffer into the destination buffer. sourceLen is
918 the byte length of the source buffer. Upon entry, destLen is the total
919 size of the destination buffer, which must be large enough to hold the
920 entire uncompressed data. (The size of the uncompressed data must have
921 been saved previously by the compressor and transmitted to the decompressor
922 by some mechanism outside the scope of this compression library.)
923 Upon exit, destLen is the actual size of the compressed buffer.
924 This function can be used to decompress a whole file at once if the
925 input file is mmap'ed.
926
927 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
928 enough memory, Z_BUF_ERROR if there was not enough room in the output
929 buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
930*/
931
932
933typedef voidp gzFile;
934
935ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
936/*
937 Opens a gzip (.gz) file for reading or writing. The mode parameter
938 is as in fopen ("rb" or "wb") but can also include a compression level
939 ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
940 Huffman only compression as in "wb1h", or 'R' for run-length encoding
941 as in "wb1R". (See the description of deflateInit2 for more information
942 about the strategy parameter.)
943
944 gzopen can be used to read a file which is not in gzip format; in this
945 case gzread will directly read from the file without decompression.
946
947 gzopen returns NULL if the file could not be opened or if there was
948 insufficient memory to allocate the (de)compression state; errno
949 can be checked to distinguish the two cases (if errno is zero, the
950 zlib error is Z_MEM_ERROR). */
951
952ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
953/*
954 gzdopen() associates a gzFile with the file descriptor fd. File
955 descriptors are obtained from calls like open, dup, creat, pipe or
956 fileno (in the file has been previously opened with fopen).
957 The mode parameter is as in gzopen.
958 The next call of gzclose on the returned gzFile will also close the
959 file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
960 descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
961 gzdopen returns NULL if there was insufficient memory to allocate
962 the (de)compression state.
963*/
964
965ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
966/*
967 Dynamically update the compression level or strategy. See the description
968 of deflateInit2 for the meaning of these parameters.
969 gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
970 opened for writing.
971*/
972
973ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
974/*
975 Reads the given number of uncompressed bytes from the compressed file.
976 If the input file was not in gzip format, gzread copies the given number
977 of bytes into the buffer.
978 gzread returns the number of uncompressed bytes actually read (0 for
979 end of file, -1 for error). */
980
981ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
982 voidpc buf, unsigned len));
983/*
984 Writes the given number of uncompressed bytes into the compressed file.
985 gzwrite returns the number of uncompressed bytes actually written
986 (0 in case of error).
987*/
988
989ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
990/*
991 Converts, formats, and writes the args to the compressed file under
992 control of the format string, as in fprintf. gzprintf returns the number of
993 uncompressed bytes actually written (0 in case of error). The number of
994 uncompressed bytes written is limited to 4095. The caller should assure that
995 this limit is not exceeded. If it is exceeded, then gzprintf() will return
996 return an error (0) with nothing written. In this case, there may also be a
997 buffer overflow with unpredictable consequences, which is possible only if
998 zlib was compiled with the insecure functions sprintf() or vsprintf()
999 because the secure snprintf() or vsnprintf() functions were not available.
1000*/
1001
1002ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
1003/*
1004 Writes the given null-terminated string to the compressed file, excluding
1005 the terminating null character.
1006 gzputs returns the number of characters written, or -1 in case of error.
1007*/
1008
1009ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
1010/*
1011 Reads bytes from the compressed file until len-1 characters are read, or
1012 a newline character is read and transferred to buf, or an end-of-file
1013 condition is encountered. The string is then terminated with a null
1014 character.
1015 gzgets returns buf, or Z_NULL in case of error.
1016*/
1017
1018ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
1019/*
1020 Writes c, converted to an unsigned char, into the compressed file.
1021 gzputc returns the value that was written, or -1 in case of error.
1022*/
1023
1024ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
1025/*
1026 Reads one byte from the compressed file. gzgetc returns this byte
1027 or -1 in case of end of file or error.
1028*/
1029
1030ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
1031/*
1032 Push one character back onto the stream to be read again later.
1033 Only one character of push-back is allowed. gzungetc() returns the
1034 character pushed, or -1 on failure. gzungetc() will fail if a
1035 character has been pushed but not read yet, or if c is -1. The pushed
1036 character will be discarded if the stream is repositioned with gzseek()
1037 or gzrewind().
1038*/
1039
1040ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
1041/*
1042 Flushes all pending output into the compressed file. The parameter
1043 flush is as in the deflate() function. The return value is the zlib
1044 error number (see function gzerror below). gzflush returns Z_OK if
1045 the flush parameter is Z_FINISH and all output could be flushed.
1046 gzflush should be called only when strictly necessary because it can
1047 degrade compression.
1048*/
1049
1050ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
1051 z_off_t offset, int whence));
1052/*
1053 Sets the starting position for the next gzread or gzwrite on the
1054 given compressed file. The offset represents a number of bytes in the
1055 uncompressed data stream. The whence parameter is defined as in lseek(2);
1056 the value SEEK_END is not supported.
1057 If the file is opened for reading, this function is emulated but can be
1058 extremely slow. If the file is opened for writing, only forward seeks are
1059 supported; gzseek then compresses a sequence of zeroes up to the new
1060 starting position.
1061
1062 gzseek returns the resulting offset location as measured in bytes from
1063 the beginning of the uncompressed stream, or -1 in case of error, in
1064 particular if the file is opened for writing and the new starting position
1065 would be before the current position.
1066*/
1067
1068ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
1069/*
1070 Rewinds the given file. This function is supported only for reading.
1071
1072 gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
1073*/
1074
1075ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
1076/*
1077 Returns the starting position for the next gzread or gzwrite on the
1078 given compressed file. This position represents a number of bytes in the
1079 uncompressed data stream.
1080
1081 gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
1082*/
1083
1084ZEXTERN int ZEXPORT gzeof OF((gzFile file));
1085/*
1086 Returns 1 when EOF has previously been detected reading the given
1087 input stream, otherwise zero.
1088*/
1089
1090ZEXTERN int ZEXPORT gzclose OF((gzFile file));
1091/*
1092 Flushes all pending output if necessary, closes the compressed file
1093 and deallocates all the (de)compression state. The return value is the zlib
1094 error number (see function gzerror below).
1095*/
1096
1097ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
1098/*
1099 Returns the error message for the last error which occurred on the
1100 given compressed file. errnum is set to zlib error number. If an
1101 error occurred in the file system and not in the compression library,
1102 errnum is set to Z_ERRNO and the application may consult errno
1103 to get the exact error code.
1104*/
1105
1106ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1107/*
1108 Clears the error and end-of-file flags for file. This is analogous to the
1109 clearerr() function in stdio. This is useful for continuing to read a gzip
1110 file that is being written concurrently.
1111*/
1112
1113 /* checksum functions */
1114
1115/*
1116 These functions are not related to compression but are exported
1117 anyway because they might be useful in applications using the
1118 compression library.
1119*/
1120
1121ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
1122
1123/*
1124 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1125 return the updated checksum. If buf is NULL, this function returns
1126 the required initial value for the checksum.
1127 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
1128 much faster. Usage example:
1129
1130 uLong adler = adler32(0L, Z_NULL, 0);
1131
1132 while (read_buffer(buffer, length) != EOF) {
1133 adler = adler32(adler, buffer, length);
1134 }
1135 if (adler != original_adler) error();
1136*/
1137
1138ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
1139/*
1140 Update a running crc with the bytes buf[0..len-1] and return the updated
1141 crc. If buf is NULL, this function returns the required initial value
1142 for the crc. Pre- and post-conditioning (one's complement) is performed
1143 within this function so it shouldn't be done by the application.
1144 Usage example:
1145
1146 uLong crc = crc32(0L, Z_NULL, 0);
1147
1148 while (read_buffer(buffer, length) != EOF) {
1149 crc = crc32(crc, buffer, length);
1150 }
1151 if (crc != original_crc) error();
1152*/
1153
1154
1155 /* various hacks, don't look :) */
1156
1157/* deflateInit and inflateInit are macros to allow checking the zlib version
1158 * and the compiler's view of z_stream:
1159 */
1160ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
1161 const char *version, int stream_size));
1162ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
1163 const char *version, int stream_size));
1164ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
1165 int windowBits, int memLevel,
1166 int strategy, const char *version,
1167 int stream_size));
1168ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
1169 const char *version, int stream_size));
1170ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits,
1171 unsigned char FAR *window,
1172 const char *version,
1173 int stream_size));
1174#define deflateInit(strm, level) \
1175 deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
1176#define inflateInit(strm) \
1177 inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
1178#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
1179 deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
1180 (strategy), ZLIB_VERSION, sizeof(z_stream))
1181#define inflateInit2(strm, windowBits) \
1182 inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
1183#define inflateBackInit(strm, windowBits, window) \
1184 inflateBackInit_((strm), (windowBits), (window), \
1185 ZLIB_VERSION, sizeof(z_stream))
1186
1187
1188#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
1189 struct internal_state {int dummy;}; /* hack for buggy compilers */
1190#endif
1191
1192ZEXTERN const char * ZEXPORT zError OF((int));
1193ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
1194ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
1195
1196#ifdef __cplusplus
1197}
1198#endif
1199
1200#endif /* ZLIB_H */