00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2012 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __Zip_H__ 00029 #define __Zip_H__ 00030 00031 #include "OgrePrerequisites.h" 00032 00033 #include "OgreArchive.h" 00034 #include "OgreArchiveFactory.h" 00035 00036 // Forward declaration for zziplib to avoid header file dependency. 00037 typedef struct zzip_dir ZZIP_DIR; 00038 typedef struct zzip_file ZZIP_FILE; 00039 typedef union _zzip_plugin_io zzip_plugin_io_handlers; 00040 00041 namespace Ogre { 00042 00055 class _OgreExport ZipArchive : public Archive 00056 { 00057 protected: 00059 ZZIP_DIR* mZzipDir; 00061 void checkZzipError(int zzipError, const String& operation) const; 00063 FileInfoList mFileList; 00065 zzip_plugin_io_handlers* mPluginIo; 00066 00067 OGRE_AUTO_MUTEX 00068 public: 00069 ZipArchive(const String& name, const String& archType, zzip_plugin_io_handlers* pluginIo = NULL); 00070 ~ZipArchive(); 00072 bool isCaseSensitive(void) const { return false; } 00073 00075 void load(); 00077 void unload(); 00078 00080 DataStreamPtr open(const String& filename, bool readOnly = true) const; 00081 00083 DataStreamPtr create(const String& filename) const; 00084 00086 void remove(const String& filename) const; 00087 00089 StringVectorPtr list(bool recursive = true, bool dirs = false); 00090 00092 FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false); 00093 00095 StringVectorPtr find(const String& pattern, bool recursive = true, 00096 bool dirs = false); 00097 00099 FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true, 00100 bool dirs = false) const; 00101 00103 bool exists(const String& filename); 00104 00106 time_t getModifiedTime(const String& filename); 00107 }; 00108 00110 class _OgrePrivate ZipArchiveFactory : public ArchiveFactory 00111 { 00112 public: 00113 virtual ~ZipArchiveFactory() {} 00115 const String& getType(void) const; 00117 Archive *createInstance( const String& name ) 00118 { 00119 return OGRE_NEW ZipArchive(name, "Zip"); 00120 } 00122 void destroyInstance( Archive* arch) { OGRE_DELETE arch; } 00123 }; 00124 00126 class _OgreExport EmbeddedZipArchiveFactory : public ZipArchiveFactory 00127 { 00128 protected: 00130 static zzip_plugin_io_handlers* mPluginIo; 00131 public: 00132 EmbeddedZipArchiveFactory(); 00133 virtual ~EmbeddedZipArchiveFactory(); 00135 const String& getType(void) const; 00137 Archive *createInstance( const String& name ) 00138 { 00139 ZipArchive * resZipArchive = OGRE_NEW ZipArchive(name, "EmbeddedZip", mPluginIo); 00140 return resZipArchive; 00141 } 00142 00149 typedef bool (*DecryptEmbeddedZipFileFunc)(size_t pos, void* buf, size_t len); 00150 00152 static void addEmbbeddedFile(const String& name, const uint8 * fileData, 00153 size_t fileSize, DecryptEmbeddedZipFileFunc decryptFunc); 00154 00156 static void removeEmbbeddedFile(const String& name); 00157 00158 }; 00159 00161 class _OgrePrivate ZipDataStream : public DataStream 00162 { 00163 protected: 00164 ZZIP_FILE* mZzipFile; 00166 StaticCache<2 * OGRE_STREAM_TEMP_SIZE> mCache; 00167 public: 00169 ZipDataStream(ZZIP_FILE* zzipFile, size_t uncompressedSize); 00171 ZipDataStream(const String& name, ZZIP_FILE* zzipFile, size_t uncompressedSize); 00172 ~ZipDataStream(); 00174 size_t read(void* buf, size_t count); 00176 size_t write(void* buf, size_t count); 00178 void skip(long count); 00180 void seek( size_t pos ); 00182 size_t tell(void) const; 00184 bool eof(void) const; 00186 void close(void); 00187 00188 00189 }; 00190 00194 } 00195 00196 #endif
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:28 2012