summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/quazip
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2011-03-25 22:16:12 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2011-03-25 22:16:12 +0000
commit8c1d114dcfcc8b3d47505e3139151eec43ebbdc4 (patch)
tree4925e1900520b0c89001c95c9da83f3533903d1e /rbutil/rbutilqt/quazip
parent0258895faa9a18c0b620ae0a63ee3768ba62747a (diff)
downloadrockbox-8c1d114dcfcc8b3d47505e3139151eec43ebbdc4.tar.gz
rockbox-8c1d114dcfcc8b3d47505e3139151eec43ebbdc4.zip
Rockbox Utility: Replace OSDaB Zip with QuaZip.
This change fixes problems with zip files created with newer zip utilities (a known issue is the iLike theme). QuaZip also allows better feedback during operations without changing the imported code. Additionally Rockbox Utility and the Theme Editor are now both using QuaZip; currently Rockbox Utility uses a copy of the sources, merging them later is planned. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29645 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt/quazip')
-rw-r--r--rbutil/rbutilqt/quazip/LICENSE.GPL341
-rw-r--r--rbutil/rbutilqt/quazip/README.ROCKBOX6
-rw-r--r--rbutil/rbutilqt/quazip/crypt.h133
-rw-r--r--rbutil/rbutilqt/quazip/ioapi.c184
-rw-r--r--rbutil/rbutilqt/quazip/ioapi.h75
-rw-r--r--rbutil/rbutilqt/quazip/quazip.cpp285
-rw-r--r--rbutil/rbutilqt/quazip/quazip.h346
-rw-r--r--rbutil/rbutilqt/quazip/quazipfile.cpp377
-rw-r--r--rbutil/rbutilqt/quazip/quazipfile.h442
-rw-r--r--rbutil/rbutilqt/quazip/quazipfileinfo.h73
-rw-r--r--rbutil/rbutilqt/quazip/quazipnewinfo.cpp59
-rw-r--r--rbutil/rbutilqt/quazip/quazipnewinfo.h109
-rw-r--r--rbutil/rbutilqt/quazip/unzip.c1601
-rw-r--r--rbutil/rbutilqt/quazip/unzip.h354
-rw-r--r--rbutil/rbutilqt/quazip/zip.c1221
-rw-r--r--rbutil/rbutilqt/quazip/zip.h235
16 files changed, 5841 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/quazip/LICENSE.GPL b/rbutil/rbutilqt/quazip/LICENSE.GPL
new file mode 100644
index 0000000000..04a7580109
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/README.ROCKBOX b/rbutil/rbutilqt/quazip/README.ROCKBOX
new file mode 100644
index 0000000000..b95f80caee
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/crypt.h b/rbutil/rbutilqt/quazip/crypt.h
new file mode 100644
index 0000000000..82748c5715
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/ioapi.c b/rbutil/rbutilqt/quazip/ioapi.c
new file mode 100644
index 0000000000..cf29a317fd
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/ioapi.h b/rbutil/rbutilqt/quazip/ioapi.h
new file mode 100644
index 0000000000..7d457baab3
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/quazip.cpp b/rbutil/rbutilqt/quazip/quazip.cpp
new file mode 100644
index 0000000000..3f7314a433
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/quazip.h b/rbutil/rbutilqt/quazip/quazip.h
new file mode 100644
index 0000000000..ced1ea0f1a
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/quazipfile.cpp b/rbutil/rbutilqt/quazip/quazipfile.cpp
new file mode 100644
index 0000000000..0399d1dbd0
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/quazipfile.h b/rbutil/rbutilqt/quazip/quazipfile.h
new file mode 100644
index 0000000000..09af5bceca
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/quazipfileinfo.h b/rbutil/rbutilqt/quazip/quazipfileinfo.h
new file mode 100644
index 0000000000..3216d776d5
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/quazipnewinfo.cpp b/rbutil/rbutilqt/quazip/quazipnewinfo.cpp
new file mode 100644
index 0000000000..17571f2fc8
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/quazipnewinfo.h b/rbutil/rbutilqt/quazip/quazipnewinfo.h
new file mode 100644
index 0000000000..93ff1a2fc0
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/unzip.c b/rbutil/rbutilqt/quazip/unzip.c
new file mode 100644
index 0000000000..ace7a08837
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/unzip.h b/rbutil/rbutilqt/quazip/unzip.h
new file mode 100644
index 0000000000..b247937c80
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/zip.c b/rbutil/rbutilqt/quazip/zip.c
new file mode 100644
index 0000000000..13463fe336
--- /dev/null
+++ b/rbutil/rbutilqt/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/rbutil/rbutilqt/quazip/zip.h b/rbutil/rbutilqt/quazip/zip.h
new file mode 100644
index 0000000000..acacce83b9
--- /dev/null
+++ b/rbutil/rbutilqt/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 */