OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreZip.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __Zip_H__
29 #define __Zip_H__
30 
31 #include "OgrePrerequisites.h"
32 
33 #include "OgreArchive.h"
34 #include "OgreArchiveFactory.h"
35 #include "OgreHeaderPrefix.h"
36 
37 // Forward declaration for zziplib to avoid header file dependency.
38 typedef struct zzip_dir ZZIP_DIR;
39 typedef struct zzip_file ZZIP_FILE;
40 typedef union _zzip_plugin_io zzip_plugin_io_handlers;
41 
42 namespace Ogre {
43 
56  class _OgreExport ZipArchive : public Archive
57  {
58  protected:
62  void checkZzipError(int zzipError, const String& operation) const;
67 
69  public:
70  ZipArchive(const String& name, const String& archType, zzip_plugin_io_handlers* pluginIo = NULL);
71  ~ZipArchive();
73  bool isCaseSensitive(void) const { return false; }
74 
76  void load();
78  void unload();
79 
81  DataStreamPtr open(const String& filename, bool readOnly = true) const;
82 
84  DataStreamPtr create(const String& filename) const;
85 
87  void remove(const String& filename) const;
88 
90  StringVectorPtr list(bool recursive = true, bool dirs = false);
91 
93  FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false);
94 
96  StringVectorPtr find(const String& pattern, bool recursive = true,
97  bool dirs = false);
98 
100  FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true,
101  bool dirs = false) const;
102 
104  bool exists(const String& filename);
105 
107  time_t getModifiedTime(const String& filename);
108  };
109 
112  {
113  public:
114  virtual ~ZipArchiveFactory() {}
116  const String& getType(void) const;
118  Archive *createInstance( const String& name, bool readOnly )
119  {
120  if(!readOnly)
121  return NULL;
122 
123  return OGRE_NEW ZipArchive(name, "Zip");
124  }
126  void destroyInstance( Archive* ptr) { OGRE_DELETE ptr; }
127  };
128 
131  {
132  protected:
135  public:
137  virtual ~EmbeddedZipArchiveFactory();
139  const String& getType(void) const;
141  Archive *createInstance( const String& name, bool readOnly )
142  {
143  ZipArchive * resZipArchive = OGRE_NEW ZipArchive(name, "EmbeddedZip", mPluginIo);
144  return resZipArchive;
145  }
146 
153  typedef bool (*DecryptEmbeddedZipFileFunc)(size_t pos, void* buf, size_t len);
154 
156  static void addEmbbeddedFile(const String& name, const uint8 * fileData,
157  size_t fileSize, DecryptEmbeddedZipFileFunc decryptFunc);
158 
160  static void removeEmbbeddedFile(const String& name);
161 
162  };
163 
166  {
167  protected:
171  public:
173  ZipDataStream(ZZIP_FILE* zzipFile, size_t uncompressedSize);
175  ZipDataStream(const String& name, ZZIP_FILE* zzipFile, size_t uncompressedSize);
176  ~ZipDataStream();
178  size_t read(void* buf, size_t count);
180  size_t write(void* buf, size_t count);
182  void skip(long count);
184  void seek( size_t pos );
186  size_t tell(void) const;
188  bool eof(void) const;
190  void close(void);
191 
192 
193  };
194 
198 }
199 
200 #include "OgreHeaderSuffix.h"
201 
202 #endif
unsigned char uint8
Definition: OgrePlatform.h:422
ZZIP_FILE * mZzipFile
Definition: OgreZip.h:168
ZZIP_DIR * mZzipDir
Handle to root zip file.
Definition: OgreZip.h:60
#define _OgreExport
Definition: OgrePlatform.h:255
zzip_plugin_io_handlers * mPluginIo
A pointer to file io alternative implementation.
Definition: OgreZip.h:66
struct zzip_dir ZZIP_DIR
Definition: OgreZip.h:38
Archive * createInstance(const String &name, bool readOnly)
Creates a new object.
Definition: OgreZip.h:141
Specialisation of the Archive class to allow reading of files from a zip format source archive...
Definition: OgreZip.h:56
#define _OgrePrivate
Definition: OgrePlatform.h:256
#define OGRE_DELETE
void destroyInstance(Archive *ptr)
Destroys an object which was created by this factory.
Definition: OgreZip.h:126
Archive * createInstance(const String &name, bool readOnly)
Creates a new object.
Definition: OgreZip.h:118
Specialisation of ZipArchiveFactory for embedded Zip files.
Definition: OgreZip.h:130
Specialisation of ArchiveFactory for Zip files.
Definition: OgreZip.h:111
union _zzip_plugin_io zzip_plugin_io_handlers
Definition: OgreZip.h:40
Abstract factory class, archive codec plugins can register concrete subclasses of this...
FileInfoList mFileList
File list (since zziplib seems to only allow scanning of dir tree once)
Definition: OgreZip.h:64
struct zzip_file ZZIP_FILE
Definition: OgreZip.h:39
vector< FileInfo >::type FileInfoList
Definition: OgreArchive.h:67
#define OGRE_NEW
static zzip_plugin_io_handlers * mPluginIo
A static pointer to file io alternative implementation for the embedded files.
Definition: OgreZip.h:134
Archive-handling class.
Definition: OgreArchive.h:86
General purpose class used for encapsulating the reading and writing of data.
_StringBase String
Definition: OgreCommon.h:53
Specialisation of DataStream to handle streaming data from zip archives.
Definition: OgreZip.h:165
StaticCache< 2 *OGRE_STREAM_TEMP_SIZE > mCache
We need caching because sometimes serializers step back in data stream and zziplib behaves slow...
Definition: OgreZip.h:170
virtual ~ZipArchiveFactory()
Definition: OgreZip.h:114
bool isCaseSensitive(void) const
Returns whether this archive is case sensitive in the way it matches files.
Definition: OgreZip.h:73