]>
Commit | Line | Data |
---|---|---|
5526e819 | 1 | ///////////////////////////////////////////////////////////////////////////// |
ce7208d4 | 2 | // Name: wx/zipstrm.h |
00375592 VZ |
3 | // Purpose: Streams for Zip files |
4 | // Author: Mike Wetherell | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) Mike Wetherell | |
65571936 | 7 | // Licence: wxWindows licence |
5526e819 VS |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
00375592 VZ |
10 | #ifndef _WX_WXZIPSTREAM_H__ |
11 | #define _WX_WXZIPSTREAM_H__ | |
5526e819 | 12 | |
d1af991f | 13 | #include "wx/defs.h" |
5526e819 | 14 | |
5410f572 | 15 | #if wxUSE_ZIPSTREAM |
d1af991f | 16 | |
00375592 | 17 | #include "wx/archive.h" |
00375592 | 18 | #include "wx/filename.h" |
5526e819 | 19 | |
fe47da7b MW |
20 | // some methods from wxZipInputStream and wxZipOutputStream stream do not get |
21 | // exported/imported when compiled with Mingw versions before 3.4.2. So they | |
22 | // are imported/exported individually as a workaround | |
23 | #if (defined(__GNUWIN32__) || defined(__MINGW32__)) \ | |
24 | && (!defined __GNUC__ \ | |
25 | || !defined __GNUC_MINOR__ \ | |
26 | || !defined __GNUC_PATCHLEVEL__ \ | |
27 | || __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 30402) | |
ce7208d4 | 28 | #define WXZIPFIX WXDLLIMPEXP_BASE |
fe47da7b MW |
29 | #else |
30 | #define WXZIPFIX | |
31 | #endif | |
5526e819 | 32 | |
00375592 VZ |
33 | ///////////////////////////////////////////////////////////////////////////// |
34 | // constants | |
35 | ||
36 | // Compression Method, only 0 (store) and 8 (deflate) are supported here | |
37 | // | |
38 | enum wxZipMethod | |
39 | { | |
40 | wxZIP_METHOD_STORE, | |
41 | wxZIP_METHOD_SHRINK, | |
42 | wxZIP_METHOD_REDUCE1, | |
43 | wxZIP_METHOD_REDUCE2, | |
44 | wxZIP_METHOD_REDUCE3, | |
45 | wxZIP_METHOD_REDUCE4, | |
46 | wxZIP_METHOD_IMPLODE, | |
47 | wxZIP_METHOD_TOKENIZE, | |
48 | wxZIP_METHOD_DEFLATE, | |
49 | wxZIP_METHOD_DEFLATE64, | |
50 | wxZIP_METHOD_BZIP2 = 12, | |
51 | wxZIP_METHOD_DEFAULT = 0xffff | |
52 | }; | |
53 | ||
54 | // Originating File-System. | |
ce7208d4 | 55 | // |
00375592 VZ |
56 | // These are Pkware's values. Note that Info-zip disagree on some of them, |
57 | // most notably NTFS. | |
58 | // | |
59 | enum wxZipSystem | |
60 | { | |
61 | wxZIP_SYSTEM_MSDOS, | |
62 | wxZIP_SYSTEM_AMIGA, | |
63 | wxZIP_SYSTEM_OPENVMS, | |
64 | wxZIP_SYSTEM_UNIX, | |
65 | wxZIP_SYSTEM_VM_CMS, | |
66 | wxZIP_SYSTEM_ATARI_ST, | |
67 | wxZIP_SYSTEM_OS2_HPFS, | |
68 | wxZIP_SYSTEM_MACINTOSH, | |
69 | wxZIP_SYSTEM_Z_SYSTEM, | |
70 | wxZIP_SYSTEM_CPM, | |
71 | wxZIP_SYSTEM_WINDOWS_NTFS, | |
72 | wxZIP_SYSTEM_MVS, | |
73 | wxZIP_SYSTEM_VSE, | |
74 | wxZIP_SYSTEM_ACORN_RISC, | |
75 | wxZIP_SYSTEM_VFAT, | |
76 | wxZIP_SYSTEM_ALTERNATE_MVS, | |
77 | wxZIP_SYSTEM_BEOS, | |
78 | wxZIP_SYSTEM_TANDEM, | |
79 | wxZIP_SYSTEM_OS_400 | |
80 | }; | |
81 | ||
82 | // Dos/Win file attributes | |
83 | // | |
84 | enum wxZipAttributes | |
85 | { | |
86 | wxZIP_A_RDONLY = 0x01, | |
87 | wxZIP_A_HIDDEN = 0x02, | |
88 | wxZIP_A_SYSTEM = 0x04, | |
89 | wxZIP_A_SUBDIR = 0x10, | |
90 | wxZIP_A_ARCH = 0x20, | |
91 | ||
92 | wxZIP_A_MASK = 0x37 | |
93 | }; | |
94 | ||
95 | // Values for the flags field in the zip headers | |
96 | // | |
97 | enum wxZipFlags | |
98 | { | |
99 | wxZIP_ENCRYPTED = 0x0001, | |
100 | wxZIP_DEFLATE_NORMAL = 0x0000, // normal compression | |
101 | wxZIP_DEFLATE_EXTRA = 0x0002, // extra compression | |
102 | wxZIP_DEFLATE_FAST = 0x0004, // fast compression | |
103 | wxZIP_DEFLATE_SUPERFAST = 0x0006, // superfast compression | |
104 | wxZIP_DEFLATE_MASK = 0x0006, | |
105 | wxZIP_SUMS_FOLLOW = 0x0008, // crc and sizes come after the data | |
106 | wxZIP_ENHANCED = 0x0010, | |
107 | wxZIP_PATCH = 0x0020, | |
108 | wxZIP_STRONG_ENC = 0x0040, | |
109 | wxZIP_UNUSED = 0x0F80, | |
110 | wxZIP_RESERVED = 0xF000 | |
111 | }; | |
112 | ||
113 | // Forward decls | |
114 | // | |
115 | class WXDLLIMPEXP_BASE wxZipEntry; | |
116 | class WXDLLIMPEXP_BASE wxZipInputStream; | |
117 | ||
118 | ||
119 | ///////////////////////////////////////////////////////////////////////////// | |
120 | // wxZipNotifier | |
5526e819 | 121 | |
00375592 | 122 | class WXDLLIMPEXP_BASE wxZipNotifier |
5526e819 | 123 | { |
f6bcfd97 | 124 | public: |
00375592 VZ |
125 | virtual ~wxZipNotifier() { } |
126 | ||
127 | virtual void OnEntryUpdated(wxZipEntry& entry) = 0; | |
128 | }; | |
129 | ||
130 | ||
131 | ///////////////////////////////////////////////////////////////////////////// | |
132 | // Zip Entry - holds the meta data for a file in the zip | |
133 | ||
134 | class WXDLLIMPEXP_BASE wxZipEntry : public wxArchiveEntry | |
135 | { | |
136 | public: | |
137 | wxZipEntry(const wxString& name = wxEmptyString, | |
138 | const wxDateTime& dt = wxDateTime::Now(), | |
139 | wxFileOffset size = wxInvalidOffset); | |
140 | virtual ~wxZipEntry(); | |
141 | ||
142 | wxZipEntry(const wxZipEntry& entry); | |
143 | wxZipEntry& operator=(const wxZipEntry& entry); | |
144 | ||
145 | // Get accessors | |
146 | wxDateTime GetDateTime() const { return m_DateTime; } | |
147 | wxFileOffset GetSize() const { return m_Size; } | |
148 | wxFileOffset GetOffset() const { return m_Offset; } | |
149 | wxString GetInternalName() const { return m_Name; } | |
150 | int GetMethod() const { return m_Method; } | |
151 | int GetFlags() const { return m_Flags; } | |
152 | wxUint32 GetCrc() const { return m_Crc; } | |
153 | wxFileOffset GetCompressedSize() const { return m_CompressedSize; } | |
154 | int GetSystemMadeBy() const { return m_SystemMadeBy; } | |
155 | wxString GetComment() const { return m_Comment; } | |
156 | wxUint32 GetExternalAttributes() const { return m_ExternalAttributes; } | |
157 | wxPathFormat GetInternalFormat() const { return wxPATH_UNIX; } | |
158 | int GetMode() const; | |
159 | const char *GetLocalExtra() const; | |
160 | size_t GetLocalExtraLen() const; | |
161 | const char *GetExtra() const; | |
162 | size_t GetExtraLen() const; | |
163 | wxString GetName(wxPathFormat format = wxPATH_NATIVE) const; | |
164 | ||
165 | // is accessors | |
166 | inline bool IsDir() const; | |
167 | inline bool IsText() const; | |
168 | inline bool IsReadOnly() const; | |
169 | inline bool IsMadeByUnix() const; | |
170 | ||
171 | // set accessors | |
172 | void SetDateTime(const wxDateTime& dt) { m_DateTime = dt; } | |
173 | void SetSize(wxFileOffset size) { m_Size = size; } | |
ceefc965 | 174 | void SetMethod(int method) { m_Method = (wxUint16)method; } |
00375592 VZ |
175 | void SetComment(const wxString& comment) { m_Comment = comment; } |
176 | void SetExternalAttributes(wxUint32 attr ) { m_ExternalAttributes = attr; } | |
177 | void SetSystemMadeBy(int system); | |
178 | void SetMode(int mode); | |
179 | void SetExtra(const char *extra, size_t len); | |
180 | void SetLocalExtra(const char *extra, size_t len); | |
181 | ||
182 | inline void SetName(const wxString& name, | |
183 | wxPathFormat format = wxPATH_NATIVE); | |
184 | ||
185 | static wxString GetInternalName(const wxString& name, | |
186 | wxPathFormat format = wxPATH_NATIVE, | |
187 | bool *pIsDir = NULL); | |
188 | ||
189 | // set is accessors | |
190 | void SetIsDir(bool isDir = true); | |
191 | inline void SetIsReadOnly(bool isReadOnly = true); | |
192 | inline void SetIsText(bool isText = true); | |
f6bcfd97 | 193 | |
00375592 VZ |
194 | wxZipEntry *Clone() const { return ZipClone(); } |
195 | ||
196 | void SetNotifier(wxZipNotifier& notifier); | |
197 | void UnsetNotifier(); | |
f6bcfd97 BP |
198 | |
199 | protected: | |
00375592 VZ |
200 | // Internal attributes |
201 | enum { TEXT_ATTR = 1 }; | |
202 | ||
203 | // protected Get accessors | |
204 | int GetVersionNeeded() const { return m_VersionNeeded; } | |
205 | wxFileOffset GetKey() const { return m_Key; } | |
206 | int GetVersionMadeBy() const { return m_VersionMadeBy; } | |
207 | int GetDiskStart() const { return m_DiskStart; } | |
208 | int GetInternalAttributes() const { return m_InternalAttributes; } | |
209 | ||
ceefc965 | 210 | void SetVersionNeeded(int version) { m_VersionNeeded = (wxUint16)version; } |
00375592 | 211 | void SetOffset(wxFileOffset offset) { m_Offset = offset; } |
ceefc965 WS |
212 | void SetFlags(int flags) { m_Flags = (wxUint16)flags; } |
213 | void SetVersionMadeBy(int version) { m_VersionMadeBy = (wxUint8)version; } | |
00375592 VZ |
214 | void SetCrc(wxUint32 crc) { m_Crc = crc; } |
215 | void SetCompressedSize(wxFileOffset size) { m_CompressedSize = size; } | |
216 | void SetKey(wxFileOffset offset) { m_Key = offset; } | |
ceefc965 WS |
217 | void SetDiskStart(int start) { m_DiskStart = (wxUint16)start; } |
218 | void SetInternalAttributes(int attr) { m_InternalAttributes = (wxUint16)attr; } | |
00375592 VZ |
219 | |
220 | virtual wxZipEntry *ZipClone() const { return new wxZipEntry(*this); } | |
221 | ||
222 | void Notify(); | |
f6bcfd97 | 223 | |
9ff1e319 | 224 | private: |
00375592 VZ |
225 | wxArchiveEntry* DoClone() const { return ZipClone(); } |
226 | ||
227 | size_t ReadLocal(wxInputStream& stream, wxMBConv& conv); | |
228 | size_t WriteLocal(wxOutputStream& stream, wxMBConv& conv) const; | |
229 | ||
230 | size_t ReadCentral(wxInputStream& stream, wxMBConv& conv); | |
231 | size_t WriteCentral(wxOutputStream& stream, wxMBConv& conv) const; | |
232 | ||
233 | size_t ReadDescriptor(wxInputStream& stream); | |
234 | size_t WriteDescriptor(wxOutputStream& stream, wxUint32 crc, | |
235 | wxFileOffset compressedSize, wxFileOffset size); | |
236 | ||
237 | wxUint8 m_SystemMadeBy; // one of enum wxZipSystem | |
238 | wxUint8 m_VersionMadeBy; // major * 10 + minor | |
239 | ||
240 | wxUint16 m_VersionNeeded; // ver needed to extract (20 i.e. v2.0) | |
241 | wxUint16 m_Flags; | |
242 | wxUint16 m_Method; // compression method (one of wxZipMethod) | |
243 | wxDateTime m_DateTime; | |
244 | wxUint32 m_Crc; | |
245 | wxFileOffset m_CompressedSize; | |
588066b7 | 246 | wxFileOffset m_Size; |
00375592 VZ |
247 | wxString m_Name; // in internal format |
248 | wxFileOffset m_Key; // the original offset for copied entries | |
249 | wxFileOffset m_Offset; // file offset of the entry | |
250 | ||
251 | wxString m_Comment; | |
252 | wxUint16 m_DiskStart; // for multidisk archives, not unsupported | |
253 | wxUint16 m_InternalAttributes; // bit 0 set for text files | |
254 | wxUint32 m_ExternalAttributes; // system specific depends on SystemMadeBy | |
255 | ||
256 | class wxZipMemory *m_Extra; | |
257 | class wxZipMemory *m_LocalExtra; | |
258 | ||
259 | wxZipNotifier *m_zipnotifier; | |
260 | class wxZipWeakLinks *m_backlink; | |
f6bcfd97 | 261 | |
00375592 VZ |
262 | friend class wxZipInputStream; |
263 | friend class wxZipOutputStream; | |
264 | ||
265 | DECLARE_DYNAMIC_CLASS(wxZipEntry) | |
266 | }; | |
267 | ||
268 | ||
269 | ///////////////////////////////////////////////////////////////////////////// | |
ce7208d4 | 270 | // wxZipOutputStream |
00375592 | 271 | |
8fc574b4 | 272 | WX_DECLARE_LIST_WITH_DECL(wxZipEntry, wxZipEntryList_, class WXDLLIMPEXP_BASE); |
00375592 VZ |
273 | |
274 | class WXDLLIMPEXP_BASE wxZipOutputStream : public wxArchiveOutputStream | |
275 | { | |
276 | public: | |
277 | wxZipOutputStream(wxOutputStream& stream, | |
278 | int level = -1, | |
279 | wxMBConv& conv = wxConvLocal); | |
8fc574b4 MW |
280 | wxZipOutputStream(wxOutputStream *stream, |
281 | int level = -1, | |
282 | wxMBConv& conv = wxConvLocal); | |
fe47da7b | 283 | virtual WXZIPFIX ~wxZipOutputStream(); |
00375592 VZ |
284 | |
285 | bool PutNextEntry(wxZipEntry *entry) { return DoCreate(entry); } | |
286 | ||
fe47da7b MW |
287 | bool WXZIPFIX PutNextEntry(const wxString& name, |
288 | const wxDateTime& dt = wxDateTime::Now(), | |
289 | wxFileOffset size = wxInvalidOffset); | |
00375592 | 290 | |
fe47da7b MW |
291 | bool WXZIPFIX PutNextDirEntry(const wxString& name, |
292 | const wxDateTime& dt = wxDateTime::Now()); | |
00375592 | 293 | |
fe47da7b MW |
294 | bool WXZIPFIX CopyEntry(wxZipEntry *entry, wxZipInputStream& inputStream); |
295 | bool WXZIPFIX CopyArchiveMetaData(wxZipInputStream& inputStream); | |
00375592 | 296 | |
fe47da7b MW |
297 | void WXZIPFIX Sync(); |
298 | bool WXZIPFIX CloseEntry(); | |
299 | bool WXZIPFIX Close(); | |
00375592 VZ |
300 | |
301 | void SetComment(const wxString& comment) { m_Comment = comment; } | |
302 | ||
303 | int GetLevel() const { return m_level; } | |
fe47da7b | 304 | void WXZIPFIX SetLevel(int level); |
ce7208d4 | 305 | |
00375592 | 306 | protected: |
fe47da7b | 307 | virtual size_t WXZIPFIX OnSysWrite(const void *buffer, size_t size); |
00375592 VZ |
308 | virtual wxFileOffset OnSysTell() const { return m_entrySize; } |
309 | ||
fe47da7b | 310 | // this protected interface isn't yet finalised |
00375592 | 311 | struct Buffer { const char *m_data; size_t m_size; }; |
fe47da7b MW |
312 | virtual wxOutputStream* WXZIPFIX OpenCompressor(wxOutputStream& stream, |
313 | wxZipEntry& entry, | |
314 | const Buffer bufs[]); | |
315 | virtual bool WXZIPFIX CloseCompressor(wxOutputStream *comp); | |
00375592 | 316 | |
fe47da7b MW |
317 | bool IsParentSeekable() const |
318 | { return m_offsetAdjustment != wxInvalidOffset; } | |
00375592 VZ |
319 | |
320 | private: | |
8fc574b4 MW |
321 | void Init(int level); |
322 | ||
9ff1e319 MW |
323 | bool WXZIPFIX PutNextEntry(wxArchiveEntry *entry); |
324 | bool WXZIPFIX CopyEntry(wxArchiveEntry *entry, wxArchiveInputStream& stream); | |
325 | bool WXZIPFIX CopyArchiveMetaData(wxArchiveInputStream& stream); | |
326 | ||
fe47da7b | 327 | bool IsOpened() const { return m_comp || m_pending; } |
00375592 VZ |
328 | |
329 | bool DoCreate(wxZipEntry *entry, bool raw = false); | |
330 | void CreatePendingEntry(const void *buffer, size_t size); | |
331 | void CreatePendingEntry(); | |
332 | ||
333 | class wxStoredOutputStream *m_store; | |
334 | class wxZlibOutputStream2 *m_deflate; | |
335 | class wxZipStreamLink *m_backlink; | |
8fc574b4 | 336 | wxZipEntryList_ m_entries; |
00375592 VZ |
337 | char *m_initialData; |
338 | size_t m_initialSize; | |
339 | wxZipEntry *m_pending; | |
340 | bool m_raw; | |
341 | wxFileOffset m_headerOffset; | |
342 | size_t m_headerSize; | |
343 | wxFileOffset m_entrySize; | |
344 | wxUint32 m_crcAccumulator; | |
345 | wxOutputStream *m_comp; | |
346 | int m_level; | |
347 | wxFileOffset m_offsetAdjustment; | |
348 | wxString m_Comment; | |
349 | ||
350 | DECLARE_NO_COPY_CLASS(wxZipOutputStream) | |
351 | }; | |
352 | ||
353 | ||
354 | ///////////////////////////////////////////////////////////////////////////// | |
ce7208d4 | 355 | // wxZipInputStream |
00375592 VZ |
356 | |
357 | class WXDLLIMPEXP_BASE wxZipInputStream : public wxArchiveInputStream | |
358 | { | |
359 | public: | |
360 | typedef wxZipEntry entry_type; | |
361 | ||
362 | wxZipInputStream(wxInputStream& stream, wxMBConv& conv = wxConvLocal); | |
8fc574b4 | 363 | wxZipInputStream(wxInputStream *stream, wxMBConv& conv = wxConvLocal); |
d13a08ab | 364 | |
8fc574b4 | 365 | #if WXWIN_COMPATIBILITY_2_6 && wxUSE_FFILE |
fe47da7b MW |
366 | wxZipInputStream(const wxString& archive, const wxString& file) |
367 | : wxArchiveInputStream(OpenFile(archive), wxConvLocal) { Init(file); } | |
d13a08ab MW |
368 | #endif |
369 | ||
fe47da7b | 370 | virtual WXZIPFIX ~wxZipInputStream(); |
00375592 VZ |
371 | |
372 | bool OpenEntry(wxZipEntry& entry) { return DoOpen(&entry); } | |
fe47da7b | 373 | bool WXZIPFIX CloseEntry(); |
00375592 VZ |
374 | |
375 | wxZipEntry *GetNextEntry(); | |
376 | ||
fe47da7b MW |
377 | wxString WXZIPFIX GetComment(); |
378 | int WXZIPFIX GetTotalEntries(); | |
00375592 VZ |
379 | |
380 | virtual wxFileOffset GetLength() const { return m_entry.GetSize(); } | |
381 | ||
382 | protected: | |
fe47da7b | 383 | size_t WXZIPFIX OnSysRead(void *buffer, size_t size); |
00375592 | 384 | wxFileOffset OnSysTell() const { return m_decomp ? m_decomp->TellI() : 0; } |
d13a08ab | 385 | |
8fc574b4 | 386 | #if WXWIN_COMPATIBILITY_2_6 && wxUSE_FFILE |
fe47da7b | 387 | wxFileOffset WXZIPFIX OnSysSeek(wxFileOffset seek, wxSeekMode mode); |
d13a08ab | 388 | #endif |
00375592 | 389 | |
d13a08ab | 390 | // this protected interface isn't yet finalised |
fe47da7b MW |
391 | virtual wxInputStream* WXZIPFIX OpenDecompressor(wxInputStream& stream); |
392 | virtual bool WXZIPFIX CloseDecompressor(wxInputStream *decomp); | |
00375592 VZ |
393 | |
394 | private: | |
395 | void Init(); | |
fe47da7b | 396 | void Init(const wxString& file); |
8fc574b4 MW |
397 | #if WXWIN_COMPATIBILITY_2_6 && wxUSE_FFILE |
398 | static wxInputStream *OpenFile(const wxString& archive); | |
399 | #endif | |
00375592 | 400 | |
9ff1e319 MW |
401 | wxArchiveEntry *DoGetNextEntry() { return GetNextEntry(); } |
402 | ||
403 | bool WXZIPFIX OpenEntry(wxArchiveEntry& entry); | |
404 | ||
00375592 VZ |
405 | wxStreamError ReadLocal(bool readEndRec = false); |
406 | wxStreamError ReadCentral(); | |
407 | ||
408 | wxUint32 ReadSignature(); | |
409 | bool FindEndRecord(); | |
410 | bool LoadEndRecord(); | |
ce7208d4 | 411 | |
00375592 VZ |
412 | bool AtHeader() const { return m_headerSize == 0; } |
413 | bool AfterHeader() const { return m_headerSize > 0 && !m_decomp; } | |
414 | bool IsOpened() const { return m_decomp != NULL; } | |
415 | ||
416 | wxZipStreamLink *MakeLink(wxZipOutputStream *out); | |
417 | ||
418 | bool DoOpen(wxZipEntry *entry = NULL, bool raw = false); | |
419 | bool OpenDecompressor(bool raw = false); | |
420 | ||
421 | class wxStoredInputStream *m_store; | |
422 | class wxZlibInputStream2 *m_inflate; | |
423 | class wxRawInputStream *m_rawin; | |
00375592 VZ |
424 | wxZipEntry m_entry; |
425 | bool m_raw; | |
426 | size_t m_headerSize; | |
427 | wxUint32 m_crcAccumulator; | |
428 | wxInputStream *m_decomp; | |
429 | bool m_parentSeekable; | |
430 | class wxZipWeakLinks *m_weaklinks; | |
431 | class wxZipStreamLink *m_streamlink; | |
432 | wxFileOffset m_offsetAdjustment; | |
433 | wxFileOffset m_position; | |
434 | wxUint32 m_signature; | |
435 | size_t m_TotalEntries; | |
436 | wxString m_Comment; | |
437 | ||
438 | friend bool wxZipOutputStream::CopyEntry( | |
439 | wxZipEntry *entry, wxZipInputStream& inputStream); | |
440 | friend bool wxZipOutputStream::CopyArchiveMetaData( | |
441 | wxZipInputStream& inputStream); | |
22f3361e | 442 | |
8fc574b4 | 443 | #if WXWIN_COMPATIBILITY_2_6 && wxUSE_FFILE |
d13a08ab MW |
444 | bool m_allowSeeking; |
445 | friend class wxZipFSInputStream; | |
446 | #endif | |
447 | ||
22f3361e | 448 | DECLARE_NO_COPY_CLASS(wxZipInputStream) |
5526e819 VS |
449 | }; |
450 | ||
451 | ||
81f90336 MW |
452 | ///////////////////////////////////////////////////////////////////////////// |
453 | // Iterators | |
454 | ||
455 | #if wxUSE_STL || defined WX_TEST_ARCHIVE_ITERATOR | |
456 | typedef wxArchiveIterator<wxZipInputStream> wxZipIter; | |
457 | typedef wxArchiveIterator<wxZipInputStream, | |
458 | std::pair<wxString, wxZipEntry*> > wxZipPairIter; | |
459 | #endif | |
460 | ||
461 | ||
00375592 VZ |
462 | ///////////////////////////////////////////////////////////////////////////// |
463 | // wxZipClassFactory | |
5526e819 | 464 | |
00375592 VZ |
465 | class WXDLLIMPEXP_BASE wxZipClassFactory : public wxArchiveClassFactory |
466 | { | |
467 | public: | |
81f90336 MW |
468 | typedef wxZipEntry entry_type; |
469 | typedef wxZipInputStream instream_type; | |
470 | typedef wxZipOutputStream outstream_type; | |
471 | typedef wxZipNotifier notifier_type; | |
472 | #if wxUSE_STL || defined WX_TEST_ARCHIVE_ITERATOR | |
473 | typedef wxZipIter iter_type; | |
474 | typedef wxZipPairIter pairiter_type; | |
475 | #endif | |
476 | ||
8fc574b4 MW |
477 | wxZipClassFactory(); |
478 | ||
00375592 VZ |
479 | wxZipEntry *NewEntry() const |
480 | { return new wxZipEntry; } | |
481 | wxZipInputStream *NewStream(wxInputStream& stream) const | |
482 | { return new wxZipInputStream(stream, GetConv()); } | |
483 | wxZipOutputStream *NewStream(wxOutputStream& stream) const | |
484 | { return new wxZipOutputStream(stream, -1, GetConv()); } | |
8fc574b4 MW |
485 | wxZipInputStream *NewStream(wxInputStream *stream) const |
486 | { return new wxZipInputStream(stream, GetConv()); } | |
487 | wxZipOutputStream *NewStream(wxOutputStream *stream) const | |
488 | { return new wxZipOutputStream(stream, -1, GetConv()); } | |
00375592 VZ |
489 | |
490 | wxString GetInternalName(const wxString& name, | |
491 | wxPathFormat format = wxPATH_NATIVE) const | |
492 | { return wxZipEntry::GetInternalName(name, format); } | |
493 | ||
8fc574b4 MW |
494 | const wxChar * const *GetProtocols(wxStreamProtocolType type |
495 | = wxSTREAM_PROTOCOL) const; | |
496 | ||
00375592 VZ |
497 | protected: |
498 | wxArchiveEntry *DoNewEntry() const | |
499 | { return NewEntry(); } | |
500 | wxArchiveInputStream *DoNewStream(wxInputStream& stream) const | |
501 | { return NewStream(stream); } | |
502 | wxArchiveOutputStream *DoNewStream(wxOutputStream& stream) const | |
503 | { return NewStream(stream); } | |
8fc574b4 MW |
504 | wxArchiveInputStream *DoNewStream(wxInputStream *stream) const |
505 | { return NewStream(stream); } | |
506 | wxArchiveOutputStream *DoNewStream(wxOutputStream *stream) const | |
507 | { return NewStream(stream); } | |
00375592 VZ |
508 | |
509 | private: | |
510 | DECLARE_DYNAMIC_CLASS(wxZipClassFactory) | |
511 | }; | |
512 | ||
513 | ||
00375592 VZ |
514 | ///////////////////////////////////////////////////////////////////////////// |
515 | // wxZipEntry inlines | |
516 | ||
f44eaed6 | 517 | inline bool wxZipEntry::IsText() const |
00375592 VZ |
518 | { |
519 | return (m_InternalAttributes & TEXT_ATTR) != 0; | |
520 | } | |
521 | ||
f44eaed6 | 522 | inline bool wxZipEntry::IsDir() const |
00375592 VZ |
523 | { |
524 | return (m_ExternalAttributes & wxZIP_A_SUBDIR) != 0; | |
525 | } | |
526 | ||
f44eaed6 | 527 | inline bool wxZipEntry::IsReadOnly() const |
00375592 VZ |
528 | { |
529 | return (m_ExternalAttributes & wxZIP_A_RDONLY) != 0; | |
530 | } | |
531 | ||
f44eaed6 | 532 | inline bool wxZipEntry::IsMadeByUnix() const |
00375592 VZ |
533 | { |
534 | const int pattern = | |
535 | (1 << wxZIP_SYSTEM_OPENVMS) | | |
536 | (1 << wxZIP_SYSTEM_UNIX) | | |
537 | (1 << wxZIP_SYSTEM_ATARI_ST) | | |
538 | (1 << wxZIP_SYSTEM_ACORN_RISC) | | |
539 | (1 << wxZIP_SYSTEM_BEOS) | (1 << wxZIP_SYSTEM_TANDEM); | |
540 | ||
541 | // note: some unix zippers put madeby = dos | |
542 | return (m_SystemMadeBy == wxZIP_SYSTEM_MSDOS | |
543 | && (m_ExternalAttributes & ~0xFFFF)) | |
544 | || ((pattern >> m_SystemMadeBy) & 1); | |
545 | } | |
546 | ||
f44eaed6 | 547 | inline void wxZipEntry::SetIsText(bool isText) |
00375592 VZ |
548 | { |
549 | if (isText) | |
550 | m_InternalAttributes |= TEXT_ATTR; | |
551 | else | |
552 | m_InternalAttributes &= ~TEXT_ATTR; | |
553 | } | |
554 | ||
f44eaed6 | 555 | inline void wxZipEntry::SetIsReadOnly(bool isReadOnly) |
00375592 VZ |
556 | { |
557 | if (isReadOnly) | |
558 | SetMode(GetMode() & ~0222); | |
559 | else | |
560 | SetMode(GetMode() | 0200); | |
561 | } | |
562 | ||
f44eaed6 RN |
563 | inline void wxZipEntry::SetName(const wxString& name, |
564 | wxPathFormat format /*=wxPATH_NATIVE*/) | |
00375592 VZ |
565 | { |
566 | bool isDir; | |
567 | m_Name = GetInternalName(name, format, &isDir); | |
568 | SetIsDir(isDir); | |
569 | } | |
570 | ||
571 | ||
5410f572 | 572 | #endif // wxUSE_ZIPSTREAM |
00375592 VZ |
573 | |
574 | #endif // _WX_WXZIPSTREAM_H__ |