1999-07-07 22:04:58 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-10-30 11:56:12 +00:00
|
|
|
// Name: wx/zipstrm.h
|
2004-11-10 23:58:38 +00:00
|
|
|
// Purpose: Streams for Zip files
|
|
|
|
// Author: Mike Wetherell
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Mike Wetherell
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1999-07-07 22:04:58 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2004-11-10 23:58:38 +00:00
|
|
|
#ifndef _WX_WXZIPSTREAM_H__
|
|
|
|
#define _WX_WXZIPSTREAM_H__
|
1999-07-07 22:04:58 +00:00
|
|
|
|
1999-07-11 15:56:57 +00:00
|
|
|
#include "wx/defs.h"
|
1999-07-07 22:04:58 +00:00
|
|
|
|
2006-10-27 22:03:29 +00:00
|
|
|
#if wxUSE_ZIPSTREAM
|
1999-07-11 15:56:57 +00:00
|
|
|
|
2004-11-10 23:58:38 +00:00
|
|
|
#include "wx/archive.h"
|
|
|
|
#include "wx/filename.h"
|
1999-07-07 22:04:58 +00:00
|
|
|
|
2005-04-11 23:26:44 +00:00
|
|
|
// 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)
|
2006-10-30 11:56:12 +00:00
|
|
|
#define WXZIPFIX WXDLLIMPEXP_BASE
|
2005-04-11 23:26:44 +00:00
|
|
|
#else
|
|
|
|
#define WXZIPFIX
|
|
|
|
#endif
|
1999-07-07 22:04:58 +00:00
|
|
|
|
2004-11-10 23:58:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// constants
|
|
|
|
|
|
|
|
// Compression Method, only 0 (store) and 8 (deflate) are supported here
|
|
|
|
//
|
|
|
|
enum wxZipMethod
|
|
|
|
{
|
|
|
|
wxZIP_METHOD_STORE,
|
|
|
|
wxZIP_METHOD_SHRINK,
|
|
|
|
wxZIP_METHOD_REDUCE1,
|
|
|
|
wxZIP_METHOD_REDUCE2,
|
|
|
|
wxZIP_METHOD_REDUCE3,
|
|
|
|
wxZIP_METHOD_REDUCE4,
|
|
|
|
wxZIP_METHOD_IMPLODE,
|
|
|
|
wxZIP_METHOD_TOKENIZE,
|
|
|
|
wxZIP_METHOD_DEFLATE,
|
|
|
|
wxZIP_METHOD_DEFLATE64,
|
|
|
|
wxZIP_METHOD_BZIP2 = 12,
|
|
|
|
wxZIP_METHOD_DEFAULT = 0xffff
|
|
|
|
};
|
|
|
|
|
|
|
|
// Originating File-System.
|
2006-10-30 11:56:12 +00:00
|
|
|
//
|
2004-11-10 23:58:38 +00:00
|
|
|
// These are Pkware's values. Note that Info-zip disagree on some of them,
|
|
|
|
// most notably NTFS.
|
|
|
|
//
|
|
|
|
enum wxZipSystem
|
|
|
|
{
|
|
|
|
wxZIP_SYSTEM_MSDOS,
|
|
|
|
wxZIP_SYSTEM_AMIGA,
|
|
|
|
wxZIP_SYSTEM_OPENVMS,
|
|
|
|
wxZIP_SYSTEM_UNIX,
|
|
|
|
wxZIP_SYSTEM_VM_CMS,
|
|
|
|
wxZIP_SYSTEM_ATARI_ST,
|
|
|
|
wxZIP_SYSTEM_OS2_HPFS,
|
|
|
|
wxZIP_SYSTEM_MACINTOSH,
|
|
|
|
wxZIP_SYSTEM_Z_SYSTEM,
|
|
|
|
wxZIP_SYSTEM_CPM,
|
|
|
|
wxZIP_SYSTEM_WINDOWS_NTFS,
|
|
|
|
wxZIP_SYSTEM_MVS,
|
|
|
|
wxZIP_SYSTEM_VSE,
|
|
|
|
wxZIP_SYSTEM_ACORN_RISC,
|
|
|
|
wxZIP_SYSTEM_VFAT,
|
|
|
|
wxZIP_SYSTEM_ALTERNATE_MVS,
|
|
|
|
wxZIP_SYSTEM_BEOS,
|
|
|
|
wxZIP_SYSTEM_TANDEM,
|
|
|
|
wxZIP_SYSTEM_OS_400
|
|
|
|
};
|
|
|
|
|
|
|
|
// Dos/Win file attributes
|
|
|
|
//
|
|
|
|
enum wxZipAttributes
|
|
|
|
{
|
|
|
|
wxZIP_A_RDONLY = 0x01,
|
|
|
|
wxZIP_A_HIDDEN = 0x02,
|
|
|
|
wxZIP_A_SYSTEM = 0x04,
|
|
|
|
wxZIP_A_SUBDIR = 0x10,
|
|
|
|
wxZIP_A_ARCH = 0x20,
|
|
|
|
|
|
|
|
wxZIP_A_MASK = 0x37
|
|
|
|
};
|
|
|
|
|
|
|
|
// Values for the flags field in the zip headers
|
|
|
|
//
|
|
|
|
enum wxZipFlags
|
|
|
|
{
|
|
|
|
wxZIP_ENCRYPTED = 0x0001,
|
|
|
|
wxZIP_DEFLATE_NORMAL = 0x0000, // normal compression
|
|
|
|
wxZIP_DEFLATE_EXTRA = 0x0002, // extra compression
|
|
|
|
wxZIP_DEFLATE_FAST = 0x0004, // fast compression
|
|
|
|
wxZIP_DEFLATE_SUPERFAST = 0x0006, // superfast compression
|
|
|
|
wxZIP_DEFLATE_MASK = 0x0006,
|
|
|
|
wxZIP_SUMS_FOLLOW = 0x0008, // crc and sizes come after the data
|
|
|
|
wxZIP_ENHANCED = 0x0010,
|
|
|
|
wxZIP_PATCH = 0x0020,
|
|
|
|
wxZIP_STRONG_ENC = 0x0040,
|
|
|
|
wxZIP_UNUSED = 0x0F80,
|
|
|
|
wxZIP_RESERVED = 0xF000
|
|
|
|
};
|
|
|
|
|
|
|
|
// Forward decls
|
|
|
|
//
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxZipEntry;
|
|
|
|
class WXDLLIMPEXP_FWD_BASE wxZipInputStream;
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// wxZipNotifier
|
1999-07-07 22:04:58 +00:00
|
|
|
|
2004-11-10 23:58:38 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxZipNotifier
|
1999-07-07 22:04:58 +00:00
|
|
|
{
|
2000-07-15 19:51:35 +00:00
|
|
|
public:
|
2004-11-10 23:58:38 +00:00
|
|
|
virtual ~wxZipNotifier() { }
|
|
|
|
|
|
|
|
virtual void OnEntryUpdated(wxZipEntry& entry) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Zip Entry - holds the meta data for a file in the zip
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxZipEntry : public wxArchiveEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxZipEntry(const wxString& name = wxEmptyString,
|
|
|
|
const wxDateTime& dt = wxDateTime::Now(),
|
|
|
|
wxFileOffset size = wxInvalidOffset);
|
|
|
|
virtual ~wxZipEntry();
|
|
|
|
|
|
|
|
wxZipEntry(const wxZipEntry& entry);
|
|
|
|
wxZipEntry& operator=(const wxZipEntry& entry);
|
|
|
|
|
|
|
|
// Get accessors
|
|
|
|
wxDateTime GetDateTime() const { return m_DateTime; }
|
|
|
|
wxFileOffset GetSize() const { return m_Size; }
|
|
|
|
wxFileOffset GetOffset() const { return m_Offset; }
|
|
|
|
wxString GetInternalName() const { return m_Name; }
|
|
|
|
int GetMethod() const { return m_Method; }
|
|
|
|
int GetFlags() const { return m_Flags; }
|
|
|
|
wxUint32 GetCrc() const { return m_Crc; }
|
|
|
|
wxFileOffset GetCompressedSize() const { return m_CompressedSize; }
|
|
|
|
int GetSystemMadeBy() const { return m_SystemMadeBy; }
|
|
|
|
wxString GetComment() const { return m_Comment; }
|
|
|
|
wxUint32 GetExternalAttributes() const { return m_ExternalAttributes; }
|
|
|
|
wxPathFormat GetInternalFormat() const { return wxPATH_UNIX; }
|
|
|
|
int GetMode() const;
|
|
|
|
const char *GetLocalExtra() const;
|
|
|
|
size_t GetLocalExtraLen() const;
|
|
|
|
const char *GetExtra() const;
|
|
|
|
size_t GetExtraLen() const;
|
|
|
|
wxString GetName(wxPathFormat format = wxPATH_NATIVE) const;
|
|
|
|
|
|
|
|
// is accessors
|
|
|
|
inline bool IsDir() const;
|
|
|
|
inline bool IsText() const;
|
|
|
|
inline bool IsReadOnly() const;
|
|
|
|
inline bool IsMadeByUnix() const;
|
|
|
|
|
|
|
|
// set accessors
|
|
|
|
void SetDateTime(const wxDateTime& dt) { m_DateTime = dt; }
|
|
|
|
void SetSize(wxFileOffset size) { m_Size = size; }
|
2004-11-12 14:23:02 +00:00
|
|
|
void SetMethod(int method) { m_Method = (wxUint16)method; }
|
2004-11-10 23:58:38 +00:00
|
|
|
void SetComment(const wxString& comment) { m_Comment = comment; }
|
|
|
|
void SetExternalAttributes(wxUint32 attr ) { m_ExternalAttributes = attr; }
|
|
|
|
void SetSystemMadeBy(int system);
|
|
|
|
void SetMode(int mode);
|
|
|
|
void SetExtra(const char *extra, size_t len);
|
|
|
|
void SetLocalExtra(const char *extra, size_t len);
|
|
|
|
|
|
|
|
inline void SetName(const wxString& name,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE);
|
|
|
|
|
|
|
|
static wxString GetInternalName(const wxString& name,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE,
|
|
|
|
bool *pIsDir = NULL);
|
|
|
|
|
|
|
|
// set is accessors
|
|
|
|
void SetIsDir(bool isDir = true);
|
|
|
|
inline void SetIsReadOnly(bool isReadOnly = true);
|
|
|
|
inline void SetIsText(bool isText = true);
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2004-11-10 23:58:38 +00:00
|
|
|
wxZipEntry *Clone() const { return ZipClone(); }
|
|
|
|
|
|
|
|
void SetNotifier(wxZipNotifier& notifier);
|
|
|
|
void UnsetNotifier();
|
2000-07-15 19:51:35 +00:00
|
|
|
|
|
|
|
protected:
|
2004-11-10 23:58:38 +00:00
|
|
|
// Internal attributes
|
|
|
|
enum { TEXT_ATTR = 1 };
|
|
|
|
|
|
|
|
// protected Get accessors
|
|
|
|
int GetVersionNeeded() const { return m_VersionNeeded; }
|
|
|
|
wxFileOffset GetKey() const { return m_Key; }
|
|
|
|
int GetVersionMadeBy() const { return m_VersionMadeBy; }
|
|
|
|
int GetDiskStart() const { return m_DiskStart; }
|
|
|
|
int GetInternalAttributes() const { return m_InternalAttributes; }
|
|
|
|
|
2004-11-12 14:23:02 +00:00
|
|
|
void SetVersionNeeded(int version) { m_VersionNeeded = (wxUint16)version; }
|
2004-11-10 23:58:38 +00:00
|
|
|
void SetOffset(wxFileOffset offset) { m_Offset = offset; }
|
2004-11-12 14:23:02 +00:00
|
|
|
void SetFlags(int flags) { m_Flags = (wxUint16)flags; }
|
|
|
|
void SetVersionMadeBy(int version) { m_VersionMadeBy = (wxUint8)version; }
|
2004-11-10 23:58:38 +00:00
|
|
|
void SetCrc(wxUint32 crc) { m_Crc = crc; }
|
|
|
|
void SetCompressedSize(wxFileOffset size) { m_CompressedSize = size; }
|
|
|
|
void SetKey(wxFileOffset offset) { m_Key = offset; }
|
2004-11-12 14:23:02 +00:00
|
|
|
void SetDiskStart(int start) { m_DiskStart = (wxUint16)start; }
|
|
|
|
void SetInternalAttributes(int attr) { m_InternalAttributes = (wxUint16)attr; }
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
virtual wxZipEntry *ZipClone() const { return new wxZipEntry(*this); }
|
|
|
|
|
|
|
|
void Notify();
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2006-12-09 22:28:11 +00:00
|
|
|
private:
|
2004-11-10 23:58:38 +00:00
|
|
|
wxArchiveEntry* DoClone() const { return ZipClone(); }
|
|
|
|
|
|
|
|
size_t ReadLocal(wxInputStream& stream, wxMBConv& conv);
|
|
|
|
size_t WriteLocal(wxOutputStream& stream, wxMBConv& conv) const;
|
|
|
|
|
|
|
|
size_t ReadCentral(wxInputStream& stream, wxMBConv& conv);
|
|
|
|
size_t WriteCentral(wxOutputStream& stream, wxMBConv& conv) const;
|
|
|
|
|
|
|
|
size_t ReadDescriptor(wxInputStream& stream);
|
|
|
|
size_t WriteDescriptor(wxOutputStream& stream, wxUint32 crc,
|
|
|
|
wxFileOffset compressedSize, wxFileOffset size);
|
|
|
|
|
|
|
|
wxUint8 m_SystemMadeBy; // one of enum wxZipSystem
|
|
|
|
wxUint8 m_VersionMadeBy; // major * 10 + minor
|
|
|
|
|
|
|
|
wxUint16 m_VersionNeeded; // ver needed to extract (20 i.e. v2.0)
|
|
|
|
wxUint16 m_Flags;
|
|
|
|
wxUint16 m_Method; // compression method (one of wxZipMethod)
|
|
|
|
wxDateTime m_DateTime;
|
|
|
|
wxUint32 m_Crc;
|
|
|
|
wxFileOffset m_CompressedSize;
|
2004-11-10 21:10:30 +00:00
|
|
|
wxFileOffset m_Size;
|
2004-11-10 23:58:38 +00:00
|
|
|
wxString m_Name; // in internal format
|
|
|
|
wxFileOffset m_Key; // the original offset for copied entries
|
|
|
|
wxFileOffset m_Offset; // file offset of the entry
|
|
|
|
|
|
|
|
wxString m_Comment;
|
|
|
|
wxUint16 m_DiskStart; // for multidisk archives, not unsupported
|
|
|
|
wxUint16 m_InternalAttributes; // bit 0 set for text files
|
|
|
|
wxUint32 m_ExternalAttributes; // system specific depends on SystemMadeBy
|
|
|
|
|
|
|
|
class wxZipMemory *m_Extra;
|
|
|
|
class wxZipMemory *m_LocalExtra;
|
|
|
|
|
|
|
|
wxZipNotifier *m_zipnotifier;
|
|
|
|
class wxZipWeakLinks *m_backlink;
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2004-11-10 23:58:38 +00:00
|
|
|
friend class wxZipInputStream;
|
|
|
|
friend class wxZipOutputStream;
|
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxZipEntry)
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-10-30 11:56:12 +00:00
|
|
|
// wxZipOutputStream
|
2004-11-10 23:58:38 +00:00
|
|
|
|
2006-10-27 09:54:39 +00:00
|
|
|
WX_DECLARE_LIST_WITH_DECL(wxZipEntry, wxZipEntryList_, class WXDLLIMPEXP_BASE);
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxZipOutputStream : public wxArchiveOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxZipOutputStream(wxOutputStream& stream,
|
|
|
|
int level = -1,
|
|
|
|
wxMBConv& conv = wxConvLocal);
|
2006-10-27 09:54:39 +00:00
|
|
|
wxZipOutputStream(wxOutputStream *stream,
|
|
|
|
int level = -1,
|
|
|
|
wxMBConv& conv = wxConvLocal);
|
2005-04-11 23:26:44 +00:00
|
|
|
virtual WXZIPFIX ~wxZipOutputStream();
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
bool PutNextEntry(wxZipEntry *entry) { return DoCreate(entry); }
|
|
|
|
|
2005-04-11 23:26:44 +00:00
|
|
|
bool WXZIPFIX PutNextEntry(const wxString& name,
|
|
|
|
const wxDateTime& dt = wxDateTime::Now(),
|
|
|
|
wxFileOffset size = wxInvalidOffset);
|
2004-11-10 23:58:38 +00:00
|
|
|
|
2005-04-11 23:26:44 +00:00
|
|
|
bool WXZIPFIX PutNextDirEntry(const wxString& name,
|
|
|
|
const wxDateTime& dt = wxDateTime::Now());
|
2004-11-10 23:58:38 +00:00
|
|
|
|
2005-04-11 23:26:44 +00:00
|
|
|
bool WXZIPFIX CopyEntry(wxZipEntry *entry, wxZipInputStream& inputStream);
|
|
|
|
bool WXZIPFIX CopyArchiveMetaData(wxZipInputStream& inputStream);
|
2004-11-10 23:58:38 +00:00
|
|
|
|
2005-04-11 23:26:44 +00:00
|
|
|
void WXZIPFIX Sync();
|
|
|
|
bool WXZIPFIX CloseEntry();
|
|
|
|
bool WXZIPFIX Close();
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
void SetComment(const wxString& comment) { m_Comment = comment; }
|
|
|
|
|
|
|
|
int GetLevel() const { return m_level; }
|
2005-04-11 23:26:44 +00:00
|
|
|
void WXZIPFIX SetLevel(int level);
|
2006-10-30 11:56:12 +00:00
|
|
|
|
2004-11-10 23:58:38 +00:00
|
|
|
protected:
|
2005-04-11 23:26:44 +00:00
|
|
|
virtual size_t WXZIPFIX OnSysWrite(const void *buffer, size_t size);
|
2004-11-10 23:58:38 +00:00
|
|
|
virtual wxFileOffset OnSysTell() const { return m_entrySize; }
|
|
|
|
|
2005-04-11 23:26:44 +00:00
|
|
|
// this protected interface isn't yet finalised
|
2004-11-10 23:58:38 +00:00
|
|
|
struct Buffer { const char *m_data; size_t m_size; };
|
2005-04-11 23:26:44 +00:00
|
|
|
virtual wxOutputStream* WXZIPFIX OpenCompressor(wxOutputStream& stream,
|
|
|
|
wxZipEntry& entry,
|
|
|
|
const Buffer bufs[]);
|
|
|
|
virtual bool WXZIPFIX CloseCompressor(wxOutputStream *comp);
|
2004-11-10 23:58:38 +00:00
|
|
|
|
2005-04-11 23:26:44 +00:00
|
|
|
bool IsParentSeekable() const
|
|
|
|
{ return m_offsetAdjustment != wxInvalidOffset; }
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
private:
|
2006-10-27 09:54:39 +00:00
|
|
|
void Init(int level);
|
|
|
|
|
2006-12-09 22:28:11 +00:00
|
|
|
bool WXZIPFIX PutNextEntry(wxArchiveEntry *entry);
|
|
|
|
bool WXZIPFIX CopyEntry(wxArchiveEntry *entry, wxArchiveInputStream& stream);
|
|
|
|
bool WXZIPFIX CopyArchiveMetaData(wxArchiveInputStream& stream);
|
|
|
|
|
2005-04-11 23:26:44 +00:00
|
|
|
bool IsOpened() const { return m_comp || m_pending; }
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
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;
|
2006-10-27 09:54:39 +00:00
|
|
|
wxZipEntryList_ m_entries;
|
2004-11-10 23:58:38 +00:00
|
|
|
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;
|
2008-01-03 17:09:10 +00:00
|
|
|
bool m_endrecWritten;
|
2004-11-10 23:58:38 +00:00
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxZipOutputStream);
|
2004-11-10 23:58:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-10-30 11:56:12 +00:00
|
|
|
// wxZipInputStream
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxZipInputStream : public wxArchiveInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef wxZipEntry entry_type;
|
|
|
|
|
|
|
|
wxZipInputStream(wxInputStream& stream, wxMBConv& conv = wxConvLocal);
|
2006-10-27 09:54:39 +00:00
|
|
|
wxZipInputStream(wxInputStream *stream, wxMBConv& conv = wxConvLocal);
|
2005-04-06 20:32:28 +00:00
|
|
|
|
2006-10-27 09:54:39 +00:00
|
|
|
#if WXWIN_COMPATIBILITY_2_6 && wxUSE_FFILE
|
2005-04-11 23:26:44 +00:00
|
|
|
wxZipInputStream(const wxString& archive, const wxString& file)
|
|
|
|
: wxArchiveInputStream(OpenFile(archive), wxConvLocal) { Init(file); }
|
2005-04-06 20:32:28 +00:00
|
|
|
#endif
|
|
|
|
|
2005-04-11 23:26:44 +00:00
|
|
|
virtual WXZIPFIX ~wxZipInputStream();
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
bool OpenEntry(wxZipEntry& entry) { return DoOpen(&entry); }
|
2005-04-11 23:26:44 +00:00
|
|
|
bool WXZIPFIX CloseEntry();
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
wxZipEntry *GetNextEntry();
|
|
|
|
|
2005-04-11 23:26:44 +00:00
|
|
|
wxString WXZIPFIX GetComment();
|
|
|
|
int WXZIPFIX GetTotalEntries();
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
virtual wxFileOffset GetLength() const { return m_entry.GetSize(); }
|
|
|
|
|
|
|
|
protected:
|
2005-04-11 23:26:44 +00:00
|
|
|
size_t WXZIPFIX OnSysRead(void *buffer, size_t size);
|
2004-11-10 23:58:38 +00:00
|
|
|
wxFileOffset OnSysTell() const { return m_decomp ? m_decomp->TellI() : 0; }
|
2005-04-06 20:32:28 +00:00
|
|
|
|
2006-11-19 22:04:53 +00:00
|
|
|
#if WXWIN_COMPATIBILITY_2_6
|
2005-04-11 23:26:44 +00:00
|
|
|
wxFileOffset WXZIPFIX OnSysSeek(wxFileOffset seek, wxSeekMode mode);
|
2005-04-06 20:32:28 +00:00
|
|
|
#endif
|
2004-11-10 23:58:38 +00:00
|
|
|
|
2005-04-06 20:32:28 +00:00
|
|
|
// this protected interface isn't yet finalised
|
2005-04-11 23:26:44 +00:00
|
|
|
virtual wxInputStream* WXZIPFIX OpenDecompressor(wxInputStream& stream);
|
|
|
|
virtual bool WXZIPFIX CloseDecompressor(wxInputStream *decomp);
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void Init();
|
2005-04-11 23:26:44 +00:00
|
|
|
void Init(const wxString& file);
|
2006-10-27 09:54:39 +00:00
|
|
|
#if WXWIN_COMPATIBILITY_2_6 && wxUSE_FFILE
|
|
|
|
static wxInputStream *OpenFile(const wxString& archive);
|
|
|
|
#endif
|
2004-11-10 23:58:38 +00:00
|
|
|
|
2006-12-09 22:28:11 +00:00
|
|
|
wxArchiveEntry *DoGetNextEntry() { return GetNextEntry(); }
|
|
|
|
|
|
|
|
bool WXZIPFIX OpenEntry(wxArchiveEntry& entry);
|
|
|
|
|
2004-11-10 23:58:38 +00:00
|
|
|
wxStreamError ReadLocal(bool readEndRec = false);
|
|
|
|
wxStreamError ReadCentral();
|
|
|
|
|
|
|
|
wxUint32 ReadSignature();
|
|
|
|
bool FindEndRecord();
|
|
|
|
bool LoadEndRecord();
|
2006-10-30 11:56:12 +00:00
|
|
|
|
2004-11-10 23:58:38 +00:00
|
|
|
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;
|
|
|
|
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);
|
2003-01-02 23:38:11 +00:00
|
|
|
|
2006-11-19 02:11:40 +00:00
|
|
|
#if WXWIN_COMPATIBILITY_2_6
|
2005-04-06 20:32:28 +00:00
|
|
|
bool m_allowSeeking;
|
2006-11-19 02:11:40 +00:00
|
|
|
friend class wxArchiveFSHandler;
|
2005-04-06 20:32:28 +00:00
|
|
|
#endif
|
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxZipInputStream);
|
1999-07-07 22:04:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-02-10 13:54:41 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Iterators
|
|
|
|
|
|
|
|
#if wxUSE_STL || defined WX_TEST_ARCHIVE_ITERATOR
|
|
|
|
typedef wxArchiveIterator<wxZipInputStream> wxZipIter;
|
|
|
|
typedef wxArchiveIterator<wxZipInputStream,
|
|
|
|
std::pair<wxString, wxZipEntry*> > wxZipPairIter;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-11-10 23:58:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// wxZipClassFactory
|
1999-07-07 22:04:58 +00:00
|
|
|
|
2004-11-10 23:58:38 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxZipClassFactory : public wxArchiveClassFactory
|
|
|
|
{
|
|
|
|
public:
|
2005-02-10 13:54:41 +00:00
|
|
|
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
|
|
|
|
|
2006-10-27 09:54:39 +00:00
|
|
|
wxZipClassFactory();
|
|
|
|
|
2004-11-10 23:58:38 +00:00
|
|
|
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()); }
|
2006-10-27 09:54:39 +00:00
|
|
|
wxZipInputStream *NewStream(wxInputStream *stream) const
|
|
|
|
{ return new wxZipInputStream(stream, GetConv()); }
|
|
|
|
wxZipOutputStream *NewStream(wxOutputStream *stream) const
|
|
|
|
{ return new wxZipOutputStream(stream, -1, GetConv()); }
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
wxString GetInternalName(const wxString& name,
|
|
|
|
wxPathFormat format = wxPATH_NATIVE) const
|
|
|
|
{ return wxZipEntry::GetInternalName(name, format); }
|
|
|
|
|
2006-10-27 09:54:39 +00:00
|
|
|
const wxChar * const *GetProtocols(wxStreamProtocolType type
|
|
|
|
= wxSTREAM_PROTOCOL) const;
|
|
|
|
|
2004-11-10 23:58:38 +00:00
|
|
|
protected:
|
|
|
|
wxArchiveEntry *DoNewEntry() const
|
|
|
|
{ return NewEntry(); }
|
|
|
|
wxArchiveInputStream *DoNewStream(wxInputStream& stream) const
|
|
|
|
{ return NewStream(stream); }
|
|
|
|
wxArchiveOutputStream *DoNewStream(wxOutputStream& stream) const
|
|
|
|
{ return NewStream(stream); }
|
2006-10-27 09:54:39 +00:00
|
|
|
wxArchiveInputStream *DoNewStream(wxInputStream *stream) const
|
|
|
|
{ return NewStream(stream); }
|
|
|
|
wxArchiveOutputStream *DoNewStream(wxOutputStream *stream) const
|
|
|
|
{ return NewStream(stream); }
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxZipClassFactory)
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// wxZipEntry inlines
|
|
|
|
|
2004-11-25 20:37:44 +00:00
|
|
|
inline bool wxZipEntry::IsText() const
|
2004-11-10 23:58:38 +00:00
|
|
|
{
|
|
|
|
return (m_InternalAttributes & TEXT_ATTR) != 0;
|
|
|
|
}
|
|
|
|
|
2004-11-25 20:37:44 +00:00
|
|
|
inline bool wxZipEntry::IsDir() const
|
2004-11-10 23:58:38 +00:00
|
|
|
{
|
|
|
|
return (m_ExternalAttributes & wxZIP_A_SUBDIR) != 0;
|
|
|
|
}
|
|
|
|
|
2004-11-25 20:37:44 +00:00
|
|
|
inline bool wxZipEntry::IsReadOnly() const
|
2004-11-10 23:58:38 +00:00
|
|
|
{
|
|
|
|
return (m_ExternalAttributes & wxZIP_A_RDONLY) != 0;
|
|
|
|
}
|
|
|
|
|
2004-11-25 20:37:44 +00:00
|
|
|
inline bool wxZipEntry::IsMadeByUnix() const
|
2004-11-10 23:58:38 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2004-11-25 20:37:44 +00:00
|
|
|
inline void wxZipEntry::SetIsText(bool isText)
|
2004-11-10 23:58:38 +00:00
|
|
|
{
|
|
|
|
if (isText)
|
|
|
|
m_InternalAttributes |= TEXT_ATTR;
|
|
|
|
else
|
|
|
|
m_InternalAttributes &= ~TEXT_ATTR;
|
|
|
|
}
|
|
|
|
|
2004-11-25 20:37:44 +00:00
|
|
|
inline void wxZipEntry::SetIsReadOnly(bool isReadOnly)
|
2004-11-10 23:58:38 +00:00
|
|
|
{
|
|
|
|
if (isReadOnly)
|
|
|
|
SetMode(GetMode() & ~0222);
|
|
|
|
else
|
|
|
|
SetMode(GetMode() | 0200);
|
|
|
|
}
|
|
|
|
|
2004-11-25 20:37:44 +00:00
|
|
|
inline void wxZipEntry::SetName(const wxString& name,
|
|
|
|
wxPathFormat format /*=wxPATH_NATIVE*/)
|
2004-11-10 23:58:38 +00:00
|
|
|
{
|
|
|
|
bool isDir;
|
|
|
|
m_Name = GetInternalName(name, format, &isDir);
|
|
|
|
SetIsDir(isDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-27 22:03:29 +00:00
|
|
|
#endif // wxUSE_ZIPSTREAM
|
2004-11-10 23:58:38 +00:00
|
|
|
|
|
|
|
#endif // _WX_WXZIPSTREAM_H__
|