X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ceefc965f987990f561915bba9eda19c6571918e..d642db66a5efc82d374b813022c72ba88bc50839:/include/wx/zipstrm.h diff --git a/include/wx/zipstrm.h b/include/wx/zipstrm.h index 1ecc46718d..618403f95c 100644 --- a/include/wx/zipstrm.h +++ b/include/wx/zipstrm.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: zipstrm.h +// Name: wx/zipstrm.h // Purpose: Streams for Zip files // Author: Mike Wetherell // RCS-ID: $Id$ @@ -10,18 +10,25 @@ #ifndef _WX_WXZIPSTREAM_H__ #define _WX_WXZIPSTREAM_H__ -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma interface "zipstrm.h" -#endif - #include "wx/defs.h" -#if wxUSE_ZLIB && wxUSE_STREAMS && wxUSE_ZIPSTREAM +#if wxUSE_ZIPSTREAM #include "wx/archive.h" -#include "wx/hashmap.h" #include "wx/filename.h" +// some methods from wxZipInputStream and wxZipOutputStream stream do not get +// exported/imported when compiled with Mingw versions before 3.4.2. So they +// are imported/exported individually as a workaround +#if (defined(__GNUWIN32__) || defined(__MINGW32__)) \ + && (!defined __GNUC__ \ + || !defined __GNUC_MINOR__ \ + || !defined __GNUC_PATCHLEVEL__ \ + || __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 30402) +#define WXZIPFIX WXDLLIMPEXP_BASE +#else +#define WXZIPFIX +#endif ///////////////////////////////////////////////////////////////////////////// // constants @@ -45,7 +52,7 @@ enum wxZipMethod }; // Originating File-System. -// +// // These are Pkware's values. Note that Info-zip disagree on some of them, // most notably NTFS. // @@ -105,8 +112,8 @@ enum wxZipFlags // Forward decls // -class WXDLLIMPEXP_BASE wxZipEntry; -class WXDLLIMPEXP_BASE wxZipInputStream; +class WXDLLIMPEXP_FWD_BASE wxZipEntry; +class WXDLLIMPEXP_FWD_BASE wxZipInputStream; ///////////////////////////////////////////////////////////////////////////// @@ -260,9 +267,9 @@ private: ///////////////////////////////////////////////////////////////////////////// -// wxZipOutputStream +// wxZipOutputStream -WX_DECLARE_LIST_WITH_DECL(wxZipEntry, _wxZipEntryList, class WXDLLIMPEXP_BASE); +WX_DECLARE_LIST_WITH_DECL(wxZipEntry, wxZipEntryList_, class WXDLLIMPEXP_BASE); class WXDLLIMPEXP_BASE wxZipOutputStream : public wxArchiveOutputStream { @@ -270,48 +277,54 @@ public: wxZipOutputStream(wxOutputStream& stream, int level = -1, wxMBConv& conv = wxConvLocal); - virtual ~wxZipOutputStream(); + wxZipOutputStream(wxOutputStream *stream, + int level = -1, + wxMBConv& conv = wxConvLocal); + virtual WXZIPFIX ~wxZipOutputStream(); bool PutNextEntry(wxZipEntry *entry) { return DoCreate(entry); } - bool PutNextEntry(const wxString& name, - const wxDateTime& dt = wxDateTime::Now(), - wxFileOffset size = wxInvalidOffset); + bool WXZIPFIX PutNextEntry(const wxString& name, + const wxDateTime& dt = wxDateTime::Now(), + wxFileOffset size = wxInvalidOffset); - bool PutNextDirEntry(const wxString& name, - const wxDateTime& dt = wxDateTime::Now()); + bool WXZIPFIX PutNextDirEntry(const wxString& name, + const wxDateTime& dt = wxDateTime::Now()); - bool CopyEntry(wxZipEntry *entry, wxZipInputStream& inputStream); - bool CopyArchiveMetaData(wxZipInputStream& inputStream); + bool WXZIPFIX CopyEntry(wxZipEntry *entry, wxZipInputStream& inputStream); + bool WXZIPFIX CopyArchiveMetaData(wxZipInputStream& inputStream); - void Sync(); - bool CloseEntry(); - bool Close(); + void WXZIPFIX Sync(); + bool WXZIPFIX CloseEntry(); + bool WXZIPFIX Close(); void SetComment(const wxString& comment) { m_Comment = comment; } int GetLevel() const { return m_level; } - void SetLevel(int level); - + void WXZIPFIX SetLevel(int level); + protected: - virtual size_t OnSysWrite(const void *buffer, size_t size); + virtual size_t WXZIPFIX OnSysWrite(const void *buffer, size_t size); virtual wxFileOffset OnSysTell() const { return m_entrySize; } + // this protected interface isn't yet finalised struct Buffer { const char *m_data; size_t m_size; }; - virtual wxOutputStream *OpenCompressor(wxOutputStream& stream, - wxZipEntry& entry, - const Buffer bufs[]); - virtual bool CloseCompressor(wxOutputStream *comp); + virtual wxOutputStream* WXZIPFIX OpenCompressor(wxOutputStream& stream, + wxZipEntry& entry, + const Buffer bufs[]); + virtual bool WXZIPFIX CloseCompressor(wxOutputStream *comp); - bool IsParentSeekable() const { return m_offsetAdjustment - != wxInvalidOffset; } + bool IsParentSeekable() const + { return m_offsetAdjustment != wxInvalidOffset; } private: - bool PutNextEntry(wxArchiveEntry *entry); - bool CopyEntry(wxArchiveEntry *entry, wxArchiveInputStream& stream); - bool CopyArchiveMetaData(wxArchiveInputStream& stream); + void Init(int level); + + bool WXZIPFIX PutNextEntry(wxArchiveEntry *entry); + bool WXZIPFIX CopyEntry(wxArchiveEntry *entry, wxArchiveInputStream& stream); + bool WXZIPFIX CopyArchiveMetaData(wxArchiveInputStream& stream); - bool IsOpened() const { return m_comp || m_pending; } + bool IsOpened() const { return m_comp || m_pending; } bool DoCreate(wxZipEntry *entry, bool raw = false); void CreatePendingEntry(const void *buffer, size_t size); @@ -320,7 +333,7 @@ private: class wxStoredOutputStream *m_store; class wxZlibOutputStream2 *m_deflate; class wxZipStreamLink *m_backlink; - _wxZipEntryList m_entries; + wxZipEntryList_ m_entries; char *m_initialData; size_t m_initialSize; wxZipEntry *m_pending; @@ -333,13 +346,14 @@ private: int m_level; wxFileOffset m_offsetAdjustment; wxString m_Comment; + bool m_endrecWritten; - DECLARE_NO_COPY_CLASS(wxZipOutputStream) + wxDECLARE_NO_COPY_CLASS(wxZipOutputStream); }; ///////////////////////////////////////////////////////////////////////////// -// wxZipInputStream +// wxZipInputStream class WXDLLIMPEXP_BASE wxZipInputStream : public wxArchiveInputStream { @@ -347,34 +361,47 @@ public: typedef wxZipEntry entry_type; wxZipInputStream(wxInputStream& stream, wxMBConv& conv = wxConvLocal); - wxZipInputStream(const wxString& archive, const wxString& file); - virtual ~wxZipInputStream(); + wxZipInputStream(wxInputStream *stream, wxMBConv& conv = wxConvLocal); + +#if WXWIN_COMPATIBILITY_2_6 && wxUSE_FFILE + wxZipInputStream(const wxString& archive, const wxString& file) + : wxArchiveInputStream(OpenFile(archive), wxConvLocal) { Init(file); } +#endif + + virtual WXZIPFIX ~wxZipInputStream(); bool OpenEntry(wxZipEntry& entry) { return DoOpen(&entry); } - bool CloseEntry(); + bool WXZIPFIX CloseEntry(); wxZipEntry *GetNextEntry(); - wxString GetComment(); - int GetTotalEntries(); + wxString WXZIPFIX GetComment(); + int WXZIPFIX GetTotalEntries(); virtual wxFileOffset GetLength() const { return m_entry.GetSize(); } protected: - size_t OnSysRead(void *buffer, size_t size); + size_t WXZIPFIX OnSysRead(void *buffer, size_t size); wxFileOffset OnSysTell() const { return m_decomp ? m_decomp->TellI() : 0; } - wxFileOffset OnSysSeek(wxFileOffset seek, wxSeekMode mode); - virtual wxInputStream *OpenDecompressor(wxInputStream& stream); - virtual bool CloseDecompressor(wxInputStream *decomp); +#if WXWIN_COMPATIBILITY_2_6 + wxFileOffset WXZIPFIX OnSysSeek(wxFileOffset seek, wxSeekMode mode); +#endif + + // this protected interface isn't yet finalised + virtual wxInputStream* WXZIPFIX OpenDecompressor(wxInputStream& stream); + virtual bool WXZIPFIX CloseDecompressor(wxInputStream *decomp); private: void Init(); - wxInputStream& OpenFile(const wxString& archive); + void Init(const wxString& file); +#if WXWIN_COMPATIBILITY_2_6 && wxUSE_FFILE + static wxInputStream *OpenFile(const wxString& archive); +#endif wxArchiveEntry *DoGetNextEntry() { return GetNextEntry(); } - bool OpenEntry(wxArchiveEntry& entry); + bool WXZIPFIX OpenEntry(wxArchiveEntry& entry); wxStreamError ReadLocal(bool readEndRec = false); wxStreamError ReadCentral(); @@ -382,7 +409,7 @@ private: wxUint32 ReadSignature(); bool FindEndRecord(); bool LoadEndRecord(); - + bool AtHeader() const { return m_headerSize == 0; } bool AfterHeader() const { return m_headerSize > 0 && !m_decomp; } bool IsOpened() const { return m_decomp != NULL; } @@ -395,7 +422,6 @@ private: class wxStoredInputStream *m_store; class wxZlibInputStream2 *m_inflate; class wxRawInputStream *m_rawin; - class wxFFileInputStream *m_ffile; wxZipEntry m_entry; bool m_raw; size_t m_headerSize; @@ -415,27 +441,60 @@ private: friend bool wxZipOutputStream::CopyArchiveMetaData( wxZipInputStream& inputStream); - DECLARE_NO_COPY_CLASS(wxZipInputStream) +#if WXWIN_COMPATIBILITY_2_6 + bool m_allowSeeking; + friend class wxArchiveFSHandler; +#endif + + wxDECLARE_NO_COPY_CLASS(wxZipInputStream); }; +///////////////////////////////////////////////////////////////////////////// +// Iterators + +#if wxUSE_STL || defined WX_TEST_ARCHIVE_ITERATOR +typedef wxArchiveIterator wxZipIter; +typedef wxArchiveIterator > wxZipPairIter; +#endif + + ///////////////////////////////////////////////////////////////////////////// // wxZipClassFactory class WXDLLIMPEXP_BASE wxZipClassFactory : public wxArchiveClassFactory { public: + typedef wxZipEntry entry_type; + typedef wxZipInputStream instream_type; + typedef wxZipOutputStream outstream_type; + typedef wxZipNotifier notifier_type; +#if wxUSE_STL || defined WX_TEST_ARCHIVE_ITERATOR + typedef wxZipIter iter_type; + typedef wxZipPairIter pairiter_type; +#endif + + wxZipClassFactory(); + wxZipEntry *NewEntry() const { return new wxZipEntry; } wxZipInputStream *NewStream(wxInputStream& stream) const { return new wxZipInputStream(stream, GetConv()); } wxZipOutputStream *NewStream(wxOutputStream& stream) const { return new wxZipOutputStream(stream, -1, GetConv()); } + wxZipInputStream *NewStream(wxInputStream *stream) const + { return new wxZipInputStream(stream, GetConv()); } + wxZipOutputStream *NewStream(wxOutputStream *stream) const + { return new wxZipOutputStream(stream, -1, GetConv()); } wxString GetInternalName(const wxString& name, wxPathFormat format = wxPATH_NATIVE) const { return wxZipEntry::GetInternalName(name, format); } + const wxChar * const *GetProtocols(wxStreamProtocolType type + = wxSTREAM_PROTOCOL) const; + protected: wxArchiveEntry *DoNewEntry() const { return NewEntry(); } @@ -443,41 +502,35 @@ protected: { return NewStream(stream); } wxArchiveOutputStream *DoNewStream(wxOutputStream& stream) const { return NewStream(stream); } + wxArchiveInputStream *DoNewStream(wxInputStream *stream) const + { return NewStream(stream); } + wxArchiveOutputStream *DoNewStream(wxOutputStream *stream) const + { return NewStream(stream); } private: DECLARE_DYNAMIC_CLASS(wxZipClassFactory) }; -///////////////////////////////////////////////////////////////////////////// -// Iterators - -#if wxUSE_STL || defined WX_TEST_ARCHIVE_ITERATOR -typedef wxArchiveIterator wxZipIter; -typedef wxArchiveIterator > wxZipPairIter; -#endif - - ///////////////////////////////////////////////////////////////////////////// // wxZipEntry inlines -bool wxZipEntry::IsText() const +inline bool wxZipEntry::IsText() const { return (m_InternalAttributes & TEXT_ATTR) != 0; } -bool wxZipEntry::IsDir() const +inline bool wxZipEntry::IsDir() const { return (m_ExternalAttributes & wxZIP_A_SUBDIR) != 0; } -bool wxZipEntry::IsReadOnly() const +inline bool wxZipEntry::IsReadOnly() const { return (m_ExternalAttributes & wxZIP_A_RDONLY) != 0; } -bool wxZipEntry::IsMadeByUnix() const +inline bool wxZipEntry::IsMadeByUnix() const { const int pattern = (1 << wxZIP_SYSTEM_OPENVMS) | @@ -492,7 +545,7 @@ bool wxZipEntry::IsMadeByUnix() const || ((pattern >> m_SystemMadeBy) & 1); } -void wxZipEntry::SetIsText(bool isText) +inline void wxZipEntry::SetIsText(bool isText) { if (isText) m_InternalAttributes |= TEXT_ATTR; @@ -500,7 +553,7 @@ void wxZipEntry::SetIsText(bool isText) m_InternalAttributes &= ~TEXT_ATTR; } -void wxZipEntry::SetIsReadOnly(bool isReadOnly) +inline void wxZipEntry::SetIsReadOnly(bool isReadOnly) { if (isReadOnly) SetMode(GetMode() & ~0222); @@ -508,8 +561,8 @@ void wxZipEntry::SetIsReadOnly(bool isReadOnly) SetMode(GetMode() | 0200); } -void wxZipEntry::SetName(const wxString& name, - wxPathFormat format /*=wxPATH_NATIVE*/) +inline void wxZipEntry::SetName(const wxString& name, + wxPathFormat format /*=wxPATH_NATIVE*/) { bool isDir; m_Name = GetInternalName(name, format, &isDir); @@ -517,6 +570,6 @@ void wxZipEntry::SetName(const wxString& name, } -#endif // wxUSE_ZLIB && wxUSE_STREAMS && wxUSE_ZIPSTREAM +#endif // wxUSE_ZIPSTREAM #endif // _WX_WXZIPSTREAM_H__