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