OgreZip.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __Zip_H__
#define __Zip_H__
#include "OgrePrerequisites.h"
#include "OgreArchive.h"
#include "OgreArchiveFactory.h"
#if OGRE_THREAD_SUPPORT
#include "Threading/OgreThreadHeaders.h"
#endif
#include "OgreHeaderPrefix.h"
// Forward declaration for zziplib to avoid header file dependency.
typedef struct zzip_dir ZZIP_DIR;
typedef struct zzip_file ZZIP_FILE;
typedef union _zzip_plugin_io zzip_plugin_io_handlers;
namespace Ogre {
class _OgreExport ZipArchive : public Archive
{
protected:
ZZIP_DIR* mZzipDir;
void checkZzipError(int zzipError, const String& operation) const;
FileInfoList mFileList;
zzip_plugin_io_handlers* mPluginIo;
OGRE_AUTO_MUTEX;
public:
ZipArchive(const String& name, const String& archType, zzip_plugin_io_handlers* pluginIo = NULL);
~ZipArchive();
bool isCaseSensitive(void) const { return false; }
void load();
void unload();
DataStreamPtr open(const String& filename, bool readOnly = true) const;
DataStreamPtr create(const String& filename) const;
void remove(const String& filename) const;
StringVectorPtr list(bool recursive = true, bool dirs = false);
FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false);
StringVectorPtr find(const String& pattern, bool recursive = true,
bool dirs = false);
FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true,
bool dirs = false) const;
bool exists(const String& filename);
time_t getModifiedTime(const String& filename);
};
class _OgrePrivate ZipArchiveFactory : public ArchiveFactory
{
public:
virtual ~ZipArchiveFactory() {}
const String& getType(void) const;
Archive *createInstance( const String& name, bool readOnly )
{
if(!readOnly)
return NULL;
return OGRE_NEW ZipArchive(name, "Zip");
}
void destroyInstance( Archive* ptr) { OGRE_DELETE ptr; }
};
class _OgreExport EmbeddedZipArchiveFactory : public ZipArchiveFactory
{
protected:
static zzip_plugin_io_handlers* mPluginIo;
public:
EmbeddedZipArchiveFactory();
virtual ~EmbeddedZipArchiveFactory();
const String& getType(void) const;
Archive *createInstance( const String& name, bool readOnly )
{
ZipArchive * resZipArchive = OGRE_NEW ZipArchive(name, "EmbeddedZip", mPluginIo);
return resZipArchive;
}
typedef bool (*DecryptEmbeddedZipFileFunc)(size_t pos, void* buf, size_t len);
static void addEmbbeddedFile(const String& name, const uint8 * fileData,
size_t fileSize, DecryptEmbeddedZipFileFunc decryptFunc);
static void removeEmbbeddedFile(const String& name);
};
class _OgrePrivate ZipDataStream : public DataStream
{
protected:
ZZIP_FILE* mZzipFile;
StaticCache<2 * OGRE_STREAM_TEMP_SIZE> mCache;
public:
ZipDataStream(ZZIP_FILE* zzipFile, size_t uncompressedSize);
ZipDataStream(const String& name, ZZIP_FILE* zzipFile, size_t uncompressedSize);
~ZipDataStream();
size_t read(void* buf, size_t count);
size_t write(void* buf, size_t count);
void skip(long count);
void seek( size_t pos );
size_t tell(void) const;
bool eof(void) const;
void close(void);
};
}
#include "OgreHeaderSuffix.h"
#endif
Ogre::ZipDataStream
Specialisation of DataStream to handle streaming data from zip archives.
Definition: OgreZip.h:168
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::list
Definition: OgrePrerequisites.h:505
Ogre::ZipDataStream::mZzipFile
ZZIP_FILE * mZzipFile
Definition: OgreZip.h:171
Ogre::ZipArchive::isCaseSensitive
bool isCaseSensitive(void) const
Returns whether this archive is case sensitive in the way it matches files.
Definition: OgreZip.h:76
Ogre::ZipArchive::OGRE_AUTO_MUTEX
OGRE_AUTO_MUTEX
Definition: OgreZip.h:71
OGRE_DELETE
#define OGRE_DELETE
Definition: OgreMemoryAllocatorConfig.h:474
Ogre::ZipArchive::mZzipDir
ZZIP_DIR * mZzipDir
Handle to root zip file.
Definition: OgreZip.h:63
Ogre::EmbeddedZipArchiveFactory
Specialisation of ZipArchiveFactory for embedded Zip files.
Definition: OgreZip.h:133
OGRE_NEW
#define OGRE_NEW
Definition: OgreMemoryAllocatorConfig.h:473
Ogre::ZipDataStream::mCache
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
ZZIP_DIR
struct zzip_dir ZZIP_DIR
Definition: OgreZip.h:41
OgrePrerequisites.h
_OgrePrivate
#define _OgrePrivate
Definition: OgrePlatform.h:258
ZZIP_FILE
struct zzip_file ZZIP_FILE
Definition: OgreZip.h:42
Ogre::uint8
unsigned char uint8
Definition: OgrePlatform.h:361
Ogre::DataStream
General purpose class used for encapsulating the reading and writing of data.
Definition: OgreDataStream.h:176
Ogre::StaticCache< 2 *OGRE_STREAM_TEMP_SIZE >
OgreArchiveFactory.h
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::EmbeddedZipArchiveFactory::mPluginIo
static zzip_plugin_io_handlers * mPluginIo
A static pointer to file io alternative implementation for the embedded files.
Definition: OgreZip.h:137
Ogre::ArchiveFactory
Abstract factory class, archive codec plugins can register concrete subclasses of this...
Definition: OgreArchiveFactory.h:59
OgreHeaderSuffix.h
OgreThreadHeaders.h
Ogre::FileInfoList
vector< FileInfo >::type FileInfoList
Definition: OgreArchive.h:69
Ogre::ZipArchive::mFileList
FileInfoList mFileList
File list (since zziplib seems to only allow scanning of dir tree once)
Definition: OgreZip.h:67
zzip_plugin_io_handlers
union _zzip_plugin_io zzip_plugin_io_handlers
Definition: OgreZip.h:43
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::ZipArchive::mPluginIo
zzip_plugin_io_handlers * mPluginIo
A pointer to file io alternative implementation.
Definition: OgreZip.h:69
Ogre::SharedPtr< DataStream >
OgreHeaderPrefix.h
OgreArchive.h
Ogre::Archive
Archive-handling class.
Definition: OgreArchive.h:88
Ogre::ZipArchiveFactory::~ZipArchiveFactory
virtual ~ZipArchiveFactory()
Definition: OgreZip.h:117
Ogre::EmbeddedZipArchiveFactory::createInstance
Archive * createInstance(const String &name, bool readOnly)
Creates a new object.
Definition: OgreZip.h:144
Ogre::ZipArchiveFactory
Specialisation of ArchiveFactory for Zip files.
Definition: OgreZip.h:114
Ogre::ZipArchive
Specialisation of the Archive class to allow reading of files from a zip format source archive...
Definition: OgreZip.h:59
Ogre::ZipArchiveFactory::destroyInstance
void destroyInstance(Archive *ptr)
Destroys an object which was created by this factory.
Definition: OgreZip.h:129
Ogre::ZipArchiveFactory::createInstance
Archive * createInstance(const String &name, bool readOnly)
Creates a new object.
Definition: OgreZip.h:121

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.