summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt')
-rw-r--r--rbutil/rbutilqt/quazip/LICENSE.GPL341
-rw-r--r--rbutil/rbutilqt/quazip/LICENSE.LGPL458
-rw-r--r--rbutil/rbutilqt/quazip/README.ROCKBOX9
-rw-r--r--rbutil/rbutilqt/quazip/crypt.h12
-rw-r--r--rbutil/rbutilqt/quazip/ioapi.c184
-rw-r--r--rbutil/rbutilqt/quazip/ioapi.h190
-rw-r--r--rbutil/rbutilqt/quazip/qioapi.cpp361
-rw-r--r--rbutil/rbutilqt/quazip/quazip.cpp723
-rw-r--r--rbutil/rbutilqt/quazip/quazip.h377
-rw-r--r--rbutil/rbutilqt/quazip/quazip_global.h59
-rw-r--r--rbutil/rbutilqt/quazip/quazipfile.cpp385
-rw-r--r--rbutil/rbutilqt/quazip/quazipfile.h114
-rw-r--r--rbutil/rbutilqt/quazip/quazipfileinfo.cpp176
-rw-r--r--rbutil/rbutilqt/quazip/quazipfileinfo.h157
-rw-r--r--rbutil/rbutilqt/quazip/quazipnewinfo.cpp284
-rw-r--r--rbutil/rbutilqt/quazip/quazipnewinfo.h152
-rw-r--r--rbutil/rbutilqt/quazip/unzip.c1344
-rw-r--r--rbutil/rbutilqt/quazip/unzip.h154
-rw-r--r--rbutil/rbutilqt/quazip/zip.c1950
-rw-r--r--rbutil/rbutilqt/quazip/zip.h211
-rw-r--r--rbutil/rbutilqt/rbutilqt.pri5
-rw-r--r--rbutil/rbutilqt/rbutilqt.pro2
22 files changed, 5650 insertions, 1998 deletions
diff --git a/rbutil/rbutilqt/quazip/LICENSE.GPL b/rbutil/rbutilqt/quazip/LICENSE.GPL
deleted file mode 100644
index 04a7580109..0000000000
--- a/rbutil/rbutilqt/quazip/LICENSE.GPL
+++ /dev/null
@@ -1,341 +0,0 @@
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/LICENSE.LGPL b/rbutil/rbutilqt/quazip/LICENSE.LGPL
new file mode 100644
index 0000000000..2cba2ac74c
--- /dev/null
+++ b/rbutil/rbutilqt/quazip/LICENSE.LGPL
@@ -0,0 +1,458 @@
1 GNU LESSER GENERAL PUBLIC LICENSE
2 Version 2.1, February 1999
3
4 Copyright (C) 1991, 1999 Free Software Foundation, Inc.
5 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6 Everyone is permitted to copy and distribute verbatim copies
7 of this license document, but changing it is not allowed.
8
9[This is the first released version of the Lesser GPL. It also counts
10 as the successor of the GNU Library Public License, version 2, hence
11 the version number 2.1.]
12
13 Preamble
14
15 The licenses for most software are designed to take away your
16freedom to share and change it. By contrast, the GNU General Public
17Licenses are intended to guarantee your freedom to share and change
18free software--to make sure the software is free for all its users.
19
20 This license, the Lesser General Public License, applies to some
21specially designated software packages--typically libraries--of the
22Free Software Foundation and other authors who decide to use it. You
23can use it too, but we suggest you first think carefully about whether
24this license or the ordinary General Public License is the better
25strategy to use in any particular case, based on the explanations below.
26
27 When we speak of free software, we are referring to freedom of use,
28not price. Our General Public Licenses are designed to make sure that
29you have the freedom to distribute copies of free software (and charge
30for this service if you wish); that you receive source code or can get
31it if you want it; that you can change the software and use pieces of
32it in new free programs; and that you are informed that you can do
33these things.
34
35 To protect your rights, we need to make restrictions that forbid
36distributors to deny you these rights or to ask you to surrender these
37rights. These restrictions translate to certain responsibilities for
38you if you distribute copies of the library or if you modify it.
39
40 For example, if you distribute copies of the library, whether gratis
41or for a fee, you must give the recipients all the rights that we gave
42you. You must make sure that they, too, receive or can get the source
43code. If you link other code with the library, you must provide
44complete object files to the recipients, so that they can relink them
45with the library after making changes to the library and recompiling
46it. And you must show them these terms so they know their rights.
47
48 We protect your rights with a two-step method: (1) we copyright the
49library, and (2) we offer you this license, which gives you legal
50permission to copy, distribute and/or modify the library.
51
52 To protect each distributor, we want to make it very clear that
53there is no warranty for the free library. Also, if the library is
54modified by someone else and passed on, the recipients should know
55that what they have is not the original version, so that the original
56author's reputation will not be affected by problems that might be
57introduced by others.
58
59 Finally, software patents pose a constant threat to the existence of
60any free program. We wish to make sure that a company cannot
61effectively restrict the users of a free program by obtaining a
62restrictive license from a patent holder. Therefore, we insist that
63any patent license obtained for a version of the library must be
64consistent with the full freedom of use specified in this license.
65
66 Most GNU software, including some libraries, is covered by the
67ordinary GNU General Public License. This license, the GNU Lesser
68General Public License, applies to certain designated libraries, and
69is quite different from the ordinary General Public License. We use
70this license for certain libraries in order to permit linking those
71libraries into non-free programs.
72
73 When a program is linked with a library, whether statically or using
74a shared library, the combination of the two is legally speaking a
75combined work, a derivative of the original library. The ordinary
76General Public License therefore permits such linking only if the
77entire combination fits its criteria of freedom. The Lesser General
78Public License permits more lax criteria for linking other code with
79the library.
80
81 We call this license the "Lesser" General Public License because it
82does Less to protect the user's freedom than the ordinary General
83Public License. It also provides other free software developers Less
84of an advantage over competing non-free programs. These disadvantages
85are the reason we use the ordinary General Public License for many
86libraries. However, the Lesser license provides advantages in certain
87special circumstances.
88
89 For example, on rare occasions, there may be a special need to
90encourage the widest possible use of a certain library, so that it becomes
91a de-facto standard. To achieve this, non-free programs must be
92allowed to use the library. A more frequent case is that a free
93library does the same job as widely used non-free libraries. In this
94case, there is little to gain by limiting the free library to free
95software only, so we use the Lesser General Public License.
96
97 In other cases, permission to use a particular library in non-free
98programs enables a greater number of people to use a large body of
99free software. For example, permission to use the GNU C Library in
100non-free programs enables many more people to use the whole GNU
101operating system, as well as its variant, the GNU/Linux operating
102system.
103
104 Although the Lesser General Public License is Less protective of the
105users' freedom, it does ensure that the user of a program that is
106linked with the Library has the freedom and the wherewithal to run
107that program using a modified version of the Library.
108
109 The precise terms and conditions for copying, distribution and
110modification follow. Pay close attention to the difference between a
111"work based on the library" and a "work that uses the library". The
112former contains code derived from the library, whereas the latter must
113be combined with the library in order to run.
114
115 GNU LESSER GENERAL PUBLIC LICENSE
116 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
117
118 0. This License Agreement applies to any software library or other
119program which contains a notice placed by the copyright holder or
120other authorized party saying it may be distributed under the terms of
121this Lesser General Public License (also called "this License").
122Each licensee is addressed as "you".
123
124 A "library" means a collection of software functions and/or data
125prepared so as to be conveniently linked with application programs
126(which use some of those functions and data) to form executables.
127
128 The "Library", below, refers to any such software library or work
129which has been distributed under these terms. A "work based on the
130Library" means either the Library or any derivative work under
131copyright law: that is to say, a work containing the Library or a
132portion of it, either verbatim or with modifications and/or translated
133straightforwardly into another language. (Hereinafter, translation is
134included without limitation in the term "modification".)
135
136 "Source code" for a work means the preferred form of the work for
137making modifications to it. For a library, complete source code means
138all the source code for all modules it contains, plus any associated
139interface definition files, plus the scripts used to control compilation
140and installation of the library.
141
142 Activities other than copying, distribution and modification are not
143covered by this License; they are outside its scope. The act of
144running a program using the Library is not restricted, and output from
145such a program is covered only if its contents constitute a work based
146on the Library (independent of the use of the Library in a tool for
147writing it). Whether that is true depends on what the Library does
148and what the program that uses the Library does.
149
150 1. You may copy and distribute verbatim copies of the Library's
151complete source code as you receive it, in any medium, provided that
152you conspicuously and appropriately publish on each copy an
153appropriate copyright notice and disclaimer of warranty; keep intact
154all the notices that refer to this License and to the absence of any
155warranty; and distribute a copy of this License along with the
156Library.
157
158 You may charge a fee for the physical act of transferring a copy,
159and you may at your option offer warranty protection in exchange for a
160fee.
161
162 2. You may modify your copy or copies of the Library or any portion
163of it, thus forming a work based on the Library, and copy and
164distribute such modifications or work under the terms of Section 1
165above, provided that you also meet all of these conditions:
166
167 a) The modified work must itself be a software library.
168
169 b) You must cause the files modified to carry prominent notices
170 stating that you changed the files and the date of any change.
171
172 c) You must cause the whole of the work to be licensed at no
173 charge to all third parties under the terms of this License.
174
175 d) If a facility in the modified Library refers to a function or a
176 table of data to be supplied by an application program that uses
177 the facility, other than as an argument passed when the facility
178 is invoked, then you must make a good faith effort to ensure that,
179 in the event an application does not supply such function or
180 table, the facility still operates, and performs whatever part of
181 its purpose remains meaningful.
182
183 (For example, a function in a library to compute square roots has
184 a purpose that is entirely well-defined independent of the
185 application. Therefore, Subsection 2d requires that any
186 application-supplied function or table used by this function must
187 be optional: if the application does not supply it, the square
188 root function must still compute square roots.)
189
190These requirements apply to the modified work as a whole. If
191identifiable sections of that work are not derived from the Library,
192and can be reasonably considered independent and separate works in
193themselves, then this License, and its terms, do not apply to those
194sections when you distribute them as separate works. But when you
195distribute the same sections as part of a whole which is a work based
196on the Library, the distribution of the whole must be on the terms of
197this License, whose permissions for other licensees extend to the
198entire whole, and thus to each and every part regardless of who wrote
199it.
200
201Thus, it is not the intent of this section to claim rights or contest
202your rights to work written entirely by you; rather, the intent is to
203exercise the right to control the distribution of derivative or
204collective works based on the Library.
205
206In addition, mere aggregation of another work not based on the Library
207with the Library (or with a work based on the Library) on a volume of
208a storage or distribution medium does not bring the other work under
209the scope of this License.
210
211 3. You may opt to apply the terms of the ordinary GNU General Public
212License instead of this License to a given copy of the Library. To do
213this, you must alter all the notices that refer to this License, so
214that they refer to the ordinary GNU General Public License, version 2,
215instead of to this License. (If a newer version than version 2 of the
216ordinary GNU General Public License has appeared, then you can specify
217that version instead if you wish.) Do not make any other change in
218these notices.
219
220 Once this change is made in a given copy, it is irreversible for
221that copy, so the ordinary GNU General Public License applies to all
222subsequent copies and derivative works made from that copy.
223
224 This option is useful when you wish to copy part of the code of
225the Library into a program that is not a library.
226
227 4. You may copy and distribute the Library (or a portion or
228derivative of it, under Section 2) in object code or executable form
229under the terms of Sections 1 and 2 above provided that you accompany
230it with the complete corresponding machine-readable source code, which
231must be distributed under the terms of Sections 1 and 2 above on a
232medium customarily used for software interchange.
233
234 If distribution of object code is made by offering access to copy
235from a designated place, then offering equivalent access to copy the
236source code from the same place satisfies the requirement to
237distribute the source code, even though third parties are not
238compelled to copy the source along with the object code.
239
240 5. A program that contains no derivative of any portion of the
241Library, but is designed to work with the Library by being compiled or
242linked with it, is called a "work that uses the Library". Such a
243work, in isolation, is not a derivative work of the Library, and
244therefore falls outside the scope of this License.
245
246 However, linking a "work that uses the Library" with the Library
247creates an executable that is a derivative of the Library (because it
248contains portions of the Library), rather than a "work that uses the
249library". The executable is therefore covered by this License.
250Section 6 states terms for distribution of such executables.
251
252 When a "work that uses the Library" uses material from a header file
253that is part of the Library, the object code for the work may be a
254derivative work of the Library even though the source code is not.
255Whether this is true is especially significant if the work can be
256linked without the Library, or if the work is itself a library. The
257threshold for this to be true is not precisely defined by law.
258
259 If such an object file uses only numerical parameters, data
260structure layouts and accessors, and small macros and small inline
261functions (ten lines or less in length), then the use of the object
262file is unrestricted, regardless of whether it is legally a derivative
263work. (Executables containing this object code plus portions of the
264Library will still fall under Section 6.)
265
266 Otherwise, if the work is a derivative of the Library, you may
267distribute the object code for the work under the terms of Section 6.
268Any executables containing that work also fall under Section 6,
269whether or not they are linked directly with the Library itself.
270
271 6. As an exception to the Sections above, you may also combine or
272link a "work that uses the Library" with the Library to produce a
273work containing portions of the Library, and distribute that work
274under terms of your choice, provided that the terms permit
275modification of the work for the customer's own use and reverse
276engineering for debugging such modifications.
277
278 You must give prominent notice with each copy of the work that the
279Library is used in it and that the Library and its use are covered by
280this License. You must supply a copy of this License. If the work
281during execution displays copyright notices, you must include the
282copyright notice for the Library among them, as well as a reference
283directing the user to the copy of this License. Also, you must do one
284of these things:
285
286 a) Accompany the work with the complete corresponding
287 machine-readable source code for the Library including whatever
288 changes were used in the work (which must be distributed under
289 Sections 1 and 2 above); and, if the work is an executable linked
290 with the Library, with the complete machine-readable "work that
291 uses the Library", as object code and/or source code, so that the
292 user can modify the Library and then relink to produce a modified
293 executable containing the modified Library. (It is understood
294 that the user who changes the contents of definitions files in the
295 Library will not necessarily be able to recompile the application
296 to use the modified definitions.)
297
298 b) Use a suitable shared library mechanism for linking with the
299 Library. A suitable mechanism is one that (1) uses at run time a
300 copy of the library already present on the user's computer system,
301 rather than copying library functions into the executable, and (2)
302 will operate properly with a modified version of the library, if
303 the user installs one, as long as the modified version is
304 interface-compatible with the version that the work was made with.
305
306 c) Accompany the work with a written offer, valid for at
307 least three years, to give the same user the materials
308 specified in Subsection 6a, above, for a charge no more
309 than the cost of performing this distribution.
310
311 d) If distribution of the work is made by offering access to copy
312 from a designated place, offer equivalent access to copy the above
313 specified materials from the same place.
314
315 e) Verify that the user has already received a copy of these
316 materials or that you have already sent this user a copy.
317
318 For an executable, the required form of the "work that uses the
319Library" must include any data and utility programs needed for
320reproducing the executable from it. However, as a special exception,
321the materials to be distributed need not include anything that is
322normally distributed (in either source or binary form) with the major
323components (compiler, kernel, and so on) of the operating system on
324which the executable runs, unless that component itself accompanies
325the executable.
326
327 It may happen that this requirement contradicts the license
328restrictions of other proprietary libraries that do not normally
329accompany the operating system. Such a contradiction means you cannot
330use both them and the Library together in an executable that you
331distribute.
332
333 7. You may place library facilities that are a work based on the
334Library side-by-side in a single library together with other library
335facilities not covered by this License, and distribute such a combined
336library, provided that the separate distribution of the work based on
337the Library and of the other library facilities is otherwise
338permitted, and provided that you do these two things:
339
340 a) Accompany the combined library with a copy of the same work
341 based on the Library, uncombined with any other library
342 facilities. This must be distributed under the terms of the
343 Sections above.
344
345 b) Give prominent notice with the combined library of the fact
346 that part of it is a work based on the Library, and explaining
347 where to find the accompanying uncombined form of the same work.
348
349 8. You may not copy, modify, sublicense, link with, or distribute
350the Library except as expressly provided under this License. Any
351attempt otherwise to copy, modify, sublicense, link with, or
352distribute the Library is void, and will automatically terminate your
353rights under this License. However, parties who have received copies,
354or rights, from you under this License will not have their licenses
355terminated so long as such parties remain in full compliance.
356
357 9. You are not required to accept this License, since you have not
358signed it. However, nothing else grants you permission to modify or
359distribute the Library or its derivative works. These actions are
360prohibited by law if you do not accept this License. Therefore, by
361modifying or distributing the Library (or any work based on the
362Library), you indicate your acceptance of this License to do so, and
363all its terms and conditions for copying, distributing or modifying
364the Library or works based on it.
365
366 10. Each time you redistribute the Library (or any work based on the
367Library), the recipient automatically receives a license from the
368original licensor to copy, distribute, link with or modify the Library
369subject to these terms and conditions. You may not impose any further
370restrictions on the recipients' exercise of the rights granted herein.
371You are not responsible for enforcing compliance by third parties with
372this License.
373
374 11. If, as a consequence of a court judgment or allegation of patent
375infringement or for any other reason (not limited to patent issues),
376conditions are imposed on you (whether by court order, agreement or
377otherwise) that contradict the conditions of this License, they do not
378excuse you from the conditions of this License. If you cannot
379distribute so as to satisfy simultaneously your obligations under this
380License and any other pertinent obligations, then as a consequence you
381may not distribute the Library at all. For example, if a patent
382license would not permit royalty-free redistribution of the Library by
383all those who receive copies directly or indirectly through you, then
384the only way you could satisfy both it and this License would be to
385refrain entirely from distribution of the Library.
386
387If any portion of this section is held invalid or unenforceable under any
388particular circumstance, the balance of the section is intended to apply,
389and the section as a whole is intended to apply in other circumstances.
390
391It is not the purpose of this section to induce you to infringe any
392patents or other property right claims or to contest validity of any
393such claims; this section has the sole purpose of protecting the
394integrity of the free software distribution system which is
395implemented by public license practices. Many people have made
396generous contributions to the wide range of software distributed
397through that system in reliance on consistent application of that
398system; it is up to the author/donor to decide if he or she is willing
399to distribute software through any other system and a licensee cannot
400impose that choice.
401
402This section is intended to make thoroughly clear what is believed to
403be a consequence of the rest of this License.
404
405 12. If the distribution and/or use of the Library is restricted in
406certain countries either by patents or by copyrighted interfaces, the
407original copyright holder who places the Library under this License may add
408an explicit geographical distribution limitation excluding those countries,
409so that distribution is permitted only in or among countries not thus
410excluded. In such case, this License incorporates the limitation as if
411written in the body of this License.
412
413 13. The Free Software Foundation may publish revised and/or new
414versions of the Lesser General Public License from time to time.
415Such new versions will be similar in spirit to the present version,
416but may differ in detail to address new problems or concerns.
417
418Each version is given a distinguishing version number. If the Library
419specifies a version number of this License which applies to it and
420"any later version", you have the option of following the terms and
421conditions either of that version or of any later version published by
422the Free Software Foundation. If the Library does not specify a
423license version number, you may choose any version ever published by
424the Free Software Foundation.
425
426 14. If you wish to incorporate parts of the Library into other free
427programs whose distribution conditions are incompatible with these,
428write to the author to ask for permission. For software which is
429copyrighted by the Free Software Foundation, write to the Free
430Software Foundation; we sometimes make exceptions for this. Our
431decision will be guided by the two goals of preserving the free status
432of all derivatives of our free software and of promoting the sharing
433and reuse of software generally.
434
435 NO WARRANTY
436
437 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
438WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
439EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
440OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
441KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
442IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
443PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
444LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
445THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
446
447 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
448WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
449AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
450FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
451CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
452LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
453RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
454FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
455SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456DAMAGES.
457
458 END OF TERMS AND CONDITIONS
diff --git a/rbutil/rbutilqt/quazip/README.ROCKBOX b/rbutil/rbutilqt/quazip/README.ROCKBOX
index b95f80caee..b4ffc270ae 100644
--- a/rbutil/rbutilqt/quazip/README.ROCKBOX
+++ b/rbutil/rbutilqt/quazip/README.ROCKBOX
@@ -1,6 +1,9 @@
1This folder contains the quazip project for ZIP file compression/decompression. 1This folder contains the quazip project for ZIP file compression/decompression.
2These files are distributed under the GPL v2 or later. 2These files are distributed under the LGPL v2.1 or later. Only source files
3The source files have been last synced with the projects release at 3actually used in Rockbox Utility are included, further sources have been left
4http://sourceforge.net/projects/quazip/ on July 20, 2010 4out. Check the quazip source distribution for those.
5
6The source files have been last synced with the projects release 0.7.1 at
7http://sourceforge.net/projects/quazip/ on March 8, 2015.
5 8
6 9
diff --git a/rbutil/rbutilqt/quazip/crypt.h b/rbutil/rbutilqt/quazip/crypt.h
index 359cf6726e..ddee28e7dd 100644
--- a/rbutil/rbutilqt/quazip/crypt.h
+++ b/rbutil/rbutilqt/quazip/crypt.h
@@ -27,17 +27,19 @@
27 Encryption is not supported. 27 Encryption is not supported.
28*/ 28*/
29 29
30#include "quazip_global.h"
31
30#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 32#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
31 33
32/*********************************************************************** 34/***********************************************************************
33 * Return the next byte in the pseudo-random sequence 35 * Return the next byte in the pseudo-random sequence
34 */ 36 */
35static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) 37static int decrypt_byte(unsigned long* pkeys, const z_crc_t FAR * pcrc_32_tab UNUSED)
36{ 38{
39 //(void) pcrc_32_tab; /* avoid "unused parameter" warning */
37 unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 40 unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
38 * unpredictable manner on 16-bit systems; not a problem 41 * unpredictable manner on 16-bit systems; not a problem
39 * with any known compiler so far, though */ 42 * with any known compiler so far, though */
40 (void) pcrc_32_tab; /* avoid "unused parameter" warning */
41 43
42 temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; 44 temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
43 return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); 45 return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
@@ -46,7 +48,7 @@ static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
46/*********************************************************************** 48/***********************************************************************
47 * Update the encryption keys with the next byte of plain text 49 * Update the encryption keys with the next byte of plain text
48 */ 50 */
49static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) 51static int update_keys(unsigned long* pkeys,const z_crc_t FAR * pcrc_32_tab,int c)
50{ 52{
51 (*(pkeys+0)) = CRC32((*(pkeys+0)), c); 53 (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
52 (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 54 (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
@@ -63,7 +65,7 @@ static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int
63 * Initialize the encryption keys and the random header according to 65 * Initialize the encryption keys and the random header according to
64 * the given password. 66 * the given password.
65 */ 67 */
66static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) 68static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t FAR * pcrc_32_tab)
67{ 69{
68 *(pkeys+0) = 305419896L; 70 *(pkeys+0) = 305419896L;
69 *(pkeys+1) = 591751049L; 71 *(pkeys+1) = 591751049L;
@@ -93,7 +95,7 @@ static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
93 unsigned char *buf; /* where to write header */ 95 unsigned char *buf; /* where to write header */
94 int bufSize; 96 int bufSize;
95 unsigned long* pkeys; 97 unsigned long* pkeys;
96 const unsigned long* pcrc_32_tab; 98 const z_crc_t FAR * pcrc_32_tab;
97 unsigned long crcForCrypting; 99 unsigned long crcForCrypting;
98{ 100{
99 int n; /* index in random header */ 101 int n; /* index in random header */
diff --git a/rbutil/rbutilqt/quazip/ioapi.c b/rbutil/rbutilqt/quazip/ioapi.c
deleted file mode 100644
index c43144006c..0000000000
--- a/rbutil/rbutilqt/quazip/ioapi.c
+++ /dev/null
@@ -1,184 +0,0 @@
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 FILE* file = NULL;
74 const char* mode_fopen = NULL;
75 (void) opaque; /* avoid "unused parameter" warning */
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 uLong ret;
98 (void) opaque; /* avoid "unused parameter" warning */
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 uLong ret;
111 (void) opaque; /* avoid "unused parameter" warning */
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 long ret;
121 (void) opaque; /* avoid "unused parameter" warning */
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 int fseek_origin=0;
133 long ret;
134 (void) opaque; /* avoid "unused parameter" warning */
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 int ret;
158 (void) opaque; /* avoid "unused parameter" warning */
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 int ret;
168 (void) opaque; /* avoid "unused parameter" warning */
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
index 7d457baab3..bbb94c8c76 100644
--- a/rbutil/rbutilqt/quazip/ioapi.h
+++ b/rbutil/rbutilqt/quazip/ioapi.h
@@ -1,14 +1,110 @@
1/* ioapi.h -- IO base function header for compress/uncompress .zip 1/* ioapi.h -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API 2 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
3 3
4 Version 1.01e, February 12th, 2005 4 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
5
6 Modifications for Zip64 support
7 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
8
9 Modified by Sergey A. Tachenov to allow QIODevice API usage.
10
11 For more info read MiniZip_info.txt
12
13 Changes
14
15 Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this)
16 Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
17 More if/def section may be needed to support other platforms
18 Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
19 (but you should use iowin32.c for windows instead)
5 20
6 Copyright (C) 1998-2005 Gilles Vollant
7*/ 21*/
8 22
9#ifndef _ZLIBIOAPI_H 23#ifndef _ZLIBIOAPI64_H
10#define _ZLIBIOAPI_H 24#define _ZLIBIOAPI64_H
25
26#if (!defined(_WIN32)) && (!defined(WIN32))
27
28 // Linux needs this to support file operation on files larger then 4+GB
29 // But might need better if/def to select just the platforms that needs them.
30
31 #ifndef __USE_FILE_OFFSET64
32 #define __USE_FILE_OFFSET64
33 #endif
34 #ifndef __USE_LARGEFILE64
35 #define __USE_LARGEFILE64
36 #endif
37 #ifndef _LARGEFILE64_SOURCE
38 #define _LARGEFILE64_SOURCE
39 #endif
40 #ifndef _FILE_OFFSET_BIT
41 #define _FILE_OFFSET_BIT 64
42 #endif
43#endif
44
45#include <stdio.h>
46#include <stdlib.h>
47#include "zlib.h"
48
49#if defined(USE_FILE32API)
50#define fopen64 fopen
51#define ftello64 ftell
52#define fseeko64 fseek
53#else
54#ifdef _MSC_VER
55 #define fopen64 fopen
56 #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
57 #define ftello64 _ftelli64
58 #define fseeko64 _fseeki64
59 #else // old MSC
60 #define ftello64 ftell
61 #define fseeko64 fseek
62 #endif
63#endif
64#endif
65
66/*
67#ifndef ZPOS64_T
68 #ifdef _WIN32
69 #define ZPOS64_T fpos_t
70 #else
71 #include <stdint.h>
72 #define ZPOS64_T uint64_t
73 #endif
74#endif
75*/
76
77#ifdef HAVE_MINIZIP64_CONF_H
78#include "mz64conf.h"
79#endif
80
81/* a type choosen by DEFINE */
82#ifdef HAVE_64BIT_INT_CUSTOM
83typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
84#else
85#ifdef HAS_STDINT_H
86#include "stdint.h"
87typedef uint64_t ZPOS64_T;
88#else
89
90
91#if defined(_MSC_VER) || defined(__BORLANDC__)
92typedef unsigned __int64 ZPOS64_T;
93#else
94typedef unsigned long long int ZPOS64_T;
95#endif
96#endif
97#endif
98
99
11 100
101#ifdef __cplusplus
102extern "C" {
103#endif
104
105#ifndef OF
106#define OF _Z_OF
107#endif
12 108
13#define ZLIB_FILEFUNC_SEEK_CUR (1) 109#define ZLIB_FILEFUNC_SEEK_CUR (1)
14#define ZLIB_FILEFUNC_SEEK_END (2) 110#define ZLIB_FILEFUNC_SEEK_END (2)
@@ -23,26 +119,27 @@
23 119
24 120
25#ifndef ZCALLBACK 121#ifndef ZCALLBACK
26 122 #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
27#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 123 #define ZCALLBACK CALLBACK
28#define ZCALLBACK CALLBACK 124 #else
29#else 125 #define ZCALLBACK
30#define ZCALLBACK 126 #endif
31#endif
32#endif 127#endif
33 128
34#ifdef __cplusplus
35extern "C" {
36#endif
37 129
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 130
131
132typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, voidpf file, int mode));
133typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
134typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
135typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
136typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
137
138typedef uLong (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
139typedef int (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
140
141
142/* here is the "old" 32 bits structure structure */
46typedef struct zlib_filefunc_def_s 143typedef struct zlib_filefunc_def_s
47{ 144{
48 open_file_func zopen_file; 145 open_file_func zopen_file;
@@ -55,21 +152,56 @@ typedef struct zlib_filefunc_def_s
55 voidpf opaque; 152 voidpf opaque;
56} zlib_filefunc_def; 153} zlib_filefunc_def;
57 154
155typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
156typedef int (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
157typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, voidpf file, int mode));
58 158
159typedef struct zlib_filefunc64_def_s
160{
161 open64_file_func zopen64_file;
162 read_file_func zread_file;
163 write_file_func zwrite_file;
164 tell64_file_func ztell64_file;
165 seek64_file_func zseek64_file;
166 close_file_func zclose_file;
167 testerror_file_func zerror_file;
168 voidpf opaque;
169 close_file_func zfakeclose_file; // for no-auto-close flag
170} zlib_filefunc64_def;
59 171
60void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 172void fill_qiodevice64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
173void fill_qiodevice_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
61 174
62#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) 175/* now internal definition, only for zip.c and unzip.h */
63#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) 176typedef struct zlib_filefunc64_32_def_s
64#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) 177{
65#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) 178 zlib_filefunc64_def zfile_func64;
66#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) 179 open_file_func zopen32_file;
67#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) 180 tell_file_func ztell32_file;
181 seek_file_func zseek32_file;
182} zlib_filefunc64_32_def;
183
184
185#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
186#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
187//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
188//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
189#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
190#define ZFAKECLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zfakeclose_file)) ((filefunc).zfile_func64.opaque,filestream))
191#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
68 192
193voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf file,int mode));
194int call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
195ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
196
197void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
198
199#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
200#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
201#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
69 202
70#ifdef __cplusplus 203#ifdef __cplusplus
71} 204}
72#endif 205#endif
73 206
74#endif 207#endif
75
diff --git a/rbutil/rbutilqt/quazip/qioapi.cpp b/rbutil/rbutilqt/quazip/qioapi.cpp
new file mode 100644
index 0000000000..534dbdf51f
--- /dev/null
+++ b/rbutil/rbutilqt/quazip/qioapi.cpp
@@ -0,0 +1,361 @@
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 Modified by Sergey A. Tachenov to integrate with Qt.
9*/
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14
15#include "zlib.h"
16#include "ioapi.h"
17#include "quazip_global.h"
18#include <QIODevice>
19#if (QT_VERSION >= 0x050100)
20#define QUAZIP_QSAVEFILE_BUG_WORKAROUND
21#endif
22#ifdef QUAZIP_QSAVEFILE_BUG_WORKAROUND
23#include <QSaveFile>
24#endif
25
26/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
27
28#ifndef SEEK_CUR
29#define SEEK_CUR 1
30#endif
31
32#ifndef SEEK_END
33#define SEEK_END 2
34#endif
35
36#ifndef SEEK_SET
37#define SEEK_SET 0
38#endif
39
40voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,voidpf file,int mode)
41{
42 if (pfilefunc->zfile_func64.zopen64_file != NULL)
43 return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,file,mode);
44 else
45 {
46 return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,file,mode);
47 }
48}
49
50int call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
51{
52 if (pfilefunc->zfile_func64.zseek64_file != NULL)
53 return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
54 else
55 {
56 uLong offsetTruncated = (uLong)offset;
57 if (offsetTruncated != offset)
58 return -1;
59 else
60 return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
61 }
62}
63
64ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
65{
66 if (pfilefunc->zfile_func64.zseek64_file != NULL)
67 return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
68 else
69 {
70 uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
71 if ((tell_uLong) == ((uLong)-1))
72 return (ZPOS64_T)-1;
73 else
74 return tell_uLong;
75 }
76}
77
78struct QIODevice_descriptor {
79 // Position only used for writing to sequential devices.
80 qint64 pos;
81 inline QIODevice_descriptor():
82 pos(0)
83 {}
84};
85
86voidpf ZCALLBACK qiodevice_open_file_func (
87 voidpf opaque,
88 voidpf file,
89 int mode)
90{
91 QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
92 QIODevice *iodevice = reinterpret_cast<QIODevice*>(file);
93 QIODevice::OpenMode desiredMode;
94 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
95 desiredMode = QIODevice::ReadOnly;
96 else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
97 desiredMode = QIODevice::ReadWrite;
98 else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
99 desiredMode = QIODevice::WriteOnly;
100 if (iodevice->isOpen()) {
101 if ((iodevice->openMode() & desiredMode) == desiredMode) {
102 if (desiredMode != QIODevice::WriteOnly
103 && iodevice->isSequential()) {
104 // We can use sequential devices only for writing.
105 delete d;
106 return NULL;
107 } else {
108 if ((desiredMode & QIODevice::WriteOnly) != 0) {
109 // open for writing, need to seek existing device
110 if (!iodevice->isSequential()) {
111 iodevice->seek(0);
112 } else {
113 d->pos = iodevice->pos();
114 }
115 }
116 }
117 return iodevice;
118 } else {
119 delete d;
120 return NULL;
121 }
122 }
123 iodevice->open(desiredMode);
124 if (iodevice->isOpen()) {
125 if (desiredMode != QIODevice::WriteOnly && iodevice->isSequential()) {
126 // We can use sequential devices only for writing.
127 iodevice->close();
128 delete d;
129 return NULL;
130 } else {
131 return iodevice;
132 }
133 } else {
134 delete d;
135 return NULL;
136 }
137}
138
139
140uLong ZCALLBACK qiodevice_read_file_func (
141 voidpf opaque,
142 voidpf stream,
143 void* buf,
144 uLong size)
145{
146 QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
147 QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
148 qint64 ret64 = iodevice->read((char*)buf,size);
149 uLong ret;
150 ret = (uLong) ret64;
151 if (ret64 != -1) {
152 d->pos += ret64;
153 }
154 return ret;
155}
156
157
158uLong ZCALLBACK qiodevice_write_file_func (
159 voidpf opaque,
160 voidpf stream,
161 const void* buf,
162 uLong size)
163{
164 QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
165 QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
166 uLong ret;
167 qint64 ret64 = iodevice->write((char*)buf,size);
168 if (ret64 != -1) {
169 d->pos += ret64;
170 }
171 ret = (uLong) ret64;
172 return ret;
173}
174
175uLong ZCALLBACK qiodevice_tell_file_func (
176 voidpf opaque,
177 voidpf stream)
178{
179 QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
180 QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
181 uLong ret;
182 qint64 ret64;
183 if (iodevice->isSequential()) {
184 ret64 = d->pos;
185 } else {
186 ret64 = iodevice->pos();
187 }
188 ret = static_cast<uLong>(ret64);
189 return ret;
190}
191
192ZPOS64_T ZCALLBACK qiodevice64_tell_file_func (
193 voidpf opaque,
194 voidpf stream)
195{
196 QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
197 QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
198 qint64 ret;
199 if (iodevice->isSequential()) {
200 ret = d->pos;
201 } else {
202 ret = iodevice->pos();
203 }
204 return static_cast<ZPOS64_T>(ret);
205}
206
207int ZCALLBACK qiodevice_seek_file_func (
208 voidpf /*opaque UNUSED*/,
209 voidpf stream,
210 uLong offset,
211 int origin)
212{
213 QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
214 if (iodevice->isSequential()) {
215 if (origin == ZLIB_FILEFUNC_SEEK_END
216 && offset == 0) {
217 // sequential devices are always at end (needed in mdAppend)
218 return 0;
219 } else {
220 qWarning("qiodevice_seek_file_func() called for sequential device");
221 return -1;
222 }
223 }
224 uLong qiodevice_seek_result=0;
225 int ret;
226 switch (origin)
227 {
228 case ZLIB_FILEFUNC_SEEK_CUR :
229 qiodevice_seek_result = ((QIODevice*)stream)->pos() + offset;
230 break;
231 case ZLIB_FILEFUNC_SEEK_END :
232 qiodevice_seek_result = ((QIODevice*)stream)->size() - offset;
233 break;
234 case ZLIB_FILEFUNC_SEEK_SET :
235 qiodevice_seek_result = offset;
236 break;
237 default:
238 return -1;
239 }
240 ret = !iodevice->seek(qiodevice_seek_result);
241 return ret;
242}
243
244int ZCALLBACK qiodevice64_seek_file_func (
245 voidpf /*opaque UNUSED*/,
246 voidpf stream,
247 ZPOS64_T offset,
248 int origin)
249{
250 QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
251 if (iodevice->isSequential()) {
252 if (origin == ZLIB_FILEFUNC_SEEK_END
253 && offset == 0) {
254 // sequential devices are always at end (needed in mdAppend)
255 return 0;
256 } else {
257 qWarning("qiodevice_seek_file_func() called for sequential device");
258 return -1;
259 }
260 }
261 qint64 qiodevice_seek_result=0;
262 int ret;
263 switch (origin)
264 {
265 case ZLIB_FILEFUNC_SEEK_CUR :
266 qiodevice_seek_result = ((QIODevice*)stream)->pos() + offset;
267 break;
268 case ZLIB_FILEFUNC_SEEK_END :
269 qiodevice_seek_result = ((QIODevice*)stream)->size() - offset;
270 break;
271 case ZLIB_FILEFUNC_SEEK_SET :
272 qiodevice_seek_result = offset;
273 break;
274 default:
275 return -1;
276 }
277 ret = !iodevice->seek(qiodevice_seek_result);
278 return ret;
279}
280
281int ZCALLBACK qiodevice_close_file_func (
282 voidpf opaque,
283 voidpf stream)
284{
285 QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
286 delete d;
287 QIODevice *device = reinterpret_cast<QIODevice*>(stream);
288#ifdef QUAZIP_QSAVEFILE_BUG_WORKAROUND
289 // QSaveFile terribly breaks the is-a idiom:
290 // it IS a QIODevice, but it is NOT compatible with it: close() is private
291 QSaveFile *file = qobject_cast<QSaveFile*>(device);
292 if (file != NULL) {
293 // We have to call the ugly commit() instead:
294 return file->commit() ? 0 : -1;
295 }
296#endif
297 device->close();
298 return 0;
299}
300
301int ZCALLBACK qiodevice_fakeclose_file_func (
302 voidpf opaque,
303 voidpf /*stream*/)
304{
305 QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
306 delete d;
307 return 0;
308}
309
310int ZCALLBACK qiodevice_error_file_func (
311 voidpf /*opaque UNUSED*/,
312 voidpf /*stream UNUSED*/)
313{
314 // can't check for error due to the QIODevice API limitation
315 return 0;
316}
317
318void fill_qiodevice_filefunc (
319 zlib_filefunc_def* pzlib_filefunc_def)
320{
321 pzlib_filefunc_def->zopen_file = qiodevice_open_file_func;
322 pzlib_filefunc_def->zread_file = qiodevice_read_file_func;
323 pzlib_filefunc_def->zwrite_file = qiodevice_write_file_func;
324 pzlib_filefunc_def->ztell_file = qiodevice_tell_file_func;
325 pzlib_filefunc_def->zseek_file = qiodevice_seek_file_func;
326 pzlib_filefunc_def->zclose_file = qiodevice_close_file_func;
327 pzlib_filefunc_def->zerror_file = qiodevice_error_file_func;
328 pzlib_filefunc_def->opaque = new QIODevice_descriptor;
329}
330
331void fill_qiodevice64_filefunc (
332 zlib_filefunc64_def* pzlib_filefunc_def)
333{
334 // Open functions are the same for Qt.
335 pzlib_filefunc_def->zopen64_file = qiodevice_open_file_func;
336 pzlib_filefunc_def->zread_file = qiodevice_read_file_func;
337 pzlib_filefunc_def->zwrite_file = qiodevice_write_file_func;
338 pzlib_filefunc_def->ztell64_file = qiodevice64_tell_file_func;
339 pzlib_filefunc_def->zseek64_file = qiodevice64_seek_file_func;
340 pzlib_filefunc_def->zclose_file = qiodevice_close_file_func;
341 pzlib_filefunc_def->zerror_file = qiodevice_error_file_func;
342 pzlib_filefunc_def->opaque = new QIODevice_descriptor;
343 pzlib_filefunc_def->zfakeclose_file = qiodevice_fakeclose_file_func;
344}
345
346void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
347{
348 p_filefunc64_32->zfile_func64.zopen64_file = NULL;
349 p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
350 p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
351 p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
352 p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
353 p_filefunc64_32->zfile_func64.ztell64_file = NULL;
354 p_filefunc64_32->zfile_func64.zseek64_file = NULL;
355 p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
356 p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
357 p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
358 p_filefunc64_32->zfile_func64.zfakeclose_file = NULL;
359 p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
360 p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
361}
diff --git a/rbutil/rbutilqt/quazip/quazip.cpp b/rbutil/rbutilqt/quazip/quazip.cpp
index 3f7314a433..e3623c76e3 100644
--- a/rbutil/rbutilqt/quazip/quazip.cpp
+++ b/rbutil/rbutilqt/quazip/quazip.cpp
@@ -1,94 +1,321 @@
1/* 1/*
2-- A kind of "standard" GPL license statement -- 2Copyright (C) 2005-2014 Sergey A. Tachenov
3QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package 3
4Copyright (C) 2005-2007 Sergey A. Tachenov 4This file is part of QuaZIP.
5 5
6This program is free software; you can redistribute it and/or modify it 6QuaZIP is free software: you can redistribute it and/or modify
7under the terms of the GNU General Public License as published by the 7it under the terms of the GNU Lesser General Public License as published by
8Free Software Foundation; either version 2 of the License, or (at your 8the Free Software Foundation, either version 2.1 of the License, or
9option) any later version. 9(at your option) any later version.
10 10
11This program is distributed in the hope that it will be useful, but 11QuaZIP is distributed in the hope that it will be useful,
12WITHOUT ANY WARRANTY; without even the implied warranty of 12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14Public License for more details. 14GNU Lesser General Public License for more details.
15 15
16You should have received a copy of the GNU General Public License along 16You should have received a copy of the GNU Lesser General Public License
17with this program; if not, write to the Free Software Foundation, Inc., 17along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
1859 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18
19 19See COPYING file for the full LGPL text.
20-- A kind of "standard" GPL license statement ends here -- 20
21 21Original ZIP package is copyrighted by Gilles Vollant, see
22See COPYING file for GPL. 22quazip/(un)zip.h files for details, basically it's zlib license.
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 **/ 23 **/
32 24
33#include <QFile> 25#include <QFile>
26#include <QFlags>
27#include <QHash>
34 28
35#include "quazip.h" 29#include "quazip.h"
36 30
31/// All the internal stuff for the QuaZip class.
32/**
33 \internal
34
35 This class keeps all the private stuff for the QuaZip class so it can
36 be changed without breaking binary compatibility, according to the
37 Pimpl idiom.
38 */
39class QuaZipPrivate {
40 friend class QuaZip;
41 private:
42 /// The pointer to the corresponding QuaZip instance.
43 QuaZip *q;
44 /// The codec for file names.
45 QTextCodec *fileNameCodec;
46 /// The codec for comments.
47 QTextCodec *commentCodec;
48 /// The archive file name.
49 QString zipName;
50 /// The device to access the archive.
51 QIODevice *ioDevice;
52 /// The global comment.
53 QString comment;
54 /// The open mode.
55 QuaZip::Mode mode;
56 union {
57 /// The internal handle for UNZIP modes.
58 unzFile unzFile_f;
59 /// The internal handle for ZIP modes.
60 zipFile zipFile_f;
61 };
62 /// Whether a current file is set.
63 bool hasCurrentFile_f;
64 /// The last error.
65 int zipError;
66 /// Whether \ref QuaZip::setDataDescriptorWritingEnabled() "the data descriptor writing mode" is enabled.
67 bool dataDescriptorWritingEnabled;
68 /// The zip64 mode.
69 bool zip64;
70 /// The auto-close flag.
71 bool autoClose;
72 inline QTextCodec *getDefaultFileNameCodec()
73 {
74 if (defaultFileNameCodec == NULL) {
75 return QTextCodec::codecForLocale();
76 } else {
77 return defaultFileNameCodec;
78 }
79 }
80 /// The constructor for the corresponding QuaZip constructor.
81 inline QuaZipPrivate(QuaZip *q):
82 q(q),
83 fileNameCodec(getDefaultFileNameCodec()),
84 commentCodec(QTextCodec::codecForLocale()),
85 ioDevice(NULL),
86 mode(QuaZip::mdNotOpen),
87 hasCurrentFile_f(false),
88 zipError(UNZ_OK),
89 dataDescriptorWritingEnabled(true),
90 zip64(false),
91 autoClose(true)
92 {
93 lastMappedDirectoryEntry.num_of_file = 0;
94 lastMappedDirectoryEntry.pos_in_zip_directory = 0;
95 }
96 /// The constructor for the corresponding QuaZip constructor.
97 inline QuaZipPrivate(QuaZip *q, const QString &zipName):
98 q(q),
99 fileNameCodec(getDefaultFileNameCodec()),
100 commentCodec(QTextCodec::codecForLocale()),
101 zipName(zipName),
102 ioDevice(NULL),
103 mode(QuaZip::mdNotOpen),
104 hasCurrentFile_f(false),
105 zipError(UNZ_OK),
106 dataDescriptorWritingEnabled(true),
107 zip64(false),
108 autoClose(true)
109 {
110 lastMappedDirectoryEntry.num_of_file = 0;
111 lastMappedDirectoryEntry.pos_in_zip_directory = 0;
112 }
113 /// The constructor for the corresponding QuaZip constructor.
114 inline QuaZipPrivate(QuaZip *q, QIODevice *ioDevice):
115 q(q),
116 fileNameCodec(getDefaultFileNameCodec()),
117 commentCodec(QTextCodec::codecForLocale()),
118 ioDevice(ioDevice),
119 mode(QuaZip::mdNotOpen),
120 hasCurrentFile_f(false),
121 zipError(UNZ_OK),
122 dataDescriptorWritingEnabled(true),
123 zip64(false),
124 autoClose(true)
125 {
126 lastMappedDirectoryEntry.num_of_file = 0;
127 lastMappedDirectoryEntry.pos_in_zip_directory = 0;
128 }
129 /// Returns either a list of file names or a list of QuaZipFileInfo.
130 template<typename TFileInfo>
131 bool getFileInfoList(QList<TFileInfo> *result) const;
132
133 /// Stores map of filenames and file locations for unzipping
134 inline void clearDirectoryMap();
135 inline void addCurrentFileToDirectoryMap(const QString &fileName);
136 bool goToFirstUnmappedFile();
137 QHash<QString, unz64_file_pos> directoryCaseSensitive;
138 QHash<QString, unz64_file_pos> directoryCaseInsensitive;
139 unz64_file_pos lastMappedDirectoryEntry;
140 static QTextCodec *defaultFileNameCodec;
141};
142
143QTextCodec *QuaZipPrivate::defaultFileNameCodec = NULL;
144
145void QuaZipPrivate::clearDirectoryMap()
146{
147 directoryCaseInsensitive.clear();
148 directoryCaseSensitive.clear();
149 lastMappedDirectoryEntry.num_of_file = 0;
150 lastMappedDirectoryEntry.pos_in_zip_directory = 0;
151}
152
153void QuaZipPrivate::addCurrentFileToDirectoryMap(const QString &fileName)
154{
155 if (!hasCurrentFile_f || fileName.isEmpty()) {
156 return;
157 }
158 // Adds current file to filename map as fileName
159 unz64_file_pos fileDirectoryPos;
160 unzGetFilePos64(unzFile_f, &fileDirectoryPos);
161 directoryCaseSensitive.insert(fileName, fileDirectoryPos);
162 // Only add lowercase to directory map if not already there
163 // ensures only map the first one seen
164 QString lower = fileName.toLower();
165 if (!directoryCaseInsensitive.contains(lower))
166 directoryCaseInsensitive.insert(lower, fileDirectoryPos);
167 // Mark last one
168 if (fileDirectoryPos.pos_in_zip_directory > lastMappedDirectoryEntry.pos_in_zip_directory)
169 lastMappedDirectoryEntry = fileDirectoryPos;
170}
171
172bool QuaZipPrivate::goToFirstUnmappedFile()
173{
174 zipError = UNZ_OK;
175 if (mode != QuaZip::mdUnzip) {
176 qWarning("QuaZipPrivate::goToNextUnmappedFile(): ZIP is not open in mdUnzip mode");
177 return false;
178 }
179 // If not mapped anything, go to beginning
180 if (lastMappedDirectoryEntry.pos_in_zip_directory == 0) {
181 unzGoToFirstFile(unzFile_f);
182 } else {
183 // Goto the last one mapped, plus one
184 unzGoToFilePos64(unzFile_f, &lastMappedDirectoryEntry);
185 unzGoToNextFile(unzFile_f);
186 }
187 hasCurrentFile_f=zipError==UNZ_OK;
188 if(zipError==UNZ_END_OF_LIST_OF_FILE)
189 zipError=UNZ_OK;
190 return hasCurrentFile_f;
191}
192
37QuaZip::QuaZip(): 193QuaZip::QuaZip():
38 fileNameCodec(QTextCodec::codecForLocale()), 194 p(new QuaZipPrivate(this))
39 commentCodec(QTextCodec::codecForLocale()),
40 mode(mdNotOpen), hasCurrentFile_f(false), zipError(UNZ_OK)
41{ 195{
42} 196}
43 197
44QuaZip::QuaZip(const QString& zipName): 198QuaZip::QuaZip(const QString& zipName):
45 fileNameCodec(QTextCodec::codecForLocale()), 199 p(new QuaZipPrivate(this, zipName))
46 commentCodec(QTextCodec::codecForLocale()), 200{
47 zipName(zipName), 201}
48 mode(mdNotOpen), hasCurrentFile_f(false), zipError(UNZ_OK) 202
203QuaZip::QuaZip(QIODevice *ioDevice):
204 p(new QuaZipPrivate(this, ioDevice))
49{ 205{
50} 206}
51 207
52QuaZip::~QuaZip() 208QuaZip::~QuaZip()
53{ 209{
54 if(isOpen()) close(); 210 if(isOpen())
211 close();
212 delete p;
55} 213}
56 214
57bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi) 215bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
58{ 216{
59 zipError=UNZ_OK; 217 p->zipError=UNZ_OK;
60 if(isOpen()) { 218 if(isOpen()) {
61 qWarning("QuaZip::open(): ZIP already opened"); 219 qWarning("QuaZip::open(): ZIP already opened");
62 return false; 220 return false;
63 } 221 }
222 QIODevice *ioDevice = p->ioDevice;
223 if (ioDevice == NULL) {
224 if (p->zipName.isEmpty()) {
225 qWarning("QuaZip::open(): set either ZIP file name or IO device first");
226 return false;
227 } else {
228 ioDevice = new QFile(p->zipName);
229 }
230 }
231 unsigned flags = 0;
64 switch(mode) { 232 switch(mode) {
65 case mdUnzip: 233 case mdUnzip:
66 unzFile_f=unzOpen2(QFile::encodeName(zipName).constData(), ioApi); 234 if (ioApi == NULL) {
67 if(unzFile_f!=NULL) { 235 if (p->autoClose)
68 this->mode=mode; 236 flags |= UNZ_AUTO_CLOSE;
237 p->unzFile_f=unzOpenInternal(ioDevice, NULL, 1, flags);
238 } else {
239 // QuaZIP pre-zip64 compatibility mode
240 p->unzFile_f=unzOpen2(ioDevice, ioApi);
241 if (p->unzFile_f != NULL) {
242 if (p->autoClose) {
243 unzSetFlags(p->unzFile_f, UNZ_AUTO_CLOSE);
244 } else {
245 unzClearFlags(p->unzFile_f, UNZ_AUTO_CLOSE);
246 }
247 }
248 }
249 if(p->unzFile_f!=NULL) {
250 if (ioDevice->isSequential()) {
251 unzClose(p->unzFile_f);
252 if (!p->zipName.isEmpty())
253 delete ioDevice;
254 qWarning("QuaZip::open(): "
255 "only mdCreate can be used with "
256 "sequential devices");
257 return false;
258 }
259 p->mode=mode;
260 p->ioDevice = ioDevice;
69 return true; 261 return true;
70 } else { 262 } else {
71 zipError=UNZ_OPENERROR; 263 p->zipError=UNZ_OPENERROR;
264 if (!p->zipName.isEmpty())
265 delete ioDevice;
72 return false; 266 return false;
73 } 267 }
74 case mdCreate: 268 case mdCreate:
75 case mdAppend: 269 case mdAppend:
76 case mdAdd: 270 case mdAdd:
77 zipFile_f=zipOpen2(QFile::encodeName(zipName).constData(), 271 if (ioApi == NULL) {
78 mode==mdCreate?APPEND_STATUS_CREATE: 272 if (p->autoClose)
79 mode==mdAppend?APPEND_STATUS_CREATEAFTER: 273 flags |= ZIP_AUTO_CLOSE;
80 APPEND_STATUS_ADDINZIP, 274 if (p->dataDescriptorWritingEnabled)
81 NULL, 275 flags |= ZIP_WRITE_DATA_DESCRIPTOR;
82 ioApi); 276 p->zipFile_f=zipOpen3(ioDevice,
83 if(zipFile_f!=NULL) { 277 mode==mdCreate?APPEND_STATUS_CREATE:
84 this->mode=mode; 278 mode==mdAppend?APPEND_STATUS_CREATEAFTER:
279 APPEND_STATUS_ADDINZIP,
280 NULL, NULL, flags);
281 } else {
282 // QuaZIP pre-zip64 compatibility mode
283 p->zipFile_f=zipOpen2(ioDevice,
284 mode==mdCreate?APPEND_STATUS_CREATE:
285 mode==mdAppend?APPEND_STATUS_CREATEAFTER:
286 APPEND_STATUS_ADDINZIP,
287 NULL,
288 ioApi);
289 if (p->zipFile_f != NULL) {
290 zipSetFlags(p->zipFile_f, flags);
291 }
292 }
293 if(p->zipFile_f!=NULL) {
294 if (ioDevice->isSequential()) {
295 if (mode != mdCreate) {
296 zipClose(p->zipFile_f, NULL);
297 qWarning("QuaZip::open(): "
298 "only mdCreate can be used with "
299 "sequential devices");
300 if (!p->zipName.isEmpty())
301 delete ioDevice;
302 return false;
303 }
304 zipSetFlags(p->zipFile_f, ZIP_SEQUENTIAL);
305 }
306 p->mode=mode;
307 p->ioDevice = ioDevice;
85 return true; 308 return true;
86 } else { 309 } else {
87 zipError=UNZ_OPENERROR; 310 p->zipError=UNZ_OPENERROR;
311 if (!p->zipName.isEmpty())
312 delete ioDevice;
88 return false; 313 return false;
89 } 314 }
90 default: 315 default:
91 qWarning("QuaZip::open(): unknown mode: %d", (int)mode); 316 qWarning("QuaZip::open(): unknown mode: %d", (int)mode);
317 if (!p->zipName.isEmpty())
318 delete ioDevice;
92 return false; 319 return false;
93 break; 320 break;
94 } 321 }
@@ -96,24 +323,33 @@ bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
96 323
97void QuaZip::close() 324void QuaZip::close()
98{ 325{
99 zipError=UNZ_OK; 326 p->zipError=UNZ_OK;
100 switch(mode) { 327 switch(p->mode) {
101 case mdNotOpen: 328 case mdNotOpen:
102 qWarning("QuaZip::close(): ZIP is not open"); 329 qWarning("QuaZip::close(): ZIP is not open");
103 return; 330 return;
104 case mdUnzip: 331 case mdUnzip:
105 zipError=unzClose(unzFile_f); 332 p->zipError=unzClose(p->unzFile_f);
106 break; 333 break;
107 case mdCreate: 334 case mdCreate:
108 case mdAppend: 335 case mdAppend:
109 case mdAdd: 336 case mdAdd:
110 zipError=zipClose(zipFile_f, commentCodec->fromUnicode(comment).constData()); 337 p->zipError=zipClose(p->zipFile_f,
338 p->comment.isNull() ? NULL
339 : p->commentCodec->fromUnicode(p->comment).constData());
111 break; 340 break;
112 default: 341 default:
113 qWarning("QuaZip::close(): unknown mode: %d", (int)mode); 342 qWarning("QuaZip::close(): unknown mode: %d", (int)p->mode);
114 return; 343 return;
115 } 344 }
116 if(zipError==UNZ_OK) mode=mdNotOpen; 345 // opened by name, need to delete the internal IO device
346 if (!p->zipName.isEmpty()) {
347 delete p->ioDevice;
348 p->ioDevice = NULL;
349 }
350 p->clearDirectoryMap();
351 if(p->zipError==UNZ_OK)
352 p->mode=mdNotOpen;
117} 353}
118 354
119void QuaZip::setZipName(const QString& zipName) 355void QuaZip::setZipName(const QString& zipName)
@@ -122,129 +358,171 @@ void QuaZip::setZipName(const QString& zipName)
122 qWarning("QuaZip::setZipName(): ZIP is already open!"); 358 qWarning("QuaZip::setZipName(): ZIP is already open!");
123 return; 359 return;
124 } 360 }
125 this->zipName=zipName; 361 p->zipName=zipName;
362 p->ioDevice = NULL;
363}
364
365void QuaZip::setIoDevice(QIODevice *ioDevice)
366{
367 if(isOpen()) {
368 qWarning("QuaZip::setIoDevice(): ZIP is already open!");
369 return;
370 }
371 p->ioDevice = ioDevice;
372 p->zipName = QString();
126} 373}
127 374
128int QuaZip::getEntriesCount()const 375int QuaZip::getEntriesCount()const
129{ 376{
130 QuaZip *fakeThis=(QuaZip*)this; // non-const 377 QuaZip *fakeThis=(QuaZip*)this; // non-const
131 fakeThis->zipError=UNZ_OK; 378 fakeThis->p->zipError=UNZ_OK;
132 if(mode!=mdUnzip) { 379 if(p->mode!=mdUnzip) {
133 qWarning("QuaZip::getEntriesCount(): ZIP is not open in mdUnzip mode"); 380 qWarning("QuaZip::getEntriesCount(): ZIP is not open in mdUnzip mode");
134 return -1; 381 return -1;
135 } 382 }
136 unz_global_info globalInfo; 383 unz_global_info64 globalInfo;
137 if((fakeThis->zipError=unzGetGlobalInfo(unzFile_f, &globalInfo))!=UNZ_OK) 384 if((fakeThis->p->zipError=unzGetGlobalInfo64(p->unzFile_f, &globalInfo))!=UNZ_OK)
138 return zipError; 385 return p->zipError;
139 return (int)globalInfo.number_entry; 386 return (int)globalInfo.number_entry;
140} 387}
141 388
142QString QuaZip::getComment()const 389QString QuaZip::getComment()const
143{ 390{
144 QuaZip *fakeThis=(QuaZip*)this; // non-const 391 QuaZip *fakeThis=(QuaZip*)this; // non-const
145 fakeThis->zipError=UNZ_OK; 392 fakeThis->p->zipError=UNZ_OK;
146 if(mode!=mdUnzip) { 393 if(p->mode!=mdUnzip) {
147 qWarning("QuaZip::getComment(): ZIP is not open in mdUnzip mode"); 394 qWarning("QuaZip::getComment(): ZIP is not open in mdUnzip mode");
148 return QString(); 395 return QString();
149 } 396 }
150 unz_global_info globalInfo; 397 unz_global_info64 globalInfo;
151 QByteArray comment; 398 QByteArray comment;
152 if((fakeThis->zipError=unzGetGlobalInfo(unzFile_f, &globalInfo))!=UNZ_OK) 399 if((fakeThis->p->zipError=unzGetGlobalInfo64(p->unzFile_f, &globalInfo))!=UNZ_OK)
153 return QString(); 400 return QString();
154 comment.resize(globalInfo.size_comment); 401 comment.resize(globalInfo.size_comment);
155 if((fakeThis->zipError=unzGetGlobalComment(unzFile_f, comment.data(), comment.size()))!=UNZ_OK) 402 if((fakeThis->p->zipError=unzGetGlobalComment(p->unzFile_f, comment.data(), comment.size())) < 0)
156 return QString(); 403 return QString();
157 return commentCodec->toUnicode(comment); 404 fakeThis->p->zipError = UNZ_OK;
405 return p->commentCodec->toUnicode(comment);
158} 406}
159 407
160bool QuaZip::setCurrentFile(const QString& fileName, CaseSensitivity cs) 408bool QuaZip::setCurrentFile(const QString& fileName, CaseSensitivity cs)
161{ 409{
162 zipError=UNZ_OK; 410 p->zipError=UNZ_OK;
163 if(mode!=mdUnzip) { 411 if(p->mode!=mdUnzip) {
164 qWarning("QuaZip::setCurrentFile(): ZIP is not open in mdUnzip mode"); 412 qWarning("QuaZip::setCurrentFile(): ZIP is not open in mdUnzip mode");
165 return false; 413 return false;
166 } 414 }
167 if(fileName.isNull()) { 415 if(fileName.isEmpty()) {
168 hasCurrentFile_f=false; 416 p->hasCurrentFile_f=false;
169 return true; 417 return true;
170 } 418 }
171 // Unicode-aware reimplementation of the unzLocateFile function 419 // Unicode-aware reimplementation of the unzLocateFile function
172 if(unzFile_f==NULL) { 420 if(p->unzFile_f==NULL) {
173 zipError=UNZ_PARAMERROR; 421 p->zipError=UNZ_PARAMERROR;
174 return false; 422 return false;
175 } 423 }
176 if(fileName.length()>MAX_FILE_NAME_LENGTH) { 424 if(fileName.length()>MAX_FILE_NAME_LENGTH) {
177 zipError=UNZ_PARAMERROR; 425 p->zipError=UNZ_PARAMERROR;
178 return false; 426 return false;
179 } 427 }
180 bool sens; 428 // Find the file by name
181 if(cs==csDefault) { 429 bool sens = convertCaseSensitivity(cs) == Qt::CaseSensitive;
182#ifdef Q_WS_WIN
183 sens=false;
184#else
185 sens=true;
186#endif
187 } else sens=cs==csSensitive;
188 QString lower, current; 430 QString lower, current;
189 if(!sens) lower=fileName.toLower(); 431 if(!sens) lower=fileName.toLower();
190 hasCurrentFile_f=false; 432 p->hasCurrentFile_f=false;
191 for(bool more=goToFirstFile(); more; more=goToNextFile()) { 433
434 // Check the appropriate Map
435 unz64_file_pos fileDirPos;
436 fileDirPos.pos_in_zip_directory = 0;
437 if (sens) {
438 if (p->directoryCaseSensitive.contains(fileName))
439 fileDirPos = p->directoryCaseSensitive.value(fileName);
440 } else {
441 if (p->directoryCaseInsensitive.contains(lower))
442 fileDirPos = p->directoryCaseInsensitive.value(lower);
443 }
444
445 if (fileDirPos.pos_in_zip_directory != 0) {
446 p->zipError = unzGoToFilePos64(p->unzFile_f, &fileDirPos);
447 p->hasCurrentFile_f = p->zipError == UNZ_OK;
448 }
449
450 if (p->hasCurrentFile_f)
451 return p->hasCurrentFile_f;
452
453 // Not mapped yet, start from where we have got to so far
454 for(bool more=p->goToFirstUnmappedFile(); more; more=goToNextFile()) {
192 current=getCurrentFileName(); 455 current=getCurrentFileName();
193 if(current.isNull()) return false; 456 if(current.isEmpty()) return false;
194 if(sens) { 457 if(sens) {
195 if(current==fileName) break; 458 if(current==fileName) break;
196 } else { 459 } else {
197 if(current.toLower()==lower) break; 460 if(current.toLower()==lower) break;
198 } 461 }
199 } 462 }
200 return hasCurrentFile_f; 463 return p->hasCurrentFile_f;
201} 464}
202 465
203bool QuaZip::goToFirstFile() 466bool QuaZip::goToFirstFile()
204{ 467{
205 zipError=UNZ_OK; 468 p->zipError=UNZ_OK;
206 if(mode!=mdUnzip) { 469 if(p->mode!=mdUnzip) {
207 qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode"); 470 qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode");
208 return false; 471 return false;
209 } 472 }
210 zipError=unzGoToFirstFile(unzFile_f); 473 p->zipError=unzGoToFirstFile(p->unzFile_f);
211 hasCurrentFile_f=zipError==UNZ_OK; 474 p->hasCurrentFile_f=p->zipError==UNZ_OK;
212 return hasCurrentFile_f; 475 return p->hasCurrentFile_f;
213} 476}
214 477
215bool QuaZip::goToNextFile() 478bool QuaZip::goToNextFile()
216{ 479{
217 zipError=UNZ_OK; 480 p->zipError=UNZ_OK;
218 if(mode!=mdUnzip) { 481 if(p->mode!=mdUnzip) {
219 qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode"); 482 qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode");
220 return false; 483 return false;
221 } 484 }
222 zipError=unzGoToNextFile(unzFile_f); 485 p->zipError=unzGoToNextFile(p->unzFile_f);
223 hasCurrentFile_f=zipError==UNZ_OK; 486 p->hasCurrentFile_f=p->zipError==UNZ_OK;
224 if(zipError==UNZ_END_OF_LIST_OF_FILE) zipError=UNZ_OK; 487 if(p->zipError==UNZ_END_OF_LIST_OF_FILE)
225 return hasCurrentFile_f; 488 p->zipError=UNZ_OK;
489 return p->hasCurrentFile_f;
226} 490}
227 491
228bool QuaZip::getCurrentFileInfo(QuaZipFileInfo *info)const 492bool QuaZip::getCurrentFileInfo(QuaZipFileInfo *info)const
229{ 493{
494 QuaZipFileInfo64 info64;
495 if (info == NULL) { // Very unlikely because of the overloads
496 return false;
497 }
498 if (getCurrentFileInfo(&info64)) {
499 info64.toQuaZipFileInfo(*info);
500 return true;
501 } else {
502 return false;
503 }
504}
505
506bool QuaZip::getCurrentFileInfo(QuaZipFileInfo64 *info)const
507{
230 QuaZip *fakeThis=(QuaZip*)this; // non-const 508 QuaZip *fakeThis=(QuaZip*)this; // non-const
231 fakeThis->zipError=UNZ_OK; 509 fakeThis->p->zipError=UNZ_OK;
232 if(mode!=mdUnzip) { 510 if(p->mode!=mdUnzip) {
233 qWarning("QuaZip::getCurrentFileInfo(): ZIP is not open in mdUnzip mode"); 511 qWarning("QuaZip::getCurrentFileInfo(): ZIP is not open in mdUnzip mode");
234 return false; 512 return false;
235 } 513 }
236 unz_file_info info_z; 514 unz_file_info64 info_z;
237 QByteArray fileName; 515 QByteArray fileName;
238 QByteArray extra; 516 QByteArray extra;
239 QByteArray comment; 517 QByteArray comment;
240 if(info==NULL) return false; 518 if(info==NULL) return false;
241 if(!isOpen()||!hasCurrentFile()) return false; 519 if(!isOpen()||!hasCurrentFile()) return false;
242 if((fakeThis->zipError=unzGetCurrentFileInfo(unzFile_f, &info_z, NULL, 0, NULL, 0, NULL, 0))!=UNZ_OK) 520 if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, &info_z, NULL, 0, NULL, 0, NULL, 0))!=UNZ_OK)
243 return false; 521 return false;
244 fileName.resize(info_z.size_filename); 522 fileName.resize(info_z.size_filename);
245 extra.resize(info_z.size_file_extra); 523 extra.resize(info_z.size_file_extra);
246 comment.resize(info_z.size_file_comment); 524 comment.resize(info_z.size_file_comment);
247 if((fakeThis->zipError=unzGetCurrentFileInfo(unzFile_f, NULL, 525 if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, NULL,
248 fileName.data(), fileName.size(), 526 fileName.data(), fileName.size(),
249 extra.data(), extra.size(), 527 extra.data(), extra.size(),
250 comment.data(), comment.size()))!=UNZ_OK) 528 comment.data(), comment.size()))!=UNZ_OK)
@@ -259,27 +537,252 @@ bool QuaZip::getCurrentFileInfo(QuaZipFileInfo *info)const
259 info->diskNumberStart=info_z.disk_num_start; 537 info->diskNumberStart=info_z.disk_num_start;
260 info->internalAttr=info_z.internal_fa; 538 info->internalAttr=info_z.internal_fa;
261 info->externalAttr=info_z.external_fa; 539 info->externalAttr=info_z.external_fa;
262 info->name=fileNameCodec->toUnicode(fileName); 540 info->name=p->fileNameCodec->toUnicode(fileName);
263 info->comment=commentCodec->toUnicode(comment); 541 info->comment=p->commentCodec->toUnicode(comment);
264 info->extra=extra; 542 info->extra=extra;
265 info->dateTime=QDateTime( 543 info->dateTime=QDateTime(
266 QDate(info_z.tmu_date.tm_year, info_z.tmu_date.tm_mon+1, info_z.tmu_date.tm_mday), 544 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)); 545 QTime(info_z.tmu_date.tm_hour, info_z.tmu_date.tm_min, info_z.tmu_date.tm_sec));
546 // Add to directory map
547 p->addCurrentFileToDirectoryMap(info->name);
268 return true; 548 return true;
269} 549}
270 550
271QString QuaZip::getCurrentFileName()const 551QString QuaZip::getCurrentFileName()const
272{ 552{
273 QuaZip *fakeThis=(QuaZip*)this; // non-const 553 QuaZip *fakeThis=(QuaZip*)this; // non-const
274 fakeThis->zipError=UNZ_OK; 554 fakeThis->p->zipError=UNZ_OK;
275 if(mode!=mdUnzip) { 555 if(p->mode!=mdUnzip) {
276 qWarning("QuaZip::getCurrentFileName(): ZIP is not open in mdUnzip mode"); 556 qWarning("QuaZip::getCurrentFileName(): ZIP is not open in mdUnzip mode");
277 return QString(); 557 return QString();
278 } 558 }
279 if(!isOpen()||!hasCurrentFile()) return QString(); 559 if(!isOpen()||!hasCurrentFile()) return QString();
280 QByteArray fileName(MAX_FILE_NAME_LENGTH, 0); 560 QByteArray fileName(MAX_FILE_NAME_LENGTH, 0);
281 if((fakeThis->zipError=unzGetCurrentFileInfo(unzFile_f, NULL, fileName.data(), fileName.size(), 561 if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, NULL, fileName.data(), fileName.size(),
282 NULL, 0, NULL, 0))!=UNZ_OK) 562 NULL, 0, NULL, 0))!=UNZ_OK)
283 return QString(); 563 return QString();
284 return fileNameCodec->toUnicode(fileName.constData()); 564 QString result = p->fileNameCodec->toUnicode(fileName.constData());
565 if (result.isEmpty())
566 return result;
567 // Add to directory map
568 p->addCurrentFileToDirectoryMap(result);
569 return result;
570}
571
572void QuaZip::setFileNameCodec(QTextCodec *fileNameCodec)
573{
574 p->fileNameCodec=fileNameCodec;
575}
576
577void QuaZip::setFileNameCodec(const char *fileNameCodecName)
578{
579 p->fileNameCodec=QTextCodec::codecForName(fileNameCodecName);
580}
581
582QTextCodec *QuaZip::getFileNameCodec()const
583{
584 return p->fileNameCodec;
585}
586
587void QuaZip::setCommentCodec(QTextCodec *commentCodec)
588{
589 p->commentCodec=commentCodec;
590}
591
592void QuaZip::setCommentCodec(const char *commentCodecName)
593{
594 p->commentCodec=QTextCodec::codecForName(commentCodecName);
595}
596
597QTextCodec *QuaZip::getCommentCodec()const
598{
599 return p->commentCodec;
600}
601
602QString QuaZip::getZipName() const
603{
604 return p->zipName;
605}
606
607QIODevice *QuaZip::getIoDevice() const
608{
609 if (!p->zipName.isEmpty()) // opened by name, using an internal QIODevice
610 return NULL;
611 return p->ioDevice;
612}
613
614QuaZip::Mode QuaZip::getMode()const
615{
616 return p->mode;
617}
618
619bool QuaZip::isOpen()const
620{
621 return p->mode!=mdNotOpen;
622}
623
624int QuaZip::getZipError() const
625{
626 return p->zipError;
627}
628
629void QuaZip::setComment(const QString& comment)
630{
631 p->comment=comment;
632}
633
634bool QuaZip::hasCurrentFile()const
635{
636 return p->hasCurrentFile_f;
637}
638
639unzFile QuaZip::getUnzFile()
640{
641 return p->unzFile_f;
642}
643
644zipFile QuaZip::getZipFile()
645{
646 return p->zipFile_f;
647}
648
649void QuaZip::setDataDescriptorWritingEnabled(bool enabled)
650{
651 p->dataDescriptorWritingEnabled = enabled;
652}
653
654bool QuaZip::isDataDescriptorWritingEnabled() const
655{
656 return p->dataDescriptorWritingEnabled;
657}
658
659template<typename TFileInfo>
660TFileInfo QuaZip_getFileInfo(QuaZip *zip, bool *ok);
661
662template<>
663QuaZipFileInfo QuaZip_getFileInfo(QuaZip *zip, bool *ok)
664{
665 QuaZipFileInfo info;
666 *ok = zip->getCurrentFileInfo(&info);
667 return info;
668}
669
670template<>
671QuaZipFileInfo64 QuaZip_getFileInfo(QuaZip *zip, bool *ok)
672{
673 QuaZipFileInfo64 info;
674 *ok = zip->getCurrentFileInfo(&info);
675 return info;
676}
677
678template<>
679QString QuaZip_getFileInfo(QuaZip *zip, bool *ok)
680{
681 QString name = zip->getCurrentFileName();
682 *ok = !name.isEmpty();
683 return name;
684}
685
686template<typename TFileInfo>
687bool QuaZipPrivate::getFileInfoList(QList<TFileInfo> *result) const
688{
689 QuaZipPrivate *fakeThis=const_cast<QuaZipPrivate*>(this);
690 fakeThis->zipError=UNZ_OK;
691 if (mode!=QuaZip::mdUnzip) {
692 qWarning("QuaZip::getFileNameList/getFileInfoList(): "
693 "ZIP is not open in mdUnzip mode");
694 return false;
695 }
696 QString currentFile;
697 if (q->hasCurrentFile()) {
698 currentFile = q->getCurrentFileName();
699 }
700 if (q->goToFirstFile()) {
701 do {
702 bool ok;
703 result->append(QuaZip_getFileInfo<TFileInfo>(q, &ok));
704 if (!ok)
705 return false;
706 } while (q->goToNextFile());
707 }
708 if (zipError != UNZ_OK)
709 return false;
710 if (currentFile.isEmpty()) {
711 if (!q->goToFirstFile())
712 return false;
713 } else {
714 if (!q->setCurrentFile(currentFile))
715 return false;
716 }
717 return true;
718}
719
720QStringList QuaZip::getFileNameList() const
721{
722 QStringList list;
723 if (p->getFileInfoList(&list))
724 return list;
725 else
726 return QStringList();
727}
728
729QList<QuaZipFileInfo> QuaZip::getFileInfoList() const
730{
731 QList<QuaZipFileInfo> list;
732 if (p->getFileInfoList(&list))
733 return list;
734 else
735 return QList<QuaZipFileInfo>();
736}
737
738QList<QuaZipFileInfo64> QuaZip::getFileInfoList64() const
739{
740 QList<QuaZipFileInfo64> list;
741 if (p->getFileInfoList(&list))
742 return list;
743 else
744 return QList<QuaZipFileInfo64>();
745}
746
747Qt::CaseSensitivity QuaZip::convertCaseSensitivity(QuaZip::CaseSensitivity cs)
748{
749 if (cs == csDefault) {
750#ifdef Q_WS_WIN
751 return Qt::CaseInsensitive;
752#else
753 return Qt::CaseSensitive;
754#endif
755 } else {
756 return cs == csSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
757 }
758}
759
760void QuaZip::setDefaultFileNameCodec(QTextCodec *codec)
761{
762 QuaZipPrivate::defaultFileNameCodec = codec;
763}
764
765void QuaZip::setDefaultFileNameCodec(const char *codecName)
766{
767 setDefaultFileNameCodec(QTextCodec::codecForName(codecName));
768}
769
770void QuaZip::setZip64Enabled(bool zip64)
771{
772 p->zip64 = zip64;
773}
774
775bool QuaZip::isZip64Enabled() const
776{
777 return p->zip64;
778}
779
780bool QuaZip::isAutoClose() const
781{
782 return p->autoClose;
783}
784
785void QuaZip::setAutoClose(bool autoClose) const
786{
787 p->autoClose = autoClose;
285} 788}
diff --git a/rbutil/rbutilqt/quazip/quazip.h b/rbutil/rbutilqt/quazip/quazip.h
index ced1ea0f1a..ae2c8f494f 100644
--- a/rbutil/rbutilqt/quazip/quazip.h
+++ b/rbutil/rbutilqt/quazip/quazip.h
@@ -2,43 +2,37 @@
2#define QUA_ZIP_H 2#define QUA_ZIP_H
3 3
4/* 4/*
5-- A kind of "standard" GPL license statement -- 5Copyright (C) 2005-2014 Sergey A. Tachenov
6QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
7Copyright (C) 2005-2007 Sergey A. Tachenov
8 6
9This program is free software; you can redistribute it and/or modify it 7This file is part of QuaZIP.
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 8
14This program is distributed in the hope that it will be useful, but 9QuaZIP is free software: you can redistribute it and/or modify
15WITHOUT ANY WARRANTY; without even the implied warranty of 10it under the terms of the GNU Lesser General Public License as published by
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 11the Free Software Foundation, either version 2.1 of the License, or
17Public License for more details. 12(at your option) any later version.
18 13
19You should have received a copy of the GNU General Public License along 14QuaZIP is distributed in the hope that it will be useful,
20with this program; if not, write to the Free Software Foundation, Inc., 15but WITHOUT ANY WARRANTY; without even the implied warranty of
2159 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU Lesser General Public License for more details.
22 18
23-- A kind of "standard" GPL license statement ends here -- 19You should have received a copy of the GNU Lesser General Public License
20along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
24 21
25See COPYING file for GPL. 22See COPYING file for the full LGPL text.
26 23
27You are also permitted to use QuaZIP under the terms of LGPL (see 24Original ZIP package is copyrighted by Gilles Vollant, see
28COPYING.LGPL). You are free to choose either license, but please note 25quazip/(un)zip.h files for details, basically it's zlib license.
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 **/ 26 **/
35 27
36#include <QString> 28#include <QString>
29#include <QStringList>
37#include <QTextCodec> 30#include <QTextCodec>
38 31
39#include "zip.h" 32#include "zip.h"
40#include "unzip.h" 33#include "unzip.h"
41 34
35#include "quazip_global.h"
42#include "quazipfileinfo.h" 36#include "quazipfileinfo.h"
43 37
44// just in case it will be defined in the later versions of the ZIP/UNZIP 38// just in case it will be defined in the later versions of the ZIP/UNZIP
@@ -47,6 +41,8 @@ QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
47#define UNZ_OPENERROR -1000 41#define UNZ_OPENERROR -1000
48#endif 42#endif
49 43
44class QuaZipPrivate;
45
50/// ZIP archive. 46/// ZIP archive.
51/** \class QuaZip quazip.h <quazip/quazip.h> 47/** \class QuaZip quazip.h <quazip/quazip.h>
52 * This class implements basic interface to the ZIP archive. It can be 48 * This class implements basic interface to the ZIP archive. It can be
@@ -85,7 +81,8 @@ QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
85 * detection using locale information. Does anyone know a good way to do 81 * detection using locale information. Does anyone know a good way to do
86 * it? 82 * it?
87 **/ 83 **/
88class QuaZip { 84class QUAZIP_EXPORT QuaZip {
85 friend class QuaZipPrivate;
89 public: 86 public:
90 /// Useful constants. 87 /// Useful constants.
91 enum Constants { 88 enum Constants {
@@ -119,17 +116,17 @@ class QuaZip {
119 csSensitive=1, ///< Case sensitive. 116 csSensitive=1, ///< Case sensitive.
120 csInsensitive=2 ///< Case insensitive. 117 csInsensitive=2 ///< Case insensitive.
121 }; 118 };
119 /// Returns the actual case sensitivity for the specified QuaZIP one.
120 /**
121 \param cs The value to convert.
122 \returns If CaseSensitivity::csDefault, then returns the default
123 file name case sensitivity for the platform. Otherwise, just
124 returns the appropriate value from the Qt::CaseSensitivity enum.
125 */
126 static Qt::CaseSensitivity convertCaseSensitivity(
127 CaseSensitivity cs);
122 private: 128 private:
123 QTextCodec *fileNameCodec, *commentCodec; 129 QuaZipPrivate *p;
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 130 // not (and will not be) implemented
134 QuaZip(const QuaZip& that); 131 QuaZip(const QuaZip& that);
135 // not (and will not be) implemented 132 // not (and will not be) implemented
@@ -140,39 +137,83 @@ class QuaZip {
140 QuaZip(); 137 QuaZip();
141 /// Constructs QuaZip object associated with ZIP file \a zipName. 138 /// Constructs QuaZip object associated with ZIP file \a zipName.
142 QuaZip(const QString& zipName); 139 QuaZip(const QString& zipName);
140 /// Constructs QuaZip object associated with ZIP file represented by \a ioDevice.
141 /** The IO device must be seekable, otherwise an error will occur when opening. */
142 QuaZip(QIODevice *ioDevice);
143 /// Destroys QuaZip object. 143 /// Destroys QuaZip object.
144 /** Calls close() if necessary. */ 144 /** Calls close() if necessary. */
145 ~QuaZip(); 145 ~QuaZip();
146 /// Opens ZIP file. 146 /// Opens ZIP file.
147 /** Argument \a ioApi specifies IO function set for ZIP/UNZIP 147 /**
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 148 * Argument \a mode specifies open mode of the ZIP archive. See Mode
162 * for details. Note that there is zipOpen2() function in the 149 * for details. Note that there is zipOpen2() function in the
163 * ZIP/UNZIP API which accepts \a globalcomment argument, but it 150 * ZIP/UNZIP API which accepts \a globalcomment argument, but it
164 * does not use it anywhere, so this open() function does not have this 151 * does not use it anywhere, so this open() function does not have this
165 * argument. See setComment() if you need to set global comment. 152 * argument. See setComment() if you need to set global comment.
166 * 153 *
154 * If the ZIP file is accessed via explicitly set QIODevice, then
155 * this device is opened in the necessary mode. If the device was
156 * already opened by some other means, then QuaZIP checks if the
157 * open mode is compatible to the mode needed for the requested operation.
158 * If necessary, seeking is performed to position the device properly.
159 *
160 * \return \c true if successful, \c false otherwise.
161 *
167 * \note ZIP/UNZIP API open calls do not return error code - they 162 * \note ZIP/UNZIP API open calls do not return error code - they
168 * just return \c NULL indicating an error. But to make things 163 * just return \c NULL indicating an error. But to make things
169 * easier, quazip.h header defines additional error code \c 164 * easier, quazip.h header defines additional error code \c
170 * UNZ_ERROROPEN and getZipError() will return it if the open call 165 * UNZ_ERROROPEN and getZipError() will return it if the open call
171 * of the ZIP/UNZIP API returns \c NULL. 166 * of the ZIP/UNZIP API returns \c NULL.
167 *
168 * Argument \a ioApi specifies IO function set for ZIP/UNZIP
169 * package to use. See unzip.h, zip.h and ioapi.h for details. Note
170 * that IO API for QuaZip is different from the original package.
171 * The file path argument was changed to be of type \c voidpf, and
172 * QuaZip passes a QIODevice pointer there. This QIODevice is either
173 * set explicitly via setIoDevice() or the QuaZip(QIODevice*)
174 * constructor, or it is created internally when opening the archive
175 * by its file name. The default API (qioapi.cpp) just delegates
176 * everything to the QIODevice API. Not only this allows to use a
177 * QIODevice instead of file name, but also has a nice side effect
178 * of raising the file size limit from 2G to 4G (in non-zip64 archives).
179 *
180 * \note If the zip64 support is needed, the ioApi argument \em must be NULL
181 * because due to the backwards compatibility issues it can be used to
182 * provide a 32-bit API only.
183 *
184 * \note If the \ref QuaZip::setAutoClose() "no-auto-close" feature is used,
185 * then the \a ioApi argument \em should be NULL because the old API
186 * doesn't support the 'fake close' operation, causing slight memory leaks
187 * and other possible troubles (like closing the output device in case
188 * when an error occurs during opening).
189 *
190 * In short: just forget about the \a ioApi argument and you'll be
191 * fine.
172 **/ 192 **/
173 bool open(Mode mode, zlib_filefunc_def *ioApi =NULL); 193 bool open(Mode mode, zlib_filefunc_def *ioApi =NULL);
174 /// Closes ZIP file. 194 /// Closes ZIP file.
175 /** Call getZipError() to determine if the close was successful. */ 195 /** Call getZipError() to determine if the close was successful.
196 *
197 * If the file was opened by name, then the underlying QIODevice is closed
198 * and deleted.
199 *
200 * If the underlying QIODevice was set explicitly using setIoDevice() or
201 * the appropriate constructor, then it is closed if the auto-close flag
202 * is set (which it is by default). Call setAutoClose() to clear the
203 * auto-close flag if this behavior is undesirable.
204 *
205 * Since Qt 5.1, the QSaveFile was introduced. It breaks the QIODevice API
206 * by making close() private and crashing the application if it is called
207 * from the base class where it is public. It is an excellent example
208 * of poor design that illustrates why you should never ever break
209 * an is-a relationship between the base class and a subclass. QuaZIP
210 * works around this bug by checking if the QIODevice is an instance
211 * of QSaveFile, using qobject_cast<>, and if it is, calls
212 * QSaveFile::commit() instead of close(). It is a really ugly hack,
213 * but at least it makes your programs work instead of crashing. Note that
214 * if the auto-close flag is cleared, then this is a non-issue, and
215 * commit() isn't called.
216 */
176 void close(); 217 void close();
177 /// Sets the codec used to encode/decode file names inside archive. 218 /// Sets the codec used to encode/decode file names inside archive.
178 /** This is necessary to access files in the ZIP archive created 219 /** This is necessary to access files in the ZIP archive created
@@ -180,44 +221,56 @@ class QuaZip {
180 * example, file names with cyrillic letters will be in \c IBM866 221 * example, file names with cyrillic letters will be in \c IBM866
181 * encoding. 222 * encoding.
182 **/ 223 **/
183 void setFileNameCodec(QTextCodec *fileNameCodec) 224 void setFileNameCodec(QTextCodec *fileNameCodec);
184 {this->fileNameCodec=fileNameCodec;}
185 /// Sets the codec used to encode/decode file names inside archive. 225 /// Sets the codec used to encode/decode file names inside archive.
186 /** \overload 226 /** \overload
187 * Equivalent to calling setFileNameCodec(QTextCodec::codecForName(codecName)); 227 * Equivalent to calling setFileNameCodec(QTextCodec::codecForName(codecName));
188 **/ 228 **/
189 void setFileNameCodec(const char *fileNameCodecName) 229 void setFileNameCodec(const char *fileNameCodecName);
190 {fileNameCodec=QTextCodec::codecForName(fileNameCodecName);}
191 /// Returns the codec used to encode/decode comments inside archive. 230 /// Returns the codec used to encode/decode comments inside archive.
192 QTextCodec* getFileNameCodec()const {return fileNameCodec;} 231 QTextCodec* getFileNameCodec() const;
193 /// Sets the codec used to encode/decode comments inside archive. 232 /// Sets the codec used to encode/decode comments inside archive.
194 /** This codec defaults to locale codec, which is probably ok. 233 /** This codec defaults to locale codec, which is probably ok.
195 **/ 234 **/
196 void setCommentCodec(QTextCodec *commentCodec) 235 void setCommentCodec(QTextCodec *commentCodec);
197 {this->commentCodec=commentCodec;}
198 /// Sets the codec used to encode/decode comments inside archive. 236 /// Sets the codec used to encode/decode comments inside archive.
199 /** \overload 237 /** \overload
200 * Equivalent to calling setCommentCodec(QTextCodec::codecForName(codecName)); 238 * Equivalent to calling setCommentCodec(QTextCodec::codecForName(codecName));
201 **/ 239 **/
202 void setCommentCodec(const char *commentCodecName) 240 void setCommentCodec(const char *commentCodecName);
203 {commentCodec=QTextCodec::codecForName(commentCodecName);}
204 /// Returns the codec used to encode/decode comments inside archive. 241 /// Returns the codec used to encode/decode comments inside archive.
205 QTextCodec* getCommentCodec()const {return commentCodec;} 242 QTextCodec* getCommentCodec() const;
206 /// Returns the name of the ZIP file. 243 /// Returns the name of the ZIP file.
207 /** Returns null string if no ZIP file name has been set. 244 /** Returns null string if no ZIP file name has been set, for
208 * \sa setZipName() 245 * example when the QuaZip instance is set up to use a QIODevice
246 * instead.
247 * \sa setZipName(), setIoDevice(), getIoDevice()
209 **/ 248 **/
210 QString getZipName()const {return zipName;} 249 QString getZipName() const;
211 /// Sets the name of the ZIP file. 250 /// Sets the name of the ZIP file.
212 /** Does nothing if the ZIP file is open. 251 /** Does nothing if the ZIP file is open.
213 * 252 *
214 * Does not reset error code returned by getZipError(). 253 * Does not reset error code returned by getZipError().
254 * \sa setIoDevice(), getIoDevice(), getZipName()
215 **/ 255 **/
216 void setZipName(const QString& zipName); 256 void setZipName(const QString& zipName);
257 /// Returns the device representing this ZIP file.
258 /** Returns null string if no device has been set explicitly, for
259 * example when opening a ZIP file by name.
260 * \sa setIoDevice(), getZipName(), setZipName()
261 **/
262 QIODevice *getIoDevice() const;
263 /// Sets the device representing the ZIP file.
264 /** Does nothing if the ZIP file is open.
265 *
266 * Does not reset error code returned by getZipError().
267 * \sa getIoDevice(), getZipName(), setZipName()
268 **/
269 void setIoDevice(QIODevice *ioDevice);
217 /// Returns the mode in which ZIP file was opened. 270 /// Returns the mode in which ZIP file was opened.
218 Mode getMode()const {return mode;} 271 Mode getMode() const;
219 /// Returns \c true if ZIP file is open, \c false otherwise. 272 /// Returns \c true if ZIP file is open, \c false otherwise.
220 bool isOpen()const {return mode!=mdNotOpen;} 273 bool isOpen() const;
221 /// Returns the error code of the last operation. 274 /// Returns the error code of the last operation.
222 /** Returns \c UNZ_OK if the last operation was successful. 275 /** Returns \c UNZ_OK if the last operation was successful.
223 * 276 *
@@ -227,20 +280,24 @@ class QuaZip {
227 * error code too. See documentation for the specific functions for 280 * error code too. See documentation for the specific functions for
228 * details on error detection. 281 * details on error detection.
229 **/ 282 **/
230 int getZipError()const {return zipError;} 283 int getZipError() const;
231 /// Returns number of the entries in the ZIP central directory. 284 /// Returns number of the entries in the ZIP central directory.
232 /** Returns negative error code in the case of error. The same error 285 /** Returns negative error code in the case of error. The same error
233 * code will be returned by subsequent getZipError() call. 286 * code will be returned by subsequent getZipError() call.
234 **/ 287 **/
235 int getEntriesCount()const; 288 int getEntriesCount() const;
236 /// Returns global comment in the ZIP file. 289 /// Returns global comment in the ZIP file.
237 QString getComment()const; 290 QString getComment() const;
238 /// Sets global comment in the ZIP file. 291 /// Sets the global comment in the ZIP file.
239 /** Comment will be written to the archive on close operation. 292 /** The comment will be written to the archive on close operation.
293 * QuaZip makes a distinction between a null QByteArray() comment
294 * and an empty &quot;&quot; comment in the QuaZip::mdAdd mode.
295 * A null comment is the default and it means &quot;don't change
296 * the comment&quot;. An empty comment removes the original comment.
240 * 297 *
241 * \sa open() 298 * \sa open()
242 **/ 299 **/
243 void setComment(const QString& comment) {this->comment=comment;} 300 void setComment(const QString& comment);
244 /// Sets the current file to the first file in the archive. 301 /// Sets the current file to the first file in the archive.
245 /** Returns \c true on success, \c false otherwise. Call 302 /** Returns \c true on success, \c false otherwise. Call
246 * getZipError() to get the error code. 303 * getZipError() to get the error code.
@@ -292,7 +349,7 @@ class QuaZip {
292 **/ 349 **/
293 bool setCurrentFile(const QString& fileName, CaseSensitivity cs =csDefault); 350 bool setCurrentFile(const QString& fileName, CaseSensitivity cs =csDefault);
294 /// Returns \c true if the current file has been set. 351 /// Returns \c true if the current file has been set.
295 bool hasCurrentFile()const {return hasCurrentFile_f;} 352 bool hasCurrentFile() const;
296 /// Retrieves information about the current file. 353 /// Retrieves information about the current file.
297 /** Fills the structure pointed by \a info. Returns \c true on 354 /** Fills the structure pointed by \a info. Returns \c true on
298 * success, \c false otherwise. In the latter case structure pointed 355 * success, \c false otherwise. In the latter case structure pointed
@@ -303,13 +360,29 @@ class QuaZip {
303 * 360 *
304 * Does nothing and returns \c false in any of the following cases. 361 * Does nothing and returns \c false in any of the following cases.
305 * - ZIP is not open; 362 * - ZIP is not open;
306 * - ZIP does not have current file; 363 * - ZIP does not have current file.
307 * - \a info is \c NULL;
308 * 364 *
309 * In all these cases getZipError() returns \c UNZ_OK since there 365 * In both cases getZipError() returns \c UNZ_OK since there
310 * is no ZIP/UNZIP API call. 366 * is no ZIP/UNZIP API call.
367 *
368 * This overload doesn't support zip64, but will work OK on zip64 archives
369 * except that if one of the sizes (compressed or uncompressed) is greater
370 * than 0xFFFFFFFFu, it will be set to exactly 0xFFFFFFFFu.
371 *
372 * \sa getCurrentFileInfo(QuaZipFileInfo64* info)const
373 * \sa QuaZipFileInfo64::toQuaZipFileInfo(QuaZipFileInfo&)const
311 **/ 374 **/
312 bool getCurrentFileInfo(QuaZipFileInfo* info)const; 375 bool getCurrentFileInfo(QuaZipFileInfo* info)const;
376 /// Retrieves information about the current file.
377 /** \overload
378 *
379 * This function supports zip64. If the archive doesn't use zip64, it is
380 * completely equivalent to getCurrentFileInfo(QuaZipFileInfo* info)
381 * except for the argument type.
382 *
383 * \sa
384 **/
385 bool getCurrentFileInfo(QuaZipFileInfo64* info)const;
313 /// Returns the current file name. 386 /// Returns the current file name.
314 /** Equivalent to calling getCurrentFileInfo() and then getting \c 387 /** Equivalent to calling getCurrentFileInfo() and then getting \c
315 * name field of the QuaZipFileInfo structure, but faster and more 388 * name field of the QuaZipFileInfo structure, but faster and more
@@ -334,13 +407,165 @@ class QuaZip {
334 * file in the ZIP archive - then change it back or you may 407 * file in the ZIP archive - then change it back or you may
335 * experience some strange behavior or even crashes. 408 * experience some strange behavior or even crashes.
336 **/ 409 **/
337 unzFile getUnzFile() {return unzFile_f;} 410 unzFile getUnzFile();
338 /// Returns \c zipFile handle. 411 /// Returns \c zipFile handle.
339 /** You can use this handle to directly call ZIP part of the 412 /** You can use this handle to directly call ZIP part of the
340 * ZIP/UNZIP package functions (see zip.h). Warnings about the 413 * ZIP/UNZIP package functions (see zip.h). Warnings about the
341 * getUnzFile() function also apply to this function. 414 * getUnzFile() function also apply to this function.
342 **/ 415 **/
343 zipFile getZipFile() {return zipFile_f;} 416 zipFile getZipFile();
417 /// Changes the data descriptor writing mode.
418 /**
419 According to the ZIP format specification, a file inside archive
420 may have a data descriptor immediately following the file
421 data. This is reflected by a special flag in the local file header
422 and in the central directory. By default, QuaZIP sets this flag
423 and writes the data descriptor unless both method and level were
424 set to 0, in which case it operates in 1.0-compatible mode and
425 never writes data descriptors.
426
427 By setting this flag to false, it is possible to disable data
428 descriptor writing, thus increasing compatibility with archive
429 readers that don't understand this feature of the ZIP file format.
430
431 Setting this flag affects all the QuaZipFile instances that are
432 opened after this flag is set.
433
434 The data descriptor writing mode is enabled by default.
435
436 Note that if the ZIP archive is written into a QIODevice for which
437 QIODevice::isSequential() returns \c true, then the data descriptor
438 is mandatory and will be written even if this flag is set to false.
439
440 \param enabled If \c true, enable local descriptor writing,
441 disable it otherwise.
442
443 \sa QuaZipFile::isDataDescriptorWritingEnabled()
444 */
445 void setDataDescriptorWritingEnabled(bool enabled);
446 /// Returns the data descriptor default writing mode.
447 /**
448 \sa setDataDescriptorWritingEnabled()
449 */
450 bool isDataDescriptorWritingEnabled() const;
451 /// Returns a list of files inside the archive.
452 /**
453 \return A list of file names or an empty list if there
454 was an error or if the archive is empty (call getZipError() to
455 figure out which).
456 \sa getFileInfoList()
457 */
458 QStringList getFileNameList() const;
459 /// Returns information list about all files inside the archive.
460 /**
461 \return A list of QuaZipFileInfo objects or an empty list if there
462 was an error or if the archive is empty (call getZipError() to
463 figure out which).
464
465 This function doesn't support zip64, but will still work with zip64
466 archives, converting results using QuaZipFileInfo64::toQuaZipFileInfo().
467 If all file sizes are below 4 GB, it will work just fine.
468
469 \sa getFileNameList()
470 \sa getFileInfoList64()
471 */
472 QList<QuaZipFileInfo> getFileInfoList() const;
473 /// Returns information list about all files inside the archive.
474 /**
475 \overload
476
477 This function supports zip64.
478
479 \sa getFileNameList()
480 \sa getFileInfoList()
481 */
482 QList<QuaZipFileInfo64> getFileInfoList64() const;
483 /// Enables the zip64 mode.
484 /**
485 * @param zip64 If \c true, the zip64 mode is enabled, disabled otherwise.
486 *
487 * Once this is enabled, all new files (until the mode is disabled again)
488 * will be created in the zip64 mode, thus enabling the ability to write
489 * files larger than 4 GB. By default, the zip64 mode is off due to
490 * compatibility reasons.
491 *
492 * Note that this does not affect the ability to read zip64 archives in any
493 * way.
494 *
495 * \sa isZip64Enabled()
496 */
497 void setZip64Enabled(bool zip64);
498 /// Returns whether the zip64 mode is enabled.
499 /**
500 * @return \c true if and only if the zip64 mode is enabled.
501 *
502 * \sa setZip64Enabled()
503 */
504 bool isZip64Enabled() const;
505 /// Returns the auto-close flag.
506 /**
507 @sa setAutoClose()
508 */
509 bool isAutoClose() const;
510 /// Sets or unsets the auto-close flag.
511 /**
512 By default, QuaZIP opens the underlying QIODevice when open() is called,
513 and closes it when close() is called. In some cases, when the device
514 is set explicitly using setIoDevice(), it may be desirable to
515 leave the device open. If the auto-close flag is unset using this method,
516 then the device isn't closed automatically if it was set explicitly.
517
518 If it is needed to clear this flag, it is recommended to do so before
519 opening the archive because otherwise QuaZIP may close the device
520 during the open() call if an error is encountered after the device
521 is opened.
522
523 If the device was not set explicitly, but rather the setZipName() or
524 the appropriate constructor was used to set the ZIP file name instead,
525 then the auto-close flag has no effect, and the internal device
526 is closed nevertheless because there is no other way to close it.
527
528 @sa isAutoClose()
529 @sa setIoDevice()
530 */
531 void setAutoClose(bool autoClose) const;
532 /// Sets the default file name codec to use.
533 /**
534 * The default codec is used by the constructors, so calling this function
535 * won't affect the QuaZip instances already created at that moment.
536 *
537 * The codec specified here can be overriden by calling setFileNameCodec().
538 * If neither function is called, QTextCodec::codecForLocale() will be used
539 * to decode or encode file names. Use this function with caution if
540 * the application uses other libraries that depend on QuaZIP. Those
541 * libraries can either call this function by themselves, thus overriding
542 * your setting or can rely on the default encoding, thus failing
543 * mysteriously if you change it. For these reasons, it isn't recommended
544 * to use this function if you are developing a library, not an application.
545 * Instead, ask your library users to call it in case they need specific
546 * encoding.
547 *
548 * In most cases, using setFileNameCodec() instead is the right choice.
549 * However, if you depend on third-party code that uses QuaZIP, then the
550 * reasons stated above can actually become a reason to use this function
551 * in case the third-party code in question fails because it doesn't
552 * understand the encoding you need and doesn't provide a way to specify it.
553 * This applies to the JlCompress class as well, as it was contributed and
554 * doesn't support explicit encoding parameters.
555 *
556 * In short: use setFileNameCodec() when you can, resort to
557 * setDefaultFileNameCodec() when you don't have access to the QuaZip
558 * instance.
559 *
560 * @param codec The codec to use by default. If NULL, resets to default.
561 */
562 static void setDefaultFileNameCodec(QTextCodec *codec);
563 /**
564 * @overload
565 * Equivalent to calling
566 * setDefltFileNameCodec(QTextCodec::codecForName(codecName)).
567 */
568 static void setDefaultFileNameCodec(const char *codecName);
344}; 569};
345 570
346#endif 571#endif
diff --git a/rbutil/rbutilqt/quazip/quazip_global.h b/rbutil/rbutilqt/quazip/quazip_global.h
new file mode 100644
index 0000000000..7e3798afc1
--- /dev/null
+++ b/rbutil/rbutilqt/quazip/quazip_global.h
@@ -0,0 +1,59 @@
1#ifndef QUAZIP_GLOBAL_H
2#define QUAZIP_GLOBAL_H
3
4/*
5Copyright (C) 2005-2014 Sergey A. Tachenov
6
7This file is part of QuaZIP.
8
9QuaZIP is free software: you can redistribute it and/or modify
10it under the terms of the GNU Lesser General Public License as published by
11the Free Software Foundation, either version 2.1 of the License, or
12(at your option) any later version.
13
14QuaZIP is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License
20along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
21
22See COPYING file for the full LGPL text.
23
24Original ZIP package is copyrighted by Gilles Vollant and contributors,
25see quazip/(un)zip.h files for details. Basically it's the zlib license.
26*/
27
28#include <QtCore/qglobal.h>
29
30/**
31 This is automatically defined when building a static library, but when
32 including QuaZip sources directly into a project, QUAZIP_STATIC should
33 be defined explicitly to avoid possible troubles with unnecessary
34 importing/exporting.
35 */
36#ifdef QUAZIP_STATIC
37#define QUAZIP_EXPORT
38#else
39/**
40 * When building a DLL with MSVC, QUAZIP_BUILD must be defined.
41 * qglobal.h takes care of defining Q_DECL_* correctly for msvc/gcc.
42 */
43#if defined(QUAZIP_BUILD)
44 #define QUAZIP_EXPORT Q_DECL_EXPORT
45#else
46 #define QUAZIP_EXPORT Q_DECL_IMPORT
47#endif
48#endif // QUAZIP_STATIC
49
50#ifdef __GNUC__
51#define UNUSED __attribute__((__unused__))
52#else
53#define UNUSED
54#endif
55
56#define QUAZIP_EXTRA_NTFS_MAGIC 0x000Au
57#define QUAZIP_EXTRA_NTFS_TIME_MAGIC 0x0001u
58
59#endif // QUAZIP_GLOBAL_H
diff --git a/rbutil/rbutilqt/quazip/quazipfile.cpp b/rbutil/rbutilqt/quazip/quazipfile.cpp
index 0399d1dbd0..8d56417698 100644
--- a/rbutil/rbutilqt/quazip/quazipfile.cpp
+++ b/rbutil/rbutilqt/quazip/quazipfile.cpp
@@ -1,91 +1,165 @@
1/* 1/*
2-- A kind of "standard" GPL license statement -- 2Copyright (C) 2005-2014 Sergey A. Tachenov
3QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package 3
4Copyright (C) 2005-2007 Sergey A. Tachenov 4This file is part of QuaZIP.
5 5
6This program is free software; you can redistribute it and/or modify it 6QuaZIP is free software: you can redistribute it and/or modify
7under the terms of the GNU General Public License as published by the 7it under the terms of the GNU Lesser General Public License as published by
8Free Software Foundation; either version 2 of the License, or (at your 8the Free Software Foundation, either version 2.1 of the License, or
9option) any later version. 9(at your option) any later version.
10 10
11This program is distributed in the hope that it will be useful, but 11QuaZIP is distributed in the hope that it will be useful,
12WITHOUT ANY WARRANTY; without even the implied warranty of 12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14Public License for more details. 14GNU Lesser General Public License for more details.
15 15
16You should have received a copy of the GNU General Public License along 16You should have received a copy of the GNU Lesser General Public License
17with this program; if not, write to the Free Software Foundation, Inc., 17along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
1859 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18
19 19See COPYING file for the full LGPL text.
20-- A kind of "standard" GPL license statement ends here -- 20
21 21Original ZIP package is copyrighted by Gilles Vollant, see
22See COPYING file for GPL. 22quazip/(un)zip.h files for details, basically it's zlib license.
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 **/ 23 **/
32 24
33#include "quazipfile.h" 25#include "quazipfile.h"
34 26
35using namespace std; 27using namespace std;
36 28
29/// The implementation class for QuaZip.
30/**
31\internal
32
33This class contains all the private stuff for the QuaZipFile class, thus
34allowing to preserve binary compatibility between releases, the
35technique known as the Pimpl (private implementation) idiom.
36*/
37class QuaZipFilePrivate {
38 friend class QuaZipFile;
39 private:
40 /// The pointer to the associated QuaZipFile instance.
41 QuaZipFile *q;
42 /// The QuaZip object to work with.
43 QuaZip *zip;
44 /// The file name.
45 QString fileName;
46 /// Case sensitivity mode.
47 QuaZip::CaseSensitivity caseSensitivity;
48 /// Whether this file is opened in the raw mode.
49 bool raw;
50 /// Write position to keep track of.
51 /**
52 QIODevice::pos() is broken for non-seekable devices, so we need
53 our own position.
54 */
55 qint64 writePos;
56 /// Uncompressed size to write along with a raw file.
57 quint64 uncompressedSize;
58 /// CRC to write along with a raw file.
59 quint32 crc;
60 /// Whether \ref zip points to an internal QuaZip instance.
61 /**
62 This is true if the archive was opened by name, rather than by
63 supplying an existing QuaZip instance.
64 */
65 bool internal;
66 /// The last error.
67 int zipError;
68 /// Resets \ref zipError.
69 inline void resetZipError() const {setZipError(UNZ_OK);}
70 /// Sets the zip error.
71 /**
72 This function is marked as const although it changes one field.
73 This allows to call it from const functions that don't change
74 anything by themselves.
75 */
76 void setZipError(int zipError) const;
77 /// The constructor for the corresponding QuaZipFile constructor.
78 inline QuaZipFilePrivate(QuaZipFile *q):
79 q(q), zip(NULL), internal(true), zipError(UNZ_OK) {}
80 /// The constructor for the corresponding QuaZipFile constructor.
81 inline QuaZipFilePrivate(QuaZipFile *q, const QString &zipName):
82 q(q), internal(true), zipError(UNZ_OK)
83 {
84 zip=new QuaZip(zipName);
85 }
86 /// The constructor for the corresponding QuaZipFile constructor.
87 inline QuaZipFilePrivate(QuaZipFile *q, const QString &zipName, const QString &fileName,
88 QuaZip::CaseSensitivity cs):
89 q(q), internal(true), zipError(UNZ_OK)
90 {
91 zip=new QuaZip(zipName);
92 this->fileName=fileName;
93 if (this->fileName.startsWith('/'))
94 this->fileName = this->fileName.mid(1);
95 this->caseSensitivity=cs;
96 }
97 /// The constructor for the QuaZipFile constructor accepting a file name.
98 inline QuaZipFilePrivate(QuaZipFile *q, QuaZip *zip):
99 q(q), zip(zip), internal(false), zipError(UNZ_OK) {}
100 /// The destructor.
101 inline ~QuaZipFilePrivate()
102 {
103 if (internal)
104 delete zip;
105 }
106};
107
37QuaZipFile::QuaZipFile(): 108QuaZipFile::QuaZipFile():
38 zip(NULL), internal(true), zipError(UNZ_OK) 109 p(new QuaZipFilePrivate(this))
39{ 110{
40} 111}
41 112
42QuaZipFile::QuaZipFile(QObject *parent): 113QuaZipFile::QuaZipFile(QObject *parent):
43 QIODevice(parent), zip(NULL), internal(true), zipError(UNZ_OK) 114 QIODevice(parent),
115 p(new QuaZipFilePrivate(this))
44{ 116{
45} 117}
46 118
47QuaZipFile::QuaZipFile(const QString& zipName, QObject *parent): 119QuaZipFile::QuaZipFile(const QString& zipName, QObject *parent):
48 QIODevice(parent), internal(true), zipError(UNZ_OK) 120 QIODevice(parent),
121 p(new QuaZipFilePrivate(this, zipName))
49{ 122{
50 zip=new QuaZip(zipName);
51 Q_CHECK_PTR(zip);
52} 123}
53 124
54QuaZipFile::QuaZipFile(const QString& zipName, const QString& fileName, 125QuaZipFile::QuaZipFile(const QString& zipName, const QString& fileName,
55 QuaZip::CaseSensitivity cs, QObject *parent): 126 QuaZip::CaseSensitivity cs, QObject *parent):
56 QIODevice(parent), internal(true), zipError(UNZ_OK) 127 QIODevice(parent),
128 p(new QuaZipFilePrivate(this, zipName, fileName, cs))
57{ 129{
58 zip=new QuaZip(zipName);
59 Q_CHECK_PTR(zip);
60 this->fileName=fileName;
61 this->caseSensitivity=cs;
62} 130}
63 131
64QuaZipFile::QuaZipFile(QuaZip *zip, QObject *parent): 132QuaZipFile::QuaZipFile(QuaZip *zip, QObject *parent):
65 QIODevice(parent), 133 QIODevice(parent),
66 zip(zip), internal(false), 134 p(new QuaZipFilePrivate(this, zip))
67 zipError(UNZ_OK)
68{ 135{
69} 136}
70 137
71QuaZipFile::~QuaZipFile() 138QuaZipFile::~QuaZipFile()
72{ 139{
73 if(isOpen()) close(); 140 if (isOpen())
74 if(internal) delete zip; 141 close();
142 delete p;
143}
144
145QString QuaZipFile::getZipName() const
146{
147 return p->zip==NULL ? QString() : p->zip->getZipName();
75} 148}
76 149
77QString QuaZipFile::getZipName()const 150QuaZip *QuaZipFile::getZip() const
78{ 151{
79 return zip==NULL?QString():zip->getZipName(); 152 return p->internal ? NULL : p->zip;
80} 153}
81 154
82QString QuaZipFile::getActualFileName()const 155QString QuaZipFile::getActualFileName()const
83{ 156{
84 setZipError(UNZ_OK); 157 p->setZipError(UNZ_OK);
85 if(zip==NULL||(openMode()&WriteOnly)) return QString(); 158 if (p->zip == NULL || (openMode() & WriteOnly))
86 QString name=zip->getCurrentFileName(); 159 return QString();
160 QString name=p->zip->getCurrentFileName();
87 if(name.isNull()) 161 if(name.isNull())
88 setZipError(zip->getZipError()); 162 p->setZipError(p->zip->getZipError());
89 return name; 163 return name;
90} 164}
91 165
@@ -95,10 +169,10 @@ void QuaZipFile::setZipName(const QString& zipName)
95 qWarning("QuaZipFile::setZipName(): file is already open - can not set ZIP name"); 169 qWarning("QuaZipFile::setZipName(): file is already open - can not set ZIP name");
96 return; 170 return;
97 } 171 }
98 if(zip!=NULL&&internal) delete zip; 172 if(p->zip!=NULL && p->internal)
99 zip=new QuaZip(zipName); 173 delete p->zip;
100 Q_CHECK_PTR(zip); 174 p->zip=new QuaZip(zipName);
101 internal=true; 175 p->internal=true;
102} 176}
103 177
104void QuaZipFile::setZip(QuaZip *zip) 178void QuaZipFile::setZip(QuaZip *zip)
@@ -107,19 +181,20 @@ void QuaZipFile::setZip(QuaZip *zip)
107 qWarning("QuaZipFile::setZip(): file is already open - can not set ZIP"); 181 qWarning("QuaZipFile::setZip(): file is already open - can not set ZIP");
108 return; 182 return;
109 } 183 }
110 if(this->zip!=NULL&&internal) delete this->zip; 184 if(p->zip!=NULL && p->internal)
111 this->zip=zip; 185 delete p->zip;
112 this->fileName=QString(); 186 p->zip=zip;
113 internal=false; 187 p->fileName=QString();
188 p->internal=false;
114} 189}
115 190
116void QuaZipFile::setFileName(const QString& fileName, QuaZip::CaseSensitivity cs) 191void QuaZipFile::setFileName(const QString& fileName, QuaZip::CaseSensitivity cs)
117{ 192{
118 if(zip==NULL) { 193 if(p->zip==NULL) {
119 qWarning("QuaZipFile::setFileName(): call setZipName() first"); 194 qWarning("QuaZipFile::setFileName(): call setZipName() first");
120 return; 195 return;
121 } 196 }
122 if(!internal) { 197 if(!p->internal) {
123 qWarning("QuaZipFile::setFileName(): should not be used when not using internal QuaZip"); 198 qWarning("QuaZipFile::setFileName(): should not be used when not using internal QuaZip");
124 return; 199 return;
125 } 200 }
@@ -127,18 +202,20 @@ void QuaZipFile::setFileName(const QString& fileName, QuaZip::CaseSensitivity cs
127 qWarning("QuaZipFile::setFileName(): can not set file name for already opened file"); 202 qWarning("QuaZipFile::setFileName(): can not set file name for already opened file");
128 return; 203 return;
129 } 204 }
130 this->fileName=fileName; 205 p->fileName=fileName;
131 this->caseSensitivity=cs; 206 if (p->fileName.startsWith('/'))
207 p->fileName = p->fileName.mid(1);
208 p->caseSensitivity=cs;
132} 209}
133 210
134void QuaZipFile::setZipError(int zipError)const 211void QuaZipFilePrivate::setZipError(int zipError) const
135{ 212{
136 QuaZipFile *fakeThis=(QuaZipFile*)this; // non-const 213 QuaZipFilePrivate *fakeThis = const_cast<QuaZipFilePrivate*>(this); // non-const
137 fakeThis->zipError=zipError; 214 fakeThis->zipError=zipError;
138 if(zipError==UNZ_OK) 215 if(zipError==UNZ_OK)
139 fakeThis->setErrorString(QString()); 216 q->setErrorString(QString());
140 else 217 else
141 fakeThis->setErrorString(tr("ZIP/UNZIP API error %1").arg(zipError)); 218 q->setErrorString(QuaZipFile::tr("ZIP/UNZIP API error %1").arg(zipError));
142} 219}
143 220
144bool QuaZipFile::open(OpenMode mode) 221bool QuaZipFile::open(OpenMode mode)
@@ -148,7 +225,7 @@ bool QuaZipFile::open(OpenMode mode)
148 225
149bool QuaZipFile::open(OpenMode mode, int *method, int *level, bool raw, const char *password) 226bool QuaZipFile::open(OpenMode mode, int *method, int *level, bool raw, const char *password)
150{ 227{
151 resetZipError(); 228 p->resetZipError();
152 if(isOpen()) { 229 if(isOpen()) {
153 qWarning("QuaZipFile::open(): already opened"); 230 qWarning("QuaZipFile::open(): already opened");
154 return false; 231 return false;
@@ -158,35 +235,35 @@ bool QuaZipFile::open(OpenMode mode, int *method, int *level, bool raw, const ch
158 return false; 235 return false;
159 } 236 }
160 if((mode&ReadOnly)&&!(mode&WriteOnly)) { 237 if((mode&ReadOnly)&&!(mode&WriteOnly)) {
161 if(internal) { 238 if(p->internal) {
162 if(!zip->open(QuaZip::mdUnzip)) { 239 if(!p->zip->open(QuaZip::mdUnzip)) {
163 setZipError(zip->getZipError()); 240 p->setZipError(p->zip->getZipError());
164 return false; 241 return false;
165 } 242 }
166 if(!zip->setCurrentFile(fileName, caseSensitivity)) { 243 if(!p->zip->setCurrentFile(p->fileName, p->caseSensitivity)) {
167 setZipError(zip->getZipError()); 244 p->setZipError(p->zip->getZipError());
168 zip->close(); 245 p->zip->close();
169 return false; 246 return false;
170 } 247 }
171 } else { 248 } else {
172 if(zip==NULL) { 249 if(p->zip==NULL) {
173 qWarning("QuaZipFile::open(): zip is NULL"); 250 qWarning("QuaZipFile::open(): zip is NULL");
174 return false; 251 return false;
175 } 252 }
176 if(zip->getMode()!=QuaZip::mdUnzip) { 253 if(p->zip->getMode()!=QuaZip::mdUnzip) {
177 qWarning("QuaZipFile::open(): file open mode %d incompatible with ZIP open mode %d", 254 qWarning("QuaZipFile::open(): file open mode %d incompatible with ZIP open mode %d",
178 (int)mode, (int)zip->getMode()); 255 (int)mode, (int)p->zip->getMode());
179 return false; 256 return false;
180 } 257 }
181 if(!zip->hasCurrentFile()) { 258 if(!p->zip->hasCurrentFile()) {
182 qWarning("QuaZipFile::open(): zip does not have current file"); 259 qWarning("QuaZipFile::open(): zip does not have current file");
183 return false; 260 return false;
184 } 261 }
185 } 262 }
186 setZipError(unzOpenCurrentFile3(zip->getUnzFile(), method, level, (int)raw, password)); 263 p->setZipError(unzOpenCurrentFile3(p->zip->getUnzFile(), method, level, (int)raw, password));
187 if(zipError==UNZ_OK) { 264 if(p->zipError==UNZ_OK) {
188 setOpenMode(mode); 265 setOpenMode(mode);
189 this->raw=raw; 266 p->raw=raw;
190 return true; 267 return true;
191 } else 268 } else
192 return false; 269 return false;
@@ -201,23 +278,23 @@ bool QuaZipFile::open(OpenMode mode, const QuaZipNewInfo& info,
201 int windowBits, int memLevel, int strategy) 278 int windowBits, int memLevel, int strategy)
202{ 279{
203 zip_fileinfo info_z; 280 zip_fileinfo info_z;
204 resetZipError(); 281 p->resetZipError();
205 if(isOpen()) { 282 if(isOpen()) {
206 qWarning("QuaZipFile::open(): already opened"); 283 qWarning("QuaZipFile::open(): already opened");
207 return false; 284 return false;
208 } 285 }
209 if((mode&WriteOnly)&&!(mode&ReadOnly)) { 286 if((mode&WriteOnly)&&!(mode&ReadOnly)) {
210 if(internal) { 287 if(p->internal) {
211 qWarning("QuaZipFile::open(): write mode is incompatible with internal QuaZip approach"); 288 qWarning("QuaZipFile::open(): write mode is incompatible with internal QuaZip approach");
212 return false; 289 return false;
213 } 290 }
214 if(zip==NULL) { 291 if(p->zip==NULL) {
215 qWarning("QuaZipFile::open(): zip is NULL"); 292 qWarning("QuaZipFile::open(): zip is NULL");
216 return false; 293 return false;
217 } 294 }
218 if(zip->getMode()!=QuaZip::mdCreate&&zip->getMode()!=QuaZip::mdAppend&&zip->getMode()!=QuaZip::mdAdd) { 295 if(p->zip->getMode()!=QuaZip::mdCreate&&p->zip->getMode()!=QuaZip::mdAppend&&p->zip->getMode()!=QuaZip::mdAdd) {
219 qWarning("QuaZipFile::open(): file open mode %d incompatible with ZIP open mode %d", 296 qWarning("QuaZipFile::open(): file open mode %d incompatible with ZIP open mode %d",
220 (int)mode, (int)zip->getMode()); 297 (int)mode, (int)p->zip->getMode());
221 return false; 298 return false;
222 } 299 }
223 info_z.tmz_date.tm_year=info.dateTime.date().year(); 300 info_z.tmz_date.tm_year=info.dateTime.date().year();
@@ -229,21 +306,25 @@ bool QuaZipFile::open(OpenMode mode, const QuaZipNewInfo& info,
229 info_z.dosDate = 0; 306 info_z.dosDate = 0;
230 info_z.internal_fa=(uLong)info.internalAttr; 307 info_z.internal_fa=(uLong)info.internalAttr;
231 info_z.external_fa=(uLong)info.externalAttr; 308 info_z.external_fa=(uLong)info.externalAttr;
232 setZipError(zipOpenNewFileInZip3(zip->getZipFile(), 309 if (p->zip->isDataDescriptorWritingEnabled())
233 zip->getFileNameCodec()->fromUnicode(info.name).constData(), &info_z, 310 zipSetFlags(p->zip->getZipFile(), ZIP_WRITE_DATA_DESCRIPTOR);
311 else
312 zipClearFlags(p->zip->getZipFile(), ZIP_WRITE_DATA_DESCRIPTOR);
313 p->setZipError(zipOpenNewFileInZip3_64(p->zip->getZipFile(),
314 p->zip->getFileNameCodec()->fromUnicode(info.name).constData(), &info_z,
234 info.extraLocal.constData(), info.extraLocal.length(), 315 info.extraLocal.constData(), info.extraLocal.length(),
235 info.extraGlobal.constData(), info.extraGlobal.length(), 316 info.extraGlobal.constData(), info.extraGlobal.length(),
236 zip->getCommentCodec()->fromUnicode(info.comment).constData(), 317 p->zip->getCommentCodec()->fromUnicode(info.comment).constData(),
237 method, level, (int)raw, 318 method, level, (int)raw,
238 windowBits, memLevel, strategy, 319 windowBits, memLevel, strategy,
239 password, (uLong)crc)); 320 password, (uLong)crc, p->zip->isZip64Enabled()));
240 if(zipError==UNZ_OK) { 321 if(p->zipError==UNZ_OK) {
241 writePos=0; 322 p->writePos=0;
242 setOpenMode(mode); 323 setOpenMode(mode);
243 this->raw=raw; 324 p->raw=raw;
244 if(raw) { 325 if(raw) {
245 this->crc=crc; 326 p->crc=crc;
246 this->uncompressedSize=info.uncompressedSize; 327 p->uncompressedSize=info.uncompressedSize;
247 } 328 }
248 return true; 329 return true;
249 } else 330 } else
@@ -260,7 +341,7 @@ bool QuaZipFile::isSequential()const
260 341
261qint64 QuaZipFile::pos()const 342qint64 QuaZipFile::pos()const
262{ 343{
263 if(zip==NULL) { 344 if(p->zip==NULL) {
264 qWarning("QuaZipFile::pos(): call setZipName() or setZip() first"); 345 qWarning("QuaZipFile::pos(): call setZipName() or setZip() first");
265 return -1; 346 return -1;
266 } 347 }
@@ -269,14 +350,17 @@ qint64 QuaZipFile::pos()const
269 return -1; 350 return -1;
270 } 351 }
271 if(openMode()&ReadOnly) 352 if(openMode()&ReadOnly)
272 return unztell(zip->getUnzFile()); 353 // QIODevice::pos() is broken for sequential devices,
354 // but thankfully bytesAvailable() returns the number of
355 // bytes buffered, so we know how far ahead we are.
356 return unztell(p->zip->getUnzFile()) - QIODevice::bytesAvailable();
273 else 357 else
274 return writePos; 358 return p->writePos;
275} 359}
276 360
277bool QuaZipFile::atEnd()const 361bool QuaZipFile::atEnd()const
278{ 362{
279 if(zip==NULL) { 363 if(p->zip==NULL) {
280 qWarning("QuaZipFile::atEnd(): call setZipName() or setZip() first"); 364 qWarning("QuaZipFile::atEnd(): call setZipName() or setZip() first");
281 return false; 365 return false;
282 } 366 }
@@ -285,7 +369,9 @@ bool QuaZipFile::atEnd()const
285 return false; 369 return false;
286 } 370 }
287 if(openMode()&ReadOnly) 371 if(openMode()&ReadOnly)
288 return unzeof(zip->getUnzFile())==1; 372 // the same problem as with pos()
373 return QIODevice::bytesAvailable() == 0
374 && unzeof(p->zip->getUnzFile())==1;
289 else 375 else
290 return true; 376 return true;
291} 377}
@@ -297,81 +383,120 @@ qint64 QuaZipFile::size()const
297 return -1; 383 return -1;
298 } 384 }
299 if(openMode()&ReadOnly) 385 if(openMode()&ReadOnly)
300 return raw?csize():usize(); 386 return p->raw?csize():usize();
301 else 387 else
302 return writePos; 388 return p->writePos;
303} 389}
304 390
305qint64 QuaZipFile::csize()const 391qint64 QuaZipFile::csize()const
306{ 392{
307 unz_file_info info_z; 393 unz_file_info64 info_z;
308 setZipError(UNZ_OK); 394 p->setZipError(UNZ_OK);
309 if(zip==NULL||zip->getMode()!=QuaZip::mdUnzip) return -1; 395 if(p->zip==NULL||p->zip->getMode()!=QuaZip::mdUnzip) return -1;
310 setZipError(unzGetCurrentFileInfo(zip->getUnzFile(), &info_z, NULL, 0, NULL, 0, NULL, 0)); 396 p->setZipError(unzGetCurrentFileInfo64(p->zip->getUnzFile(), &info_z, NULL, 0, NULL, 0, NULL, 0));
311 if(zipError!=UNZ_OK) 397 if(p->zipError!=UNZ_OK)
312 return -1; 398 return -1;
313 return info_z.compressed_size; 399 return info_z.compressed_size;
314} 400}
315 401
316qint64 QuaZipFile::usize()const 402qint64 QuaZipFile::usize()const
317{ 403{
318 unz_file_info info_z; 404 unz_file_info64 info_z;
319 setZipError(UNZ_OK); 405 p->setZipError(UNZ_OK);
320 if(zip==NULL||zip->getMode()!=QuaZip::mdUnzip) return -1; 406 if(p->zip==NULL||p->zip->getMode()!=QuaZip::mdUnzip) return -1;
321 setZipError(unzGetCurrentFileInfo(zip->getUnzFile(), &info_z, NULL, 0, NULL, 0, NULL, 0)); 407 p->setZipError(unzGetCurrentFileInfo64(p->zip->getUnzFile(), &info_z, NULL, 0, NULL, 0, NULL, 0));
322 if(zipError!=UNZ_OK) 408 if(p->zipError!=UNZ_OK)
323 return -1; 409 return -1;
324 return info_z.uncompressed_size; 410 return info_z.uncompressed_size;
325} 411}
326 412
327bool QuaZipFile::getFileInfo(QuaZipFileInfo *info) 413bool QuaZipFile::getFileInfo(QuaZipFileInfo *info)
328{ 414{
329 if(zip==NULL||zip->getMode()!=QuaZip::mdUnzip) return false; 415 QuaZipFileInfo64 info64;
330 zip->getCurrentFileInfo(info); 416 if (getFileInfo(&info64)) {
331 setZipError(zip->getZipError()); 417 info64.toQuaZipFileInfo(*info);
332 return zipError==UNZ_OK; 418 return true;
419 } else {
420 return false;
421 }
422}
423
424bool QuaZipFile::getFileInfo(QuaZipFileInfo64 *info)
425{
426 if(p->zip==NULL||p->zip->getMode()!=QuaZip::mdUnzip) return false;
427 p->zip->getCurrentFileInfo(info);
428 p->setZipError(p->zip->getZipError());
429 return p->zipError==UNZ_OK;
333} 430}
334 431
335void QuaZipFile::close() 432void QuaZipFile::close()
336{ 433{
337 resetZipError(); 434 p->resetZipError();
338 if(zip==NULL||!zip->isOpen()) return; 435 if(p->zip==NULL||!p->zip->isOpen()) return;
339 if(!isOpen()) { 436 if(!isOpen()) {
340 qWarning("QuaZipFile::close(): file isn't open"); 437 qWarning("QuaZipFile::close(): file isn't open");
341 return; 438 return;
342 } 439 }
343 if(openMode()&ReadOnly) 440 if(openMode()&ReadOnly)
344 setZipError(unzCloseCurrentFile(zip->getUnzFile())); 441 p->setZipError(unzCloseCurrentFile(p->zip->getUnzFile()));
345 else if(openMode()&WriteOnly) 442 else if(openMode()&WriteOnly)
346 if(isRaw()) setZipError(zipCloseFileInZipRaw(zip->getZipFile(), uncompressedSize, crc)); 443 if(isRaw()) p->setZipError(zipCloseFileInZipRaw64(p->zip->getZipFile(), p->uncompressedSize, p->crc));
347 else setZipError(zipCloseFileInZip(zip->getZipFile())); 444 else p->setZipError(zipCloseFileInZip(p->zip->getZipFile()));
348 else { 445 else {
349 qWarning("Wrong open mode: %d", (int)openMode()); 446 qWarning("Wrong open mode: %d", (int)openMode());
350 return; 447 return;
351 } 448 }
352 if(zipError==UNZ_OK) setOpenMode(QIODevice::NotOpen); 449 if(p->zipError==UNZ_OK) setOpenMode(QIODevice::NotOpen);
353 else return; 450 else return;
354 if(internal) { 451 if(p->internal) {
355 zip->close(); 452 p->zip->close();
356 setZipError(zip->getZipError()); 453 p->setZipError(p->zip->getZipError());
357 } 454 }
358} 455}
359 456
360qint64 QuaZipFile::readData(char *data, qint64 maxSize) 457qint64 QuaZipFile::readData(char *data, qint64 maxSize)
361{ 458{
362 setZipError(UNZ_OK); 459 p->setZipError(UNZ_OK);
363 qint64 bytesRead=unzReadCurrentFile(zip->getUnzFile(), data, (unsigned)maxSize); 460 qint64 bytesRead=unzReadCurrentFile(p->zip->getUnzFile(), data, (unsigned)maxSize);
364 if(bytesRead<0) setZipError((int)bytesRead); 461 if (bytesRead < 0) {
462 p->setZipError((int) bytesRead);
463 return -1;
464 }
365 return bytesRead; 465 return bytesRead;
366} 466}
367 467
368qint64 QuaZipFile::writeData(const char* data, qint64 maxSize) 468qint64 QuaZipFile::writeData(const char* data, qint64 maxSize)
369{ 469{
370 setZipError(ZIP_OK); 470 p->setZipError(ZIP_OK);
371 setZipError(zipWriteInFileInZip(zip->getZipFile(), data, (uint)maxSize)); 471 p->setZipError(zipWriteInFileInZip(p->zip->getZipFile(), data, (uint)maxSize));
372 if(zipError!=ZIP_OK) return -1; 472 if(p->zipError!=ZIP_OK) return -1;
373 else { 473 else {
374 writePos+=maxSize; 474 p->writePos+=maxSize;
375 return maxSize; 475 return maxSize;
376 } 476 }
377} 477}
478
479QString QuaZipFile::getFileName() const
480{
481 return p->fileName;
482}
483
484QuaZip::CaseSensitivity QuaZipFile::getCaseSensitivity() const
485{
486 return p->caseSensitivity;
487}
488
489bool QuaZipFile::isRaw() const
490{
491 return p->raw;
492}
493
494int QuaZipFile::getZipError() const
495{
496 return p->zipError;
497}
498
499qint64 QuaZipFile::bytesAvailable() const
500{
501 return size() - pos();
502}
diff --git a/rbutil/rbutilqt/quazip/quazipfile.h b/rbutil/rbutilqt/quazip/quazipfile.h
index 09af5bceca..e27b7a4a6c 100644
--- a/rbutil/rbutilqt/quazip/quazipfile.h
+++ b/rbutil/rbutilqt/quazip/quazipfile.h
@@ -2,42 +2,37 @@
2#define QUA_ZIPFILE_H 2#define QUA_ZIPFILE_H
3 3
4/* 4/*
5-- A kind of "standard" GPL license statement -- 5Copyright (C) 2005-2014 Sergey A. Tachenov
6QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
7Copyright (C) 2005-2008 Sergey A. Tachenov
8 6
9This program is free software; you can redistribute it and/or modify it 7This file is part of QuaZIP.
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 8
14This program is distributed in the hope that it will be useful, but 9QuaZIP is free software: you can redistribute it and/or modify
15WITHOUT ANY WARRANTY; without even the implied warranty of 10it under the terms of the GNU Lesser General Public License as published by
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 11the Free Software Foundation, either version 2.1 of the License, or
17Public License for more details. 12(at your option) any later version.
18 13
19You should have received a copy of the GNU General Public License along 14QuaZIP is distributed in the hope that it will be useful,
20with this program; if not, write to the Free Software Foundation, Inc., 15but WITHOUT ANY WARRANTY; without even the implied warranty of
2159 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU Lesser General Public License for more details.
22 18
23-- A kind of "standard" GPL license statement ends here -- 19You should have received a copy of the GNU Lesser General Public License
20along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
24 21
25See COPYING file for GPL. 22See COPYING file for the full LGPL text.
26 23
27You are also permitted to use QuaZIP under the terms of LGPL (see 24Original ZIP package is copyrighted by Gilles Vollant, see
28COPYING.LGPL). You are free to choose either license, but please note 25quazip/(un)zip.h files for details, basically it's zlib license.
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 **/ 26 **/
35 27
36#include <QIODevice> 28#include <QIODevice>
37 29
30#include "quazip_global.h"
38#include "quazip.h" 31#include "quazip.h"
39#include "quazipnewinfo.h" 32#include "quazipnewinfo.h"
40 33
34class QuaZipFilePrivate;
35
41/// A file inside ZIP archive. 36/// A file inside ZIP archive.
42/** \class QuaZipFile quazipfile.h <quazip/quazipfile.h> 37/** \class QuaZipFile quazipfile.h <quazip/quazipfile.h>
43 * This is the most interesting class. Not only it provides C++ 38 * This is the most interesting class. Not only it provides C++
@@ -51,6 +46,14 @@ QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
51 * it will create internal QuaZip object. See constructors' descriptions 46 * it will create internal QuaZip object. See constructors' descriptions
52 * for details. Writing is only possible with the existing instance. 47 * for details. Writing is only possible with the existing instance.
53 * 48 *
49 * Note that due to the underlying library's limitation it is not
50 * possible to use multiple QuaZipFile instances to open several files
51 * in the same archive at the same time. If you need to write to
52 * multiple files in parallel, then you should write to temporary files
53 * first, then pack them all at once when you have finished writing. If
54 * you need to read multiple files inside the same archive in parallel,
55 * you should extract them all into a temporary directory first.
56 *
54 * \section quazipfile-sequential Sequential or random-access? 57 * \section quazipfile-sequential Sequential or random-access?
55 * 58 *
56 * At the first thought, QuaZipFile has fixed size, the start and the 59 * At the first thought, QuaZipFile has fixed size, the start and the
@@ -58,7 +61,7 @@ QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
58 * there is one major obstacle to making it random-access: ZIP/UNZIP API 61 * 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 62 * 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, 63 * through reopening the file and re-reading to the required position,
61 * but this is prohibitely slow. 64 * but this is prohibitively slow.
62 * 65 *
63 * Therefore, QuaZipFile is considered to be a sequential device. This 66 * Therefore, QuaZipFile is considered to be a sequential device. This
64 * has advantage of availability of the ungetChar() operation (QIODevice 67 * has advantage of availability of the ungetChar() operation (QIODevice
@@ -68,25 +71,14 @@ QuaZIP as long as you respect either GPL or LGPL for QuaZIP code.
68 * this class. 71 * this class.
69 * 72 *
70 **/ 73 **/
71class QuaZipFile: public QIODevice { 74class QUAZIP_EXPORT QuaZipFile: public QIODevice {
75 friend class QuaZipFilePrivate;
72 Q_OBJECT 76 Q_OBJECT
73 private: 77 private:
74 QuaZip *zip; 78 QuaZipFilePrivate *p;
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 79 // these are not supported nor implemented
85 QuaZipFile(const QuaZipFile& that); 80 QuaZipFile(const QuaZipFile& that);
86 QuaZipFile& operator=(const QuaZipFile& that); 81 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: 82 protected:
91 /// Implementation of the QIODevice::readData(). 83 /// Implementation of the QIODevice::readData().
92 qint64 readData(char *data, qint64 maxSize); 84 qint64 readData(char *data, qint64 maxSize);
@@ -212,7 +204,7 @@ class QuaZipFile: public QIODevice {
212 * 204 *
213 * \sa getActualFileName 205 * \sa getActualFileName
214 **/ 206 **/
215 QString getFileName()const {return fileName;} 207 QString getFileName() const;
216 /// Returns case sensitivity of the file name. 208 /// Returns case sensitivity of the file name.
217 /** This function returns case sensitivity argument you passed to 209 /** This function returns case sensitivity argument you passed to
218 * this object either by using 210 * this object either by using
@@ -225,7 +217,7 @@ class QuaZipFile: public QIODevice {
225 * 217 *
226 * \sa getFileName 218 * \sa getFileName
227 **/ 219 **/
228 QuaZip::CaseSensitivity getCaseSensitivity()const {return caseSensitivity;} 220 QuaZip::CaseSensitivity getCaseSensitivity() const;
229 /// Returns the actual file name in the archive. 221 /// Returns the actual file name in the archive.
230 /** This is \em not a ZIP archive file name, but a name of file inside 222 /** 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 223 * archive. It is not necessary the same name that you have passed
@@ -265,7 +257,7 @@ class QuaZipFile: public QIODevice {
265 * 257 *
266 * \sa open(OpenMode,int*,int*,bool,const char*) 258 * \sa open(OpenMode,int*,int*,bool,const char*)
267 **/ 259 **/
268 bool isRaw()const {return raw;} 260 bool isRaw() const;
269 /// Binds to the existing QuaZip instance. 261 /// Binds to the existing QuaZip instance.
270 /** This function destroys internal QuaZip object, if any, and makes 262 /** This function destroys internal QuaZip object, if any, and makes
271 * this QuaZipFile to use current file in the \a zip object for any 263 * this QuaZipFile to use current file in the \a zip object for any
@@ -303,7 +295,7 @@ class QuaZipFile: public QIODevice {
303 * Argument \a password specifies a password to decrypt the file. If 295 * Argument \a password specifies a password to decrypt the file. If
304 * it is NULL then this function behaves just like open(OpenMode). 296 * it is NULL then this function behaves just like open(OpenMode).
305 **/ 297 **/
306 bool open(OpenMode mode, const char *password) 298 inline bool open(OpenMode mode, const char *password)
307 {return open(mode, NULL, NULL, false, password);} 299 {return open(mode, NULL, NULL, false, password);}
308 /// Opens a file for reading. 300 /// Opens a file for reading.
309 /** \overload 301 /** \overload
@@ -324,14 +316,21 @@ class QuaZipFile: public QIODevice {
324 * specify correct timestamp (by default, current time will be 316 * specify correct timestamp (by default, current time will be
325 * used). See QuaZipNewInfo. 317 * used). See QuaZipNewInfo.
326 * 318 *
327 * Arguments \a password and \a crc provide necessary information 319 * The \a password argument specifies the password for crypting. Pass NULL
328 * for crypting. Note that you should specify both of them if you 320 * if you don't need any crypting. The \a crc argument was supposed
329 * need crypting. If you do not, pass \c NULL as password, but you 321 * to be used for crypting too, but then it turned out that it's
330 * still need to specify \a crc if you are going to use raw mode 322 * false information, so you need to set it to 0 unless you want to
331 * (see below). 323 * use the raw mode (see below).
332 * 324 *
333 * Arguments \a method and \a level specify compression method and 325 * Arguments \a method and \a level specify compression method and
334 * level. 326 * level. The only method supported is Z_DEFLATED, but you may also
327 * specify 0 for no compression. If all of the files in the archive
328 * use both method 0 and either level 0 is explicitly specified or
329 * data descriptor writing is disabled with
330 * QuaZip::setDataDescriptorWritingEnabled(), then the
331 * resulting archive is supposed to be compatible with the 1.0 ZIP
332 * format version, should you need that. Except for this, \a level
333 * has no other effects with method 0.
335 * 334 *
336 * If \a raw is \c true, no compression is performed. In this case, 335 * 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. 336 * \a crc and uncompressedSize field of the \a info are required.
@@ -428,15 +427,30 @@ class QuaZipFile: public QIODevice {
428 * 427 *
429 * File must be open for reading before calling this function. 428 * File must be open for reading before calling this function.
430 * 429 *
431 * Returns \c false in the case of an error. 430 * \return \c false in the case of an error.
431 *
432 * This function doesn't support zip64, but will still work fine on zip64
433 * archives if file sizes are below 4 GB, otherwise the values will be set
434 * as if converted using QuaZipFileInfo64::toQuaZipFileInfo().
435 *
436 * \sa getFileInfo(QuaZipFileInfo64*)
432 **/ 437 **/
433 bool getFileInfo(QuaZipFileInfo *info); 438 bool getFileInfo(QuaZipFileInfo *info);
439 /// Gets information about current file with zip64 support.
440 /**
441 * @overload
442 *
443 * \sa getFileInfo(QuaZipFileInfo*)
444 */
445 bool getFileInfo(QuaZipFileInfo64 *info);
434 /// Closes the file. 446 /// Closes the file.
435 /** Call getZipError() to determine if the close was successful. 447 /** Call getZipError() to determine if the close was successful.
436 **/ 448 **/
437 virtual void close(); 449 virtual void close();
438 /// Returns the error code returned by the last ZIP/UNZIP API call. 450 /// Returns the error code returned by the last ZIP/UNZIP API call.
439 int getZipError()const {return zipError;} 451 int getZipError() const;
452 /// Returns the number of bytes available for reading.
453 virtual qint64 bytesAvailable() const;
440}; 454};
441 455
442#endif 456#endif
diff --git a/rbutil/rbutilqt/quazip/quazipfileinfo.cpp b/rbutil/rbutilqt/quazip/quazipfileinfo.cpp
new file mode 100644
index 0000000000..f11c91017c
--- /dev/null
+++ b/rbutil/rbutilqt/quazip/quazipfileinfo.cpp
@@ -0,0 +1,176 @@
1/*
2Copyright (C) 2005-2014 Sergey A. Tachenov
3
4This file is part of QuaZIP.
5
6QuaZIP is free software: you can redistribute it and/or modify
7it under the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation, either version 2.1 of the License, or
9(at your option) any later version.
10
11QuaZIP is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License
17along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
18
19See COPYING file for the full LGPL text.
20
21Original ZIP package is copyrighted by Gilles Vollant and contributors,
22see quazip/(un)zip.h files for details. Basically it's the zlib license.
23*/
24
25#include "quazipfileinfo.h"
26
27static QFile::Permissions permissionsFromExternalAttr(quint32 externalAttr) {
28 quint32 uPerm = (externalAttr & 0xFFFF0000u) >> 16;
29 QFile::Permissions perm = 0;
30 if ((uPerm & 0400) != 0)
31 perm |= QFile::ReadOwner;
32 if ((uPerm & 0200) != 0)
33 perm |= QFile::WriteOwner;
34 if ((uPerm & 0100) != 0)
35 perm |= QFile::ExeOwner;
36 if ((uPerm & 0040) != 0)
37 perm |= QFile::ReadGroup;
38 if ((uPerm & 0020) != 0)
39 perm |= QFile::WriteGroup;
40 if ((uPerm & 0010) != 0)
41 perm |= QFile::ExeGroup;
42 if ((uPerm & 0004) != 0)
43 perm |= QFile::ReadOther;
44 if ((uPerm & 0002) != 0)
45 perm |= QFile::WriteOther;
46 if ((uPerm & 0001) != 0)
47 perm |= QFile::ExeOther;
48 return perm;
49
50}
51
52QFile::Permissions QuaZipFileInfo::getPermissions() const
53{
54 return permissionsFromExternalAttr(externalAttr);
55}
56
57QFile::Permissions QuaZipFileInfo64::getPermissions() const
58{
59 return permissionsFromExternalAttr(externalAttr);
60}
61
62bool QuaZipFileInfo64::toQuaZipFileInfo(QuaZipFileInfo &info) const
63{
64 bool noOverflow = true;
65 info.name = name;
66 info.versionCreated = versionCreated;
67 info.versionNeeded = versionNeeded;
68 info.flags = flags;
69 info.method = method;
70 info.dateTime = dateTime;
71 info.crc = crc;
72 if (compressedSize > 0xFFFFFFFFu) {
73 info.compressedSize = 0xFFFFFFFFu;
74 noOverflow = false;
75 } else {
76 info.compressedSize = compressedSize;
77 }
78 if (uncompressedSize > 0xFFFFFFFFu) {
79 info.uncompressedSize = 0xFFFFFFFFu;
80 noOverflow = false;
81 } else {
82 info.uncompressedSize = uncompressedSize;
83 }
84 info.diskNumberStart = diskNumberStart;
85 info.internalAttr = internalAttr;
86 info.externalAttr = externalAttr;
87 info.comment = comment;
88 info.extra = extra;
89 return noOverflow;
90}
91
92static QDateTime getNTFSTime(const QByteArray &extra, int position,
93 int *fineTicks)
94{
95 QDateTime dateTime;
96 for (int i = 0; i <= extra.size() - 4; ) {
97 unsigned type = static_cast<unsigned>(static_cast<unsigned char>(
98 extra.at(i)))
99 | (static_cast<unsigned>(static_cast<unsigned char>(
100 extra.at(i + 1))) << 8);
101 i += 2;
102 unsigned length = static_cast<unsigned>(static_cast<unsigned char>(
103 extra.at(i)))
104 | (static_cast<unsigned>(static_cast<unsigned char>(
105 extra.at(i + 1))) << 8);
106 i += 2;
107 if (type == QUAZIP_EXTRA_NTFS_MAGIC && length >= 32) {
108 i += 4; // reserved
109 while (i <= extra.size() - 4) {
110 unsigned tag = static_cast<unsigned>(
111 static_cast<unsigned char>(extra.at(i)))
112 | (static_cast<unsigned>(
113 static_cast<unsigned char>(extra.at(i + 1)))
114 << 8);
115 i += 2;
116 int tagsize = static_cast<unsigned>(
117 static_cast<unsigned char>(extra.at(i)))
118 | (static_cast<unsigned>(
119 static_cast<unsigned char>(extra.at(i + 1)))
120 << 8);
121 i += 2;
122 if (tag == QUAZIP_EXTRA_NTFS_TIME_MAGIC
123 && tagsize >= position + 8) {
124 i += position;
125 quint64 mtime = static_cast<quint64>(
126 static_cast<unsigned char>(extra.at(i)))
127 | (static_cast<quint64>(static_cast<unsigned char>(
128 extra.at(i + 1))) << 8)
129 | (static_cast<quint64>(static_cast<unsigned char>(
130 extra.at(i + 2))) << 16)
131 | (static_cast<quint64>(static_cast<unsigned char>(
132 extra.at(i + 3))) << 24)
133 | (static_cast<quint64>(static_cast<unsigned char>(
134 extra.at(i + 4))) << 32)
135 | (static_cast<quint64>(static_cast<unsigned char>(
136 extra.at(i + 5))) << 40)
137 | (static_cast<quint64>(static_cast<unsigned char>(
138 extra.at(i + 6))) << 48)
139 | (static_cast<quint64>(static_cast<unsigned char>(
140 extra.at(i + 7))) << 56);
141 // the NTFS time is measured from 1601 for whatever reason
142 QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
143 dateTime = base.addMSecs(mtime / 10000);
144 if (fineTicks != NULL) {
145 *fineTicks = static_cast<int>(mtime % 10000);
146 }
147 i += tagsize - position;
148 } else {
149 i += tagsize;
150 }
151
152 }
153 } else {
154 i += length;
155 }
156 }
157 if (fineTicks != NULL && dateTime.isNull()) {
158 *fineTicks = 0;
159 }
160 return dateTime;
161}
162
163QDateTime QuaZipFileInfo64::getNTFSmTime(int *fineTicks) const
164{
165 return getNTFSTime(extra, 0, fineTicks);
166}
167
168QDateTime QuaZipFileInfo64::getNTFSaTime(int *fineTicks) const
169{
170 return getNTFSTime(extra, 8, fineTicks);
171}
172
173QDateTime QuaZipFileInfo64::getNTFScTime(int *fineTicks) const
174{
175 return getNTFSTime(extra, 16, fineTicks);
176}
diff --git a/rbutil/rbutilqt/quazip/quazipfileinfo.h b/rbutil/rbutilqt/quazip/quazipfileinfo.h
index 3216d776d5..4e142a4eb5 100644
--- a/rbutil/rbutilqt/quazip/quazipfileinfo.h
+++ b/rbutil/rbutilqt/quazip/quazipfileinfo.h
@@ -2,44 +2,43 @@
2#define QUA_ZIPFILEINFO_H 2#define QUA_ZIPFILEINFO_H
3 3
4/* 4/*
5-- A kind of "standard" GPL license statement -- 5Copyright (C) 2005-2014 Sergey A. Tachenov
6QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
7Copyright (C) 2005-2007 Sergey A. Tachenov
8 6
9This program is free software; you can redistribute it and/or modify it 7This file is part of QuaZIP.
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 8
14This program is distributed in the hope that it will be useful, but 9QuaZIP is free software: you can redistribute it and/or modify
15WITHOUT ANY WARRANTY; without even the implied warranty of 10it under the terms of the GNU Lesser General Public License as published by
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 11the Free Software Foundation, either version 2.1 of the License, or
17Public License for more details. 12(at your option) any later version.
18 13
19You should have received a copy of the GNU General Public License along 14QuaZIP is distributed in the hope that it will be useful,
20with this program; if not, write to the Free Software Foundation, Inc., 15but WITHOUT ANY WARRANTY; without even the implied warranty of
2159 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU Lesser General Public License for more details.
22 18
23-- A kind of "standard" GPL license statement ends here -- 19You should have received a copy of the GNU Lesser General Public License
20along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
24 21
25See COPYING file for GPL. 22See COPYING file for the full LGPL text.
26 23
27You are also permitted to use QuaZIP under the terms of LGPL (see 24Original ZIP package is copyrighted by Gilles Vollant and contributors,
28COPYING.LGPL). You are free to choose either license, but please note 25see quazip/(un)zip.h files for details. Basically it's the zlib license.
29that QuaZIP makes use of Qt, which is not licensed under LGPL. So if 26*/
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 27
36#include <QByteArray> 28#include <QByteArray>
37#include <QDateTime> 29#include <QDateTime>
30#include <QFile>
31
32#include "quazip_global.h"
38 33
39/// Information about a file inside archive. 34/// Information about a file inside archive.
40/** Call QuaZip::getCurrentFileInfo() or QuaZipFile::getFileInfo() to 35/**
36 * \deprecated Use QuaZipFileInfo64 instead. Not only it supports large files,
37 * but also more convenience methods as well.
38 *
39 * Call QuaZip::getCurrentFileInfo() or QuaZipFile::getFileInfo() to
41 * fill this structure. */ 40 * fill this structure. */
42struct QuaZipFileInfo { 41struct QUAZIP_EXPORT QuaZipFileInfo {
43 /// File name. 42 /// File name.
44 QString name; 43 QString name;
45 /// Version created by. 44 /// Version created by.
@@ -68,6 +67,112 @@ struct QuaZipFileInfo {
68 QString comment; 67 QString comment;
69 /// Extra field. 68 /// Extra field.
70 QByteArray extra; 69 QByteArray extra;
70 /// Get the file permissions.
71 /**
72 Returns the high 16 bits of external attributes converted to
73 QFile::Permissions.
74 */
75 QFile::Permissions getPermissions() const;
76};
77
78/// Information about a file inside archive (with zip64 support).
79/** Call QuaZip::getCurrentFileInfo() or QuaZipFile::getFileInfo() to
80 * fill this structure. */
81struct QUAZIP_EXPORT QuaZipFileInfo64 {
82 /// File name.
83 QString name;
84 /// Version created by.
85 quint16 versionCreated;
86 /// Version needed to extract.
87 quint16 versionNeeded;
88 /// General purpose flags.
89 quint16 flags;
90 /// Compression method.
91 quint16 method;
92 /// Last modification date and time.
93 /**
94 * This is the time stored in the standard ZIP header. This format only allows
95 * to store time with 2-second precision, so the seconds will always be even
96 * and the milliseconds will always be zero. If you need more precise
97 * date and time, you can try to call the getNTFSmTime() function or
98 * its siblings, provided that the archive itself contains these NTFS times.
99 */
100 QDateTime dateTime;
101 /// CRC.
102 quint32 crc;
103 /// Compressed file size.
104 quint64 compressedSize;
105 /// Uncompressed file size.
106 quint64 uncompressedSize;
107 /// Disk number start.
108 quint16 diskNumberStart;
109 /// Internal file attributes.
110 quint16 internalAttr;
111 /// External file attributes.
112 quint32 externalAttr;
113 /// Comment.
114 QString comment;
115 /// Extra field.
116 QByteArray extra;
117 /// Get the file permissions.
118 /**
119 Returns the high 16 bits of external attributes converted to
120 QFile::Permissions.
121 */
122 QFile::Permissions getPermissions() const;
123 /// Converts to QuaZipFileInfo
124 /**
125 If any of the fields are greater than 0xFFFFFFFFu, they are set to
126 0xFFFFFFFFu exactly, not just truncated. This function should be mainly used
127 for compatibility with the old code expecting QuaZipFileInfo, in the cases
128 when it's impossible or otherwise unadvisable (due to ABI compatibility
129 reasons, for example) to modify that old code to use QuaZipFileInfo64.
130
131 \return \c true if all fields converted correctly, \c false if an overflow
132 occured.
133 */
134 bool toQuaZipFileInfo(QuaZipFileInfo &info) const;
135 /// Returns the NTFS modification time
136 /**
137 * The getNTFS*Time() functions only work if there is an NTFS extra field
138 * present. Otherwise, they all return invalid null timestamps.
139 * @param fineTicks If not NULL, the fractional part of milliseconds returned
140 * there, measured in 100-nanosecond ticks. Will be set to
141 * zero if there is no NTFS extra field.
142 * @sa dateTime
143 * @sa getNTFSaTime()
144 * @sa getNTFScTime()
145 * @return The NTFS modification time, UTC
146 */
147 QDateTime getNTFSmTime(int *fineTicks = NULL) const;
148 /// Returns the NTFS access time
149 /**
150 * The getNTFS*Time() functions only work if there is an NTFS extra field
151 * present. Otherwise, they all return invalid null timestamps.
152 * @param fineTicks If not NULL, the fractional part of milliseconds returned
153 * there, measured in 100-nanosecond ticks. Will be set to
154 * zero if there is no NTFS extra field.
155 * @sa dateTime
156 * @sa getNTFSmTime()
157 * @sa getNTFScTime()
158 * @return The NTFS access time, UTC
159 */
160 QDateTime getNTFSaTime(int *fineTicks = NULL) const;
161 /// Returns the NTFS creation time
162 /**
163 * The getNTFS*Time() functions only work if there is an NTFS extra field
164 * present. Otherwise, they all return invalid null timestamps.
165 * @param fineTicks If not NULL, the fractional part of milliseconds returned
166 * there, measured in 100-nanosecond ticks. Will be set to
167 * zero if there is no NTFS extra field.
168 * @sa dateTime
169 * @sa getNTFSmTime()
170 * @sa getNTFSaTime()
171 * @return The NTFS creation time, UTC
172 */
173 QDateTime getNTFScTime(int *fineTicks = NULL) const;
174 /// Checks whether the file is encrypted.
175 bool isEncrypted() const {return (flags & 1) != 0;}
71}; 176};
72 177
73#endif 178#endif
diff --git a/rbutil/rbutilqt/quazip/quazipnewinfo.cpp b/rbutil/rbutilqt/quazip/quazipnewinfo.cpp
index 17571f2fc8..02e01da9c5 100644
--- a/rbutil/rbutilqt/quazip/quazipnewinfo.cpp
+++ b/rbutil/rbutilqt/quazip/quazipnewinfo.cpp
@@ -1,53 +1,98 @@
1/* -- A kind of "standard" GPL license statement -- 1/*
2QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package 2Copyright (C) 2005-2014 Sergey A. Tachenov
3Copyright (C) 2005-2007 Sergey A. Tachenov 3
4 4This file is part of QuaZIP.
5This program is free software; you can redistribute it and/or modify it 5
6under the terms of the GNU General Public License as published by the 6QuaZIP is free software: you can redistribute it and/or modify
7Free Software Foundation; either version 2 of the License, or (at your 7it under the terms of the GNU Lesser General Public License as published by
8option) any later version. 8the Free Software Foundation, either version 2.1 of the License, or
9 9(at your option) any later version.
10This program is distributed in the hope that it will be useful, but 10
11WITHOUT ANY WARRANTY; without even the implied warranty of 11QuaZIP is distributed in the hope that it will be useful,
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 12but WITHOUT ANY WARRANTY; without even the implied warranty of
13Public License for more details. 13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14GNU Lesser General Public License for more details.
15You should have received a copy of the GNU General Public License along 15
16with this program; if not, write to the Free Software Foundation, Inc., 16You should have received a copy of the GNU Lesser General Public License
1759 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
18 18
19-- A kind of "standard" GPL license statement ends here -- 19See COPYING file for the full LGPL text.
20 20
21See COPYING file for GPL. 21Original ZIP package is copyrighted by Gilles Vollant and contributors,
22 22see quazip/(un)zip.h files for details. Basically it's the zlib license.
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*/ 23*/
31 24
32#include <QFileInfo> 25#include <QFileInfo>
33 26
34#include "quazipnewinfo.h" 27#include "quazipnewinfo.h"
35 28
29#include <string.h>
30
31static void QuaZipNewInfo_setPermissions(QuaZipNewInfo *info,
32 QFile::Permissions perm, bool isDir)
33{
34 quint32 uPerm = isDir ? 0040000 : 0100000;
35 if ((perm & QFile::ReadOwner) != 0)
36 uPerm |= 0400;
37 if ((perm & QFile::WriteOwner) != 0)
38 uPerm |= 0200;
39 if ((perm & QFile::ExeOwner) != 0)
40 uPerm |= 0100;
41 if ((perm & QFile::ReadGroup) != 0)
42 uPerm |= 0040;
43 if ((perm & QFile::WriteGroup) != 0)
44 uPerm |= 0020;
45 if ((perm & QFile::ExeGroup) != 0)
46 uPerm |= 0010;
47 if ((perm & QFile::ReadOther) != 0)
48 uPerm |= 0004;
49 if ((perm & QFile::WriteOther) != 0)
50 uPerm |= 0002;
51 if ((perm & QFile::ExeOther) != 0)
52 uPerm |= 0001;
53 info->externalAttr = (info->externalAttr & ~0xFFFF0000u) | (uPerm << 16);
54}
55
56template<typename FileInfo>
57void QuaZipNewInfo_init(QuaZipNewInfo &self, const FileInfo &existing)
58{
59 self.name = existing.name;
60 self.dateTime = existing.dateTime;
61 self.internalAttr = existing.internalAttr;
62 self.externalAttr = existing.externalAttr;
63 self.comment = existing.comment;
64 self.extraLocal = existing.extra;
65 self.extraGlobal = existing.extra;
66 self.uncompressedSize = existing.uncompressedSize;
67}
68
69QuaZipNewInfo::QuaZipNewInfo(const QuaZipFileInfo &existing)
70{
71 QuaZipNewInfo_init(*this, existing);
72}
73
74QuaZipNewInfo::QuaZipNewInfo(const QuaZipFileInfo64 &existing)
75{
76 QuaZipNewInfo_init(*this, existing);
77}
36 78
37QuaZipNewInfo::QuaZipNewInfo(const QString& name): 79QuaZipNewInfo::QuaZipNewInfo(const QString& name):
38 name(name), dateTime(QDateTime::currentDateTime()), internalAttr(0), externalAttr(0) 80 name(name), dateTime(QDateTime::currentDateTime()), internalAttr(0), externalAttr(0),
81 uncompressedSize(0)
39{ 82{
40} 83}
41 84
42QuaZipNewInfo::QuaZipNewInfo(const QString& name, const QString& file): 85QuaZipNewInfo::QuaZipNewInfo(const QString& name, const QString& file):
43 name(name), internalAttr(0), externalAttr(0) 86 name(name), internalAttr(0), externalAttr(0), uncompressedSize(0)
44{ 87{
45 QFileInfo info(file); 88 QFileInfo info(file);
46 QDateTime lm = info.lastModified(); 89 QDateTime lm = info.lastModified();
47 if (!info.exists()) 90 if (!info.exists()) {
48 dateTime = QDateTime::currentDateTime(); 91 dateTime = QDateTime::currentDateTime();
49 else 92 } else {
50 dateTime = lm; 93 dateTime = lm;
94 QuaZipNewInfo_setPermissions(this, info.permissions(), info.isDir());
95 }
51} 96}
52 97
53void QuaZipNewInfo::setFileDateTime(const QString& file) 98void QuaZipNewInfo::setFileDateTime(const QString& file)
@@ -57,3 +102,176 @@ void QuaZipNewInfo::setFileDateTime(const QString& file)
57 if (info.exists()) 102 if (info.exists())
58 dateTime = lm; 103 dateTime = lm;
59} 104}
105
106void QuaZipNewInfo::setFilePermissions(const QString &file)
107{
108 QFileInfo info = QFileInfo(file);
109 QFile::Permissions perm = info.permissions();
110 QuaZipNewInfo_setPermissions(this, perm, info.isDir());
111}
112
113void QuaZipNewInfo::setPermissions(QFile::Permissions permissions)
114{
115 QuaZipNewInfo_setPermissions(this, permissions, name.endsWith('/'));
116}
117
118void QuaZipNewInfo::setFileNTFSTimes(const QString &fileName)
119{
120 QFileInfo fi(fileName);
121 if (!fi.exists()) {
122 qWarning("QuaZipNewInfo::setFileNTFSTimes(): '%s' doesn't exist",
123 fileName.toUtf8().constData());
124 return;
125 }
126 setFileNTFSmTime(fi.lastModified());
127 setFileNTFSaTime(fi.lastRead());
128 setFileNTFScTime(fi.created());
129}
130
131static void setNTFSTime(QByteArray &extra, const QDateTime &time, int position,
132 int fineTicks) {
133 int ntfsPos = -1, timesPos = -1;
134 unsigned ntfsLength = 0, ntfsTimesLength = 0;
135 for (int i = 0; i <= extra.size() - 4; ) {
136 unsigned type = static_cast<unsigned>(static_cast<unsigned char>(
137 extra.at(i)))
138 | (static_cast<unsigned>(static_cast<unsigned char>(
139 extra.at(i + 1))) << 8);
140 i += 2;
141 unsigned length = static_cast<unsigned>(static_cast<unsigned char>(
142 extra.at(i)))
143 | (static_cast<unsigned>(static_cast<unsigned char>(
144 extra.at(i + 1))) << 8);
145 i += 2;
146 if (type == QUAZIP_EXTRA_NTFS_MAGIC) {
147 ntfsPos = i - 4; // the beginning of the NTFS record
148 ntfsLength = length;
149 if (length <= 4) {
150 break; // no times in the NTFS record
151 }
152 i += 4; // reserved
153 while (i <= extra.size() - 4) {
154 unsigned tag = static_cast<unsigned>(
155 static_cast<unsigned char>(extra.at(i)))
156 | (static_cast<unsigned>(
157 static_cast<unsigned char>(extra.at(i + 1)))
158 << 8);
159 i += 2;
160 unsigned tagsize = static_cast<unsigned>(
161 static_cast<unsigned char>(extra.at(i)))
162 | (static_cast<unsigned>(
163 static_cast<unsigned char>(extra.at(i + 1)))
164 << 8);
165 i += 2;
166 if (tag == QUAZIP_EXTRA_NTFS_TIME_MAGIC) {
167 timesPos = i - 4; // the beginning of the NTFS times tag
168 ntfsTimesLength = tagsize;
169 break;
170 } else {
171 i += tagsize;
172 }
173 }
174 break; // I ain't going to search for yet another NTFS record!
175 } else {
176 i += length;
177 }
178 }
179 if (ntfsPos == -1) {
180 // No NTFS record, need to create one.
181 ntfsPos = extra.size();
182 ntfsLength = 32;
183 extra.resize(extra.size() + 4 + ntfsLength);
184 // the NTFS record header
185 extra[ntfsPos] = static_cast<char>(QUAZIP_EXTRA_NTFS_MAGIC);
186 extra[ntfsPos + 1] = static_cast<char>(QUAZIP_EXTRA_NTFS_MAGIC >> 8);
187 extra[ntfsPos + 2] = 32; // the 2-byte size in LittleEndian
188 extra[ntfsPos + 3] = 0;
189 // zero the record
190 memset(extra.data() + ntfsPos + 4, 0, 32);
191 timesPos = ntfsPos + 8;
192 // now set the tag data
193 extra[timesPos] = static_cast<char>(QUAZIP_EXTRA_NTFS_TIME_MAGIC);
194 extra[timesPos + 1] = static_cast<char>(QUAZIP_EXTRA_NTFS_TIME_MAGIC
195 >> 8);
196 // the size:
197 extra[timesPos + 2] = 24;
198 extra[timesPos + 3] = 0;
199 ntfsTimesLength = 24;
200 }
201 if (timesPos == -1) {
202 // No time tag in the NTFS record, need to add one.
203 timesPos = ntfsPos + 4 + ntfsLength;
204 extra.resize(extra.size() + 28);
205 // Now we need to move the rest of the field
206 // (possibly zero bytes, but memmove() is OK with that).
207 // 0 ......... ntfsPos .. ntfsPos + 4 ... timesPos
208 // <some data> <header> <NTFS record> <need-to-move data> <end>
209 memmove(extra.data() + timesPos + 28, extra.data() + timesPos,
210 extra.size() - 28 - timesPos);
211 ntfsLength += 28;
212 // now set the tag data
213 extra[timesPos] = static_cast<char>(QUAZIP_EXTRA_NTFS_TIME_MAGIC);
214 extra[timesPos + 1] = static_cast<char>(QUAZIP_EXTRA_NTFS_TIME_MAGIC
215 >> 8);
216 // the size:
217 extra[timesPos + 2] = 24;
218 extra[timesPos + 3] = 0;
219 // zero the record
220 memset(extra.data() + timesPos + 4, 0, 24);
221 ntfsTimesLength = 24;
222 }
223 if (ntfsTimesLength < 24) {
224 // Broken times field. OK, this is really unlikely, but just in case...
225 size_t timesEnd = timesPos + 4 + ntfsTimesLength;
226 extra.resize(extra.size() + (24 - ntfsTimesLength));
227 // Move it!
228 // 0 ......... timesPos .... timesPos + 4 .. timesEnd
229 // <some data> <time header> <broken times> <need-to-move data> <end>
230 memmove(extra.data() + timesEnd + (24 - ntfsTimesLength),
231 extra.data() + timesEnd,
232 extra.size() - (24 - ntfsTimesLength) - timesEnd);
233 // Now we have to increase the NTFS record and time tag lengths.
234 ntfsLength += (24 - ntfsTimesLength);
235 ntfsTimesLength = 24;
236 extra[ntfsPos + 2] = static_cast<char>(ntfsLength);
237 extra[ntfsPos + 3] = static_cast<char>(ntfsLength >> 8);
238 extra[timesPos + 2] = static_cast<char>(ntfsTimesLength);
239 extra[timesPos + 3] = static_cast<char>(ntfsTimesLength >> 8);
240 }
241 QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
242#if (QT_VERSION >= 0x040700)
243 quint64 ticks = base.msecsTo(time) * 10000 + fineTicks;
244#else
245 QDateTime utc = time.toUTC();
246 quint64 ticks = (static_cast<qint64>(base.date().daysTo(utc.date()))
247 * Q_INT64_C(86400000)
248 + static_cast<qint64>(base.time().msecsTo(utc.time())))
249 * Q_INT64_C(10000) + fineTicks;
250#endif
251 extra[timesPos + 4 + position] = static_cast<char>(ticks);
252 extra[timesPos + 5 + position] = static_cast<char>(ticks >> 8);
253 extra[timesPos + 6 + position] = static_cast<char>(ticks >> 16);
254 extra[timesPos + 7 + position] = static_cast<char>(ticks >> 24);
255 extra[timesPos + 8 + position] = static_cast<char>(ticks >> 32);
256 extra[timesPos + 9 + position] = static_cast<char>(ticks >> 40);
257 extra[timesPos + 10 + position] = static_cast<char>(ticks >> 48);
258 extra[timesPos + 11 + position] = static_cast<char>(ticks >> 56);
259}
260
261void QuaZipNewInfo::setFileNTFSmTime(const QDateTime &mTime, int fineTicks)
262{
263 setNTFSTime(extraLocal, mTime, 0, fineTicks);
264 setNTFSTime(extraGlobal, mTime, 0, fineTicks);
265}
266
267void QuaZipNewInfo::setFileNTFSaTime(const QDateTime &aTime, int fineTicks)
268{
269 setNTFSTime(extraLocal, aTime, 8, fineTicks);
270 setNTFSTime(extraGlobal, aTime, 8, fineTicks);
271}
272
273void QuaZipNewInfo::setFileNTFScTime(const QDateTime &cTime, int fineTicks)
274{
275 setNTFSTime(extraLocal, cTime, 16, fineTicks);
276 setNTFSTime(extraGlobal, cTime, 16, fineTicks);
277}
diff --git a/rbutil/rbutilqt/quazip/quazipnewinfo.h b/rbutil/rbutilqt/quazip/quazipnewinfo.h
index 93ff1a2fc0..bfd498682f 100644
--- a/rbutil/rbutilqt/quazip/quazipnewinfo.h
+++ b/rbutil/rbutilqt/quazip/quazipnewinfo.h
@@ -2,47 +2,52 @@
2#define QUA_ZIPNEWINFO_H 2#define QUA_ZIPNEWINFO_H
3 3
4/* 4/*
5-- A kind of "standard" GPL license statement -- 5Copyright (C) 2005-2014 Sergey A. Tachenov
6QuaZIP - a Qt/C++ wrapper for the ZIP/UNZIP package
7Copyright (C) 2005-2007 Sergey A. Tachenov
8 6
9This program is free software; you can redistribute it and/or modify it 7This file is part of QuaZIP.
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 8
14This program is distributed in the hope that it will be useful, but 9QuaZIP is free software: you can redistribute it and/or modify
15WITHOUT ANY WARRANTY; without even the implied warranty of 10it under the terms of the GNU Lesser General Public License as published by
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 11the Free Software Foundation, either version 2.1 of the License, or
17Public License for more details. 12(at your option) any later version.
18 13
19You should have received a copy of the GNU General Public License along 14QuaZIP is distributed in the hope that it will be useful,
20with this program; if not, write to the Free Software Foundation, Inc., 15but WITHOUT ANY WARRANTY; without even the implied warranty of
2159 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU Lesser General Public License for more details.
22 18
23-- A kind of "standard" GPL license statement ends here -- 19You should have received a copy of the GNU Lesser General Public License
20along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
24 21
25See COPYING file for GPL. 22See COPYING file for the full LGPL text.
26 23
27You are also permitted to use QuaZIP under the terms of LGPL (see 24Original ZIP package is copyrighted by Gilles Vollant, see
28COPYING.LGPL). You are free to choose either license, but please note 25quazip/(un)zip.h files for details, basically it's zlib license.
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 **/ 26 **/
35 27
36#include <QDateTime> 28#include <QDateTime>
29#include <QFile>
37#include <QString> 30#include <QString>
38 31
32#include "quazip_global.h"
33
34#include "quazipfileinfo.h"
35
39/// Information about a file to be created. 36/// Information about a file to be created.
40/** This structure holds information about a file to be created inside 37/** This structure holds information about a file to be created inside
41 * ZIP archive. At least name should be set to something correct before 38 * ZIP archive. At least name should be set to something correct before
42 * passing this structure to 39 * passing this structure to
43 * QuaZipFile::open(OpenMode,const QuaZipNewInfo&,int,int,bool). 40 * QuaZipFile::open(OpenMode,const QuaZipNewInfo&,int,int,bool).
41 *
42 * Zip64 support of this structure is slightly limited: in the raw mode (when
43 * a pre-compressed file is written into a ZIP file as-is), it is necessary
44 * to specify the uncompressed file size and the appropriate field is 32 bit.
45 * Since the raw mode is used extremely rare, there is no real need to have
46 * a separate QuaZipNewInfo64 structure like QuaZipFileInfo64. It may be added
47 * in the future though, if there is a demand for the raw mode with zip64
48 * archives.
44 **/ 49 **/
45struct QuaZipNewInfo { 50struct QUAZIP_EXPORT QuaZipNewInfo {
46 /// File name. 51 /// File name.
47 /** This field holds file name inside archive, including path relative 52 /** This field holds file name inside archive, including path relative
48 * to archive root. 53 * to archive root.
@@ -58,6 +63,11 @@ struct QuaZipNewInfo {
58 /// File internal attributes. 63 /// File internal attributes.
59 quint16 internalAttr; 64 quint16 internalAttr;
60 /// File external attributes. 65 /// File external attributes.
66 /**
67 The highest 16 bits contain Unix file permissions and type (dir or
68 file). The constructor QuaZipNewInfo(const QString&, const QString&)
69 takes permissions from the provided file.
70 */
61 quint32 externalAttr; 71 quint32 externalAttr;
62 /// File comment. 72 /// File comment.
63 /** Will be encoded using QuaZip::getCommentCodec(). 73 /** Will be encoded using QuaZip::getCommentCodec().
@@ -79,15 +89,31 @@ struct QuaZipNewInfo {
79 **/ 89 **/
80 QuaZipNewInfo(const QString& name); 90 QuaZipNewInfo(const QString& name);
81 /// Constructs QuaZipNewInfo instance. 91 /// Constructs QuaZipNewInfo instance.
82 /** Initializes name with \a name and dateTime with timestamp of the 92 /** Initializes name with \a name. Timestamp and permissions are taken
83 * file named \a file. If the \a file does not exists or its timestamp 93 * from the specified file. If the \a file does not exists or its timestamp
84 * is inaccessible (e. g. you do not have read permission for the 94 * is inaccessible (e. g. you do not have read permission for the
85 * directory file in), uses current date and time. Attributes are 95 * directory file in), uses current time and zero permissions. Other attributes are
86 * initialized with zeros, comment and extra field with null values. 96 * initialized with zeros, comment and extra field with null values.
87 * 97 *
88 * \sa setFileDateTime() 98 * \sa setFileDateTime()
89 **/ 99 **/
90 QuaZipNewInfo(const QString& name, const QString& file); 100 QuaZipNewInfo(const QString& name, const QString& file);
101 /// Initializes the new instance from existing file info.
102 /** Mainly used when copying files between archives.
103 *
104 * Both extra fields are initialized to existing.extra.
105 * @brief QuaZipNewInfo
106 * @param existing
107 */
108 QuaZipNewInfo(const QuaZipFileInfo &existing);
109 /// Initializes the new instance from existing file info.
110 /** Mainly used when copying files between archives.
111 *
112 * Both extra fields are initialized to existing.extra.
113 * @brief QuaZipNewInfo
114 * @param existing
115 */
116 QuaZipNewInfo(const QuaZipFileInfo64 &existing);
91 /// Sets the file timestamp from the existing file. 117 /// Sets the file timestamp from the existing file.
92 /** Use this function to set the file timestamp from the existing 118 /** Use this function to set the file timestamp from the existing
93 * file. Use it like this: 119 * file. Use it like this:
@@ -104,6 +130,78 @@ struct QuaZipNewInfo {
104 * file is inaccessible). 130 * file is inaccessible).
105 **/ 131 **/
106 void setFileDateTime(const QString& file); 132 void setFileDateTime(const QString& file);
133 /// Sets the file permissions from the existing file.
134 /**
135 Takes permissions from the file and sets the high 16 bits of
136 external attributes. Uses QFileInfo to get permissions on all
137 platforms.
138 */
139 void setFilePermissions(const QString &file);
140 /// Sets the file permissions.
141 /**
142 Modifies the highest 16 bits of external attributes. The type part
143 is set to dir if the name ends with a slash, and to regular file
144 otherwise.
145 */
146 void setPermissions(QFile::Permissions permissions);
147 /// Sets the NTFS times from an existing file.
148 /**
149 * If the file doesn't exist, a warning is printed to the stderr and nothing
150 * is done. Otherwise, all three times, as reported by
151 * QFileInfo::lastModified(), QFileInfo::lastRead() and QFileInfo::created(),
152 * are written to the NTFS extra field record.
153 *
154 * The NTFS record is written to
155 * both the local and the global extra fields, updating the existing record
156 * if there is one, or creating a new one and appending it to the end
157 * of each extra field.
158 *
159 * The microseconds will be zero, as they aren't reported by QFileInfo.
160 * @param fileName
161 */
162 void setFileNTFSTimes(const QString &fileName);
163 /// Sets the NTFS modification time.
164 /**
165 * The time is written into the NTFS record in
166 * both the local and the global extra fields, updating the existing record
167 * if there is one, or creating a new one and appending it to the end
168 * of each extra field. When updating an existing record, all other fields
169 * are left intact.
170 * @param mTime The new modification time.
171 * @param fineTicks The fractional part of milliseconds, in 100-nanosecond
172 * ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than
173 * 9999 will add milliseconds or even seconds, but this can be
174 * confusing and therefore is discouraged.
175 */
176 void setFileNTFSmTime(const QDateTime &mTime, int fineTicks = 0);
177 /// Sets the NTFS access time.
178 /**
179 * The time is written into the NTFS record in
180 * both the local and the global extra fields, updating the existing record
181 * if there is one, or creating a new one and appending it to the end
182 * of each extra field. When updating an existing record, all other fields
183 * are left intact.
184 * @param aTime The new access time.
185 * @param fineTicks The fractional part of milliseconds, in 100-nanosecond
186 * ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than
187 * 9999 will add milliseconds or even seconds, but this can be
188 * confusing and therefore is discouraged.
189 */
190 void setFileNTFSaTime(const QDateTime &aTime, int fineTicks = 0);
191 /// Sets the NTFS creation time.
192 /**
193 * The time is written into the NTFS record in
194 * both the local and the global extra fields, updating the existing record
195 * if there is one, or creating a new one and appending it to the end
196 * of each extra field. When updating an existing record, all other fields
197 * are left intact.
198 * @param cTime The new creation time.
199 * @param fineTicks The fractional part of milliseconds, in 100-nanosecond
200 * ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than
201 * 9999 will add milliseconds or even seconds, but this can be
202 * confusing and therefore is discouraged.
203 */
204 void setFileNTFScTime(const QDateTime &cTime, int fineTicks = 0);
107}; 205};
108 206
109#endif 207#endif
diff --git a/rbutil/rbutilqt/quazip/unzip.c b/rbutil/rbutilqt/quazip/unzip.c
index ace7a08837..bca03f8323 100644
--- a/rbutil/rbutilqt/quazip/unzip.c
+++ b/rbutil/rbutilqt/quazip/unzip.c
@@ -1,44 +1,80 @@
1/* unzip.c -- IO for uncompress .zip files using zlib 1/* unzip.c -- IO for uncompress .zip files using zlib
2 Version 1.01e, February 12th, 2005 2 Version 1.1, February 14h, 2010
3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
3 4
4 Copyright (C) 1998-2005 Gilles Vollant 5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
5 6
6 Read unzip.h for more info 7 Modifications of Unzip for Zip64
7*/ 8 Copyright (C) 2007-2008 Even Rouault
9
10 Modifications for Zip64 support on both zip and unzip
11 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
12
13 Modifications for QIODevice support and other QuaZIP fixes
14 Copyright (C) 2005-2014 Sergey A. Tachenov
15
16 For more info read MiniZip_info.txt
17
18
19 ------------------------------------------------------------------------------------
20 Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
21 compatibility with older software. The following is from the original crypt.c.
22 Code woven in by Terry Thorsen 1/2003.
8 23
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. 24 Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
15 25
16 See the accompanying file LICENSE, version 2000-Apr-09 or later 26 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. 27 (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 28 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 29 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
20*/ 30
21/* 31 crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
22 crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
23 32
24 The encryption/decryption parts of this source code (as opposed to the 33 The encryption/decryption parts of this source code (as opposed to the
25 non-echoing password parts) were originally written in Europe. The 34 non-echoing password parts) were originally written in Europe. The
26 whole source package can be freely distributed, including from the USA. 35 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.) 36 (Prior to January 2000, re-export from the US was a violation of US law.)
28 */
29 37
30/* 38 This encryption code is a direct transcription of the algorithm from
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 39 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 40 file (appnote.txt) is distributed with the PKZIP program (even in the
34 version without encryption capabilities). 41 version without encryption capabilities).
35 */ 42
43 ------------------------------------------------------------------------------------
44
45 Changes in unzip.c
46
47 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos
48 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz*
49 2007-2008 - Even Rouault - Remove old C style function prototypes
50 2007-2008 - Even Rouault - Add unzip support for ZIP64
51
52 Copyright (C) 2007-2008 Even Rouault
53
54
55 Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again).
56 Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
57 should only read the compressed/uncompressed size from the Zip64 format if
58 the size from normal header was 0xFFFFFFFF
59 Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant
60 Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required)
61 Patch created by Daniel Borca
62
63 Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
64
65 Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson
66
67*/
36 68
37 69
38#include <stdio.h> 70#include <stdio.h>
39#include <stdlib.h> 71#include <stdlib.h>
40#include <string.h> 72#include <string.h>
73
41#include "zlib.h" 74#include "zlib.h"
75#if (ZLIB_VERNUM < 0x1270)
76typedef uLongf z_crc_t;
77#endif
42#include "unzip.h" 78#include "unzip.h"
43 79
44#ifdef STDC 80#ifdef STDC
@@ -85,16 +121,14 @@ woven in by Terry Thorsen 1/2003.
85#define SIZEZIPLOCALHEADER (0x1e) 121#define SIZEZIPLOCALHEADER (0x1e)
86 122
87 123
88
89
90const char unz_copyright[] = 124const char unz_copyright[] =
91 " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; 125 " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
92 126
93/* unz_file_info_interntal contain internal info about a file in zipfile*/ 127/* unz_file_info_interntal contain internal info about a file in zipfile*/
94typedef struct unz_file_info_internal_s 128typedef struct unz_file_info64_internal_s
95{ 129{
96 uLong offset_curfile;/* relative offset of local header 4 bytes */ 130 ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */
97} unz_file_info_internal; 131} unz_file_info64_internal;
98 132
99 133
100/* file_in_zip_read_info_s contain internal information about a file in zipfile, 134/* file_in_zip_read_info_s contain internal information about a file in zipfile,
@@ -104,52 +138,62 @@ typedef struct
104 char *read_buffer; /* internal buffer for compressed data */ 138 char *read_buffer; /* internal buffer for compressed data */
105 z_stream stream; /* zLib stream structure for inflate */ 139 z_stream stream; /* zLib stream structure for inflate */
106 140
107 uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ 141#ifdef HAVE_BZIP2
142 bz_stream bstream; /* bzLib stream structure for bziped */
143#endif
144
145 ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
108 uLong stream_initialised; /* flag set if stream structure is initialised*/ 146 uLong stream_initialised; /* flag set if stream structure is initialised*/
109 147
110 uLong offset_local_extrafield;/* offset of the local extra field */ 148 ZPOS64_T offset_local_extrafield;/* offset of the local extra field */
111 uInt size_local_extrafield;/* size of the local extra field */ 149 uInt size_local_extrafield;/* size of the local extra field */
112 uLong pos_local_extrafield; /* position in the local extra field in read*/ 150 ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/
151 ZPOS64_T total_out_64;
113 152
114 uLong crc32; /* crc32 of all data uncompressed */ 153 uLong crc32; /* crc32 of all data uncompressed */
115 uLong crc32_wait; /* crc32 we must obtain after decompress all */ 154 uLong crc32_wait; /* crc32 we must obtain after decompress all */
116 uLong rest_read_compressed; /* number of byte to be decompressed */ 155 ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
117 uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ 156 ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
118 zlib_filefunc_def z_filefunc; 157 zlib_filefunc64_32_def z_filefunc;
119 voidpf filestream; /* io structore of the zipfile */ 158 voidpf filestream; /* io structore of the zipfile */
120 uLong compression_method; /* compression method (0==store) */ 159 uLong compression_method; /* compression method (0==store) */
121 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 160 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
122 int raw; 161 int raw;
123} file_in_zip_read_info_s; 162} file_in_zip64_read_info_s;
124 163
125 164
126/* unz_s contain internal information about the zipfile 165/* unz64_s contain internal information about the zipfile
127*/ 166*/
128typedef struct 167typedef struct
129{ 168{
130 zlib_filefunc_def z_filefunc; 169 zlib_filefunc64_32_def z_filefunc;
170 int is64bitOpenFunction;
131 voidpf filestream; /* io structore of the zipfile */ 171 voidpf filestream; /* io structore of the zipfile */
132 unz_global_info gi; /* public global information */ 172 unz_global_info64 gi; /* public global information */
133 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 173 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
134 uLong num_file; /* number of the current file in the zipfile*/ 174 ZPOS64_T 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*/ 175 ZPOS64_T 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*/ 176 ZPOS64_T current_file_ok; /* flag about the usability of the current file*/
137 uLong central_pos; /* position of the beginning of the central dir*/ 177 ZPOS64_T central_pos; /* position of the beginning of the central dir*/
138 178
139 uLong size_central_dir; /* size of the central directory */ 179 ZPOS64_T size_central_dir; /* size of the central directory */
140 uLong offset_central_dir; /* offset of start of central directory with 180 ZPOS64_T offset_central_dir; /* offset of start of central directory with
141 respect to the starting disk number */ 181 respect to the starting disk number */
142 182
143 unz_file_info cur_file_info; /* public info about the current file in zip*/ 183 unz_file_info64 cur_file_info; /* public info about the current file in zip*/
144 unz_file_info_internal cur_file_info_internal; /* private info about it*/ 184 unz_file_info64_internal cur_file_info_internal; /* private info about it*/
145 file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current 185 file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current
146 file if we are decompressing it */ 186 file if we are decompressing it */
147 int encrypted; 187 int encrypted;
188
189 int isZip64;
190 unsigned flags;
191
148# ifndef NOUNCRYPT 192# ifndef NOUNCRYPT
149 unsigned long keys[3]; /* keys defining the pseudo-random sequence */ 193 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
150 const unsigned long* pcrc_32_tab; 194 const z_crc_t FAR * pcrc_32_tab;
151# endif 195# endif
152} unz_s; 196} unz64_s;
153 197
154 198
155#ifndef NOUNCRYPT 199#ifndef NOUNCRYPT
@@ -163,18 +207,15 @@ typedef struct
163*/ 207*/
164 208
165 209
166local int unzlocal_getByte OF(( 210local int unz64local_getByte OF((
167 const zlib_filefunc_def* pzlib_filefunc_def, 211 const zlib_filefunc64_32_def* pzlib_filefunc_def,
168 voidpf filestream, 212 voidpf filestream,
169 int *pi)); 213 int *pi));
170 214
171local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi) 215local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)
172 const zlib_filefunc_def* pzlib_filefunc_def;
173 voidpf filestream;
174 int *pi;
175{ 216{
176 unsigned char c; 217 unsigned char c;
177 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); 218 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
178 if (err==1) 219 if (err==1)
179 { 220 {
180 *pi = (int)c; 221 *pi = (int)c;
@@ -182,7 +223,7 @@ local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
182 } 223 }
183 else 224 else
184 { 225 {
185 if (ZERROR(*pzlib_filefunc_def,filestream)) 226 if (ZERROR64(*pzlib_filefunc_def,filestream))
186 return UNZ_ERRNO; 227 return UNZ_ERRNO;
187 else 228 else
188 return UNZ_EOF; 229 return UNZ_EOF;
@@ -193,26 +234,25 @@ local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
193/* =========================================================================== 234/* ===========================================================================
194 Reads a long in LSB order from the given gz_stream. Sets 235 Reads a long in LSB order from the given gz_stream. Sets
195*/ 236*/
196local int unzlocal_getShort OF(( 237local int unz64local_getShort OF((
197 const zlib_filefunc_def* pzlib_filefunc_def, 238 const zlib_filefunc64_32_def* pzlib_filefunc_def,
198 voidpf filestream, 239 voidpf filestream,
199 uLong *pX)); 240 uLong *pX));
200 241
201local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX) 242local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def,
202 const zlib_filefunc_def* pzlib_filefunc_def; 243 voidpf filestream,
203 voidpf filestream; 244 uLong *pX)
204 uLong *pX;
205{ 245{
206 uLong x ; 246 uLong x ;
207 int i; 247 int i = 0;
208 int err; 248 int err;
209 249
210 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 250 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
211 x = (uLong)i; 251 x = (uLong)i;
212 252
213 if (err==UNZ_OK) 253 if (err==UNZ_OK)
214 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 254 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
215 x += ((uLong)i)<<8; 255 x |= ((uLong)i)<<8;
216 256
217 if (err==UNZ_OK) 257 if (err==UNZ_OK)
218 *pX = x; 258 *pX = x;
@@ -221,33 +261,32 @@ local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
221 return err; 261 return err;
222} 262}
223 263
224local int unzlocal_getLong OF(( 264local int unz64local_getLong OF((
225 const zlib_filefunc_def* pzlib_filefunc_def, 265 const zlib_filefunc64_32_def* pzlib_filefunc_def,
226 voidpf filestream, 266 voidpf filestream,
227 uLong *pX)); 267 uLong *pX));
228 268
229local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX) 269local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def,
230 const zlib_filefunc_def* pzlib_filefunc_def; 270 voidpf filestream,
231 voidpf filestream; 271 uLong *pX)
232 uLong *pX;
233{ 272{
234 uLong x ; 273 uLong x ;
235 int i; 274 int i = 0;
236 int err; 275 int err;
237 276
238 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 277 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
239 x = (uLong)i; 278 x = (uLong)i;
240 279
241 if (err==UNZ_OK) 280 if (err==UNZ_OK)
242 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 281 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
243 x += ((uLong)i)<<8; 282 x |= ((uLong)i)<<8;
244 283
245 if (err==UNZ_OK) 284 if (err==UNZ_OK)
246 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 285 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
247 x += ((uLong)i)<<16; 286 x |= ((uLong)i)<<16;
248 287
249 if (err==UNZ_OK) 288 if (err==UNZ_OK)
250 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 289 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
251 x += ((uLong)i)<<24; 290 x += ((uLong)i)<<24;
252 291
253 if (err==UNZ_OK) 292 if (err==UNZ_OK)
@@ -257,11 +296,60 @@ local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
257 return err; 296 return err;
258} 297}
259 298
299local int unz64local_getLong64 OF((
300 const zlib_filefunc64_32_def* pzlib_filefunc_def,
301 voidpf filestream,
302 ZPOS64_T *pX));
303
304
305local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def,
306 voidpf filestream,
307 ZPOS64_T *pX)
308{
309 ZPOS64_T x ;
310 int i = 0;
311 int err;
312
313 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
314 x = (ZPOS64_T)i;
315
316 if (err==UNZ_OK)
317 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
318 x |= ((ZPOS64_T)i)<<8;
319
320 if (err==UNZ_OK)
321 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
322 x |= ((ZPOS64_T)i)<<16;
323
324 if (err==UNZ_OK)
325 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
326 x |= ((ZPOS64_T)i)<<24;
327
328 if (err==UNZ_OK)
329 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
330 x |= ((ZPOS64_T)i)<<32;
331
332 if (err==UNZ_OK)
333 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
334 x |= ((ZPOS64_T)i)<<40;
335
336 if (err==UNZ_OK)
337 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
338 x |= ((ZPOS64_T)i)<<48;
339
340 if (err==UNZ_OK)
341 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
342 x |= ((ZPOS64_T)i)<<56;
343
344 if (err==UNZ_OK)
345 *pX = x;
346 else
347 *pX = 0;
348 return err;
349}
260 350
261/* My own strcmpi / strcasecmp */ 351/* My own strcmpi / strcasecmp */
262local int strcmpcasenosensitive_internal (fileName1,fileName2) 352local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
263 const char* fileName1;
264 const char* fileName2;
265{ 353{
266 for (;;) 354 for (;;)
267 { 355 {
@@ -302,10 +390,10 @@ local int strcmpcasenosensitive_internal (fileName1,fileName2)
302 (like 1 on Unix, 2 on Windows) 390 (like 1 on Unix, 2 on Windows)
303 391
304*/ 392*/
305extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) 393extern int ZEXPORT unzStringFileNameCompare (const char* fileName1,
306 const char* fileName1; 394 const char* fileName2,
307 const char* fileName2; 395 int iCaseSensitivity)
308 int iCaseSensitivity; 396
309{ 397{
310 if (iCaseSensitivity==0) 398 if (iCaseSensitivity==0)
311 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; 399 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
@@ -324,25 +412,20 @@ extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivit
324 Locate the Central directory of a zipfile (at the end, just before 412 Locate the Central directory of a zipfile (at the end, just before
325 the global comment) 413 the global comment)
326*/ 414*/
327local uLong unzlocal_SearchCentralDir OF(( 415local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
328 const zlib_filefunc_def* pzlib_filefunc_def, 416local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
329 voidpf filestream));
330
331local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
332 const zlib_filefunc_def* pzlib_filefunc_def;
333 voidpf filestream;
334{ 417{
335 unsigned char* buf; 418 unsigned char* buf;
336 uLong uSizeFile; 419 ZPOS64_T uSizeFile;
337 uLong uBackRead; 420 ZPOS64_T uBackRead;
338 uLong uMaxBack=0xffff; /* maximum size of global comment */ 421 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
339 uLong uPosFound=0; 422 ZPOS64_T uPosFound=0;
340 423
341 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) 424 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
342 return 0; 425 return 0;
343 426
344 427
345 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); 428 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
346 429
347 if (uMaxBack>uSizeFile) 430 if (uMaxBack>uSizeFile)
348 uMaxBack = uSizeFile; 431 uMaxBack = uSizeFile;
@@ -354,7 +437,8 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
354 uBackRead = 4; 437 uBackRead = 4;
355 while (uBackRead<uMaxBack) 438 while (uBackRead<uMaxBack)
356 { 439 {
357 uLong uReadSize,uReadPos ; 440 uLong uReadSize;
441 ZPOS64_T uReadPos ;
358 int i; 442 int i;
359 if (uBackRead+BUFREADCOMMENT>uMaxBack) 443 if (uBackRead+BUFREADCOMMENT>uMaxBack)
360 uBackRead = uMaxBack; 444 uBackRead = uMaxBack;
@@ -363,11 +447,11 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
363 uReadPos = uSizeFile-uBackRead ; 447 uReadPos = uSizeFile-uBackRead ;
364 448
365 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 449 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
366 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); 450 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
367 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) 451 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
368 break; 452 break;
369 453
370 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) 454 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
371 break; 455 break;
372 456
373 for (i=(int)uReadSize-3; (i--)>0;) 457 for (i=(int)uReadSize-3; (i--)>0;)
@@ -385,6 +469,112 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
385 return uPosFound; 469 return uPosFound;
386} 470}
387 471
472
473/*
474 Locate the Central directory 64 of a zipfile (at the end, just before
475 the global comment)
476*/
477local ZPOS64_T unz64local_SearchCentralDir64 OF((
478 const zlib_filefunc64_32_def* pzlib_filefunc_def,
479 voidpf filestream));
480
481local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
482 voidpf filestream)
483{
484 unsigned char* buf;
485 ZPOS64_T uSizeFile;
486 ZPOS64_T uBackRead;
487 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
488 ZPOS64_T uPosFound=0;
489 uLong uL;
490 ZPOS64_T relativeOffset;
491
492 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
493 return 0;
494
495
496 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
497
498 if (uMaxBack>uSizeFile)
499 uMaxBack = uSizeFile;
500
501 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
502 if (buf==NULL)
503 return 0;
504
505 uBackRead = 4;
506 while (uBackRead<uMaxBack)
507 {
508 uLong uReadSize;
509 ZPOS64_T uReadPos;
510 int i;
511 if (uBackRead+BUFREADCOMMENT>uMaxBack)
512 uBackRead = uMaxBack;
513 else
514 uBackRead+=BUFREADCOMMENT;
515 uReadPos = uSizeFile-uBackRead ;
516
517 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
518 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
519 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
520 break;
521
522 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
523 break;
524
525 for (i=(int)uReadSize-3; (i--)>0;)
526 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
527 ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
528 {
529 uPosFound = uReadPos+i;
530 break;
531 }
532
533 if (uPosFound!=0)
534 break;
535 }
536 TRYFREE(buf);
537 if (uPosFound == 0)
538 return 0;
539
540 /* Zip64 end of central directory locator */
541 if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
542 return 0;
543
544 /* the signature, already checked */
545 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
546 return 0;
547
548 /* number of the disk with the start of the zip64 end of central directory */
549 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
550 return 0;
551 if (uL != 0)
552 return 0;
553
554 /* relative offset of the zip64 end of central directory record */
555 if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
556 return 0;
557
558 /* total number of disks */
559 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
560 return 0;
561 if (uL != 1)
562 return 0;
563
564 /* Goto end of central directory record */
565 if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
566 return 0;
567
568 /* the signature */
569 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
570 return 0;
571
572 if (uL != 0x06064b50)
573 return 0;
574
575 return relativeOffset;
576}
577
388/* 578/*
389 Open a Zip file. path contain the full pathname (by example, 579 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 580 on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
@@ -394,19 +584,20 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
394 Else, the return value is a unzFile Handle, usable with other function 584 Else, the return value is a unzFile Handle, usable with other function
395 of this unzip package. 585 of this unzip package.
396*/ 586*/
397extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) 587extern unzFile unzOpenInternal (voidpf file,
398 const char *path; 588 zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
399 zlib_filefunc_def* pzlib_filefunc_def; 589 int is64bitOpenFunction, unsigned flags)
400{ 590{
401 unz_s us; 591 unz64_s us;
402 unz_s *s; 592 unz64_s *s;
403 uLong central_pos,uL; 593 ZPOS64_T central_pos;
594 uLong uL;
404 595
405 uLong number_disk; /* number of the current dist, used for 596 uLong number_disk; /* number of the current dist, used for
406 spaning ZIP, unsupported, always 0*/ 597 spaning ZIP, unsupported, always 0*/
407 uLong number_disk_with_CD; /* number the the disk with central dir, used 598 uLong number_disk_with_CD; /* number the the disk with central dir, used
408 for spaning ZIP, unsupported, always 0*/ 599 for spaning ZIP, unsupported, always 0*/
409 uLong number_entry_CD; /* total number of entries in 600 ZPOS64_T number_entry_CD; /* total number of entries in
410 the central dir 601 the central dir
411 (same than number_entry on nospan) */ 602 (same than number_entry on nospan) */
412 603
@@ -415,63 +606,138 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
415 if (unz_copyright[0]!=' ') 606 if (unz_copyright[0]!=' ')
416 return NULL; 607 return NULL;
417 608
418 if (pzlib_filefunc_def==NULL) 609 us.flags = flags;
419 fill_fopen_filefunc(&us.z_filefunc); 610 us.z_filefunc.zseek32_file = NULL;
611 us.z_filefunc.ztell32_file = NULL;
612 if (pzlib_filefunc64_32_def==NULL)
613 fill_qiodevice64_filefunc(&us.z_filefunc.zfile_func64);
420 else 614 else
421 us.z_filefunc = *pzlib_filefunc_def; 615 us.z_filefunc = *pzlib_filefunc64_32_def;
616 us.is64bitOpenFunction = is64bitOpenFunction;
422 617
423 us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque, 618
424 path, 619
620 us.filestream = ZOPEN64(us.z_filefunc,
621 file,
425 ZLIB_FILEFUNC_MODE_READ | 622 ZLIB_FILEFUNC_MODE_READ |
426 ZLIB_FILEFUNC_MODE_EXISTING); 623 ZLIB_FILEFUNC_MODE_EXISTING);
427 if (us.filestream==NULL) 624 if (us.filestream==NULL)
428 return NULL; 625 return NULL;
429 626
430 central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream); 627 central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
431 if (central_pos==0) 628 if (central_pos)
432 err=UNZ_ERRNO; 629 {
630 uLong uS;
631 ZPOS64_T uL64;
632
633 us.isZip64 = 1;
433 634
434 if (ZSEEK(us.z_filefunc, us.filestream, 635 if (ZSEEK64(us.z_filefunc, us.filestream,
435 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) 636 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
436 err=UNZ_ERRNO; 637 err=UNZ_ERRNO;
437 638
438 /* the signature, already checked */ 639 /* the signature, already checked */
439 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 640 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
440 err=UNZ_ERRNO; 641 err=UNZ_ERRNO;
441 642
442 /* number of this disk */ 643 /* size of zip64 end of central directory record */
443 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) 644 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
444 err=UNZ_ERRNO; 645 err=UNZ_ERRNO;
445 646
446 /* number of the disk with the start of the central directory */ 647 /* version made by */
447 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) 648 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
448 err=UNZ_ERRNO; 649 err=UNZ_ERRNO;
449 650
450 /* total number of entries in the central dir on this disk */ 651 /* version needed to extract */
451 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) 652 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
452 err=UNZ_ERRNO; 653 err=UNZ_ERRNO;
453 654
454 /* total number of entries in the central dir */ 655 /* number of this disk */
455 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) 656 if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
456 err=UNZ_ERRNO; 657 err=UNZ_ERRNO;
457 658
458 if ((number_entry_CD!=us.gi.number_entry) || 659 /* number of the disk with the start of the central directory */
459 (number_disk_with_CD!=0) || 660 if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
460 (number_disk!=0)) 661 err=UNZ_ERRNO;
461 err=UNZ_BADZIPFILE;
462 662
463 /* size of the central directory */ 663 /* total number of entries in the central directory on this disk */
464 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) 664 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
465 err=UNZ_ERRNO; 665 err=UNZ_ERRNO;
666
667 /* total number of entries in the central directory */
668 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
669 err=UNZ_ERRNO;
466 670
467 /* offset of start of central directory with respect to the 671 if ((number_entry_CD!=us.gi.number_entry) ||
672 (number_disk_with_CD!=0) ||
673 (number_disk!=0))
674 err=UNZ_BADZIPFILE;
675
676 /* size of the central directory */
677 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
678 err=UNZ_ERRNO;
679
680 /* offset of start of central directory with respect to the
468 starting disk number */ 681 starting disk number */
469 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) 682 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
470 err=UNZ_ERRNO; 683 err=UNZ_ERRNO;
471 684
472 /* zipfile comment length */ 685 us.gi.size_comment = 0;
473 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) 686 }
474 err=UNZ_ERRNO; 687 else
688 {
689 central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
690 if (central_pos==0)
691 err=UNZ_ERRNO;
692
693 us.isZip64 = 0;
694
695 if (ZSEEK64(us.z_filefunc, us.filestream,
696 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
697 err=UNZ_ERRNO;
698
699 /* the signature, already checked */
700 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
701 err=UNZ_ERRNO;
702
703 /* number of this disk */
704 if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
705 err=UNZ_ERRNO;
706
707 /* number of the disk with the start of the central directory */
708 if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
709 err=UNZ_ERRNO;
710
711 /* total number of entries in the central dir on this disk */
712 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
713 err=UNZ_ERRNO;
714 us.gi.number_entry = uL;
715
716 /* total number of entries in the central dir */
717 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
718 err=UNZ_ERRNO;
719 number_entry_CD = uL;
720
721 if ((number_entry_CD!=us.gi.number_entry) ||
722 (number_disk_with_CD!=0) ||
723 (number_disk!=0))
724 err=UNZ_BADZIPFILE;
725
726 /* size of the central directory */
727 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
728 err=UNZ_ERRNO;
729 us.size_central_dir = uL;
730
731 /* offset of start of central directory with respect to the
732 starting disk number */
733 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
734 err=UNZ_ERRNO;
735 us.offset_central_dir = uL;
736
737 /* zipfile comment length */
738 if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
739 err=UNZ_ERRNO;
740 }
475 741
476 if ((central_pos<us.offset_central_dir+us.size_central_dir) && 742 if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
477 (err==UNZ_OK)) 743 (err==UNZ_OK))
@@ -479,7 +745,10 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
479 745
480 if (err!=UNZ_OK) 746 if (err!=UNZ_OK)
481 { 747 {
482 ZCLOSE(us.z_filefunc, us.filestream); 748 if ((us.flags & UNZ_AUTO_CLOSE) != 0)
749 ZCLOSE64(us.z_filefunc, us.filestream);
750 else
751 ZFAKECLOSE64(us.z_filefunc, us.filestream);
483 return NULL; 752 return NULL;
484 } 753 }
485 754
@@ -490,17 +759,52 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
490 us.encrypted = 0; 759 us.encrypted = 0;
491 760
492 761
493 s=(unz_s*)ALLOC(sizeof(unz_s)); 762 s=(unz64_s*)ALLOC(sizeof(unz64_s));
494 *s=us; 763 if( s != NULL)
495 unzGoToFirstFile((unzFile)s); 764 {
765 *s=us;
766 unzGoToFirstFile((unzFile)s);
767 }
496 return (unzFile)s; 768 return (unzFile)s;
497} 769}
498 770
499 771
500extern unzFile ZEXPORT unzOpen (path) 772extern unzFile ZEXPORT unzOpen2 (voidpf file,
501 const char *path; 773 zlib_filefunc_def* pzlib_filefunc32_def)
502{ 774{
503 return unzOpen2(path, NULL); 775 if (pzlib_filefunc32_def != NULL)
776 {
777 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
778 fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
779 return unzOpenInternal(file, &zlib_filefunc64_32_def_fill, 0, UNZ_DEFAULT_FLAGS);
780 }
781 else
782 return unzOpenInternal(file, NULL, 0, UNZ_DEFAULT_FLAGS);
783}
784
785extern unzFile ZEXPORT unzOpen2_64 (voidpf file,
786 zlib_filefunc64_def* pzlib_filefunc_def)
787{
788 if (pzlib_filefunc_def != NULL)
789 {
790 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
791 zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
792 zlib_filefunc64_32_def_fill.ztell32_file = NULL;
793 zlib_filefunc64_32_def_fill.zseek32_file = NULL;
794 return unzOpenInternal(file, &zlib_filefunc64_32_def_fill, 1, UNZ_DEFAULT_FLAGS);
795 }
796 else
797 return unzOpenInternal(file, NULL, 1, UNZ_DEFAULT_FLAGS);
798}
799
800extern unzFile ZEXPORT unzOpen (voidpf file)
801{
802 return unzOpenInternal(file, NULL, 0, UNZ_DEFAULT_FLAGS);
803}
804
805extern unzFile ZEXPORT unzOpen64 (voidpf file)
806{
807 return unzOpenInternal(file, NULL, 1, UNZ_DEFAULT_FLAGS);
504} 808}
505 809
506/* 810/*
@@ -508,18 +812,20 @@ extern unzFile ZEXPORT unzOpen (path)
508 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later), 812 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
509 these files MUST be closed with unzipCloseCurrentFile before call unzipClose. 813 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
510 return UNZ_OK if there is no problem. */ 814 return UNZ_OK if there is no problem. */
511extern int ZEXPORT unzClose (file) 815extern int ZEXPORT unzClose (unzFile file)
512 unzFile file;
513{ 816{
514 unz_s* s; 817 unz64_s* s;
515 if (file==NULL) 818 if (file==NULL)
516 return UNZ_PARAMERROR; 819 return UNZ_PARAMERROR;
517 s=(unz_s*)file; 820 s=(unz64_s*)file;
518 821
519 if (s->pfile_in_zip_read!=NULL) 822 if (s->pfile_in_zip_read!=NULL)
520 unzCloseCurrentFile(file); 823 unzCloseCurrentFile(file);
521 824
522 ZCLOSE(s->z_filefunc, s->filestream); 825 if ((s->flags & UNZ_AUTO_CLOSE) != 0)
826 ZCLOSE64(s->z_filefunc, s->filestream);
827 else
828 ZFAKECLOSE64(s->z_filefunc, s->filestream);
523 TRYFREE(s); 829 TRYFREE(s);
524 return UNZ_OK; 830 return UNZ_OK;
525} 831}
@@ -529,28 +835,34 @@ extern int ZEXPORT unzClose (file)
529 Write info about the ZipFile in the *pglobal_info structure. 835 Write info about the ZipFile in the *pglobal_info structure.
530 No preparation of the structure is needed 836 No preparation of the structure is needed
531 return UNZ_OK if there is no problem. */ 837 return UNZ_OK if there is no problem. */
532extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) 838extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info)
533 unzFile file;
534 unz_global_info *pglobal_info;
535{ 839{
536 unz_s* s; 840 unz64_s* s;
537 if (file==NULL) 841 if (file==NULL)
538 return UNZ_PARAMERROR; 842 return UNZ_PARAMERROR;
539 s=(unz_s*)file; 843 s=(unz64_s*)file;
540 *pglobal_info=s->gi; 844 *pglobal_info=s->gi;
541 return UNZ_OK; 845 return UNZ_OK;
542} 846}
543 847
544 848extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32)
849{
850 unz64_s* s;
851 if (file==NULL)
852 return UNZ_PARAMERROR;
853 s=(unz64_s*)file;
854 /* to do : check if number_entry is not truncated */
855 pglobal_info32->number_entry = (uLong)s->gi.number_entry;
856 pglobal_info32->size_comment = s->gi.size_comment;
857 return UNZ_OK;
858}
545/* 859/*
546 Translate date/time from Dos format to tm_unz (readable more easilty) 860 Translate date/time from Dos format to tm_unz (readable more easilty)
547*/ 861*/
548local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) 862local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
549 uLong ulDosDate;
550 tm_unz* ptm;
551{ 863{
552 uLong uDate; 864 ZPOS64_T uDate;
553 uDate = (uLong)(ulDosDate>>16); 865 uDate = (ZPOS64_T)(ulDosDate>>16);
554 ptm->tm_mday = (uInt)(uDate&0x1f) ; 866 ptm->tm_mday = (uInt)(uDate&0x1f) ;
555 ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; 867 ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
556 ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; 868 ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
@@ -563,9 +875,9 @@ local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
563/* 875/*
564 Get Info about the current file in the zipfile, with internal only info 876 Get Info about the current file in the zipfile, with internal only info
565*/ 877*/
566local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, 878local int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
567 unz_file_info *pfile_info, 879 unz_file_info64 *pfile_info,
568 unz_file_info_internal 880 unz_file_info64_internal
569 *pfile_info_internal, 881 *pfile_info_internal,
570 char *szFileName, 882 char *szFileName,
571 uLong fileNameBufferSize, 883 uLong fileNameBufferSize,
@@ -574,94 +886,95 @@ local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
574 char *szComment, 886 char *szComment,
575 uLong commentBufferSize)); 887 uLong commentBufferSize));
576 888
577local int unzlocal_GetCurrentFileInfoInternal (file, 889local int unz64local_GetCurrentFileInfoInternal (unzFile file,
578 pfile_info, 890 unz_file_info64 *pfile_info,
579 pfile_info_internal, 891 unz_file_info64_internal
580 szFileName, fileNameBufferSize, 892 *pfile_info_internal,
581 extraField, extraFieldBufferSize, 893 char *szFileName,
582 szComment, commentBufferSize) 894 uLong fileNameBufferSize,
583 unzFile file; 895 void *extraField,
584 unz_file_info *pfile_info; 896 uLong extraFieldBufferSize,
585 unz_file_info_internal *pfile_info_internal; 897 char *szComment,
586 char *szFileName; 898 uLong commentBufferSize)
587 uLong fileNameBufferSize;
588 void *extraField;
589 uLong extraFieldBufferSize;
590 char *szComment;
591 uLong commentBufferSize;
592{ 899{
593 unz_s* s; 900 unz64_s* s;
594 unz_file_info file_info; 901 unz_file_info64 file_info;
595 unz_file_info_internal file_info_internal; 902 unz_file_info64_internal file_info_internal;
596 int err=UNZ_OK; 903 int err=UNZ_OK;
597 uLong uMagic; 904 uLong uMagic;
598 long lSeek=0; 905 ZPOS64_T llSeek=0;
906 uLong uL;
599 907
600 if (file==NULL) 908 if (file==NULL)
601 return UNZ_PARAMERROR; 909 return UNZ_PARAMERROR;
602 s=(unz_s*)file; 910 s=(unz64_s*)file;
603 if (ZSEEK(s->z_filefunc, s->filestream, 911 if (ZSEEK64(s->z_filefunc, s->filestream,
604 s->pos_in_central_dir+s->byte_before_the_zipfile, 912 s->pos_in_central_dir+s->byte_before_the_zipfile,
605 ZLIB_FILEFUNC_SEEK_SET)!=0) 913 ZLIB_FILEFUNC_SEEK_SET)!=0)
606 err=UNZ_ERRNO; 914 err=UNZ_ERRNO;
607 915
608 916
609 /* we check the magic */ 917 /* we check the magic */
610 if (err==UNZ_OK) { 918 if (err==UNZ_OK)
611 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) 919 {
920 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
612 err=UNZ_ERRNO; 921 err=UNZ_ERRNO;
613 else if (uMagic!=0x02014b50) 922 else if (uMagic!=0x02014b50)
614 err=UNZ_BADZIPFILE; 923 err=UNZ_BADZIPFILE;
615 } 924 }
616 925
617 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) 926 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
618 err=UNZ_ERRNO; 927 err=UNZ_ERRNO;
619 928
620 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) 929 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
621 err=UNZ_ERRNO; 930 err=UNZ_ERRNO;
622 931
623 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) 932 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
624 err=UNZ_ERRNO; 933 err=UNZ_ERRNO;
625 934
626 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) 935 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
627 err=UNZ_ERRNO; 936 err=UNZ_ERRNO;
628 937
629 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) 938 if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
630 err=UNZ_ERRNO; 939 err=UNZ_ERRNO;
631 940
632 unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); 941 unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
633 942
634 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) 943 if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
635 err=UNZ_ERRNO; 944 err=UNZ_ERRNO;
636 945
637 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) 946 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
638 err=UNZ_ERRNO; 947 err=UNZ_ERRNO;
948 file_info.compressed_size = uL;
639 949
640 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) 950 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
641 err=UNZ_ERRNO; 951 err=UNZ_ERRNO;
952 file_info.uncompressed_size = uL;
642 953
643 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) 954 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
644 err=UNZ_ERRNO; 955 err=UNZ_ERRNO;
645 956
646 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) 957 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
647 err=UNZ_ERRNO; 958 err=UNZ_ERRNO;
648 959
649 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) 960 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
650 err=UNZ_ERRNO; 961 err=UNZ_ERRNO;
651 962
652 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) 963 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
653 err=UNZ_ERRNO; 964 err=UNZ_ERRNO;
654 965
655 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) 966 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
656 err=UNZ_ERRNO; 967 err=UNZ_ERRNO;
657 968
658 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) 969 if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
659 err=UNZ_ERRNO; 970 err=UNZ_ERRNO;
660 971
661 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) 972 /* relative offset of local header */
973 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
662 err=UNZ_ERRNO; 974 err=UNZ_ERRNO;
975 file_info_internal.offset_curfile = uL;
663 976
664 lSeek+=file_info.size_filename; 977 llSeek+=file_info.size_filename;
665 if ((err==UNZ_OK) && (szFileName!=NULL)) 978 if ((err==UNZ_OK) && (szFileName!=NULL))
666 { 979 {
667 uLong uSizeRead ; 980 uLong uSizeRead ;
@@ -674,35 +987,106 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
674 uSizeRead = fileNameBufferSize; 987 uSizeRead = fileNameBufferSize;
675 988
676 if ((file_info.size_filename>0) && (fileNameBufferSize>0)) 989 if ((file_info.size_filename>0) && (fileNameBufferSize>0))
677 if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) 990 if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
678 err=UNZ_ERRNO; 991 err=UNZ_ERRNO;
679 lSeek -= uSizeRead; 992 llSeek -= uSizeRead;
680 } 993 }
681 994
682 995 /* Read extrafield */
683 if ((err==UNZ_OK) && (extraField!=NULL)) 996 if ((err==UNZ_OK) && (extraField!=NULL))
684 { 997 {
685 uLong uSizeRead ; 998 ZPOS64_T uSizeRead ;
686 if (file_info.size_file_extra<extraFieldBufferSize) 999 if (file_info.size_file_extra<extraFieldBufferSize)
687 uSizeRead = file_info.size_file_extra; 1000 uSizeRead = file_info.size_file_extra;
688 else 1001 else
689 uSizeRead = extraFieldBufferSize; 1002 uSizeRead = extraFieldBufferSize;
690 1003
691 if (lSeek!=0) { 1004 if (llSeek!=0)
692 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 1005 {
693 lSeek=0; 1006 if (ZSEEK64(s->z_filefunc, s->filestream,llSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1007 llSeek=0;
694 else 1008 else
695 err=UNZ_ERRNO; 1009 err=UNZ_ERRNO;
696 } 1010 }
1011
697 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) 1012 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
698 if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead) 1013 if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead)
699 err=UNZ_ERRNO; 1014 err=UNZ_ERRNO;
700 lSeek += file_info.size_file_extra - uSizeRead; 1015
1016 llSeek += file_info.size_file_extra - (uLong)uSizeRead;
701 } 1017 }
702 else 1018 else
703 lSeek+=file_info.size_file_extra; 1019 llSeek += file_info.size_file_extra;
704 1020
705 1021
1022 if ((err==UNZ_OK) && (file_info.size_file_extra != 0))
1023 {
1024 uLong acc = 0;
1025
1026 /* since lSeek now points to after the extra field we need to move back */
1027 llSeek -= file_info.size_file_extra;
1028
1029 if (llSeek!=0)
1030 {
1031 if (ZSEEK64(s->z_filefunc, s->filestream,llSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1032 llSeek=0;
1033 else
1034 err=UNZ_ERRNO;
1035 }
1036
1037 while(acc < file_info.size_file_extra)
1038 {
1039 uLong headerId;
1040 uLong dataSize;
1041
1042 if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK)
1043 err=UNZ_ERRNO;
1044
1045 if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK)
1046 err=UNZ_ERRNO;
1047
1048 /* ZIP64 extra fields */
1049 if (headerId == 0x0001)
1050 {
1051 uLong uL;
1052
1053 if(file_info.uncompressed_size == (ZPOS64_T)0xFFFFFFFFu)
1054 {
1055 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
1056 err=UNZ_ERRNO;
1057 }
1058
1059 if(file_info.compressed_size == (ZPOS64_T)0xFFFFFFFFu)
1060 {
1061 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
1062 err=UNZ_ERRNO;
1063 }
1064
1065 if(file_info_internal.offset_curfile == (ZPOS64_T)0xFFFFFFFFu)
1066 {
1067 /* Relative Header offset */
1068 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
1069 err=UNZ_ERRNO;
1070 }
1071
1072 if(file_info.disk_num_start == 0xFFFFFFFFu)
1073 {
1074 /* Disk Start Number */
1075 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
1076 err=UNZ_ERRNO;
1077 }
1078
1079 }
1080 else
1081 {
1082 if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
1083 err=UNZ_ERRNO;
1084 }
1085
1086 acc += 2 + 2 + dataSize;
1087 }
1088 }
1089
706 if ((err==UNZ_OK) && (szComment!=NULL)) 1090 if ((err==UNZ_OK) && (szComment!=NULL))
707 { 1091 {
708 uLong uSizeRead ; 1092 uLong uSizeRead ;
@@ -714,19 +1098,22 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
714 else 1098 else
715 uSizeRead = commentBufferSize; 1099 uSizeRead = commentBufferSize;
716 1100
717 if (lSeek!=0) { 1101 if (llSeek!=0)
718 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 1102 {
719 lSeek=0; 1103 if (ZSEEK64(s->z_filefunc, s->filestream,llSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1104 llSeek=0;
720 else 1105 else
721 err=UNZ_ERRNO; 1106 err=UNZ_ERRNO;
722 } 1107 }
1108
723 if ((file_info.size_file_comment>0) && (commentBufferSize>0)) 1109 if ((file_info.size_file_comment>0) && (commentBufferSize>0))
724 if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) 1110 if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
725 err=UNZ_ERRNO; 1111 err=UNZ_ERRNO;
726 lSeek+=file_info.size_file_comment - uSizeRead; 1112 llSeek+=file_info.size_file_comment - uSizeRead;
727 } 1113 }
728 else 1114 else
729 lSeek+=file_info.size_file_comment; 1115 llSeek+=file_info.size_file_comment;
1116
730 1117
731 if ((err==UNZ_OK) && (pfile_info!=NULL)) 1118 if ((err==UNZ_OK) && (pfile_info!=NULL))
732 *pfile_info=file_info; 1119 *pfile_info=file_info;
@@ -744,41 +1131,70 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
744 No preparation of the structure is needed 1131 No preparation of the structure is needed
745 return UNZ_OK if there is no problem. 1132 return UNZ_OK if there is no problem.
746*/ 1133*/
747extern int ZEXPORT unzGetCurrentFileInfo (file, 1134extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file,
748 pfile_info, 1135 unz_file_info64 * pfile_info,
749 szFileName, fileNameBufferSize, 1136 char * szFileName, uLong fileNameBufferSize,
750 extraField, extraFieldBufferSize, 1137 void *extraField, uLong extraFieldBufferSize,
751 szComment, commentBufferSize) 1138 char* szComment, uLong 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{ 1139{
761 return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, 1140 return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
762 szFileName,fileNameBufferSize, 1141 szFileName,fileNameBufferSize,
763 extraField,extraFieldBufferSize, 1142 extraField,extraFieldBufferSize,
764 szComment,commentBufferSize); 1143 szComment,commentBufferSize);
765} 1144}
766 1145
1146extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
1147 unz_file_info * pfile_info,
1148 char * szFileName, uLong fileNameBufferSize,
1149 void *extraField, uLong extraFieldBufferSize,
1150 char* szComment, uLong commentBufferSize)
1151{
1152 int err;
1153 unz_file_info64 file_info64;
1154 err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
1155 szFileName,fileNameBufferSize,
1156 extraField,extraFieldBufferSize,
1157 szComment,commentBufferSize);
1158 if (err==UNZ_OK && pfile_info != NULL)
1159 {
1160 pfile_info->version = file_info64.version;
1161 pfile_info->version_needed = file_info64.version_needed;
1162 pfile_info->flag = file_info64.flag;
1163 pfile_info->compression_method = file_info64.compression_method;
1164 pfile_info->dosDate = file_info64.dosDate;
1165 pfile_info->crc = file_info64.crc;
1166
1167 pfile_info->size_filename = file_info64.size_filename;
1168 pfile_info->size_file_extra = file_info64.size_file_extra;
1169 pfile_info->size_file_comment = file_info64.size_file_comment;
1170
1171 pfile_info->disk_num_start = file_info64.disk_num_start;
1172 pfile_info->internal_fa = file_info64.internal_fa;
1173 pfile_info->external_fa = file_info64.external_fa;
1174
1175 pfile_info->tmu_date = file_info64.tmu_date,
1176
1177
1178 pfile_info->compressed_size = (uLong)file_info64.compressed_size;
1179 pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
1180
1181 }
1182 return err;
1183}
767/* 1184/*
768 Set the current file of the zipfile to the first file. 1185 Set the current file of the zipfile to the first file.
769 return UNZ_OK if there is no problem 1186 return UNZ_OK if there is no problem
770*/ 1187*/
771extern int ZEXPORT unzGoToFirstFile (file) 1188extern int ZEXPORT unzGoToFirstFile (unzFile file)
772 unzFile file;
773{ 1189{
774 int err=UNZ_OK; 1190 int err=UNZ_OK;
775 unz_s* s; 1191 unz64_s* s;
776 if (file==NULL) 1192 if (file==NULL)
777 return UNZ_PARAMERROR; 1193 return UNZ_PARAMERROR;
778 s=(unz_s*)file; 1194 s=(unz64_s*)file;
779 s->pos_in_central_dir=s->offset_central_dir; 1195 s->pos_in_central_dir=s->offset_central_dir;
780 s->num_file=0; 1196 s->num_file=0;
781 err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1197 err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
782 &s->cur_file_info_internal, 1198 &s->cur_file_info_internal,
783 NULL,0,NULL,0,NULL,0); 1199 NULL,0,NULL,0,NULL,0);
784 s->current_file_ok = (err == UNZ_OK); 1200 s->current_file_ok = (err == UNZ_OK);
@@ -790,15 +1206,14 @@ extern int ZEXPORT unzGoToFirstFile (file)
790 return UNZ_OK if there is no problem 1206 return UNZ_OK if there is no problem
791 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 1207 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
792*/ 1208*/
793extern int ZEXPORT unzGoToNextFile (file) 1209extern int ZEXPORT unzGoToNextFile (unzFile file)
794 unzFile file;
795{ 1210{
796 unz_s* s; 1211 unz64_s* s;
797 int err; 1212 int err;
798 1213
799 if (file==NULL) 1214 if (file==NULL)
800 return UNZ_PARAMERROR; 1215 return UNZ_PARAMERROR;
801 s=(unz_s*)file; 1216 s=(unz64_s*)file;
802 if (!s->current_file_ok) 1217 if (!s->current_file_ok)
803 return UNZ_END_OF_LIST_OF_FILE; 1218 return UNZ_END_OF_LIST_OF_FILE;
804 if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ 1219 if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
@@ -808,7 +1223,7 @@ extern int ZEXPORT unzGoToNextFile (file)
808 s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + 1223 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 ; 1224 s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
810 s->num_file++; 1225 s->num_file++;
811 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1226 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
812 &s->cur_file_info_internal, 1227 &s->cur_file_info_internal,
813 NULL,0,NULL,0,NULL,0); 1228 NULL,0,NULL,0,NULL,0);
814 s->current_file_ok = (err == UNZ_OK); 1229 s->current_file_ok = (err == UNZ_OK);
@@ -824,21 +1239,18 @@ extern int ZEXPORT unzGoToNextFile (file)
824 UNZ_OK if the file is found. It becomes the current file. 1239 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 1240 UNZ_END_OF_LIST_OF_FILE if the file is not found
826*/ 1241*/
827extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) 1242extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
828 unzFile file;
829 const char *szFileName;
830 int iCaseSensitivity;
831{ 1243{
832 unz_s* s; 1244 unz64_s* s;
833 int err; 1245 int err;
834 1246
835 /* We remember the 'current' position in the file so that we can jump 1247 /* We remember the 'current' position in the file so that we can jump
836 * back there if we fail. 1248 * back there if we fail.
837 */ 1249 */
838 unz_file_info cur_file_infoSaved; 1250 unz_file_info64 cur_file_infoSaved;
839 unz_file_info_internal cur_file_info_internalSaved; 1251 unz_file_info64_internal cur_file_info_internalSaved;
840 uLong num_fileSaved; 1252 ZPOS64_T num_fileSaved;
841 uLong pos_in_central_dirSaved; 1253 ZPOS64_T pos_in_central_dirSaved;
842 1254
843 1255
844 if (file==NULL) 1256 if (file==NULL)
@@ -847,7 +1259,7 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
847 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) 1259 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
848 return UNZ_PARAMERROR; 1260 return UNZ_PARAMERROR;
849 1261
850 s=(unz_s*)file; 1262 s=(unz64_s*)file;
851 if (!s->current_file_ok) 1263 if (!s->current_file_ok)
852 return UNZ_END_OF_LIST_OF_FILE; 1264 return UNZ_END_OF_LIST_OF_FILE;
853 1265
@@ -862,7 +1274,7 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
862 while (err == UNZ_OK) 1274 while (err == UNZ_OK)
863 { 1275 {
864 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; 1276 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
865 err = unzGetCurrentFileInfo(file,NULL, 1277 err = unzGetCurrentFileInfo64(file,NULL,
866 szCurrentFileName,sizeof(szCurrentFileName)-1, 1278 szCurrentFileName,sizeof(szCurrentFileName)-1,
867 NULL,0,NULL,0); 1279 NULL,0,NULL,0);
868 if (err == UNZ_OK) 1280 if (err == UNZ_OK)
@@ -898,20 +1310,18 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
898/* 1310/*
899typedef struct unz_file_pos_s 1311typedef struct unz_file_pos_s
900{ 1312{
901 uLong pos_in_zip_directory; // offset in file 1313 ZPOS64_T pos_in_zip_directory; // offset in file
902 uLong num_of_file; // # of file 1314 ZPOS64_T num_of_file; // # of file
903} unz_file_pos; 1315} unz_file_pos;
904*/ 1316*/
905 1317
906extern int ZEXPORT unzGetFilePos(file, file_pos) 1318extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos)
907 unzFile file;
908 unz_file_pos* file_pos;
909{ 1319{
910 unz_s* s; 1320 unz64_s* s;
911 1321
912 if (file==NULL || file_pos==NULL) 1322 if (file==NULL || file_pos==NULL)
913 return UNZ_PARAMERROR; 1323 return UNZ_PARAMERROR;
914 s=(unz_s*)file; 1324 s=(unz64_s*)file;
915 if (!s->current_file_ok) 1325 if (!s->current_file_ok)
916 return UNZ_END_OF_LIST_OF_FILE; 1326 return UNZ_END_OF_LIST_OF_FILE;
917 1327
@@ -921,23 +1331,35 @@ extern int ZEXPORT unzGetFilePos(file, file_pos)
921 return UNZ_OK; 1331 return UNZ_OK;
922} 1332}
923 1333
924extern int ZEXPORT unzGoToFilePos(file, file_pos) 1334extern int ZEXPORT unzGetFilePos(
925 unzFile file; 1335 unzFile file,
926 unz_file_pos* file_pos; 1336 unz_file_pos* file_pos)
927{ 1337{
928 unz_s* s; 1338 unz64_file_pos file_pos64;
1339 int err = unzGetFilePos64(file,&file_pos64);
1340 if (err==UNZ_OK)
1341 {
1342 file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
1343 file_pos->num_of_file = (uLong)file_pos64.num_of_file;
1344 }
1345 return err;
1346}
1347
1348extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
1349{
1350 unz64_s* s;
929 int err; 1351 int err;
930 1352
931 if (file==NULL || file_pos==NULL) 1353 if (file==NULL || file_pos==NULL)
932 return UNZ_PARAMERROR; 1354 return UNZ_PARAMERROR;
933 s=(unz_s*)file; 1355 s=(unz64_s*)file;
934 1356
935 /* jump to the right spot */ 1357 /* jump to the right spot */
936 s->pos_in_central_dir = file_pos->pos_in_zip_directory; 1358 s->pos_in_central_dir = file_pos->pos_in_zip_directory;
937 s->num_file = file_pos->num_of_file; 1359 s->num_file = file_pos->num_of_file;
938 1360
939 /* set the current file */ 1361 /* set the current file */
940 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1362 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
941 &s->cur_file_info_internal, 1363 &s->cur_file_info_internal,
942 NULL,0,NULL,0,NULL,0); 1364 NULL,0,NULL,0,NULL,0);
943 /* return results */ 1365 /* return results */
@@ -945,10 +1367,21 @@ extern int ZEXPORT unzGoToFilePos(file, file_pos)
945 return err; 1367 return err;
946} 1368}
947 1369
948/* 1370extern int ZEXPORT unzGoToFilePos(
949// Unzip Helper Functions - should be here? 1371 unzFile file,
950/////////////////////////////////////////// 1372 unz_file_pos* file_pos)
951*/ 1373{
1374 unz64_file_pos file_pos64;
1375 if (file_pos == NULL)
1376 return UNZ_PARAMERROR;
1377
1378 file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
1379 file_pos64.num_of_file = file_pos->num_of_file;
1380 return unzGoToFilePos64(file,&file_pos64);
1381}
1382
1383/* Unzip Helper Functions - should be here? */
1384/*///////////////////////////////////////// */
952 1385
953/* 1386/*
954 Read the local header of the current zipfile 1387 Read the local header of the current zipfile
@@ -957,13 +1390,9 @@ extern int ZEXPORT unzGoToFilePos(file, file_pos)
957 store in *piSizeVar the size of extra info in local header 1390 store in *piSizeVar the size of extra info in local header
958 (filename and size of extra field data) 1391 (filename and size of extra field data)
959*/ 1392*/
960local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, 1393local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar,
961 poffset_local_extrafield, 1394 ZPOS64_T * poffset_local_extrafield,
962 psize_local_extrafield) 1395 uInt * psize_local_extrafield)
963 unz_s* s;
964 uInt* piSizeVar;
965 uLong *poffset_local_extrafield;
966 uInt *psize_local_extrafield;
967{ 1396{
968 uLong uMagic,uData,uFlags; 1397 uLong uMagic,uData,uFlags;
969 uLong size_filename; 1398 uLong size_filename;
@@ -974,66 +1403,66 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
974 *poffset_local_extrafield = 0; 1403 *poffset_local_extrafield = 0;
975 *psize_local_extrafield = 0; 1404 *psize_local_extrafield = 0;
976 1405
977 if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + 1406 if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
978 s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) 1407 s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
979 return UNZ_ERRNO; 1408 return UNZ_ERRNO;
980 1409
981 1410
982 if (err==UNZ_OK) { 1411 if (err==UNZ_OK)
983 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) 1412 {
1413 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
984 err=UNZ_ERRNO; 1414 err=UNZ_ERRNO;
985 else if (uMagic!=0x04034b50) 1415 else if (uMagic!=0x04034b50)
986 err=UNZ_BADZIPFILE; 1416 err=UNZ_BADZIPFILE;
987 } 1417 }
988 1418
989 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) 1419 if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
990 err=UNZ_ERRNO; 1420 err=UNZ_ERRNO;
991/* 1421/*
992 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) 1422 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
993 err=UNZ_BADZIPFILE; 1423 err=UNZ_BADZIPFILE;
994*/ 1424*/
995 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) 1425 if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
996 err=UNZ_ERRNO; 1426 err=UNZ_ERRNO;
997 1427
998 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) 1428 if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
999 err=UNZ_ERRNO; 1429 err=UNZ_ERRNO;
1000 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) 1430 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
1001 err=UNZ_BADZIPFILE; 1431 err=UNZ_BADZIPFILE;
1002 1432
1003 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && 1433 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
1434/* #ifdef HAVE_BZIP2 */
1435 (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
1436/* #endif */
1004 (s->cur_file_info.compression_method!=Z_DEFLATED)) 1437 (s->cur_file_info.compression_method!=Z_DEFLATED))
1005 err=UNZ_BADZIPFILE; 1438 err=UNZ_BADZIPFILE;
1006 1439
1007 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ 1440 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
1008 err=UNZ_ERRNO; 1441 err=UNZ_ERRNO;
1009 1442
1010 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ 1443 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
1011 err=UNZ_ERRNO; 1444 err=UNZ_ERRNO;
1012 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && 1445 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0))
1013 ((uFlags & 8)==0))
1014 err=UNZ_BADZIPFILE; 1446 err=UNZ_BADZIPFILE;
1015 1447
1016 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ 1448 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
1017 err=UNZ_ERRNO; 1449 err=UNZ_ERRNO;
1018 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && 1450 else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0))
1019 ((uFlags & 8)==0))
1020 err=UNZ_BADZIPFILE; 1451 err=UNZ_BADZIPFILE;
1021 1452
1022 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ 1453 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
1023 err=UNZ_ERRNO; 1454 err=UNZ_ERRNO;
1024 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && 1455 else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0))
1025 ((uFlags & 8)==0))
1026 err=UNZ_BADZIPFILE; 1456 err=UNZ_BADZIPFILE;
1027 1457
1028 1458 if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1029 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1030 err=UNZ_ERRNO; 1459 err=UNZ_ERRNO;
1031 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) 1460 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1032 err=UNZ_BADZIPFILE; 1461 err=UNZ_BADZIPFILE;
1033 1462
1034 *piSizeVar += (uInt)size_filename; 1463 *piSizeVar += (uInt)size_filename;
1035 1464
1036 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) 1465 if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
1037 err=UNZ_ERRNO; 1466 err=UNZ_ERRNO;
1038 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + 1467 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
1039 SIZEZIPLOCALHEADER + size_filename; 1468 SIZEZIPLOCALHEADER + size_filename;
@@ -1048,18 +1477,14 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
1048 Open for reading data the current file in the zipfile. 1477 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. 1478 If there is no error and the file is opened, the return value is UNZ_OK.
1050*/ 1479*/
1051extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password) 1480extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
1052 unzFile file; 1481 int* level, int raw, const char* password)
1053 int* method;
1054 int* level;
1055 int raw;
1056 const char* password;
1057{ 1482{
1058 int err=UNZ_OK; 1483 int err=UNZ_OK;
1059 uInt iSizeVar; 1484 uInt iSizeVar;
1060 unz_s* s; 1485 unz64_s* s;
1061 file_in_zip_read_info_s* pfile_in_zip_read_info; 1486 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1062 uLong offset_local_extrafield; /* offset of the local extra field */ 1487 ZPOS64_T offset_local_extrafield; /* offset of the local extra field */
1063 uInt size_local_extrafield; /* size of the local extra field */ 1488 uInt size_local_extrafield; /* size of the local extra field */
1064# ifndef NOUNCRYPT 1489# ifndef NOUNCRYPT
1065 char source[12]; 1490 char source[12];
@@ -1070,19 +1495,17 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1070 1495
1071 if (file==NULL) 1496 if (file==NULL)
1072 return UNZ_PARAMERROR; 1497 return UNZ_PARAMERROR;
1073 s=(unz_s*)file; 1498 s=(unz64_s*)file;
1074 if (!s->current_file_ok) 1499 if (!s->current_file_ok)
1075 return UNZ_PARAMERROR; 1500 return UNZ_PARAMERROR;
1076 1501
1077 if (s->pfile_in_zip_read != NULL) 1502 if (s->pfile_in_zip_read != NULL)
1078 unzCloseCurrentFile(file); 1503 unzCloseCurrentFile(file);
1079 1504
1080 if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, 1505 if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1081 &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1082 return UNZ_BADZIPFILE; 1506 return UNZ_BADZIPFILE;
1083 1507
1084 pfile_in_zip_read_info = (file_in_zip_read_info_s*) 1508 pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s));
1085 ALLOC(sizeof(file_in_zip_read_info_s));
1086 if (pfile_in_zip_read_info==NULL) 1509 if (pfile_in_zip_read_info==NULL)
1087 return UNZ_INTERNALERROR; 1510 return UNZ_INTERNALERROR;
1088 1511
@@ -1115,31 +1538,60 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1115 } 1538 }
1116 1539
1117 if ((s->cur_file_info.compression_method!=0) && 1540 if ((s->cur_file_info.compression_method!=0) &&
1541/* #ifdef HAVE_BZIP2 */
1542 (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
1543/* #endif */
1118 (s->cur_file_info.compression_method!=Z_DEFLATED)) 1544 (s->cur_file_info.compression_method!=Z_DEFLATED))
1545
1119 err=UNZ_BADZIPFILE; 1546 err=UNZ_BADZIPFILE;
1120 1547
1121 pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; 1548 pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
1122 pfile_in_zip_read_info->crc32=0; 1549 pfile_in_zip_read_info->crc32=0;
1123 pfile_in_zip_read_info->compression_method = 1550 pfile_in_zip_read_info->total_out_64=0;
1124 s->cur_file_info.compression_method; 1551 pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
1125 pfile_in_zip_read_info->filestream=s->filestream; 1552 pfile_in_zip_read_info->filestream=s->filestream;
1126 pfile_in_zip_read_info->z_filefunc=s->z_filefunc; 1553 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; 1554 pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
1128 1555
1129 pfile_in_zip_read_info->stream.total_out = 0; 1556 pfile_in_zip_read_info->stream.total_out = 0;
1130 1557
1131 if ((s->cur_file_info.compression_method==Z_DEFLATED) && 1558 if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw))
1132 (!raw))
1133 { 1559 {
1560#ifdef HAVE_BZIP2
1561 pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
1562 pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
1563 pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
1564 pfile_in_zip_read_info->bstream.state = (voidpf)0;
1565
1134 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; 1566 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1135 pfile_in_zip_read_info->stream.zfree = (free_func)0; 1567 pfile_in_zip_read_info->stream.zfree = (free_func)0;
1136 pfile_in_zip_read_info->stream.opaque = (voidpf)0; 1568 pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1137 pfile_in_zip_read_info->stream.next_in = (voidpf)0; 1569 pfile_in_zip_read_info->stream.next_in = (voidpf)0;
1138 pfile_in_zip_read_info->stream.avail_in = 0; 1570 pfile_in_zip_read_info->stream.avail_in = 0;
1139 1571
1572 err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
1573 if (err == Z_OK)
1574 pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
1575 else
1576 {
1577 TRYFREE(pfile_in_zip_read_info);
1578 return err;
1579 }
1580#else
1581 pfile_in_zip_read_info->raw=1;
1582#endif
1583 }
1584 else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
1585 {
1586 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1587 pfile_in_zip_read_info->stream.zfree = (free_func)0;
1588 pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1589 pfile_in_zip_read_info->stream.next_in = 0;
1590 pfile_in_zip_read_info->stream.avail_in = 0;
1591
1140 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); 1592 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1141 if (err == Z_OK) 1593 if (err == Z_OK)
1142 pfile_in_zip_read_info->stream_initialised=1; 1594 pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
1143 else 1595 else
1144 { 1596 {
1145 TRYFREE(pfile_in_zip_read_info); 1597 TRYFREE(pfile_in_zip_read_info);
@@ -1166,6 +1618,7 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1166 pfile_in_zip_read_info->stream.avail_in = (uInt)0; 1618 pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1167 1619
1168 s->pfile_in_zip_read = pfile_in_zip_read_info; 1620 s->pfile_in_zip_read = pfile_in_zip_read_info;
1621 s->encrypted = 0;
1169 1622
1170# ifndef NOUNCRYPT 1623# ifndef NOUNCRYPT
1171 if (password != NULL) 1624 if (password != NULL)
@@ -1173,12 +1626,12 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1173 int i; 1626 int i;
1174 s->pcrc_32_tab = get_crc_table(); 1627 s->pcrc_32_tab = get_crc_table();
1175 init_keys(password,s->keys,s->pcrc_32_tab); 1628 init_keys(password,s->keys,s->pcrc_32_tab);
1176 if (ZSEEK(s->z_filefunc, s->filestream, 1629 if (ZSEEK64(s->z_filefunc, s->filestream,
1177 s->pfile_in_zip_read->pos_in_zipfile + 1630 s->pfile_in_zip_read->pos_in_zipfile +
1178 s->pfile_in_zip_read->byte_before_the_zipfile, 1631 s->pfile_in_zip_read->byte_before_the_zipfile,
1179 SEEK_SET)!=0) 1632 SEEK_SET)!=0)
1180 return UNZ_INTERNALERROR; 1633 return UNZ_INTERNALERROR;
1181 if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12) 1634 if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12)
1182 return UNZ_INTERNALERROR; 1635 return UNZ_INTERNALERROR;
1183 1636
1184 for (i = 0; i<12; i++) 1637 for (i = 0; i<12; i++)
@@ -1193,28 +1646,39 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1193 return UNZ_OK; 1646 return UNZ_OK;
1194} 1647}
1195 1648
1196extern int ZEXPORT unzOpenCurrentFile (file) 1649extern int ZEXPORT unzOpenCurrentFile (unzFile file)
1197 unzFile file;
1198{ 1650{
1199 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); 1651 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1200} 1652}
1201 1653
1202extern int ZEXPORT unzOpenCurrentFilePassword (file, password) 1654extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password)
1203 unzFile file;
1204 const char* password;
1205{ 1655{
1206 return unzOpenCurrentFile3(file, NULL, NULL, 0, password); 1656 return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1207} 1657}
1208 1658
1209extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw) 1659extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
1210 unzFile file;
1211 int* method;
1212 int* level;
1213 int raw;
1214{ 1660{
1215 return unzOpenCurrentFile3(file, method, level, raw, NULL); 1661 return unzOpenCurrentFile3(file, method, level, raw, NULL);
1216} 1662}
1217 1663
1664/** Addition for GDAL : START */
1665
1666extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file)
1667{
1668 unz64_s* s;
1669 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1670 s=(unz64_s*)file;
1671 if (file==NULL)
1672 return 0; /*UNZ_PARAMERROR; */
1673 pfile_in_zip_read_info=s->pfile_in_zip_read;
1674 if (pfile_in_zip_read_info==NULL)
1675 return 0; /*UNZ_PARAMERROR; */
1676 return pfile_in_zip_read_info->pos_in_zipfile +
1677 pfile_in_zip_read_info->byte_before_the_zipfile;
1678}
1679
1680/** Addition for GDAL : END */
1681
1218/* 1682/*
1219 Read bytes from the current file. 1683 Read bytes from the current file.
1220 buf contain buffer where data must be copied 1684 buf contain buffer where data must be copied
@@ -1225,25 +1689,22 @@ extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
1225 return <0 with error code if there is an error 1689 return <0 with error code if there is an error
1226 (UNZ_ERRNO for IO error, or zLib error for uncompress error) 1690 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
1227*/ 1691*/
1228extern int ZEXPORT unzReadCurrentFile (file, buf, len) 1692extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
1229 unzFile file;
1230 voidp buf;
1231 unsigned len;
1232{ 1693{
1233 int err=UNZ_OK; 1694 int err=UNZ_OK;
1234 uInt iRead = 0; 1695 uInt iRead = 0;
1235 unz_s* s; 1696 unz64_s* s;
1236 file_in_zip_read_info_s* pfile_in_zip_read_info; 1697 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1237 if (file==NULL) 1698 if (file==NULL)
1238 return UNZ_PARAMERROR; 1699 return UNZ_PARAMERROR;
1239 s=(unz_s*)file; 1700 s=(unz64_s*)file;
1240 pfile_in_zip_read_info=s->pfile_in_zip_read; 1701 pfile_in_zip_read_info=s->pfile_in_zip_read;
1241 1702
1242 if (pfile_in_zip_read_info==NULL) 1703 if (pfile_in_zip_read_info==NULL)
1243 return UNZ_PARAMERROR; 1704 return UNZ_PARAMERROR;
1244 1705
1245 1706
1246 if ((pfile_in_zip_read_info->read_buffer == NULL)) 1707 if (pfile_in_zip_read_info->read_buffer == NULL)
1247 return UNZ_END_OF_LIST_OF_FILE; 1708 return UNZ_END_OF_LIST_OF_FILE;
1248 if (len==0) 1709 if (len==0)
1249 return 0; 1710 return 0;
@@ -1274,13 +1735,13 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1274 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed; 1735 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
1275 if (uReadThis == 0) 1736 if (uReadThis == 0)
1276 return UNZ_EOF; 1737 return UNZ_EOF;
1277 if (ZSEEK(pfile_in_zip_read_info->z_filefunc, 1738 if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
1278 pfile_in_zip_read_info->filestream, 1739 pfile_in_zip_read_info->filestream,
1279 pfile_in_zip_read_info->pos_in_zipfile + 1740 pfile_in_zip_read_info->pos_in_zipfile +
1280 pfile_in_zip_read_info->byte_before_the_zipfile, 1741 pfile_in_zip_read_info->byte_before_the_zipfile,
1281 ZLIB_FILEFUNC_SEEK_SET)!=0) 1742 ZLIB_FILEFUNC_SEEK_SET)!=0)
1282 return UNZ_ERRNO; 1743 return UNZ_ERRNO;
1283 if (ZREAD(pfile_in_zip_read_info->z_filefunc, 1744 if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
1284 pfile_in_zip_read_info->filestream, 1745 pfile_in_zip_read_info->filestream,
1285 pfile_in_zip_read_info->read_buffer, 1746 pfile_in_zip_read_info->read_buffer,
1286 uReadThis)!=uReadThis) 1747 uReadThis)!=uReadThis)
@@ -1326,6 +1787,8 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1326 *(pfile_in_zip_read_info->stream.next_out+i) = 1787 *(pfile_in_zip_read_info->stream.next_out+i) =
1327 *(pfile_in_zip_read_info->stream.next_in+i); 1788 *(pfile_in_zip_read_info->stream.next_in+i);
1328 1789
1790 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy;
1791
1329 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, 1792 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
1330 pfile_in_zip_read_info->stream.next_out, 1793 pfile_in_zip_read_info->stream.next_out,
1331 uDoCopy); 1794 uDoCopy);
@@ -1337,11 +1800,54 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1337 pfile_in_zip_read_info->stream.total_out += uDoCopy; 1800 pfile_in_zip_read_info->stream.total_out += uDoCopy;
1338 iRead += uDoCopy; 1801 iRead += uDoCopy;
1339 } 1802 }
1340 else 1803 else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
1341 { 1804 {
1805#ifdef HAVE_BZIP2
1342 uLong uTotalOutBefore,uTotalOutAfter; 1806 uLong uTotalOutBefore,uTotalOutAfter;
1343 const Bytef *bufBefore; 1807 const Bytef *bufBefore;
1344 uLong uOutThis; 1808 uLong uOutThis;
1809
1810 pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in;
1811 pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in;
1812 pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in;
1813 pfile_in_zip_read_info->bstream.total_in_hi32 = 0;
1814 pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out;
1815 pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out;
1816 pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
1817 pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
1818
1819 uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
1820 bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out;
1821
1822 err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
1823
1824 uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
1825 uOutThis = uTotalOutAfter-uTotalOutBefore;
1826
1827 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
1828
1829 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis));
1830 pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
1831 iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
1832
1833 pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in;
1834 pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in;
1835 pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32;
1836 pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out;
1837 pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
1838 pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
1839
1840 if (err==BZ_STREAM_END)
1841 return (iRead==0) ? UNZ_EOF : iRead;
1842 if (err!=BZ_OK)
1843 break;
1844#endif
1845 } /* end Z_BZIP2ED */
1846 else
1847 {
1848 ZPOS64_T uTotalOutBefore,uTotalOutAfter;
1849 const Bytef *bufBefore;
1850 ZPOS64_T uOutThis;
1345 int flush=Z_SYNC_FLUSH; 1851 int flush=Z_SYNC_FLUSH;
1346 1852
1347 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; 1853 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
@@ -1361,6 +1867,8 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1361 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; 1867 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1362 uOutThis = uTotalOutAfter-uTotalOutBefore; 1868 uOutThis = uTotalOutAfter-uTotalOutBefore;
1363 1869
1870 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
1871
1364 pfile_in_zip_read_info->crc32 = 1872 pfile_in_zip_read_info->crc32 =
1365 crc32(pfile_in_zip_read_info->crc32,bufBefore, 1873 crc32(pfile_in_zip_read_info->crc32,bufBefore,
1366 (uInt)(uOutThis)); 1874 (uInt)(uOutThis));
@@ -1386,14 +1894,13 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1386/* 1894/*
1387 Give the current position in uncompressed data 1895 Give the current position in uncompressed data
1388*/ 1896*/
1389extern z_off_t ZEXPORT unztell (file) 1897extern z_off_t ZEXPORT unztell (unzFile file)
1390 unzFile file;
1391{ 1898{
1392 unz_s* s; 1899 unz64_s* s;
1393 file_in_zip_read_info_s* pfile_in_zip_read_info; 1900 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1394 if (file==NULL) 1901 if (file==NULL)
1395 return UNZ_PARAMERROR; 1902 return UNZ_PARAMERROR;
1396 s=(unz_s*)file; 1903 s=(unz64_s*)file;
1397 pfile_in_zip_read_info=s->pfile_in_zip_read; 1904 pfile_in_zip_read_info=s->pfile_in_zip_read;
1398 1905
1399 if (pfile_in_zip_read_info==NULL) 1906 if (pfile_in_zip_read_info==NULL)
@@ -1402,18 +1909,33 @@ extern z_off_t ZEXPORT unztell (file)
1402 return (z_off_t)pfile_in_zip_read_info->stream.total_out; 1909 return (z_off_t)pfile_in_zip_read_info->stream.total_out;
1403} 1910}
1404 1911
1912extern ZPOS64_T ZEXPORT unztell64 (unzFile file)
1913{
1914
1915 unz64_s* s;
1916 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1917 if (file==NULL)
1918 return (ZPOS64_T)-1;
1919 s=(unz64_s*)file;
1920 pfile_in_zip_read_info=s->pfile_in_zip_read;
1921
1922 if (pfile_in_zip_read_info==NULL)
1923 return (ZPOS64_T)-1;
1924
1925 return pfile_in_zip_read_info->total_out_64;
1926}
1927
1405 1928
1406/* 1929/*
1407 return 1 if the end of file was reached, 0 elsewhere 1930 return 1 if the end of file was reached, 0 elsewhere
1408*/ 1931*/
1409extern int ZEXPORT unzeof (file) 1932extern int ZEXPORT unzeof (unzFile file)
1410 unzFile file;
1411{ 1933{
1412 unz_s* s; 1934 unz64_s* s;
1413 file_in_zip_read_info_s* pfile_in_zip_read_info; 1935 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1414 if (file==NULL) 1936 if (file==NULL)
1415 return UNZ_PARAMERROR; 1937 return UNZ_PARAMERROR;
1416 s=(unz_s*)file; 1938 s=(unz64_s*)file;
1417 pfile_in_zip_read_info=s->pfile_in_zip_read; 1939 pfile_in_zip_read_info=s->pfile_in_zip_read;
1418 1940
1419 if (pfile_in_zip_read_info==NULL) 1941 if (pfile_in_zip_read_info==NULL)
@@ -1428,9 +1950,9 @@ extern int ZEXPORT unzeof (file)
1428 1950
1429 1951
1430/* 1952/*
1431 Read extra field from the current file (opened by unzOpenCurrentFile) 1953Read extra field from the current file (opened by unzOpenCurrentFile)
1432 This is the local-header version of the extra field (sometimes, there is 1954This 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) 1955more info in the local-header version than in the central-header)
1434 1956
1435 if buf==NULL, it return the size of the local extra field that can be read 1957 if buf==NULL, it return the size of the local extra field that can be read
1436 1958
@@ -1439,19 +1961,16 @@ extern int ZEXPORT unzeof (file)
1439 the return value is the number of bytes copied in buf, or (if <0) 1961 the return value is the number of bytes copied in buf, or (if <0)
1440 the error code 1962 the error code
1441*/ 1963*/
1442extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) 1964extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
1443 unzFile file;
1444 voidp buf;
1445 unsigned len;
1446{ 1965{
1447 unz_s* s; 1966 unz64_s* s;
1448 file_in_zip_read_info_s* pfile_in_zip_read_info; 1967 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1449 uInt read_now; 1968 uInt read_now;
1450 uLong size_to_read; 1969 ZPOS64_T size_to_read;
1451 1970
1452 if (file==NULL) 1971 if (file==NULL)
1453 return UNZ_PARAMERROR; 1972 return UNZ_PARAMERROR;
1454 s=(unz_s*)file; 1973 s=(unz64_s*)file;
1455 pfile_in_zip_read_info=s->pfile_in_zip_read; 1974 pfile_in_zip_read_info=s->pfile_in_zip_read;
1456 1975
1457 if (pfile_in_zip_read_info==NULL) 1976 if (pfile_in_zip_read_info==NULL)
@@ -1471,14 +1990,14 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
1471 if (read_now==0) 1990 if (read_now==0)
1472 return 0; 1991 return 0;
1473 1992
1474 if (ZSEEK(pfile_in_zip_read_info->z_filefunc, 1993 if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
1475 pfile_in_zip_read_info->filestream, 1994 pfile_in_zip_read_info->filestream,
1476 pfile_in_zip_read_info->offset_local_extrafield + 1995 pfile_in_zip_read_info->offset_local_extrafield +
1477 pfile_in_zip_read_info->pos_local_extrafield, 1996 pfile_in_zip_read_info->pos_local_extrafield,
1478 ZLIB_FILEFUNC_SEEK_SET)!=0) 1997 ZLIB_FILEFUNC_SEEK_SET)!=0)
1479 return UNZ_ERRNO; 1998 return UNZ_ERRNO;
1480 1999
1481 if (ZREAD(pfile_in_zip_read_info->z_filefunc, 2000 if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
1482 pfile_in_zip_read_info->filestream, 2001 pfile_in_zip_read_info->filestream,
1483 buf,read_now)!=read_now) 2002 buf,read_now)!=read_now)
1484 return UNZ_ERRNO; 2003 return UNZ_ERRNO;
@@ -1490,16 +2009,15 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
1490 Close the file in zip opened with unzipOpenCurrentFile 2009 Close the file in zip opened with unzipOpenCurrentFile
1491 Return UNZ_CRCERROR if all the file was read but the CRC is not good 2010 Return UNZ_CRCERROR if all the file was read but the CRC is not good
1492*/ 2011*/
1493extern int ZEXPORT unzCloseCurrentFile (file) 2012extern int ZEXPORT unzCloseCurrentFile (unzFile file)
1494 unzFile file;
1495{ 2013{
1496 int err=UNZ_OK; 2014 int err=UNZ_OK;
1497 2015
1498 unz_s* s; 2016 unz64_s* s;
1499 file_in_zip_read_info_s* pfile_in_zip_read_info; 2017 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1500 if (file==NULL) 2018 if (file==NULL)
1501 return UNZ_PARAMERROR; 2019 return UNZ_PARAMERROR;
1502 s=(unz_s*)file; 2020 s=(unz64_s*)file;
1503 pfile_in_zip_read_info=s->pfile_in_zip_read; 2021 pfile_in_zip_read_info=s->pfile_in_zip_read;
1504 2022
1505 if (pfile_in_zip_read_info==NULL) 2023 if (pfile_in_zip_read_info==NULL)
@@ -1516,8 +2034,13 @@ extern int ZEXPORT unzCloseCurrentFile (file)
1516 2034
1517 TRYFREE(pfile_in_zip_read_info->read_buffer); 2035 TRYFREE(pfile_in_zip_read_info->read_buffer);
1518 pfile_in_zip_read_info->read_buffer = NULL; 2036 pfile_in_zip_read_info->read_buffer = NULL;
1519 if (pfile_in_zip_read_info->stream_initialised) 2037 if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
1520 inflateEnd(&pfile_in_zip_read_info->stream); 2038 inflateEnd(&pfile_in_zip_read_info->stream);
2039#ifdef HAVE_BZIP2
2040 else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
2041 BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
2042#endif
2043
1521 2044
1522 pfile_in_zip_read_info->stream_initialised = 0; 2045 pfile_in_zip_read_info->stream_initialised = 0;
1523 TRYFREE(pfile_in_zip_read_info); 2046 TRYFREE(pfile_in_zip_read_info);
@@ -1533,28 +2056,25 @@ extern int ZEXPORT unzCloseCurrentFile (file)
1533 uSizeBuf is the size of the szComment buffer. 2056 uSizeBuf is the size of the szComment buffer.
1534 return the number of byte copied or an error code <0 2057 return the number of byte copied or an error code <0
1535*/ 2058*/
1536extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) 2059extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf)
1537 unzFile file;
1538 char *szComment;
1539 uLong uSizeBuf;
1540{ 2060{
1541 unz_s* s; 2061 unz64_s* s;
1542 uLong uReadThis ; 2062 uLong uReadThis ;
1543 if (file==NULL) 2063 if (file==NULL)
1544 return UNZ_PARAMERROR; 2064 return (int)UNZ_PARAMERROR;
1545 s=(unz_s*)file; 2065 s=(unz64_s*)file;
1546 2066
1547 uReadThis = uSizeBuf; 2067 uReadThis = uSizeBuf;
1548 if (uReadThis>s->gi.size_comment) 2068 if (uReadThis>s->gi.size_comment)
1549 uReadThis = s->gi.size_comment; 2069 uReadThis = s->gi.size_comment;
1550 2070
1551 if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) 2071 if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
1552 return UNZ_ERRNO; 2072 return UNZ_ERRNO;
1553 2073
1554 if (uReadThis>0) 2074 if (uReadThis>0)
1555 { 2075 {
1556 *szComment='\0'; 2076 *szComment='\0';
1557 if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) 2077 if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
1558 return UNZ_ERRNO; 2078 return UNZ_ERRNO;
1559 } 2079 }
1560 2080
@@ -1564,14 +2084,13 @@ extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
1564} 2084}
1565 2085
1566/* Additions by RX '2004 */ 2086/* Additions by RX '2004 */
1567extern uLong ZEXPORT unzGetOffset (file) 2087extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
1568 unzFile file;
1569{ 2088{
1570 unz_s* s; 2089 unz64_s* s;
1571 2090
1572 if (file==NULL) 2091 if (file==NULL)
1573 return UNZ_PARAMERROR; 2092 return 0; /*UNZ_PARAMERROR; */
1574 s=(unz_s*)file; 2093 s=(unz64_s*)file;
1575 if (!s->current_file_ok) 2094 if (!s->current_file_ok)
1576 return 0; 2095 return 0;
1577 if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) 2096 if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
@@ -1580,22 +2099,57 @@ extern uLong ZEXPORT unzGetOffset (file)
1580 return s->pos_in_central_dir; 2099 return s->pos_in_central_dir;
1581} 2100}
1582 2101
1583extern int ZEXPORT unzSetOffset (file, pos) 2102extern uLong ZEXPORT unzGetOffset (unzFile file)
1584 unzFile file;
1585 uLong pos;
1586{ 2103{
1587 unz_s* s; 2104 ZPOS64_T offset64;
2105
2106 if (file==NULL)
2107 return 0; /*UNZ_PARAMERROR; */
2108 offset64 = unzGetOffset64(file);
2109 return (uLong)offset64;
2110}
2111
2112extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
2113{
2114 unz64_s* s;
1588 int err; 2115 int err;
1589 2116
1590 if (file==NULL) 2117 if (file==NULL)
1591 return UNZ_PARAMERROR; 2118 return UNZ_PARAMERROR;
1592 s=(unz_s*)file; 2119 s=(unz64_s*)file;
1593 2120
1594 s->pos_in_central_dir = pos; 2121 s->pos_in_central_dir = pos;
1595 s->num_file = s->gi.number_entry; /* hack */ 2122 s->num_file = s->gi.number_entry; /* hack */
1596 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 2123 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1597 &s->cur_file_info_internal, 2124 &s->cur_file_info_internal,
1598 NULL,0,NULL,0,NULL,0); 2125 NULL,0,NULL,0,NULL,0);
1599 s->current_file_ok = (err == UNZ_OK); 2126 s->current_file_ok = (err == UNZ_OK);
1600 return err; 2127 return err;
1601} 2128}
2129
2130extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
2131{
2132 return unzSetOffset64(file,pos);
2133}
2134
2135
2136int ZEXPORT unzSetFlags(unzFile file, unsigned flags)
2137{
2138 unz64_s* s;
2139 if (file == NULL)
2140 return UNZ_PARAMERROR;
2141 s = (unz64_s*)file;
2142 s->flags |= flags;
2143 return UNZ_OK;
2144}
2145
2146
2147int ZEXPORT unzClearFlags(unzFile file, unsigned flags)
2148{
2149 unz64_s* s;
2150 if (file == NULL)
2151 return UNZ_PARAMERROR;
2152 s = (unz64_s*)file;
2153 s->flags &= ~flags;
2154 return UNZ_OK;
2155}
diff --git a/rbutil/rbutilqt/quazip/unzip.h b/rbutil/rbutilqt/quazip/unzip.h
index b247937c80..da7b062845 100644
--- a/rbutil/rbutilqt/quazip/unzip.h
+++ b/rbutil/rbutilqt/quazip/unzip.h
@@ -1,20 +1,20 @@
1/* unzip.h -- IO for uncompress .zip files using zlib 1/* unzip.h -- IO for uncompress .zip files using zlib
2 Version 1.01e, February 12th, 2005 2 Version 1.1, February 14h, 2010
3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
3 4
4 Copyright (C) 1998-2005 Gilles Vollant 5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
5 6
6 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g 7 Modifications of Unzip for Zip64
7 WinZip, InfoZip tools and compatible. 8 Copyright (C) 2007-2008 Even Rouault
8 9
9 Multi volume ZipFile (span) are not supported. 10 Modifications for Zip64 support on both zip and unzip
10 Encryption compatible with pkzip 2.04g only supported 11 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
11 Old compressions used by old PKZip 1.x are not supported
12 12
13 For more info read MiniZip_info.txt
13 14
14 I WAIT FEEDBACK at mail info@winimage.com 15 ---------------------------------------------------------------------------------
15 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
16 16
17 Condition of use and distribution are the same than zlib : 17 Condition of use and distribution are the same than zlib :
18 18
19 This software is provided 'as-is', without any express or implied 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 20 warranty. In no event will the authors be held liable for any damages
@@ -32,18 +32,21 @@
32 misrepresented as being the original software. 32 misrepresented as being the original software.
33 3. This notice may not be removed or altered from any source distribution. 33 3. This notice may not be removed or altered from any source distribution.
34 34
35 ---------------------------------------------------------------------------------
35 36
36*/ 37 Changes
38
39 See header of unzip64.c
37 40
38/* for more info about .ZIP format, see 41 ---------------------------------------------------------------------------
39 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip 42
40 http://www.info-zip.org/pub/infozip/doc/ 43 As per the requirement above, this file is plainly marked as modified
41 PkWare has also a specification at : 44 by Sergey A. Tachenov. Most modifications include the I/O API redesign
42 ftp://ftp.pkware.com/probdesc.zip 45 to support QIODevice interface. Some improvements and small fixes were also made.
43*/ 46*/
44 47
45#ifndef _unz_H 48#ifndef _unz64_H
46#define _unz_H 49#define _unz64_H
47 50
48#ifdef __cplusplus 51#ifdef __cplusplus
49extern "C" { 52extern "C" {
@@ -53,10 +56,16 @@ extern "C" {
53#include "zlib.h" 56#include "zlib.h"
54#endif 57#endif
55 58
56#ifndef _ZLIBIOAPI_H 59#ifndef _ZLIBIOAPI_H
57#include "ioapi.h" 60#include "ioapi.h"
58#endif 61#endif
59 62
63#ifdef HAVE_BZIP2
64#include "bzlib.h"
65#endif
66
67#define Z_BZIP2ED 12
68
60#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 69#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
61/* like the STRICT of WIN32, we define a pointer that cannot be converted 70/* like the STRICT of WIN32, we define a pointer that cannot be converted
62 from (void*) without cast */ 71 from (void*) without cast */
@@ -76,6 +85,9 @@ typedef voidp unzFile;
76#define UNZ_INTERNALERROR (-104) 85#define UNZ_INTERNALERROR (-104)
77#define UNZ_CRCERROR (-105) 86#define UNZ_CRCERROR (-105)
78 87
88#define UNZ_AUTO_CLOSE 0x01u
89#define UNZ_DEFAULT_FLAGS UNZ_AUTO_CLOSE
90
79/* tm_unz contain date/time info */ 91/* tm_unz contain date/time info */
80typedef struct tm_unz_s 92typedef struct tm_unz_s
81{ 93{
@@ -89,15 +101,42 @@ typedef struct tm_unz_s
89 101
90/* unz_global_info structure contain global data about the ZIPfile 102/* unz_global_info structure contain global data about the ZIPfile
91 These data comes from the end of central dir */ 103 These data comes from the end of central dir */
104typedef struct unz_global_info64_s
105{
106 ZPOS64_T number_entry; /* total number of entries in
107 the central dir on this disk */
108 uLong size_comment; /* size of the global comment of the zipfile */
109} unz_global_info64;
110
92typedef struct unz_global_info_s 111typedef struct unz_global_info_s
93{ 112{
94 uLong number_entry; /* total number of entries in 113 uLong number_entry; /* total number of entries in
95 the central dir on this disk */ 114 the central dir on this disk */
96 uLong size_comment; /* size of the global comment of the zipfile */ 115 uLong size_comment; /* size of the global comment of the zipfile */
97} unz_global_info; 116} unz_global_info;
98 117
99
100/* unz_file_info contain information about a file in the zipfile */ 118/* unz_file_info contain information about a file in the zipfile */
119typedef struct unz_file_info64_s
120{
121 uLong version; /* version made by 2 bytes */
122 uLong version_needed; /* version needed to extract 2 bytes */
123 uLong flag; /* general purpose bit flag 2 bytes */
124 uLong compression_method; /* compression method 2 bytes */
125 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
126 uLong crc; /* crc-32 4 bytes */
127 ZPOS64_T compressed_size; /* compressed size 8 bytes */
128 ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
129 uLong size_filename; /* filename length 2 bytes */
130 uLong size_file_extra; /* extra field length 2 bytes */
131 uLong size_file_comment; /* file comment length 2 bytes */
132
133 uLong disk_num_start; /* disk number start 2 bytes */
134 uLong internal_fa; /* internal file attributes 2 bytes */
135 uLong external_fa; /* external file attributes 4 bytes */
136
137 tm_unz tmu_date;
138} unz_file_info64;
139
101typedef struct unz_file_info_s 140typedef struct unz_file_info_s
102{ 141{
103 uLong version; /* version made by 2 bytes */ 142 uLong version; /* version made by 2 bytes */
@@ -132,7 +171,8 @@ extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
132*/ 171*/
133 172
134 173
135extern unzFile ZEXPORT unzOpen OF((const char *path)); 174extern unzFile ZEXPORT unzOpen OF((voidpf file));
175extern unzFile ZEXPORT unzOpen64 OF((voidpf file));
136/* 176/*
137 Open a Zip file. path contain the full pathname (by example, 177 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 178 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
@@ -141,15 +181,40 @@ extern unzFile ZEXPORT unzOpen OF((const char *path));
141 return value is NULL. 181 return value is NULL.
142 Else, the return value is a unzFile Handle, usable with other function 182 Else, the return value is a unzFile Handle, usable with other function
143 of this unzip package. 183 of this unzip package.
184 the "64" function take a const void* pointer, because the path is just the
185 value passed to the open64_file_func callback.
186 Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
187 is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
188 does not describe the reality
144*/ 189*/
145 190
146extern unzFile ZEXPORT unzOpen2 OF((const char *path, 191
192extern unzFile ZEXPORT unzOpen2 OF((voidpf file,
147 zlib_filefunc_def* pzlib_filefunc_def)); 193 zlib_filefunc_def* pzlib_filefunc_def));
148/* 194/*
149 Open a Zip file, like unzOpen, but provide a set of file low level API 195 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) 196 for read/write the zip file (see ioapi.h)
151*/ 197*/
152 198
199extern unzFile ZEXPORT unzOpen2_64 OF((voidpf file,
200 zlib_filefunc64_def* pzlib_filefunc_def));
201/*
202 Open a Zip file, like unz64Open, but provide a set of file low level API
203 for read/write the zip file (see ioapi.h)
204*/
205
206
207/*
208 * Exported by Sergey A. Tachenov to implement some QuaZIP features. This
209 * function MAY change signature in order to implement even more features.
210 * You have been warned!
211 * */
212extern unzFile unzOpenInternal (voidpf file,
213 zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
214 int is64bitOpenFunction, unsigned flags);
215
216
217
153extern int ZEXPORT unzClose OF((unzFile file)); 218extern int ZEXPORT unzClose OF((unzFile file));
154/* 219/*
155 Close a ZipFile opened with unzipOpen. 220 Close a ZipFile opened with unzipOpen.
@@ -159,6 +224,9 @@ extern int ZEXPORT unzClose OF((unzFile file));
159 224
160extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, 225extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
161 unz_global_info *pglobal_info)); 226 unz_global_info *pglobal_info));
227
228extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
229 unz_global_info64 *pglobal_info));
162/* 230/*
163 Write info about the ZipFile in the *pglobal_info structure. 231 Write info about the ZipFile in the *pglobal_info structure.
164 No preparation of the structure is needed 232 No preparation of the structure is needed
@@ -221,8 +289,31 @@ extern int ZEXPORT unzGoToFilePos(
221 unzFile file, 289 unzFile file,
222 unz_file_pos* file_pos); 290 unz_file_pos* file_pos);
223 291
292typedef struct unz64_file_pos_s
293{
294 ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */
295 ZPOS64_T num_of_file; /* # of file */
296} unz64_file_pos;
297
298extern int ZEXPORT unzGetFilePos64(
299 unzFile file,
300 unz64_file_pos* file_pos);
301
302extern int ZEXPORT unzGoToFilePos64(
303 unzFile file,
304 const unz64_file_pos* file_pos);
305
224/* ****************************************** */ 306/* ****************************************** */
225 307
308extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
309 unz_file_info64 *pfile_info,
310 char *szFileName,
311 uLong fileNameBufferSize,
312 void *extraField,
313 uLong extraFieldBufferSize,
314 char *szComment,
315 uLong commentBufferSize));
316
226extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, 317extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
227 unz_file_info *pfile_info, 318 unz_file_info *pfile_info,
228 char *szFileName, 319 char *szFileName,
@@ -244,6 +335,14 @@ extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
244 (commentBufferSize is the size of the buffer) 335 (commentBufferSize is the size of the buffer)
245*/ 336*/
246 337
338
339/** Addition for GDAL : START */
340
341extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
342
343/** Addition for GDAL : END */
344
345
247/***************************************************************************/ 346/***************************************************************************/
248/* for reading the content of the current zipfile, you can open it, read data 347/* 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) 348 from it, and close it (you can close it before reading all the file)
@@ -312,6 +411,8 @@ extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
312*/ 411*/
313 412
314extern z_off_t ZEXPORT unztell OF((unzFile file)); 413extern z_off_t ZEXPORT unztell OF((unzFile file));
414
415extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
315/* 416/*
316 Give the current position in uncompressed data 417 Give the current position in uncompressed data
317*/ 418*/
@@ -340,15 +441,18 @@ extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
340/***************************************************************************/ 441/***************************************************************************/
341 442
342/* Get the current file offset */ 443/* Get the current file offset */
444extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
343extern uLong ZEXPORT unzGetOffset (unzFile file); 445extern uLong ZEXPORT unzGetOffset (unzFile file);
344 446
345/* Set the current file offset */ 447/* Set the current file offset */
448extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
346extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); 449extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
347 450
348 451extern int ZEXPORT unzSetFlags(unzFile file, unsigned flags);
452extern int ZEXPORT unzClearFlags(unzFile file, unsigned flags);
349 453
350#ifdef __cplusplus 454#ifdef __cplusplus
351} 455}
352#endif 456#endif
353 457
354#endif /* _unz_H */ 458#endif /* _unz64_H */
diff --git a/rbutil/rbutilqt/quazip/zip.c b/rbutil/rbutilqt/quazip/zip.c
index 0bd9aeeb29..96496539f4 100644
--- a/rbutil/rbutilqt/quazip/zip.c
+++ b/rbutil/rbutilqt/quazip/zip.c
@@ -1,12 +1,27 @@
1/* zip.c -- IO on .zip files using zlib 1/* zip.c -- IO on .zip files using zlib
2 Version 1.01e, February 12th, 2005 2 Version 1.1, February 14h, 2010
3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
3 4
4 27 Dec 2004 Rolf Kalbermatter 5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
5 Modification to zipOpen2 to support globalComment retrieval.
6 6
7 Copyright (C) 1998-2005 Gilles Vollant 7 Modifications for Zip64 support
8 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
9
10 For more info read MiniZip_info.txt
11
12 Modifications for QIODevice support and other QuaZIP fixes
13 Copyright (C) 2005-2014 Sergey A. Tachenov
14
15 Changes
16 Oct-2009 - Mathias Svensson - Remove old C style function prototypes
17 Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives
18 Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions.
19 Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data
20 It is used when recreting zip archive with RAW when deleting items from a zip.
21 ZIP64 data is automaticly added to items that needs it, and existing ZIP64 data need to be removed.
22 Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required)
23 Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
8 24
9 Read zip.h for more info
10*/ 25*/
11 26
12 27
@@ -15,6 +30,9 @@
15#include <string.h> 30#include <string.h>
16#include <time.h> 31#include <time.h>
17#include "zlib.h" 32#include "zlib.h"
33#if (ZLIB_VERNUM < 0x1270)
34typedef uLongf z_crc_t;
35#endif
18#include "zip.h" 36#include "zip.h"
19 37
20#ifdef STDC 38#ifdef STDC
@@ -35,11 +53,11 @@
35/* compile with -Dlocal if your debugger can't find static symbols */ 53/* compile with -Dlocal if your debugger can't find static symbols */
36 54
37#ifndef VERSIONMADEBY 55#ifndef VERSIONMADEBY
38# define VERSIONMADEBY (0x0) /* platform depedent */ 56# define VERSIONMADEBY (0x031e) /* best for standard pkware crypt */
39#endif 57#endif
40 58
41#ifndef Z_BUFSIZE 59#ifndef Z_BUFSIZE
42#define Z_BUFSIZE (16384) 60#define Z_BUFSIZE (64*1024) /* (16384) */
43#endif 61#endif
44 62
45#ifndef Z_MAXFILENAMEINZIP 63#ifndef Z_MAXFILENAMEINZIP
@@ -60,6 +78,10 @@
60 78
61/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ 79/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
62 80
81
82/* NOT sure that this work on ALL platform */
83#define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32))
84
63#ifndef SEEK_CUR 85#ifndef SEEK_CUR
64#define SEEK_CUR 1 86#define SEEK_CUR 1
65#endif 87#endif
@@ -79,15 +101,17 @@
79# define DEF_MEM_LEVEL MAX_MEM_LEVEL 101# define DEF_MEM_LEVEL MAX_MEM_LEVEL
80#endif 102#endif
81#endif 103#endif
82const char zip_copyright[] = 104const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
83 " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
84 105
85 106
86#define SIZEDATA_INDATABLOCK (4096-(4*4)) 107#define SIZEDATA_INDATABLOCK (4096-(4*4))
87 108
88#define LOCALHEADERMAGIC (0x04034b50) 109#define LOCALHEADERMAGIC (0x04034b50)
110#define DESCRIPTORHEADERMAGIC (0x08074b50)
89#define CENTRALHEADERMAGIC (0x02014b50) 111#define CENTRALHEADERMAGIC (0x02014b50)
90#define ENDHEADERMAGIC (0x06054b50) 112#define ENDHEADERMAGIC (0x06054b50)
113#define ZIP64ENDHEADERMAGIC (0x6064b50)
114#define ZIP64ENDLOCHEADERMAGIC (0x7064b50)
91 115
92#define FLAG_LOCALHEADER_OFFSET (0x06) 116#define FLAG_LOCALHEADER_OFFSET (0x06)
93#define CRC_LOCALHEADER_OFFSET (0x0e) 117#define CRC_LOCALHEADER_OFFSET (0x0e)
@@ -113,13 +137,19 @@ typedef struct linkedlist_data_s
113typedef struct 137typedef struct
114{ 138{
115 z_stream stream; /* zLib stream structure for inflate */ 139 z_stream stream; /* zLib stream structure for inflate */
140#ifdef HAVE_BZIP2
141 bz_stream bstream; /* bzLib stream structure for bziped */
142#endif
143
116 int stream_initialised; /* 1 is stream is initialised */ 144 int stream_initialised; /* 1 is stream is initialised */
117 uInt pos_in_buffered_data; /* last written byte in buffered_data */ 145 uInt pos_in_buffered_data; /* last written byte in buffered_data */
118 146
119 uLong pos_local_header; /* offset of the local header of the file 147 ZPOS64_T pos_local_header; /* offset of the local header of the file
120 currenty writing */ 148 currenty writing */
121 char* central_header; /* central header data for the current file */ 149 char* central_header; /* central header data for the current file */
150 uLong size_centralExtra;
122 uLong size_centralheader; /* size of the central header for cur file */ 151 uLong size_centralheader; /* size of the central header for cur file */
152 uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */
123 uLong flag; /* flag of the file currently writing */ 153 uLong flag; /* flag of the file currently writing */
124 154
125 int method; /* compression method of file currenty wr.*/ 155 int method; /* compression method of file currenty wr.*/
@@ -128,29 +158,36 @@ typedef struct
128 uLong dosDate; 158 uLong dosDate;
129 uLong crc32; 159 uLong crc32;
130 int encrypt; 160 int encrypt;
161 int zip64; /* Add ZIP64 extened information in the extra field */
162 ZPOS64_T pos_zip64extrainfo;
163 ZPOS64_T totalCompressedData;
164 ZPOS64_T totalUncompressedData;
131#ifndef NOCRYPT 165#ifndef NOCRYPT
132 unsigned long keys[3]; /* keys defining the pseudo-random sequence */ 166 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
133 const unsigned long* pcrc_32_tab; 167 const z_crc_t FAR * pcrc_32_tab;
134 int crypt_header_size; 168 int crypt_header_size;
135#endif 169#endif
136} curfile_info; 170} curfile64_info;
137 171
138typedef struct 172typedef struct
139{ 173{
140 zlib_filefunc_def z_filefunc; 174 zlib_filefunc64_32_def z_filefunc;
141 voidpf filestream; /* io structore of the zipfile */ 175 voidpf filestream; /* io structore of the zipfile */
142 linkedlist_data central_dir;/* datablock with central dir in construction*/ 176 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.*/ 177 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 */ 178 curfile64_info ci; /* info on the file curretly writing */
179
180 ZPOS64_T begin_pos; /* position of the beginning of the zipfile */
181 ZPOS64_T add_position_when_writting_offset;
182 ZPOS64_T number_entry;
145 183
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 184#ifndef NO_ADDFILEINEXISTINGZIP
150 char *globalcomment; 185 char *globalcomment;
151#endif 186#endif
152} zip_internal;
153 187
188 unsigned flags;
189
190} zip64_internal;
154 191
155 192
156#ifndef NOCRYPT 193#ifndef NOCRYPT
@@ -172,8 +209,7 @@ local linkedlist_datablock_internal* allocate_new_datablock()
172 return ldi; 209 return ldi;
173} 210}
174 211
175local void free_datablock(ldi) 212local void free_datablock(linkedlist_datablock_internal* ldi)
176 linkedlist_datablock_internal* ldi;
177{ 213{
178 while (ldi!=NULL) 214 while (ldi!=NULL)
179 { 215 {
@@ -183,25 +219,19 @@ local void free_datablock(ldi)
183 } 219 }
184} 220}
185 221
186local void init_linkedlist(ll) 222local void init_linkedlist(linkedlist_data* ll)
187 linkedlist_data* ll;
188{ 223{
189 ll->first_block = ll->last_block = NULL; 224 ll->first_block = ll->last_block = NULL;
190} 225}
191 226
192#if 0 // unused 227local void free_linkedlist(linkedlist_data* ll)
193local void free_linkedlist(ll)
194 linkedlist_data* ll;
195{ 228{
196 free_datablock(ll->first_block); 229 free_datablock(ll->first_block);
197 ll->first_block = ll->last_block = NULL; 230 ll->first_block = ll->last_block = NULL;
198} 231}
199#endif
200 232
201local int add_data_in_datablock(ll,buf,len) 233
202 linkedlist_data* ll; 234local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len)
203 const void* buf;
204 uLong len;
205{ 235{
206 linkedlist_datablock_internal* ldi; 236 linkedlist_datablock_internal* ldi;
207 const unsigned char* from_copy; 237 const unsigned char* from_copy;
@@ -259,18 +289,13 @@ local int add_data_in_datablock(ll,buf,len)
259#ifndef NO_ADDFILEINEXISTINGZIP 289#ifndef NO_ADDFILEINEXISTINGZIP
260/* =========================================================================== 290/* ===========================================================================
261 Inputs a long in LSB order to the given file 291 Inputs a long in LSB order to the given file
262 nbByte == 1, 2 or 4 (byte, short or long) 292 nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T)
263*/ 293*/
264 294
265local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def, 295local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte));
266 voidpf filestream, uLong x, int nbByte)); 296local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T 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{ 297{
273 unsigned char buf[4]; 298 unsigned char buf[8];
274 int n; 299 int n;
275 for (n = 0; n < nbByte; n++) 300 for (n = 0; n < nbByte; n++)
276 { 301 {
@@ -285,17 +310,14 @@ local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte)
285 } 310 }
286 } 311 }
287 312
288 if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) 313 if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
289 return ZIP_ERRNO; 314 return ZIP_ERRNO;
290 else 315 else
291 return ZIP_OK; 316 return ZIP_OK;
292} 317}
293 318
294local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte)); 319local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte));
295local void ziplocal_putValue_inmemory (dest, x, nbByte) 320local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte)
296 void* dest;
297 uLong x;
298 int nbByte;
299{ 321{
300 unsigned char* buf=(unsigned char*)dest; 322 unsigned char* buf=(unsigned char*)dest;
301 int n; 323 int n;
@@ -316,15 +338,12 @@ local void ziplocal_putValue_inmemory (dest, x, nbByte)
316/****************************************************************************/ 338/****************************************************************************/
317 339
318 340
319local uLong ziplocal_TmzDateToDosDate(ptm,dosDate) 341local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm)
320 const tm_zip* ptm;
321 uLong dosDate;
322{ 342{
323 uLong year = (uLong)ptm->tm_year; 343 uLong year = (uLong)ptm->tm_year;
324 (void) dosDate; /* avoid "unused parameter" warning */ 344 if (year>=1980)
325 if (year>1980)
326 year-=1980; 345 year-=1980;
327 else if (year>80) 346 else if (year>=80)
328 year-=80; 347 year-=80;
329 return 348 return
330 (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | 349 (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
@@ -334,18 +353,12 @@ local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)
334 353
335/****************************************************************************/ 354/****************************************************************************/
336 355
337local int ziplocal_getByte OF(( 356local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi));
338 const zlib_filefunc_def* pzlib_filefunc_def,
339 voidpf filestream,
340 int *pi));
341 357
342local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi) 358local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi)
343 const zlib_filefunc_def* pzlib_filefunc_def;
344 voidpf filestream;
345 int *pi;
346{ 359{
347 unsigned char c; 360 unsigned char c;
348 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); 361 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
349 if (err==1) 362 if (err==1)
350 { 363 {
351 *pi = (int)c; 364 *pi = (int)c;
@@ -353,7 +366,7 @@ local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi)
353 } 366 }
354 else 367 else
355 { 368 {
356 if (ZERROR(*pzlib_filefunc_def,filestream)) 369 if (ZERROR64(*pzlib_filefunc_def,filestream))
357 return ZIP_ERRNO; 370 return ZIP_ERRNO;
358 else 371 else
359 return ZIP_EOF; 372 return ZIP_EOF;
@@ -364,25 +377,19 @@ local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi)
364/* =========================================================================== 377/* ===========================================================================
365 Reads a long in LSB order from the given gz_stream. Sets 378 Reads a long in LSB order from the given gz_stream. Sets
366*/ 379*/
367local int ziplocal_getShort OF(( 380local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
368 const zlib_filefunc_def* pzlib_filefunc_def, 381
369 voidpf filestream, 382local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
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{ 383{
377 uLong x ; 384 uLong x ;
378 int i; 385 int i = 0;
379 int err; 386 int err;
380 387
381 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 388 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
382 x = (uLong)i; 389 x = (uLong)i;
383 390
384 if (err==ZIP_OK) 391 if (err==ZIP_OK)
385 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 392 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
386 x += ((uLong)i)<<8; 393 x += ((uLong)i)<<8;
387 394
388 if (err==ZIP_OK) 395 if (err==ZIP_OK)
@@ -392,33 +399,27 @@ local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX)
392 return err; 399 return err;
393} 400}
394 401
395local int ziplocal_getLong OF(( 402local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
396 const zlib_filefunc_def* pzlib_filefunc_def,
397 voidpf filestream,
398 uLong *pX));
399 403
400local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX) 404local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
401 const zlib_filefunc_def* pzlib_filefunc_def;
402 voidpf filestream;
403 uLong *pX;
404{ 405{
405 uLong x ; 406 uLong x ;
406 int i; 407 int i = 0;
407 int err; 408 int err;
408 409
409 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 410 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
410 x = (uLong)i; 411 x = (uLong)i;
411 412
412 if (err==ZIP_OK) 413 if (err==ZIP_OK)
413 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 414 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
414 x += ((uLong)i)<<8; 415 x += ((uLong)i)<<8;
415 416
416 if (err==ZIP_OK) 417 if (err==ZIP_OK)
417 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 418 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
418 x += ((uLong)i)<<16; 419 x += ((uLong)i)<<16;
419 420
420 if (err==ZIP_OK) 421 if (err==ZIP_OK)
421 err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); 422 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
422 x += ((uLong)i)<<24; 423 x += ((uLong)i)<<24;
423 424
424 if (err==ZIP_OK) 425 if (err==ZIP_OK)
@@ -428,6 +429,54 @@ local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX)
428 return err; 429 return err;
429} 430}
430 431
432local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX));
433
434
435local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
436{
437 ZPOS64_T x;
438 int i = 0;
439 int err;
440
441 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
442 x = (ZPOS64_T)i;
443
444 if (err==ZIP_OK)
445 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
446 x += ((ZPOS64_T)i)<<8;
447
448 if (err==ZIP_OK)
449 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
450 x += ((ZPOS64_T)i)<<16;
451
452 if (err==ZIP_OK)
453 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
454 x += ((ZPOS64_T)i)<<24;
455
456 if (err==ZIP_OK)
457 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
458 x += ((ZPOS64_T)i)<<32;
459
460 if (err==ZIP_OK)
461 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
462 x += ((ZPOS64_T)i)<<40;
463
464 if (err==ZIP_OK)
465 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
466 x += ((ZPOS64_T)i)<<48;
467
468 if (err==ZIP_OK)
469 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
470 x += ((ZPOS64_T)i)<<56;
471
472 if (err==ZIP_OK)
473 *pX = x;
474 else
475 *pX = 0;
476
477 return err;
478}
479
431#ifndef BUFREADCOMMENT 480#ifndef BUFREADCOMMENT
432#define BUFREADCOMMENT (0x400) 481#define BUFREADCOMMENT (0x400)
433#endif 482#endif
@@ -435,95 +484,409 @@ local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX)
435 Locate the Central directory of a zipfile (at the end, just before 484 Locate the Central directory of a zipfile (at the end, just before
436 the global comment) 485 the global comment)
437*/ 486*/
438local uLong ziplocal_SearchCentralDir OF(( 487local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
439 const zlib_filefunc_def* pzlib_filefunc_def,
440 voidpf filestream));
441 488
442local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream) 489local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
443 const zlib_filefunc_def* pzlib_filefunc_def;
444 voidpf filestream;
445{ 490{
446 unsigned char* buf; 491 unsigned char* buf;
447 uLong uSizeFile; 492 ZPOS64_T uSizeFile;
448 uLong uBackRead; 493 ZPOS64_T uBackRead;
449 uLong uMaxBack=0xffff; /* maximum size of global comment */ 494 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
450 uLong uPosFound=0; 495 ZPOS64_T uPosFound=0;
496
497 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
498 return 0;
499
500
501 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
451 502
452 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) 503 if (uMaxBack>uSizeFile)
453 return 0; 504 uMaxBack = uSizeFile;
505
506 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
507 if (buf==NULL)
508 return 0;
509
510 uBackRead = 4;
511 while (uBackRead<uMaxBack)
512 {
513 uLong uReadSize;
514 ZPOS64_T uReadPos ;
515 int i;
516 if (uBackRead+BUFREADCOMMENT>uMaxBack)
517 uBackRead = uMaxBack;
518 else
519 uBackRead+=BUFREADCOMMENT;
520 uReadPos = uSizeFile-uBackRead ;
521
522 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
523 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
524 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
525 break;
526
527 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
528 break;
529
530 for (i=(int)uReadSize-3; (i--)>0;)
531 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
532 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
533 {
534 uPosFound = uReadPos+i;
535 break;
536 }
537
538 if (uPosFound!=0)
539 break;
540 }
541 TRYFREE(buf);
542 return uPosFound;
543}
454 544
545/*
546Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before
547the global comment)
548*/
549local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
455 550
456 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); 551local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
552{
553 unsigned char* buf;
554 ZPOS64_T uSizeFile;
555 ZPOS64_T uBackRead;
556 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
557 ZPOS64_T uPosFound=0;
558 uLong uL;
559 ZPOS64_T relativeOffset;
560
561 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
562 return 0;
563
564 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
565
566 if (uMaxBack>uSizeFile)
567 uMaxBack = uSizeFile;
568
569 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
570 if (buf==NULL)
571 return 0;
572
573 uBackRead = 4;
574 while (uBackRead<uMaxBack)
575 {
576 uLong uReadSize;
577 ZPOS64_T uReadPos;
578 int i;
579 if (uBackRead+BUFREADCOMMENT>uMaxBack)
580 uBackRead = uMaxBack;
581 else
582 uBackRead+=BUFREADCOMMENT;
583 uReadPos = uSizeFile-uBackRead ;
457 584
458 if (uMaxBack>uSizeFile) 585 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
459 uMaxBack = uSizeFile; 586 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
587 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
588 break;
460 589
461 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); 590 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
462 if (buf==NULL) 591 break;
463 return 0;
464 592
465 uBackRead = 4; 593 for (i=(int)uReadSize-3; (i--)>0;)
466 while (uBackRead<uMaxBack)
467 { 594 {
468 uLong uReadSize,uReadPos ; 595 /* Signature "0x07064b50" Zip64 end of central directory locater */
469 int i; 596 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
470 if (uBackRead+BUFREADCOMMENT>uMaxBack) 597 {
471 uBackRead = uMaxBack; 598 uPosFound = uReadPos+i;
472 else 599 break;
473 uBackRead+=BUFREADCOMMENT; 600 }
474 uReadPos = uSizeFile-uBackRead ; 601 }
475 602
476 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 603 if (uPosFound!=0)
477 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); 604 break;
478 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) 605 }
479 break;
480 606
481 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) 607 TRYFREE(buf);
482 break; 608 if (uPosFound == 0)
609 return 0;
483 610
484 for (i=(int)uReadSize-3; (i--)>0;) 611 /* Zip64 end of central directory locator */
485 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && 612 if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
486 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) 613 return 0;
487 { 614
488 uPosFound = uReadPos+i; 615 /* the signature, already checked */
489 break; 616 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
490 } 617 return 0;
618
619 /* number of the disk with the start of the zip64 end of central directory */
620 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
621 return 0;
622 if (uL != 0)
623 return 0;
624
625 /* relative offset of the zip64 end of central directory record */
626 if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK)
627 return 0;
628
629 /* total number of disks */
630 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
631 return 0;
632 if (uL != 1)
633 return 0;
491 634
492 if (uPosFound!=0) 635 /* Goto Zip64 end of central directory record */
493 break; 636 if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
637 return 0;
638
639 /* the signature */
640 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
641 return 0;
642
643 if (uL != 0x06064b50) /* signature of 'Zip64 end of central directory' */
644 return 0;
645
646 return relativeOffset;
647}
648
649int LoadCentralDirectoryRecord(zip64_internal* pziinit)
650{
651 int err=ZIP_OK;
652 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
653
654 ZPOS64_T size_central_dir; /* size of the central directory */
655 ZPOS64_T offset_central_dir; /* offset of start of central directory */
656 ZPOS64_T central_pos;
657 uLong uL;
658
659 uLong number_disk; /* number of the current dist, used for
660 spaning ZIP, unsupported, always 0*/
661 uLong number_disk_with_CD; /* number the the disk with central dir, used
662 for spaning ZIP, unsupported, always 0*/
663 ZPOS64_T number_entry;
664 ZPOS64_T number_entry_CD; /* total number of entries in
665 the central dir
666 (same than number_entry on nospan) */
667 uLong VersionMadeBy;
668 uLong VersionNeeded;
669 uLong size_comment;
670
671 int hasZIP64Record = 0;
672
673 /* check first if we find a ZIP64 record */
674 central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream);
675 if(central_pos > 0)
676 {
677 hasZIP64Record = 1;
678 }
679 else if(central_pos == 0)
680 {
681 central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream);
682 }
683
684/* disable to allow appending to empty ZIP archive
685 if (central_pos==0)
686 err=ZIP_ERRNO;
687*/
688
689 if(hasZIP64Record)
690 {
691 ZPOS64_T sizeEndOfCentralDirectory;
692 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
693 err=ZIP_ERRNO;
694
695 /* the signature, already checked */
696 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
697 err=ZIP_ERRNO;
698
699 /* size of zip64 end of central directory record */
700 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK)
701 err=ZIP_ERRNO;
702
703 /* version made by */
704 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK)
705 err=ZIP_ERRNO;
706
707 /* version needed to extract */
708 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK)
709 err=ZIP_ERRNO;
710
711 /* number of this disk */
712 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
713 err=ZIP_ERRNO;
714
715 /* number of the disk with the start of the central directory */
716 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
717 err=ZIP_ERRNO;
718
719 /* total number of entries in the central directory on this disk */
720 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK)
721 err=ZIP_ERRNO;
722
723 /* total number of entries in the central directory */
724 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK)
725 err=ZIP_ERRNO;
726
727 if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
728 err=ZIP_BADZIPFILE;
729
730 /* size of the central directory */
731 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK)
732 err=ZIP_ERRNO;
733
734 /* offset of start of central directory with respect to the
735 starting disk number */
736 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK)
737 err=ZIP_ERRNO;
738
739 /* TODO.. */
740 /* read the comment from the standard central header. */
741 size_comment = 0;
742 }
743 else
744 {
745 /* Read End of central Directory info */
746 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
747 err=ZIP_ERRNO;
748
749 /* the signature, already checked */
750 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
751 err=ZIP_ERRNO;
752
753 /* number of this disk */
754 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
755 err=ZIP_ERRNO;
756
757 /* number of the disk with the start of the central directory */
758 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
759 err=ZIP_ERRNO;
760
761 /* total number of entries in the central dir on this disk */
762 number_entry = 0;
763 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
764 err=ZIP_ERRNO;
765 else
766 number_entry = uL;
767
768 /* total number of entries in the central dir */
769 number_entry_CD = 0;
770 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
771 err=ZIP_ERRNO;
772 else
773 number_entry_CD = uL;
774
775 if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
776 err=ZIP_BADZIPFILE;
777
778 /* size of the central directory */
779 size_central_dir = 0;
780 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
781 err=ZIP_ERRNO;
782 else
783 size_central_dir = uL;
784
785 /* offset of start of central directory with respect to the starting disk number */
786 offset_central_dir = 0;
787 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
788 err=ZIP_ERRNO;
789 else
790 offset_central_dir = uL;
791
792
793 /* zipfile global comment length */
794 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK)
795 err=ZIP_ERRNO;
796 }
797
798 if ((central_pos<offset_central_dir+size_central_dir) &&
799 (err==ZIP_OK))
800 err=ZIP_BADZIPFILE;
801
802 if (err!=ZIP_OK)
803 {
804 if ((pziinit->flags & ZIP_AUTO_CLOSE) != 0) {
805 ZCLOSE64(pziinit->z_filefunc, pziinit->filestream);
806 } else {
807 ZFAKECLOSE64(pziinit->z_filefunc, pziinit->filestream);
808 }
809 return ZIP_ERRNO;
810 }
811
812 if (size_comment>0)
813 {
814 pziinit->globalcomment = (char*)ALLOC(size_comment+1);
815 if (pziinit->globalcomment)
816 {
817 size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment);
818 pziinit->globalcomment[size_comment]=0;
819 }
820 }
821
822 byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir);
823 pziinit->add_position_when_writting_offset = byte_before_the_zipfile;
824
825 {
826 ZPOS64_T size_central_dir_to_read = size_central_dir;
827 size_t buf_size = SIZEDATA_INDATABLOCK;
828 void* buf_read = (void*)ALLOC(buf_size);
829 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
830 err=ZIP_ERRNO;
831
832 while ((size_central_dir_to_read>0) && (err==ZIP_OK))
833 {
834 ZPOS64_T read_this = SIZEDATA_INDATABLOCK;
835 if (read_this > size_central_dir_to_read)
836 read_this = size_central_dir_to_read;
837
838 if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this)
839 err=ZIP_ERRNO;
840
841 if (err==ZIP_OK)
842 err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this);
843
844 size_central_dir_to_read-=read_this;
494 } 845 }
495 TRYFREE(buf); 846 TRYFREE(buf_read);
496 return uPosFound; 847 }
848 pziinit->begin_pos = byte_before_the_zipfile;
849 pziinit->number_entry = number_entry_CD;
850
851 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
852 err=ZIP_ERRNO;
853
854 return err;
497} 855}
856
857
498#endif /* !NO_ADDFILEINEXISTINGZIP*/ 858#endif /* !NO_ADDFILEINEXISTINGZIP*/
499 859
860
500/************************************************************/ 861/************************************************************/
501extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def) 862extern zipFile ZEXPORT zipOpen3 (voidpf file, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
502 const char *pathname; 863 unsigned flags)
503 int append;
504 zipcharpc* globalcomment;
505 zlib_filefunc_def* pzlib_filefunc_def;
506{ 864{
507 zip_internal ziinit; 865 zip64_internal ziinit;
508 zip_internal* zi; 866 zip64_internal* zi;
509 int err=ZIP_OK; 867 int err=ZIP_OK;
510 868
511 869 ziinit.flags = flags;
512 if (pzlib_filefunc_def==NULL) 870 ziinit.z_filefunc.zseek32_file = NULL;
513 fill_fopen_filefunc(&ziinit.z_filefunc); 871 ziinit.z_filefunc.ztell32_file = NULL;
872 if (pzlib_filefunc64_32_def==NULL)
873 fill_qiodevice64_filefunc(&ziinit.z_filefunc.zfile_func64);
514 else 874 else
515 ziinit.z_filefunc = *pzlib_filefunc_def; 875 ziinit.z_filefunc = *pzlib_filefunc64_32_def;
516 876
517 ziinit.filestream = (*(ziinit.z_filefunc.zopen_file)) 877 ziinit.filestream = ZOPEN64(ziinit.z_filefunc,
518 (ziinit.z_filefunc.opaque, 878 file,
519 pathname,
520 (append == APPEND_STATUS_CREATE) ? 879 (append == APPEND_STATUS_CREATE) ?
521 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : 880 (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)); 881 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
523 882
524 if (ziinit.filestream == NULL) 883 if (ziinit.filestream == NULL)
525 return NULL; 884 return NULL;
526 ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream); 885
886 if (append == APPEND_STATUS_CREATEAFTER)
887 ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END);
888
889 ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream);
527 ziinit.in_opened_file_inzip = 0; 890 ziinit.in_opened_file_inzip = 0;
528 ziinit.ci.stream_initialised = 0; 891 ziinit.ci.stream_initialised = 0;
529 ziinit.number_entry = 0; 892 ziinit.number_entry = 0;
@@ -531,10 +894,15 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
531 init_linkedlist(&(ziinit.central_dir)); 894 init_linkedlist(&(ziinit.central_dir));
532 895
533 896
534 zi = (zip_internal*)ALLOC(sizeof(zip_internal)); 897
898 zi = (zip64_internal*)ALLOC(sizeof(zip64_internal));
535 if (zi==NULL) 899 if (zi==NULL)
536 { 900 {
537 ZCLOSE(ziinit.z_filefunc,ziinit.filestream); 901 if ((ziinit.flags & ZIP_AUTO_CLOSE) != 0) {
902 ZCLOSE64(ziinit.z_filefunc,ziinit.filestream);
903 } else {
904 ZFAKECLOSE64(ziinit.z_filefunc,ziinit.filestream);
905 }
538 return NULL; 906 return NULL;
539 } 907 }
540 908
@@ -543,122 +911,8 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
543 ziinit.globalcomment = NULL; 911 ziinit.globalcomment = NULL;
544 if (append == APPEND_STATUS_ADDINZIP) 912 if (append == APPEND_STATUS_ADDINZIP)
545 { 913 {
546 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 914 /* Read and Cache Central Directory Records */
547 915 err = LoadCentralDirectoryRecord(&ziinit);
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 } 916 }
663 917
664 if (globalcomment) 918 if (globalcomment)
@@ -682,41 +936,158 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
682 } 936 }
683} 937}
684 938
685extern zipFile ZEXPORT zipOpen (pathname, append) 939extern zipFile ZEXPORT zipOpen2 (voidpf file, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def)
686 const char *pathname; 940{
687 int append; 941 if (pzlib_filefunc32_def != NULL)
942 {
943 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
944 fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
945 return zipOpen3(file, append, globalcomment, &zlib_filefunc64_32_def_fill, ZIP_DEFAULT_FLAGS);
946 }
947 else
948 return zipOpen3(file, append, globalcomment, NULL, ZIP_DEFAULT_FLAGS);
949}
950
951extern zipFile ZEXPORT zipOpen2_64 (voidpf file, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def)
952{
953 if (pzlib_filefunc_def != NULL)
954 {
955 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
956 zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
957 zlib_filefunc64_32_def_fill.ztell32_file = NULL;
958 zlib_filefunc64_32_def_fill.zseek32_file = NULL;
959 return zipOpen3(file, append, globalcomment, &zlib_filefunc64_32_def_fill, ZIP_DEFAULT_FLAGS);
960 }
961 else
962 return zipOpen3(file, append, globalcomment, NULL, ZIP_DEFAULT_FLAGS);
963}
964
965
966
967extern zipFile ZEXPORT zipOpen (voidpf file, int append)
968{
969 return zipOpen3(file,append,NULL,NULL, ZIP_DEFAULT_FLAGS);
970}
971
972extern zipFile ZEXPORT zipOpen64 (voidpf file, int append)
688{ 973{
689 return zipOpen2(pathname,append,NULL,NULL); 974 return zipOpen3(file,append,NULL,NULL, ZIP_DEFAULT_FLAGS);
690} 975}
691 976
692extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, 977int Write_LocalFileHeader(zip64_internal* zi, const char* filename,
693 extrafield_local, size_extrafield_local, 978 uInt size_extrafield_local,
694 extrafield_global, size_extrafield_global, 979 const void* extrafield_local,
695 comment, method, level, raw, 980 uLong version_to_extract)
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{ 981{
715 zip_internal* zi; 982 /* write the local header */
983 int err;
984 uInt size_filename = (uInt)strlen(filename);
985 uInt size_extrafield = size_extrafield_local;
986
987 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4);
988
989 if (err==ZIP_OK)
990 {
991 if(zi->ci.zip64)
992 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */
993 else
994 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)version_to_extract,2);
995 }
996
997 if (err==ZIP_OK)
998 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
999
1000 if (err==ZIP_OK)
1001 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
1002
1003 if (err==ZIP_OK)
1004 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
1005
1006 /* CRC / Compressed size / Uncompressed size will be filled in later and rewritten later */
1007 if (err==ZIP_OK)
1008 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
1009 if (err==ZIP_OK)
1010 {
1011 if(zi->ci.zip64)
1012 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* compressed size, unknown */
1013 else
1014 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
1015 }
1016 if (err==ZIP_OK)
1017 {
1018 if(zi->ci.zip64)
1019 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */
1020 else
1021 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
1022 }
1023
1024 if (err==ZIP_OK)
1025 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
1026
1027 if(zi->ci.zip64)
1028 {
1029 size_extrafield += 20;
1030 }
1031
1032 if (err==ZIP_OK)
1033 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2);
1034
1035 if ((err==ZIP_OK) && (size_filename > 0))
1036 {
1037 if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
1038 err = ZIP_ERRNO;
1039 }
1040
1041 if ((err==ZIP_OK) && (size_extrafield_local > 0))
1042 {
1043 if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local)
1044 err = ZIP_ERRNO;
1045 }
1046
1047
1048 if ((err==ZIP_OK) && (zi->ci.zip64))
1049 {
1050 /* write the Zip64 extended info */
1051 short HeaderID = 1;
1052 short DataSize = 16;
1053 ZPOS64_T CompressedSize = 0;
1054 ZPOS64_T UncompressedSize = 0;
1055
1056 /* Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file) */
1057 zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream);
1058
1059 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2);
1060 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2);
1061
1062 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8);
1063 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8);
1064 }
1065
1066 return err;
1067}
1068
1069/*
1070 NOTE.
1071 When writing RAW the ZIP64 extended information in extrafield_local and extrafield_global needs to be stripped
1072 before calling this function it can be done with zipRemoveExtraInfoBlock
1073
1074 It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize
1075 unnecessary allocations.
1076 */
1077extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1078 const void* extrafield_local, uInt size_extrafield_local,
1079 const void* extrafield_global, uInt size_extrafield_global,
1080 const char* comment, int method, int level, int raw,
1081 int windowBits,int memLevel, int strategy,
1082 const char* password, uLong crcForCrypting,
1083 uLong versionMadeBy, uLong flagBase, int zip64)
1084{
1085 zip64_internal* zi;
716 uInt size_filename; 1086 uInt size_filename;
717 uInt size_comment; 1087 uInt size_comment;
718 uInt i; 1088 uInt i;
719 int err = ZIP_OK; 1089 int err = ZIP_OK;
1090 uLong version_to_extract;
720 1091
721# ifdef NOCRYPT 1092# ifdef NOCRYPT
722 if (password != NULL) 1093 if (password != NULL)
@@ -725,10 +1096,16 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
725 1096
726 if (file == NULL) 1097 if (file == NULL)
727 return ZIP_PARAMERROR; 1098 return ZIP_PARAMERROR;
1099
1100#ifdef HAVE_BZIP2
1101 if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED))
1102 return ZIP_PARAMERROR;
1103#else
728 if ((method!=0) && (method!=Z_DEFLATED)) 1104 if ((method!=0) && (method!=Z_DEFLATED))
729 return ZIP_PARAMERROR; 1105 return ZIP_PARAMERROR;
1106#endif
730 1107
731 zi = (zip_internal*)file; 1108 zi = (zip64_internal*)file;
732 1109
733 if (zi->in_opened_file_inzip == 1) 1110 if (zi->in_opened_file_inzip == 1)
734 { 1111 {
@@ -737,6 +1114,16 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
737 return err; 1114 return err;
738 } 1115 }
739 1116
1117 if (method == 0
1118 && (level == 0 || (zi->flags & ZIP_WRITE_DATA_DESCRIPTOR) == 0)
1119 && (zi->flags & ZIP_SEQUENTIAL) == 0)
1120 {
1121 version_to_extract = 10;
1122 }
1123 else
1124 {
1125 version_to_extract = 20;
1126 }
740 1127
741 if (filename==NULL) 1128 if (filename==NULL)
742 filename="-"; 1129 filename="-";
@@ -754,18 +1141,23 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
754 { 1141 {
755 if (zipfi->dosDate != 0) 1142 if (zipfi->dosDate != 0)
756 zi->ci.dosDate = zipfi->dosDate; 1143 zi->ci.dosDate = zipfi->dosDate;
757 else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate); 1144 else
1145 zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date);
758 } 1146 }
759 1147
760 zi->ci.flag = 0; 1148 zi->ci.flag = flagBase;
761 if ((level==8) || (level==9)) 1149 if ((level==8) || (level==9))
762 zi->ci.flag |= 2; 1150 zi->ci.flag |= 2;
763 if ((level==2)) 1151 if (level==2)
764 zi->ci.flag |= 4; 1152 zi->ci.flag |= 4;
765 if ((level==1)) 1153 if (level==1)
766 zi->ci.flag |= 6; 1154 zi->ci.flag |= 6;
767 if (password != NULL) 1155 if (password != NULL)
768 zi->ci.flag |= 1; 1156 zi->ci.flag |= 1;
1157 if (version_to_extract >= 20
1158 && ((zi->flags & ZIP_WRITE_DATA_DESCRIPTOR) != 0
1159 || (zi->flags & ZIP_SEQUENTIAL) != 0))
1160 zi->ci.flag |= 8;
769 1161
770 zi->ci.crc32 = 0; 1162 zi->ci.crc32 = 0;
771 zi->ci.method = method; 1163 zi->ci.method = method;
@@ -773,37 +1165,43 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
773 zi->ci.stream_initialised = 0; 1165 zi->ci.stream_initialised = 0;
774 zi->ci.pos_in_buffered_data = 0; 1166 zi->ci.pos_in_buffered_data = 0;
775 zi->ci.raw = raw; 1167 zi->ci.raw = raw;
776 zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ; 1168 zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream);
777 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + 1169
778 size_extrafield_global + size_comment; 1170 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment;
779 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader); 1171 zi->ci.size_centralExtraFree = 32; /* Extra space we have reserved in case we need to add ZIP64 extra info data */
780 1172
781 ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); 1173 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree);
1174
1175 zi->ci.size_centralExtra = size_extrafield_global;
1176 zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
782 /* version info */ 1177 /* version info */
783 ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2); 1178 zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2);
784 ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); 1179 zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)version_to_extract,2);
785 ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); 1180 zip64local_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); 1181 zip64local_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); 1182 zip64local_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*/ 1183 zip64local_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*/ 1184 zip64local_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*/ 1185 zip64local_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); 1186 zip64local_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); 1187 zip64local_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); 1188 zip64local_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*/ 1189 zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
795 1190
796 if (zipfi==NULL) 1191 if (zipfi==NULL)
797 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); 1192 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
798 else 1193 else
799 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); 1194 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
800 1195
801 if (zipfi==NULL) 1196 if (zipfi==NULL)
802 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); 1197 zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
803 else 1198 else
804 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); 1199 zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
805 1200
806 ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4); 1201 if(zi->ci.pos_local_header >= 0xffffffff)
1202 zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4);
1203 else
1204 zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset,4);
807 1205
808 for (i=0;i<size_filename;i++) 1206 for (i=0;i<size_filename;i++)
809 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i); 1207 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
@@ -818,63 +1216,67 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
818 if (zi->ci.central_header == NULL) 1216 if (zi->ci.central_header == NULL)
819 return ZIP_INTERNALERROR; 1217 return ZIP_INTERNALERROR;
820 1218
821 /* write the local header */ 1219 zi->ci.zip64 = zip64;
822 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4); 1220 zi->ci.totalCompressedData = 0;
823 1221 zi->ci.totalUncompressedData = 0;
824 if (err==ZIP_OK) 1222 zi->ci.pos_zip64extrainfo = 0;
825 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ 1223
826 if (err==ZIP_OK) 1224 err = Write_LocalFileHeader(zi, filename, size_extrafield_local,
827 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); 1225 extrafield_local, version_to_extract);
828 1226
829 if (err==ZIP_OK) 1227#ifdef HAVE_BZIP2
830 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); 1228 zi->ci.bstream.avail_in = (uInt)0;
831 1229 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
832 if (err==ZIP_OK) 1230 zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
833 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); 1231 zi->ci.bstream.total_in_hi32 = 0;
834 1232 zi->ci.bstream.total_in_lo32 = 0;
835 if (err==ZIP_OK) 1233 zi->ci.bstream.total_out_hi32 = 0;
836 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ 1234 zi->ci.bstream.total_out_lo32 = 0;
837 if (err==ZIP_OK) 1235#endif
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 1236
857 zi->ci.stream.avail_in = (uInt)0; 1237 zi->ci.stream.avail_in = (uInt)0;
858 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 1238 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
859 zi->ci.stream.next_out = zi->ci.buffered_data; 1239 zi->ci.stream.next_out = zi->ci.buffered_data;
860 zi->ci.stream.total_in = 0; 1240 zi->ci.stream.total_in = 0;
861 zi->ci.stream.total_out = 0; 1241 zi->ci.stream.total_out = 0;
1242 zi->ci.stream.data_type = Z_BINARY;
862 1243
1244#ifdef HAVE_BZIP2
1245 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1246#else
863 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1247 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1248#endif
864 { 1249 {
865 zi->ci.stream.zalloc = (alloc_func)0; 1250 if(zi->ci.method == Z_DEFLATED)
866 zi->ci.stream.zfree = (free_func)0; 1251 {
867 zi->ci.stream.opaque = (voidpf)0; 1252 zi->ci.stream.zalloc = (alloc_func)0;
1253 zi->ci.stream.zfree = (free_func)0;
1254 zi->ci.stream.opaque = (voidpf)0;
868 1255
869 if (windowBits>0) 1256 if (windowBits>0)
870 windowBits = -windowBits; 1257 windowBits = -windowBits;
871 1258
872 err = deflateInit2(&zi->ci.stream, level, 1259 err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy);
873 Z_DEFLATED, windowBits, memLevel, strategy); 1260
1261 if (err==Z_OK)
1262 zi->ci.stream_initialised = Z_DEFLATED;
1263 }
1264 else if(zi->ci.method == Z_BZIP2ED)
1265 {
1266#ifdef HAVE_BZIP2
1267 /* Init BZip stuff here */
1268 zi->ci.bstream.bzalloc = 0;
1269 zi->ci.bstream.bzfree = 0;
1270 zi->ci.bstream.opaque = (voidpf)0;
1271
1272 err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35);
1273 if(err == BZ_OK)
1274 zi->ci.stream_initialised = Z_BZIP2ED;
1275#endif
1276 }
874 1277
875 if (err==Z_OK)
876 zi->ci.stream_initialised = 1;
877 } 1278 }
1279
878# ifndef NOCRYPT 1280# ifndef NOCRYPT
879 zi->ci.crypt_header_size = 0; 1281 zi->ci.crypt_header_size = 0;
880 if ((err==Z_OK) && (password != NULL)) 1282 if ((err==Z_OK) && (password != NULL))
@@ -884,11 +1286,13 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
884 zi->ci.encrypt = 1; 1286 zi->ci.encrypt = 1;
885 zi->ci.pcrc_32_tab = get_crc_table(); 1287 zi->ci.pcrc_32_tab = get_crc_table();
886 /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/ 1288 /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
887 1289 if (crcForCrypting == 0) {
1290 crcForCrypting = (uLong)zi->ci.dosDate << 16; /* ATTANTION! Without this row, you don't unpack your password protected archive in other app. */
1291 }
888 sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); 1292 sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
889 zi->ci.crypt_header_size = sizeHead; 1293 zi->ci.crypt_header_size = sizeHead;
890 1294
891 if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) 1295 if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
892 err = ZIP_ERRNO; 1296 err = ZIP_ERRNO;
893 } 1297 }
894# endif 1298# endif
@@ -898,53 +1302,105 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
898 return err; 1302 return err;
899} 1303}
900 1304
901extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi, 1305extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
902 extrafield_local, size_extrafield_local, 1306 const void* extrafield_local, uInt size_extrafield_local,
903 extrafield_global, size_extrafield_global, 1307 const void* extrafield_global, uInt size_extrafield_global,
904 comment, method, level, raw) 1308 const char* comment, int method, int level, int raw,
905 zipFile file; 1309 int windowBits,int memLevel, int strategy,
906 const char* filename; 1310 const char* password, uLong crcForCrypting,
907 const zip_fileinfo* zipfi; 1311 uLong versionMadeBy, uLong flagBase)
908 const void* extrafield_local; 1312{
909 uInt size_extrafield_local; 1313 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
910 const void* extrafield_global; 1314 extrafield_local, size_extrafield_local,
911 uInt size_extrafield_global; 1315 extrafield_global, size_extrafield_global,
912 const char* comment; 1316 comment, method, level, raw,
913 int method; 1317 windowBits, memLevel, strategy,
914 int level; 1318 password, crcForCrypting, versionMadeBy, flagBase, 0);
915 int raw; 1319}
1320
1321extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1322 const void* extrafield_local, uInt size_extrafield_local,
1323 const void* extrafield_global, uInt size_extrafield_global,
1324 const char* comment, int method, int level, int raw,
1325 int windowBits,int memLevel, int strategy,
1326 const char* password, uLong crcForCrypting)
1327{
1328 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1329 extrafield_local, size_extrafield_local,
1330 extrafield_global, size_extrafield_global,
1331 comment, method, level, raw,
1332 windowBits, memLevel, strategy,
1333 password, crcForCrypting, VERSIONMADEBY, 0, 0);
1334}
1335
1336extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1337 const void* extrafield_local, uInt size_extrafield_local,
1338 const void* extrafield_global, uInt size_extrafield_global,
1339 const char* comment, int method, int level, int raw,
1340 int windowBits,int memLevel, int strategy,
1341 const char* password, uLong crcForCrypting, int zip64)
1342{
1343 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1344 extrafield_local, size_extrafield_local,
1345 extrafield_global, size_extrafield_global,
1346 comment, method, level, raw,
1347 windowBits, memLevel, strategy,
1348 password, crcForCrypting, VERSIONMADEBY, 0, zip64);
1349}
1350
1351extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1352 const void* extrafield_local, uInt size_extrafield_local,
1353 const void* extrafield_global, uInt size_extrafield_global,
1354 const char* comment, int method, int level, int raw)
1355{
1356 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1357 extrafield_local, size_extrafield_local,
1358 extrafield_global, size_extrafield_global,
1359 comment, method, level, raw,
1360 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1361 NULL, 0, VERSIONMADEBY, 0, 0);
1362}
1363
1364extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
1365 const void* extrafield_local, uInt size_extrafield_local,
1366 const void* extrafield_global, uInt size_extrafield_global,
1367 const char* comment, int method, int level, int raw, int zip64)
916{ 1368{
917 return zipOpenNewFileInZip3 (file, filename, zipfi, 1369 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
918 extrafield_local, size_extrafield_local, 1370 extrafield_local, size_extrafield_local,
919 extrafield_global, size_extrafield_global, 1371 extrafield_global, size_extrafield_global,
920 comment, method, level, raw, 1372 comment, method, level, raw,
921 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, 1373 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
922 NULL, 0); 1374 NULL, 0, VERSIONMADEBY, 0, zip64);
1375}
1376
1377extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
1378 const void* extrafield_local, uInt size_extrafield_local,
1379 const void*extrafield_global, uInt size_extrafield_global,
1380 const char* comment, int method, int level, int zip64)
1381{
1382 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1383 extrafield_local, size_extrafield_local,
1384 extrafield_global, size_extrafield_global,
1385 comment, method, level, 0,
1386 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1387 NULL, 0, VERSIONMADEBY, 0, zip64);
923} 1388}
924 1389
925extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi, 1390extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi,
926 extrafield_local, size_extrafield_local, 1391 const void* extrafield_local, uInt size_extrafield_local,
927 extrafield_global, size_extrafield_global, 1392 const void*extrafield_global, uInt size_extrafield_global,
928 comment, method, level) 1393 const char* comment, int method, int 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{ 1394{
940 return zipOpenNewFileInZip2 (file, filename, zipfi, 1395 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
941 extrafield_local, size_extrafield_local, 1396 extrafield_local, size_extrafield_local,
942 extrafield_global, size_extrafield_global, 1397 extrafield_global, size_extrafield_global,
943 comment, method, level, 0); 1398 comment, method, level, 0,
1399 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1400 NULL, 0, VERSIONMADEBY, 0, 0);
944} 1401}
945 1402
946local int zipFlushWriteBuffer(zi) 1403local int zip64FlushWriteBuffer(zip64_internal* zi)
947 zip_internal* zi;
948{ 1404{
949 int err=ZIP_OK; 1405 int err=ZIP_OK;
950 1406
@@ -954,170 +1410,395 @@ local int zipFlushWriteBuffer(zi)
954 uInt i; 1410 uInt i;
955 int t; 1411 int t;
956 for (i=0;i<zi->ci.pos_in_buffered_data;i++) 1412 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, 1413 zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t);
958 zi->ci.buffered_data[i],t);
959#endif 1414#endif
960 } 1415 }
961 if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) 1416
962 !=zi->ci.pos_in_buffered_data) 1417 if (ZWRITE64(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) != zi->ci.pos_in_buffered_data)
963 err = ZIP_ERRNO; 1418 err = ZIP_ERRNO;
1419
1420 zi->ci.totalCompressedData += zi->ci.pos_in_buffered_data;
1421
1422#ifdef HAVE_BZIP2
1423 if(zi->ci.method == Z_BZIP2ED)
1424 {
1425 zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32;
1426 zi->ci.bstream.total_in_lo32 = 0;
1427 zi->ci.bstream.total_in_hi32 = 0;
1428 }
1429 else
1430#endif
1431 {
1432 zi->ci.totalUncompressedData += zi->ci.stream.total_in;
1433 zi->ci.stream.total_in = 0;
1434 }
1435
1436
964 zi->ci.pos_in_buffered_data = 0; 1437 zi->ci.pos_in_buffered_data = 0;
1438
965 return err; 1439 return err;
966} 1440}
967 1441
968extern int ZEXPORT zipWriteInFileInZip (file, buf, len) 1442extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len)
969 zipFile file;
970 const void* buf;
971 unsigned len;
972{ 1443{
973 zip_internal* zi; 1444 zip64_internal* zi;
974 int err=ZIP_OK; 1445 int err=ZIP_OK;
975 1446
976 if (file == NULL) 1447 if (file == NULL)
977 return ZIP_PARAMERROR; 1448 return ZIP_PARAMERROR;
978 zi = (zip_internal*)file; 1449 zi = (zip64_internal*)file;
979 1450
980 if (zi->in_opened_file_inzip == 0) 1451 if (zi->in_opened_file_inzip == 0)
981 return ZIP_PARAMERROR; 1452 return ZIP_PARAMERROR;
982 1453
983 zi->ci.stream.next_in = (void*)buf; 1454 zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len);
984 zi->ci.stream.avail_in = len;
985 zi->ci.crc32 = crc32(zi->ci.crc32,buf,len);
986 1455
987 while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) 1456#ifdef HAVE_BZIP2
1457 if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw))
988 { 1458 {
989 if (zi->ci.stream.avail_out == 0) 1459 zi->ci.bstream.next_in = (void*)buf;
1460 zi->ci.bstream.avail_in = len;
1461 err = BZ_RUN_OK;
1462
1463 while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0))
1464 {
1465 if (zi->ci.bstream.avail_out == 0)
990 { 1466 {
991 if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) 1467 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
992 err = ZIP_ERRNO; 1468 err = ZIP_ERRNO;
993 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 1469 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
994 zi->ci.stream.next_out = zi->ci.buffered_data; 1470 zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
995 } 1471 }
996 1472
997 1473
998 if(err != ZIP_OK) 1474 if(err != BZ_RUN_OK)
999 break; 1475 break;
1000 1476
1001 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1477 if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1002 { 1478 {
1003 uLong uTotalOutBefore = zi->ci.stream.total_out; 1479 uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
1004 err=deflate(&zi->ci.stream, Z_NO_FLUSH); 1480/* uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32; */
1005 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; 1481 err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN);
1006 1482
1483 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ;
1007 } 1484 }
1008 else 1485 }
1009 { 1486
1010 uInt copy_this,i; 1487 if(err == BZ_RUN_OK)
1011 if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) 1488 err = ZIP_OK;
1012 copy_this = zi->ci.stream.avail_in; 1489 }
1013 else 1490 else
1014 copy_this = zi->ci.stream.avail_out; 1491#endif
1015 for (i=0;i<copy_this;i++) 1492 {
1016 *(((char*)zi->ci.stream.next_out)+i) = 1493 zi->ci.stream.next_in = (Bytef*)buf;
1017 *(((const char*)zi->ci.stream.next_in)+i); 1494 zi->ci.stream.avail_in = len;
1018 { 1495
1019 zi->ci.stream.avail_in -= copy_this; 1496 while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
1020 zi->ci.stream.avail_out-= copy_this; 1497 {
1021 zi->ci.stream.next_in+= copy_this; 1498 if (zi->ci.stream.avail_out == 0)
1022 zi->ci.stream.next_out+= copy_this; 1499 {
1023 zi->ci.stream.total_in+= copy_this; 1500 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1024 zi->ci.stream.total_out+= copy_this; 1501 err = ZIP_ERRNO;
1025 zi->ci.pos_in_buffered_data += copy_this; 1502 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1026 } 1503 zi->ci.stream.next_out = zi->ci.buffered_data;
1027 } 1504 }
1505
1506
1507 if(err != ZIP_OK)
1508 break;
1509
1510 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1511 {
1512 uLong uTotalOutBefore = zi->ci.stream.total_out;
1513 err=deflate(&zi->ci.stream, Z_NO_FLUSH);
1514 if(uTotalOutBefore > zi->ci.stream.total_out)
1515 {
1516 int bBreak = 0;
1517 bBreak++;
1518 }
1519
1520 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
1521 }
1522 else
1523 {
1524 uInt copy_this,i;
1525 if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
1526 copy_this = zi->ci.stream.avail_in;
1527 else
1528 copy_this = zi->ci.stream.avail_out;
1529
1530 for (i = 0; i < copy_this; i++)
1531 *(((char*)zi->ci.stream.next_out)+i) =
1532 *(((const char*)zi->ci.stream.next_in)+i);
1533 {
1534 zi->ci.stream.avail_in -= copy_this;
1535 zi->ci.stream.avail_out-= copy_this;
1536 zi->ci.stream.next_in+= copy_this;
1537 zi->ci.stream.next_out+= copy_this;
1538 zi->ci.stream.total_in+= copy_this;
1539 zi->ci.stream.total_out+= copy_this;
1540 zi->ci.pos_in_buffered_data += copy_this;
1541 }
1542 }
1543 }/* while(...) */
1028 } 1544 }
1029 1545
1030 return err; 1546 return err;
1031} 1547}
1032 1548
1033extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32) 1549extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32)
1034 zipFile file; 1550{
1035 uLong uncompressed_size; 1551 return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32);
1036 uLong crc32; 1552}
1553
1554extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
1037{ 1555{
1038 zip_internal* zi; 1556 zip64_internal* zi;
1039 uLong compressed_size; 1557 ZPOS64_T compressed_size;
1558 uLong invalidValue = 0xffffffff;
1559 short datasize = 0;
1040 int err=ZIP_OK; 1560 int err=ZIP_OK;
1041 1561
1042 if (file == NULL) 1562 if (file == NULL)
1043 return ZIP_PARAMERROR; 1563 return ZIP_PARAMERROR;
1044 zi = (zip_internal*)file; 1564 zi = (zip64_internal*)file;
1045 1565
1046 if (zi->in_opened_file_inzip == 0) 1566 if (zi->in_opened_file_inzip == 0)
1047 return ZIP_PARAMERROR; 1567 return ZIP_PARAMERROR;
1048 zi->ci.stream.avail_in = 0; 1568 zi->ci.stream.avail_in = 0;
1049 1569
1050 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1570 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1051 while (err==ZIP_OK) 1571 {
1572 while (err==ZIP_OK)
1573 {
1574 uLong uTotalOutBefore;
1575 if (zi->ci.stream.avail_out == 0)
1576 {
1577 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1578 err = ZIP_ERRNO;
1579 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1580 zi->ci.stream.next_out = zi->ci.buffered_data;
1581 }
1582 uTotalOutBefore = zi->ci.stream.total_out;
1583 err=deflate(&zi->ci.stream, Z_FINISH);
1584 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
1585 }
1586 }
1587 else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1052 { 1588 {
1589#ifdef HAVE_BZIP2
1590 err = BZ_FINISH_OK;
1591 while (err==BZ_FINISH_OK)
1592 {
1053 uLong uTotalOutBefore; 1593 uLong uTotalOutBefore;
1054 if (zi->ci.stream.avail_out == 0) 1594 if (zi->ci.bstream.avail_out == 0)
1055 { 1595 {
1056 if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) 1596 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1057 err = ZIP_ERRNO; 1597 err = ZIP_ERRNO;
1058 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; 1598 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1059 zi->ci.stream.next_out = zi->ci.buffered_data; 1599 zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
1060 } 1600 }
1061 uTotalOutBefore = zi->ci.stream.total_out; 1601 uTotalOutBefore = zi->ci.bstream.total_out_lo32;
1062 err=deflate(&zi->ci.stream, Z_FINISH); 1602 err=BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH);
1063 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; 1603 if(err == BZ_STREAM_END)
1604 err = Z_STREAM_END;
1605
1606 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore);
1607 }
1608
1609 if(err == BZ_FINISH_OK)
1610 err = ZIP_OK;
1611#endif
1064 } 1612 }
1065 1613
1066 if (err==Z_STREAM_END) 1614 if (err==Z_STREAM_END)
1067 err=ZIP_OK; /* this is normal */ 1615 err=ZIP_OK; /* this is normal */
1068 1616
1069 if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) 1617 if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
1070 if (zipFlushWriteBuffer(zi)==ZIP_ERRNO) 1618 {
1619 if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO)
1071 err = ZIP_ERRNO; 1620 err = ZIP_ERRNO;
1621 }
1072 1622
1073 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) 1623 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1074 { 1624 {
1075 err=deflateEnd(&zi->ci.stream); 1625 int tmp_err = deflateEnd(&zi->ci.stream);
1626 if (err == ZIP_OK)
1627 err = tmp_err;
1076 zi->ci.stream_initialised = 0; 1628 zi->ci.stream_initialised = 0;
1077 } 1629 }
1630#ifdef HAVE_BZIP2
1631 else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1632 {
1633 int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream);
1634 if (err==ZIP_OK)
1635 err = tmperr;
1636 zi->ci.stream_initialised = 0;
1637 }
1638#endif
1078 1639
1079 if (!zi->ci.raw) 1640 if (!zi->ci.raw)
1080 { 1641 {
1081 crc32 = (uLong)zi->ci.crc32; 1642 crc32 = (uLong)zi->ci.crc32;
1082 uncompressed_size = (uLong)zi->ci.stream.total_in; 1643 uncompressed_size = zi->ci.totalUncompressedData;
1083 } 1644 }
1084 compressed_size = (uLong)zi->ci.stream.total_out; 1645 compressed_size = zi->ci.totalCompressedData;
1646
1085# ifndef NOCRYPT 1647# ifndef NOCRYPT
1086 compressed_size += zi->ci.crypt_header_size; 1648 compressed_size += zi->ci.crypt_header_size;
1087# endif 1649# endif
1088 1650
1089 ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/ 1651 /* update Current Item crc and sizes, */
1090 ziplocal_putValue_inmemory(zi->ci.central_header+20, 1652 if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff)
1091 compressed_size,4); /*compr size*/ 1653 {
1654 /*version Made by*/
1655 zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2);
1656 /*version needed*/
1657 zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2);
1658
1659 }
1660
1661 zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
1662
1663
1664 if(compressed_size >= 0xffffffff)
1665 zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/
1666 else
1667 zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/
1668
1669 /* set internal file attributes field */
1092 if (zi->ci.stream.data_type == Z_ASCII) 1670 if (zi->ci.stream.data_type == Z_ASCII)
1093 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); 1671 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
1094 ziplocal_putValue_inmemory(zi->ci.central_header+24, 1672
1095 uncompressed_size,4); /*uncompr size*/ 1673 if(uncompressed_size >= 0xffffffff)
1674 zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/
1675 else
1676 zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/
1677
1678 /* Add ZIP64 extra info field for uncompressed size */
1679 if(uncompressed_size >= 0xffffffff)
1680 datasize += 8;
1681
1682 /* Add ZIP64 extra info field for compressed size */
1683 if(compressed_size >= 0xffffffff)
1684 datasize += 8;
1685
1686 /* Add ZIP64 extra info field for relative offset to local file header of current file */
1687 if(zi->ci.pos_local_header >= 0xffffffff)
1688 datasize += 8;
1689
1690 if(datasize > 0)
1691 {
1692 char* p = NULL;
1693
1694 if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree)
1695 {
1696 /* we can not write more data to the buffer that we have room for. */
1697 return ZIP_BADZIPFILE;
1698 }
1699
1700 p = zi->ci.central_header + zi->ci.size_centralheader;
1701
1702 /* Add Extra Information Header for 'ZIP64 information' */
1703 zip64local_putValue_inmemory(p, 0x0001, 2); /* HeaderID */
1704 p += 2;
1705 zip64local_putValue_inmemory(p, datasize, 2); /* DataSize */
1706 p += 2;
1707
1708 if(uncompressed_size >= 0xffffffff)
1709 {
1710 zip64local_putValue_inmemory(p, uncompressed_size, 8);
1711 p += 8;
1712 }
1713
1714 if(compressed_size >= 0xffffffff)
1715 {
1716 zip64local_putValue_inmemory(p, compressed_size, 8);
1717 p += 8;
1718 }
1719
1720 if(zi->ci.pos_local_header >= 0xffffffff)
1721 {
1722 zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8);
1723 p += 8;
1724 }
1725
1726 /* Update how much extra free space we got in the memory buffer */
1727 /* and increase the centralheader size so the new ZIP64 fields are included */
1728 /* ( 4 below is the size of HeaderID and DataSize field ) */
1729 zi->ci.size_centralExtraFree -= datasize + 4;
1730 zi->ci.size_centralheader += datasize + 4;
1731
1732 /* Update the extra info size field */
1733 zi->ci.size_centralExtra += datasize + 4;
1734 zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2);
1735 }
1096 1736
1097 if (err==ZIP_OK) 1737 if (err==ZIP_OK)
1098 err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header, 1738 err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
1099 (uLong)zi->ci.size_centralheader); 1739
1100 free(zi->ci.central_header); 1740 free(zi->ci.central_header);
1101 1741
1102 if (err==ZIP_OK) 1742 if (err==ZIP_OK)
1103 { 1743 {
1104 long cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); 1744 if ((zi->flags & ZIP_SEQUENTIAL) == 0) {
1105 if (ZSEEK(zi->z_filefunc,zi->filestream, 1745 /* Update the LocalFileHeader with the new values. */
1106 zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
1107 err = ZIP_ERRNO;
1108 1746
1109 if (err==ZIP_OK) 1747 ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
1110 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
1111 1748
1112 if (err==ZIP_OK) /* compressed size, unknown */ 1749 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
1113 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4); 1750 err = ZIP_ERRNO;
1114 1751
1115 if (err==ZIP_OK) /* uncompressed size, unknown */ 1752 if (err==ZIP_OK)
1116 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4); 1753 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
1117 1754
1118 if (ZSEEK(zi->z_filefunc,zi->filestream, 1755 if(uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff)
1119 cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0) 1756 {
1120 err = ZIP_ERRNO; 1757 if(zi->ci.pos_zip64extrainfo > 0)
1758 {
1759 /* Update the size in the ZIP64 extended field. */
1760 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0)
1761 err = ZIP_ERRNO;
1762
1763 if (err==ZIP_OK) /* compressed size, unknown */
1764 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8);
1765
1766 if (err==ZIP_OK) /* uncompressed size, unknown */
1767 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
1768 }
1769 }
1770 else
1771 {
1772 if (err==ZIP_OK) /* compressed size, unknown */
1773 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
1774
1775 if (err==ZIP_OK) /* uncompressed size, unknown */
1776 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
1777 }
1778
1779 if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
1780 err = ZIP_ERRNO;
1781 }
1782
1783 if ((zi->ci.flag & 8) != 0) {
1784 /* Write local Descriptor after file data */
1785 if (err==ZIP_OK)
1786 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)DESCRIPTORHEADERMAGIC,4);
1787 if (err==ZIP_OK)
1788 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
1789 if (zi->ci.zip64) {
1790 if (err==ZIP_OK) /* compressed size, unknown */
1791 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,8);
1792
1793 if (err==ZIP_OK) /* uncompressed size, unknown */
1794 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,8);
1795 } else {
1796 if (err==ZIP_OK) /* compressed size, unknown */
1797 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
1798 if (err==ZIP_OK) /* uncompressed size, unknown */
1799 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
1800 }
1801 }
1121 } 1802 }
1122 1803
1123 zi->number_entry ++; 1804 zi->number_entry ++;
@@ -1126,24 +1807,150 @@ extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32)
1126 return err; 1807 return err;
1127} 1808}
1128 1809
1129extern int ZEXPORT zipCloseFileInZip (file) 1810extern int ZEXPORT zipCloseFileInZip (zipFile file)
1130 zipFile file;
1131{ 1811{
1132 return zipCloseFileInZipRaw (file,0,0); 1812 return zipCloseFileInZipRaw (file,0,0);
1133} 1813}
1134 1814
1135extern int ZEXPORT zipClose (file, global_comment) 1815int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip)
1136 zipFile file; 1816{
1137 const char* global_comment; 1817 int err = ZIP_OK;
1818 ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset;
1819
1820 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4);
1821
1822 /*num disks*/
1823 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1824 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
1825
1826 /*relative offset*/
1827 if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */
1828 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8);
1829
1830 /*total disks*/ /* Do not support spawning of disk so always say 1 here*/
1831 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1832 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4);
1833
1834 return err;
1835}
1836
1837int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
1838{
1839 int err = ZIP_OK;
1840
1841 uLong Zip64DataSize = 44;
1842
1843 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4);
1844
1845 if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */
1846 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); /* why ZPOS64_T of this ? */
1847
1848 if (err==ZIP_OK) /* version made by */
1849 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
1850
1851 if (err==ZIP_OK) /* version needed */
1852 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
1853
1854 if (err==ZIP_OK) /* number of this disk */
1855 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
1856
1857 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1858 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
1859
1860 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
1861 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
1862
1863 if (err==ZIP_OK) /* total number of entries in the central dir */
1864 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
1865
1866 if (err==ZIP_OK) /* size of the central directory */
1867 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8);
1868
1869 if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
1870 {
1871 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
1872 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8);
1873 }
1874 return err;
1875}
1876int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
1877{
1878 int err = ZIP_OK;
1879
1880 /*signature*/
1881 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
1882
1883 if (err==ZIP_OK) /* number of this disk */
1884 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
1885
1886 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
1887 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
1888
1889 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
1890 {
1891 {
1892 if(zi->number_entry >= 0xFFFF)
1893 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); /* use value in ZIP64 record */
1894 else
1895 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
1896 }
1897 }
1898
1899 if (err==ZIP_OK) /* total number of entries in the central dir */
1900 {
1901 if(zi->number_entry >= 0xFFFF)
1902 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); /* use value in ZIP64 record */
1903 else
1904 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
1905 }
1906
1907 if (err==ZIP_OK) /* size of the central directory */
1908 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
1909
1910 if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
1911 {
1912 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
1913 if(pos >= 0xffffffff)
1914 {
1915 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4);
1916 }
1917 else
1918 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);
1919 }
1920
1921 return err;
1922}
1923
1924int Write_GlobalComment(zip64_internal* zi, const char* global_comment)
1925{
1926 int err = ZIP_OK;
1927 uInt size_global_comment = 0;
1928
1929 if(global_comment != NULL)
1930 size_global_comment = (uInt)strlen(global_comment);
1931
1932 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
1933
1934 if (err == ZIP_OK && size_global_comment > 0)
1935 {
1936 if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment)
1937 err = ZIP_ERRNO;
1938 }
1939 return err;
1940}
1941
1942extern int ZEXPORT zipClose (zipFile file, const char* global_comment)
1138{ 1943{
1139 zip_internal* zi; 1944 zip64_internal* zi;
1140 int err = 0; 1945 int err = 0;
1141 uLong size_centraldir = 0; 1946 uLong size_centraldir = 0;
1142 uLong centraldir_pos_inzip; 1947 ZPOS64_T centraldir_pos_inzip;
1143 uInt size_global_comment; 1948 ZPOS64_T pos;
1949
1144 if (file == NULL) 1950 if (file == NULL)
1145 return ZIP_PARAMERROR; 1951 return ZIP_PARAMERROR;
1146 zi = (zip_internal*)file; 1952
1953 zi = (zip64_internal*)file;
1147 1954
1148 if (zi->in_opened_file_inzip == 1) 1955 if (zi->in_opened_file_inzip == 1)
1149 { 1956 {
@@ -1154,63 +1961,52 @@ extern int ZEXPORT zipClose (file, global_comment)
1154 if (global_comment==NULL) 1961 if (global_comment==NULL)
1155 global_comment = zi->globalcomment; 1962 global_comment = zi->globalcomment;
1156#endif 1963#endif
1157 if (global_comment==NULL)
1158 size_global_comment = 0;
1159 else
1160 size_global_comment = (uInt)strlen(global_comment);
1161 1964
1162 centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); 1965 centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
1966
1163 if (err==ZIP_OK) 1967 if (err==ZIP_OK)
1164 { 1968 {
1165 linkedlist_datablock_internal* ldi = zi->central_dir.first_block ; 1969 linkedlist_datablock_internal* ldi = zi->central_dir.first_block;
1166 while (ldi!=NULL) 1970 while (ldi!=NULL)
1167 { 1971 {
1168 if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) 1972 if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
1169 if (ZWRITE(zi->z_filefunc,zi->filestream, 1973 {
1170 ldi->data,ldi->filled_in_this_block) 1974 if (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data, ldi->filled_in_this_block) != ldi->filled_in_this_block)
1171 !=ldi->filled_in_this_block )
1172 err = ZIP_ERRNO; 1975 err = ZIP_ERRNO;
1976 }
1173 1977
1174 size_centraldir += ldi->filled_in_this_block; 1978 size_centraldir += ldi->filled_in_this_block;
1175 ldi = ldi->next_datablock; 1979 ldi = ldi->next_datablock;
1176 } 1980 }
1177 } 1981 }
1178 free_datablock(zi->central_dir.first_block); 1982 free_linkedlist(&(zi->central_dir));
1179
1180 if (err==ZIP_OK) /* Magic End */
1181 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
1182 1983
1183 if (err==ZIP_OK) /* number of this disk */ 1984 pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
1184 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); 1985 if(pos >= 0xffffffff || zi->number_entry > 0xFFFF)
1185 1986 {
1186 if (err==ZIP_OK) /* number of the disk with the start of the central directory */ 1987 ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream);
1187 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); 1988 Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
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 1989
1195 if (err==ZIP_OK) /* size of the central directory */ 1990 Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos);
1196 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); 1991 }
1197 1992
1198 if (err==ZIP_OK) /* offset of start of central directory with respect to the 1993 if (err==ZIP_OK)
1199 starting disk number */ 1994 err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
1200 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,
1201 (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);
1202 1995
1203 if (err==ZIP_OK) /* zipfile comment length */ 1996 if(err == ZIP_OK)
1204 err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); 1997 err = Write_GlobalComment(zi, global_comment);
1205 1998
1206 if ((err==ZIP_OK) && (size_global_comment>0)) 1999 if ((zi->flags & ZIP_AUTO_CLOSE) != 0) {
1207 if (ZWRITE(zi->z_filefunc,zi->filestream, 2000 if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0) {
1208 global_comment,size_global_comment) != size_global_comment) 2001 if (err == ZIP_OK)
1209 err = ZIP_ERRNO; 2002 err = ZIP_ERRNO;
1210 2003 }
1211 if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0) 2004 } else {
1212 if (err == ZIP_OK) 2005 if (ZFAKECLOSE64(zi->z_filefunc,zi->filestream) != 0) {
1213 err = ZIP_ERRNO; 2006 if (err == ZIP_OK)
2007 err = ZIP_ERRNO;
2008 }
2009 }
1214 2010
1215#ifndef NO_ADDFILEINEXISTINGZIP 2011#ifndef NO_ADDFILEINEXISTINGZIP
1216 TRYFREE(zi->globalcomment); 2012 TRYFREE(zi->globalcomment);
@@ -1219,3 +2015,89 @@ extern int ZEXPORT zipClose (file, global_comment)
1219 2015
1220 return err; 2016 return err;
1221} 2017}
2018
2019extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader)
2020{
2021 char* p = pData;
2022 int size = 0;
2023 char* pNewHeader;
2024 char* pTmp;
2025 short header;
2026 short dataSize;
2027
2028 int retVal = ZIP_OK;
2029
2030 if(pData == NULL || *dataLen < 4)
2031 return ZIP_PARAMERROR;
2032
2033 pNewHeader = (char*)ALLOC(*dataLen);
2034 pTmp = pNewHeader;
2035
2036 while(p < (pData + *dataLen))
2037 {
2038 header = *(short*)p;
2039 dataSize = *(((short*)p)+1);
2040
2041 if( header == sHeader ) /* Header found. */
2042 {
2043 p += dataSize + 4; /* skip it. do not copy to temp buffer */
2044 }
2045 else
2046 {
2047 /* Extra Info block should not be removed, So copy it to the temp buffer. */
2048 memcpy(pTmp, p, dataSize + 4);
2049 p += dataSize + 4;
2050 size += dataSize + 4;
2051 }
2052
2053 }
2054
2055 if(size < *dataLen)
2056 {
2057 /* clean old extra info block. */
2058 memset(pData,0, *dataLen);
2059
2060 /* copy the new extra info block over the old */
2061 if(size > 0)
2062 memcpy(pData, pNewHeader, size);
2063
2064 /* set the new extra info size */
2065 *dataLen = size;
2066
2067 retVal = ZIP_OK;
2068 }
2069 else
2070 retVal = ZIP_ERRNO;
2071
2072 TRYFREE(pNewHeader);
2073
2074 return retVal;
2075}
2076
2077int ZEXPORT zipSetFlags(zipFile file, unsigned flags)
2078{
2079 zip64_internal* zi;
2080 if (file == NULL)
2081 return ZIP_PARAMERROR;
2082 zi = (zip64_internal*)file;
2083 zi->flags |= flags;
2084 // If the output is non-seekable, the data descriptor is needed.
2085 if ((zi->flags & ZIP_SEQUENTIAL) != 0) {
2086 zi->flags |= ZIP_WRITE_DATA_DESCRIPTOR;
2087 }
2088 return ZIP_OK;
2089}
2090
2091int ZEXPORT zipClearFlags(zipFile file, unsigned flags)
2092{
2093 zip64_internal* zi;
2094 if (file == NULL)
2095 return ZIP_PARAMERROR;
2096 zi = (zip64_internal*)file;
2097 zi->flags &= ~flags;
2098 // If the data descriptor is not written, we can't use a non-seekable output.
2099 if ((zi->flags & ZIP_WRITE_DATA_DESCRIPTOR) == 0) {
2100 zi->flags &= ~ZIP_SEQUENTIAL;
2101 }
2102 return ZIP_OK;
2103}
diff --git a/rbutil/rbutilqt/quazip/zip.h b/rbutil/rbutilqt/quazip/zip.h
index acacce83b9..a6617add0f 100644
--- a/rbutil/rbutilqt/quazip/zip.h
+++ b/rbutil/rbutilqt/quazip/zip.h
@@ -1,19 +1,15 @@
1/* zip.h -- IO for compress .zip files using zlib 1/* zip.h -- IO on .zip files using zlib
2 Version 1.01e, February 12th, 2005 2 Version 1.1, February 14h, 2010
3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
3 4
4 Copyright (C) 1998-2005 Gilles Vollant 5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
5 6
6 This unzip package allow creates .ZIP file, compatible with PKZip 2.04g 7 Modifications for Zip64 support
7 WinZip, InfoZip tools and compatible. 8 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
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 9
12 For uncompress .zip file, look at unzip.h 10 For more info read MiniZip_info.txt
13 11
14 12 ---------------------------------------------------------------------------
15 I WAIT FEEDBACK at mail info@winimage.com
16 Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
17 13
18 Condition of use and distribution are the same than zlib : 14 Condition of use and distribution are the same than zlib :
19 15
@@ -33,23 +29,29 @@
33 misrepresented as being the original software. 29 misrepresented as being the original software.
34 3. This notice may not be removed or altered from any source distribution. 30 3. This notice may not be removed or altered from any source distribution.
35 31
32 ---------------------------------------------------------------------------
36 33
37*/ 34 Changes
35
36 See header of zip.h
37
38 ---------------------------------------------------------------------------
39
40 As per the requirement above, this file is plainly marked as modified
41 by Sergey A. Tachenov. Most modifications include the I/O API redesign
42 to support QIODevice interface. Some improvements and small fixes were also made.
38 43
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*/ 44*/
45 45
46#ifndef _zip_H 46#ifndef _zip12_H
47#define _zip_H 47#define _zip12_H
48 48
49#ifdef __cplusplus 49#ifdef __cplusplus
50extern "C" { 50extern "C" {
51#endif 51#endif
52 52
53//#define HAVE_BZIP2
54
53#ifndef _ZLIB_H 55#ifndef _ZLIB_H
54#include "zlib.h" 56#include "zlib.h"
55#endif 57#endif
@@ -58,6 +60,12 @@ extern "C" {
58#include "ioapi.h" 60#include "ioapi.h"
59#endif 61#endif
60 62
63#ifdef HAVE_BZIP2
64#include "bzlib.h"
65#endif
66
67#define Z_BZIP2ED 12
68
61#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) 69#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
62/* like the STRICT of WIN32, we define a pointer that cannot be converted 70/* like the STRICT of WIN32, we define a pointer that cannot be converted
63 from (void*) without cast */ 71 from (void*) without cast */
@@ -74,6 +82,11 @@ typedef voidp zipFile;
74#define ZIP_BADZIPFILE (-103) 82#define ZIP_BADZIPFILE (-103)
75#define ZIP_INTERNALERROR (-104) 83#define ZIP_INTERNALERROR (-104)
76 84
85#define ZIP_WRITE_DATA_DESCRIPTOR 0x8u
86#define ZIP_AUTO_CLOSE 0x1u
87#define ZIP_SEQUENTIAL 0x2u
88#define ZIP_DEFAULT_FLAGS (ZIP_AUTO_CLOSE | ZIP_WRITE_DATA_DESCRIPTOR)
89
77#ifndef DEF_MEM_LEVEL 90#ifndef DEF_MEM_LEVEL
78# if MAX_MEM_LEVEL >= 8 91# if MAX_MEM_LEVEL >= 8
79# define DEF_MEM_LEVEL 8 92# define DEF_MEM_LEVEL 8
@@ -111,11 +124,12 @@ typedef const char* zipcharpc;
111#define APPEND_STATUS_CREATEAFTER (1) 124#define APPEND_STATUS_CREATEAFTER (1)
112#define APPEND_STATUS_ADDINZIP (2) 125#define APPEND_STATUS_ADDINZIP (2)
113 126
114extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); 127extern zipFile ZEXPORT zipOpen OF((voidpf file, int append));
128extern zipFile ZEXPORT zipOpen64 OF((voidpf file, int append));
115/* 129/*
116 Create a zipfile. 130 Create a zipfile.
117 pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on 131 the file argument depends on the API used, for QuaZIP it's a QIODevice
118 an Unix computer "zlib/zlib113.zip". 132 pointer.
119 if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip 133 if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
120 will be created at the end of the file. 134 will be created at the end of the file.
121 (useful if the file contain a self extractor code) 135 (useful if the file contain a self extractor code)
@@ -131,11 +145,27 @@ extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
131 Of couse, you can use RAW reading and writing to copy the file you did not want delte 145 Of couse, you can use RAW reading and writing to copy the file you did not want delte
132*/ 146*/
133 147
134extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, 148extern zipFile ZEXPORT zipOpen2 OF((voidpf file,
135 int append, 149 int append,
136 zipcharpc* globalcomment, 150 zipcharpc* globalcomment,
137 zlib_filefunc_def* pzlib_filefunc_def)); 151 zlib_filefunc_def* pzlib_filefunc_def));
138 152
153extern zipFile ZEXPORT zipOpen2_64 OF((voidpf file,
154 int append,
155 zipcharpc* globalcomment,
156 zlib_filefunc64_def* pzlib_filefunc_def));
157
158/*
159 * Exported by Sergey A. Tachenov to suit the needs of QuaZIP.
160 * Note that this function MAY change signature in order to
161 * provide new QuaZIP features. You have been warned!
162 * */
163extern zipFile ZEXPORT zipOpen3 (voidpf file,
164 int append,
165 zipcharpc* globalcomment,
166 zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
167 unsigned flags);
168
139extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, 169extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
140 const char* filename, 170 const char* filename,
141 const zip_fileinfo* zipfi, 171 const zip_fileinfo* zipfi,
@@ -146,6 +176,19 @@ extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
146 const char* comment, 176 const char* comment,
147 int method, 177 int method,
148 int level)); 178 int level));
179
180extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
181 const char* filename,
182 const zip_fileinfo* zipfi,
183 const void* extrafield_local,
184 uInt size_extrafield_local,
185 const void* extrafield_global,
186 uInt size_extrafield_global,
187 const char* comment,
188 int method,
189 int level,
190 int zip64));
191
149/* 192/*
150 Open a file in the ZIP for writing. 193 Open a file in the ZIP for writing.
151 filename : the filename in zip (if NULL, '-' without quote will be used 194 filename : the filename in zip (if NULL, '-' without quote will be used
@@ -157,6 +200,9 @@ extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
157 if comment != NULL, comment contain the comment string 200 if comment != NULL, comment contain the comment string
158 method contain the compression method (0 for store, Z_DEFLATED for deflate) 201 method contain the compression method (0 for store, Z_DEFLATED for deflate)
159 level contain the level of compression (can be Z_DEFAULT_COMPRESSION) 202 level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
203 zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
204 this MUST be '1' if the uncompressed size is >= 0xffffffff.
205
160*/ 206*/
161 207
162 208
@@ -172,6 +218,19 @@ extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
172 int level, 218 int level,
173 int raw)); 219 int raw));
174 220
221
222extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
223 const char* filename,
224 const zip_fileinfo* zipfi,
225 const void* extrafield_local,
226 uInt size_extrafield_local,
227 const void* extrafield_global,
228 uInt size_extrafield_global,
229 const char* comment,
230 int method,
231 int level,
232 int raw,
233 int zip64));
175/* 234/*
176 Same than zipOpenNewFileInZip, except if raw=1, we write raw file 235 Same than zipOpenNewFileInZip, except if raw=1, we write raw file
177 */ 236 */
@@ -191,13 +250,79 @@ extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
191 int memLevel, 250 int memLevel,
192 int strategy, 251 int strategy,
193 const char* password, 252 const char* password,
194 uLong crcForCtypting)); 253 uLong crcForCrypting));
254
255extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
256 const char* filename,
257 const zip_fileinfo* zipfi,
258 const void* extrafield_local,
259 uInt size_extrafield_local,
260 const void* extrafield_global,
261 uInt size_extrafield_global,
262 const char* comment,
263 int method,
264 int level,
265 int raw,
266 int windowBits,
267 int memLevel,
268 int strategy,
269 const char* password,
270 uLong crcForCrypting,
271 int zip64
272 ));
195 273
196/* 274/*
197 Same than zipOpenNewFileInZip2, except 275 Same than zipOpenNewFileInZip2, except
198 windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 276 windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
199 password : crypting password (NULL for no crypting) 277 password : crypting password (NULL for no crypting)
200 crcForCtypting : crc of file to compress (needed for crypting) 278 crcForCrypting : crc of file to compress (needed for crypting)
279 */
280
281extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
282 const char* filename,
283 const zip_fileinfo* zipfi,
284 const void* extrafield_local,
285 uInt size_extrafield_local,
286 const void* extrafield_global,
287 uInt size_extrafield_global,
288 const char* comment,
289 int method,
290 int level,
291 int raw,
292 int windowBits,
293 int memLevel,
294 int strategy,
295 const char* password,
296 uLong crcForCrypting,
297 uLong versionMadeBy,
298 uLong flagBase
299 ));
300
301
302extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
303 const char* filename,
304 const zip_fileinfo* zipfi,
305 const void* extrafield_local,
306 uInt size_extrafield_local,
307 const void* extrafield_global,
308 uInt size_extrafield_global,
309 const char* comment,
310 int method,
311 int level,
312 int raw,
313 int windowBits,
314 int memLevel,
315 int strategy,
316 const char* password,
317 uLong crcForCrypting,
318 uLong versionMadeBy,
319 uLong flagBase,
320 int zip64
321 ));
322/*
323 Same than zipOpenNewFileInZip4, except
324 versionMadeBy : value for Version made by field
325 flag : value for flag field (compression level info will be added)
201 */ 326 */
202 327
203 328
@@ -216,8 +341,13 @@ extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
216extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, 341extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
217 uLong uncompressed_size, 342 uLong uncompressed_size,
218 uLong crc32)); 343 uLong crc32));
344
345extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
346 ZPOS64_T uncompressed_size,
347 uLong crc32));
348
219/* 349/*
220 Close the current file in the zipfile, for fiel opened with 350 Close the current file in the zipfile, for file opened with
221 parameter raw=1 in zipOpenNewFileInZip2 351 parameter raw=1 in zipOpenNewFileInZip2
222 uncompressed_size and crc32 are value for the uncompressed size 352 uncompressed_size and crc32 are value for the uncompressed size
223*/ 353*/
@@ -228,8 +358,33 @@ extern int ZEXPORT zipClose OF((zipFile file,
228 Close the zipfile 358 Close the zipfile
229*/ 359*/
230 360
361
362extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
363/*
364 zipRemoveExtraInfoBlock - Added by Mathias Svensson
365
366 Remove extra information block from a extra information data for the local file header or central directory header
367
368 It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
369
370 0x0001 is the signature header for the ZIP64 extra information blocks
371
372 usage.
373 Remove ZIP64 Extra information from a central director extra field data
374 zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
375
376 Remove ZIP64 Extra information from a Local File Header extra field data
377 zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
378*/
379
380/*
381 Added by Sergey A. Tachenov to tweak zipping behaviour.
382*/
383extern int ZEXPORT zipSetFlags(zipFile file, unsigned flags);
384extern int ZEXPORT zipClearFlags(zipFile file, unsigned flags);
385
231#ifdef __cplusplus 386#ifdef __cplusplus
232} 387}
233#endif 388#endif
234 389
235#endif /* _zip_H */ 390#endif /* _zip64_H */
diff --git a/rbutil/rbutilqt/rbutilqt.pri b/rbutil/rbutilqt/rbutilqt.pri
index d67bf65bc3..a1cddb81bc 100644
--- a/rbutil/rbutilqt/rbutilqt.pri
+++ b/rbutil/rbutilqt/rbutilqt.pri
@@ -72,9 +72,10 @@ SOURCES += \
72 quazip/quazip.cpp \ 72 quazip/quazip.cpp \
73 quazip/quazipfile.cpp \ 73 quazip/quazipfile.cpp \
74 quazip/quazipnewinfo.cpp \ 74 quazip/quazipnewinfo.cpp \
75 quazip/quazipfileinfo.cpp \
76 quazip/qioapi.cpp \
75 quazip/unzip.c \ 77 quazip/unzip.c \
76 quazip/zip.c \ 78 quazip/zip.c \
77 quazip/ioapi.c \
78 base/ziputil.cpp \ 79 base/ziputil.cpp \
79 gui/comboboxviewdelegate.cpp \ 80 gui/comboboxviewdelegate.cpp \
80 gui/selectiveinstallwidget.cpp \ 81 gui/selectiveinstallwidget.cpp \
@@ -160,8 +161,10 @@ HEADERS += \
160 quazip/ioapi.h \ 161 quazip/ioapi.h \
161 quazip/quazipfile.h \ 162 quazip/quazipfile.h \
162 quazip/quazipfileinfo.h \ 163 quazip/quazipfileinfo.h \
164 quazip/quazipnewinfo.h \
163 quazip/quazip.h \ 165 quazip/quazip.h \
164 quazip/quazipnewinfo.h \ 166 quazip/quazipnewinfo.h \
167 quazip/quazip_global.h \
165 quazip/unzip.h \ 168 quazip/unzip.h \
166 quazip/zip.h \ 169 quazip/zip.h \
167 base/ziputil.h \ 170 base/ziputil.h \
diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro
index 19da13df81..1f09f2d35e 100644
--- a/rbutil/rbutilqt/rbutilqt.pro
+++ b/rbutil/rbutilqt/rbutilqt.pro
@@ -163,7 +163,7 @@ dbg {
163 message("release") 163 message("release")
164} 164}
165 165
166DEFINES += RBUTIL _LARGEFILE64_SOURCE CUTELOGGER_STATIC 166DEFINES += RBUTIL _LARGEFILE64_SOURCE CUTELOGGER_STATIC QUAZIP_STATIC
167 167
168# check version of Qt installation 168# check version of Qt installation
169!contains(QT_MAJOR_VERSION, 5):!macx:!*-msvc* { 169!contains(QT_MAJOR_VERSION, 5):!macx:!*-msvc* {