+ friend class wxZipInputStream;
+ friend class wxZipOutputStream;
+
+ DECLARE_DYNAMIC_CLASS(wxZipEntry)
+};
+
+
+/////////////////////////////////////////////////////////////////////////////
+// wxZipOutputStream
+
+WX_DECLARE_LIST_WITH_DECL(wxZipEntry, wx__ZipEntryList, class WXDLLIMPEXP_BASE);
+
+class WXDLLIMPEXP_BASE wxZipOutputStream : public wxArchiveOutputStream
+{
+public:
+ wxZipOutputStream(wxOutputStream& stream,
+ int level = -1,
+ wxMBConv& conv = wxConvLocal);
+ virtual WXZIPFIX ~wxZipOutputStream();
+
+ bool PutNextEntry(wxZipEntry *entry) { return DoCreate(entry); }
+
+ bool WXZIPFIX PutNextEntry(const wxString& name,
+ const wxDateTime& dt = wxDateTime::Now(),
+ wxFileOffset size = wxInvalidOffset);
+
+ bool WXZIPFIX PutNextDirEntry(const wxString& name,
+ const wxDateTime& dt = wxDateTime::Now());
+
+ bool WXZIPFIX CopyEntry(wxZipEntry *entry, wxZipInputStream& inputStream);
+ bool WXZIPFIX CopyArchiveMetaData(wxZipInputStream& inputStream);
+
+ void WXZIPFIX Sync();
+ bool WXZIPFIX CloseEntry();
+ bool WXZIPFIX Close();
+
+ void SetComment(const wxString& comment) { m_Comment = comment; }
+
+ int GetLevel() const { return m_level; }
+ void WXZIPFIX SetLevel(int level);
+
+ bool WXZIPFIX PutNextEntry(wxArchiveEntry *entry);
+ bool WXZIPFIX CopyEntry(wxArchiveEntry *entry, wxArchiveInputStream& stream);
+ bool WXZIPFIX CopyArchiveMetaData(wxArchiveInputStream& stream);
+
+protected:
+ 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* WXZIPFIX OpenCompressor(wxOutputStream& stream,
+ wxZipEntry& entry,
+ const Buffer bufs[]);
+ virtual bool WXZIPFIX CloseCompressor(wxOutputStream *comp);
+
+ bool IsParentSeekable() const
+ { return m_offsetAdjustment != wxInvalidOffset; }
+
+private:
+ bool IsOpened() const { return m_comp || m_pending; }
+
+ bool DoCreate(wxZipEntry *entry, bool raw = false);
+ void CreatePendingEntry(const void *buffer, size_t size);
+ void CreatePendingEntry();
+
+ class wxStoredOutputStream *m_store;
+ class wxZlibOutputStream2 *m_deflate;
+ class wxZipStreamLink *m_backlink;
+ wx__ZipEntryList m_entries;
+ char *m_initialData;
+ size_t m_initialSize;
+ wxZipEntry *m_pending;
+ bool m_raw;
+ wxFileOffset m_headerOffset;
+ size_t m_headerSize;
+ wxFileOffset m_entrySize;
+ wxUint32 m_crcAccumulator;
+ wxOutputStream *m_comp;
+ int m_level;
+ wxFileOffset m_offsetAdjustment;
+ wxString m_Comment;
+
+ DECLARE_NO_COPY_CLASS(wxZipOutputStream)
+};
+
+
+/////////////////////////////////////////////////////////////////////////////
+// wxZipInputStream
+
+class WXDLLIMPEXP_BASE wxZipInputStream : public wxArchiveInputStream
+{
+public:
+ typedef wxZipEntry entry_type;
+
+ wxZipInputStream(wxInputStream& stream, wxMBConv& conv = wxConvLocal);
+
+#if 1 //WXWIN_COMPATIBILITY_2_6
+ wxZipInputStream(const wxString& archive, const wxString& file)
+ : wxArchiveInputStream(OpenFile(archive), wxConvLocal) { Init(file); }
+#endif
+
+ virtual WXZIPFIX ~wxZipInputStream();
+
+ bool WXZIPFIX OpenEntry(wxArchiveEntry& entry);
+ bool OpenEntry(wxZipEntry& entry) { return DoOpen(&entry); }
+ bool WXZIPFIX CloseEntry();
+
+ wxZipEntry *GetNextEntry();
+
+ wxString WXZIPFIX GetComment();
+ int WXZIPFIX GetTotalEntries();
+
+ virtual wxFileOffset GetLength() const { return m_entry.GetSize(); }
+
+protected:
+ size_t WXZIPFIX OnSysRead(void *buffer, size_t size);
+ wxFileOffset OnSysTell() const { return m_decomp ? m_decomp->TellI() : 0; }
+
+#if 1 //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);
+
+ wxArchiveEntry *DoGetNextEntry() { return GetNextEntry(); }
+
+private:
+ void Init();
+ void Init(const wxString& file);
+ wxInputStream& OpenFile(const wxString& archive);
+
+ wxStreamError ReadLocal(bool readEndRec = false);
+ wxStreamError ReadCentral();
+
+ 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; }
+
+ wxZipStreamLink *MakeLink(wxZipOutputStream *out);
+
+ bool DoOpen(wxZipEntry *entry = NULL, bool raw = false);
+ bool OpenDecompressor(bool raw = false);
+
+ 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;
+ wxUint32 m_crcAccumulator;
+ wxInputStream *m_decomp;
+ bool m_parentSeekable;
+ class wxZipWeakLinks *m_weaklinks;
+ class wxZipStreamLink *m_streamlink;
+ wxFileOffset m_offsetAdjustment;
+ wxFileOffset m_position;
+ wxUint32 m_signature;
+ size_t m_TotalEntries;
+ wxString m_Comment;
+
+ friend bool wxZipOutputStream::CopyEntry(
+ wxZipEntry *entry, wxZipInputStream& inputStream);
+ friend bool wxZipOutputStream::CopyArchiveMetaData(
+ wxZipInputStream& inputStream);
+
+#if 1 //WXWIN_COMPATIBILITY_2_6
+ bool m_allowSeeking;
+ friend class wxZipFSInputStream;
+#endif
+
+ DECLARE_NO_COPY_CLASS(wxZipInputStream)
+};
+
+
+/////////////////////////////////////////////////////////////////////////////
+// Iterators
+
+#if wxUSE_STL || defined WX_TEST_ARCHIVE_ITERATOR
+typedef wxArchiveIterator<wxZipInputStream> wxZipIter;
+typedef wxArchiveIterator<wxZipInputStream,
+ std::pair<wxString, wxZipEntry*> > 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
+
+ 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()); }
+
+ wxString GetInternalName(const wxString& name,
+ wxPathFormat format = wxPATH_NATIVE) const
+ { return wxZipEntry::GetInternalName(name, format); }
+
+protected:
+ wxArchiveEntry *DoNewEntry() const
+ { return NewEntry(); }
+ wxArchiveInputStream *DoNewStream(wxInputStream& stream) const
+ { return NewStream(stream); }
+ wxArchiveOutputStream *DoNewStream(wxOutputStream& stream) const
+ { return NewStream(stream); }
+
+private:
+ DECLARE_DYNAMIC_CLASS(wxZipClassFactory)
+};
+
+
+/////////////////////////////////////////////////////////////////////////////
+// wxZipEntry inlines
+
+inline bool wxZipEntry::IsText() const
+{
+ return (m_InternalAttributes & TEXT_ATTR) != 0;
+}
+
+inline bool wxZipEntry::IsDir() const
+{
+ return (m_ExternalAttributes & wxZIP_A_SUBDIR) != 0;
+}
+
+inline bool wxZipEntry::IsReadOnly() const
+{
+ return (m_ExternalAttributes & wxZIP_A_RDONLY) != 0;
+}
+
+inline bool wxZipEntry::IsMadeByUnix() const
+{
+ const int pattern =
+ (1 << wxZIP_SYSTEM_OPENVMS) |
+ (1 << wxZIP_SYSTEM_UNIX) |
+ (1 << wxZIP_SYSTEM_ATARI_ST) |
+ (1 << wxZIP_SYSTEM_ACORN_RISC) |
+ (1 << wxZIP_SYSTEM_BEOS) | (1 << wxZIP_SYSTEM_TANDEM);
+
+ // note: some unix zippers put madeby = dos
+ return (m_SystemMadeBy == wxZIP_SYSTEM_MSDOS
+ && (m_ExternalAttributes & ~0xFFFF))
+ || ((pattern >> m_SystemMadeBy) & 1);
+}
+
+inline void wxZipEntry::SetIsText(bool isText)
+{
+ if (isText)
+ m_InternalAttributes |= TEXT_ATTR;
+ else
+ m_InternalAttributes &= ~TEXT_ATTR;
+}
+
+inline void wxZipEntry::SetIsReadOnly(bool isReadOnly)
+{
+ if (isReadOnly)
+ SetMode(GetMode() & ~0222);
+ else
+ SetMode(GetMode() | 0200);
+}
+
+inline void wxZipEntry::SetName(const wxString& name,
+ wxPathFormat format /*=wxPATH_NATIVE*/)
+{
+ bool isDir;
+ m_Name = GetInternalName(name, format, &isDir);
+ SetIsDir(isDir);
+}