From 04366df3bca16d4e0cbe254551e44427ae6338bb Mon Sep 17 00:00:00 2001 From: Fridrich Štrba Date: Mon, 19 Mar 2012 15:09:34 +0100 Subject: Simple Zip file-format implementation to avoid the need of minizip --- shell/inc/internal/basereader.hxx | 2 +- shell/inc/internal/contentreader.hxx | 3 ++- shell/inc/internal/metainforeader.hxx | 2 +- shell/inc/internal/stream_helper.hxx | 24 +++++++++++++++++++++++- shell/inc/internal/types.hxx | 17 +++++++++-------- shell/inc/internal/zipfile.hxx | 29 +++++++++++++++++------------ 6 files changed, 53 insertions(+), 24 deletions(-) (limited to 'shell/inc') diff --git a/shell/inc/internal/basereader.hxx b/shell/inc/internal/basereader.hxx index bb5c27645e2a..7a154103e44c 100644 --- a/shell/inc/internal/basereader.hxx +++ b/shell/inc/internal/basereader.hxx @@ -46,7 +46,7 @@ public: protected: // protected because its only an implementation relevant class CBaseReader( const std::string& DocumentName ); - CBaseReader( void* stream, zlib_filefunc_def* fa ); + CBaseReader( StreamInterface *stream ); virtual void start_document(); diff --git a/shell/inc/internal/contentreader.hxx b/shell/inc/internal/contentreader.hxx index 6a7dc594af60..e55a76035b90 100644 --- a/shell/inc/internal/contentreader.hxx +++ b/shell/inc/internal/contentreader.hxx @@ -32,6 +32,7 @@ #include "internal/basereader.hxx" class ITag; +class StreamInterface; class CContentReader : public CBaseReader { @@ -40,7 +41,7 @@ public: CContentReader( const std::string& DocumentName, LocaleSet_t const & DocumentLocale ); - CContentReader( void* stream, LocaleSet_t const & DocumentLocale, zlib_filefunc_def* fa ); + CContentReader( StreamInterface* stream, LocaleSet_t const & DocumentLocale ); /** Get the chunkbuffer. diff --git a/shell/inc/internal/metainforeader.hxx b/shell/inc/internal/metainforeader.hxx index 516224571078..a0ed7d9584c1 100644 --- a/shell/inc/internal/metainforeader.hxx +++ b/shell/inc/internal/metainforeader.hxx @@ -44,7 +44,7 @@ public: CMetaInfoReader( const std::string& DocumentName ); - CMetaInfoReader( void* stream, zlib_filefunc_def* fa); + CMetaInfoReader( StreamInterface* stream ); /** check if the Tag is in the target meta.xml file. diff --git a/shell/inc/internal/stream_helper.hxx b/shell/inc/internal/stream_helper.hxx index bd31ee111315..72eaf7355b2c 100644 --- a/shell/inc/internal/stream_helper.hxx +++ b/shell/inc/internal/stream_helper.hxx @@ -31,7 +31,29 @@ #include "internal/types.hxx" -IStream* PrepareIStream( IStream* pStream, zlib_filefunc_def &zFileFunc ); +class BufferStream : public StreamInterface +{ +public: + BufferStream(IStream *str); + ~BufferStream(); + unsigned long sread (unsigned char *vuf, unsigned long size); + long stell (); + long sseek (unsigned long offset, int origin); +private: + IStream *stream; +}; + +class FileStream : public StreamInterface +{ +public: + FileStream(const char *filename); + ~FileStream(); + unsigned long sread (unsigned char *buf, unsigned long size); + long stell (); + long sseek (unsigned long offset, int origin); +private: + FILE *file; +}; #endif diff --git a/shell/inc/internal/types.hxx b/shell/inc/internal/types.hxx index 0c6810aec0d0..c6fbfac5e50c 100644 --- a/shell/inc/internal/types.hxx +++ b/shell/inc/internal/types.hxx @@ -35,14 +35,6 @@ #include #include -#if defined SYSTEM_ZLIB -#include -#include -#else -#include -#include -#endif - typedef std::vector StringList_t; //+------------------------------------------------------------------------- @@ -89,6 +81,15 @@ typedef ::std::map StyleLocaleMap_t; const StyleLocalePair_t EMPTY_STYLELOCALE_PAIR = ::std::make_pair(::std::wstring(), EMPTY_LOCALE ); +class StreamInterface +{ +public: + virtual ~StreamInterface() {} + virtual unsigned long sread (unsigned char* vuf, unsigned long size) = 0; + virtual long stell () = 0; + virtual long sseek (unsigned long offset, int origin) = 0; +}; + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/inc/internal/zipfile.hxx b/shell/inc/internal/zipfile.hxx index 062ce38cf1af..24fba6542fcf 100644 --- a/shell/inc/internal/zipfile.hxx +++ b/shell/inc/internal/zipfile.hxx @@ -33,16 +33,19 @@ #define _WINDOWS #endif -#if defined SYSTEM_ZLIB -#include +#ifdef SYSTEM_ZLIB +#include #else -#include +#include #endif #include #include #include +class StreamInterface; +class ZipFilePrivate; + /** A simple zip content provider based on the zlib */ @@ -69,9 +72,9 @@ public: IOException if the specified file doesn't exist AccessViolationException if read access to the file is denied */ - static bool IsZipFile(const std::string& FileName); + static bool IsZipFile(const std::string &FileName); - static bool IsZipFile(void* stream); + static bool IsZipFile(void *stream); /** Returns wheter the version of the specified zip file may be uncompressed with the @@ -89,9 +92,9 @@ public: IOException if the specified file doesn't exist or is no zip file AccessViolationException if read access to the file is denied */ - static bool IsValidZipFileVersionNumber(const std::string& FileName); + static bool IsValidZipFileVersionNumber(const std::string &FileName); - static bool IsValidZipFileVersionNumber(void* stream); + static bool IsValidZipFileVersionNumber(void *stream); public: @@ -107,9 +110,9 @@ public: WrongZipVersionException if the zip file cannot be uncompressed with the used zlib version */ - ZipFile(const std::string& FileName); + ZipFile(const std::string &FileName); - ZipFile(void* stream, zlib_filefunc_def* fa); + ZipFile(StreamInterface *stream); /** Destroys a zip file @@ -134,7 +137,7 @@ public: ZipContentMissException if the specified zip content does not exist in this zip file */ - void GetUncompressedContent(const std::string& ContentName, /*inout*/ ZipContentBuffer_t& ContentBuffer); + void GetUncompressedContent(const std::string &ContentName, /*inout*/ ZipContentBuffer_t &ContentBuffer); /** Returns a list with the content names contained within this file @@ -146,7 +149,7 @@ public: iterating over a ZipFileDirectory returned by GetDirectory */ - bool HasContent(const std::string& ContentName) const; + bool HasContent(const std::string &ContentName) const; private: @@ -158,7 +161,9 @@ private: long GetFileLongestFileNameLength() const; private: - unzFile m_uzFile; + StreamInterface *m_pStream; + bool m_bShouldFree; + long m_iStartOffset; }; #endif -- cgit