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