+/////////////////////////////////////////////////////////////////////////////
+// Class factory
+
+wxZipClassFactory g_wxZipClassFactory;
+
+wxZipClassFactory::wxZipClassFactory()
+{
+ if (this == &g_wxZipClassFactory)
+ PushFront();
+}
+
+const wxChar * const *
+wxZipClassFactory::GetProtocols(wxStreamProtocolType type) const
+{
+ static const wxChar *protocols[] = { _T("zip"), NULL };
+ static const wxChar *mimetypes[] = { _T("application/zip"), NULL };
+ static const wxChar *fileexts[] = { _T(".zip"), _T(".htb"), NULL };
+ static const wxChar *empty[] = { NULL };
+
+ switch (type) {
+ case wxSTREAM_PROTOCOL: return protocols;
+ case wxSTREAM_MIMETYPE: return mimetypes;
+ case wxSTREAM_FILEEXT: return fileexts;
+ default: return empty;
+ }
+}
+
+
+/////////////////////////////////////////////////////////////////////////////
+// Read a zip header
+
+class wxZipHeader
+{
+public:
+ wxZipHeader(wxInputStream& stream, size_t size);
+
+ inline wxUint8 Read8();
+ inline wxUint16 Read16();
+ inline wxUint32 Read32();
+
+ const char *GetData() const { return m_data; }
+ size_t GetSize() const { return m_size; }
+ operator bool() const { return m_ok; }
+
+ size_t Seek(size_t pos) { m_pos = pos; return m_pos; }
+ size_t Skip(size_t size) { m_pos += size; return m_pos; }
+
+ wxZipHeader& operator>>(wxUint8& n) { n = Read8(); return *this; }
+ wxZipHeader& operator>>(wxUint16& n) { n = Read16(); return *this; }
+ wxZipHeader& operator>>(wxUint32& n) { n = Read32(); return *this; }
+
+private:
+ char m_data[64];
+ size_t m_size;
+ size_t m_pos;
+ bool m_ok;
+};
+
+wxZipHeader::wxZipHeader(wxInputStream& stream, size_t size)
+ : m_size(0),
+ m_pos(0),
+ m_ok(false)
+{
+ wxCHECK_RET(size <= sizeof(m_data), _T("buffer too small"));
+ m_size = stream.Read(m_data, size).LastRead();
+ m_ok = m_size == size;
+}
+
+wxUint8 wxZipHeader::Read8()
+{
+ wxASSERT(m_pos < m_size);
+ return m_data[m_pos++];
+}
+
+wxUint16 wxZipHeader::Read16()
+{
+ wxASSERT(m_pos + 2 <= m_size);
+ wxUint16 n = CrackUint16(m_data + m_pos);
+ m_pos += 2;
+ return n;
+}
+
+wxUint32 wxZipHeader::Read32()
+{
+ wxASSERT(m_pos + 4 <= m_size);
+ wxUint32 n = CrackUint32(m_data + m_pos);
+ m_pos += 4;
+ return n;
+}
+
+