2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: zipstrm.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxZipNotifier
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxZipNotifier
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
If you need to know when a wxZipInputStream
|
|
|
|
updates a wxZipEntry,
|
|
|
|
you can create a notifier by deriving from this abstract base class,
|
|
|
|
overriding wxZipNotifier::OnEntryUpdated.
|
|
|
|
An instance of your notifier class can then be assigned to wxZipEntry
|
|
|
|
objects, using wxZipEntry::SetNotifier.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Setting a notifier is not usually necessary. It is used to handle
|
|
|
|
certain cases when modifying an zip in a pipeline (i.e. between
|
|
|
|
non-seekable streams).
|
|
|
|
See '@ref overview_wxarcnoseek "Archives on non-seekable streams"'.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{FIXME}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see @ref overview_wxarcnoseek "Archives on non-seekable streams", wxZipEntry,
|
2008-03-08 08:52:38 -05:00
|
|
|
wxZipInputStream, wxZipOutputStream
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxZipNotifier
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Override this to receive notifications when
|
|
|
|
an wxZipEntry object changes.
|
|
|
|
*/
|
|
|
|
void OnEntryUpdated(wxZipEntry& entry);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxZipEntry
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Holds the meta-data for an entry in a zip.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{FIXME}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see @ref overview_wxarc "Archive formats such as zip", wxZipInputStream,
|
2008-03-08 08:52:38 -05:00
|
|
|
wxZipOutputStream, wxZipNotifier
|
|
|
|
*/
|
|
|
|
class wxZipEntry : public wxArchiveEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Copy constructor.
|
|
|
|
*/
|
|
|
|
wxZipEntry(const wxString& name = wxEmptyString);
|
2008-03-08 09:43:31 -05:00
|
|
|
wxZipEntry(const wxZipEntry& entry);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Make a copy of this entry.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxZipEntry* Clone() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
A short comment for this entry.
|
|
|
|
*/
|
|
|
|
wxString GetComment();
|
2008-03-09 12:24:26 -04:00
|
|
|
const void SetComment(const wxString& comment);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
The low 8 bits are always the DOS/Windows file attributes for this entry.
|
|
|
|
The values of these attributes are given in the
|
|
|
|
enumeration @c wxZipAttributes.
|
|
|
|
The remaining bits can store platform specific permission bits or
|
|
|
|
attributes, and their meaning depends on the value
|
|
|
|
of @ref systemmadeby() SetSystemMadeBy.
|
|
|
|
If IsMadeByUnix() is @true then the
|
|
|
|
high 16 bits are unix mode bits.
|
|
|
|
The following other accessors access these bits:
|
|
|
|
@ref wxArchiveEntry::isreadonly IsReadOnly/SetIsReadOnly
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@ref wxArchiveEntry::isdir IsDir/SetIsDir
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@ref mode() Get/SetMode
|
|
|
|
*/
|
|
|
|
wxUint32 GetExternalAttributes();
|
2008-03-09 12:24:26 -04:00
|
|
|
const void SetExternalAttributes(wxUint32 attr);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
The extra field from the entry's central directory record.
|
|
|
|
The extra field is used to store platform or application specific
|
|
|
|
data. See Pkware's document 'appnote.txt' for information on its format.
|
|
|
|
*/
|
|
|
|
const char* GetExtra();
|
2008-03-09 12:24:26 -04:00
|
|
|
const size_t GetExtraLen();
|
|
|
|
const void SetExtra(const char* extra, size_t len);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
The extra field from the entry's local record.
|
|
|
|
The extra field is used to store platform or application specific
|
|
|
|
data. See Pkware's document 'appnote.txt' for information on its format.
|
|
|
|
*/
|
|
|
|
const char* GetLocalExtra();
|
2008-03-09 12:24:26 -04:00
|
|
|
const size_t GetLocalExtraLen();
|
|
|
|
const void SetLocalExtra(const char* extra, size_t len);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
The compression method. The enumeration @c wxZipMethod lists the
|
|
|
|
possible values.
|
|
|
|
The default constructor sets this to wxZIP_METHOD_DEFAULT,
|
|
|
|
which allows wxZipOutputStream to
|
|
|
|
choose the method when writing the entry.
|
|
|
|
*/
|
|
|
|
int GetMethod();
|
2008-03-09 12:24:26 -04:00
|
|
|
const void SetMethod(int method);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Sets the DOS attributes
|
|
|
|
in @ref externalattributes() GetExternalAttributes
|
|
|
|
to be consistent with the @c mode given.
|
|
|
|
If IsMadeByUnix() is @true then also
|
|
|
|
stores @c mode in GetExternalAttributes().
|
|
|
|
Note that the default constructor
|
2008-03-08 09:43:31 -05:00
|
|
|
sets @ref systemmadeby() GetSystemMadeBy to
|
2008-03-08 08:52:38 -05:00
|
|
|
wxZIP_SYSTEM_MSDOS by default. So to be able to store unix
|
|
|
|
permissions when creating zips, call SetSystemMadeBy(wxZIP_SYSTEM_UNIX).
|
|
|
|
*/
|
|
|
|
int GetMode();
|
2008-03-09 12:24:26 -04:00
|
|
|
const void SetMode(int mode);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
The originating file-system. The default constructor sets this to
|
|
|
|
wxZIP_SYSTEM_MSDOS. Set it to wxZIP_SYSTEM_UNIX in order to be
|
|
|
|
able to store unix permissions using @ref mode() SetMode.
|
|
|
|
*/
|
|
|
|
int GetSystemMadeBy();
|
2008-03-09 12:24:26 -04:00
|
|
|
const void SetSystemMadeBy(int system);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
The compressed size of this entry in bytes.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
off_t GetCompressedSize() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
CRC32 for this entry's data.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxUint32 GetCrc() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a combination of the bits flags in the enumeration @c wxZipFlags.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
int GetFlags() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
A static member that translates a filename into the internal format used
|
|
|
|
within the archive. If the third parameter is provided, the bool pointed
|
|
|
|
to is set to indicate whether the name looks like a directory name
|
|
|
|
(i.e. has a trailing path separator).
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see @ref overview_wxarcbyname "Looking up an archive entry by name"
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxString GetInternalName();
|
2008-03-09 12:24:26 -04:00
|
|
|
const wxString GetInternalName(const wxString& name,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE,
|
|
|
|
bool* pIsDir = NULL);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if @ref systemmadeby() GetSystemMadeBy
|
|
|
|
is a flavour of unix.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsMadeByUnix() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Indicates that this entry's data is text in an 8-bit encoding.
|
|
|
|
*/
|
|
|
|
bool IsText();
|
2008-03-09 12:24:26 -04:00
|
|
|
const void SetIsText(bool isText = true);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2008-03-10 11:24:38 -04:00
|
|
|
Sets the notifier() for this entry.
|
2008-03-08 08:52:38 -05:00
|
|
|
Whenever the wxZipInputStream updates
|
|
|
|
this entry, it will then invoke the associated
|
|
|
|
notifier's wxZipNotifier::OnEntryUpdated
|
|
|
|
method.
|
|
|
|
Setting a notifier is not usually necessary. It is used to handle
|
|
|
|
certain cases when modifying an zip in a pipeline (i.e. between
|
|
|
|
non-seekable streams).
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see @ref overview_wxarcnoseek "Archives on non-seekable streams", wxZipNotifier
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void SetNotifier(wxZipNotifier& notifier);
|
2008-03-08 09:43:31 -05:00
|
|
|
void UnsetNotifier();
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Assignment operator.
|
|
|
|
*/
|
|
|
|
wxZipEntry& operator operator=(const wxZipEntry& entry);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxZipInputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Input stream for reading zip files.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxZipInputStream::GetNextEntry returns an
|
|
|
|
wxZipEntry object containing the meta-data
|
|
|
|
for the next entry in the zip (and gives away ownership). Reading from
|
|
|
|
the wxZipInputStream then returns the entry's data. Eof() becomes @true
|
|
|
|
after an attempt has been made to read past the end of the entry's data.
|
|
|
|
When there are no more entries, GetNextEntry() returns @NULL and sets Eof().
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Note that in general zip entries are not seekable, and
|
|
|
|
wxZipInputStream::SeekI() always returns wxInvalidOffset.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see @ref overview_wxarc "Archive formats such as zip", wxZipEntry,
|
|
|
|
wxZipOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxZipInputStream : public wxArchiveInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Compatibility constructor (requires WXWIN_COMPATIBILITY_2_6).
|
|
|
|
When this constructor is used, an emulation of seeking is
|
|
|
|
switched on for compatibility with previous versions. Note however,
|
|
|
|
that it is deprecated.
|
|
|
|
*/
|
|
|
|
wxZipInputStream(wxInputStream& stream,
|
|
|
|
wxMBConv& conv = wxConvLocal);
|
2008-03-08 09:43:31 -05:00
|
|
|
wxZipInputStream(wxInputStream* stream,
|
|
|
|
wxMBConv& conv = wxConvLocal);
|
|
|
|
wxZipInputStream(const wxString& archive,
|
|
|
|
const wxString& file);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Closes the current entry. On a non-seekable stream reads to the end of
|
|
|
|
the current entry first.
|
|
|
|
*/
|
|
|
|
bool CloseEntry();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the zip comment.
|
|
|
|
This is stored at the end of the zip, therefore when reading a zip
|
|
|
|
from a non-seekable stream, it returns the empty string until the
|
|
|
|
end of the zip has been reached, i.e. when GetNextEntry() returns
|
|
|
|
@NULL.
|
|
|
|
*/
|
|
|
|
wxString GetComment();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Closes the current entry if one is open, then reads the meta-data for
|
|
|
|
the next entry and returns it in a wxZipEntry
|
|
|
|
object, giving away ownership. The stream is then open and can be read.
|
|
|
|
*/
|
|
|
|
wxZipEntry* GetNextEntry();
|
|
|
|
|
|
|
|
/**
|
|
|
|
For a zip on a seekable stream returns the total number of entries in
|
|
|
|
the zip. For zips on non-seekable streams returns the number of entries
|
|
|
|
returned so far by GetNextEntry().
|
|
|
|
*/
|
|
|
|
int GetTotalEntries();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Closes the current entry if one is open, then opens the entry specified
|
2008-03-09 08:33:59 -04:00
|
|
|
by the @a entry object.
|
|
|
|
@a entry should be from the same zip file, and the zip should
|
2008-03-08 08:52:38 -05:00
|
|
|
be on a seekable stream.
|
|
|
|
*/
|
|
|
|
bool OpenEntry(wxZipEntry& entry);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxZipClassFactory
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Class factory for the zip archive format. See the base class
|
|
|
|
for details.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{FIXME}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see @ref overview_wxarc "Archive formats such as zip", @ref
|
|
|
|
overview_wxarcgeneric "Generic archive programming", wxZipEntry, wxZipInputStream, wxZipOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxZipClassFactory : public wxArchiveClassFactory
|
|
|
|
{
|
|
|
|
public:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxZipOutputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Output stream for writing zip files.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxZipOutputStream::PutNextEntry is used to create
|
|
|
|
a new entry in the output zip, then the entry's data is written to the
|
|
|
|
wxZipOutputStream. Another call to PutNextEntry() closes the current
|
|
|
|
entry and begins the next.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see @ref overview_wxarc "Archive formats such as zip", wxZipEntry,
|
|
|
|
wxZipInputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxZipOutputStream : public wxArchiveOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Constructor. @c level is the compression level to use.
|
|
|
|
It can be a value between 0 and 9 or -1 to use the default value
|
|
|
|
which currently is equivalent to 6.
|
|
|
|
If the parent stream is passed as a pointer then the new filter stream
|
|
|
|
takes ownership of it. If it is passed by reference then it does not.
|
|
|
|
In a Unicode build the third parameter @c conv is used to translate
|
|
|
|
the filename and comment fields to an 8-bit encoding. It has no effect on the
|
|
|
|
stream's data.
|
|
|
|
*/
|
|
|
|
wxZipOutputStream(wxOutputStream& stream, int level = -1,
|
|
|
|
wxMBConv& conv = wxConvLocal);
|
2008-03-08 09:43:31 -05:00
|
|
|
wxZipOutputStream(wxOutputStream* stream, int level = -1,
|
|
|
|
wxMBConv& conv = wxConvLocal);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
The destructor calls Close() to finish
|
|
|
|
writing the zip if it has not been called already.
|
|
|
|
*/
|
|
|
|
~wxZipOutputStream();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Finishes writing the zip, returning @true if successful.
|
|
|
|
Called by the destructor if not called explicitly.
|
|
|
|
*/
|
|
|
|
bool Close();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Close the current entry. It is called implicitly whenever another new
|
|
|
|
entry is created with CopyEntry()
|
|
|
|
or PutNextEntry(), or
|
|
|
|
when the zip is closed.
|
|
|
|
*/
|
|
|
|
bool CloseEntry();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Transfers the zip comment from the wxZipInputStream
|
|
|
|
to this output stream.
|
|
|
|
*/
|
|
|
|
bool CopyArchiveMetaData(wxZipInputStream& inputStream);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Takes ownership of @c entry and uses it to create a new entry
|
|
|
|
in the zip. @c entry is then opened in @c inputStream and its contents
|
|
|
|
copied to this stream.
|
|
|
|
CopyEntry() is much more efficient than transferring the data using
|
|
|
|
Read() and Write() since it will copy them without decompressing and
|
|
|
|
recompressing them.
|
|
|
|
For zips on seekable streams, @c entry must be from the same zip file
|
|
|
|
as @c stream. For non-seekable streams, @c entry must also be the
|
|
|
|
last thing read from @c inputStream.
|
|
|
|
*/
|
|
|
|
bool CopyEntry(wxZipEntry* entry, wxZipInputStream& inputStream);
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Set the compression level that will be used the next time an entry is
|
|
|
|
created. It can be a value between 0 and 9 or -1 to use the default value
|
|
|
|
which currently is equivalent to 6.
|
|
|
|
*/
|
|
|
|
int GetLevel();
|
2008-03-09 12:24:26 -04:00
|
|
|
const void SetLevel(int level);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
)
|
|
|
|
Create a new directory entry
|
|
|
|
(see wxArchiveEntry::IsDir)
|
|
|
|
with the given name and timestamp.
|
|
|
|
PutNextEntry() can
|
|
|
|
also be used to create directory entries, by supplying a name with
|
|
|
|
a trailing path separator.
|
|
|
|
*/
|
|
|
|
bool PutNextDirEntry(const wxString& name);
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
, @b off_t@e size = wxInvalidOffset)
|
|
|
|
Create a new entry with the given name, timestamp and size.
|
|
|
|
*/
|
|
|
|
bool PutNextEntry(wxZipEntry* entry);
|
2008-03-08 09:43:31 -05:00
|
|
|
bool PutNextEntry(const wxString& name);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets a comment for the zip as a whole. It is written at the end of the
|
|
|
|
zip.
|
|
|
|
*/
|
|
|
|
void SetComment(const wxString& comment);
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|