OGRE  1.9.0
OgreZip.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE 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#if OGRE_THREAD_SUPPORT
37#endif
38#include "OgreHeaderPrefix.h"
39
40// Forward declaration for zziplib to avoid header file dependency.
41typedef struct zzip_dir ZZIP_DIR;
42typedef struct zzip_file ZZIP_FILE;
43typedef union _zzip_plugin_io zzip_plugin_io_handlers;
44
45namespace Ogre {
46
60 {
61 protected:
65 void checkZzipError(int zzipError, const String& operation) const;
70
72 public:
73 ZipArchive(const String& name, const String& archType, zzip_plugin_io_handlers* pluginIo = NULL);
76 bool isCaseSensitive(void) const { return false; }
77
79 void load();
81 void unload();
82
84 DataStreamPtr open(const String& filename, bool readOnly = true) const;
85
87 DataStreamPtr create(const String& filename) const;
88
90 void remove(const String& filename) const;
91
93 StringVectorPtr list(bool recursive = true, bool dirs = false);
94
96 FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false);
97
99 StringVectorPtr find(const String& pattern, bool recursive = true,
100 bool dirs = false);
101
103 FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true,
104 bool dirs = false) const;
105
107 bool exists(const String& filename);
108
110 time_t getModifiedTime(const String& filename);
111 };
112
115 {
116 public:
119 const String& getType(void) const;
121 Archive *createInstance( const String& name, bool readOnly )
122 {
123 if(!readOnly)
124 return NULL;
125
126 return OGRE_NEW ZipArchive(name, "Zip");
127 }
128
130 };
131
134 {
135 protected:
138 public:
142 const String& getType(void) const;
144 Archive *createInstance( const String& name, bool readOnly )
145 {
146 ZipArchive * resZipArchive = OGRE_NEW ZipArchive(name, "EmbeddedZip", mPluginIo);
147 return resZipArchive;
148 }
149
156 typedef bool (*DecryptEmbeddedZipFileFunc)(size_t pos, void* buf, size_t len);
157
159 static void addEmbbeddedFile(const String& name, const uint8 * fileData,
160 size_t fileSize, DecryptEmbeddedZipFileFunc decryptFunc);
161
163 static void removeEmbbeddedFile(const String& name);
164
165 };
166
169 {
170 protected:
174 public:
176 ZipDataStream(ZZIP_FILE* zzipFile, size_t uncompressedSize);
178 ZipDataStream(const String& name, ZZIP_FILE* zzipFile, size_t uncompressedSize);
181 size_t read(void* buf, size_t count);
183 size_t write(void* buf, size_t count);
185 void skip(long count);
187 void seek( size_t pos );
189 size_t tell(void) const;
191 bool eof(void) const;
193 void close(void);
194
195
196 };
197
200
201}
202
203#include "OgreHeaderSuffix.h"
204
205#endif
#define _OgreExport
#define _OgrePrivate
struct zzip_file ZZIP_FILE
Definition OgreZip.h:42
struct zzip_dir ZZIP_DIR
Definition OgreZip.h:41
union _zzip_plugin_io zzip_plugin_io_handlers
Definition OgreZip.h:43
Abstract factory class, archive codec plugins can register concrete subclasses of this.
Archive-handling class.
Definition OgreArchive.h:89
Archive(const String &name, const String &archType)
Constructor - don't call direct, used by ArchiveFactory.
DataStream(uint16 accessMode=READ)
Constructor for creating unnamed streams.
static void removeEmbbeddedFile(const String &name)
Remove an embedded file to the embedded file list.
static zzip_plugin_io_handlers * mPluginIo
A static pointer to file io alternative implementation for the embedded files.
Definition OgreZip.h:137
Archive * createInstance(const String &name, bool readOnly)
Creates a new object.
Definition OgreZip.h:144
bool(* DecryptEmbeddedZipFileFunc)(size_t pos, void *buf, size_t len)
a function type to decrypt embedded zip file
Definition OgreZip.h:156
static void addEmbbeddedFile(const String &name, const uint8 *fileData, size_t fileSize, DecryptEmbeddedZipFileFunc decryptFunc)
Add an embedded file to the embedded file list.
const String & getType(void) const
Returns the factory type.
Template version of cache based on static array.
Specialisation of ArchiveFactory for Zip files.
Definition OgreZip.h:115
Archive * createInstance(const String &name, bool readOnly)
Creates a new object.
Definition OgreZip.h:121
const String & getType(void) const
Returns the factory type.
void destroyInstance(Archive *ptr)
Destroys an object which was created by this factory.
Definition OgreZip.h:129
virtual ~ZipArchiveFactory()
Definition OgreZip.h:117
Specialisation of the Archive class to allow reading of files from a zip format source archive.
Definition OgreZip.h:60
bool exists(const String &filename)
Find out if the named file exists (note: fully qualified filename required)
DataStreamPtr create(const String &filename) const
Create a new file (or overwrite one already there).
void unload()
Unloads the archive.
FileInfoList mFileList
File list (since zziplib seems to only allow scanning of dir tree once)
Definition OgreZip.h:67
StringVectorPtr find(const String &pattern, bool recursive=true, bool dirs=false)
Find all file or directory names matching a given pattern in this archive.
void load()
Loads the archive.
void remove(const String &filename) const
Delete a named file.
StringVectorPtr list(bool recursive=true, bool dirs=false)
List all file names in the archive.
ZipArchive(const String &name, const String &archType, zzip_plugin_io_handlers *pluginIo=NULL)
FileInfoListPtr listFileInfo(bool recursive=true, bool dirs=false)
List all files in the archive with accompanying information.
time_t getModifiedTime(const String &filename)
Retrieve the modification time of a given file.
ZZIP_DIR * mZzipDir
Handle to root zip file.
Definition OgreZip.h:63
void checkZzipError(int zzipError, const String &operation) const
Handle any errors from zzip.
zzip_plugin_io_handlers * mPluginIo
A pointer to file io alternative implementation.
Definition OgreZip.h:69
FileInfoListPtr findFileInfo(const String &pattern, bool recursive=true, bool dirs=false) const
Find all files or directories matching a given pattern in this archive and get some detailed informat...
DataStreamPtr open(const String &filename, bool readOnly=true) const
Open a stream on a given file.
bool isCaseSensitive(void) const
Returns whether this archive is case sensitive in the way it matches files.
Definition OgreZip.h:76
ZZIP_FILE * mZzipFile
Definition OgreZip.h:171
void close(void)
Close the stream; this makes further operations invalid.
bool eof(void) const
Returns true if the stream has reached the end.
ZipDataStream(ZZIP_FILE *zzipFile, size_t uncompressedSize)
Unnamed constructor.
size_t read(void *buf, size_t count)
Read the requisite number of bytes from the stream, stopping at the end of the file.
size_t tell(void) const
Repositions the read point to a specified byte.
void seek(size_t pos)
Repositions the read point to a specified byte.
ZipDataStream(const String &name, ZZIP_FILE *zzipFile, size_t uncompressedSize)
Constructor for creating named streams.
size_t write(void *buf, size_t count)
Write the requisite number of bytes from the stream (only applicable to streams that are not read-onl...
void skip(long count)
Skip a defined number of bytes.
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:173
SharedPtr< StringVector > StringVectorPtr
#define OGRE_NEW
#define OGRE_DELETE
vector< FileInfo >::type FileInfoList
Definition OgreArchive.h:69
SharedPtr< DataStream > DataStreamPtr
Shared pointer to allow data streams to be passed around without worrying about deallocation.
SharedPtr< FileInfoList > FileInfoListPtr
Definition OgreArchive.h:70
unsigned char uint8
_StringBase String