Merge lp:~guillaume-chereau/stellarium/no-kde into lp:stellarium
- no-kde
- Merge into trunk
Proposed by
Alexander Wolf
Status: | Merged |
---|---|
Merged at revision: | 6854 |
Proposed branch: | lp:~guillaume-chereau/stellarium/no-kde |
Merge into: | lp:stellarium |
Diff against target: |
7032 lines (+1696/-5001) (has conflicts) 35 files modified
CMakeLists.txt (+1/-1) src/CMakeLists.txt (+12/-13) src/core/MultiLevelJsonBase.cpp (+3/-6) src/core/StelLocationMgr.cpp (+1/-7) src/core/StelUtils.cpp (+39/-0) src/core/StelUtils.hpp (+3/-0) src/core/external/kdewin32/errno.h (+0/-36) src/core/external/kdewin32/grp.c (+0/-48) src/core/external/kdewin32/grp.h (+0/-47) src/core/external/kdewin32/pwd.c (+0/-62) src/core/external/kdewin32/pwd.h (+0/-71) src/core/external/kdewin32/stdio.h (+0/-37) src/core/external/kdewin32/stdlib.h (+0/-71) src/core/external/kdewin32/sys/stat.h (+0/-50) src/core/external/kdewin32/sys/types.h (+0/-48) src/core/external/kdewin32/unistd.c (+0/-48) src/core/external/kdewin32/unistd.h (+0/-45) src/core/external/kfilter/karchive.cpp (+0/-828) src/core/external/kfilter/karchive.h (+0/-603) src/core/external/kfilter/kfilterbase.cpp (+0/-113) src/core/external/kfilter/kfilterbase.h (+0/-115) src/core/external/kfilter/kfilterdev.cpp (+0/-372) src/core/external/kfilter/kfilterdev.h (+0/-153) src/core/external/kfilter/kgzipfilter.cpp (+0/-333) src/core/external/kfilter/kgzipfilter.h (+0/-54) src/core/external/kfilter/klimitediodevice.cpp (+0/-77) src/core/external/kfilter/klimitediodevice.h (+0/-63) src/core/external/kfilter/kzip.cpp (+0/-1402) src/core/external/kfilter/kzip.h (+0/-224) src/core/external/kfilter/readme.txt (+0/-9) src/core/external/qtcompress/qzip.cpp (+1395/-0) src/core/external/qtcompress/qzipreader.h (+112/-0) src/core/external/qtcompress/qzipwriter.h (+103/-0) src/core/modules/LandscapeMgr.cpp (+27/-58) src/core/modules/StarMgr.cpp (+0/-7) Text conflict in src/CMakeLists.txt |
To merge this branch: | bzr merge lp:~guillaume-chereau/stellarium/no-kde |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexander Wolf | Approve | ||
Review via email: mp+223148@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Alexander Wolf (alexwolf) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2014-06-14 00:05:12 +0000 |
3 | +++ CMakeLists.txt 2014-06-14 08:34:53 +0000 |
4 | @@ -456,7 +456,7 @@ |
5 | ${CMAKE_SOURCE_DIR}/src/core/modules |
6 | ${CMAKE_SOURCE_DIR}/src/core/planetsephems |
7 | ${CMAKE_SOURCE_DIR}/src/core/external |
8 | - ${CMAKE_SOURCE_DIR}/src/core/external/kfilter |
9 | + ${CMAKE_SOURCE_DIR}/src/core/external/qtcompress |
10 | ${CMAKE_SOURCE_DIR}/src/core/external/glues_stel/source/ |
11 | ${CMAKE_SOURCE_DIR}/src/core/external/glues_stel/source/libtess |
12 | ${CMAKE_SOURCE_DIR}/src/gui |
13 | |
14 | === modified file 'src/CMakeLists.txt' |
15 | --- src/CMakeLists.txt 2014-06-14 00:05:12 +0000 |
16 | +++ src/CMakeLists.txt 2014-06-14 08:34:53 +0000 |
17 | @@ -158,19 +158,6 @@ |
18 | |
19 | ${gl_lib_SRCS} |
20 | |
21 | - core/external/kfilter/kfilterdev.h |
22 | - core/external/kfilter/kfilterdev.cpp |
23 | - core/external/kfilter/kfilterbase.h |
24 | - core/external/kfilter/kfilterbase.cpp |
25 | - core/external/kfilter/kgzipfilter.h |
26 | - core/external/kfilter/kgzipfilter.cpp |
27 | - core/external/kfilter/kzip.h |
28 | - core/external/kfilter/kzip.cpp |
29 | - core/external/kfilter/klimitediodevice.h |
30 | - core/external/kfilter/klimitediodevice.cpp |
31 | - core/external/kfilter/karchive.h |
32 | - core/external/kfilter/karchive.cpp |
33 | - |
34 | ${glues_lib_SRCS} |
35 | |
36 | core/planetsephems/calc_interpolated_elements.c |
37 | @@ -254,6 +241,15 @@ |
38 | config.h |
39 | ) |
40 | |
41 | +# On windows, QZipReader is already included in the lib |
42 | +IF(!WIN32) |
43 | + SET(stellarium_lib_SRCS ${stellarium_lib_SRCS} |
44 | + core/external/qtcompress/qzip.cpp |
45 | + core/external/qtcompress/qzipreader.h |
46 | + core/external/qtcompress/qzipwriter.h |
47 | + ) |
48 | +ENDIF() |
49 | + |
50 | IF(ENABLE_SCRIPTING) |
51 | SET(stellarium_lib_SRCS ${stellarium_lib_SRCS} |
52 | scripting/StelScriptMgr.cpp |
53 | @@ -268,6 +264,7 @@ |
54 | ) |
55 | ENDIF() |
56 | |
57 | +<<<<<<< TREE |
58 | IF(WIN32) |
59 | SET(stellarium_lib_SRCS ${stellarium_lib_SRCS} |
60 | ${zlib_SRCS} |
61 | @@ -280,6 +277,8 @@ |
62 | ) |
63 | ENDIF() |
64 | |
65 | +======= |
66 | +>>>>>>> MERGE-SOURCE |
67 | SET(stellarium_exe_SRCS main.cpp) |
68 | |
69 | ################# compiles resources files ############ |
70 | |
71 | === modified file 'src/core/MultiLevelJsonBase.cpp' |
72 | --- src/core/MultiLevelJsonBase.cpp 2014-04-13 20:54:51 +0000 |
73 | +++ src/core/MultiLevelJsonBase.cpp 2014-06-14 08:34:53 +0000 |
74 | @@ -22,7 +22,6 @@ |
75 | #include "StelFileMgr.hpp" |
76 | #include "StelProjector.hpp" |
77 | #include "StelCore.hpp" |
78 | -#include "kfilterdev.h" |
79 | #include "StelUtils.hpp" |
80 | |
81 | #include <QDebug> |
82 | @@ -274,11 +273,9 @@ |
83 | } |
84 | else if (gzCompressed) |
85 | { |
86 | - QIODevice* d = KFilterDev::device(&input, "application/x-gzip", false); |
87 | - d->open(QIODevice::ReadOnly); |
88 | - map = parser.parse(d).toMap(); |
89 | - d->close(); |
90 | - delete d; |
91 | + QByteArray ar = StelUtils::uncompress(input.readAll()); |
92 | + input.close(); |
93 | + map = parser.parse(ar).toMap(); |
94 | } |
95 | else |
96 | { |
97 | |
98 | === modified file 'src/core/StelLocationMgr.cpp' |
99 | --- src/core/StelLocationMgr.cpp 2014-05-18 12:09:31 +0000 |
100 | +++ src/core/StelLocationMgr.cpp 2014-06-14 08:34:53 +0000 |
101 | @@ -20,7 +20,6 @@ |
102 | #include "StelFileMgr.hpp" |
103 | #include "StelLocationMgr.hpp" |
104 | #include "StelUtils.hpp" |
105 | -#include "kfilterdev.h" |
106 | |
107 | #include <QStringListModel> |
108 | #include <QDebug> |
109 | @@ -72,14 +71,9 @@ |
110 | if (fileName.endsWith(".gz")) |
111 | { |
112 | // FIXME: This code doesn't work with MSVC2012 -- need fix! --AW |
113 | - QIODevice* d = KFilterDev::device(&sourcefile, "application/x-gzip", false); |
114 | - d->open(QIODevice::ReadOnly); |
115 | - QByteArray arr = d->readAll(); |
116 | - QDataStream in(&arr, QIODevice::ReadOnly); |
117 | + QDataStream in(StelUtils::uncompress(sourcefile.readAll())); |
118 | in.setVersion(QDataStream::Qt_4_6); |
119 | in >> res; |
120 | - d->close(); |
121 | - delete d; |
122 | return res; |
123 | } |
124 | else |
125 | |
126 | === modified file 'src/core/StelUtils.cpp' |
127 | --- src/core/StelUtils.cpp 2014-06-11 15:48:31 +0000 |
128 | +++ src/core/StelUtils.cpp 2014-06-14 08:34:53 +0000 |
129 | @@ -33,6 +33,7 @@ |
130 | #include <QProcess> |
131 | #include <QSysInfo> |
132 | #include <cmath> // std::fmod |
133 | +#include <zlib.h> |
134 | |
135 | namespace StelUtils |
136 | { |
137 | @@ -1879,5 +1880,43 @@ |
138 | return cos_sin_rho; |
139 | } |
140 | |
141 | +//! Uncompress gzip or zlib compressed data. |
142 | +QByteArray uncompress(const QByteArray& data) |
143 | +{ |
144 | + if (data.size() <= 4) |
145 | + return QByteArray(); |
146 | + static const int CHUNK = 1024; |
147 | + QByteArray buffer(CHUNK, 0); |
148 | + QByteArray out; |
149 | + z_stream strm; |
150 | + strm.zalloc = Z_NULL; |
151 | + strm.zfree = Z_NULL; |
152 | + strm.opaque = Z_NULL; |
153 | + strm.avail_in = data.size(); |
154 | + strm.next_in = (Bytef*)(data.data()); |
155 | + |
156 | + // 15 + 32 for gzip automatic header detection. |
157 | + int ret = inflateInit2(&strm, 15 + 32); |
158 | + if (ret != Z_OK) return QByteArray(); |
159 | + |
160 | + do |
161 | + { |
162 | + strm.avail_out = CHUNK; |
163 | + strm.next_out = (Bytef*)(buffer.data()); |
164 | + ret = inflate(&strm, Z_NO_FLUSH); |
165 | + Q_ASSERT(ret != Z_STREAM_ERROR); |
166 | + if (ret < 0) |
167 | + { |
168 | + out.clear(); |
169 | + break; |
170 | + } |
171 | + out.append(buffer.data(), CHUNK - strm.avail_out); |
172 | + } |
173 | + while (strm.avail_out == 0); |
174 | + |
175 | + inflateEnd(&strm); |
176 | + return out; |
177 | +} |
178 | + |
179 | } // end of the StelUtils namespace |
180 | |
181 | |
182 | === modified file 'src/core/StelUtils.hpp' |
183 | --- src/core/StelUtils.hpp 2014-06-11 15:48:31 +0000 |
184 | +++ src/core/StelUtils.hpp 2014-06-14 08:34:53 +0000 |
185 | @@ -591,6 +591,9 @@ |
186 | //! @param segments number of segments |
187 | //! @param minAngle start angle inside the half-circle. maxAngle=minAngle+segments*phi |
188 | float* ComputeCosSinRhoZone(const float dRho, const int segments, const float minAngle); |
189 | + |
190 | + //! Uncompress gzip or zlib compressed data. |
191 | + QByteArray uncompress(const QByteArray& data); |
192 | } |
193 | |
194 | #endif // _STELUTILS_HPP_ |
195 | |
196 | === removed directory 'src/core/external/kdewin32' |
197 | === removed file 'src/core/external/kdewin32/errno.h' |
198 | --- src/core/external/kdewin32/errno.h 2010-11-28 04:24:13 +0000 |
199 | +++ src/core/external/kdewin32/errno.h 1970-01-01 00:00:00 +0000 |
200 | @@ -1,36 +0,0 @@ |
201 | -/* This file is part of the KDE project |
202 | - Copyright (C) 2006 Ralf Habacker <ralf.habacker@freenet.de> |
203 | - |
204 | - This program is free software; you can redistribute it and/or |
205 | - modify it under the terms of the GNU Library General Public |
206 | - License as published by the Free Software Foundation; either |
207 | - version 2 of the License, or (at your option) any later version. |
208 | - |
209 | - This program is distributed in the hope that it will be useful, |
210 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
211 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
212 | - Library General Public License for more details. |
213 | - |
214 | - You should have received a copy of the GNU Library General Public License |
215 | - along with this program; see the file COPYING. If not, write to |
216 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
217 | - Boston, MA 02110-1301, USA. |
218 | -*/ |
219 | - |
220 | -#ifndef _KDEWIN_ERRNO_H |
221 | -#define _KDEWIN_ERRNO_H |
222 | - |
223 | -#include "kdewin32/sys/types.h" |
224 | -#include <../include/errno.h> |
225 | - |
226 | -int __cdecl _set_errno(int value); |
227 | - |
228 | -#ifndef ENOFILE |
229 | -#define ENOFILE ENOENT |
230 | -#endif |
231 | - |
232 | -#ifndef ENOTSUP |
233 | -#define ENOTSUP ENOSYS |
234 | -#endif |
235 | - |
236 | -#endif |
237 | |
238 | === removed file 'src/core/external/kdewin32/grp.c' |
239 | --- src/core/external/kdewin32/grp.c 2010-11-28 04:24:13 +0000 |
240 | +++ src/core/external/kdewin32/grp.c 1970-01-01 00:00:00 +0000 |
241 | @@ -1,48 +0,0 @@ |
242 | -/* This file is part of the KDE project |
243 | - Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl> |
244 | - |
245 | - This program is free software; you can redistribute it and/or |
246 | - modify it under the terms of the GNU Library General Public |
247 | - License as published by the Free Software Foundation; either |
248 | - version 2 of the License, or (at your option) any later version. |
249 | - |
250 | - This program is distributed in the hope that it will be useful, |
251 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
252 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
253 | - Library General Public License for more details. |
254 | - |
255 | - You should have received a copy of the GNU Library General Public License |
256 | - along with this program; see the file COPYING. If not, write to |
257 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
258 | - Boston, MA 02110-1301, USA. |
259 | -*/ |
260 | - |
261 | -#include "kdewin32/grp.h" |
262 | -#include <windows.h> |
263 | - |
264 | - |
265 | -/* these functions always fail. for win32 */ |
266 | - |
267 | -struct group *getgrnam (const char *name) |
268 | -{ |
269 | - return 0; |
270 | -} |
271 | - |
272 | -struct group *getgrgid (gid_t gid) |
273 | -{ |
274 | - return 0; |
275 | -} |
276 | - |
277 | -struct group *getgrent(void) |
278 | -{ |
279 | - return 0; |
280 | -} |
281 | - |
282 | -void setgrent(void) |
283 | -{ |
284 | -} |
285 | - |
286 | -void endgrent(void) |
287 | -{ |
288 | -} |
289 | - |
290 | |
291 | === removed file 'src/core/external/kdewin32/grp.h' |
292 | --- src/core/external/kdewin32/grp.h 2010-11-28 04:24:13 +0000 |
293 | +++ src/core/external/kdewin32/grp.h 1970-01-01 00:00:00 +0000 |
294 | @@ -1,47 +0,0 @@ |
295 | -/* This file is part of the KDE project |
296 | - Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl> |
297 | - |
298 | - This program is free software; you can redistribute it and/or |
299 | - modify it under the terms of the GNU Library General Public |
300 | - License as published by the Free Software Foundation; either |
301 | - version 2 of the License, or (at your option) any later version. |
302 | - |
303 | - This program is distributed in the hope that it will be useful, |
304 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
305 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
306 | - Library General Public License for more details. |
307 | - |
308 | - You should have received a copy of the GNU Library General Public License |
309 | - along with this program; see the file COPYING. If not, write to |
310 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
311 | - Boston, MA 02110-1301, USA. |
312 | -*/ |
313 | - |
314 | -#ifndef GRP_H_ |
315 | -#define GRP_H_ |
316 | - |
317 | -#include "kdewin32/sys/types.h" |
318 | - |
319 | -#ifdef __cplusplus |
320 | -extern "C" { |
321 | -#endif |
322 | - |
323 | -struct group { |
324 | - char *gr_name; /* group name */ |
325 | - char *gr_passwd; /* group password */ |
326 | - gid_t gr_gid; /* group id */ |
327 | - char **gr_mem; /* group members */ |
328 | -}; |
329 | - |
330 | -struct group *getgrnam (const char *name); |
331 | -struct group *getgrgid (gid_t gid); |
332 | -struct group *getgrent(void); |
333 | -void setgrent(void); |
334 | -void endgrent(void); |
335 | - |
336 | -#ifdef __cplusplus |
337 | -} |
338 | -#endif |
339 | - |
340 | -#endif /* GRP_H_ */ |
341 | - |
342 | |
343 | === removed file 'src/core/external/kdewin32/pwd.c' |
344 | --- src/core/external/kdewin32/pwd.c 2013-06-05 05:59:53 +0000 |
345 | +++ src/core/external/kdewin32/pwd.c 1970-01-01 00:00:00 +0000 |
346 | @@ -1,62 +0,0 @@ |
347 | -/* This file is part of the KDE project |
348 | - Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl> |
349 | - |
350 | - This program is free software; you can redistribute it and/or |
351 | - modify it under the terms of the GNU Library General Public |
352 | - License as published by the Free Software Foundation; either |
353 | - version 2 of the License, or (at your option) any later version. |
354 | - |
355 | - This program is distributed in the hope that it will be useful, |
356 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
357 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
358 | - Library General Public License for more details. |
359 | - |
360 | - You should have received a copy of the GNU Library General Public License |
361 | - along with this program; see the file COPYING. If not, write to |
362 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
363 | - Boston, MA 02110-1301, USA. |
364 | -*/ |
365 | - |
366 | -#include <windows.h> |
367 | - |
368 | -#ifdef _MSC_BUILD |
369 | -#include <stdlib.h> |
370 | -#include "kdewin32/pwd.h" |
371 | -#include <stdio.h> |
372 | -#include <errno.h> |
373 | -#else |
374 | -#include "kdewin32/stdlib.h" |
375 | -#include "kdewin32/pwd.h" |
376 | -#include "kdewin32/stdio.h" |
377 | -#include "kdewin32/errno.h" |
378 | -#endif |
379 | - |
380 | -/* these functions always fail for win32 */ |
381 | - |
382 | -struct passwd * getpwnam (const char *name) |
383 | -{ |
384 | - return 0; |
385 | -} |
386 | - |
387 | - |
388 | -struct passwd * getpwuid (uid_t uid) |
389 | -{ |
390 | - return 0; |
391 | -} |
392 | - |
393 | - |
394 | -void setpwent (void) |
395 | -{ |
396 | -} |
397 | - |
398 | - |
399 | -struct passwd *getpwent() |
400 | -{ |
401 | - return 0; |
402 | -} |
403 | - |
404 | - |
405 | -void endpwent() |
406 | -{ |
407 | -} |
408 | - |
409 | |
410 | === removed file 'src/core/external/kdewin32/pwd.h' |
411 | --- src/core/external/kdewin32/pwd.h 2010-11-28 04:24:13 +0000 |
412 | +++ src/core/external/kdewin32/pwd.h 1970-01-01 00:00:00 +0000 |
413 | @@ -1,71 +0,0 @@ |
414 | -/* This file is part of the KDE project |
415 | - * Copyright (c) 1989 The Regents of the University of California. |
416 | - * All rights reserved. |
417 | - * |
418 | - * Redistribution and use in source and binary forms, with or without |
419 | - * modification, are permitted provided that the following conditions |
420 | - * are met: |
421 | - * 1. Redistributions of source code must retain the above copyright |
422 | - * notice, this list of conditions and the following disclaimer. |
423 | - * 2. Redistributions in binary form must reproduce the above copyright |
424 | - * notice, this list of conditions and the following disclaimer in the |
425 | - * documentation and/or other materials provided with the distribution. |
426 | - * 3. All advertising materials mentioning features or use of this software |
427 | - * must display the following acknowledgment: |
428 | - * This product includes software developed by the University of |
429 | - * California, Berkeley and its contributors. |
430 | - * 4. Neither the name of the University nor the names of its contributors |
431 | - * may be used to endorse or promote products derived from this software |
432 | - * without specific prior written permission. |
433 | - * |
434 | - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
435 | - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
436 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
437 | - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
438 | - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
439 | - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
440 | - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
441 | - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
442 | - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
443 | - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
444 | - * SUCH DAMAGE. |
445 | - * |
446 | - * @(#)pwd.h 5.13 (Berkeley) 5/28/91 |
447 | - */ |
448 | - |
449 | -#ifndef _KDEWIN_PWD_H_ |
450 | -#define _KDEWIN_PWD_H_ |
451 | - |
452 | -#include "kdewin32/sys/types.h" |
453 | - |
454 | -#ifdef __cplusplus |
455 | -extern "C" { |
456 | -#endif |
457 | - |
458 | - |
459 | -struct passwd { |
460 | - char *pw_name; /* user name */ |
461 | - char *pw_passwd; /* encrypted password */ |
462 | - int pw_uid; /* user uid */ |
463 | - int pw_gid; /* user gid */ |
464 | - char *pw_comment; /* comment */ |
465 | - char *pw_gecos; /* Honeywell login info */ |
466 | - char *pw_dir; /* home directory */ |
467 | - char *pw_shell; /* default shell */ |
468 | -}; |
469 | - |
470 | -struct passwd *getpwuid (uid_t); |
471 | -struct passwd *getpwnam (const char *); |
472 | -int getpwnam_r (const char *, struct passwd *, |
473 | - char *, size_t , struct passwd **); |
474 | -int getpwuid_r (uid_t, struct passwd *, char *, |
475 | - size_t, struct passwd **); |
476 | - |
477 | -struct passwd *getpwent (void); |
478 | -void setpwent (void); |
479 | -void endpwent (void); |
480 | - |
481 | -#ifdef __cplusplus |
482 | -} |
483 | -#endif |
484 | -#endif /* _PWD_H_ */ |
485 | |
486 | === removed file 'src/core/external/kdewin32/stdio.h' |
487 | --- src/core/external/kdewin32/stdio.h 2010-11-28 04:24:13 +0000 |
488 | +++ src/core/external/kdewin32/stdio.h 1970-01-01 00:00:00 +0000 |
489 | @@ -1,37 +0,0 @@ |
490 | -/* |
491 | - This file is part of the KDE libraries |
492 | - Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl> |
493 | - Copyright (C) 2005 Ralf Habacker <ralf.habacker@freenet.de> |
494 | - |
495 | - This library is free software; you can redistribute it and/or |
496 | - modify it under the terms of the GNU Library General Public |
497 | - License version 2 as published by the Free Software Foundation. |
498 | - |
499 | - This library is distributed in the hope that it will be useful, |
500 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
501 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
502 | - Library General Public License for more details. |
503 | - |
504 | - You should have received a copy of the GNU Library General Public License |
505 | - along with this library; see the file COPYING.LIB. If not, write to |
506 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
507 | - Boston, MA 02110-1301, USA. |
508 | -*/ |
509 | - |
510 | -/* |
511 | - * Definitions for common types, variables, and functions. |
512 | - */ |
513 | - |
514 | -#ifndef KDE_STDIO_H |
515 | -#define KDE_STDIO_H |
516 | - |
517 | -// stdio.h includes sys/types.h in an extern "C" context, which fails for c++ definitions |
518 | -#include "kdewin32/sys/types.h" |
519 | -#include <../include/stdio.h> |
520 | - |
521 | -#define snprintf _snprintf |
522 | -#define vsnprintf _vsnprintf |
523 | -#define popen _popen |
524 | -#define pclose _pclose |
525 | - |
526 | -#endif /* KDE_STDIO_H_ */ |
527 | |
528 | === removed file 'src/core/external/kdewin32/stdlib.h' |
529 | --- src/core/external/kdewin32/stdlib.h 2010-11-28 04:24:13 +0000 |
530 | +++ src/core/external/kdewin32/stdlib.h 1970-01-01 00:00:00 +0000 |
531 | @@ -1,71 +0,0 @@ |
532 | -/* |
533 | - This file is part of the KDE libraries |
534 | - Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl> |
535 | - |
536 | - This library is free software; you can redistribute it and/or |
537 | - modify it under the terms of the GNU Library General Public |
538 | - License version 2 as published by the Free Software Foundation. |
539 | - |
540 | - This library is distributed in the hope that it will be useful, |
541 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
542 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
543 | - Library General Public License for more details. |
544 | - |
545 | - You should have received a copy of the GNU Library General Public License |
546 | - along with this library; see the file COPYING.LIB. If not, write to |
547 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
548 | - Boston, MA 02110-1301, USA. |
549 | -*/ |
550 | - |
551 | -/* |
552 | - * Definitions for common types, variables, and functions. |
553 | - */ |
554 | - |
555 | -#ifndef KDE_STDLIB_H |
556 | -#define KDE_STDLIB_H |
557 | - |
558 | -#include "kdewin32/sys/types.h" |
559 | -#include <../include/stdlib.h> |
560 | - |
561 | -#ifdef __cplusplus |
562 | -extern "C" { |
563 | -#endif |
564 | -/* |
565 | -#define __need_size_t |
566 | -#define __need_wchar_t |
567 | -#include <stddef.h> |
568 | - |
569 | -#ifndef _STDLIB_H_ |
570 | -#endif |
571 | -#define _STDLIB_H_ |
572 | - |
573 | -#ifndef NULL |
574 | -#define NULL 0 |
575 | -#endif |
576 | - |
577 | -#define EXIT_FAILURE 1 |
578 | -#define EXIT_SUCCESS 0 |
579 | -*/ |
580 | - |
581 | -long int random(); |
582 | - |
583 | -void srandom(unsigned int seed); |
584 | - |
585 | -double drand48(void); |
586 | - |
587 | -int rand_r(unsigned *seed); |
588 | - |
589 | -char* realpath(const char *path,char *resolved_path); |
590 | - |
591 | -/* from kdecore/fakes.c */ |
592 | - |
593 | -int setenv(const char *__string, const char *__value, int __overwrite); |
594 | - |
595 | -void unsetenv(const char *__string); |
596 | - |
597 | - |
598 | -#ifdef __cplusplus |
599 | -} |
600 | -#endif |
601 | - |
602 | -#endif /* KDE_STDLIB_H_ */ |
603 | |
604 | === removed directory 'src/core/external/kdewin32/sys' |
605 | === removed file 'src/core/external/kdewin32/sys/stat.h' |
606 | --- src/core/external/kdewin32/sys/stat.h 2010-11-28 04:24:13 +0000 |
607 | +++ src/core/external/kdewin32/sys/stat.h 1970-01-01 00:00:00 +0000 |
608 | @@ -1,50 +0,0 @@ |
609 | -/* |
610 | - * stat.h |
611 | - * This file has no copyright assigned and is placed in the Public Domain. |
612 | - * This file is a part of the mingw-runtime package. |
613 | - * No warranty is given; refer to the file DISCLAIMER within the package. |
614 | - * |
615 | - * Symbolic constants for opening and creating files, also stat, fstat and |
616 | - * chmod functions. |
617 | - * |
618 | - */ |
619 | -#ifndef KDEWIN_SYS_STAT_H |
620 | -#define KDEWIN_SYS_STAT_H |
621 | - |
622 | -#include "kdewin32/sys/types.h" |
623 | -#include <../include/sys/stat.h> |
624 | - |
625 | -#ifdef __cplusplus |
626 | -extern "C" { |
627 | -#endif |
628 | - |
629 | -#define _S_IFLNK 0xF000 /* Pretend */ |
630 | -#define S_IFLNK _S_IFLNK /* kio/kio/kzip.cpp */ |
631 | -#define _S_IFSOCK 0140000 /* socket */ |
632 | - |
633 | -#define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) /* Should always be zero.*/ |
634 | -#define S_ISSOCK(m) (((m)&_S_IFMT) == _S_IFSOCK) |
635 | - |
636 | -#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) |
637 | -#define S_IRGRP 0000040 /* read permission, group */ |
638 | -#define S_IWGRP 0000020 /* write permission, grougroup */ |
639 | -#define S_IXGRP 0000010 /* execute/search permission, group */ |
640 | -#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) |
641 | -#define S_IROTH 0000004 /* read permission, other */ |
642 | -#define S_IWOTH 0000002 /* write permission, other */ |
643 | -#define S_IXOTH 0000001 /* execute/search permission, other */ |
644 | - |
645 | -#define S_ISUID 0004000 /* set user id on execution */ |
646 | -#define S_ISGID 0002000 /* set group id on execution */ |
647 | -#define S_ISVTX 0001000 /* save swapped text even after use */ |
648 | - |
649 | -#define S_IFSOCK _S_IFSOCK |
650 | - |
651 | -int lstat( const char *__path, struct stat *__buf); |
652 | -int fchmod(int __fd, mode_t __mode); |
653 | - |
654 | -#ifdef __cplusplus |
655 | -} |
656 | -#endif |
657 | - |
658 | -#endif // KDEWIN_SYS_STAT_H |
659 | |
660 | === removed file 'src/core/external/kdewin32/sys/types.h' |
661 | --- src/core/external/kdewin32/sys/types.h 2013-06-05 05:59:53 +0000 |
662 | +++ src/core/external/kdewin32/sys/types.h 1970-01-01 00:00:00 +0000 |
663 | @@ -1,48 +0,0 @@ |
664 | -/* This file is part of the KDE project |
665 | - Copyright (C) 2005 Ralf Habacker <ralf.habacker@freenet.de> |
666 | - |
667 | - This program is free software; you can redistribute it and/or |
668 | - modify it under the terms of the GNU Library General Public |
669 | - License as published by the Free Software Foundation; either |
670 | - version 2 of the License, or (at your option) any later version. |
671 | - |
672 | - This program is distributed in the hope that it will be useful, |
673 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
674 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 | - Library General Public License for more details. |
676 | - |
677 | - You should have received a copy of the GNU Library General Public License |
678 | - along with this program; see the file COPYING. If not, write to |
679 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
680 | - Boston, MA 02110-1301, USA. |
681 | -*/ |
682 | - |
683 | -#ifndef KDEWIN_SYS_TYPES_H |
684 | -#define KDEWIN_SYS_TYPES_H |
685 | - |
686 | -#ifdef _MSC_BUILD |
687 | - |
688 | -typedef unsigned int uid_t; |
689 | -typedef unsigned int gid_t; |
690 | -typedef unsigned int pid_t; |
691 | -typedef unsigned short mode_t; |
692 | -typedef int caddr_t; |
693 | -typedef unsigned int nlink_t; |
694 | - |
695 | -#else |
696 | - |
697 | -#include <../include/sys/types.h> |
698 | - |
699 | -typedef unsigned int uid_t; |
700 | -typedef unsigned int gid_t; |
701 | -typedef int caddr_t; |
702 | - |
703 | -typedef unsigned int nlink_t; |
704 | - |
705 | -#endif |
706 | - |
707 | -// uint32 |
708 | -#include <stdint.h> |
709 | - |
710 | -#endif // KDEWIN_SYS_TYPES_H |
711 | - |
712 | |
713 | === removed file 'src/core/external/kdewin32/unistd.c' |
714 | --- src/core/external/kdewin32/unistd.c 2013-11-12 18:24:13 +0000 |
715 | +++ src/core/external/kdewin32/unistd.c 1970-01-01 00:00:00 +0000 |
716 | @@ -1,48 +0,0 @@ |
717 | -/* This file is part of the KDE project |
718 | - Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl> |
719 | - |
720 | - This program is free software; you can redistribute it and/or |
721 | - modify it under the terms of the GNU Library General Public |
722 | - License as published by the Free Software Foundation; either |
723 | - version 2 of the License, or (at your option) any later version. |
724 | - |
725 | - This program is distributed in the hope that it will be useful, |
726 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
727 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
728 | - Library General Public License for more details. |
729 | - |
730 | - You should have received a copy of the GNU Library General Public License |
731 | - along with this program; see the file COPYING. If not, write to |
732 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
733 | - Boston, MA 02110-1301, USA. |
734 | -*/ |
735 | - |
736 | -// Note: I removed most of the code from the original file, I just keep enough |
737 | -// to be able to compile kfilter, needed by Stellarium. |
738 | - |
739 | -#include "kdewin32/unistd.h" |
740 | - |
741 | -/* Get the real user ID of the calling process. */ |
742 | -uid_t getuid() |
743 | -{ |
744 | - return -2; // keep in sync with Qt! |
745 | -} |
746 | - |
747 | -/* Get the effective user ID of the calling process. */ |
748 | -uid_t geteuid (void) |
749 | -{ |
750 | - return -2; // keep in sync with Qt! |
751 | -} |
752 | - |
753 | -/* Get the real group ID of the calling process. */ |
754 | -gid_t getgid (void) |
755 | -{ |
756 | - return -2; // keep in sync with Qt! |
757 | -} |
758 | - |
759 | -/* Get the effective group ID of the calling process. */ |
760 | -gid_t getegid (void) |
761 | -{ |
762 | - return -2; // keep in sync with Qt! |
763 | -} |
764 | - |
765 | |
766 | === removed file 'src/core/external/kdewin32/unistd.h' |
767 | --- src/core/external/kdewin32/unistd.h 2013-11-12 18:24:13 +0000 |
768 | +++ src/core/external/kdewin32/unistd.h 1970-01-01 00:00:00 +0000 |
769 | @@ -1,45 +0,0 @@ |
770 | -/* This file is part of the KDE project |
771 | - Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl> |
772 | - |
773 | - This program is free software; you can redistribute it and/or |
774 | - modify it under the terms of the GNU Library General Public |
775 | - License as published by the Free Software Foundation; either |
776 | - version 2 of the License, or (at your option) any later version. |
777 | - |
778 | - This program is distributed in the hope that it will be useful, |
779 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
780 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
781 | - Library General Public License for more details. |
782 | - |
783 | - You should have received a copy of the GNU Library General Public License |
784 | - along with this program; see the file COPYING. If not, write to |
785 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
786 | - Boston, MA 02110-1301, USA. |
787 | -*/ |
788 | - |
789 | -#ifndef _KDEWIN_UNISTD_H |
790 | -#define _KDEWIN_UNISTD_H |
791 | - |
792 | -#include "kdewin32/sys/types.h" |
793 | - |
794 | -#ifdef __cplusplus |
795 | -extern "C" { |
796 | -#endif |
797 | - |
798 | -/* Get the real user ID of the calling process. */ |
799 | -uid_t getuid (void); |
800 | - |
801 | -/* Get the effective user ID of the calling process. */ |
802 | -uid_t geteuid (void); |
803 | - |
804 | -/* Get the real group ID of the calling process. */ |
805 | -gid_t getgid (void); |
806 | - |
807 | -/* Get the effective group ID of the calling process. */ |
808 | -gid_t getegid (void); |
809 | - |
810 | -#ifdef __cplusplus |
811 | -} |
812 | -#endif |
813 | - |
814 | -#endif /* _KDEWIN_UNISTD_H */ |
815 | |
816 | === removed directory 'src/core/external/kfilter' |
817 | === removed file 'src/core/external/kfilter/karchive.cpp' |
818 | --- src/core/external/kfilter/karchive.cpp 2013-06-05 05:59:53 +0000 |
819 | +++ src/core/external/kfilter/karchive.cpp 1970-01-01 00:00:00 +0000 |
820 | @@ -1,828 +0,0 @@ |
821 | -/* This file is part of the KDE libraries |
822 | - Copyright (C) 2000-2005 David Faure <faure@kde.org> |
823 | - Copyright (C) 2003 Leo Savernik <l.savernik@aon.at> |
824 | - |
825 | - Moved from ktar.cpp by Roberto Teixeira <maragato@kde.org> |
826 | - |
827 | - This library is free software; you can redistribute it and/or |
828 | - modify it under the terms of the GNU Library General Public |
829 | - License version 2 as published by the Free Software Foundation. |
830 | - |
831 | - This library is distributed in the hope that it will be useful, |
832 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
833 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
834 | - Library General Public License for more details. |
835 | - |
836 | - You should have received a copy of the GNU Library General Public License |
837 | - along with this library; see the file COPYING.LIB. If not, write to |
838 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
839 | - Boston, MA 02110-1301, USA. |
840 | -*/ |
841 | - |
842 | -#include "karchive.h" |
843 | -#include "klimitediodevice.h" |
844 | - |
845 | -#include <QStack> |
846 | -#include <QtCore/QMap> |
847 | -#include <QtCore/QDir> |
848 | -#include <QtCore/QFile> |
849 | -#include <QDebug> |
850 | - |
851 | -#include <stdio.h> |
852 | -#include <stdlib.h> |
853 | -#include <time.h> |
854 | -#ifdef Q_OS_UNIX |
855 | -#include <unistd.h> |
856 | -#endif |
857 | -#include <errno.h> |
858 | -#include <assert.h> |
859 | -#include <sys/types.h> |
860 | -#include <sys/stat.h> |
861 | -#ifdef Q_OS_UNIX |
862 | -#include <limits.h> // PATH_MAX |
863 | -#endif |
864 | - |
865 | -#ifndef Q_OS_WIN |
866 | -#include <grp.h> |
867 | -#include <pwd.h> |
868 | -#else |
869 | -#include "kdewin32/grp.h" |
870 | -#include "kdewin32/pwd.h" |
871 | -#include "kdewin32/unistd.h" |
872 | -#endif |
873 | - |
874 | -class KArchivePrivate |
875 | -{ |
876 | -public: |
877 | - KArchivePrivate() |
878 | - : rootDir( 0 ), |
879 | -// saveFile( 0 ), |
880 | - dev ( 0 ), |
881 | - fileName(), |
882 | - mode( QIODevice::NotOpen ), |
883 | - deviceOwned( false ) |
884 | - {} |
885 | - ~KArchivePrivate() |
886 | - { |
887 | -// delete saveFile; |
888 | - delete rootDir; |
889 | - } |
890 | - void abortWriting(); |
891 | - |
892 | - KArchiveDirectory* rootDir; |
893 | -// KSaveFile* saveFile; |
894 | - QIODevice * dev; |
895 | - QString fileName; |
896 | - QIODevice::OpenMode mode; |
897 | - bool deviceOwned; // if true, we (KArchive) own dev and must delete it |
898 | -}; |
899 | - |
900 | - |
901 | -//////////////////////////////////////////////////////////////////////// |
902 | -/////////////////////////// KArchive /////////////////////////////////// |
903 | -//////////////////////////////////////////////////////////////////////// |
904 | - |
905 | -KArchive::KArchive( const QString& fileName ) |
906 | - : d(new KArchivePrivate) |
907 | -{ |
908 | - Q_ASSERT( !fileName.isEmpty() ); |
909 | - d->fileName = fileName; |
910 | - // This constructor leaves the device set to 0. |
911 | - // This is for the use of KSaveFile, see open(). |
912 | -} |
913 | - |
914 | -KArchive::KArchive( QIODevice * dev ) |
915 | - : d(new KArchivePrivate) |
916 | -{ |
917 | - d->dev = dev; |
918 | -} |
919 | - |
920 | -KArchive::~KArchive() |
921 | -{ |
922 | - if ( isOpen() ) |
923 | - close(); // WARNING: won't call the virtual method close in the derived class!!! |
924 | - |
925 | - delete d; |
926 | -} |
927 | - |
928 | -bool KArchive::open( QIODevice::OpenMode mode ) |
929 | -{ |
930 | - Q_ASSERT( mode != QIODevice::NotOpen ); |
931 | - |
932 | - if ( isOpen() ) |
933 | - close(); |
934 | - |
935 | - if ( !d->fileName.isEmpty() ) |
936 | - { |
937 | - Q_ASSERT( !d->dev ); |
938 | - if ( !createDevice( mode ) ) |
939 | - return false; |
940 | - } |
941 | - |
942 | - Q_ASSERT( d->dev ); |
943 | - |
944 | - if ( !d->dev->isOpen() && !d->dev->open( mode ) ) |
945 | - return false; |
946 | - |
947 | - d->mode = mode; |
948 | - |
949 | - Q_ASSERT( !d->rootDir ); |
950 | - d->rootDir = 0; |
951 | - |
952 | - return openArchive( mode ); |
953 | -} |
954 | - |
955 | -bool KArchive::createDevice( QIODevice::OpenMode mode ) |
956 | -{ |
957 | - switch( mode ) { |
958 | - case QIODevice::WriteOnly: |
959 | -// if ( !d->fileName.isEmpty() ) { |
960 | -// // The use of KSaveFile can't be done in the ctor (no mode known yet) |
961 | -// //qDebug() << "Writing to a file using KSaveFile"; |
962 | -// d->saveFile = new KSaveFile( d->fileName ); |
963 | -// if ( !d->saveFile->open() ) { |
964 | -// qWarning() << "KSaveFile creation for " << d->fileName << " failed, " << d->saveFile->errorString(); |
965 | -// delete d->saveFile; |
966 | -// d->saveFile = 0; |
967 | -// return false; |
968 | -// } |
969 | -// d->dev = d->saveFile; |
970 | -// Q_ASSERT( d->dev ); |
971 | -// } |
972 | - Q_ASSERT(0); // Unsupported for Stellarium |
973 | - break; |
974 | - case QIODevice::ReadOnly: |
975 | - case QIODevice::ReadWrite: |
976 | - // ReadWrite mode still uses QFile for now; we'd need to copy to the tempfile, in fact. |
977 | - if ( !d->fileName.isEmpty() ) { |
978 | - d->dev = new QFile( d->fileName ); |
979 | - d->deviceOwned = true; |
980 | - } |
981 | - break; // continued below |
982 | - default: |
983 | - qWarning() << "Unsupported mode " << d->mode; |
984 | - return false; |
985 | - } |
986 | - return true; |
987 | -} |
988 | - |
989 | -bool KArchive::close() |
990 | -{ |
991 | - if ( !isOpen() ) |
992 | - return false; // already closed (return false or true? arguable...) |
993 | - |
994 | - // moved by holger to allow kzip to write the zip central dir |
995 | - // to the file in closeArchive() |
996 | - // DF: added d->dev so that we skip closeArchive if saving aborted. |
997 | - bool closeSucceeded = true; |
998 | - if ( d->dev ) { |
999 | - closeSucceeded = closeArchive(); |
1000 | - if ( d->mode == QIODevice::WriteOnly && !closeSucceeded ) |
1001 | - d->abortWriting(); |
1002 | - } |
1003 | - |
1004 | - if ( d->dev ) |
1005 | - d->dev->close(); |
1006 | - |
1007 | - if ( d->deviceOwned ) { |
1008 | - delete d->dev; // we created it ourselves in open() |
1009 | - } |
1010 | -// Disabled for Stellarium |
1011 | -// if ( d->saveFile ) { |
1012 | -// closeSucceeded = d->saveFile->finalize(); |
1013 | -// delete d->saveFile; |
1014 | -// d->saveFile = 0; |
1015 | -// } |
1016 | - |
1017 | - delete d->rootDir; |
1018 | - d->rootDir = 0; |
1019 | - d->mode = QIODevice::NotOpen; |
1020 | - d->dev = 0; |
1021 | - return closeSucceeded; |
1022 | -} |
1023 | - |
1024 | -const KArchiveDirectory* KArchive::directory() const |
1025 | -{ |
1026 | - // rootDir isn't const so that parsing-on-demand is possible |
1027 | - return const_cast<KArchive *>(this)->rootDir(); |
1028 | -} |
1029 | - |
1030 | - |
1031 | -bool KArchive::addLocalFile(const QString&, const QString&) |
1032 | -{ |
1033 | - Q_ASSERT(0); // Disabled for Stellarium |
1034 | - return true; |
1035 | -// QFileInfo fileInfo( fileName ); |
1036 | -// if ( !fileInfo.isFile() && !fileInfo.isSymLink() ) |
1037 | -// { |
1038 | -// qWarning() << fileName << "doesn't exist or is not a regular file."; |
1039 | -// return false; |
1040 | -// } |
1041 | -// |
1042 | -// KDE_struct_stat fi; |
1043 | -// if (KDE_lstat(QFile::encodeName(fileName),&fi) == -1) { |
1044 | -// qWarning() << "stat'ing" << fileName |
1045 | -// << "failed:" << strerror(errno); |
1046 | -// return false; |
1047 | -// } |
1048 | -// |
1049 | -// if (fileInfo.isSymLink()) { |
1050 | -// QString symLinkTarget; |
1051 | -// // Do NOT use fileInfo.readLink() for unix symlinks! |
1052 | -// // It returns the -full- path to the target, while we want the target string "as is". |
1053 | -// #if defined(Q_OS_UNIX) && !defined(Q_OS_OS2EMX) |
1054 | -// QByteArray s; |
1055 | -// s.resize(PATH_MAX+1); |
1056 | -// int len = readlink( QFile::encodeName(fileName).data(), s.data(), PATH_MAX ); |
1057 | -// if ( len >= 0 ) { |
1058 | -// s[len] = '\0'; |
1059 | -// symLinkTarget = QFile::decodeName(s); |
1060 | -// } |
1061 | -// #endif |
1062 | -// if (symLinkTarget.isEmpty()) // Mac or Windows |
1063 | -// symLinkTarget = fileInfo.symLinkTarget(); |
1064 | -// return writeSymLink(destName, symLinkTarget, fileInfo.owner(), |
1065 | -// fileInfo.group(), fi.st_mode, fi.st_atime, fi.st_mtime, |
1066 | -// fi.st_ctime); |
1067 | -// }/*end if*/ |
1068 | -// |
1069 | -// qint64 size = fileInfo.size(); |
1070 | -// |
1071 | -// // the file must be opened before prepareWriting is called, otherwise |
1072 | -// // if the opening fails, no content will follow the already written |
1073 | -// // header and the tar file is effectively f*cked up |
1074 | -// QFile file( fileName ); |
1075 | -// if ( !file.open( QIODevice::ReadOnly ) ) |
1076 | -// { |
1077 | -// qWarning() << "couldn't open file " << fileName; |
1078 | -// return false; |
1079 | -// } |
1080 | -// |
1081 | -// if ( !prepareWriting( destName, fileInfo.owner(), fileInfo.group(), size, |
1082 | -// fi.st_mode, fi.st_atime, fi.st_mtime, fi.st_ctime ) ) |
1083 | -// { |
1084 | -// qWarning() << " prepareWriting" << destName << "failed"; |
1085 | -// return false; |
1086 | -// } |
1087 | -// |
1088 | -// // Read and write data in chunks to minimize memory usage |
1089 | -// QByteArray array; |
1090 | -// array.resize(8*1024); |
1091 | -// qint64 n; |
1092 | -// qint64 total = 0; |
1093 | -// while ( ( n = file.read( array.data(), array.size() ) ) > 0 ) |
1094 | -// { |
1095 | -// if ( !writeData( array.data(), n ) ) |
1096 | -// { |
1097 | -// qWarning() << "writeData failed"; |
1098 | -// return false; |
1099 | -// } |
1100 | -// total += n; |
1101 | -// } |
1102 | -// Q_ASSERT( total == size ); |
1103 | -// |
1104 | -// if ( !finishWriting( size ) ) |
1105 | -// { |
1106 | -// qWarning() << "finishWriting failed"; |
1107 | -// return false; |
1108 | -// } |
1109 | -// return true; |
1110 | -} |
1111 | - |
1112 | -bool KArchive::addLocalDirectory( const QString& path, const QString& destName ) |
1113 | -{ |
1114 | - QDir dir( path ); |
1115 | - if ( !dir.exists() ) |
1116 | - return false; |
1117 | - dir.setFilter(dir.filter() | QDir::Hidden); |
1118 | - const QStringList files = dir.entryList(); |
1119 | - for ( QStringList::ConstIterator it = files.begin(); it != files.end(); ++it ) |
1120 | - { |
1121 | - if ( *it != "." && *it != ".." ) |
1122 | - { |
1123 | - QString fileName = path + '/' + *it; |
1124 | -// qDebug() << "storing " << fileName; |
1125 | - QString dest = destName.isEmpty() ? *it : (destName + '/' + *it); |
1126 | - QFileInfo fileInfo( fileName ); |
1127 | - |
1128 | - if ( fileInfo.isFile() || fileInfo.isSymLink() ) |
1129 | - addLocalFile( fileName, dest ); |
1130 | - else if ( fileInfo.isDir() ) |
1131 | - addLocalDirectory( fileName, dest ); |
1132 | - // We omit sockets |
1133 | - } |
1134 | - } |
1135 | - return true; |
1136 | -} |
1137 | - |
1138 | -bool KArchive::writeFile( const QString& name, const QString& user, |
1139 | - const QString& group, const char* data, qint64 size, |
1140 | - mode_t perm, time_t atime, time_t mtime, time_t ctime ) |
1141 | -{ |
1142 | - if ( !prepareWriting( name, user, group, size, perm, atime, mtime, ctime ) ) |
1143 | - { |
1144 | - qWarning() << "prepareWriting failed"; |
1145 | - return false; |
1146 | - } |
1147 | - |
1148 | - // Write data |
1149 | - // Note: if data is 0L, don't call write, it would terminate the KFilterDev |
1150 | - if ( data && size && !writeData( data, size ) ) |
1151 | - { |
1152 | - qWarning() << "writeData failed"; |
1153 | - return false; |
1154 | - } |
1155 | - |
1156 | - if ( !finishWriting( size ) ) |
1157 | - { |
1158 | - qWarning() << "finishWriting failed"; |
1159 | - return false; |
1160 | - } |
1161 | - return true; |
1162 | -} |
1163 | - |
1164 | -bool KArchive::writeData( const char* data, qint64 size ) |
1165 | -{ |
1166 | - bool ok = device()->write( data, size ) == size; |
1167 | - if ( !ok ) |
1168 | - d->abortWriting(); |
1169 | - return ok; |
1170 | -} |
1171 | - |
1172 | -// The writeDir -> doWriteDir pattern allows to avoid propagating the default |
1173 | -// values into all virtual methods of subclasses, and it allows more extensibility: |
1174 | -// if a new argument is needed, we can add a writeDir overload which stores the |
1175 | -// additional argument in the d pointer, and doWriteDir reimplementations can fetch |
1176 | -// it from there. |
1177 | - |
1178 | -bool KArchive::writeDir( const QString& name, const QString& user, const QString& group, |
1179 | - mode_t perm, time_t atime, |
1180 | - time_t mtime, time_t ctime ) |
1181 | -{ |
1182 | - return doWriteDir( name, user, group, perm, atime, mtime, ctime ); |
1183 | -} |
1184 | - |
1185 | -bool KArchive::writeSymLink(const QString &name, const QString &target, |
1186 | - const QString &user, const QString &group, |
1187 | - mode_t perm, time_t atime, |
1188 | - time_t mtime, time_t ctime ) |
1189 | -{ |
1190 | - return doWriteSymLink( name, target, user, group, perm, atime, mtime, ctime ); |
1191 | -} |
1192 | - |
1193 | - |
1194 | -bool KArchive::prepareWriting( const QString& name, const QString& user, |
1195 | - const QString& group, qint64 size, |
1196 | - mode_t perm, time_t atime, |
1197 | - time_t mtime, time_t ctime ) |
1198 | -{ |
1199 | - bool ok = doPrepareWriting( name, user, group, size, perm, atime, mtime, ctime ); |
1200 | - if ( !ok ) |
1201 | - d->abortWriting(); |
1202 | - return ok; |
1203 | -} |
1204 | - |
1205 | -bool KArchive::finishWriting( qint64 size ) |
1206 | -{ |
1207 | - return doFinishWriting( size ); |
1208 | -} |
1209 | - |
1210 | -KArchiveDirectory * KArchive::rootDir() |
1211 | -{ |
1212 | - if ( !d->rootDir ) |
1213 | - { |
1214 | - //qDebug() << "Making root dir "; |
1215 | - struct passwd* pw = getpwuid( getuid() ); |
1216 | - struct group* grp = getgrgid( getgid() ); |
1217 | - QString username = pw ? QFile::decodeName(pw->pw_name) : QString::number( getuid() ); |
1218 | - QString groupname = grp ? QFile::decodeName(grp->gr_name) : QString::number( getgid() ); |
1219 | - |
1220 | - d->rootDir = new KArchiveDirectory( this, QLatin1String("/"), (int)(0777 + S_IFDIR), 0, username, groupname, QString() ); |
1221 | - } |
1222 | - return d->rootDir; |
1223 | -} |
1224 | - |
1225 | -KArchiveDirectory * KArchive::findOrCreate( const QString & path ) |
1226 | -{ |
1227 | - //qDebug() << path; |
1228 | - if ( path.isEmpty() || path == "/" || path == "." ) // root dir => found |
1229 | - { |
1230 | - //qDebug() << "returning rootdir"; |
1231 | - return rootDir(); |
1232 | - } |
1233 | - // Important note : for tar files containing absolute paths |
1234 | - // (i.e. beginning with "/"), this means the leading "/" will |
1235 | - // be removed (no KDirectory for it), which is exactly the way |
1236 | - // the "tar" program works (though it displays a warning about it) |
1237 | - // See also KArchiveDirectory::entry(). |
1238 | - |
1239 | - // Already created ? => found |
1240 | - const KArchiveEntry* ent = rootDir()->entry( path ); |
1241 | - if ( ent ) |
1242 | - { |
1243 | - if ( ent->isDirectory() ) |
1244 | - //qDebug() << "found it"; |
1245 | - return (KArchiveDirectory *) ent; |
1246 | - else |
1247 | - qWarning() << "Found" << path << "but it's not a directory"; |
1248 | - } |
1249 | - |
1250 | - // Otherwise go up and try again |
1251 | - int pos = path.lastIndexOf( '/' ); |
1252 | - KArchiveDirectory * parent; |
1253 | - QString dirname; |
1254 | - if ( pos == -1 ) // no more slash => create in root dir |
1255 | - { |
1256 | - parent = rootDir(); |
1257 | - dirname = path; |
1258 | - } |
1259 | - else |
1260 | - { |
1261 | - QString left = path.left( pos ); |
1262 | - dirname = path.mid( pos + 1 ); |
1263 | - parent = findOrCreate( left ); // recursive call... until we find an existing dir. |
1264 | - } |
1265 | - |
1266 | - //qDebug() << "found parent " << parent->name() << " adding " << dirname << " to ensure " << path; |
1267 | - // Found -> add the missing piece |
1268 | - KArchiveDirectory * e = new KArchiveDirectory( this, dirname, d->rootDir->permissions(), |
1269 | - d->rootDir->date(), d->rootDir->user(), |
1270 | - d->rootDir->group(), QString() ); |
1271 | - parent->addEntry( e ); |
1272 | - return e; // now a directory to <path> exists |
1273 | -} |
1274 | - |
1275 | -void KArchive::setDevice( QIODevice * dev ) |
1276 | -{ |
1277 | - if ( d->deviceOwned ) |
1278 | - delete d->dev; |
1279 | - d->dev = dev; |
1280 | - d->deviceOwned = false; |
1281 | -} |
1282 | - |
1283 | -void KArchive::setRootDir( KArchiveDirectory *rootDir ) |
1284 | -{ |
1285 | - Q_ASSERT( !d->rootDir ); // Call setRootDir only once during parsing please ;) |
1286 | - d->rootDir = rootDir; |
1287 | -} |
1288 | - |
1289 | -QIODevice::OpenMode KArchive::mode() const |
1290 | -{ |
1291 | - return d->mode; |
1292 | -} |
1293 | - |
1294 | -QIODevice * KArchive::device() const |
1295 | -{ |
1296 | - return d->dev; |
1297 | -} |
1298 | - |
1299 | -bool KArchive::isOpen() const |
1300 | -{ |
1301 | - return d->mode != QIODevice::NotOpen; |
1302 | -} |
1303 | - |
1304 | -QString KArchive::fileName() const |
1305 | -{ |
1306 | - return d->fileName; |
1307 | -} |
1308 | - |
1309 | -void KArchivePrivate::abortWriting() |
1310 | -{ |
1311 | -// Disabled for Stellarium |
1312 | -// if ( saveFile ) { |
1313 | -// saveFile->abort(); |
1314 | -// delete saveFile; |
1315 | -// saveFile = 0; |
1316 | -// dev = 0; |
1317 | -// } |
1318 | -} |
1319 | - |
1320 | -//////////////////////////////////////////////////////////////////////// |
1321 | -/////////////////////// KArchiveEntry ////////////////////////////////// |
1322 | -//////////////////////////////////////////////////////////////////////// |
1323 | - |
1324 | -class KArchiveEntryPrivate |
1325 | -{ |
1326 | -public: |
1327 | - KArchiveEntryPrivate( KArchive* _archive, const QString& _name, int _access, |
1328 | - int _date, const QString& _user, const QString& _group, |
1329 | - const QString& _symlink) : |
1330 | - name(_name), |
1331 | - date(_date), |
1332 | - access(_access), |
1333 | - user(_user), |
1334 | - group(_group), |
1335 | - symlink(_symlink), |
1336 | - archive(_archive) |
1337 | - {} |
1338 | - QString name; |
1339 | - int date; |
1340 | - mode_t access; |
1341 | - QString user; |
1342 | - QString group; |
1343 | - QString symlink; |
1344 | - KArchive* archive; |
1345 | -}; |
1346 | - |
1347 | -KArchiveEntry::KArchiveEntry( KArchive* t, const QString& name, int access, int date, |
1348 | - const QString& user, const QString& group, const |
1349 | - QString& symlink) : |
1350 | - d(new KArchiveEntryPrivate(t,name,access,date,user,group,symlink)) |
1351 | -{ |
1352 | -} |
1353 | - |
1354 | -KArchiveEntry::~KArchiveEntry() |
1355 | -{ |
1356 | - delete d; |
1357 | -} |
1358 | - |
1359 | -QDateTime KArchiveEntry::datetime() const |
1360 | -{ |
1361 | - QDateTime datetimeobj; |
1362 | - datetimeobj.setTime_t( d->date ); |
1363 | - return datetimeobj; |
1364 | -} |
1365 | - |
1366 | -int KArchiveEntry::date() const |
1367 | -{ |
1368 | - return d->date; |
1369 | -} |
1370 | - |
1371 | -QString KArchiveEntry::name() const |
1372 | -{ |
1373 | - return d->name; |
1374 | -} |
1375 | - |
1376 | -mode_t KArchiveEntry::permissions() const |
1377 | -{ |
1378 | - return d->access; |
1379 | -} |
1380 | - |
1381 | -QString KArchiveEntry::user() const |
1382 | -{ |
1383 | - return d->user; |
1384 | -} |
1385 | - |
1386 | -QString KArchiveEntry::group() const |
1387 | -{ |
1388 | - return d->group; |
1389 | -} |
1390 | - |
1391 | -QString KArchiveEntry::symLinkTarget() const |
1392 | -{ |
1393 | - return d->symlink; |
1394 | -} |
1395 | - |
1396 | -bool KArchiveEntry::isFile() const |
1397 | -{ |
1398 | - return false; |
1399 | -} |
1400 | - |
1401 | -bool KArchiveEntry::isDirectory() const |
1402 | -{ |
1403 | - return false; |
1404 | -} |
1405 | - |
1406 | -KArchive* KArchiveEntry::archive() const |
1407 | -{ |
1408 | - return d->archive; |
1409 | -} |
1410 | - |
1411 | -//////////////////////////////////////////////////////////////////////// |
1412 | -/////////////////////// KArchiveFile /////////////////////////////////// |
1413 | -//////////////////////////////////////////////////////////////////////// |
1414 | - |
1415 | -class KArchiveFilePrivate |
1416 | -{ |
1417 | -public: |
1418 | - KArchiveFilePrivate( qint64 _pos, qint64 _size ) : |
1419 | - pos(_pos), |
1420 | - size(_size) |
1421 | - {} |
1422 | - qint64 pos; |
1423 | - qint64 size; |
1424 | -}; |
1425 | - |
1426 | -KArchiveFile::KArchiveFile( KArchive* t, const QString& name, int access, int date, |
1427 | - const QString& user, const QString& group, |
1428 | - const QString & symlink, |
1429 | - qint64 pos, qint64 size ) |
1430 | - : KArchiveEntry( t, name, access, date, user, group, symlink ), |
1431 | - d( new KArchiveFilePrivate(pos, size) ) |
1432 | -{ |
1433 | -} |
1434 | - |
1435 | -KArchiveFile::~KArchiveFile() |
1436 | -{ |
1437 | - delete d; |
1438 | -} |
1439 | - |
1440 | -qint64 KArchiveFile::position() const |
1441 | -{ |
1442 | - return d->pos; |
1443 | -} |
1444 | - |
1445 | -qint64 KArchiveFile::size() const |
1446 | -{ |
1447 | - return d->size; |
1448 | -} |
1449 | - |
1450 | -void KArchiveFile::setSize( qint64 s ) |
1451 | -{ |
1452 | - d->size = s; |
1453 | -} |
1454 | - |
1455 | -QByteArray KArchiveFile::data() const |
1456 | -{ |
1457 | - archive()->device()->seek( d->pos ); |
1458 | - |
1459 | - // Read content |
1460 | - QByteArray arr; |
1461 | - if ( d->size ) |
1462 | - { |
1463 | - assert( arr.data() ); |
1464 | - arr = archive()->device()->read( d->size ); |
1465 | - Q_ASSERT( arr.size() == d->size ); |
1466 | - } |
1467 | - return arr; |
1468 | -} |
1469 | - |
1470 | -QIODevice * KArchiveFile::createDevice() const |
1471 | -{ |
1472 | - return new KLimitedIODevice( archive()->device(), d->pos, d->size ); |
1473 | -} |
1474 | - |
1475 | -bool KArchiveFile::isFile() const |
1476 | -{ |
1477 | - return true; |
1478 | -} |
1479 | - |
1480 | -void KArchiveFile::copyTo(const QString& dest) const |
1481 | -{ |
1482 | - QFile f( dest + '/' + name() ); |
1483 | - if ( f.open( QIODevice::ReadWrite | QIODevice::Truncate ) ) |
1484 | - { |
1485 | - f.write( data() ); |
1486 | - f.close(); |
1487 | - } |
1488 | -} |
1489 | - |
1490 | -//////////////////////////////////////////////////////////////////////// |
1491 | -//////////////////////// KArchiveDirectory ///////////////////////////////// |
1492 | -//////////////////////////////////////////////////////////////////////// |
1493 | - |
1494 | -class KArchiveDirectoryPrivate |
1495 | -{ |
1496 | -public: |
1497 | - ~KArchiveDirectoryPrivate() |
1498 | - { |
1499 | - qDeleteAll(entries); |
1500 | - } |
1501 | - QHash<QString, KArchiveEntry *> entries; |
1502 | -}; |
1503 | - |
1504 | -KArchiveDirectory::KArchiveDirectory( KArchive* t, const QString& name, int access, |
1505 | - int date, |
1506 | - const QString& user, const QString& group, |
1507 | - const QString &symlink) |
1508 | - : KArchiveEntry( t, name, access, date, user, group, symlink ), |
1509 | - d( new KArchiveDirectoryPrivate ) |
1510 | -{ |
1511 | -} |
1512 | - |
1513 | -KArchiveDirectory::~KArchiveDirectory() |
1514 | -{ |
1515 | - delete d; |
1516 | -} |
1517 | - |
1518 | -QStringList KArchiveDirectory::entries() const |
1519 | -{ |
1520 | - return d->entries.keys(); |
1521 | -} |
1522 | - |
1523 | -const KArchiveEntry* KArchiveDirectory::entry( const QString& _name ) const |
1524 | -{ |
1525 | - QString name = _name; |
1526 | - int pos = name.indexOf( '/' ); |
1527 | - if ( pos == 0 ) // ouch absolute path (see also KArchive::findOrCreate) |
1528 | - { |
1529 | - if (name.length()>1) |
1530 | - { |
1531 | - name = name.mid( 1 ); // remove leading slash |
1532 | - pos = name.indexOf( '/' ); // look again |
1533 | - } |
1534 | - else // "/" |
1535 | - return this; |
1536 | - } |
1537 | - // trailing slash ? -> remove |
1538 | - if ( pos != -1 && pos == name.length()-1 ) |
1539 | - { |
1540 | - name = name.left( pos ); |
1541 | - pos = name.indexOf( '/' ); // look again |
1542 | - } |
1543 | - if ( pos != -1 ) |
1544 | - { |
1545 | - QString left = name.left( pos ); |
1546 | - QString right = name.mid( pos + 1 ); |
1547 | - |
1548 | - //qDebug() << "left=" << left << "right=" << right; |
1549 | - |
1550 | - const KArchiveEntry* e = d->entries.value( left ); |
1551 | - if ( !e || !e->isDirectory() ) |
1552 | - return 0; |
1553 | - return static_cast<const KArchiveDirectory*>(e)->entry( right ); |
1554 | - } |
1555 | - |
1556 | - return d->entries.value( name ); |
1557 | -} |
1558 | - |
1559 | -void KArchiveDirectory::addEntry( KArchiveEntry* entry ) |
1560 | -{ |
1561 | - Q_ASSERT( !entry->name().isEmpty() ); |
1562 | - if( d->entries.value( entry->name() ) ) { |
1563 | - qWarning() << "directory " << name() |
1564 | - << "has entry" << entry->name() << "already"; |
1565 | - } |
1566 | - d->entries.insert( entry->name(), entry ); |
1567 | -} |
1568 | - |
1569 | -bool KArchiveDirectory::isDirectory() const |
1570 | -{ |
1571 | - return true; |
1572 | -} |
1573 | - |
1574 | -static int sortByPosition( const KArchiveFile* file1, const KArchiveFile* file2 ) { |
1575 | - return file1->position() - file2->position(); |
1576 | -} |
1577 | - |
1578 | -void KArchiveDirectory::copyTo(const QString& dest, bool recursiveCopy ) const |
1579 | -{ |
1580 | - QDir root; |
1581 | - |
1582 | - QList<const KArchiveFile*> fileList; |
1583 | - QMap<qint64, QString> fileToDir; |
1584 | - |
1585 | - // placeholders for iterated items |
1586 | - QStack<const KArchiveDirectory *> dirStack; |
1587 | - QStack<QString> dirNameStack; |
1588 | - |
1589 | - dirStack.push( this ); // init stack at current directory |
1590 | - dirNameStack.push( dest ); // ... with given path |
1591 | - do { |
1592 | - const KArchiveDirectory* curDir = dirStack.pop(); |
1593 | - const QString curDirName = dirNameStack.pop(); |
1594 | - root.mkdir(curDirName); |
1595 | - |
1596 | - const QStringList dirEntries = curDir->entries(); |
1597 | - for ( QStringList::const_iterator it = dirEntries.begin(); it != dirEntries.end(); ++it ) { |
1598 | - const KArchiveEntry* curEntry = curDir->entry(*it); |
1599 | - if (!curEntry->symLinkTarget().isEmpty()) { |
1600 | - const QString linkName = curDirName+'/'+curEntry->name(); |
1601 | -#ifdef Q_OS_UNIX |
1602 | - if (!::symlink(curEntry->symLinkTarget().toLocal8Bit(), linkName.toLocal8Bit())) { |
1603 | - qDebug() << "symlink(" << curEntry->symLinkTarget() << ',' << linkName << ") failed:" << strerror(errno); |
1604 | - } |
1605 | -#else |
1606 | - // TODO - how to create symlinks on other platforms? |
1607 | -#endif |
1608 | - } else { |
1609 | - if ( curEntry->isFile() ) { |
1610 | - const KArchiveFile* curFile = dynamic_cast<const KArchiveFile*>( curEntry ); |
1611 | - if (curFile) { |
1612 | - fileList.append( curFile ); |
1613 | - fileToDir.insert( curFile->position(), curDirName ); |
1614 | - } |
1615 | - } |
1616 | - |
1617 | - if ( curEntry->isDirectory() && recursiveCopy ) { |
1618 | - const KArchiveDirectory *ad = dynamic_cast<const KArchiveDirectory*>( curEntry ); |
1619 | - if (ad) { |
1620 | - dirStack.push( ad ); |
1621 | - dirNameStack.push( curDirName + '/' + curEntry->name() ); |
1622 | - } |
1623 | - } |
1624 | - } |
1625 | - } |
1626 | - } while (!dirStack.isEmpty()); |
1627 | - |
1628 | - qSort( fileList.begin(), fileList.end(), sortByPosition ); // sort on d->pos, so we have a linear access |
1629 | - |
1630 | - for ( QList<const KArchiveFile*>::const_iterator it = fileList.constBegin(), end = fileList.constEnd() ; |
1631 | - it != end ; ++it ) { |
1632 | - const KArchiveFile* f = *it; |
1633 | - qint64 pos = f->position(); |
1634 | - f->copyTo( fileToDir[pos] ); |
1635 | - } |
1636 | -} |
1637 | - |
1638 | -void KArchive::virtual_hook( int, void* ) |
1639 | -{ /*BASE::virtual_hook( id, data )*/; } |
1640 | - |
1641 | -void KArchiveEntry::virtual_hook( int, void* ) |
1642 | -{ /*BASE::virtual_hook( id, data );*/ } |
1643 | - |
1644 | -void KArchiveFile::virtual_hook( int id, void* data ) |
1645 | -{ KArchiveEntry::virtual_hook( id, data ); } |
1646 | - |
1647 | -void KArchiveDirectory::virtual_hook( int id, void* data ) |
1648 | -{ KArchiveEntry::virtual_hook( id, data ); } |
1649 | |
1650 | === removed file 'src/core/external/kfilter/karchive.h' |
1651 | --- src/core/external/kfilter/karchive.h 2013-06-05 05:59:53 +0000 |
1652 | +++ src/core/external/kfilter/karchive.h 1970-01-01 00:00:00 +0000 |
1653 | @@ -1,603 +0,0 @@ |
1654 | -/* This file is part of the KDE libraries |
1655 | - Copyright (C) 2000-2005 David Faure <faure@kde.org> |
1656 | - Copyright (C) 2003 Leo Savernik <l.savernik@aon.at> |
1657 | - |
1658 | - Moved from ktar.h by Roberto Teixeira <maragato@kde.org> |
1659 | - |
1660 | - This library is free software; you can redistribute it and/or |
1661 | - modify it under the terms of the GNU Library General Public |
1662 | - License version 2 as published by the Free Software Foundation. |
1663 | - |
1664 | - This library is distributed in the hope that it will be useful, |
1665 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
1666 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1667 | - Library General Public License for more details. |
1668 | - |
1669 | - You should have received a copy of the GNU Library General Public License |
1670 | - along with this library; see the file COPYING.LIB. If not, write to |
1671 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
1672 | - Boston, MA 02110-1301, USA. |
1673 | -*/ |
1674 | -#ifndef KARCHIVE_H |
1675 | -#define KARCHIVE_H |
1676 | - |
1677 | -#ifdef _MSC_BUILD |
1678 | -#include "kdewin32/sys/types.h" |
1679 | -#else |
1680 | -#include <sys/types.h> |
1681 | -#endif |
1682 | - |
1683 | -#include <QtCore/QDate> |
1684 | -#include <QtCore/QString> |
1685 | -#include <QtCore/QStringList> |
1686 | -#include <QtCore/QHash> |
1687 | - |
1688 | -class KArchiveDirectory; |
1689 | -class KArchiveFile; |
1690 | - |
1691 | -class KArchivePrivate; |
1692 | -/** |
1693 | - * KArchive is a base class for reading and writing archives. |
1694 | - * @short generic class for reading/writing archives |
1695 | - * @author David Faure <faure@kde.org> |
1696 | - */ |
1697 | -class KArchive |
1698 | -{ |
1699 | -protected: |
1700 | - /** |
1701 | - * Base constructor (protected since this is a pure virtual class). |
1702 | - * @param fileName is a local path (e.g. "/tmp/myfile.ext"), |
1703 | - * from which the archive will be read from, or into which the archive |
1704 | - * will be written, depending on the mode given to open(). |
1705 | - */ |
1706 | - KArchive( const QString& fileName ); |
1707 | - |
1708 | - /** |
1709 | - * Base constructor (protected since this is a pure virtual class). |
1710 | - * @param dev the I/O device where the archive reads its data |
1711 | - * Note that this can be a file, but also a data buffer, a compression filter, etc. |
1712 | - * For a file in writing mode it is better to use the other constructor |
1713 | - * though, to benefit from the use of KSaveFile when saving. |
1714 | - */ |
1715 | - KArchive( QIODevice * dev ); |
1716 | - |
1717 | -public: |
1718 | - virtual ~KArchive(); |
1719 | - |
1720 | - /** |
1721 | - * Opens the archive for reading or writing. |
1722 | - * Inherited classes might want to reimplement openArchive instead. |
1723 | - * @param mode may be QIODevice::ReadOnly or QIODevice::WriteOnly |
1724 | - * @see close |
1725 | - */ |
1726 | - virtual bool open( QIODevice::OpenMode mode ); |
1727 | - |
1728 | - /** |
1729 | - * Closes the archive. |
1730 | - * Inherited classes might want to reimplement closeArchive instead. |
1731 | - * |
1732 | - * @return true if close succeeded without problems |
1733 | - * @see open |
1734 | - */ |
1735 | - virtual bool close(); |
1736 | - |
1737 | - /** |
1738 | - * Checks whether the archive is open. |
1739 | - * @return true if the archive is opened |
1740 | - */ |
1741 | - bool isOpen() const; |
1742 | - |
1743 | - /** |
1744 | - * Returns the mode in which the archive was opened |
1745 | - * @return the mode in which the archive was opened (QIODevice::ReadOnly or QIODevice::WriteOnly) |
1746 | - * @see open() |
1747 | - */ |
1748 | - QIODevice::OpenMode mode() const; |
1749 | - |
1750 | - /** |
1751 | - * The underlying device. |
1752 | - * @return the underlying device. |
1753 | - */ |
1754 | - QIODevice * device() const; |
1755 | - |
1756 | - /** |
1757 | - * The name of the archive file, as passed to the constructor that takes a |
1758 | - * fileName, or an empty string if you used the QIODevice constructor. |
1759 | - * @return the name of the file, or QString() if unknown |
1760 | - */ |
1761 | - QString fileName() const; |
1762 | - |
1763 | - /** |
1764 | - * If an archive is opened for reading, then the contents |
1765 | - * of the archive can be accessed via this function. |
1766 | - * @return the directory of the archive |
1767 | - */ |
1768 | - const KArchiveDirectory* directory() const; |
1769 | - |
1770 | - /** |
1771 | - * Writes a local file into the archive. The main difference with writeFile, |
1772 | - * is that this method minimizes memory usage, by not loading the whole file |
1773 | - * into memory in one go. |
1774 | - * |
1775 | - * If @p fileName is a symbolic link, it will be written as is, i. e. |
1776 | - * it will not be resolved before. |
1777 | - * @param fileName full path to an existing local file, to be added to the archive. |
1778 | - * @param destName the resulting name (or relative path) of the file in the archive. |
1779 | - */ |
1780 | - bool addLocalFile( const QString& fileName, const QString& destName ); |
1781 | - |
1782 | - /** |
1783 | - * Writes a local directory into the archive, including all its contents, recursively. |
1784 | - * Calls addLocalFile for each file to be added. |
1785 | - * |
1786 | - * Since KDE 3.2 it will also add a @p path that is a symbolic link to a |
1787 | - * directory. The symbolic link will be dereferenced and the content of the |
1788 | - * directory it is pointing to added recursively. However, symbolic links |
1789 | - * *under* @p path will be stored as is. |
1790 | - * @param path full path to an existing local directory, to be added to the archive. |
1791 | - * @param destName the resulting name (or relative path) of the file in the archive. |
1792 | - */ |
1793 | - bool addLocalDirectory( const QString& path, const QString& destName ); |
1794 | - |
1795 | - enum { UnknownTime = static_cast<time_t>( -1 ) }; |
1796 | - |
1797 | - /** |
1798 | - * If an archive is opened for writing then you can add new directories |
1799 | - * using this function. KArchive won't write one directory twice. |
1800 | - * |
1801 | - * This method also allows some file metadata to be set. |
1802 | - * However, depending on the archive type not all metadata might be regarded. |
1803 | - * |
1804 | - * @param name the name of the directory |
1805 | - * @param user the user that owns the directory |
1806 | - * @param group the group that owns the directory |
1807 | - * @param perm permissions of the directory |
1808 | - * @param atime time the file was last accessed |
1809 | - * @param mtime modification time of the file |
1810 | - * @param ctime time of last status change |
1811 | - */ |
1812 | - virtual bool writeDir( const QString& name, const QString& user, const QString& group, |
1813 | - mode_t perm = 040755, time_t atime = UnknownTime, |
1814 | - time_t mtime = UnknownTime, time_t ctime = UnknownTime ); |
1815 | - |
1816 | - /** |
1817 | - * Writes a symbolic link to the archive if supported. |
1818 | - * The archive must be opened for writing. |
1819 | - * |
1820 | - * @param name name of symbolic link |
1821 | - * @param target target of symbolic link |
1822 | - * @param user the user that owns the directory |
1823 | - * @param group the group that owns the directory |
1824 | - * @param perm permissions of the directory |
1825 | - * @param atime time the file was last accessed |
1826 | - * @param mtime modification time of the file |
1827 | - * @param ctime time of last status change |
1828 | - */ |
1829 | - virtual bool writeSymLink(const QString &name, const QString &target, |
1830 | - const QString &user, const QString &group, |
1831 | - mode_t perm = 0120755, time_t atime = UnknownTime, |
1832 | - time_t mtime = UnknownTime, time_t ctime = UnknownTime ); |
1833 | - |
1834 | - /** |
1835 | - * If an archive is opened for writing then you can add a new file |
1836 | - * using this function. If the file name is for example "mydir/test1" then |
1837 | - * the directory "mydir" is automatically appended first if that did not |
1838 | - * happen yet. |
1839 | - * |
1840 | - * This method also allows some file metadata to be |
1841 | - * set. However, depending on the archive type not all metadata might be |
1842 | - * regarded. |
1843 | - * @param name the name of the file |
1844 | - * @param user the user that owns the file |
1845 | - * @param group the group that owns the file |
1846 | - * @param data the data to write (@p size bytes) |
1847 | - * @param size the size of the file |
1848 | - * @param perm permissions of the file |
1849 | - * @param atime time the file was last accessed |
1850 | - * @param mtime modification time of the file |
1851 | - * @param ctime time of last status change |
1852 | - */ |
1853 | - virtual bool writeFile( const QString& name, const QString& user, const QString& group, |
1854 | - const char* data, qint64 size, |
1855 | - mode_t perm = 0100644, time_t atime = UnknownTime, |
1856 | - time_t mtime = UnknownTime, time_t ctime = UnknownTime ); |
1857 | - |
1858 | - /** |
1859 | - * Here's another way of writing a file into an archive: |
1860 | - * Call prepareWriting(), then call writeData() |
1861 | - * as many times as wanted then call finishWriting( totalSize ). |
1862 | - * For tar.gz files, you need to know the size before hand, it is needed in the header! |
1863 | - * For zip files, size isn't used. |
1864 | - * |
1865 | - * This method also allows some file metadata to be |
1866 | - * set. However, depending on the archive type not all metadata might be |
1867 | - * regarded. |
1868 | - * @param name the name of the file |
1869 | - * @param user the user that owns the file |
1870 | - * @param group the group that owns the file |
1871 | - * @param size the size of the file |
1872 | - * @param perm permissions of the file |
1873 | - * @param atime time the file was last accessed |
1874 | - * @param mtime modification time of the file |
1875 | - * @param ctime time of last status change |
1876 | - */ |
1877 | - virtual bool prepareWriting( const QString& name, const QString& user, |
1878 | - const QString& group, qint64 size, |
1879 | - mode_t perm = 0100644, time_t atime = UnknownTime, |
1880 | - time_t mtime = UnknownTime, time_t ctime = UnknownTime ); |
1881 | - |
1882 | - /** |
1883 | - * Write data into the current file - to be called after calling prepareWriting |
1884 | - */ |
1885 | - virtual bool writeData( const char* data, qint64 size ); |
1886 | - |
1887 | - /** |
1888 | - * Call finishWriting after writing the data. |
1889 | - * @param size the size of the file |
1890 | - * @see prepareWriting() |
1891 | - */ |
1892 | - virtual bool finishWriting( qint64 size ); |
1893 | - |
1894 | -protected: |
1895 | - /** |
1896 | - * Opens an archive for reading or writing. |
1897 | - * Called by open. |
1898 | - * @param mode may be QIODevice::ReadOnly or QIODevice::WriteOnly |
1899 | - */ |
1900 | - virtual bool openArchive( QIODevice::OpenMode mode ) = 0; |
1901 | - |
1902 | - /** |
1903 | - * Closes the archive. |
1904 | - * Called by close. |
1905 | - */ |
1906 | - virtual bool closeArchive() = 0; |
1907 | - |
1908 | - /** |
1909 | - * Retrieves or create the root directory. |
1910 | - * The default implementation assumes that openArchive() did the parsing, |
1911 | - * so it creates a dummy rootdir if none was set (write mode, or no '/' in the archive). |
1912 | - * Reimplement this to provide parsing/listing on demand. |
1913 | - * @return the root directory |
1914 | - */ |
1915 | - virtual KArchiveDirectory* rootDir(); |
1916 | - |
1917 | - /** |
1918 | - * Write a directory to the archive. |
1919 | - * This virtual method must be implemented by subclasses. |
1920 | - * |
1921 | - * Depending on the archive type not all metadata might be used. |
1922 | - * |
1923 | - * @param name the name of the directory |
1924 | - * @param user the user that owns the directory |
1925 | - * @param group the group that owns the directory |
1926 | - * @param perm permissions of the directory. Use 040755 if you don't have any other information. |
1927 | - * @param atime time the file was last accessed |
1928 | - * @param mtime modification time of the file |
1929 | - * @param ctime time of last status change |
1930 | - * @see writeDir |
1931 | - */ |
1932 | - virtual bool doWriteDir( const QString& name, const QString& user, const QString& group, |
1933 | - mode_t perm, time_t atime, time_t mtime, time_t ctime ) = 0; |
1934 | - |
1935 | - /** |
1936 | - * Writes a symbolic link to the archive. |
1937 | - * This virtual method must be implemented by subclasses. |
1938 | - * |
1939 | - * @param name name of symbolic link |
1940 | - * @param target target of symbolic link |
1941 | - * @param user the user that owns the directory |
1942 | - * @param group the group that owns the directory |
1943 | - * @param perm permissions of the directory |
1944 | - * @param atime time the file was last accessed |
1945 | - * @param mtime modification time of the file |
1946 | - * @param ctime time of last status change |
1947 | - * @see writeSymLink |
1948 | - */ |
1949 | - virtual bool doWriteSymLink(const QString &name, const QString &target, |
1950 | - const QString &user, const QString &group, |
1951 | - mode_t perm, time_t atime, time_t mtime, time_t ctime) = 0; |
1952 | - |
1953 | - /** |
1954 | - * This virtual method must be implemented by subclasses. |
1955 | - * |
1956 | - * Depending on the archive type not all metadata might be used. |
1957 | - * |
1958 | - * @param name the name of the file |
1959 | - * @param user the user that owns the file |
1960 | - * @param group the group that owns the file |
1961 | - * @param size the size of the file |
1962 | - * @param perm permissions of the file. Use 0100644 if you don't have any more specific permissions to set. |
1963 | - * @param atime time the file was last accessed |
1964 | - * @param mtime modification time of the file |
1965 | - * @param ctime time of last status change |
1966 | - * @see prepareWriting |
1967 | - */ |
1968 | - virtual bool doPrepareWriting( const QString& name, const QString& user, |
1969 | - const QString& group, qint64 size, mode_t perm, |
1970 | - time_t atime, time_t mtime, time_t ctime ) = 0; |
1971 | - |
1972 | - /** |
1973 | - * Called after writing the data. |
1974 | - * This virtual method must be implemented by subclasses. |
1975 | - * |
1976 | - * @param size the size of the file |
1977 | - * @see finishWriting() |
1978 | - */ |
1979 | - virtual bool doFinishWriting( qint64 size ) = 0; |
1980 | - |
1981 | - /** |
1982 | - * Ensures that @p path exists, create otherwise. |
1983 | - * This handles e.g. tar files missing directory entries, like mico-2.3.0.tar.gz :) |
1984 | - * @param path the path of the directory |
1985 | - * @return the directory with the given @p path |
1986 | - */ |
1987 | - KArchiveDirectory * findOrCreate( const QString & path ); |
1988 | - |
1989 | - /** |
1990 | - * Can be reimplemented in order to change the creation of the device |
1991 | - * (when using the fileName constructor). By default this method uses |
1992 | - * KSaveFile when saving, and a simple QFile on reading. |
1993 | - * This method is called by open(). |
1994 | - */ |
1995 | - virtual bool createDevice( QIODevice::OpenMode mode ); |
1996 | - |
1997 | - /** |
1998 | - * Can be called by derived classes in order to set the underlying device. |
1999 | - * Note that KArchive will -not- own the device, it must be deleted by the derived class. |
2000 | - */ |
2001 | - void setDevice( QIODevice *dev ); |
2002 | - |
2003 | - /** |
2004 | - * Derived classes call setRootDir from openArchive, |
2005 | - * to set the root directory after parsing an existing archive. |
2006 | - */ |
2007 | - void setRootDir( KArchiveDirectory *rootDir ); |
2008 | - |
2009 | -protected: |
2010 | - virtual void virtual_hook( int id, void* data ); |
2011 | -private: |
2012 | - KArchivePrivate* const d; |
2013 | -}; |
2014 | - |
2015 | -class KArchiveEntryPrivate; |
2016 | -/** |
2017 | - * A base class for entries in an KArchive. |
2018 | - * @short Base class for the archive-file's directory structure. |
2019 | - * |
2020 | - * @see KArchiveFile |
2021 | - * @see KArchiveDirectory |
2022 | - */ |
2023 | -class KArchiveEntry |
2024 | -{ |
2025 | -public: |
2026 | - /** |
2027 | - * Creates a new entry. |
2028 | - * @param archive the entries archive |
2029 | - * @param name the name of the entry |
2030 | - * @param access the permissions in unix format |
2031 | - * @param date the date (in seconds since 1970) |
2032 | - * @param user the user that owns the entry |
2033 | - * @param group the group that owns the entry |
2034 | - * @param symlink the symlink, or QString() |
2035 | - */ |
2036 | - KArchiveEntry( KArchive* archive, const QString& name, int access, int date, |
2037 | - const QString& user, const QString& group, |
2038 | - const QString& symlink ); |
2039 | - |
2040 | - virtual ~KArchiveEntry(); |
2041 | - |
2042 | - /** |
2043 | - * Creation date of the file. |
2044 | - * @return the creation date |
2045 | - */ |
2046 | - QDateTime datetime() const; |
2047 | - |
2048 | - /** |
2049 | - * Creation date of the file. |
2050 | - * @return the creation date in seconds since 1970 |
2051 | - */ |
2052 | - int date() const; |
2053 | - |
2054 | - /** |
2055 | - * Name of the file without path. |
2056 | - * @return the file name without path |
2057 | - */ |
2058 | - QString name() const; |
2059 | - /** |
2060 | - * The permissions and mode flags as returned by the stat() function |
2061 | - * in st_mode. |
2062 | - * @return the permissions |
2063 | - */ |
2064 | - mode_t permissions() const; |
2065 | - /** |
2066 | - * User who created the file. |
2067 | - * @return the owner of the file |
2068 | - */ |
2069 | - QString user() const; |
2070 | - /** |
2071 | - * Group of the user who created the file. |
2072 | - * @return the group of the file |
2073 | - */ |
2074 | - QString group() const; |
2075 | - |
2076 | - /** |
2077 | - * Symlink if there is one. |
2078 | - * @return the symlink, or QString() |
2079 | - */ |
2080 | - QString symLinkTarget() const; |
2081 | - |
2082 | - /** |
2083 | - * Checks whether the entry is a file. |
2084 | - * @return true if this entry is a file |
2085 | - */ |
2086 | - virtual bool isFile() const; |
2087 | - |
2088 | - /** |
2089 | - * Checks whether the entry is a directory. |
2090 | - * @return true if this entry is a directory |
2091 | - */ |
2092 | - virtual bool isDirectory() const; |
2093 | - |
2094 | -protected: |
2095 | - KArchive* archive() const; |
2096 | - |
2097 | -protected: |
2098 | - virtual void virtual_hook( int id, void* data ); |
2099 | -private: |
2100 | - KArchiveEntryPrivate* const d; |
2101 | -}; |
2102 | - |
2103 | -class KArchiveFilePrivate; |
2104 | -/** |
2105 | - * Represents a file entry in a KArchive. |
2106 | - * @short A file in an archive. |
2107 | - * |
2108 | - * @see KArchive |
2109 | - * @see KArchiveDirectory |
2110 | - */ |
2111 | -class KArchiveFile : public KArchiveEntry |
2112 | -{ |
2113 | -public: |
2114 | - /** |
2115 | - * Creates a new file entry. Do not call this, KArchive takes care of it. |
2116 | - * @param archive the entries archive |
2117 | - * @param name the name of the entry |
2118 | - * @param access the permissions in unix format |
2119 | - * @param date the date (in seconds since 1970) |
2120 | - * @param user the user that owns the entry |
2121 | - * @param group the group that owns the entry |
2122 | - * @param symlink the symlink, or QString() |
2123 | - * @param pos the position of the file in the directory |
2124 | - * @param size the size of the file |
2125 | - */ |
2126 | - KArchiveFile( KArchive* archive, const QString& name, int access, int date, |
2127 | - const QString& user, const QString& group, const QString &symlink, |
2128 | - qint64 pos, qint64 size ); |
2129 | - |
2130 | - /** |
2131 | - * Destructor. Do not call this, KArchive takes care of it. |
2132 | - */ |
2133 | - virtual ~KArchiveFile(); |
2134 | - |
2135 | - /** |
2136 | - * Position of the data in the [uncompressed] archive. |
2137 | - * @return the position of the file |
2138 | - */ |
2139 | - qint64 position() const; |
2140 | - /** |
2141 | - * Size of the data. |
2142 | - * @return the size of the file |
2143 | - */ |
2144 | - qint64 size() const; |
2145 | - /** |
2146 | - * Set size of data, usually after writing the file. |
2147 | - * @param s the new size of the file |
2148 | - */ |
2149 | - void setSize( qint64 s ); |
2150 | - |
2151 | - /** |
2152 | - * Returns the data of the file. |
2153 | - * Call data() with care (only once per file), this data isn't cached. |
2154 | - * @return the content of this file. |
2155 | - */ |
2156 | - virtual QByteArray data() const; |
2157 | - |
2158 | - /** |
2159 | - * This method returns QIODevice (internal class: KLimitedIODevice) |
2160 | - * on top of the underlying QIODevice. This is obviously for reading only. |
2161 | - * |
2162 | - * WARNING: Note that the ownership of the device is being transferred to the caller, |
2163 | - * who will have to delete it. |
2164 | - * |
2165 | - * The returned device auto-opens (in readonly mode), no need to open it. |
2166 | - * @return the QIODevice of the file |
2167 | - */ |
2168 | - virtual QIODevice *createDevice() const; |
2169 | - |
2170 | - /** |
2171 | - * Checks whether this entry is a file. |
2172 | - * @return true, since this entry is a file |
2173 | - */ |
2174 | - virtual bool isFile() const; |
2175 | - |
2176 | - /** |
2177 | - * Extracts the file to the directory @p dest |
2178 | - * @param dest the directory to extract to |
2179 | - */ |
2180 | - void copyTo(const QString& dest) const; |
2181 | - |
2182 | -protected: |
2183 | - virtual void virtual_hook( int id, void* data ); |
2184 | -private: |
2185 | - KArchiveFilePrivate* const d; |
2186 | -}; |
2187 | - |
2188 | -class KArchiveDirectoryPrivate; |
2189 | -/** |
2190 | - * Represents a directory entry in a KArchive. |
2191 | - * @short A directory in an archive. |
2192 | - * |
2193 | - * @see KArchive |
2194 | - * @see KArchiveFile |
2195 | - */ |
2196 | -class KArchiveDirectory : public KArchiveEntry |
2197 | -{ |
2198 | -public: |
2199 | - /** |
2200 | - * Creates a new directory entry. |
2201 | - * @param archive the entries archive |
2202 | - * @param name the name of the entry |
2203 | - * @param access the permissions in unix format |
2204 | - * @param date the date (in seconds since 1970) |
2205 | - * @param user the user that owns the entry |
2206 | - * @param group the group that owns the entry |
2207 | - * @param symlink the symlink, or QString() |
2208 | - */ |
2209 | - KArchiveDirectory( KArchive* archive, const QString& name, int access, int date, |
2210 | - const QString& user, const QString& group, |
2211 | - const QString& symlink); |
2212 | - |
2213 | - virtual ~KArchiveDirectory(); |
2214 | - |
2215 | - /** |
2216 | - * Returns a list of sub-entries. |
2217 | - * Note that the list is not sorted, it's even in random order (due to using a hashtable). |
2218 | - * Use sort() on the result to sort the list by filename. |
2219 | - * |
2220 | - * @return the names of all entries in this directory (filenames, no path). |
2221 | - */ |
2222 | - QStringList entries() const; |
2223 | - /** |
2224 | - * Returns the entry with the given name. |
2225 | - * @param name may be "test1", "mydir/test3", "mydir/mysubdir/test3", etc. |
2226 | - * @return a pointer to the entry in the directory. |
2227 | - */ |
2228 | - const KArchiveEntry* entry( const QString& name ) const; |
2229 | - |
2230 | - /** |
2231 | - * @internal |
2232 | - * Adds a new entry to the directory. |
2233 | - */ |
2234 | - void addEntry( KArchiveEntry* ); |
2235 | - |
2236 | - /** |
2237 | - * Checks whether this entry is a directory. |
2238 | - * @return true, since this entry is a directory |
2239 | - */ |
2240 | - virtual bool isDirectory() const; |
2241 | - |
2242 | - /** |
2243 | - * Extracts all entries in this archive directory to the directory |
2244 | - * @p dest. |
2245 | - * @param dest the directory to extract to |
2246 | - * @param recursive if set to true, subdirectories are extracted as well |
2247 | - */ |
2248 | - void copyTo(const QString& dest, bool recursive = true) const; |
2249 | - |
2250 | -protected: |
2251 | - virtual void virtual_hook( int id, void* data ); |
2252 | -private: |
2253 | - KArchiveDirectoryPrivate* const d; |
2254 | -}; |
2255 | - |
2256 | -#endif |
2257 | |
2258 | === removed file 'src/core/external/kfilter/kfilterbase.cpp' |
2259 | --- src/core/external/kfilter/kfilterbase.cpp 2010-04-30 17:27:42 +0000 |
2260 | +++ src/core/external/kfilter/kfilterbase.cpp 1970-01-01 00:00:00 +0000 |
2261 | @@ -1,113 +0,0 @@ |
2262 | -/* This file is part of the KDE libraries |
2263 | - Copyright (C) 2000-2005 David Faure <faure@kde.org> |
2264 | - |
2265 | - This library is free software; you can redistribute it and/or |
2266 | - modify it under the terms of the GNU Library General Public |
2267 | - License version 2 as published by the Free Software Foundation. |
2268 | - |
2269 | - This library is distributed in the hope that it will be useful, |
2270 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
2271 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2272 | - Library General Public License for more details. |
2273 | - |
2274 | - You should have received a copy of the GNU Library General Public License |
2275 | - along with this library; see the file COPYING.LIB. If not, write to |
2276 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
2277 | - Boston, MA 02110-1301, USA. |
2278 | -*/ |
2279 | - |
2280 | -#include "kfilterbase.h" |
2281 | - |
2282 | -#include <QDebug> |
2283 | -#include <QtCore/QIODevice> |
2284 | -#include "kgzipfilter.h" |
2285 | - |
2286 | -KFilterBase::KFilterBase() |
2287 | - : m_dev( 0L ), m_bAutoDel( false ), d(0) |
2288 | -{ |
2289 | -} |
2290 | - |
2291 | -KFilterBase::~KFilterBase() |
2292 | -{ |
2293 | - if ( m_bAutoDel ) |
2294 | - delete m_dev; |
2295 | -} |
2296 | - |
2297 | -void KFilterBase::setDevice( QIODevice * dev, bool autodelete ) |
2298 | -{ |
2299 | - m_dev = dev; |
2300 | - m_bAutoDel = autodelete; |
2301 | -} |
2302 | - |
2303 | -QIODevice * KFilterBase::device() |
2304 | -{ |
2305 | - return m_dev; |
2306 | -} |
2307 | - |
2308 | -bool KFilterBase::inBufferEmpty() const |
2309 | -{ |
2310 | - return inBufferAvailable() == 0; |
2311 | -} |
2312 | - |
2313 | -bool KFilterBase::outBufferFull() const |
2314 | -{ |
2315 | - return outBufferAvailable() == 0; |
2316 | -} |
2317 | - |
2318 | -KFilterBase * KFilterBase::findFilterByFileName( const QString & fileName ) |
2319 | -{ |
2320 | - if ( fileName.endsWith( ".gz", Qt::CaseInsensitive ) ) |
2321 | - { |
2322 | - return new KGzipFilter; |
2323 | - } |
2324 | -#ifdef HAVE_BZIP2_SUPPORT |
2325 | - if ( fileName.endsWith( ".bz2", Qt::CaseInsensitive ) ) |
2326 | - { |
2327 | - return new KBzip2Filter; |
2328 | - } |
2329 | -#endif |
2330 | - else |
2331 | - { |
2332 | - // not a warning, since this is called often with other mimetypes (see #88574)... |
2333 | - // maybe we can avoid that though? |
2334 | - qDebug() << "KFilterBase::findFilterByFileName : no filter found for " << fileName; |
2335 | - } |
2336 | - |
2337 | - return 0; |
2338 | -} |
2339 | - |
2340 | -KFilterBase * KFilterBase::findFilterByMimeType( const QString & mimeType ) |
2341 | -{ |
2342 | - if ( mimeType == QLatin1String( "application/x-gzip" ) ) |
2343 | - { |
2344 | - return new KGzipFilter; |
2345 | - } |
2346 | -#ifdef HAVE_BZIP2_SUPPORT |
2347 | - else if ( mimeType == QLatin1String( "application/x-bzip" ) |
2348 | - || mimeType == QLatin1String( "application/x-bzip2" ) // old name, kept for compatibility |
2349 | - || (mime && mime->is("application/x-bzip")) ) |
2350 | - { |
2351 | - return new KBzip2Filter; |
2352 | - } |
2353 | -#endif |
2354 | - else |
2355 | - { |
2356 | - // not a warning, since this is called often with other mimetypes (see #88574)... |
2357 | - // maybe we can avoid that though? |
2358 | - qDebug() << "KFilterBase::findFilterByMimeType : no filter found for " << mimeType; |
2359 | - } |
2360 | - |
2361 | - return 0; |
2362 | -} |
2363 | - |
2364 | -void KFilterBase::terminate() |
2365 | -{ |
2366 | -} |
2367 | - |
2368 | -void KFilterBase::reset() |
2369 | -{ |
2370 | -} |
2371 | - |
2372 | -void KFilterBase::virtual_hook( int, void* ) |
2373 | -{ /*BASE::virtual_hook( id, data );*/ } |
2374 | - |
2375 | |
2376 | === removed file 'src/core/external/kfilter/kfilterbase.h' |
2377 | --- src/core/external/kfilter/kfilterbase.h 2010-04-15 12:28:34 +0000 |
2378 | +++ src/core/external/kfilter/kfilterbase.h 1970-01-01 00:00:00 +0000 |
2379 | @@ -1,115 +0,0 @@ |
2380 | -/* This file is part of the KDE libraries |
2381 | - Copyright (C) 2000 David Faure <faure@kde.org> |
2382 | - |
2383 | - This library is free software; you can redistribute it and/or |
2384 | - modify it under the terms of the GNU Library General Public |
2385 | - License version 2 as published by the Free Software Foundation. |
2386 | - |
2387 | - This library is distributed in the hope that it will be useful, |
2388 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
2389 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2390 | - Library General Public License for more details. |
2391 | - |
2392 | - You should have received a copy of the GNU Library General Public License |
2393 | - along with this library; see the file COPYING.LIB. If not, write to |
2394 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
2395 | - Boston, MA 02110-1301, USA. |
2396 | -*/ |
2397 | - |
2398 | -#ifndef __kfilterbase__h |
2399 | -#define __kfilterbase__h |
2400 | - |
2401 | -#include <QtCore/QObject> |
2402 | -#include <QtCore/QString> |
2403 | - |
2404 | -class QIODevice; |
2405 | - |
2406 | -/** |
2407 | - * This is the base class for compression filters |
2408 | - * such as gzip and bzip2. It's pretty much internal. |
2409 | - * Don't use directly, use KFilterDev instead. |
2410 | - * @internal |
2411 | - */ |
2412 | -class KFilterBase |
2413 | -{ |
2414 | -public: |
2415 | - KFilterBase(); |
2416 | - virtual ~KFilterBase(); |
2417 | - |
2418 | - /** |
2419 | - * Sets the device on which the filter will work |
2420 | - * @param dev the device on which the filter will work |
2421 | - * @param autodelete if true, @p dev is deleted when the filter is deleted |
2422 | - */ |
2423 | - void setDevice( QIODevice * dev, bool autodelete = false ); |
2424 | - // Note that this isn't in the constructor, because of KLibFactory::create, |
2425 | - // but it should be called before using the filterbase ! |
2426 | - |
2427 | - /** |
2428 | - * Returns the device on which the filter will work. |
2429 | - * @returns the device on which the filter will work |
2430 | - */ |
2431 | - QIODevice * device(); |
2432 | - /** \internal */ |
2433 | - virtual void init( int mode ) = 0; |
2434 | - /** \internal */ |
2435 | - virtual int mode() const = 0; |
2436 | - /** \internal */ |
2437 | - virtual void terminate(); |
2438 | - /** \internal */ |
2439 | - virtual void reset(); |
2440 | - /** \internal */ |
2441 | - virtual bool readHeader() = 0; |
2442 | - /** \internal */ |
2443 | - virtual bool writeHeader( const QByteArray & filename ) = 0; |
2444 | - /** \internal */ |
2445 | - virtual void setOutBuffer( char * data, uint maxlen ) = 0; |
2446 | - /** \internal */ |
2447 | - virtual void setInBuffer( const char * data, uint size ) = 0; |
2448 | - /** \internal */ |
2449 | - virtual bool inBufferEmpty() const; |
2450 | - /** \internal */ |
2451 | - virtual int inBufferAvailable() const = 0; |
2452 | - /** \internal */ |
2453 | - virtual bool outBufferFull() const; |
2454 | - /** \internal */ |
2455 | - virtual int outBufferAvailable() const = 0; |
2456 | - |
2457 | - /** \internal */ |
2458 | - enum Result { Ok, End, Error }; |
2459 | - /** \internal */ |
2460 | - virtual Result uncompress() = 0; |
2461 | - /** \internal */ |
2462 | - virtual Result compress( bool finish ) = 0; |
2463 | - |
2464 | - /** |
2465 | - * Call this to create the appropriate filter for the file |
2466 | - * named @p fileName. |
2467 | - * @param fileName the name of the file to filter |
2468 | - * @return the filter for the @p fileName, or 0 if not found |
2469 | - */ |
2470 | - static KFilterBase * findFilterByFileName( const QString & fileName ); |
2471 | - |
2472 | - /** |
2473 | - * Call this to create the appropriate filter for the mimetype |
2474 | - * @p mimeType. For instance application/x-gzip. |
2475 | - * @param mimeType the mime type of the file to filter |
2476 | - * @return the filter for the @p mimeType, or 0 if not found |
2477 | - */ |
2478 | - static KFilterBase * findFilterByMimeType( const QString & mimeType ); |
2479 | - |
2480 | -protected: |
2481 | - QIODevice * m_dev; |
2482 | - bool m_bAutoDel; |
2483 | -protected: |
2484 | - /** Virtual hook, used to add new "virtual" functions while maintaining |
2485 | - binary compatibility. Unused in this class. |
2486 | - */ |
2487 | - virtual void virtual_hook( int id, void* data ); |
2488 | -private: |
2489 | - Q_DISABLE_COPY( KFilterBase ) |
2490 | - class Private; |
2491 | - Private * const d; |
2492 | -}; |
2493 | - |
2494 | -#endif |
2495 | |
2496 | === removed file 'src/core/external/kfilter/kfilterdev.cpp' |
2497 | --- src/core/external/kfilter/kfilterdev.cpp 2010-04-15 12:28:34 +0000 |
2498 | +++ src/core/external/kfilter/kfilterdev.cpp 1970-01-01 00:00:00 +0000 |
2499 | @@ -1,372 +0,0 @@ |
2500 | -/* This file is part of the KDE libraries |
2501 | - Copyright (C) 2000, 2006 David Faure <faure@kde.org> |
2502 | - |
2503 | - This library is free software; you can redistribute it and/or |
2504 | - modify it under the terms of the GNU Library General Public |
2505 | - License version 2 as published by the Free Software Foundation. |
2506 | - |
2507 | - This library is distributed in the hope that it will be useful, |
2508 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
2509 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2510 | - Library General Public License for more details. |
2511 | - |
2512 | - You should have received a copy of the GNU Library General Public License |
2513 | - along with this library; see the file COPYING.LIB. If not, write to |
2514 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
2515 | - Boston, MA 02110-1301, USA. |
2516 | -*/ |
2517 | - |
2518 | -#include "kfilterdev.h" |
2519 | -#include "kfilterbase.h" |
2520 | -#include <stdio.h> // for EOF |
2521 | -#include <stdlib.h> |
2522 | -#include <assert.h> |
2523 | -#include <QtCore/QFile> |
2524 | -#include <QDebug> |
2525 | - |
2526 | -#define BUFFER_SIZE 8*1024 |
2527 | - |
2528 | -class KFilterDev::Private |
2529 | -{ |
2530 | -public: |
2531 | - Private() : bNeedHeader(true), bSkipHeaders(false), |
2532 | - autoDeleteFilterBase(false), bOpenedUnderlyingDevice(false), |
2533 | - bIgnoreData(false){} |
2534 | - bool bNeedHeader; |
2535 | - bool bSkipHeaders; |
2536 | - bool autoDeleteFilterBase; |
2537 | - bool bOpenedUnderlyingDevice; |
2538 | - bool bIgnoreData; |
2539 | - QByteArray buffer; // Used as 'input buffer' when reading, as 'output buffer' when writing |
2540 | - QByteArray origFileName; |
2541 | - KFilterBase::Result result; |
2542 | - KFilterBase *filter; |
2543 | -}; |
2544 | - |
2545 | -KFilterDev::KFilterDev( KFilterBase * _filter, bool autoDeleteFilterBase ) |
2546 | - : d(new Private) |
2547 | -{ |
2548 | - assert(_filter); |
2549 | - d->filter = _filter; |
2550 | - d->autoDeleteFilterBase = autoDeleteFilterBase; |
2551 | -} |
2552 | - |
2553 | -KFilterDev::~KFilterDev() |
2554 | -{ |
2555 | - if ( isOpen() ) |
2556 | - close(); |
2557 | - if ( d->autoDeleteFilterBase ) |
2558 | - delete d->filter; |
2559 | - delete d; |
2560 | -} |
2561 | - |
2562 | -//static |
2563 | -QIODevice * KFilterDev::deviceForFile( const QString & fileName, const QString & mimetype, |
2564 | - bool forceFilter ) |
2565 | -{ |
2566 | - QFile * f = new QFile( fileName ); |
2567 | - KFilterBase * base = mimetype.isEmpty() ? KFilterBase::findFilterByFileName( fileName ) |
2568 | - : KFilterBase::findFilterByMimeType( mimetype ); |
2569 | - if ( base ) |
2570 | - { |
2571 | - base->setDevice(f, true); |
2572 | - return new KFilterDev(base, true); |
2573 | - } |
2574 | - if(!forceFilter) |
2575 | - return f; |
2576 | - else |
2577 | - { |
2578 | - delete f; |
2579 | - return 0L; |
2580 | - } |
2581 | -} |
2582 | - |
2583 | -QIODevice * KFilterDev::device( QIODevice* inDevice, const QString & mimetype, bool autoDeleteInDevice ) |
2584 | -{ |
2585 | - if (inDevice==0) |
2586 | - return 0; |
2587 | - KFilterBase * base = KFilterBase::findFilterByMimeType(mimetype); |
2588 | - if ( base ) |
2589 | - { |
2590 | - base->setDevice(inDevice, autoDeleteInDevice); |
2591 | - return new KFilterDev(base, true /* auto-delete "base" */); |
2592 | - } |
2593 | - return 0; |
2594 | -} |
2595 | - |
2596 | -bool KFilterDev::open( QIODevice::OpenMode mode ) |
2597 | -{ |
2598 | - //qDebug() << "KFilterDev::open " << mode; |
2599 | - if ( mode == QIODevice::ReadOnly ) |
2600 | - { |
2601 | - d->buffer.resize(0); |
2602 | - } |
2603 | - else |
2604 | - { |
2605 | - d->buffer.resize( BUFFER_SIZE ); |
2606 | - d->filter->setOutBuffer( d->buffer.data(), d->buffer.size() ); |
2607 | - } |
2608 | - d->bNeedHeader = !d->bSkipHeaders; |
2609 | - d->filter->init( mode ); |
2610 | - d->bOpenedUnderlyingDevice = !d->filter->device()->isOpen(); |
2611 | - bool ret = d->bOpenedUnderlyingDevice ? d->filter->device()->open( mode ) : true; |
2612 | - d->result = KFilterBase::Ok; |
2613 | - |
2614 | - if ( !ret ) |
2615 | - qWarning() << "KFilterDev::open: Couldn't open underlying device"; |
2616 | - else |
2617 | - setOpenMode( mode ); |
2618 | - |
2619 | - return ret; |
2620 | -} |
2621 | - |
2622 | -void KFilterDev::close() |
2623 | -{ |
2624 | - if ( !isOpen() ) |
2625 | - return; |
2626 | - //qDebug() << "KFilterDev::close"; |
2627 | - if ( d->filter->mode() == QIODevice::WriteOnly ) |
2628 | - write( 0L, 0 ); // finish writing |
2629 | - //qDebug() << "KFilterDev::close. Calling terminate()."; |
2630 | - |
2631 | - d->filter->terminate(); |
2632 | - if ( d->bOpenedUnderlyingDevice ) |
2633 | - d->filter->device()->close(); |
2634 | - setOpenMode( QIODevice::NotOpen ); |
2635 | -} |
2636 | - |
2637 | -bool KFilterDev::seek( qint64 pos ) |
2638 | -{ |
2639 | - qint64 ioIndex = this->pos(); // current position |
2640 | - if ( ioIndex == pos ) |
2641 | - return true; |
2642 | - |
2643 | - qDebug() << "KFilterDev::seek(" << pos << ") called"; |
2644 | - |
2645 | - Q_ASSERT ( d->filter->mode() == QIODevice::ReadOnly ); |
2646 | - |
2647 | - if ( pos == 0 ) |
2648 | - { |
2649 | - // We can forget about the cached data |
2650 | - d->bNeedHeader = !d->bSkipHeaders; |
2651 | - d->result = KFilterBase::Ok; |
2652 | - d->filter->setInBuffer(0L,0); |
2653 | - d->filter->reset(); |
2654 | - QIODevice::seek(pos); |
2655 | - return d->filter->device()->reset(); |
2656 | - } |
2657 | - |
2658 | - if ( ioIndex > pos ) // we can start from here |
2659 | - pos = pos - ioIndex; |
2660 | - else |
2661 | - { |
2662 | - // we have to start from 0 ! Ugly and slow, but better than the previous |
2663 | - // solution (KTarGz was allocating everything into memory) |
2664 | - if (!seek(0)) // recursive |
2665 | - return false; |
2666 | - } |
2667 | - |
2668 | - //qDebug() << "KFilterDev::at : reading " << pos << " dummy bytes"; |
2669 | - QByteArray dummy( qMin( pos, (qint64)3*BUFFER_SIZE ), 0 ); |
2670 | - d->bIgnoreData = true; |
2671 | - bool result = ( read( dummy.data(), pos ) == pos ); |
2672 | - d->bIgnoreData = false; |
2673 | - QIODevice::seek(pos); |
2674 | - return result; |
2675 | -} |
2676 | - |
2677 | -bool KFilterDev::atEnd() const |
2678 | -{ |
2679 | - return (d->result == KFilterBase::End) |
2680 | - && QIODevice::atEnd() // take QIODevice's internal buffer into account |
2681 | - && d->filter->device()->atEnd(); |
2682 | -} |
2683 | - |
2684 | -qint64 KFilterDev::readData( char *data, qint64 maxlen ) |
2685 | -{ |
2686 | - Q_ASSERT ( d->filter->mode() == QIODevice::ReadOnly ); |
2687 | - //qDebug() << "KFilterDev::read maxlen=" << maxlen; |
2688 | - KFilterBase* filter = d->filter; |
2689 | - |
2690 | - uint dataReceived = 0; |
2691 | - |
2692 | - // We came to the end of the stream |
2693 | - if ( d->result == KFilterBase::End ) |
2694 | - return dataReceived; |
2695 | - |
2696 | - // If we had an error, return -1. |
2697 | - if ( d->result != KFilterBase::Ok ) |
2698 | - return -1; |
2699 | - |
2700 | - |
2701 | - qint64 outBufferSize; |
2702 | - if ( d->bIgnoreData ) |
2703 | - { |
2704 | - outBufferSize = qMin( maxlen, (qint64)3*BUFFER_SIZE ); |
2705 | - } |
2706 | - else |
2707 | - { |
2708 | - outBufferSize = maxlen; |
2709 | - } |
2710 | - outBufferSize -= dataReceived; |
2711 | - qint64 availOut = outBufferSize; |
2712 | - filter->setOutBuffer( data, outBufferSize ); |
2713 | - |
2714 | - bool decompressedAll = false; |
2715 | - while ( dataReceived < maxlen ) |
2716 | - { |
2717 | - if (filter->inBufferEmpty()) |
2718 | - { |
2719 | - // Not sure about the best size to set there. |
2720 | - // For sure, it should be bigger than the header size (see comment in readHeader) |
2721 | - d->buffer.resize( BUFFER_SIZE ); |
2722 | - // Request data from underlying device |
2723 | - int size = filter->device()->read( d->buffer.data(), |
2724 | - d->buffer.size() ); |
2725 | - if ( size ) |
2726 | - filter->setInBuffer( d->buffer.data(), size ); |
2727 | - else { |
2728 | - if ( decompressedAll ) |
2729 | - { |
2730 | - // We decoded everything there was to decode. So -> done. |
2731 | - //qDebug() << "Seems we're done. dataReceived=" << dataReceived; |
2732 | - d->result = KFilterBase::End; |
2733 | - break; |
2734 | - } |
2735 | - } |
2736 | - //qDebug() << "KFilterDev::read got " << size << " bytes from device"; |
2737 | - } |
2738 | - if (d->bNeedHeader) |
2739 | - { |
2740 | - (void) filter->readHeader(); |
2741 | - d->bNeedHeader = false; |
2742 | - } |
2743 | - |
2744 | - d->result = filter->uncompress(); |
2745 | - |
2746 | - if (d->result == KFilterBase::Error) |
2747 | - { |
2748 | - qWarning() << "KFilterDev: Error when uncompressing data"; |
2749 | - break; |
2750 | - } |
2751 | - |
2752 | - // We got that much data since the last time we went here |
2753 | - uint outReceived = availOut - filter->outBufferAvailable(); |
2754 | - //qDebug() << "avail_out = " << filter->outBufferAvailable() << " result=" << d->result << " outReceived=" << outReceived; |
2755 | - if( availOut < (uint)filter->outBufferAvailable() ) |
2756 | - qWarning() << " last availOut " << availOut << " smaller than new avail_out=" << filter->outBufferAvailable() << " !"; |
2757 | - |
2758 | - dataReceived += outReceived; |
2759 | - if ( !d->bIgnoreData ) // Move on in the output buffer |
2760 | - { |
2761 | - data += outReceived; |
2762 | - availOut = maxlen - dataReceived; |
2763 | - } |
2764 | - else if ( maxlen - dataReceived < outBufferSize ) |
2765 | - { |
2766 | - availOut = maxlen - dataReceived; |
2767 | - } |
2768 | - if (d->result == KFilterBase::End) |
2769 | - { |
2770 | - //qDebug() << "KFilterDev::read got END. dataReceived=" << dataReceived; |
2771 | - break; // Finished. |
2772 | - } |
2773 | - if (filter->inBufferEmpty() && filter->outBufferAvailable() != 0 ) |
2774 | - { |
2775 | - decompressedAll = true; |
2776 | - } |
2777 | - filter->setOutBuffer( data, availOut ); |
2778 | - } |
2779 | - |
2780 | - return dataReceived; |
2781 | -} |
2782 | - |
2783 | -qint64 KFilterDev::writeData( const char *data /*0 to finish*/, qint64 len ) |
2784 | -{ |
2785 | - KFilterBase* filter = d->filter; |
2786 | - Q_ASSERT ( filter->mode() == QIODevice::WriteOnly ); |
2787 | - // If we had an error, return 0. |
2788 | - if ( d->result != KFilterBase::Ok ) |
2789 | - return 0; |
2790 | - |
2791 | - bool finish = (data == 0L); |
2792 | - if (!finish) |
2793 | - { |
2794 | - filter->setInBuffer( data, len ); |
2795 | - if (d->bNeedHeader) |
2796 | - { |
2797 | - (void)filter->writeHeader( d->origFileName ); |
2798 | - d->bNeedHeader = false; |
2799 | - } |
2800 | - } |
2801 | - |
2802 | - uint dataWritten = 0; |
2803 | - uint availIn = len; |
2804 | - while ( dataWritten < len || finish ) |
2805 | - { |
2806 | - |
2807 | - d->result = filter->compress( finish ); |
2808 | - |
2809 | - if (d->result == KFilterBase::Error) |
2810 | - { |
2811 | - qWarning() << "KFilterDev: Error when compressing data"; |
2812 | - // What to do ? |
2813 | - break; |
2814 | - } |
2815 | - |
2816 | - // Wrote everything ? |
2817 | - if (filter->inBufferEmpty() || (d->result == KFilterBase::End)) |
2818 | - { |
2819 | - // We got that much data since the last time we went here |
2820 | - uint wrote = availIn - filter->inBufferAvailable(); |
2821 | - |
2822 | - //qDebug() << " Wrote everything for now. avail_in = " << filter->inBufferAvailable() << " result=" << d->result << " wrote=" << wrote; |
2823 | - |
2824 | - // Move on in the input buffer |
2825 | - data += wrote; |
2826 | - dataWritten += wrote; |
2827 | - |
2828 | - availIn = len - dataWritten; |
2829 | - //qDebug() << " KFilterDev::write availIn=" << availIn << " dataWritten=" << dataWritten << " ioIndex=" << pos(); |
2830 | - if ( availIn > 0 ) // Not sure this will ever happen |
2831 | - filter->setInBuffer( data, availIn ); |
2832 | - } |
2833 | - |
2834 | - if (filter->outBufferFull() || (d->result == KFilterBase::End)) |
2835 | - { |
2836 | - //qDebug() << " KFilterDev::write writing to underlying. avail_out=" << filter->outBufferAvailable(); |
2837 | - int towrite = d->buffer.size() - filter->outBufferAvailable(); |
2838 | - if ( towrite > 0 ) |
2839 | - { |
2840 | - // Write compressed data to underlying device |
2841 | - int size = filter->device()->write( d->buffer.data(), towrite ); |
2842 | - if ( size != towrite ) { |
2843 | - qWarning() << "KFilterDev::write. Could only write " << size << " out of " << towrite << " bytes"; |
2844 | - return 0; // indicate an error (happens on disk full) |
2845 | - } |
2846 | - //else |
2847 | - //qDebug() << " KFilterDev::write wrote " << size << " bytes"; |
2848 | - } |
2849 | - d->buffer.resize( 8*1024 ); |
2850 | - filter->setOutBuffer( d->buffer.data(), d->buffer.size() ); |
2851 | - if (d->result == KFilterBase::End) |
2852 | - { |
2853 | - //qDebug() << " KFilterDev::write END"; |
2854 | - Q_ASSERT(finish); // hopefully we don't get end before finishing |
2855 | - break; |
2856 | - } |
2857 | - } |
2858 | - } |
2859 | - |
2860 | - return dataWritten; |
2861 | -} |
2862 | - |
2863 | -void KFilterDev::setOrigFileName( const QByteArray & fileName ) |
2864 | -{ |
2865 | - d->origFileName = fileName; |
2866 | -} |
2867 | - |
2868 | -void KFilterDev::setSkipHeaders() |
2869 | -{ |
2870 | - d->bSkipHeaders = true; |
2871 | -} |
2872 | |
2873 | === removed file 'src/core/external/kfilter/kfilterdev.h' |
2874 | --- src/core/external/kfilter/kfilterdev.h 2010-04-15 12:28:34 +0000 |
2875 | +++ src/core/external/kfilter/kfilterdev.h 1970-01-01 00:00:00 +0000 |
2876 | @@ -1,153 +0,0 @@ |
2877 | -/* This file is part of the KDE libraries |
2878 | - Copyright (C) 2000 David Faure <faure@kde.org> |
2879 | - |
2880 | - This library is free software; you can redistribute it and/or |
2881 | - modify it under the terms of the GNU Library General Public |
2882 | - License version 2 as published by the Free Software Foundation. |
2883 | - |
2884 | - This library is distributed in the hope that it will be useful, |
2885 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
2886 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2887 | - Library General Public License for more details. |
2888 | - |
2889 | - You should have received a copy of the GNU Library General Public License |
2890 | - along with this library; see the file COPYING.LIB. If not, write to |
2891 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
2892 | - Boston, MA 02110-1301, USA. |
2893 | -*/ |
2894 | -#ifndef __kfilterdev_h |
2895 | -#define __kfilterdev_h |
2896 | - |
2897 | -#include <QtCore/QIODevice> |
2898 | -#include <QtCore/QString> |
2899 | - |
2900 | -class QFile; |
2901 | -class KFilterBase; |
2902 | - |
2903 | -/** |
2904 | - * A class for reading and writing compressed data onto a device |
2905 | - * (e.g. file, but other usages are possible, like a buffer or a socket). |
2906 | - * |
2907 | - * To simply read/write compressed files, see deviceForFile. |
2908 | - * |
2909 | - * @author David Faure <faure@kde.org> |
2910 | - */ |
2911 | -class KFilterDev : public QIODevice |
2912 | -{ |
2913 | -public: |
2914 | - /** |
2915 | - * Destructs the KFilterDev. |
2916 | - * Calls close() if the filter device is still open. |
2917 | - */ |
2918 | - virtual ~KFilterDev(); |
2919 | - |
2920 | - /** |
2921 | - * Open for reading or writing. |
2922 | - * If the KFilterBase's device is not opened, it will be opened. |
2923 | - */ |
2924 | - virtual bool open( QIODevice::OpenMode mode ); |
2925 | - /** |
2926 | - * Close after reading or writing. |
2927 | - * If the KFilterBase's device was opened by open(), it will be closed. |
2928 | - */ |
2929 | - virtual void close(); |
2930 | - |
2931 | - /** |
2932 | - * For writing gzip compressed files only: |
2933 | - * set the name of the original file, to be used in the gzip header. |
2934 | - * @param fileName the name of the original file |
2935 | - */ |
2936 | - void setOrigFileName( const QByteArray & fileName ); |
2937 | - |
2938 | - /** |
2939 | - * Call this let this device skip the gzip headers when reading/writing. |
2940 | - * This way KFilterDev (with gzip filter) can be used as a direct wrapper |
2941 | - * around zlib - this is used by KZip. |
2942 | - */ |
2943 | - void setSkipHeaders(); |
2944 | - |
2945 | - /** |
2946 | - * That one can be quite slow, when going back. Use with care. |
2947 | - */ |
2948 | - virtual bool seek( qint64 ); |
2949 | - |
2950 | - virtual bool atEnd() const; |
2951 | - |
2952 | - /// Reimplemented to return true. KFilterDev is a sequential QIODevice. |
2953 | - /// Well, not really, since it supports seeking and KZip uses that. |
2954 | - //virtual bool isSequential() const { return true; } |
2955 | - |
2956 | -public: |
2957 | - |
2958 | - |
2959 | - // KDE4 TODO: turn those static methods into constructors |
2960 | - |
2961 | - /** |
2962 | - * Creates an i/o device that is able to read from @p fileName, |
2963 | - * whether it's compressed or not. Available compression filters |
2964 | - * (gzip/bzip2 etc.) will automatically be used. |
2965 | - * |
2966 | - * The compression filter to be used is determined from the @p fileName |
2967 | - * if @p mimetype is empty. Pass "application/x-gzip" or "application/x-bzip" |
2968 | - * to force the corresponding decompression filter, if available. |
2969 | - * |
2970 | - * Warning: application/x-bzip may not be available. |
2971 | - * In that case a QFile opened on the compressed data will be returned ! |
2972 | - * Use KFilterBase::findFilterByMimeType and code similar to what |
2973 | - * deviceForFile is doing, to better control what's happening. |
2974 | - * |
2975 | - * The returned QIODevice has to be deleted after using. |
2976 | - * |
2977 | - * @param fileName the name of the file to filter |
2978 | - * @param mimetype the mime type of the file to filter, or QString() if unknown |
2979 | - * @param forceFilter if true, the function will either find a compression filter, or return 0. |
2980 | - * If false, it will always return a QIODevice. If no |
2981 | - * filter is available it will return a simple QFile. |
2982 | - * This can be useful if the file is usable without a filter. |
2983 | - * @return if a filter has been found, the QIODevice for the filter. If the |
2984 | - * filter does not exist, the return value depends on @p forceFilter. |
2985 | - * The returned QIODevice has to be deleted after using. |
2986 | - */ |
2987 | - static QIODevice * deviceForFile( const QString & fileName, const QString & mimetype = QString(), |
2988 | - bool forceFilter = false ); |
2989 | - |
2990 | - /** |
2991 | - * Creates an i/o device that is able to read from the QIODevice @p inDevice, |
2992 | - * whether the data is compressed or not. Available compression filters |
2993 | - * (gzip/bzip2 etc.) will automatically be used. |
2994 | - * |
2995 | - * The compression filter to be used is determined @p mimetype . |
2996 | - * Pass "application/x-gzip" or "application/x-bzip" |
2997 | - * to use the corresponding decompression filter. |
2998 | - * |
2999 | - * Warning: application/x-bzip may not be available. |
3000 | - * In that case 0 will be returned ! |
3001 | - * |
3002 | - * The returned QIODevice has to be deleted after using. |
3003 | - * @param inDevice input device. Won't be deleted if @p autoDeleteInDevice = false |
3004 | - * @param mimetype the mime type for the filter |
3005 | - * @param autoDeleteInDevice if true, @p inDevice will be deleted automatically |
3006 | - * @return a QIODevice that filters the original stream. Must be deleted after |
3007 | - * using |
3008 | - */ |
3009 | - static QIODevice * device( QIODevice* inDevice, const QString & mimetype, bool autoDeleteInDevice = true ); |
3010 | - |
3011 | -protected: |
3012 | - virtual qint64 readData( char *data, qint64 maxlen ); |
3013 | - virtual qint64 writeData( const char *data, qint64 len ); |
3014 | - |
3015 | -private: |
3016 | - /** |
3017 | - * Constructs a KFilterDev for a given filter (e.g. gzip, bzip2 etc.). |
3018 | - * @param filter the KFilterBase to use |
3019 | - * @param autoDeleteFilterBase when true this object will become the |
3020 | - * owner of @p filter. |
3021 | - */ |
3022 | - explicit KFilterDev( KFilterBase * filter, bool autoDeleteFilterBase = false ); |
3023 | -private: |
3024 | - class Private; |
3025 | - Private* const d; |
3026 | -}; |
3027 | - |
3028 | - |
3029 | -#endif |
3030 | |
3031 | === removed file 'src/core/external/kfilter/kgzipfilter.cpp' |
3032 | --- src/core/external/kfilter/kgzipfilter.cpp 2010-04-15 12:28:34 +0000 |
3033 | +++ src/core/external/kfilter/kgzipfilter.cpp 1970-01-01 00:00:00 +0000 |
3034 | @@ -1,333 +0,0 @@ |
3035 | -/* This file is part of the KDE libraries |
3036 | - Copyright (C) 2000-2005 David Faure <faure@kde.org> |
3037 | - |
3038 | - This library is free software; you can redistribute it and/or |
3039 | - modify it under the terms of the GNU Library General Public |
3040 | - License version 2 as published by the Free Software Foundation. |
3041 | - |
3042 | - This library is distributed in the hope that it will be useful, |
3043 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
3044 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3045 | - Library General Public License for more details. |
3046 | - |
3047 | - You should have received a copy of the GNU Library General Public License |
3048 | - along with this library; see the file COPYING.LIB. If not, write to |
3049 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
3050 | - Boston, MA 02110-1301, USA. |
3051 | -*/ |
3052 | - |
3053 | -#include "kgzipfilter.h" |
3054 | - |
3055 | -#include <time.h> |
3056 | -#include <zlib.h> |
3057 | -#include <QtCore/QIODevice> |
3058 | -#include <QDebug> |
3059 | - |
3060 | -/* gzip flag byte */ |
3061 | -#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ |
3062 | -#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */ |
3063 | -#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ |
3064 | -#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ |
3065 | -#define COMMENT 0x10 /* bit 4 set: file comment present */ |
3066 | -#define RESERVED 0xE0 /* bits 5..7: reserved */ |
3067 | - |
3068 | -// #define DEBUG_GZIP |
3069 | - |
3070 | -class KGzipFilter::Private |
3071 | -{ |
3072 | -public: |
3073 | - Private() |
3074 | - { |
3075 | - zStream.zalloc = (alloc_func)0; |
3076 | - zStream.zfree = (free_func)0; |
3077 | - zStream.opaque = (voidpf)0; |
3078 | - headerWritten = false; |
3079 | - compressed = false; |
3080 | - mode = 0; |
3081 | - } |
3082 | - |
3083 | - z_stream zStream; |
3084 | - bool headerWritten; |
3085 | - bool compressed; |
3086 | - int mode; |
3087 | - ulong crc; |
3088 | -}; |
3089 | - |
3090 | -KGzipFilter::KGzipFilter() |
3091 | - : d(new Private) |
3092 | -{ |
3093 | -} |
3094 | - |
3095 | - |
3096 | -KGzipFilter::~KGzipFilter() |
3097 | -{ |
3098 | - delete d; |
3099 | -} |
3100 | - |
3101 | -void KGzipFilter::init( int mode ) |
3102 | -{ |
3103 | - d->zStream.next_in = Z_NULL; |
3104 | - d->zStream.avail_in = 0; |
3105 | - if ( mode == QIODevice::ReadOnly ) |
3106 | - { |
3107 | - int result = inflateInit2(&d->zStream, -MAX_WBITS); // windowBits is passed < 0 to suppress zlib header |
3108 | - if ( result != Z_OK ) |
3109 | - qDebug() << "inflateInit returned " << result; |
3110 | - // No idea what to do with result :) |
3111 | - } else if ( mode == QIODevice::WriteOnly ) |
3112 | - { |
3113 | - int result = deflateInit2(&d->zStream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY); // same here |
3114 | - if ( result != Z_OK ) |
3115 | - qDebug() << "deflateInit returned " << result; |
3116 | - } else { |
3117 | - qWarning() << "KGzipFilter: Unsupported mode " << mode << ". Only QIODevice::ReadOnly and QIODevice::WriteOnly supported"; |
3118 | - } |
3119 | - d->mode = mode; |
3120 | - d->compressed = true; |
3121 | - d->headerWritten = false; |
3122 | -} |
3123 | - |
3124 | -int KGzipFilter::mode() const |
3125 | -{ |
3126 | - return d->mode; |
3127 | -} |
3128 | - |
3129 | -void KGzipFilter::terminate() |
3130 | -{ |
3131 | - if ( d->mode == QIODevice::ReadOnly ) |
3132 | - { |
3133 | - int result = inflateEnd(&d->zStream); |
3134 | - if ( result != Z_OK ) |
3135 | - qDebug() << "inflateEnd returned " << result; |
3136 | - } else if ( d->mode == QIODevice::WriteOnly ) |
3137 | - { |
3138 | - int result = deflateEnd(&d->zStream); |
3139 | - if ( result != Z_OK ) |
3140 | - qDebug() << "deflateEnd returned " << result; |
3141 | - } |
3142 | -} |
3143 | - |
3144 | - |
3145 | -void KGzipFilter::reset() |
3146 | -{ |
3147 | - if ( d->mode == QIODevice::ReadOnly ) |
3148 | - { |
3149 | - int result = inflateReset(&d->zStream); |
3150 | - if ( result != Z_OK ) |
3151 | - qDebug() << "inflateReset returned " << result; |
3152 | - } else if ( d->mode == QIODevice::WriteOnly ) { |
3153 | - int result = deflateReset(&d->zStream); |
3154 | - if ( result != Z_OK ) |
3155 | - qDebug() << "deflateReset returned " << result; |
3156 | - d->headerWritten = false; |
3157 | - } |
3158 | -} |
3159 | - |
3160 | -bool KGzipFilter::readHeader() |
3161 | -{ |
3162 | -#ifdef DEBUG_GZIP |
3163 | - qDebug() << "KGzipFilter::readHeader avail=" << d->zStream.avail_in; |
3164 | -#endif |
3165 | - // Assume not compressed until we successfully decode the header |
3166 | - d->compressed = false; |
3167 | - // Assume the first block of data contains the whole header. |
3168 | - // The right way is to build this as a big state machine which |
3169 | - // is a pain in the ass. |
3170 | - // With 8K-blocks, we don't risk much anyway. |
3171 | - Bytef *p = d->zStream.next_in; |
3172 | - int i = d->zStream.avail_in; |
3173 | - if ((i -= 10) < 0) return false; // Need at least 10 bytes |
3174 | -#ifdef DEBUG_GZIP |
3175 | - qDebug() << "KGzipFilter::readHeader first byte is " << QString::number(*p,16); |
3176 | -#endif |
3177 | - if (*p++ != 0x1f) return false; // GZip magic |
3178 | -#ifdef DEBUG_GZIP |
3179 | - qDebug() << "KGzipFilter::readHeader second byte is " << QString::number(*p,16); |
3180 | -#endif |
3181 | - if (*p++ != 0x8b) return false; |
3182 | - int method = *p++; |
3183 | - int flags = *p++; |
3184 | - if ((method != Z_DEFLATED) || (flags & RESERVED) != 0) return false; |
3185 | - p += 6; |
3186 | - if ((flags & EXTRA_FIELD) != 0) // skip extra field |
3187 | - { |
3188 | - if ((i -= 2) < 0) return false; // Need at least 2 bytes |
3189 | - int len = *p++; |
3190 | - len += (*p++) << 8; |
3191 | - if ((i -= len) < 0) return false; // Need at least len bytes |
3192 | - p += len; |
3193 | - } |
3194 | - if ((flags & ORIG_NAME) != 0) // skip original file name |
3195 | - { |
3196 | -#ifdef DEBUG_GZIP |
3197 | - qDebug() << "ORIG_NAME=" << (char*)p; |
3198 | -#endif |
3199 | - while( (i > 0) && (*p)) |
3200 | - { |
3201 | - i--; p++; |
3202 | - } |
3203 | - if (--i <= 0) return false; |
3204 | - p++; |
3205 | - } |
3206 | - if ((flags & COMMENT) != 0) // skip comment |
3207 | - { |
3208 | - while( (i > 0) && (*p)) |
3209 | - { |
3210 | - i--; p++; |
3211 | - } |
3212 | - if (--i <= 0) return false; |
3213 | - p++; |
3214 | - } |
3215 | - if ((flags & HEAD_CRC) != 0) // skip the header crc |
3216 | - { |
3217 | - if ((i-=2) < 0) return false; |
3218 | - p += 2; |
3219 | - } |
3220 | - |
3221 | - d->zStream.avail_in = i; |
3222 | - d->zStream.next_in = p; |
3223 | - d->compressed = true; |
3224 | -#ifdef DEBUG_GZIP |
3225 | - qDebug() << "header OK"; |
3226 | -#endif |
3227 | - return true; |
3228 | -} |
3229 | - |
3230 | -/* Output a 16 bit value, lsb first */ |
3231 | -#define put_short(w) \ |
3232 | - *p++ = (uchar) ((w) & 0xff); \ |
3233 | - *p++ = (uchar) ((ushort)(w) >> 8); |
3234 | - |
3235 | -/* Output a 32 bit value to the bit stream, lsb first */ |
3236 | -#define put_long(n) \ |
3237 | - put_short((n) & 0xffff); \ |
3238 | - put_short(((ulong)(n)) >> 16); |
3239 | - |
3240 | -bool KGzipFilter::writeHeader( const QByteArray & fileName ) |
3241 | -{ |
3242 | - Bytef *p = d->zStream.next_out; |
3243 | - int i = d->zStream.avail_out; |
3244 | - *p++ = 0x1f; |
3245 | - *p++ = 0x8b; |
3246 | - *p++ = Z_DEFLATED; |
3247 | - *p++ = ORIG_NAME; |
3248 | - put_long( time( 0L ) ); // Modification time (in unix format) |
3249 | - *p++ = 0; // Extra flags (2=max compress, 4=fastest compress) |
3250 | - *p++ = 3; // Unix |
3251 | - |
3252 | - uint len = fileName.length(); |
3253 | - for ( uint j = 0 ; j < len ; ++j ) |
3254 | - *p++ = fileName[j]; |
3255 | - *p++ = 0; |
3256 | - int headerSize = p - d->zStream.next_out; |
3257 | - i -= headerSize; |
3258 | - Q_ASSERT(i>0); |
3259 | - d->crc = crc32(0L, Z_NULL, 0); |
3260 | - d->zStream.next_out = p; |
3261 | - d->zStream.avail_out = i; |
3262 | - d->headerWritten = true; |
3263 | - return true; |
3264 | -} |
3265 | - |
3266 | -void KGzipFilter::writeFooter() |
3267 | -{ |
3268 | - Q_ASSERT( d->headerWritten ); |
3269 | - //if (!d->headerWritten) qDebug() << kBacktrace(); |
3270 | - Bytef *p = d->zStream.next_out; |
3271 | - int i = d->zStream.avail_out; |
3272 | - //qDebug() << "KGzipFilter::writeFooter writing CRC= " << QString::number( d->crc, 16 ); |
3273 | - put_long( d->crc ); |
3274 | - //qDebug() << "KGzipFilter::writing writing totalin= " << d->zStream.total_in; |
3275 | - put_long( d->zStream.total_in ); |
3276 | - i -= p - d->zStream.next_out; |
3277 | - d->zStream.next_out = p; |
3278 | - d->zStream.avail_out = i; |
3279 | -} |
3280 | - |
3281 | -void KGzipFilter::setOutBuffer( char * data, uint maxlen ) |
3282 | -{ |
3283 | - d->zStream.avail_out = maxlen; |
3284 | - d->zStream.next_out = (Bytef *) data; |
3285 | -} |
3286 | -void KGzipFilter::setInBuffer( const char * data, uint size ) |
3287 | -{ |
3288 | -#ifdef DEBUG_GZIP |
3289 | - qDebug() << "KGzipFilter::setInBuffer avail_in=" << size; |
3290 | -#endif |
3291 | - d->zStream.avail_in = size; |
3292 | - d->zStream.next_in = (Bytef*) data; |
3293 | -} |
3294 | -int KGzipFilter::inBufferAvailable() const |
3295 | -{ |
3296 | - return d->zStream.avail_in; |
3297 | -} |
3298 | -int KGzipFilter::outBufferAvailable() const |
3299 | -{ |
3300 | - return d->zStream.avail_out; |
3301 | -} |
3302 | - |
3303 | -KGzipFilter::Result KGzipFilter::uncompress_noop() |
3304 | -{ |
3305 | - // I'm not sure we really need support for that (uncompressed streams), |
3306 | - // but why not, it can't hurt to have it. One case I can think of is someone |
3307 | - // naming a tar file "blah.tar.gz" :-) |
3308 | - if ( d->zStream.avail_in > 0 ) |
3309 | - { |
3310 | - int n = (d->zStream.avail_in < d->zStream.avail_out) ? d->zStream.avail_in : d->zStream.avail_out; |
3311 | - memcpy( d->zStream.next_out, d->zStream.next_in, n ); |
3312 | - d->zStream.avail_out -= n; |
3313 | - d->zStream.next_in += n; |
3314 | - d->zStream.avail_in -= n; |
3315 | - return KFilterBase::Ok; |
3316 | - } else |
3317 | - return KFilterBase::End; |
3318 | -} |
3319 | - |
3320 | -KGzipFilter::Result KGzipFilter::uncompress() |
3321 | -{ |
3322 | - Q_ASSERT ( d->mode == QIODevice::ReadOnly ); |
3323 | - if ( d->compressed ) |
3324 | - { |
3325 | -#ifdef DEBUG_GZIP |
3326 | - qDebug() << "Calling inflate with avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable(); |
3327 | - qDebug() << " next_in=" << d->zStream.next_in; |
3328 | -#endif |
3329 | - int result = inflate(&d->zStream, Z_SYNC_FLUSH); |
3330 | -#ifdef DEBUG_GZIP |
3331 | - qDebug() << " -> inflate returned " << result; |
3332 | - qDebug() << "Now avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable(); |
3333 | - qDebug() << " next_in=" << d->zStream.next_in; |
3334 | -#else |
3335 | - if ( result != Z_OK && result != Z_STREAM_END ) |
3336 | - qDebug() << "Warning: inflate() returned " << result; |
3337 | -#endif |
3338 | - return ( result == Z_OK ? KFilterBase::Ok : ( result == Z_STREAM_END ? KFilterBase::End : KFilterBase::Error ) ); |
3339 | - } else |
3340 | - return uncompress_noop(); |
3341 | -} |
3342 | - |
3343 | -KGzipFilter::Result KGzipFilter::compress( bool finish ) |
3344 | -{ |
3345 | - Q_ASSERT ( d->compressed ); |
3346 | - Q_ASSERT ( d->mode == QIODevice::WriteOnly ); |
3347 | - |
3348 | - Bytef* p = d->zStream.next_in; |
3349 | - ulong len = d->zStream.avail_in; |
3350 | -#ifdef DEBUG_GZIP |
3351 | - qDebug() << " calling deflate with avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable(); |
3352 | -#endif |
3353 | - int result = deflate(&d->zStream, finish ? Z_FINISH : Z_NO_FLUSH); |
3354 | - if ( result != Z_OK && result != Z_STREAM_END ) |
3355 | - qDebug() << " deflate returned " << result; |
3356 | - if ( d->headerWritten ) |
3357 | - { |
3358 | - //qDebug() << "Computing CRC for the next " << len - d->zStream.avail_in << " bytes"; |
3359 | - d->crc = crc32(d->crc, p, len - d->zStream.avail_in); |
3360 | - } |
3361 | - if ( result == Z_STREAM_END && d->headerWritten ) |
3362 | - { |
3363 | - //qDebug() << "KGzipFilter::compress finished, write footer"; |
3364 | - writeFooter(); |
3365 | - } |
3366 | - return ( result == Z_OK ? KFilterBase::Ok : ( result == Z_STREAM_END ? KFilterBase::End : KFilterBase::Error ) ); |
3367 | -} |
3368 | |
3369 | === removed file 'src/core/external/kfilter/kgzipfilter.h' |
3370 | --- src/core/external/kfilter/kgzipfilter.h 2010-04-15 12:28:34 +0000 |
3371 | +++ src/core/external/kfilter/kgzipfilter.h 1970-01-01 00:00:00 +0000 |
3372 | @@ -1,54 +0,0 @@ |
3373 | -/* This file is part of the KDE libraries |
3374 | - Copyright (C) 2000 David Faure <faure@kde.org> |
3375 | - |
3376 | - This library is free software; you can redistribute it and/or |
3377 | - modify it under the terms of the GNU Library General Public |
3378 | - License version 2 as published by the Free Software Foundation. |
3379 | - |
3380 | - This library is distributed in the hope that it will be useful, |
3381 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
3382 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3383 | - Library General Public License for more details. |
3384 | - |
3385 | - You should have received a copy of the GNU Library General Public License |
3386 | - along with this library; see the file COPYING.LIB. If not, write to |
3387 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
3388 | - Boston, MA 02110-1301, USA. |
3389 | -*/ |
3390 | - |
3391 | -#ifndef __kgzipfilter__h |
3392 | -#define __kgzipfilter__h |
3393 | - |
3394 | -#include "kfilterbase.h" |
3395 | - |
3396 | -/** |
3397 | - * Internal class used by KFilterDev |
3398 | - * @internal |
3399 | - */ |
3400 | -class KGzipFilter : public KFilterBase |
3401 | -{ |
3402 | -public: |
3403 | - KGzipFilter(); |
3404 | - virtual ~KGzipFilter(); |
3405 | - |
3406 | - virtual void init( int mode ); |
3407 | - virtual int mode() const; |
3408 | - virtual void terminate(); |
3409 | - virtual void reset(); |
3410 | - virtual bool readHeader(); |
3411 | - virtual bool writeHeader( const QByteArray & fileName ); |
3412 | - void writeFooter(); |
3413 | - virtual void setOutBuffer( char * data, uint maxlen ); |
3414 | - virtual void setInBuffer( const char * data, uint size ); |
3415 | - virtual int inBufferAvailable() const; |
3416 | - virtual int outBufferAvailable() const; |
3417 | - virtual Result uncompress(); |
3418 | - virtual Result compress( bool finish ); |
3419 | - |
3420 | -private: |
3421 | - Result uncompress_noop(); |
3422 | - class Private; |
3423 | - Private* const d; |
3424 | -}; |
3425 | - |
3426 | -#endif |
3427 | |
3428 | === removed file 'src/core/external/kfilter/klimitediodevice.cpp' |
3429 | --- src/core/external/kfilter/klimitediodevice.cpp 2010-04-15 12:28:34 +0000 |
3430 | +++ src/core/external/kfilter/klimitediodevice.cpp 1970-01-01 00:00:00 +0000 |
3431 | @@ -1,77 +0,0 @@ |
3432 | -/* This file is part of the KDE libraries |
3433 | - Copyright (C) 2001, 2002, 2007 David Faure <faure@kde.org> |
3434 | - |
3435 | - This library is free software; you can redistribute it and/or |
3436 | - modify it under the terms of the GNU Library General Public |
3437 | - License version 2 as published by the Free Software Foundation. |
3438 | - |
3439 | - This library is distributed in the hope that it will be useful, |
3440 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
3441 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3442 | - Library General Public License for more details. |
3443 | - |
3444 | - You should have received a copy of the GNU Library General Public License |
3445 | - along with this library; see the file COPYING.LIB. If not, write to |
3446 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
3447 | - Boston, MA 02110-1301, USA. |
3448 | -*/ |
3449 | - |
3450 | -#include "klimitediodevice.h" |
3451 | -#include <QDebug> |
3452 | - |
3453 | -KLimitedIODevice::KLimitedIODevice( QIODevice *dev, int start, int length ) |
3454 | - : m_dev( dev ), m_start( start ), m_length( length ) |
3455 | -{ |
3456 | - //kDebug(7005) << "start=" << start << "length=" << length; |
3457 | - open( QIODevice::ReadOnly ); //krazy:exclude=syscalls |
3458 | -} |
3459 | - |
3460 | -bool KLimitedIODevice::open( QIODevice::OpenMode m ) |
3461 | -{ |
3462 | - //kDebug(7005) << "m=" << m; |
3463 | - if ( m & QIODevice::ReadOnly ) { |
3464 | - /*bool ok = false; |
3465 | - if ( m_dev->isOpen() ) |
3466 | - ok = ( m_dev->mode() == QIODevice::ReadOnly ); |
3467 | - else |
3468 | - ok = m_dev->open( m ); |
3469 | - if ( ok )*/ |
3470 | - m_dev->seek( m_start ); // No concurrent access ! |
3471 | - } |
3472 | - else |
3473 | - qWarning() << "KLimitedIODevice::open only supports QIODevice::ReadOnly!"; |
3474 | - setOpenMode( QIODevice::ReadOnly ); |
3475 | - return true; |
3476 | -} |
3477 | - |
3478 | -void KLimitedIODevice::close() |
3479 | -{ |
3480 | -} |
3481 | - |
3482 | -qint64 KLimitedIODevice::size() const |
3483 | -{ |
3484 | - return m_length; |
3485 | -} |
3486 | - |
3487 | -qint64 KLimitedIODevice::readData( char * data, qint64 maxlen ) |
3488 | -{ |
3489 | - maxlen = qMin( maxlen, m_length - pos() ); // Apply upper limit |
3490 | - return m_dev->read( data, maxlen ); |
3491 | -} |
3492 | - |
3493 | -bool KLimitedIODevice::seek( qint64 pos ) |
3494 | -{ |
3495 | - Q_ASSERT( pos <= m_length ); |
3496 | - pos = qMin( pos, m_length ); // Apply upper limit |
3497 | - return m_dev->seek( m_start + pos ); |
3498 | -} |
3499 | - |
3500 | -qint64 KLimitedIODevice::bytesAvailable() const |
3501 | -{ |
3502 | - return m_length + QIODevice::bytesAvailable(); |
3503 | -} |
3504 | - |
3505 | -bool KLimitedIODevice::isSequential() const |
3506 | -{ |
3507 | - return m_dev->isSequential(); |
3508 | -} |
3509 | |
3510 | === removed file 'src/core/external/kfilter/klimitediodevice.h' |
3511 | --- src/core/external/kfilter/klimitediodevice.h 2010-04-15 12:28:34 +0000 |
3512 | +++ src/core/external/kfilter/klimitediodevice.h 1970-01-01 00:00:00 +0000 |
3513 | @@ -1,63 +0,0 @@ |
3514 | -/* This file is part of the KDE libraries |
3515 | - Copyright (C) 2001, 2002, 2007 David Faure <faure@kde.org> |
3516 | - |
3517 | - This library is free software; you can redistribute it and/or |
3518 | - modify it under the terms of the GNU Library General Public |
3519 | - License version 2 as published by the Free Software Foundation. |
3520 | - |
3521 | - This library is distributed in the hope that it will be useful, |
3522 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
3523 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3524 | - Library General Public License for more details. |
3525 | - |
3526 | - You should have received a copy of the GNU Library General Public License |
3527 | - along with this library; see the file COPYING.LIB. If not, write to |
3528 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
3529 | - Boston, MA 02110-1301, USA. |
3530 | -*/ |
3531 | - |
3532 | -#ifndef klimitediodevice_h |
3533 | -#define klimitediodevice_h |
3534 | - |
3535 | -#include <QtCore/QIODevice> |
3536 | -/** |
3537 | - * A readonly device that reads from an underlying device |
3538 | - * from a given point to another (e.g. to give access to a single |
3539 | - * file inside an archive). |
3540 | - * @author David Faure <faure@kde.org> |
3541 | - * @internal - used by KArchive |
3542 | - */ |
3543 | -class KLimitedIODevice : public QIODevice |
3544 | -{ |
3545 | -public: |
3546 | - /** |
3547 | - * Creates a new KLimitedIODevice. |
3548 | - * @param dev the underlying device, opened or not |
3549 | - * This device itself auto-opens (in readonly mode), no need to open it. |
3550 | - * @param start where to start reading (position in bytes) |
3551 | - * @param length the length of the data to read (in bytes) |
3552 | - */ |
3553 | - KLimitedIODevice( QIODevice *dev, int start, int length ); |
3554 | - virtual ~KLimitedIODevice() {} |
3555 | - |
3556 | - virtual bool isSequential() const; |
3557 | - |
3558 | - virtual bool open( QIODevice::OpenMode m ); |
3559 | - virtual void close(); |
3560 | - |
3561 | - virtual qint64 size() const; |
3562 | - |
3563 | - virtual qint64 readData ( char * data, qint64 maxlen ); |
3564 | - virtual qint64 writeData ( const char *, qint64 ) { return -1; } // unsupported |
3565 | - virtual int putChar( int ) { return -1; } // unsupported |
3566 | - |
3567 | - //virtual qint64 pos() const { return m_dev->pos() - m_start; } |
3568 | - virtual bool seek( qint64 pos ); |
3569 | - virtual qint64 bytesAvailable() const; |
3570 | -private: |
3571 | - QIODevice* m_dev; |
3572 | - qint64 m_start; |
3573 | - qint64 m_length; |
3574 | -}; |
3575 | - |
3576 | -#endif |
3577 | |
3578 | === removed file 'src/core/external/kfilter/kzip.cpp' |
3579 | --- src/core/external/kfilter/kzip.cpp 2013-01-08 17:47:37 +0000 |
3580 | +++ src/core/external/kfilter/kzip.cpp 1970-01-01 00:00:00 +0000 |
3581 | @@ -1,1402 +0,0 @@ |
3582 | -/* This file is part of the KDE libraries |
3583 | - Copyright (C) 2000 David Faure <faure@kde.org> |
3584 | - Copyright (C) 2002 Holger Schroeder <holger-kde@holgis.net> |
3585 | - |
3586 | - This library is free software; you can redistribute it and/or |
3587 | - modify it under the terms of the GNU Library General Public |
3588 | - License version 2 as published by the Free Software Foundation. |
3589 | - |
3590 | - This library is distributed in the hope that it will be useful, |
3591 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
3592 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3593 | - Library General Public License for more details. |
3594 | - |
3595 | - You should have received a copy of the GNU Library General Public License |
3596 | - along with this library; see the file COPYING.LIB. If not, write to |
3597 | - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
3598 | - Boston, MA 02110-1301, USA. |
3599 | -*/ |
3600 | - |
3601 | -/* |
3602 | - This class implements a kioslave to access ZIP files from KDE. |
3603 | - you can use it in QIODevice::ReadOnly or in QIODevice::WriteOnly mode, and it |
3604 | - behaves just as expected (i hope ;-) ). |
3605 | - It can also be used in QIODevice::ReadWrite mode, in this case one can |
3606 | - append files to an existing zip archive. when you append new files, which |
3607 | - are not yet in the zip, it works as expected, they are appended at the end. |
3608 | - when you append a file, which is already in the file, the reference to the |
3609 | - old file is dropped and the new one is added to the zip. but the |
3610 | - old data from the file itself is not deleted, it is still in the |
3611 | - zipfile. so when you want to have a small and garbagefree zipfile, |
3612 | - just read the contents of the appended zipfile and write it to a new one |
3613 | - in QIODevice::WriteOnly mode. especially take care of this, when you don't want |
3614 | - to leak information of how intermediate versions of files in the zip |
3615 | - were looking. |
3616 | - For more information on the zip fileformat go to |
3617 | - http://www.pkware.com/support/appnote.html . |
3618 | - |
3619 | -*/ |
3620 | - |
3621 | -#include "kzip.h" |
3622 | -#include "kfilterdev.h" |
3623 | -#include "klimitediodevice.h" |
3624 | - |
3625 | -#include <QtCore/QHash> |
3626 | -#include <QtCore/QByteArray> |
3627 | -#include <QtCore/QFile> |
3628 | -#include <QtCore/QDir> |
3629 | -#include <QtCore/QDate> |
3630 | -#include <QtCore/QList> |
3631 | -#include <QDebug> |
3632 | - |
3633 | -#include <zlib.h> |
3634 | -#include <time.h> |
3635 | -#include <string.h> |
3636 | -#include <sys/stat.h> |
3637 | - |
3638 | -#ifdef Q_OS_WIN |
3639 | -#include "kdewin32/sys/stat.h" |
3640 | -#endif |
3641 | - |
3642 | -const int max_path_len = 4095; // maximum number of character a path may contain |
3643 | - |
3644 | -static void transformToMsDos(const QDateTime& dt, char* buffer) |
3645 | -{ |
3646 | - if ( dt.isValid() ) |
3647 | - { |
3648 | - const quint16 time = |
3649 | - ( dt.time().hour() << 11 ) // 5 bit hour |
3650 | - | ( dt.time().minute() << 5 ) // 6 bit minute |
3651 | - | ( dt.time().second() >> 1 ); // 5 bit double seconds |
3652 | - |
3653 | - buffer[0] = char(time); |
3654 | - buffer[1] = char(time >> 8); |
3655 | - |
3656 | - const quint16 date = |
3657 | - ( ( dt.date().year() - 1980 ) << 9 ) // 7 bit year 1980-based |
3658 | - | ( dt.date().month() << 5 ) // 4 bit month |
3659 | - | ( dt.date().day() ); // 5 bit day |
3660 | - |
3661 | - buffer[2] = char(date); |
3662 | - buffer[3] = char(date >> 8); |
3663 | - } |
3664 | - else // !dt.isValid(), assume 1980-01-01 midnight |
3665 | - { |
3666 | - buffer[0] = 0; |
3667 | - buffer[1] = 0; |
3668 | - buffer[2] = 33; |
3669 | - buffer[3] = 0; |
3670 | - } |
3671 | -} |
3672 | - |
3673 | -static time_t transformFromMsDos(const char* buffer) |
3674 | -{ |
3675 | - quint16 time = (uchar)buffer[0] | ( (uchar)buffer[1] << 8 ); |
3676 | - int h = time >> 11; |
3677 | - int m = ( time & 0x7ff ) >> 5; |
3678 | - int s = ( time & 0x1f ) * 2 ; |
3679 | - QTime qt(h, m, s); |
3680 | - |
3681 | - quint16 date = (uchar)buffer[2] | ( (uchar)buffer[3] << 8 ); |
3682 | - int y = ( date >> 9 ) + 1980; |
3683 | - int o = ( date & 0x1ff ) >> 5; |
3684 | - int d = ( date & 0x1f ); |
3685 | - QDate qd(y, o, d); |
3686 | - |
3687 | - QDateTime dt( qd, qt ); |
3688 | - return dt.toTime_t(); |
3689 | -} |
3690 | - |
3691 | -// == parsing routines for zip headers |
3692 | - |
3693 | -/** all relevant information about parsing file information */ |
3694 | -struct ParseFileInfo { |
3695 | - // file related info |
3696 | - mode_t perm; // permissions of this file |
3697 | - time_t atime; // last access time (UNIX format) |
3698 | - time_t mtime; // modification time (UNIX format) |
3699 | - time_t ctime; // creation time (UNIX format) |
3700 | - int uid; // user id (-1 if not specified) |
3701 | - int gid; // group id (-1 if not specified) |
3702 | - QByteArray guessed_symlink; // guessed symlink target |
3703 | - int extralen; // length of extra field |
3704 | - |
3705 | - // parsing related info |
3706 | - bool exttimestamp_seen; // true if extended timestamp extra field |
3707 | - // has been parsed |
3708 | - bool newinfounix_seen; // true if Info-ZIP Unix New extra field has |
3709 | - // been parsed |
3710 | - |
3711 | - ParseFileInfo() : perm(0100644), uid(-1), gid(-1), extralen(0), |
3712 | - exttimestamp_seen(false), newinfounix_seen(false) { |
3713 | - ctime = mtime = atime = time(0); |
3714 | - } |
3715 | -}; |
3716 | - |
3717 | -/** updates the parse information with the given extended timestamp extra field. |
3718 | - * @param buffer start content of buffer known to contain an extended |
3719 | - * timestamp extra field (without magic & size) |
3720 | - * @param size size of field content (must not count magic and size entries) |
3721 | - * @param islocal true if this is a local field, false if central |
3722 | - * @param pfi ParseFileInfo object to be updated |
3723 | - * @return true if processing was successful |
3724 | - */ |
3725 | -static bool parseExtTimestamp(const char *buffer, int size, bool islocal, |
3726 | - ParseFileInfo &pfi) { |
3727 | - if (size < 1) { |
3728 | - qDebug() << "premature end of extended timestamp (#1)"; |
3729 | - return false; |
3730 | - }/*end if*/ |
3731 | - int flags = *buffer; // read flags |
3732 | - buffer += 1; |
3733 | - size -= 1; |
3734 | - |
3735 | - if (flags & 1) { // contains modification time |
3736 | - if (size < 4) { |
3737 | - qDebug() << "premature end of extended timestamp (#2)"; |
3738 | - return false; |
3739 | - }/*end if*/ |
3740 | - pfi.mtime = time_t((uchar)buffer[0] | (uchar)buffer[1] << 8 |
3741 | - | (uchar)buffer[2] << 16 | (uchar)buffer[3] << 24); |
3742 | - buffer += 4; |
3743 | - size -= 4; |
3744 | - }/*end if*/ |
3745 | - // central extended field cannot contain more than the modification time |
3746 | - // even if other flags are set |
3747 | - if (!islocal) { |
3748 | - pfi.exttimestamp_seen = true; |
3749 | - return true; |
3750 | - }/*end if*/ |
3751 | - |
3752 | - if (flags & 2) { // contains last access time |
3753 | - if (size < 4) { |
3754 | - qDebug() << "premature end of extended timestamp (#3)"; |
3755 | - return true; |
3756 | - }/*end if*/ |
3757 | - pfi.atime = time_t((uchar)buffer[0] | (uchar)buffer[1] << 8 |
3758 | - | (uchar)buffer[2] << 16 | (uchar)buffer[3] << 24); |
3759 | - buffer += 4; |
3760 | - size -= 4; |
3761 | - }/*end if*/ |
3762 | - |
3763 | - if (flags & 4) { // contains creation time |
3764 | - if (size < 4) { |
3765 | - qDebug() << "premature end of extended timestamp (#4)"; |
3766 | - return true; |
3767 | - }/*end if*/ |
3768 | - pfi.ctime = time_t((uchar)buffer[0] | (uchar)buffer[1] << 8 |
3769 | - | (uchar)buffer[2] << 16 | (uchar)buffer[3] << 24); |
3770 | - buffer += 4; |
3771 | - }/*end if*/ |
3772 | - |
3773 | - pfi.exttimestamp_seen = true; |
3774 | - return true; |
3775 | -} |
3776 | - |
3777 | -/** updates the parse information with the given Info-ZIP Unix old extra field. |
3778 | - * @param buffer start of content of buffer known to contain an Info-ZIP |
3779 | - * Unix old extra field (without magic & size) |
3780 | - * @param size size of field content (must not count magic and size entries) |
3781 | - * @param islocal true if this is a local field, false if central |
3782 | - * @param pfi ParseFileInfo object to be updated |
3783 | - * @return true if processing was successful |
3784 | - */ |
3785 | -static bool parseInfoZipUnixOld(const char *buffer, int size, bool islocal, |
3786 | - ParseFileInfo &pfi) { |
3787 | - // spec mandates to omit this field if one of the newer fields are available |
3788 | - if (pfi.exttimestamp_seen || pfi.newinfounix_seen) return true; |
3789 | - |
3790 | - if (size < 8) { |
3791 | - qDebug() << "premature end of Info-ZIP unix extra field old"; |
3792 | - return false; |
3793 | - }/*end if*/ |
3794 | - |
3795 | - pfi.atime = time_t((uchar)buffer[0] | (uchar)buffer[1] << 8 |
3796 | - | (uchar)buffer[2] << 16 | (uchar)buffer[3] << 24); |
3797 | - buffer += 4; |
3798 | - pfi.mtime = time_t((uchar)buffer[0] | (uchar)buffer[1] << 8 |
3799 | - | (uchar)buffer[2] << 16 | (uchar)buffer[3] << 24); |
3800 | - buffer += 4; |
3801 | - if (islocal && size >= 12) { |
3802 | - pfi.uid = (uchar)buffer[0] | (uchar)buffer[1] << 8; |
3803 | - buffer += 2; |
3804 | - pfi.gid = (uchar)buffer[0] | (uchar)buffer[1] << 8; |
3805 | - buffer += 2; |
3806 | - }/*end if*/ |
3807 | - return true; |
3808 | -} |
3809 | - |
3810 | -#if 0 // not needed yet |
3811 | -/** updates the parse information with the given Info-ZIP Unix new extra field. |
3812 | - * @param buffer start of content of buffer known to contain an Info-ZIP |
3813 | - * Unix new extra field (without magic & size) |
3814 | - * @param size size of field content (must not count magic and size entries) |
3815 | - * @param islocal true if this is a local field, false if central |
3816 | - * @param pfi ParseFileInfo object to be updated |
3817 | - * @return true if processing was successful |
3818 | - */ |
3819 | -static bool parseInfoZipUnixNew(const char *buffer, int size, bool islocal, |
3820 | - ParseFileInfo &pfi) { |
3821 | - if (!islocal) { // contains nothing in central field |
3822 | - pfi.newinfounix = true; |
3823 | - return true; |
3824 | - }/*end if*/ |
3825 | - |
3826 | - if (size < 4) { |
3827 | - qDebug() << "premature end of Info-ZIP unix extra field new"; |
3828 | - return false; |
3829 | - }/*end if*/ |
3830 | - |
3831 | - pfi.uid = (uchar)buffer[0] | (uchar)buffer[1] << 8; |
3832 | - buffer += 2; |
3833 | - pfi.gid = (uchar)buffer[0] | (uchar)buffer[1] << 8; |
3834 | - buffer += 2; |
3835 | - |
3836 | - pfi.newinfounix = true; |
3837 | - return true; |
3838 | -} |
3839 | -#endif |
3840 | - |
3841 | -/** |
3842 | - * parses the extra field |
3843 | - * @param buffer start of buffer where the extra field is to be found |
3844 | - * @param size size of the extra field |
3845 | - * @param islocal true if this is part of a local header, false if of central |
3846 | - * @param pfi ParseFileInfo object which to write the results into |
3847 | - * @return true if parsing was successful |
3848 | - */ |
3849 | -static bool parseExtraField(const char *buffer, int size, bool islocal, |
3850 | - ParseFileInfo &pfi) { |
3851 | - // extra field in central directory doesn't contain useful data, so we |
3852 | - // don't bother parsing it |
3853 | - if (!islocal) return true; |
3854 | - |
3855 | - while (size >= 4) { // as long as a potential extra field can be read |
3856 | - int magic = (uchar)buffer[0] | (uchar)buffer[1] << 8; |
3857 | - buffer += 2; |
3858 | - int fieldsize = (uchar)buffer[0] | (uchar)buffer[1] << 8; |
3859 | - buffer += 2; |
3860 | - size -= 4; |
3861 | - |
3862 | - if (fieldsize > size) { |
3863 | - //qDebug() << "fieldsize: " << fieldsize << " size: " << size; |
3864 | - qDebug() << "premature end of extra fields reached"; |
3865 | - break; |
3866 | - }/*end if*/ |
3867 | - |
3868 | - switch (magic) { |
3869 | - case 0x5455: // extended timestamp |
3870 | - if (!parseExtTimestamp(buffer, fieldsize, islocal, pfi)) return false; |
3871 | - break; |
3872 | - case 0x5855: // old Info-ZIP unix extra field |
3873 | - if (!parseInfoZipUnixOld(buffer, fieldsize, islocal, pfi)) return false; |
3874 | - break; |
3875 | -#if 0 // not needed yet |
3876 | - case 0x7855: // new Info-ZIP unix extra field |
3877 | - if (!parseInfoZipUnixNew(buffer, fieldsize, islocal, pfi)) return false; |
3878 | - break; |
3879 | -#endif |
3880 | - default: |
3881 | - /* ignore everything else */; |
3882 | - }/*end switch*/ |
3883 | - |
3884 | - buffer += fieldsize; |
3885 | - size -= fieldsize; |
3886 | - }/*wend*/ |
3887 | - return true; |
3888 | -} |
3889 | - |
3890 | -//////////////////////////////////////////////////////////////////////// |
3891 | -/////////////////////////// KZip /////////////////////////////////////// |
3892 | -//////////////////////////////////////////////////////////////////////// |
3893 | - |
3894 | -class KZip::KZipPrivate |
3895 | -{ |
3896 | -public: |
3897 | - KZipPrivate() |
3898 | - : m_crc( 0 ), |
3899 | - m_currentFile( 0 ), |
3900 | - m_currentDev( 0 ), |
3901 | - m_compression( 8 ), |
3902 | - m_extraField( KZip::NoExtraField ), |
3903 | - m_offset( 0 ) |
3904 | - {} |
3905 | - |
3906 | - unsigned long m_crc; // checksum |
3907 | - KZipFileEntry* m_currentFile; // file currently being written |
3908 | - QIODevice* m_currentDev; // filterdev used to write to the above file |
3909 | - QList<KZipFileEntry*> m_fileList; // flat list of all files, for the index (saves a recursive method ;) |
3910 | - int m_compression; |
3911 | - KZip::ExtraField m_extraField; |
3912 | - // m_offset holds the offset of the place in the zip, |
3913 | - // where new data can be appended. after openarchive it points to 0, when in |
3914 | - // writeonly mode, or it points to the beginning of the central directory. |
3915 | - // each call to writefile updates this value. |
3916 | - unsigned int m_offset; |
3917 | -}; |
3918 | - |
3919 | -KZip::KZip( const QString& fileName ) |
3920 | - : KArchive( fileName ),d(new KZipPrivate) |
3921 | -{ |
3922 | -} |
3923 | - |
3924 | -KZip::KZip( QIODevice * dev ) |
3925 | - : KArchive( dev ),d(new KZipPrivate) |
3926 | -{ |
3927 | -} |
3928 | - |
3929 | -KZip::~KZip() |
3930 | -{ |
3931 | - //qDebug() << this; |
3932 | - if( isOpen() ) |
3933 | - close(); |
3934 | - delete d; |
3935 | -} |
3936 | - |
3937 | -bool KZip::openArchive( QIODevice::OpenMode mode ) |
3938 | -{ |
3939 | - //qDebug(); |
3940 | - d->m_fileList.clear(); |
3941 | - |
3942 | - if ( mode == QIODevice::WriteOnly ) |
3943 | - return true; |
3944 | - |
3945 | - char buffer[47]; |
3946 | - |
3947 | - // Check that it's a valid ZIP file |
3948 | - // KArchive::open() opened the underlying device already. |
3949 | - |
3950 | - uint offset = 0; // holds offset, where we read |
3951 | - int n; |
3952 | - |
3953 | - // contains information gathered from the local file headers |
3954 | - QHash<QByteArray, ParseFileInfo> pfi_map; |
3955 | - |
3956 | - QIODevice* dev = device(); |
3957 | - |
3958 | - // We set a bool for knowing if we are allowed to skip the start of the file |
3959 | - bool startOfFile = true; |
3960 | - |
3961 | - for (;;) // repeat until 'end of entries' signature is reached |
3962 | - { |
3963 | - //qDebug() << "loop starts"; |
3964 | - //qDebug() << "dev->pos() now : " << dev->pos(); |
3965 | - n = dev->read( buffer, 4 ); |
3966 | - |
3967 | - if (n < 4) |
3968 | - { |
3969 | - qWarning() << "Invalid ZIP file. Unexpected end of file. (#1)"; |
3970 | - |
3971 | - return false; |
3972 | - } |
3973 | - |
3974 | - if ( !memcmp( buffer, "PK\5\6", 4 ) ) // 'end of entries' |
3975 | - { |
3976 | - //qDebug() << "PK56 found end of archive"; |
3977 | - startOfFile = false; |
3978 | - break; |
3979 | - } |
3980 | - |
3981 | - if ( !memcmp( buffer, "PK\3\4", 4 ) ) // local file header |
3982 | - { |
3983 | - //qDebug() << "PK34 found local file header"; |
3984 | - startOfFile = false; |
3985 | - // can this fail ??? |
3986 | - dev->seek( dev->pos() + 2 ); // skip 'version needed to extract' |
3987 | - |
3988 | - // read static header stuff |
3989 | - n = dev->read( buffer, 24 ); |
3990 | - if (n < 24) { |
3991 | - qWarning() << "Invalid ZIP file. Unexpected end of file. (#4)"; |
3992 | - return false; |
3993 | - } |
3994 | - |
3995 | - int gpf = (uchar)buffer[0]; // "general purpose flag" not "general protection fault" ;-) |
3996 | - int compression_mode = (uchar)buffer[2] | (uchar)buffer[3] << 8; |
3997 | - time_t mtime = transformFromMsDos( buffer+4 ); |
3998 | - |
3999 | - qint64 compr_size = (uchar)buffer[12] | (uchar)buffer[13] << 8 |
4000 | - | (uchar)buffer[14] << 16 | (uchar)buffer[15] << 24; |
4001 | - qint64 uncomp_size = (uchar)buffer[16] | (uchar)buffer[17] << 8 |
4002 | - | (uchar)buffer[18] << 16 | (uchar)buffer[19] << 24; |
4003 | - int namelen = (uchar)buffer[20] | (uchar)buffer[21] << 8; |
4004 | - int extralen = (uchar)buffer[22] | (uchar)buffer[23] << 8; |
4005 | - |
4006 | - /* |
4007 | - qDebug() << "general purpose bit flag: " << gpf; |
4008 | - qDebug() << "compressed size: " << compr_size; |
4009 | - qDebug() << "uncompressed size: " << uncomp_size; |
4010 | - qDebug() << "namelen: " << namelen; |
4011 | - qDebug() << "extralen: " << extralen; |
4012 | - qDebug() << "archive size: " << dev->size(); |
4013 | - */ |
4014 | - |
4015 | - // read fileName |
4016 | - Q_ASSERT( namelen > 0 ); |
4017 | - QByteArray fileName = dev->read(namelen); |
4018 | - if ( fileName.size() < namelen ) { |
4019 | - qWarning() << "Invalid ZIP file. Name not completely read (#2)"; |
4020 | - return false; |
4021 | - } |
4022 | - |
4023 | - ParseFileInfo pfi; |
4024 | - pfi.mtime = mtime; |
4025 | - |
4026 | - // read and parse the beginning of the extra field, |
4027 | - // skip rest of extra field in case it is too long |
4028 | - unsigned int extraFieldEnd = dev->pos() + extralen; |
4029 | - pfi.extralen = extralen; |
4030 | - int handledextralen = qMin(extralen, (int)sizeof buffer); |
4031 | - |
4032 | - //if ( handledextralen ) |
4033 | - // qDebug() << "handledextralen: " << handledextralen; |
4034 | - |
4035 | - n = dev->read(buffer, handledextralen); |
4036 | - // no error msg necessary as we deliberately truncate the extra field |
4037 | - if (!parseExtraField(buffer, handledextralen, true, pfi)) |
4038 | - { |
4039 | - qWarning() << "Invalid ZIP File. Broken ExtraField."; |
4040 | - return false; |
4041 | - } |
4042 | - |
4043 | - // jump to end of extra field |
4044 | - dev->seek( extraFieldEnd ); |
4045 | - |
4046 | - // we have to take care of the 'general purpose bit flag'. |
4047 | - // if bit 3 is set, the header doesn't contain the length of |
4048 | - // the file and we look for the signature 'PK\7\8'. |
4049 | - if ( gpf & 8 ) |
4050 | - { |
4051 | - // here we have to read through the compressed data to find |
4052 | - // the next PKxx |
4053 | - qDebug() << "trying to seek for next PK78"; |
4054 | - bool foundSignature = false; |
4055 | - |
4056 | - while (!foundSignature) |
4057 | - { |
4058 | - n = dev->read( buffer, 1 ); |
4059 | - if (n < 1) |
4060 | - { |
4061 | - qWarning() << "Invalid ZIP file. Unexpected end of file. (#2)"; |
4062 | - return false; |
4063 | - } |
4064 | - |
4065 | - if ( buffer[0] != 'P' ) |
4066 | - continue; |
4067 | - |
4068 | - n = dev->read( buffer, 3 ); |
4069 | - if (n < 3) |
4070 | - { |
4071 | - qWarning() << "Invalid ZIP file. Unexpected end of file. (#3)"; |
4072 | - return false; |
4073 | - } |
4074 | - |
4075 | - // we have to detect three magic tokens here: |
4076 | - // PK34 for the next local header in case there is no data descriptor |
4077 | - // PK12 for the central header in case there is no data descriptor |
4078 | - // PK78 for the data descriptor in case it is following the compressed data |
4079 | - |
4080 | - if ( buffer[0] == 'K' && buffer[1] == 7 && buffer[2] == 8 ) |
4081 | - { |
4082 | - foundSignature = true; |
4083 | - dev->seek( dev->pos() + 12 ); // skip the 'data_descriptor' |
4084 | - } |
4085 | - else if ( ( buffer[0] == 'K' && buffer[1] == 1 && buffer[2] == 2 ) |
4086 | - || ( buffer[0] == 'K' && buffer[1] == 3 && buffer[2] == 4 ) ) |
4087 | - { |
4088 | - foundSignature = true; |
4089 | - dev->seek( dev->pos() - 4 ); // go back 4 bytes, so that the magic bytes can be found... |
4090 | - } |
4091 | - else if ( buffer[0] == 'P' || buffer[1] == 'P' || buffer[2] == 'P' ) |
4092 | - { |
4093 | - // We have another P character so we must go back a little to check if it is a magic |
4094 | - dev->seek( dev->pos() - 3 ); |
4095 | - } |
4096 | - |
4097 | - } |
4098 | - } |
4099 | - else |
4100 | - { |
4101 | - // here we skip the compressed data and jump to the next header |
4102 | - //qDebug() << "general purpose bit flag indicates, that local file header contains valid size"; |
4103 | - // check if this could be a symbolic link |
4104 | - if (compression_mode == NoCompression |
4105 | - && uncomp_size <= max_path_len |
4106 | - && uncomp_size > 0) { |
4107 | - // read content and store it |
4108 | - // If it's not a symlink, then we'll just discard the data for now. |
4109 | - pfi.guessed_symlink = dev->read(uncomp_size); |
4110 | - if (pfi.guessed_symlink.size() < uncomp_size) { |
4111 | - qWarning() << "Invalid ZIP file. Unexpected end of file. (#5)"; |
4112 | - return false; |
4113 | - } |
4114 | - } else { |
4115 | - |
4116 | - if ( compr_size > dev->size() ) |
4117 | - { |
4118 | - // here we cannot trust the compressed size, so scan through the compressed |
4119 | - // data to find the next header |
4120 | - bool foundSignature = false; |
4121 | - |
4122 | - while (!foundSignature) |
4123 | - { |
4124 | - n = dev->read( buffer, 1 ); |
4125 | - if (n < 1) |
4126 | - { |
4127 | - qWarning() << "Invalid ZIP file. Unexpected end of file. (#2)"; |
4128 | - return false; |
4129 | - } |
4130 | - |
4131 | - if ( buffer[0] != 'P' ) |
4132 | - continue; |
4133 | - |
4134 | - n = dev->read( buffer, 3 ); |
4135 | - if (n < 3) |
4136 | - { |
4137 | - qWarning() << "Invalid ZIP file. Unexpected end of file. (#3)"; |
4138 | - return false; |
4139 | - } |
4140 | - |
4141 | - // we have to detect three magic tokens here: |
4142 | - // PK34 for the next local header in case there is no data descriptor |
4143 | - // PK12 for the central header in case there is no data descriptor |
4144 | - // PK78 for the data descriptor in case it is following the compressed data |
4145 | - |
4146 | - if ( buffer[0] == 'K' && buffer[1] == 7 && buffer[2] == 8 ) |
4147 | - { |
4148 | - foundSignature = true; |
4149 | - dev->seek( dev->pos() + 12 ); // skip the 'data_descriptor' |
4150 | - } |
4151 | - |
4152 | - if ( ( buffer[0] == 'K' && buffer[1] == 1 && buffer[2] == 2 ) |
4153 | - || ( buffer[0] == 'K' && buffer[1] == 3 && buffer[2] == 4 ) ) |
4154 | - { |
4155 | - foundSignature = true; |
4156 | - dev->seek( dev->pos() - 4 ); |
4157 | - // go back 4 bytes, so that the magic bytes can be found |
4158 | - // in the next cycle... |
4159 | - } |
4160 | - } |
4161 | - } |
4162 | - else |
4163 | - { |
4164 | -// qDebug() << "before interesting dev->pos(): " << dev->pos(); |
4165 | - bool success = dev->seek( dev->pos() + compr_size ); // can this fail ??? |
4166 | - static_cast<void>(success); // annoying unused variable warning |
4167 | - Q_ASSERT( success ); // let's see... |
4168 | -/* qDebug() << "after interesting dev->pos(): " << dev->pos(); |
4169 | - if ( success ) |
4170 | - qDebug() << "dev->at was successful... "; |
4171 | - else |
4172 | - qDebug() << "dev->at failed... ";*/ |
4173 | - } |
4174 | - |
4175 | - } |
4176 | - |
4177 | -// not needed any more |
4178 | -/* // here we calculate the length of the file in the zip |
4179 | - // with headers and jump to the next header. |
4180 | - uint skip = compr_size + namelen + extralen; |
4181 | - offset += 30 + skip;*/ |
4182 | - } |
4183 | - pfi_map.insert(fileName, pfi); |
4184 | - } |
4185 | - else if ( !memcmp( buffer, "PK\1\2", 4 ) ) // central block |
4186 | - { |
4187 | - //qDebug() << "PK12 found central block"; |
4188 | - startOfFile = false; |
4189 | - |
4190 | - // so we reached the central header at the end of the zip file |
4191 | - // here we get all interesting data out of the central header |
4192 | - // of a file |
4193 | - offset = dev->pos() - 4; |
4194 | - |
4195 | - //set offset for appending new files |
4196 | - if ( d->m_offset == 0L ) d->m_offset = offset; |
4197 | - |
4198 | - n = dev->read( buffer + 4, 42 ); |
4199 | - if (n < 42) { |
4200 | - qWarning() << "Invalid ZIP file, central entry too short"; // not long enough for valid entry |
4201 | - return false; |
4202 | - } |
4203 | - |
4204 | - //int gpf = (uchar)buffer[9] << 8 | (uchar)buffer[10]; |
4205 | - //kDebug() << "general purpose flag=" << gpf; |
4206 | - // length of the fileName (well, pathname indeed) |
4207 | - int namelen = (uchar)buffer[29] << 8 | (uchar)buffer[28]; |
4208 | - Q_ASSERT( namelen > 0 ); |
4209 | - QByteArray bufferName = dev->read( namelen ); |
4210 | - if ( bufferName.size() < namelen ) |
4211 | - qWarning() << "Invalid ZIP file. Name not completely read"; |
4212 | - |
4213 | - ParseFileInfo pfi = pfi_map.value( bufferName, ParseFileInfo() ); |
4214 | - |
4215 | - QString name( QFile::decodeName(bufferName) ); |
4216 | - |
4217 | - //qDebug() << "name: " << name; |
4218 | - // only in central header ! see below. |
4219 | - // length of extra attributes |
4220 | - int extralen = (uchar)buffer[31] << 8 | (uchar)buffer[30]; |
4221 | - // length of comment for this file |
4222 | - int commlen = (uchar)buffer[33] << 8 | (uchar)buffer[32]; |
4223 | - // compression method of this file |
4224 | - int cmethod = (uchar)buffer[11] << 8 | (uchar)buffer[10]; |
4225 | - |
4226 | - //qDebug() << "cmethod: " << cmethod; |
4227 | - //qDebug() << "extralen: " << extralen; |
4228 | - |
4229 | - // crc32 of the file |
4230 | - uint crc32 = (uchar)buffer[19] << 24 | (uchar)buffer[18] << 16 | |
4231 | - (uchar)buffer[17] << 8 | (uchar)buffer[16]; |
4232 | - |
4233 | - // uncompressed file size |
4234 | - uint ucsize = (uchar)buffer[27] << 24 | (uchar)buffer[26] << 16 | |
4235 | - (uchar)buffer[25] << 8 | (uchar)buffer[24]; |
4236 | - // compressed file size |
4237 | - uint csize = (uchar)buffer[23] << 24 | (uchar)buffer[22] << 16 | |
4238 | - (uchar)buffer[21] << 8 | (uchar)buffer[20]; |
4239 | - |
4240 | - // offset of local header |
4241 | - uint localheaderoffset = (uchar)buffer[45] << 24 | (uchar)buffer[44] << 16 | |
4242 | - (uchar)buffer[43] << 8 | (uchar)buffer[42]; |
4243 | - |
4244 | - // some clever people use different extra field lengths |
4245 | - // in the central header and in the local header... funny. |
4246 | - // so we need to get the localextralen to calculate the offset |
4247 | - // from localheaderstart to dataoffset |
4248 | - int localextralen = pfi.extralen; // FIXME: this will not work if |
4249 | - // no local header exists |
4250 | - |
4251 | - //qDebug() << "localextralen: " << localextralen; |
4252 | - |
4253 | - // offset, where the real data for uncompression starts |
4254 | - uint dataoffset = localheaderoffset + 30 + localextralen + namelen; //comment only in central header |
4255 | - |
4256 | - //qDebug() << "esize: " << esize; |
4257 | - //qDebug() << "eoffset: " << eoffset; |
4258 | - //qDebug() << "csize: " << csize; |
4259 | - |
4260 | - int os_madeby = (uchar)buffer[5]; |
4261 | - bool isdir = false; |
4262 | - int access = 0100644; |
4263 | - |
4264 | - if (os_madeby == 3) { // good ole unix |
4265 | - access = (uchar)buffer[40] | (uchar)buffer[41] << 8; |
4266 | - } |
4267 | - |
4268 | - QString entryName; |
4269 | - |
4270 | - if ( name.endsWith( '/' ) ) // Entries with a trailing slash are directories |
4271 | - { |
4272 | - isdir = true; |
4273 | - name = name.left( name.length() - 1 ); |
4274 | - if (os_madeby != 3) access = S_IFDIR | 0755; |
4275 | - else Q_ASSERT(access & S_IFDIR); |
4276 | - } |
4277 | - |
4278 | - int pos = name.lastIndexOf( '/' ); |
4279 | - if ( pos == -1 ) |
4280 | - entryName = name; |
4281 | - else |
4282 | - entryName = name.mid( pos + 1 ); |
4283 | - Q_ASSERT( !entryName.isEmpty() ); |
4284 | - |
4285 | - KArchiveEntry* entry; |
4286 | - if ( isdir ) |
4287 | - { |
4288 | - QString path = QDir::cleanPath( name ); |
4289 | - const KArchiveEntry* ent = rootDir()->entry( path ); |
4290 | - if ( ent && ent->isDirectory() ) |
4291 | - { |
4292 | - //qDebug() << "Directory already exists, NOT going to add it again"; |
4293 | - entry = 0; |
4294 | - } |
4295 | - else |
4296 | - { |
4297 | - entry = new KArchiveDirectory( this, entryName, access, (int)pfi.mtime, rootDir()->user(), rootDir()->group(), QString() ); |
4298 | - //qDebug() << "KArchiveDirectory created, entryName= " << entryName << ", name=" << name; |
4299 | - } |
4300 | - } |
4301 | - else |
4302 | - { |
4303 | - QString symlink; |
4304 | - if (S_ISLNK(access)) { |
4305 | - symlink = QFile::decodeName(pfi.guessed_symlink); |
4306 | - } |
4307 | - entry = new KZipFileEntry( this, entryName, access, pfi.mtime, |
4308 | - rootDir()->user(), rootDir()->group(), |
4309 | - symlink, name, dataoffset, |
4310 | - ucsize, cmethod, csize ); |
4311 | - static_cast<KZipFileEntry *>(entry)->setHeaderStart( localheaderoffset ); |
4312 | - static_cast<KZipFileEntry*>(entry)->setCRC32(crc32); |
4313 | - //qDebug() << "KZipFileEntry created, entryName= " << entryName << ", name=" << name; |
4314 | - d->m_fileList.append( static_cast<KZipFileEntry *>( entry ) ); |
4315 | - } |
4316 | - |
4317 | - if ( entry ) |
4318 | - { |
4319 | - if ( pos == -1 ) |
4320 | - { |
4321 | - rootDir()->addEntry(entry); |
4322 | - } |
4323 | - else |
4324 | - { |
4325 | - // In some tar files we can find dir/./file => call cleanPath |
4326 | - QString path = QDir::cleanPath( name.left( pos ) ); |
4327 | - // Ensure container directory exists, create otherwise |
4328 | - KArchiveDirectory * tdir = findOrCreate( path ); |
4329 | - tdir->addEntry(entry); |
4330 | - } |
4331 | - } |
4332 | - |
4333 | - //calculate offset to next entry |
4334 | - offset += 46 + commlen + extralen + namelen; |
4335 | - bool b = dev->seek(offset); |
4336 | - Q_ASSERT( b ); |
4337 | - if ( !b ) |
4338 | - return false; |
4339 | - } |
4340 | - else if ( startOfFile ) |
4341 | - { |
4342 | - // The file does not start with any ZIP header (e.g. self-extractable ZIP files) |
4343 | - // Therefore we need to find the first PK\003\004 (local header) |
4344 | - qDebug() << "Try to skip start of file"; |
4345 | - startOfFile = false; |
4346 | - bool foundSignature = false; |
4347 | - |
4348 | - while (!foundSignature) |
4349 | - { |
4350 | - n = dev->read( buffer, 1 ); |
4351 | - if (n < 1) |
4352 | - { |
4353 | - qWarning() << "Invalid ZIP file. Unexpected end of file. " ; |
4354 | - return false; |
4355 | - } |
4356 | - |
4357 | - if ( buffer[0] != 'P' ) |
4358 | - continue; |
4359 | - |
4360 | - n = dev->read( buffer, 3 ); |
4361 | - if (n < 3) |
4362 | - { |
4363 | - qWarning() << "Invalid ZIP file. Unexpected end of file. " ; |
4364 | - return false; |
4365 | - } |
4366 | - |
4367 | - // We have to detect the magic token for a local header: PK\003\004 |
4368 | - /* |
4369 | - * Note: we do not need to check the other magics, if the ZIP file has no |
4370 | - * local header, then it has not any files! |
4371 | - */ |
4372 | - if ( buffer[0] == 'K' && buffer[1] == 3 && buffer[2] == 4 ) |
4373 | - { |
4374 | - foundSignature = true; |
4375 | - dev->seek( dev->pos() - 4 ); // go back 4 bytes, so that the magic bytes can be found... |
4376 | - } |
4377 | - else if ( buffer[0] == 'P' || buffer[1] == 'P' || buffer[2] == 'P' ) |
4378 | - { |
4379 | - // We have another P character so we must go back a little to check if it is a magic |
4380 | - dev->seek( dev->pos() - 3 ); |
4381 | - } |
4382 | - } |
4383 | - } |
4384 | - else |
4385 | - { |
4386 | - qWarning() << "Invalid ZIP file. Unrecognized header at offset " << offset; |
4387 | - |
4388 | - return false; |
4389 | - } |
4390 | - } |
4391 | - //qDebug() << "*** done *** "; |
4392 | - return true; |
4393 | -} |
4394 | - |
4395 | -bool KZip::closeArchive() |
4396 | -{ |
4397 | - if ( ! ( mode() & QIODevice::WriteOnly ) ) |
4398 | - { |
4399 | - //qDebug() << "readonly"; |
4400 | - return true; |
4401 | - } |
4402 | - |
4403 | - //ReadWrite or WriteOnly |
4404 | - //write all central dir file entries |
4405 | - |
4406 | - // to be written at the end of the file... |
4407 | - char buffer[ 22 ]; // first used for 12, then for 22 at the end |
4408 | - uLong crc = crc32(0L, Z_NULL, 0); |
4409 | - |
4410 | - qint64 centraldiroffset = device()->pos(); |
4411 | - //qDebug() << "closearchive: centraldiroffset: " << centraldiroffset; |
4412 | - qint64 atbackup = centraldiroffset; |
4413 | - QMutableListIterator<KZipFileEntry*> it( d->m_fileList ); |
4414 | - |
4415 | - while(it.hasNext()) |
4416 | - { //set crc and compressed size in each local file header |
4417 | - it.next(); |
4418 | - if ( !device()->seek( it.value()->headerStart() + 14 ) ) |
4419 | - return false; |
4420 | - //qDebug() << "closearchive setcrcandcsize: fileName:" |
4421 | - // << it.current()->path() |
4422 | - // << "encoding:" << it.current()->encoding(); |
4423 | - |
4424 | - uLong mycrc = it.value()->crc32(); |
4425 | - buffer[0] = char(mycrc); // crc checksum, at headerStart+14 |
4426 | - buffer[1] = char(mycrc >> 8); |
4427 | - buffer[2] = char(mycrc >> 16); |
4428 | - buffer[3] = char(mycrc >> 24); |
4429 | - |
4430 | - int mysize1 = it.value()->compressedSize(); |
4431 | - buffer[4] = char(mysize1); // compressed file size, at headerStart+18 |
4432 | - buffer[5] = char(mysize1 >> 8); |
4433 | - buffer[6] = char(mysize1 >> 16); |
4434 | - buffer[7] = char(mysize1 >> 24); |
4435 | - |
4436 | - int myusize = it.value()->size(); |
4437 | - buffer[8] = char(myusize); // uncompressed file size, at headerStart+22 |
4438 | - buffer[9] = char(myusize >> 8); |
4439 | - buffer[10] = char(myusize >> 16); |
4440 | - buffer[11] = char(myusize >> 24); |
4441 | - |
4442 | - if ( device()->write( buffer, 12 ) != 12 ) |
4443 | - return false; |
4444 | - } |
4445 | - device()->seek( atbackup ); |
4446 | - |
4447 | - it.toFront(); |
4448 | - while (it.hasNext()) |
4449 | - { |
4450 | - it.next(); |
4451 | - //qDebug() << "fileName:" << it.current()->path() |
4452 | - // << "encoding:" << it.current()->encoding(); |
4453 | - |
4454 | - QByteArray path = QFile::encodeName(it.value()->path()); |
4455 | - |
4456 | - const int extra_field_len = 9; |
4457 | - int bufferSize = extra_field_len + path.length() + 46; |
4458 | - char* buffer = new char[ bufferSize ]; |
4459 | - |
4460 | - memset(buffer, 0, 46); // zero is a nice default for most header fields |
4461 | - |
4462 | - const char head[] = |
4463 | - { |
4464 | - 'P', 'K', 1, 2, // central file header signature |
4465 | - 0x14, 3, // version made by (3 == UNIX) |
4466 | - 0x14, 0 // version needed to extract |
4467 | - }; |
4468 | - |
4469 | - // I do not know why memcpy is not working here |
4470 | - //memcpy(buffer, head, sizeof(head)); |
4471 | - memmove(buffer, head, sizeof(head)); |
4472 | - |
4473 | - buffer[ 10 ] = char(it.value()->encoding()); // compression method |
4474 | - buffer[ 11 ] = char(it.value()->encoding() >> 8); |
4475 | - |
4476 | - transformToMsDos( it.value()->datetime(), &buffer[ 12 ] ); |
4477 | - |
4478 | - uLong mycrc = it.value()->crc32(); |
4479 | - buffer[ 16 ] = char(mycrc); // crc checksum |
4480 | - buffer[ 17 ] = char(mycrc >> 8); |
4481 | - buffer[ 18 ] = char(mycrc >> 16); |
4482 | - buffer[ 19 ] = char(mycrc >> 24); |
4483 | - |
4484 | - int mysize1 = it.value()->compressedSize(); |
4485 | - buffer[ 20 ] = char(mysize1); // compressed file size |
4486 | - buffer[ 21 ] = char(mysize1 >> 8); |
4487 | - buffer[ 22 ] = char(mysize1 >> 16); |
4488 | - buffer[ 23 ] = char(mysize1 >> 24); |
4489 | - |
4490 | - int mysize = it.value()->size(); |
4491 | - buffer[ 24 ] = char(mysize); // uncompressed file size |
4492 | - buffer[ 25 ] = char(mysize >> 8); |
4493 | - buffer[ 26 ] = char(mysize >> 16); |
4494 | - buffer[ 27 ] = char(mysize >> 24); |
4495 | - |
4496 | - buffer[ 28 ] = char(it.value()->path().length()); // fileName length |
4497 | - buffer[ 29 ] = char(it.value()->path().length() >> 8); |
4498 | - |
4499 | - buffer[ 30 ] = char(extra_field_len); |
4500 | - buffer[ 31 ] = char(extra_field_len >> 8); |
4501 | - |
4502 | - buffer[ 40 ] = char(it.value()->permissions()); |
4503 | - buffer[ 41 ] = char(it.value()->permissions() >> 8); |
4504 | - |
4505 | - int myhst = it.value()->headerStart(); |
4506 | - buffer[ 42 ] = char(myhst); //relative offset of local header |
4507 | - buffer[ 43 ] = char(myhst >> 8); |
4508 | - buffer[ 44 ] = char(myhst >> 16); |
4509 | - buffer[ 45 ] = char(myhst >> 24); |
4510 | - |
4511 | - // file name |
4512 | - strncpy( buffer + 46, path, path.length() ); |
4513 | - //qDebug() << "closearchive length to write: " << bufferSize; |
4514 | - |
4515 | - // extra field |
4516 | - char *extfield = buffer + 46 + path.length(); |
4517 | - extfield[0] = 'U'; |
4518 | - extfield[1] = 'T'; |
4519 | - extfield[2] = 5; |
4520 | - extfield[3] = 0; |
4521 | - extfield[4] = 1 | 2 | 4; // specify flags from local field |
4522 | - // (unless I misread the spec) |
4523 | - // provide only modification time |
4524 | - unsigned long time = (unsigned long)it.value()->date(); |
4525 | - extfield[5] = char(time); |
4526 | - extfield[6] = char(time >> 8); |
4527 | - extfield[7] = char(time >> 16); |
4528 | - extfield[8] = char(time >> 24); |
4529 | - |
4530 | - crc = crc32(crc, (Bytef *)buffer, bufferSize ); |
4531 | - bool ok = ( device()->write( buffer, bufferSize ) == bufferSize ); |
4532 | - delete[] buffer; |
4533 | - if ( !ok ) |
4534 | - return false; |
4535 | - } |
4536 | - qint64 centraldirendoffset = device()->pos(); |
4537 | - //qDebug() << "closearchive: centraldirendoffset: " << centraldirendoffset; |
4538 | - //qDebug() << "closearchive: device()->pos(): " << device()->pos(); |
4539 | - |
4540 | - //write end of central dir record. |
4541 | - buffer[ 0 ] = 'P'; //end of central dir signature |
4542 | - buffer[ 1 ] = 'K'; |
4543 | - buffer[ 2 ] = 5; |
4544 | - buffer[ 3 ] = 6; |
4545 | - |
4546 | - buffer[ 4 ] = 0; // number of this disk |
4547 | - buffer[ 5 ] = 0; |
4548 | - |
4549 | - buffer[ 6 ] = 0; // number of disk with start of central dir |
4550 | - buffer[ 7 ] = 0; |
4551 | - |
4552 | - int count = d->m_fileList.count(); |
4553 | - //qDebug() << "number of files (count): " << count; |
4554 | - |
4555 | - |
4556 | - buffer[ 8 ] = char(count); // total number of entries in central dir of |
4557 | - buffer[ 9 ] = char(count >> 8); // this disk |
4558 | - |
4559 | - buffer[ 10 ] = buffer[ 8 ]; // total number of entries in the central dir |
4560 | - buffer[ 11 ] = buffer[ 9 ]; |
4561 | - |
4562 | - int cdsize = centraldirendoffset - centraldiroffset; |
4563 | - buffer[ 12 ] = char(cdsize); // size of the central dir |
4564 | - buffer[ 13 ] = char(cdsize >> 8); |
4565 | - buffer[ 14 ] = char(cdsize >> 16); |
4566 | - buffer[ 15 ] = char(cdsize >> 24); |
4567 | - |
4568 | - //qDebug() << "end : centraldiroffset: " << centraldiroffset; |
4569 | - //qDebug() << "end : centraldirsize: " << cdsize; |
4570 | - |
4571 | - buffer[ 16 ] = char(centraldiroffset); // central dir offset |
4572 | - buffer[ 17 ] = char(centraldiroffset >> 8); |
4573 | - buffer[ 18 ] = char(centraldiroffset >> 16); |
4574 | - buffer[ 19 ] = char(centraldiroffset >> 24); |
4575 | - |
4576 | - buffer[ 20 ] = 0; //zipfile comment length |
4577 | - buffer[ 21 ] = 0; |
4578 | - |
4579 | - if ( device()->write( buffer, 22 ) != 22 ) |
4580 | - return false; |
4581 | - |
4582 | - return true; |
4583 | -} |
4584 | - |
4585 | -bool KZip::doWriteDir( const QString&, const QString&, const QString&, |
4586 | - mode_t, time_t, time_t, time_t ) { |
4587 | - return true; |
4588 | -} |
4589 | - |
4590 | -bool KZip::doPrepareWriting(const QString &name, const QString &user, |
4591 | - const QString &group, qint64 /*size*/, mode_t perm, |
4592 | - time_t atime, time_t mtime, time_t ctime) { |
4593 | - //qDebug(); |
4594 | - if ( !isOpen() ) |
4595 | - { |
4596 | - qWarning( "KZip::writeFile: You must open the zip file before writing to it\n"); |
4597 | - return false; |
4598 | - } |
4599 | - |
4600 | - if ( ! ( mode() & QIODevice::WriteOnly ) ) // accept WriteOnly and ReadWrite |
4601 | - { |
4602 | - qWarning( "KZip::writeFile: You must open the zip file for writing\n"); |
4603 | - return false; |
4604 | - } |
4605 | - |
4606 | - Q_ASSERT( device() ); |
4607 | - |
4608 | - // set right offset in zip. |
4609 | - if ( !device()->seek( d->m_offset ) ) { |
4610 | - qWarning() << "doPrepareWriting: cannot seek in ZIP file. Disk full?"; |
4611 | - return false; |
4612 | - } |
4613 | - |
4614 | - // delete entries in the filelist with the same fileName as the one we want |
4615 | - // to save, so that we don't have duplicate file entries when viewing the zip |
4616 | - // with konqi... |
4617 | - // CAUTION: the old file itself is still in the zip and won't be removed !!! |
4618 | - QMutableListIterator<KZipFileEntry*> it( d->m_fileList ); |
4619 | - //qDebug() << "fileName to write: " << name; |
4620 | - while(it.hasNext()) |
4621 | - { |
4622 | - it.next(); |
4623 | - //qDebug() << "prepfileName: " << it.current()->path(); |
4624 | - if (name == it.value()->path() ) |
4625 | - { |
4626 | - //qDebug() << "removing following entry: " << it.current()->path(); |
4627 | - delete it.value(); |
4628 | - it.remove(); |
4629 | - } |
4630 | - |
4631 | - } |
4632 | - // Find or create parent dir |
4633 | - KArchiveDirectory* parentDir = rootDir(); |
4634 | - QString fileName( name ); |
4635 | - int i = name.lastIndexOf( '/' ); |
4636 | - if ( i != -1 ) |
4637 | - { |
4638 | - QString dir = name.left( i ); |
4639 | - fileName = name.mid( i + 1 ); |
4640 | - //qDebug() << "ensuring" << dir << "exists. fileName=" << fileName; |
4641 | - parentDir = findOrCreate( dir ); |
4642 | - } |
4643 | - |
4644 | - // construct a KZipFileEntry and add it to list |
4645 | - KZipFileEntry * e = new KZipFileEntry( this, fileName, perm, mtime, user, group, QString(), |
4646 | - name, device()->pos() + 30 + name.length(), // start |
4647 | - 0 /*size unknown yet*/, d->m_compression, 0 /*csize unknown yet*/ ); |
4648 | - e->setHeaderStart( device()->pos() ); |
4649 | - //qDebug() << "wrote file start: " << e->position() << " name: " << name; |
4650 | - parentDir->addEntry( e ); |
4651 | - |
4652 | - d->m_currentFile = e; |
4653 | - d->m_fileList.append( e ); |
4654 | - |
4655 | - int extra_field_len = 0; |
4656 | - if ( d->m_extraField == ModificationTime ) |
4657 | - extra_field_len = 17; // value also used in finishWriting() |
4658 | - |
4659 | - // write out zip header |
4660 | - QByteArray encodedName = QFile::encodeName(name); |
4661 | - int bufferSize = extra_field_len + encodedName.length() + 30; |
4662 | - //qDebug() << "bufferSize=" << bufferSize; |
4663 | - char* buffer = new char[ bufferSize ]; |
4664 | - |
4665 | - buffer[ 0 ] = 'P'; //local file header signature |
4666 | - buffer[ 1 ] = 'K'; |
4667 | - buffer[ 2 ] = 3; |
4668 | - buffer[ 3 ] = 4; |
4669 | - |
4670 | - buffer[ 4 ] = 0x14; // version needed to extract |
4671 | - buffer[ 5 ] = 0; |
4672 | - |
4673 | - buffer[ 6 ] = 0; // general purpose bit flag |
4674 | - buffer[ 7 ] = 0; |
4675 | - |
4676 | - buffer[ 8 ] = char(e->encoding()); // compression method |
4677 | - buffer[ 9 ] = char(e->encoding() >> 8); |
4678 | - |
4679 | - transformToMsDos( e->datetime(), &buffer[ 10 ] ); |
4680 | - |
4681 | - buffer[ 14 ] = 'C'; //dummy crc |
4682 | - buffer[ 15 ] = 'R'; |
4683 | - buffer[ 16 ] = 'C'; |
4684 | - buffer[ 17 ] = 'q'; |
4685 | - |
4686 | - buffer[ 18 ] = 'C'; //compressed file size |
4687 | - buffer[ 19 ] = 'S'; |
4688 | - buffer[ 20 ] = 'I'; |
4689 | - buffer[ 21 ] = 'Z'; |
4690 | - |
4691 | - buffer[ 22 ] = 'U'; //uncompressed file size |
4692 | - buffer[ 23 ] = 'S'; |
4693 | - buffer[ 24 ] = 'I'; |
4694 | - buffer[ 25 ] = 'Z'; |
4695 | - |
4696 | - buffer[ 26 ] = (uchar)(encodedName.length()); //fileName length |
4697 | - buffer[ 27 ] = (uchar)(encodedName.length() >> 8); |
4698 | - |
4699 | - buffer[ 28 ] = (uchar)(extra_field_len); // extra field length |
4700 | - buffer[ 29 ] = (uchar)(extra_field_len >> 8); |
4701 | - |
4702 | - // file name |
4703 | - strncpy( buffer + 30, encodedName, encodedName.length() ); |
4704 | - |
4705 | - // extra field |
4706 | - if ( d->m_extraField == ModificationTime ) |
4707 | - { |
4708 | - char *extfield = buffer + 30 + encodedName.length(); |
4709 | - // "Extended timestamp" header (0x5455) |
4710 | - extfield[0] = 'U'; |
4711 | - extfield[1] = 'T'; |
4712 | - extfield[2] = 13; // data size |
4713 | - extfield[3] = 0; |
4714 | - extfield[4] = 1 | 2 | 4; // contains mtime, atime, ctime |
4715 | - |
4716 | - extfield[5] = char(mtime); |
4717 | - extfield[6] = char(mtime >> 8); |
4718 | - extfield[7] = char(mtime >> 16); |
4719 | - extfield[8] = char(mtime >> 24); |
4720 | - |
4721 | - extfield[9] = char(atime); |
4722 | - extfield[10] = char(atime >> 8); |
4723 | - extfield[11] = char(atime >> 16); |
4724 | - extfield[12] = char(atime >> 24); |
4725 | - |
4726 | - extfield[13] = char(ctime); |
4727 | - extfield[14] = char(ctime >> 8); |
4728 | - extfield[15] = char(ctime >> 16); |
4729 | - extfield[16] = char(ctime >> 24); |
4730 | - } |
4731 | - |
4732 | - // Write header |
4733 | - bool b = (device()->write( buffer, bufferSize ) == bufferSize ); |
4734 | - d->m_crc = 0L; |
4735 | - delete[] buffer; |
4736 | - |
4737 | - Q_ASSERT( b ); |
4738 | - if (!b) { |
4739 | - return false; |
4740 | - } |
4741 | - |
4742 | - // Prepare device for writing the data |
4743 | - // Either device() if no compression, or a KFilterDev to compress |
4744 | - if ( d->m_compression == 0 ) { |
4745 | - d->m_currentDev = device(); |
4746 | - return true; |
4747 | - } |
4748 | - |
4749 | - d->m_currentDev = KFilterDev::device( device(), "application/x-gzip", false ); |
4750 | - Q_ASSERT( d->m_currentDev ); |
4751 | - if ( !d->m_currentDev ) { |
4752 | - return false; // ouch |
4753 | - } |
4754 | - static_cast<KFilterDev *>(d->m_currentDev)->setSkipHeaders(); // Just zlib, not gzip |
4755 | - |
4756 | - b = d->m_currentDev->open( QIODevice::WriteOnly ); |
4757 | - Q_ASSERT( b ); |
4758 | - return b; |
4759 | -} |
4760 | - |
4761 | -bool KZip::doFinishWriting( qint64 size ) |
4762 | -{ |
4763 | - if ( d->m_currentFile->encoding() == 8 ) { |
4764 | - // Finish |
4765 | - (void)d->m_currentDev->write( 0, 0 ); |
4766 | - delete d->m_currentDev; |
4767 | - } |
4768 | - // If 0, d->m_currentDev was device() - don't delete ;) |
4769 | - d->m_currentDev = 0L; |
4770 | - |
4771 | - Q_ASSERT( d->m_currentFile ); |
4772 | - //qDebug() << "fileName: " << d->m_currentFile->path(); |
4773 | - //qDebug() << "getpos (at): " << device()->pos(); |
4774 | - d->m_currentFile->setSize(size); |
4775 | - int extra_field_len = 0; |
4776 | - if ( d->m_extraField == ModificationTime ) |
4777 | - extra_field_len = 17; // value also used in finishWriting() |
4778 | - |
4779 | - int csize = device()->pos() - |
4780 | - d->m_currentFile->headerStart() - 30 - |
4781 | - d->m_currentFile->path().length() - extra_field_len; |
4782 | - d->m_currentFile->setCompressedSize(csize); |
4783 | - //qDebug() << "usize: " << d->m_currentFile->size(); |
4784 | - //qDebug() << "csize: " << d->m_currentFile->compressedSize(); |
4785 | - //qDebug() << "headerstart: " << d->m_currentFile->headerStart(); |
4786 | - |
4787 | - //qDebug() << "crc: " << d->m_crc; |
4788 | - d->m_currentFile->setCRC32( d->m_crc ); |
4789 | - |
4790 | - d->m_currentFile = 0L; |
4791 | - |
4792 | - // update saved offset for appending new files |
4793 | - d->m_offset = device()->pos(); |
4794 | - return true; |
4795 | -} |
4796 | - |
4797 | -bool KZip::doWriteSymLink(const QString &name, const QString &target, |
4798 | - const QString &user, const QString &group, |
4799 | - mode_t perm, time_t atime, time_t mtime, time_t ctime) { |
4800 | - // reassure that symlink flag is set, otherwise strange things happen on |
4801 | - // extraction |
4802 | - perm |= S_IFLNK; |
4803 | - Compression c = compression(); |
4804 | - setCompression(NoCompression); // link targets are never compressed |
4805 | - |
4806 | - if (!doPrepareWriting(name, user, group, 0, perm, atime, mtime, ctime)) { |
4807 | - qWarning() << "prepareWriting failed"; |
4808 | - setCompression(c); |
4809 | - return false; |
4810 | - } |
4811 | - |
4812 | - QByteArray symlink_target = QFile::encodeName(target); |
4813 | - if (!writeData(symlink_target, symlink_target.length())) { |
4814 | - qWarning() << "writeData failed"; |
4815 | - setCompression(c); |
4816 | - return false; |
4817 | - } |
4818 | - |
4819 | - if (!finishWriting(symlink_target.length())) { |
4820 | - qWarning() << "finishWriting failed"; |
4821 | - setCompression(c); |
4822 | - return false; |
4823 | - } |
4824 | - |
4825 | - setCompression(c); |
4826 | - return true; |
4827 | -} |
4828 | - |
4829 | -void KZip::virtual_hook( int id, void* data ) |
4830 | -{ |
4831 | - KArchive::virtual_hook( id, data ); |
4832 | -} |
4833 | - |
4834 | -bool KZip::writeData(const char * data, qint64 size) |
4835 | -{ |
4836 | - Q_ASSERT( d->m_currentFile ); |
4837 | - Q_ASSERT( d->m_currentDev ); |
4838 | - if (!d->m_currentFile || !d->m_currentDev) { |
4839 | - return false; |
4840 | - } |
4841 | - |
4842 | - // crc to be calculated over uncompressed stuff... |
4843 | - // and they didn't mention it in their docs... |
4844 | - d->m_crc = crc32(d->m_crc, (const Bytef *) data , size); |
4845 | - |
4846 | - qint64 written = d->m_currentDev->write( data, size ); |
4847 | - //qDebug() << "wrote" << size << "bytes."; |
4848 | - return written == size; |
4849 | -} |
4850 | - |
4851 | -void KZip::setCompression( Compression c ) |
4852 | -{ |
4853 | - d->m_compression = ( c == NoCompression ) ? 0 : 8; |
4854 | -} |
4855 | - |
4856 | -KZip::Compression KZip::compression() const |
4857 | -{ |
4858 | - return ( d->m_compression == 8 ) ? DeflateCompression : NoCompression; |
4859 | -} |
4860 | - |
4861 | -void KZip::setExtraField( ExtraField ef ) |
4862 | -{ |
4863 | - d->m_extraField = ef; |
4864 | -} |
4865 | - |
4866 | -KZip::ExtraField KZip::extraField() const |
4867 | -{ |
4868 | - return d->m_extraField; |
4869 | -} |
4870 | - |
4871 | -//////////////////////////////////////////////////////////////////////// |
4872 | -////////////////////// KZipFileEntry//////////////////////////////////// |
4873 | -//////////////////////////////////////////////////////////////////////// |
4874 | -class KZipFileEntry::KZipFileEntryPrivate |
4875 | -{ |
4876 | -public: |
4877 | - KZipFileEntryPrivate() |
4878 | - : crc(0), |
4879 | - compressedSize(0), |
4880 | - headerStart(0), |
4881 | - encoding(0) |
4882 | - {} |
4883 | - unsigned long crc; |
4884 | - qint64 compressedSize; |
4885 | - qint64 headerStart; |
4886 | - int encoding; |
4887 | - QString path; |
4888 | -}; |
4889 | - |
4890 | -KZipFileEntry::KZipFileEntry(KZip* zip, const QString& name, int access, int date, |
4891 | - const QString& user, const QString& group, const QString& symlink, |
4892 | - const QString& path, qint64 start, qint64 uncompressedSize, |
4893 | - int encoding, qint64 compressedSize) |
4894 | - : KArchiveFile(zip, name, access, date, user, group, symlink, start, uncompressedSize ), |
4895 | - d(new KZipFileEntryPrivate) |
4896 | -{ |
4897 | - d->path = path; |
4898 | - d->encoding = encoding; |
4899 | - d->compressedSize = compressedSize; |
4900 | -} |
4901 | - |
4902 | -KZipFileEntry::~KZipFileEntry() |
4903 | -{ |
4904 | - delete d; |
4905 | -} |
4906 | - |
4907 | -int KZipFileEntry::encoding() const |
4908 | -{ |
4909 | - return d->encoding; |
4910 | -} |
4911 | - |
4912 | -qint64 KZipFileEntry::compressedSize() const |
4913 | -{ |
4914 | - return d->compressedSize; |
4915 | -} |
4916 | - |
4917 | -void KZipFileEntry::setCompressedSize(qint64 compressedSize) |
4918 | -{ |
4919 | - d->compressedSize = compressedSize; |
4920 | -} |
4921 | - |
4922 | -void KZipFileEntry::setHeaderStart(qint64 headerstart) |
4923 | -{ |
4924 | - d->headerStart = headerstart; |
4925 | -} |
4926 | - |
4927 | -qint64 KZipFileEntry::headerStart() const |
4928 | -{ |
4929 | - return d->headerStart; |
4930 | -} |
4931 | - |
4932 | -unsigned long KZipFileEntry::crc32() const |
4933 | -{ |
4934 | - return d->crc; |
4935 | -} |
4936 | - |
4937 | -void KZipFileEntry::setCRC32(unsigned long crc32) |
4938 | -{ |
4939 | - d->crc=crc32; |
4940 | -} |
4941 | - |
4942 | -const QString &KZipFileEntry::path() const |
4943 | -{ |
4944 | - return d->path; |
4945 | -} |
4946 | - |
4947 | -QByteArray KZipFileEntry::data() const |
4948 | -{ |
4949 | - QIODevice* dev = createDevice(); |
4950 | - QByteArray arr; |
4951 | - if ( dev ) { |
4952 | - arr = dev->readAll(); |
4953 | - delete dev; |
4954 | - } |
4955 | - return arr; |
4956 | -} |
4957 | - |
4958 | -QIODevice* KZipFileEntry::createDevice() const |
4959 | -{ |
4960 | - //qDebug() << "creating iodevice limited to pos=" << position() << ", csize=" << compressedSize(); |
4961 | - // Limit the reading to the appropriate part of the underlying device (e.g. file) |
4962 | - KLimitedIODevice* limitedDev = new KLimitedIODevice( archive()->device(), position(), compressedSize() ); |
4963 | - if ( encoding() == 0 || compressedSize() == 0 ) // no compression (or even no data) |
4964 | - return limitedDev; |
4965 | - |
4966 | - if ( encoding() == 8 ) |
4967 | - { |
4968 | - // On top of that, create a device that uncompresses the zlib data |
4969 | - QIODevice* filterDev = KFilterDev::device( limitedDev, "application/x-gzip" ); |
4970 | - if ( !filterDev ) |
4971 | - return 0L; // ouch |
4972 | - static_cast<KFilterDev *>(filterDev)->setSkipHeaders(); // Just zlib, not gzip |
4973 | - bool b = filterDev->open( QIODevice::ReadOnly ); |
4974 | - static_cast<void>(b); // annoying unused variable warning |
4975 | - Q_ASSERT( b ); |
4976 | - return filterDev; |
4977 | - } |
4978 | - |
4979 | - qWarning() << "This zip file contains files compressed with method" |
4980 | - << encoding() << ", this method is currently not supported by KZip," |
4981 | - << "please use a command-line tool to handle this file."; |
4982 | - return 0L; |
4983 | -} |
4984 | |
4985 | === removed file 'src/core/external/kfilter/kzip.h' |
4986 | --- src/core/external/kfilter/kzip.h 2010-04-15 12:28:34 +0000 |
4987 | +++ src/core/external/kfilter/kzip.h 1970-01-01 00:00:00 +0000 |
4988 | @@ -1,224 +0,0 @@ |
4989 | -/* This file is part of the KDE libraries |
4990 | - Copyright (C) 2002 Holger Schroeder <holger-kde@holgis.net> |
4991 | - |
4992 | - This library is free software; you can redistribute it and/or |
4993 | - modify it under the terms of the GNU Library General Public |
4994 | - License version 2 as published by the Free Software Foundation. |
4995 | - |
4996 | - This library is distributed in the hope that it will be useful, |
4997 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
4998 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4999 | - Library General Public License for more details. |
5000 | - |
The diff has been truncated for viewing.