2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: archive.h
|
2008-03-13 12:30:38 -04:00
|
|
|
// Purpose: interface of wxArchive* classes
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxArchiveInputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-24 18:17:25 -04:00
|
|
|
This is an abstract base class which serves as a common interface to
|
2008-03-08 08:52:38 -05:00
|
|
|
archive input streams such as wxZipInputStream.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
wxArchiveInputStream::GetNextEntry returns an wxArchiveEntry object containing
|
|
|
|
the meta-data for the next entry in the archive (and gives away ownership).
|
|
|
|
|
|
|
|
Reading from the wxArchiveInputStream 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.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
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
|
|
|
@library{wxbase}
|
2008-10-04 07:01:50 -04:00
|
|
|
@category{archive,streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
@see @ref overview_archive, wxArchiveEntry, wxArchiveOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxArchiveInputStream : public wxFilterInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Closes the current entry. On a non-seekable stream reads to the end of
|
|
|
|
the current entry first.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual bool CloseEntry() = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Closes the current entry if one is open, then reads the meta-data for
|
2008-03-13 12:30:38 -04:00
|
|
|
the next entry and returns it in a wxArchiveEntry object, giving away
|
|
|
|
ownership. Reading this wxArchiveInputStream then returns the entry's data.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxArchiveEntry* GetNextEntry();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Closes the current entry if one is open, then opens the entry specified
|
|
|
|
by the wxArchiveEntry object.
|
2008-03-13 12:30:38 -04:00
|
|
|
|
|
|
|
@a entry must be from the same archive file that this wxArchiveInputStream
|
|
|
|
is reading, and it must be reading it from a seekable stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual bool OpenEntry(wxArchiveEntry& entry) = 0;
|
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 wxArchiveOutputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-24 18:17:25 -04:00
|
|
|
This is an abstract base class which serves as a common interface to
|
2008-03-08 08:52:38 -05:00
|
|
|
archive output streams such as wxZipOutputStream.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
wxArchiveOutputStream::PutNextEntry is used to create a new entry in the
|
|
|
|
output archive, then the entry's data is written to the wxArchiveOutputStream.
|
|
|
|
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}
|
2008-10-04 07:01:50 -04:00
|
|
|
@category{archive,streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
@see @ref overview_archive, wxArchiveEntry, wxArchiveInputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxArchiveOutputStream : public wxFilterOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Calls Close() if it has not already been called.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-23 21:02:55 -04:00
|
|
|
virtual ~wxArchiveOutputStream();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Closes the archive, returning @true if it was successfully written.
|
|
|
|
Called by the destructor if not called explicitly.
|
2008-03-21 10:22:27 -04:00
|
|
|
|
|
|
|
@see wxOutputStream::Close()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-21 10:22:27 -04:00
|
|
|
virtual bool Close();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Close the current entry.
|
|
|
|
It is called implicitly whenever another new entry is created with CopyEntry()
|
|
|
|
or PutNextEntry(), or when the archive is closed.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual bool CloseEntry() = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Some archive formats have additional meta-data that applies to the archive
|
2008-03-13 12:30:38 -04:00
|
|
|
as a whole.
|
|
|
|
For example in the case of zip there is a comment, which is stored at the end
|
|
|
|
of the zip file. CopyArchiveMetaData() can be used to transfer such information
|
|
|
|
when writing a modified copy of an archive.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Since the position of the meta-data can vary between the various archive
|
|
|
|
formats, it is best to call CopyArchiveMetaData() before transferring
|
2008-03-13 12:30:38 -04:00
|
|
|
the entries. The wxArchiveOutputStream will then hold on to the meta-data
|
|
|
|
and write it at the correct point in the output file.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
When the input archive is being read from a non-seekable stream, the
|
|
|
|
meta-data may not be available when CopyArchiveMetaData() is called,
|
|
|
|
in which case the two streams set up a link and transfer the data
|
|
|
|
when it becomes available.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual bool CopyArchiveMetaData(wxArchiveInputStream& stream) = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Takes ownership of @a entry and uses it to create a new entry in the
|
2008-03-24 08:45:43 -04:00
|
|
|
archive. @a entry is then opened in the input stream @a stream
|
2008-03-08 08:52:38 -05:00
|
|
|
and its contents copied to this stream.
|
2008-03-13 12:30:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
For archive types which compress entry data, CopyEntry() is likely to be
|
|
|
|
much more efficient than transferring the data using Read() and Write()
|
|
|
|
since it will copy them without decompressing and recompressing them.
|
2008-03-13 12:30:38 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@a entry must be from the same archive file that @a stream is
|
|
|
|
accessing. For non-seekable streams, @a entry must also be the last
|
2008-03-24 08:45:43 -04:00
|
|
|
thing read from @a stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-21 10:22:27 -04:00
|
|
|
virtual bool CopyEntry(wxArchiveEntry* entry,
|
2008-03-25 12:01:21 -04:00
|
|
|
wxArchiveInputStream& stream) = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04: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.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-21 10:22:27 -04:00
|
|
|
virtual bool PutNextDirEntry(const wxString& name,
|
2008-03-25 12:01:21 -04:00
|
|
|
const wxDateTime& dt = wxDateTime::Now()) = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Takes ownership of entry and uses it to create a new entry in the archive.
|
|
|
|
The entry's data can then be written by writing to this wxArchiveOutputStream.
|
|
|
|
*/
|
2008-03-25 12:01:21 -04:00
|
|
|
virtual bool PutNextEntry(wxArchiveEntry* entry) = 0;
|
2008-03-13 12:30:38 -04:00
|
|
|
|
|
|
|
/**
|
2008-03-08 08:52:38 -05:00
|
|
|
Create a new entry with the given name, timestamp and size. The entry's
|
|
|
|
data can then be written by writing to this wxArchiveOutputStream.
|
|
|
|
*/
|
2008-03-21 10:22:27 -04:00
|
|
|
virtual bool PutNextEntry(const wxString& name,
|
|
|
|
const wxDateTime& dt = wxDateTime::Now(),
|
2008-03-25 12:01:21 -04:00
|
|
|
wxFileOffset size = wxInvalidOffset) = 0;
|
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 wxArchiveEntry
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-24 18:17:25 -04:00
|
|
|
This is an abstract base class which serves as a common interface to
|
2008-03-08 08:52:38 -05:00
|
|
|
archive entry classes such as wxZipEntry.
|
|
|
|
These hold the meta-data (filename, timestamp, etc.), for entries
|
|
|
|
in archive files such as zips and tars.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-10-19 11:30:20 -04:00
|
|
|
@section archiveentry_nonseekable About non-seekable streams
|
2008-04-10 17:17:15 -04:00
|
|
|
|
|
|
|
This information applies only when reading archives from non-seekable streams.
|
|
|
|
When the stream is seekable GetNextEntry() returns a fully populated wxArchiveEntry.
|
2008-03-13 12:30:38 -04:00
|
|
|
See @ref overview_archive_noseek for more information.
|
|
|
|
|
|
|
|
For generic programming, when the worst case must be assumed, you can rely on
|
|
|
|
all the fields of wxArchiveEntry being fully populated when
|
|
|
|
wxArchiveInputStream::GetNextEntry() returns, with the the following exceptions:
|
|
|
|
|
|
|
|
@li GetSize(): guaranteed to be available after the entry has been read to Eof(),
|
|
|
|
or CloseEntry() has been called;
|
|
|
|
@li IsReadOnly(): guaranteed to be available after the end of the archive has
|
|
|
|
been reached, i.e. after GetNextEntry() returns NULL and Eof() is true.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-10-04 07:01:50 -04:00
|
|
|
@category{archive,streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
@see @ref overview_archive, @ref overview_archive_generic,
|
|
|
|
wxArchiveInputStream, wxArchiveOutputStream, wxArchiveNotifier
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxArchiveEntry : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Returns a copy of this entry object.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxArchiveEntry* Clone() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Gets the entry's timestamp.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual wxDateTime GetDateTime() const = 0;
|
2008-03-13 12:30:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the entry's timestamp.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual void SetDateTime(const wxDateTime& dt) = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Returns the entry's name, by default in the native format.
|
|
|
|
The name can include directory components, i.e. it can be a full path.
|
|
|
|
|
|
|
|
If this is a directory entry, (i.e. if IsDir() is @true) then the
|
|
|
|
returned string is the name with a trailing path separator.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual wxString GetName(wxPathFormat format = wxPATH_NATIVE) const = 0;
|
2008-03-13 12:30:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the entry's name.
|
|
|
|
Setting a name with a trailing path separator sets IsDir().
|
|
|
|
|
|
|
|
@see GetName()
|
|
|
|
*/
|
2008-03-21 10:22:27 -04:00
|
|
|
virtual void SetName(const wxString& name,
|
2008-03-25 12:01:21 -04:00
|
|
|
wxPathFormat format = wxPATH_NATIVE) = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Returns the size of the entry's data in bytes.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual wxFileOffset GetSize() const = 0;
|
2008-03-13 12:30:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the size of the entry's data in bytes.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual void SetSize(wxFileOffset size) = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the path format used internally within the archive to store
|
|
|
|
filenames.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual wxPathFormat GetInternalFormat() const = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the entry's filename in the internal format used within the
|
|
|
|
archive. The name can include directory components, i.e. it can be a
|
|
|
|
full path.
|
2008-03-13 12:30:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
The names of directory entries are returned without any trailing path
|
|
|
|
separator. This gives a canonical name that can be used in comparisons.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
@see @ref overview_archive_byname
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual wxString GetInternalName() const = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a numeric value unique to the entry within the archive.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual wxFileOffset GetOffset() const = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Returns @true if this is a directory entry.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Directory entries are entries with no data, which are used to store
|
|
|
|
the meta-data of directories. They also make it possible for completely
|
|
|
|
empty directories to be stored.
|
2008-03-13 12:30:38 -04:00
|
|
|
|
|
|
|
@note
|
2008-03-08 08:52:38 -05:00
|
|
|
The names of entries within an archive can be complete paths, and
|
|
|
|
unarchivers typically create whatever directories are necessary as they
|
|
|
|
restore files, even if the archive contains no explicit directory entries.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual bool IsDir() const = 0;
|
2008-03-13 12:30:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Marks this entry as a directory if @a isDir is @true. See IsDir() for more info.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual void SetIsDir(bool isDir = true) = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Returns @true if the entry is a read-only file.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual bool IsReadOnly() const = 0;
|
2008-03-13 12:30:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets this entry as a read-only file.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual void SetIsReadOnly(bool isReadOnly = true) = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Sets the notifier (see wxArchiveNotifier) for this entry.
|
|
|
|
|
|
|
|
Whenever the wxArchiveInputStream updates this entry, it will then invoke
|
|
|
|
the associated notifier's wxArchiveNotifier::OnEntryUpdated method.
|
|
|
|
|
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 archive in a pipeline (i.e. between
|
|
|
|
non-seekable streams).
|
|
|
|
*/
|
|
|
|
void SetNotifier(wxArchiveNotifier& notifier);
|
2008-03-13 12:30:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Unsets the notifier eventually attached to this entry.
|
|
|
|
*/
|
2008-03-21 10:22:27 -04:00
|
|
|
virtual void UnsetNotifier();
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
/**
|
|
|
|
Type of stream enumeration; used by wxArchiveClassFactory methods.
|
|
|
|
*/
|
|
|
|
enum wxStreamProtocolType
|
|
|
|
{
|
|
|
|
wxSTREAM_PROTOCOL, //!< wxFileSystem protocol (should be only one)
|
|
|
|
wxSTREAM_MIMETYPE, //!< MIME types the stream handles
|
|
|
|
wxSTREAM_ENCODING, //!< Not used for archives
|
|
|
|
wxSTREAM_FILEEXT //!< File extensions the stream handles
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxArchiveClassFactory
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
Allows the creation of streams to handle archive formats such as zip and tar.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
For example, given a filename you can search for a factory that will
|
|
|
|
handle it and create a stream to read it:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
2008-03-13 12:30:38 -04:00
|
|
|
factory = wxArchiveClassFactory::Find(filename, wxSTREAM_FILEEXT);
|
2008-03-08 08:52:38 -05:00
|
|
|
if (factory)
|
2008-03-13 12:30:38 -04:00
|
|
|
stream = factory->NewStream(new wxFFileInputStream(filename));
|
2008-03-08 08:52:38 -05:00
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
wxArchiveClassFactory::Find can also search for a factory by MIME type
|
|
|
|
or wxFileSystem protocol.
|
|
|
|
|
2008-03-20 09:45:17 -04:00
|
|
|
The available factories can be enumerated using
|
2008-03-13 12:30:38 -04:00
|
|
|
wxArchiveClassFactory::GetFirst() and wxArchiveClassFactory::GetNext().
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-10-04 07:01:50 -04:00
|
|
|
@category{archive,streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
@see @ref overview_archive, @ref overview_archive_generic, wxArchiveEntry,
|
|
|
|
wxArchiveInputStream, wxArchiveOutputStream, wxFilterClassFactory
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxArchiveClassFactory : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Returns @true if this factory can handle the given protocol, MIME type
|
|
|
|
or file extension.
|
2008-03-13 12:30:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
When using wxSTREAM_FILEEXT for the second parameter, the first parameter
|
|
|
|
can be a complete filename rather than just an extension.
|
|
|
|
*/
|
2009-01-08 10:36:37 -05:00
|
|
|
bool CanHandle(const wxString& protocol,
|
2008-03-09 12:24:26 -04:00
|
|
|
wxStreamProtocolType type = wxSTREAM_PROTOCOL) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
A static member that finds a factory that can handle a given protocol, MIME
|
|
|
|
type or file extension. Returns a pointer to the class factory if found, or
|
|
|
|
@NULL otherwise. It does not give away ownership of the factory.
|
2008-03-13 12:30:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
When using wxSTREAM_FILEEXT for the second parameter, the first parameter
|
|
|
|
can be a complete filename rather than just an extension.
|
|
|
|
*/
|
2009-01-10 17:42:09 -05:00
|
|
|
static const wxArchiveClassFactory* Find(const wxString& protocol,
|
2008-03-08 09:43:31 -05:00
|
|
|
wxStreamProtocolType type = wxSTREAM_PROTOCOL);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Returns the wxMBConv object that the created streams will use when
|
|
|
|
translating meta-data. The initial default, set by the constructor,
|
|
|
|
is wxConvLocal.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-08 10:36:37 -05:00
|
|
|
wxMBConv& GetConv() const;
|
2008-03-13 12:30:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the wxMBConv object that the created streams will use when
|
|
|
|
translating meta-data.
|
|
|
|
*/
|
|
|
|
void SetConv(wxMBConv& conv);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
GetFirst and GetNext can be used to enumerate the available factories.
|
|
|
|
For example, to list them:
|
2008-03-13 12:30:38 -04:00
|
|
|
|
|
|
|
@code
|
|
|
|
wxString list;
|
|
|
|
const wxArchiveClassFactory *factory = wxArchiveClassFactory::GetFirst();
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
while (factory) {
|
|
|
|
list << factory->GetProtocol() << _T("\n");
|
|
|
|
factory = factory->GetNext();
|
|
|
|
}
|
|
|
|
@endcode
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
GetFirst() and GetNext() return a pointer to a factory or @NULL if no more
|
2008-03-08 08:52:38 -05:00
|
|
|
are available. They do not give away ownership of the factory.
|
|
|
|
*/
|
2009-01-10 17:10:54 -05:00
|
|
|
static const wxArchiveClassFactory* GetFirst();
|
2008-03-09 12:24:26 -04:00
|
|
|
const wxArchiveClassFactory* GetNext() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Calls the static GetInternalName() function for the archive entry type,
|
2008-03-13 12:30:38 -04:00
|
|
|
for example wxZipEntry::GetInternalName.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-08 10:36:37 -05:00
|
|
|
virtual wxString GetInternalName(const wxString& name,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE) const = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Returns the wxFileSystem protocol supported by this factory.
|
|
|
|
Equivalent to @code wxString(*GetProtocols()) @endcode.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetProtocol() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the protocols, MIME types or file extensions supported by this
|
2008-03-13 12:30:38 -04:00
|
|
|
factory, as an array of null terminated strings.
|
|
|
|
|
|
|
|
It does not give away ownership of the array or strings.
|
2008-03-08 08:52:38 -05:00
|
|
|
For example, to list the file extensions a factory supports:
|
2008-03-13 12:30:38 -04:00
|
|
|
|
|
|
|
@code
|
|
|
|
wxString list;
|
|
|
|
const wxChar *const *p;
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
for (p = factory->GetProtocols(wxSTREAM_FILEEXT); *p; p++)
|
|
|
|
list << *p << _T("\n");
|
2008-12-12 14:34:42 -05:00
|
|
|
@endcode
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-08 10:36:37 -05:00
|
|
|
virtual const wxChar** GetProtocols(wxStreamProtocolType type = wxSTREAM_PROTOCOL) const = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Create a new wxArchiveEntry object of the appropriate type.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxArchiveEntry* NewEntry() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Create a new input or output stream to read or write an archive.
|
2008-03-13 12:30:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
If the parent stream is passed as a pointer then the new archive stream
|
|
|
|
takes ownership of it. If it is passed by reference then it does not.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxArchiveInputStream* NewStream(wxInputStream& stream) const;
|
2008-03-13 12:30:38 -04:00
|
|
|
wxArchiveOutputStream* NewStream(wxOutputStream& stream) const;
|
|
|
|
wxArchiveInputStream* NewStream(wxInputStream* stream) const;
|
|
|
|
wxArchiveOutputStream* NewStream(wxOutputStream* stream) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Adds this class factory to the list returned by GetFirst() or GetNext().
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
It is not necessary to do this to use the archive streams. It is usually
|
2008-03-08 09:43:31 -05:00
|
|
|
used when implementing streams, typically the implementation will
|
2008-03-08 08:52:38 -05:00
|
|
|
add a static instance of its factory class.
|
2008-03-13 12:30:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
It can also be used to change the order of a factory already in the list,
|
|
|
|
bringing it to the front. This isn't a thread safe operation
|
|
|
|
so can't be done when other threads are running that will be using the list.
|
|
|
|
The list does not take ownership of the factory.
|
|
|
|
*/
|
|
|
|
void PushFront();
|
|
|
|
|
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Removes this class factory from the list returned by GetFirst() and GetNext().
|
|
|
|
|
|
|
|
Removing from the list isn't a thread safe operation so can't be done when
|
|
|
|
other threads are running that will be using the list.
|
2008-03-08 08:52:38 -05:00
|
|
|
The list does not own the factories, so removing a factory does not delete it.
|
|
|
|
*/
|
|
|
|
void Remove();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxArchiveNotifier
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
If you need to know when a wxArchiveInputStream updates a wxArchiveEntry
|
|
|
|
object, you can create a notifier by deriving from this abstract base class,
|
|
|
|
overriding wxArchiveNotifier::OnEntryUpdated.
|
|
|
|
|
|
|
|
An instance of your notifier class can then be assigned to the wxArchiveEntry
|
|
|
|
object using wxArchiveEntry::SetNotifier.
|
2008-03-08 08:52:38 -05:00
|
|
|
Your OnEntryUpdated() method will then be invoked whenever the input
|
|
|
|
stream updates the entry.
|
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 archive in a pipeline (i.e. between
|
|
|
|
non-seekable streams).
|
2008-03-13 12:30:38 -04:00
|
|
|
See @ref overview_archive_noseek.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-10-04 07:01:50 -04:00
|
|
|
@category{archive,streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
@see @ref overview_archive_noseek, wxArchiveEntry, wxArchiveInputStream,
|
|
|
|
wxArchiveOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxArchiveNotifier
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
This method must be overridden in your derived class.
|
|
|
|
*/
|
2009-01-08 10:36:37 -05:00
|
|
|
virtual void OnEntryUpdated(wxArchiveEntry& entry) = 0;
|
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 wxArchiveIterator
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
An input iterator template class that can be used to transfer an archive's
|
|
|
|
catalogue to a container. It is only available if wxUSE_STL is set to 1
|
|
|
|
in setup.h, and the uses for it outlined below require a compiler which
|
|
|
|
supports member templates.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
2008-11-22 10:36:50 -05:00
|
|
|
template<class Arc, class T = typename Arc::entry_type*>
|
2008-03-08 08:52:38 -05:00
|
|
|
class wxArchiveIterator
|
|
|
|
{
|
|
|
|
// this constructor creates an 'end of sequence' object
|
|
|
|
wxArchiveIterator();
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
// template parameter 'Arc' should be the type of an archive input stream
|
|
|
|
wxArchiveIterator(Arc& arc) {
|
2008-03-09 08:33:59 -04:00
|
|
|
// ...
|
|
|
|
}
|
|
|
|
};
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
The first template parameter should be the type of archive input stream
|
2008-03-13 12:30:38 -04:00
|
|
|
(e.g. wxArchiveInputStream) and the second can either be a pointer to an entry
|
2008-11-22 10:36:50 -05:00
|
|
|
(e.g. wxArchiveEntry*), or a string/pointer pair
|
|
|
|
(e.g. std::pair<wxString,wxArchiveEntry*>).
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
The @c wx/archive.h header defines the following typedefs:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@code
|
2008-03-13 12:30:38 -04:00
|
|
|
typedef wxArchiveIterator<wxArchiveInputStream> wxArchiveIter;
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
typedef wxArchiveIterator<wxArchiveInputStream,
|
|
|
|
std::pair<wxString, wxArchiveEntry*> > wxArchivePairIter;
|
2008-03-09 08:33:59 -04:00
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
The header for any implementation of this interface should define similar
|
|
|
|
typedefs for its types, for example in @c wx/zipstrm.h there is:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@code
|
2008-03-13 12:30:38 -04:00
|
|
|
typedef wxArchiveIterator<wxZipInputStream> wxZipIter;
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
typedef wxArchiveIterator<wxZipInputStream,
|
|
|
|
std::pair<wxString, wxZipEntry*> > wxZipPairIter;
|
2008-03-09 08:33:59 -04:00
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
Transferring the catalogue of an archive @e arc to a vector @e cat,
|
|
|
|
can then be done something like this:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@code
|
2008-03-13 12:30:38 -04:00
|
|
|
std::vector<wxArchiveEntry*> cat((wxArchiveIter)arc, wxArchiveIter());
|
2008-03-09 08:33:59 -04:00
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
When the iterator is dereferenced, it gives away ownership of an entry
|
|
|
|
object. So in the above example, when you have finished with @e cat
|
|
|
|
you must delete the pointers it contains.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
If you have smart pointers with normal copy semantics (i.e. not auto_ptr
|
2008-03-13 12:30:38 -04:00
|
|
|
or wxScopedPtr), then you can create an iterator which uses them instead.
|
|
|
|
|
|
|
|
For example, with a smart pointer class for zip entries @e ZipEntryPtr:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@code
|
2008-03-13 12:30:38 -04:00
|
|
|
typedef std::vector<ZipEntryPtr> ZipCatalog;
|
|
|
|
typedef wxArchiveIterator<wxZipInputStream, ZipEntryPtr> ZipIter;
|
|
|
|
ZipCatalog cat((ZipIter)zip, ZipIter());
|
2008-03-09 08:33:59 -04:00
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-13 12:30:38 -04:00
|
|
|
Iterators that return std::pair objects can be used to populate a std::multimap,
|
|
|
|
to allow entries to be looked up by name.
|
|
|
|
The string is initialised using the wxArchiveEntry object's
|
|
|
|
wxArchiveEntry::GetInternalName function.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@code
|
2008-03-13 12:30:38 -04:00
|
|
|
typedef std::multimap<wxString, wxZipEntry*> ZipCatalog;
|
|
|
|
ZipCatalog cat((wxZipPairIter)zip, wxZipPairIter());
|
2008-03-09 08:33:59 -04:00
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
Note that this iterator also gives away ownership of an entry
|
|
|
|
object each time it is dereferenced. So in the above example, when
|
|
|
|
you have finished with @e cat you must delete the pointers it contains.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
Or if you have them, a pair containing a smart pointer can be used
|
|
|
|
(again @e ZipEntryPtr), no worries about ownership:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@code
|
2008-03-13 12:30:38 -04:00
|
|
|
typedef std::multimap<wxString, ZipEntryPtr> ZipCatalog;
|
|
|
|
typedef wxArchiveIterator<wxZipInputStream,
|
|
|
|
std::pair<wxString, ZipEntryPtr> > ZipPairIter;
|
|
|
|
ZipCatalog cat((ZipPairIter)zip, ZipPairIter());
|
2008-03-09 08:33:59 -04:00
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@library{wxbase}
|
2008-10-04 07:01:50 -04:00
|
|
|
@category{archive,streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxArchiveEntry, wxArchiveInputStream, wxArchiveOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxArchiveIterator
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
2008-03-09 08:33:59 -04:00
|
|
|
/**
|
2008-03-13 12:30:38 -04:00
|
|
|
Default constructor.
|
2008-03-09 08:33:59 -04:00
|
|
|
*/
|
|
|
|
wxArchiveIterator();
|
2008-03-13 12:30:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Construct the iterator that returns all the entries in the archive input
|
2008-03-24 08:45:43 -04:00
|
|
|
stream @a arc.
|
2008-03-13 12:30:38 -04:00
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
wxArchiveIterator(Arc& arc);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
/**
|
|
|
|
Returns an entry object from the archive input stream, giving away
|
|
|
|
ownership.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
const T operator*() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Position the input iterator at the next entry in the archive input stream.
|
|
|
|
*/
|
|
|
|
wxArchiveIterator operator++();
|
2008-03-13 12:30:38 -04:00
|
|
|
wxArchiveIterator operator++(int);
|
2008-03-09 08:33:59 -04:00
|
|
|
//@}
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|