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-2013 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 #if OGRE_THREAD_SUPPORT 00036 #include "Threading/OgreThreadHeaders.h" 00037 #endif 00038 #include "OgreHeaderPrefix.h" 00039 00040 // Forward declaration for zziplib to avoid header file dependency. 00041 typedef struct zzip_dir ZZIP_DIR; 00042 typedef struct zzip_file ZZIP_FILE; 00043 typedef union _zzip_plugin_io zzip_plugin_io_handlers; 00044 00045 namespace Ogre { 00046 00059 class _OgreExport ZipArchive : public Archive 00060 { 00061 protected: 00063 ZZIP_DIR* mZzipDir; 00065 void checkZzipError(int zzipError, const String& operation) const; 00067 FileInfoList mFileList; 00069 zzip_plugin_io_handlers* mPluginIo; 00070 00071 OGRE_AUTO_MUTEX; 00072 public: 00073 ZipArchive(const String& name, const String& archType, zzip_plugin_io_handlers* pluginIo = NULL); 00074 ~ZipArchive(); 00076 bool isCaseSensitive(void) const { return false; } 00077 00079 void load(); 00081 void unload(); 00082 00084 DataStreamPtr open(const String& filename, bool readOnly = true) const; 00085 00087 DataStreamPtr create(const String& filename) const; 00088 00090 void remove(const String& filename) const; 00091 00093 StringVectorPtr list(bool recursive = true, bool dirs = false); 00094 00096 FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false); 00097 00099 StringVectorPtr find(const String& pattern, bool recursive = true, 00100 bool dirs = false); 00101 00103 FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true, 00104 bool dirs = false) const; 00105 00107 bool exists(const String& filename); 00108 00110 time_t getModifiedTime(const String& filename); 00111 }; 00112 00114 class _OgrePrivate ZipArchiveFactory : public ArchiveFactory 00115 { 00116 public: 00117 virtual ~ZipArchiveFactory() {} 00119 const String& getType(void) const; 00121 Archive *createInstance( const String& name, bool readOnly ) 00122 { 00123 if(!readOnly) 00124 return NULL; 00125 00126 return OGRE_NEW ZipArchive(name, "Zip"); 00127 } 00129 void destroyInstance( Archive* ptr) { OGRE_DELETE ptr; } 00130 }; 00131 00133 class _OgreExport EmbeddedZipArchiveFactory : public ZipArchiveFactory 00134 { 00135 protected: 00137 static zzip_plugin_io_handlers* mPluginIo; 00138 public: 00139 EmbeddedZipArchiveFactory(); 00140 virtual ~EmbeddedZipArchiveFactory(); 00142 const String& getType(void) const; 00144 Archive *createInstance( const String& name, bool readOnly ) 00145 { 00146 ZipArchive * resZipArchive = OGRE_NEW ZipArchive(name, "EmbeddedZip", mPluginIo); 00147 return resZipArchive; 00148 } 00149 00156 typedef bool (*DecryptEmbeddedZipFileFunc)(size_t pos, void* buf, size_t len); 00157 00159 static void addEmbbeddedFile(const String& name, const uint8 * fileData, 00160 size_t fileSize, DecryptEmbeddedZipFileFunc decryptFunc); 00161 00163 static void removeEmbbeddedFile(const String& name); 00164 00165 }; 00166 00168 class _OgrePrivate ZipDataStream : public DataStream 00169 { 00170 protected: 00171 ZZIP_FILE* mZzipFile; 00173 StaticCache<2 * OGRE_STREAM_TEMP_SIZE> mCache; 00174 public: 00176 ZipDataStream(ZZIP_FILE* zzipFile, size_t uncompressedSize); 00178 ZipDataStream(const String& name, ZZIP_FILE* zzipFile, size_t uncompressedSize); 00179 ~ZipDataStream(); 00181 size_t read(void* buf, size_t count); 00183 size_t write(void* buf, size_t count); 00185 void skip(long count); 00187 void seek( size_t pos ); 00189 size_t tell(void) const; 00191 bool eof(void) const; 00193 void close(void); 00194 00195 00196 }; 00197 00201 } 00202 00203 #include "OgreHeaderSuffix.h" 00204 00205 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:48