]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/tarstrm.h
Convert wxFSW_EVENT_{WARNING,ERROR} to string correctly.
[wxWidgets.git] / interface / wx / tarstrm.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: tarstrm.h
c6cf894a 3// Purpose: interface of wxTar* classes
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
c6cf894a
FM
9
10/** wxTarEntry::GetTypeFlag() values */
11enum wxTarType
12{
13 wxTAR_REGTYPE = '0', //!< regular file
14 wxTAR_LNKTYPE = '1', //!< hard link
15 wxTAR_SYMTYPE = '2', //!< symbolic link
16 wxTAR_CHRTYPE = '3', //!< character special
17 wxTAR_BLKTYPE = '4', //!< block special
18 wxTAR_DIRTYPE = '5', //!< directory
19 wxTAR_FIFOTYPE = '6', //!< named pipe
20 wxTAR_CONTTYPE = '7' //!< contiguous file
21};
22
23/** Archive Formats (use wxTAR_PAX, it's backward compatible) used by wxTarEntry */
24enum wxTarFormat
25{
26 wxTAR_USTAR, //!< POSIX.1-1990 tar format
27 wxTAR_PAX //!< POSIX.1-2001 tar format
28};
29
30
23324ae1
FM
31/**
32 @class wxTarInputStream
7c913512 33
23324ae1 34 Input stream for reading tar files.
7c913512 35
c6cf894a
FM
36 wxTarInputStream::GetNextEntry() returns a wxTarEntry object containing the
37 meta-data for the next entry in the tar (and gives away ownership).
38 Reading from the wxTarInputStream then returns the entry's data.
39 wxTarInputStream::Eof() becomes @true after an attempt has been made to read
40 past the end of the entry's data.
41
42 When there are no more entries, wxTarInputStream::GetNextEntry() returns @NULL
43 and sets wxTarInputStream::Eof().
7c913512 44
23324ae1
FM
45 Tar entries are seekable if the parent stream is seekable. In practice this
46 usually means they are only seekable if the tar is stored as a local file and
47 is not compressed.
7c913512 48
23324ae1 49 @library{wxbase}
c6cf894a 50 @category{archive,streams}
7c913512 51
c6cf894a 52 @see @ref overview_archive_byname
23324ae1
FM
53*/
54class wxTarInputStream : public wxArchiveInputStream
55{
56public:
57 //@{
58 /**
4cc4bfaf 59 Constructor. In a Unicode build the second parameter @a conv is
c6cf894a
FM
60 used to translate fields from the standard tar header into Unicode.
61
62 It has no effect on the stream's data. @a conv is only used for the standard
23324ae1 63 tar headers, any pax extended headers are always UTF-8 encoded.
c6cf894a 64
23324ae1
FM
65 If the parent stream is passed as a pointer then the new filter stream
66 takes ownership of it. If it is passed by reference then it does not.
67 */
68 wxTarInputStream(wxInputStream& stream,
69 wxMBConv& conv = wxConvLocal);
7c913512
FM
70 wxTarInputStream(wxInputStream* stream,
71 wxMBConv& conv = wxConvLocal);
23324ae1
FM
72 //@}
73
74 /**
c6cf894a
FM
75 Closes the current entry.
76 On a non-seekable stream reads to the end of the current entry first.
23324ae1
FM
77 */
78 bool CloseEntry();
79
80 /**
81 Closes the current entry if one is open, then reads the meta-data for
c6cf894a
FM
82 the next entry and returns it in a wxTarEntry object, giving away ownership.
83 The stream is then open and can be read.
23324ae1
FM
84 */
85 wxTarEntry* GetNextEntry();
86
87 /**
88 Closes the current entry if one is open, then opens the entry specified
4cc4bfaf 89 by the @a entry object.
c6cf894a
FM
90
91 @a entry should be from the same tar file, and the tar should be on a
92 seekable stream.
23324ae1
FM
93 */
94 bool OpenEntry(wxTarEntry& entry);
95};
96
97
e54c96f1 98
23324ae1
FM
99/**
100 @class wxTarClassFactory
7c913512 101
c6cf894a
FM
102 Class factory for the tar archive format.
103 See the base class for details.
7c913512 104
23324ae1 105 @library{wxbase}
c6cf894a 106 @category{archive,streams}
7c913512 107
c6cf894a
FM
108 @see @ref overview_archive, @ref overview_archive_generic,
109 wxTarEntry, wxTarInputStream, wxTarOutputStream
23324ae1
FM
110*/
111class wxTarClassFactory : public wxArchiveClassFactory
112{
113public:
7c913512 114
23324ae1
FM
115};
116
117
e54c96f1 118
23324ae1
FM
119/**
120 @class wxTarOutputStream
7c913512 121
23324ae1 122 Output stream for writing tar files.
7c913512 123
c6cf894a
FM
124 wxTarOutputStream::PutNextEntry() is used to create a new entry in the output tar,
125 then the entry's data is written to the wxTarOutputStream.
126 Another call to wxTarOutputStream::PutNextEntry() closes the current entry
127 and begins the next.
7c913512 128
23324ae1
FM
129 @library{wxbase}
130 @category{streams}
7c913512 131
c6cf894a 132 @see @ref overview_archive, wxTarEntry, wxTarInputStream
23324ae1
FM
133*/
134class wxTarOutputStream : public wxArchiveOutputStream
135{
136public:
137 //@{
138 /**
139 If the parent stream is passed as a pointer then the new filter stream
140 takes ownership of it. If it is passed by reference then it does not.
c6cf894a 141
4cc4bfaf 142 In a Unicode build the third parameter @a conv is used to translate the
23324ae1 143 headers fields into an 8-bit encoding. It has no effect on the stream's data.
c6cf894a 144
4cc4bfaf 145 When the @a format is @e wxTAR_PAX, pax extended headers are generated
23324ae1
FM
146 when any header field will not fit the standard tar header block or if it
147 uses any non-ascii characters.
c6cf894a 148
23324ae1
FM
149 Extended headers are stored as extra 'files' within the tar, and will be
150 extracted as such by any other tar program that does not understand them.
4cc4bfaf 151 The @a conv parameter only affect the standard tar headers, the extended
23324ae1 152 headers are always UTF-8 encoded.
c6cf894a
FM
153
154 When the @a format is @e wxTAR_USTAR, no extended headers are generated,
155 and instead a warning message is logged if any header field overflows.
23324ae1
FM
156 */
157 wxTarOutputStream(wxOutputStream& stream,
158 wxTarFormat format = wxTAR_PAX,
159 wxMBConv& conv = wxConvLocal);
7c913512
FM
160 wxTarOutputStream(wxOutputStream* stream,
161 wxTarFormat format = wxTAR_PAX,
162 wxMBConv& conv = wxConvLocal);
23324ae1
FM
163 //@}
164
165 /**
c6cf894a
FM
166 The destructor calls Close() to finish writing the tar if it has
167 not been called already.
23324ae1 168 */
adaaa686 169 virtual ~wxTarOutputStream();
23324ae1
FM
170
171 /**
172 Finishes writing the tar, returning @true if successful.
173 Called by the destructor if not called explicitly.
174 */
175 bool Close();
176
177 /**
c6cf894a
FM
178 Close the current entry.
179
180 It is called implicitly whenever another new entry is created with
181 CopyEntry() or PutNextEntry(), or when the tar is closed.
23324ae1
FM
182 */
183 bool CloseEntry();
184
185 /**
c6cf894a 186 See wxArchiveOutputStream::CopyArchiveMetaData().
23324ae1
FM
187 For the tar format this function does nothing.
188 */
189 bool CopyArchiveMetaData(wxTarInputStream& s);
190
191 /**
c6cf894a
FM
192 Takes ownership of @a entry and uses it to create a new entry in the tar.
193 @a entry is then opened in @a inputStream and its contents copied to this stream.
194
23324ae1
FM
195 For some other archive formats CopyEntry() is much more efficient than
196 transferring the data using Read() and Write() since it will copy them
c6cf894a
FM
197 without decompressing and recompressing them.
198 For tar however it makes no difference.
199
4cc4bfaf 200 For tars on seekable streams, @a entry must be from the same tar file
c6cf894a
FM
201 as @a inputStream. For non-seekable streams, @a entry must also be the
202 last thing read from @a inputStream.
23324ae1
FM
203 */
204 bool CopyEntry(wxTarEntry* entry, wxTarInputStream& inputStream);
205
206 //@{
207 /**
208 The tar is zero padded to round its size up to @e BlockingFactor * 512 bytes.
c6cf894a
FM
209
210 The blocking factor defaults to 10 for @e wxTAR_PAX and 20 for @e wxTAR_USTAR
211 (see wxTarOutputStream()), as specified in the POSIX standards.
23324ae1 212 */
c6cf894a
FM
213 int GetBlockingFactor() const;
214 void SetBlockingFactor(int factor);
23324ae1
FM
215 //@}
216
217 /**
c6cf894a
FM
218 Create a new directory entry (see wxArchiveEntry::IsDir()) with the given
219 name and timestamp.
220
221 PutNextEntry() can also be used to create directory entries, by supplying
222 a name with a trailing path separator.
23324ae1 223 */
c6cf894a 224 bool PutNextDirEntry(const wxString& name, const wxDateTime& dt = wxDateTime::Now());
23324ae1 225
23324ae1 226 /**
c6cf894a 227 Takes ownership of entry and uses it to create a new entry in the tar.
23324ae1
FM
228 */
229 bool PutNextEntry(wxTarEntry* entry);
c6cf894a
FM
230
231 /**
232 Create a new entry with the given name, timestamp and size.
233 */
234 bool PutNextEntry(const wxString& name, const wxDateTime& dt = wxDateTime::Now(),
235 wxFileOffset size = wxInvalidOffset);
23324ae1
FM
236};
237
238
e54c96f1 239
23324ae1
FM
240/**
241 @class wxTarEntry
7c913512 242
23324ae1 243 Holds the meta-data for an entry in a tar.
7c913512 244
c6cf894a
FM
245 @section tarentry_fields Field availability
246
247 The tar format stores all the meta-data for an entry ahead of its data,
248 therefore GetNextEntry() always returns a fully populated wxTarEntry object,
249 both when reading from seekable and non-seekable streams.
250
23324ae1 251 @library{wxbase}
c6cf894a 252 @category{archive,streams}
7c913512 253
c6cf894a 254 @see @ref overview_archive, wxTarInputStream, wxTarOutputStream
23324ae1
FM
255*/
256class wxTarEntry : public wxArchiveEntry
257{
258public:
c6cf894a
FM
259 /**
260 Constructor.
261
262 The tar archive format stores the entry's size ahead of the entry's data.
263 Therefore when creating an archive on a non-seekable stream it is necessary
264 to supply the correct size when each entry is created.
265 */
266 wxTarEntry(const wxString& name = wxEmptyString,
267 const wxDateTime& dt = wxDateTime::Now(),
268 wxFileOffset size = wxInvalidOffset);
269
23324ae1
FM
270 /**
271 Copy constructor.
272 */
7c913512 273 wxTarEntry(const wxTarEntry& entry);
23324ae1
FM
274
275 //@{
276 /**
c6cf894a
FM
277 Gets/sets the entry's access time stamp.
278 See also wxArchiveEntry::GetDateTime() and wxArchiveEntry::SetDateTime().
23324ae1 279 */
c6cf894a
FM
280 wxDateTime GetAccessTime() const;
281 void SetAccessTime(const wxDateTime& dt);
23324ae1
FM
282 //@}
283
284 //@{
285 /**
c6cf894a
FM
286 The entry's creation time stamp.
287 See also wxArchiveEntry::GetDateTime() and wxArchiveEntry::SetDateTime().
23324ae1 288 */
c6cf894a
FM
289 wxDateTime GetCreateTime() const;
290 void SetCreateTime(const wxDateTime& dt);
23324ae1
FM
291 //@}
292
293 //@{
294 /**
c6cf894a
FM
295 OS specific IDs defining a device; these are only meaningful when
296 wxTarEntry::GetTypeFlag() is @e wxTAR_CHRTYPE or @e wxTAR_BLKTYPE.
23324ae1 297 */
c6cf894a
FM
298 int GetDevMajor() const;
299 int GetDevMinor() const;
300 void SetDevMajor(int dev);
7c913512 301 void SetDevMinor(int dev);
23324ae1
FM
302 //@}
303
304 //@{
305 /**
c6cf894a
FM
306 The user ID and group ID that has permissions (see wxTarEntry::GetMode())
307 over this entry.
308
309 These values aren't usually useful unless the file will only be
310 restored to the same system it originated from.
311 wxTarEntry::GetGroupName() and wxTarEntry::GetUserName() can be used instead.
23324ae1 312 */
c6cf894a
FM
313 int GetGroupId() const;
314 int GetUserId() const;
315 void SetGroupId(int id);
7c913512 316 void SetUserId(int id);
23324ae1
FM
317 //@}
318
319 //@{
320 /**
c6cf894a 321 The names of the user and group that has permissions (see wxTarEntry::GetMode())
23324ae1
FM
322 over this entry. These are not present in very old tars.
323 */
c6cf894a
FM
324 wxString GetGroupName() const;
325 wxString GetUserName() const;
326 void SetGroupName(const wxString& group);
7c913512 327 void SetUserName(const wxString& user);
23324ae1
FM
328 //@}
329
330 //@{
331 /**
332 The filename of a previous entry in the tar that this entry is a link to.
c6cf894a
FM
333 Only meaningful when wxTarEntry::GetTypeFlag() is set to @e wxTAR_LNKTYPE
334 or @e wxTAR_SYMTYPE.
23324ae1 335 */
c6cf894a
FM
336 wxString GetLinkName() const;
337 void SetLinkName(const wxString& link);
23324ae1
FM
338 //@}
339
340 //@{
341 /**
c6cf894a
FM
342 UNIX permission bits for this entry.
343 Giving read, write and execute permissions to the file's user and group
344 (see GetGroupName() and GetUserName()) and to others.
345
346 The integer is one or more ::wxPosixPermissions flags OR-combined.
23324ae1 347 */
c6cf894a
FM
348 int GetMode() const;
349 void SetMode(int mode);
23324ae1
FM
350 //@}
351
352 //@{
353 /**
354 The size of the entry's data in bytes.
c6cf894a 355
23324ae1
FM
356 The tar archive format stores the entry's size ahead of the entry's data.
357 Therefore when creating an archive on a non-seekable stream it is necessary to
c6cf894a
FM
358 supply the correct size when each entry is created.
359
360 For seekable streams this is not necessary as wxTarOutputStream will attempt
23324ae1
FM
361 to seek back and fix the entry's header when the entry is closed, though it is
362 still more efficient if the size is given beforehand.
363 */
c6cf894a 364 void SetSize(wxFileOffset size);
328f5751 365 wxFileOffset GetSize() const;
23324ae1
FM
366 //@}
367
368 //@{
369 /**
c6cf894a 370 Returns/Sets the type of the entry as a ::wxTarType value.
3c4f71cc 371
c6cf894a
FM
372 When creating archives use only one of ::wxTarType values.
373 When reading archives, GetTypeFlag() may return a value which does not
374 match any value of ::wxTarType; in this case the returned value should be
375 treated as @e wxTAR_REGTYPE.
23324ae1 376 */
c6cf894a
FM
377 int GetTypeFlag() const;
378 void SetTypeFlag(int type);
23324ae1
FM
379 //@}
380
c6cf894a
FM
381 /**
382 Returns the entry's filename in the internal format used within the archive.
383
384 The name can include directory components, i.e. it can be a full path.
385 The names of directory entries are returned without any trailing path separator.
386 This gives a canonical name that can be used in comparisons.
387 */
388 wxString GetInternalName() const;
389
23324ae1
FM
390 /**
391 A static member that translates a filename into the internal format used
c6cf894a
FM
392 within the archive.
393
394 If the third parameter is provided, the bool pointed to is set to indicate
395 whether the name looks like a directory name (i.e. has a trailing path separator).
23324ae1 396 */
c6cf894a 397 static wxString GetInternalName(const wxString& name,
328f5751
FM
398 wxPathFormat format = wxPATH_NATIVE,
399 bool* pIsDir = NULL);
23324ae1
FM
400
401 /**
402 Assignment operator.
403 */
404 wxTarEntry& operator operator=(const wxTarEntry& entry);
405};
e54c96f1 406