+ friend class wxZipInputStream;
+ friend class wxZipOutputStream;
+
+ DECLARE_DYNAMIC_CLASS(wxZipEntry)
+};
+
+
+/////////////////////////////////////////////////////////////////////////////
+// wxZipOutputStream
+
+WX_DECLARE_LIST_WITH_DECL(wxZipEntry, _wxZipEntryList, class WXDLLIMPEXP_BASE);
+
+class WXDLLIMPEXP_BASE wxZipOutputStream : public wxArchiveOutputStream
+{
+public:
+ wxZipOutputStream(wxOutputStream& stream,
+ int level = -1,
+ wxMBConv& conv = wxConvLocal);
+ virtual ~wxZipOutputStream();
+
+ bool PutNextEntry(wxZipEntry *entry) { return DoCreate(entry); }
+
+ bool PutNextEntry(const wxString& name,
+ const wxDateTime& dt = wxDateTime::Now(),
+ wxFileOffset size = wxInvalidOffset);
+
+ bool PutNextDirEntry(const wxString& name,
+ const wxDateTime& dt = wxDateTime::Now());
+
+ bool CopyEntry(wxZipEntry *entry, wxZipInputStream& inputStream);
+ bool CopyArchiveMetaData(wxZipInputStream& inputStream);
+
+ void Sync();
+ bool CloseEntry();
+ bool Close();
+
+ void SetComment(const wxString& comment) { m_Comment = comment; }
+
+ int GetLevel() const { return m_level; }
+ void SetLevel(int level);
+
+protected:
+ virtual size_t OnSysWrite(const void *buffer, size_t size);
+ virtual wxFileOffset OnSysTell() const { return m_entrySize; }
+
+ 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);
+
+ bool IsParentSeekable() const { return m_offsetAdjustment
+ != wxInvalidOffset; }
+
+private:
+ bool PutNextEntry(wxArchiveEntry *entry);
+ bool CopyEntry(wxArchiveEntry *entry, wxArchiveInputStream& stream);
+ bool CopyArchiveMetaData(wxArchiveInputStream& stream);
+
+ 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;
+ _wxZipEntryList 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);
+ wxZipInputStream(const wxString& archive, const wxString& file);
+ virtual ~wxZipInputStream();
+
+ bool OpenEntry(wxZipEntry& entry) { return DoOpen(&entry); }
+ bool CloseEntry();
+
+ wxZipEntry *GetNextEntry();
+
+ wxString GetComment();
+ int GetTotalEntries();
+
+ virtual wxFileOffset GetLength() const { return m_entry.GetSize(); }
+
+protected:
+ size_t 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);
+
+private:
+ void Init();
+ wxInputStream& OpenFile(const wxString& archive);
+
+ wxArchiveEntry *DoGetNextEntry() { return GetNextEntry(); }
+
+ bool OpenEntry(wxArchiveEntry& entry);
+
+ 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);