]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/zipstrm.h
Add new wxCommandLinkButton class.
[wxWidgets.git] / interface / wx / zipstrm.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: zipstrm.h
e54c96f1 3// Purpose: interface of wxZipNotifier
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
f41d6c8c
FM
9
10
11/// Compression Method, only 0 (store) and 8 (deflate) are supported here
12enum wxZipMethod
13{
14 wxZIP_METHOD_STORE,
15 wxZIP_METHOD_SHRINK,
16 wxZIP_METHOD_REDUCE1,
17 wxZIP_METHOD_REDUCE2,
18 wxZIP_METHOD_REDUCE3,
19 wxZIP_METHOD_REDUCE4,
20 wxZIP_METHOD_IMPLODE,
21 wxZIP_METHOD_TOKENIZE,
22 wxZIP_METHOD_DEFLATE,
23 wxZIP_METHOD_DEFLATE64,
24 wxZIP_METHOD_BZIP2 = 12,
25 wxZIP_METHOD_DEFAULT = 0xffff
26};
27
28/// Originating File-System.
29///
30/// These are Pkware's values. Note that Info-zip disagree on some of them,
31/// most notably NTFS.
32enum wxZipSystem
33{
34 wxZIP_SYSTEM_MSDOS,
35 wxZIP_SYSTEM_AMIGA,
36 wxZIP_SYSTEM_OPENVMS,
37 wxZIP_SYSTEM_UNIX,
38 wxZIP_SYSTEM_VM_CMS,
39 wxZIP_SYSTEM_ATARI_ST,
40 wxZIP_SYSTEM_OS2_HPFS,
41 wxZIP_SYSTEM_MACINTOSH,
42 wxZIP_SYSTEM_Z_SYSTEM,
43 wxZIP_SYSTEM_CPM,
44 wxZIP_SYSTEM_WINDOWS_NTFS,
45 wxZIP_SYSTEM_MVS,
46 wxZIP_SYSTEM_VSE,
47 wxZIP_SYSTEM_ACORN_RISC,
48 wxZIP_SYSTEM_VFAT,
49 wxZIP_SYSTEM_ALTERNATE_MVS,
50 wxZIP_SYSTEM_BEOS,
51 wxZIP_SYSTEM_TANDEM,
52 wxZIP_SYSTEM_OS_400
53};
54
55/// Dos/Win file attributes
56enum wxZipAttributes
57{
58 wxZIP_A_RDONLY = 0x01,
59 wxZIP_A_HIDDEN = 0x02,
60 wxZIP_A_SYSTEM = 0x04,
61 wxZIP_A_SUBDIR = 0x10,
62 wxZIP_A_ARCH = 0x20,
63
64 wxZIP_A_MASK = 0x37
65};
66
67/// Values for the flags field in the zip headers
68enum wxZipFlags
69{
70 wxZIP_ENCRYPTED = 0x0001,
71 wxZIP_DEFLATE_NORMAL = 0x0000, // normal compression
72 wxZIP_DEFLATE_EXTRA = 0x0002, // extra compression
73 wxZIP_DEFLATE_FAST = 0x0004, // fast compression
74 wxZIP_DEFLATE_SUPERFAST = 0x0006, // superfast compression
75 wxZIP_DEFLATE_MASK = 0x0006,
76 wxZIP_SUMS_FOLLOW = 0x0008, // crc and sizes come after the data
77 wxZIP_ENHANCED = 0x0010,
78 wxZIP_PATCH = 0x0020,
79 wxZIP_STRONG_ENC = 0x0040,
80 wxZIP_UNUSED = 0x0F80,
81 wxZIP_RESERVED = 0xF000
82};
83
84
23324ae1
FM
85/**
86 @class wxZipNotifier
7c913512 87
f41d6c8c 88 If you need to know when a wxZipInputStream updates a wxZipEntry,
23324ae1 89 you can create a notifier by deriving from this abstract base class,
f41d6c8c
FM
90 overriding wxZipNotifier::OnEntryUpdated().
91
23324ae1 92 An instance of your notifier class can then be assigned to wxZipEntry
f41d6c8c 93 objects, using wxZipEntry::SetNotifier().
7c913512 94
23324ae1
FM
95 Setting a notifier is not usually necessary. It is used to handle
96 certain cases when modifying an zip in a pipeline (i.e. between
97 non-seekable streams).
f41d6c8c 98 See @ref overview_archive_noseek.
7c913512 99
23324ae1 100 @library{wxbase}
c6cf894a 101 @category{archive,streams}
7c913512 102
f41d6c8c 103 @see @ref overview_archive_noseek, wxZipEntry, wxZipInputStream, wxZipOutputStream
23324ae1 104*/
7c913512 105class wxZipNotifier
23324ae1
FM
106{
107public:
108 /**
f41d6c8c 109 Override this to receive notifications when an wxZipEntry object changes.
23324ae1 110 */
18e8e19b 111 virtual void OnEntryUpdated(wxZipEntry& entry) = 0;
23324ae1
FM
112};
113
114
e54c96f1 115
23324ae1
FM
116/**
117 @class wxZipEntry
7c913512 118
23324ae1 119 Holds the meta-data for an entry in a zip.
7c913512 120
f41d6c8c
FM
121 @section zipentry_avail Field availability
122
123 When reading a zip from a stream that is seekable, wxZipEntry::GetNextEntry()
124 returns a fully populated wxZipEntry object except for wxZipEntry::GetLocalExtra().
125 wxZipEntry::GetLocalExtra() becomes available when the entry is opened, either by
126 calling wxZipInputStream::OpenEntry() or by making an attempt to read the entry's data.
127
128 For zips on non-seekable streams, the following fields are always available
129 when wxZipEntry::GetNextEntry() returns:
130 - wxZipEntry::GetDateTime
131 - wxZipEntry::GetInternalFormat
132 - wxZipEntry::GetInternalName
133 - wxZipEntry::GetFlags
134 - wxZipEntry::GetLocalExtra
135 - wxZipEntry::GetMethod
136 - wxZipEntry::GetName
137 - wxZipEntry::GetOffset
138 - wxZipEntry::IsDir
139
140 The following fields are also usually available when GetNextEntry() returns,
141 however, if the zip was also written to a non-seekable stream the zipper is
142 permitted to store them after the entry's data. In that case they become
143 available when the entry's data has been read to Eof(), or CloseEntry()
144 has been called. (GetFlags() & wxZIP_SUMS_FOLLOW) != 0 indicates that
145 one or more of these come after the data:
146 - wxZipEntry::GetCompressedSize
147 - wxZipEntry::GetCrc
148 - wxZipEntry::GetSize
149
150 The following are stored at the end of the zip, and become available when the
151 end of the zip has been reached, i.e. after GetNextEntry() returns @NULL
152 and Eof() is true:
153 - wxZipEntry::GetComment
154 - wxZipEntry::GetExternalAttributes
155 - wxZipEntry::GetExtra
156 - wxZipEntry::GetMode
157 - wxZipEntry::GetSystemMadeBy
158 - wxZipEntry::IsReadOnly
159 - wxZipEntry::IsMadeByUnix
160 - wxZipEntry::IsText
161
23324ae1 162 @library{wxbase}
c6cf894a 163 @category{archive,streams}
7c913512 164
f41d6c8c 165 @see @ref overview_archive, wxZipInputStream, wxZipOutputStream, wxZipNotifier
23324ae1
FM
166*/
167class wxZipEntry : public wxArchiveEntry
168{
169public:
18e8e19b
FM
170 wxZipEntry(const wxString& name = wxEmptyString,
171 const wxDateTime& dt = Now(),
172 wxFileOffset size = wxInvalidOffset);
f41d6c8c 173
23324ae1
FM
174 /**
175 Copy constructor.
176 */
7c913512 177 wxZipEntry(const wxZipEntry& entry);
23324ae1
FM
178
179 /**
180 Make a copy of this entry.
181 */
328f5751 182 wxZipEntry* Clone() const;
23324ae1
FM
183
184 //@{
185 /**
f41d6c8c 186 Gets and sets the short comment for this entry.
23324ae1 187 */
f41d6c8c
FM
188 wxString GetComment() const;
189 void SetComment(const wxString& comment);
23324ae1
FM
190 //@}
191
192 //@{
193 /**
194 The low 8 bits are always the DOS/Windows file attributes for this entry.
f41d6c8c 195 The values of these attributes are given in the enumeration ::wxZipAttributes.
3c4f71cc 196
f41d6c8c
FM
197 The remaining bits can store platform specific permission bits or
198 attributes, and their meaning depends on the value of SetSystemMadeBy().
199 If IsMadeByUnix() is @true then the high 16 bits are unix mode bits.
3c4f71cc 200
f41d6c8c
FM
201 The following other accessors access these bits:
202 - IsReadOnly() / SetIsReadOnly()
203 - IsDir() / SetIsDir()
204 - GetMode() / SetMode()
23324ae1 205 */
f41d6c8c
FM
206 wxUint32 GetExternalAttributes() const;
207 void SetExternalAttributes(wxUint32 attr);
23324ae1
FM
208 //@}
209
210 //@{
211 /**
212 The extra field from the entry's central directory record.
f41d6c8c 213
23324ae1
FM
214 The extra field is used to store platform or application specific
215 data. See Pkware's document 'appnote.txt' for information on its format.
216 */
382f12e4 217 const char* GetExtra() const;
f41d6c8c
FM
218 size_t GetExtraLen() const;
219 void SetExtra(const char* extra, size_t len);
23324ae1
FM
220 //@}
221
222 //@{
223 /**
224 The extra field from the entry's local record.
f41d6c8c 225
23324ae1
FM
226 The extra field is used to store platform or application specific
227 data. See Pkware's document 'appnote.txt' for information on its format.
228 */
382f12e4 229 const char* GetLocalExtra() const;
f41d6c8c
FM
230 size_t GetLocalExtraLen() const;
231 void SetLocalExtra(const char* extra, size_t len);
23324ae1
FM
232 //@}
233
234 //@{
235 /**
f41d6c8c
FM
236 The compression method.
237 The enumeration ::wxZipMethod lists the possible values.
238
239 The default constructor sets this to @c wxZIP_METHOD_DEFAULT,
240 which allows wxZipOutputStream to choose the method when writing the entry.
23324ae1 241 */
f41d6c8c
FM
242 int GetMethod() const;
243 void SetMethod(int method);
23324ae1
FM
244 //@}
245
246 //@{
247 /**
f41d6c8c
FM
248 If IsMadeByUnix() is true then returns the unix permission bits stored
249 in GetExternalAttributes(). Otherwise synthesises them from the DOS attributes.
250 */
251 int GetMode() const;
252
253 /**
254 Sets the DOS attributes in GetExternalAttributes() to be consistent with
255 the @a mode given.
256
257 If IsMadeByUnix() is @true then also stores @a mode in GetExternalAttributes().
258 Note that the default constructor sets GetSystemMadeBy() to
259 @c wxZIP_SYSTEM_MSDOS by default. So to be able to store unix
23324ae1
FM
260 permissions when creating zips, call SetSystemMadeBy(wxZIP_SYSTEM_UNIX).
261 */
f41d6c8c 262 void SetMode(int mode);
23324ae1
FM
263 //@}
264
265 //@{
266 /**
f41d6c8c
FM
267 The originating file-system.
268
269 The default constructor sets this to @c wxZIP_SYSTEM_MSDOS.
270 Set it to @c wxZIP_SYSTEM_UNIX in order to be able to store unix
271 permissions using SetMode().
23324ae1 272 */
f41d6c8c
FM
273 int GetSystemMadeBy() const;
274 void SetSystemMadeBy(int system);
23324ae1
FM
275 //@}
276
277 /**
278 The compressed size of this entry in bytes.
279 */
18e8e19b 280 wxFileOffset GetCompressedSize() const;
23324ae1
FM
281
282 /**
283 CRC32 for this entry's data.
284 */
328f5751 285 wxUint32 GetCrc() const;
23324ae1
FM
286
287 /**
288 Returns a combination of the bits flags in the enumeration @c wxZipFlags.
289 */
328f5751 290 int GetFlags() const;
23324ae1
FM
291
292 //@{
293 /**
294 A static member that translates a filename into the internal format used
295 within the archive. If the third parameter is provided, the bool pointed
296 to is set to indicate whether the name looks like a directory name
297 (i.e. has a trailing path separator).
3c4f71cc 298
f41d6c8c
FM
299 @see @ref overview_archive_byname
300 */
301 wxString GetInternalName(const wxString& name,
302 wxPathFormat format = wxPATH_NATIVE,
303 bool* pIsDir = NULL);
304 /**
305 Returns the entry's filename in the internal format used within the archive.
306 The name can include directory components, i.e. it can be a full path.
307
308 The names of directory entries are returned without any trailing path separator.
309 This gives a canonical name that can be used in comparisons.
23324ae1 310 */
f41d6c8c 311 wxString GetInternalName() const;
23324ae1
FM
312 //@}
313
314 /**
f41d6c8c 315 Returns @true if GetSystemMadeBy() is a flavour of unix.
23324ae1 316 */
328f5751 317 bool IsMadeByUnix() const;
23324ae1
FM
318
319 //@{
320 /**
321 Indicates that this entry's data is text in an 8-bit encoding.
322 */
f41d6c8c
FM
323 bool IsText() const;
324 void SetIsText(bool isText = true);
23324ae1
FM
325 //@}
326
327 //@{
328 /**
f41d6c8c
FM
329 Sets the notifier (see wxZipNotifier) for this entry.
330 Whenever the wxZipInputStream updates this entry, it will then invoke
331 the associated notifier's wxZipNotifier::OnEntryUpdated() method.
332
23324ae1
FM
333 Setting a notifier is not usually necessary. It is used to handle
334 certain cases when modifying an zip in a pipeline (i.e. between
335 non-seekable streams).
3c4f71cc 336
f41d6c8c 337 @see @ref overview_archive_noseek, wxZipNotifier
23324ae1
FM
338 */
339 void SetNotifier(wxZipNotifier& notifier);
7c913512 340 void UnsetNotifier();
23324ae1
FM
341 //@}
342
343 /**
344 Assignment operator.
345 */
f41d6c8c 346 wxZipEntry& operator=(const wxZipEntry& entry);
23324ae1
FM
347};
348
349
350/**
351 @class wxZipInputStream
7c913512 352
23324ae1 353 Input stream for reading zip files.
7c913512 354
e7d0a28b
FM
355 wxZipInputStream::GetNextEntry() returns a wxZipEntry object containing the
356 meta-data for the next entry in the zip (and gives away ownership).
357 Reading from the wxZipInputStream then returns the entry's data.
358 Eof() becomes @true after an attempt has been made to read past the end of
359 the entry's data.
23324ae1 360 When there are no more entries, GetNextEntry() returns @NULL and sets Eof().
7c913512 361
23324ae1 362 Note that in general zip entries are not seekable, and
e7d0a28b 363 wxZipInputStream::SeekI() always returns ::wxInvalidOffset.
7c913512 364
23324ae1 365 @library{wxbase}
c6cf894a 366 @category{archive,streams}
7c913512 367
e7d0a28b 368 @see @ref overview_archive, wxZipEntry, wxZipOutputStream
23324ae1
FM
369*/
370class wxZipInputStream : public wxArchiveInputStream
371{
372public:
e7d0a28b 373
23324ae1
FM
374 //@{
375 /**
e7d0a28b
FM
376 Constructor. In a Unicode build the second parameter @a conv is used to
377 translate the filename and comment fields into Unicode.
378 It has no effect on the stream's data.
379 If the parent stream is passed as a pointer then the new filter stream
380 takes ownership of it. If it is passed by reference then it does not.
23324ae1
FM
381 */
382 wxZipInputStream(wxInputStream& stream,
383 wxMBConv& conv = wxConvLocal);
7c913512
FM
384 wxZipInputStream(wxInputStream* stream,
385 wxMBConv& conv = wxConvLocal);
e7d0a28b
FM
386 //@}
387
388 /**
389 @deprecated
390 Compatibility constructor (requires WXWIN_COMPATIBILITY_2_6).
391 When this constructor is used, an emulation of seeking is
392 switched on for compatibility with previous versions. Note however,
393 that it is deprecated.
394 */
7c913512
FM
395 wxZipInputStream(const wxString& archive,
396 const wxString& file);
23324ae1
FM
397
398 /**
e7d0a28b
FM
399 Closes the current entry.
400 On a non-seekable stream reads to the end of the current entry first.
23324ae1
FM
401 */
402 bool CloseEntry();
403
404 /**
405 Returns the zip comment.
e7d0a28b 406
23324ae1 407 This is stored at the end of the zip, therefore when reading a zip
e7d0a28b
FM
408 from a non-seekable stream, it returns the empty string until the end
409 of the zip has been reached, i.e. when GetNextEntry() returns @NULL.
23324ae1
FM
410 */
411 wxString GetComment();
412
413 /**
414 Closes the current entry if one is open, then reads the meta-data for
e7d0a28b
FM
415 the next entry and returns it in a wxZipEntry object, giving away ownership.
416 The stream is then open and can be read.
23324ae1
FM
417 */
418 wxZipEntry* GetNextEntry();
419
420 /**
421 For a zip on a seekable stream returns the total number of entries in
422 the zip. For zips on non-seekable streams returns the number of entries
423 returned so far by GetNextEntry().
424 */
425 int GetTotalEntries();
426
427 /**
428 Closes the current entry if one is open, then opens the entry specified
4cc4bfaf 429 by the @a entry object.
e7d0a28b 430
4cc4bfaf 431 @a entry should be from the same zip file, and the zip should
23324ae1 432 be on a seekable stream.
e7d0a28b
FM
433
434 @see overview_archive_byname
23324ae1
FM
435 */
436 bool OpenEntry(wxZipEntry& entry);
437};
438
439
e54c96f1 440
23324ae1
FM
441/**
442 @class wxZipClassFactory
7c913512 443
e7d0a28b
FM
444 Class factory for the zip archive format.
445 See the base class for details.
7c913512 446
23324ae1 447 @library{wxbase}
c6cf894a 448 @category{archive,streams}
7c913512 449
e7d0a28b
FM
450 @see @ref overview_archive,
451 @ref overview_archive_generic,
452 wxZipEntry, wxZipInputStream, wxZipOutputStream
23324ae1
FM
453*/
454class wxZipClassFactory : public wxArchiveClassFactory
455{
456public:
7c913512 457
23324ae1
FM
458};
459
460
e54c96f1 461
23324ae1
FM
462/**
463 @class wxZipOutputStream
7c913512 464
23324ae1 465 Output stream for writing zip files.
7c913512 466
e7d0a28b
FM
467 wxZipOutputStream::PutNextEntry() is used to create a new entry in the
468 output zip, then the entry's data is written to the wxZipOutputStream.
469 Another call to wxZipOutputStream::PutNextEntry() closes the current
23324ae1 470 entry and begins the next.
7c913512 471
23324ae1 472 @library{wxbase}
c6cf894a 473 @category{archive,streams}
7c913512 474
e7d0a28b 475 @see @ref overview_archive, wxZipEntry, wxZipInputStream
23324ae1
FM
476*/
477class wxZipOutputStream : public wxArchiveOutputStream
478{
479public:
480 //@{
481 /**
e7d0a28b
FM
482 Constructor.
483
484 @a level is the compression level to use.
23324ae1
FM
485 It can be a value between 0 and 9 or -1 to use the default value
486 which currently is equivalent to 6.
e7d0a28b 487
23324ae1
FM
488 If the parent stream is passed as a pointer then the new filter stream
489 takes ownership of it. If it is passed by reference then it does not.
e7d0a28b
FM
490 In a Unicode build the third parameter @a conv is used to translate
491 the filename and comment fields to an 8-bit encoding.
492 It has no effect on the stream's data.
23324ae1
FM
493 */
494 wxZipOutputStream(wxOutputStream& stream, int level = -1,
495 wxMBConv& conv = wxConvLocal);
7c913512
FM
496 wxZipOutputStream(wxOutputStream* stream, int level = -1,
497 wxMBConv& conv = wxConvLocal);
23324ae1
FM
498 //@}
499
500 /**
e7d0a28b
FM
501 The destructor calls Close() to finish writing the zip if it has
502 not been called already.
23324ae1 503 */
adaaa686 504 virtual ~wxZipOutputStream();
23324ae1
FM
505
506 /**
507 Finishes writing the zip, returning @true if successful.
508 Called by the destructor if not called explicitly.
509 */
510 bool Close();
511
512 /**
e7d0a28b
FM
513 Close the current entry.
514 It is called implicitly whenever another new entry is created with CopyEntry()
515 or PutNextEntry(), or when the zip is closed.
23324ae1
FM
516 */
517 bool CloseEntry();
518
519 /**
520 Transfers the zip comment from the wxZipInputStream
521 to this output stream.
522 */
523 bool CopyArchiveMetaData(wxZipInputStream& inputStream);
524
525 /**
e7d0a28b
FM
526 Takes ownership of @a entry and uses it to create a new entry
527 in the zip. @a entry is then opened in @a inputStream and its contents
23324ae1 528 copied to this stream.
e7d0a28b 529
23324ae1
FM
530 CopyEntry() is much more efficient than transferring the data using
531 Read() and Write() since it will copy them without decompressing and
532 recompressing them.
e7d0a28b
FM
533
534 For zips on seekable streams, @a entry must be from the same zip file
535 as @a inputStream. For non-seekable streams, @a entry must also be the
536 last thing read from @a inputStream.
23324ae1
FM
537 */
538 bool CopyEntry(wxZipEntry* entry, wxZipInputStream& inputStream);
539
540 //@{
541 /**
542 Set the compression level that will be used the next time an entry is
e7d0a28b
FM
543 created.
544
545 It can be a value between 0 and 9 or -1 to use the default value
23324ae1
FM
546 which currently is equivalent to 6.
547 */
e7d0a28b
FM
548 int GetLevel() const;
549 void SetLevel(int level);
23324ae1
FM
550 //@}
551
552 /**
e7d0a28b
FM
553 Create a new directory entry (see wxArchiveEntry::IsDir) with the given
554 name and timestamp.
555
556 PutNextEntry() can also be used to create directory entries, by supplying
557 a name with a trailing path separator.
23324ae1 558 */
e7d0a28b
FM
559 bool PutNextDirEntry(const wxString& name,
560 const wxDateTime& dt = wxDateTime::Now());
23324ae1
FM
561
562 //@{
563 /**
e7d0a28b 564 Takes ownership of @a entry and uses it to create a new entry in the zip.
23324ae1
FM
565 */
566 bool PutNextEntry(wxZipEntry* entry);
e7d0a28b
FM
567
568 /**
569 Create a new entry with the given name, timestamp and size.
570 */
571 bool PutNextEntry(const wxString& name,
572 const wxDateTime& dt = wxDateTime::Now(),
18e8e19b 573 wxFileOffset size = wxInvalidOffset);
23324ae1
FM
574 //@}
575
576 /**
e7d0a28b
FM
577 Sets a comment for the zip as a whole.
578 It is written at the end of the zip.
23324ae1
FM
579 */
580 void SetComment(const wxString& comment);
581};
e54c96f1 582