| 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-2006 Torus Knot Software Ltd |
|---|
| 8 | Also see acknowledgements in Readme.html |
|---|
| 9 | |
|---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
|---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
|---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 13 | version. |
|---|
| 14 | |
|---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
|---|
| 18 | |
|---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
|---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
|---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
|---|
| 23 | |
|---|
| 24 | You may alternatively use this source under the terms of a specific version of |
|---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
|---|
| 26 | Torus Knot Software Ltd. |
|---|
| 27 | ----------------------------------------------------------------------------- |
|---|
| 28 | */ |
|---|
| 29 | #ifndef __Zip_H__ |
|---|
| 30 | #define __Zip_H__ |
|---|
| 31 | |
|---|
| 32 | #include "OgrePrerequisites.h" |
|---|
| 33 | |
|---|
| 34 | #include "OgreArchive.h" |
|---|
| 35 | #include "OgreArchiveFactory.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 | |
|---|
| 41 | namespace Ogre { |
|---|
| 42 | |
|---|
| 43 | /** Specialisation of the Archive class to allow reading of files from a zip |
|---|
| 44 | format source archive. |
|---|
| 45 | @remarks |
|---|
| 46 | This archive format supports all archives compressed in the standard |
|---|
| 47 | zip format, including iD pk3 files. |
|---|
| 48 | */ |
|---|
| 49 | class _OgreExport ZipArchive : public Archive |
|---|
| 50 | { |
|---|
| 51 | protected: |
|---|
| 52 | /// Handle to root zip file |
|---|
| 53 | ZZIP_DIR* mZzipDir; |
|---|
| 54 | /// Handle any errors from zzip |
|---|
| 55 | void checkZzipError(int zzipError, const String& operation) const; |
|---|
| 56 | /// File list (since zziplib seems to only allow scanning of dir tree once) |
|---|
| 57 | FileInfoList mFileList; |
|---|
| 58 | public: |
|---|
| 59 | ZipArchive(const String& name, const String& archType ); |
|---|
| 60 | ~ZipArchive(); |
|---|
| 61 | /// @copydoc Archive::isCaseSensitive |
|---|
| 62 | bool isCaseSensitive(void) const { return false; } |
|---|
| 63 | |
|---|
| 64 | /// @copydoc Archive::load |
|---|
| 65 | void load(); |
|---|
| 66 | /// @copydoc Archive::unload |
|---|
| 67 | void unload(); |
|---|
| 68 | |
|---|
| 69 | /// @copydoc Archive::open |
|---|
| 70 | DataStreamPtr open(const String& filename) const; |
|---|
| 71 | |
|---|
| 72 | /// @copydoc Archive::list |
|---|
| 73 | StringVectorPtr list(bool recursive = true, bool dirs = false); |
|---|
| 74 | |
|---|
| 75 | /// @copydoc Archive::listFileInfo |
|---|
| 76 | FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false); |
|---|
| 77 | |
|---|
| 78 | /// @copydoc Archive::find |
|---|
| 79 | StringVectorPtr find(const String& pattern, bool recursive = true, |
|---|
| 80 | bool dirs = false); |
|---|
| 81 | |
|---|
| 82 | /// @copydoc Archive::findFileInfo |
|---|
| 83 | FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true, |
|---|
| 84 | bool dirs = false); |
|---|
| 85 | |
|---|
| 86 | /// @copydoc Archive::exists |
|---|
| 87 | bool exists(const String& filename); |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | /** Specialisation of ArchiveFactory for Zip files. */ |
|---|
| 91 | class _OgrePrivate ZipArchiveFactory : public ArchiveFactory |
|---|
| 92 | { |
|---|
| 93 | public: |
|---|
| 94 | virtual ~ZipArchiveFactory() {} |
|---|
| 95 | /// @copydoc FactoryObj::getType |
|---|
| 96 | const String& getType(void) const; |
|---|
| 97 | /// @copydoc FactoryObj::createInstance |
|---|
| 98 | Archive *createInstance( const String& name ) |
|---|
| 99 | { |
|---|
| 100 | return new ZipArchive(name, "Zip"); |
|---|
| 101 | } |
|---|
| 102 | /// @copydoc FactoryObj::destroyInstance |
|---|
| 103 | void destroyInstance( Archive* arch) { delete arch; } |
|---|
| 104 | }; |
|---|
| 105 | |
|---|
| 106 | /** Specialisation of DataStream to handle streaming data from zip archives. */ |
|---|
| 107 | class _OgrePrivate ZipDataStream : public DataStream |
|---|
| 108 | { |
|---|
| 109 | protected: |
|---|
| 110 | ZZIP_FILE* mZzipFile; |
|---|
| 111 | public: |
|---|
| 112 | /// Unnamed constructor |
|---|
| 113 | ZipDataStream(ZZIP_FILE* zzipFile, size_t uncompressedSize); |
|---|
| 114 | /// Constructor for creating named streams |
|---|
| 115 | ZipDataStream(const String& name, ZZIP_FILE* zzipFile, size_t uncompressedSize); |
|---|
| 116 | ~ZipDataStream(); |
|---|
| 117 | /// @copydoc DataStream::read |
|---|
| 118 | size_t read(void* buf, size_t count); |
|---|
| 119 | /// @copydoc DataStream::skip |
|---|
| 120 | void skip(long count); |
|---|
| 121 | /// @copydoc DataStream::seek |
|---|
| 122 | void seek( size_t pos ); |
|---|
| 123 | /// @copydoc DataStream::seek |
|---|
| 124 | size_t tell(void) const; |
|---|
| 125 | /// @copydoc DataStream::eof |
|---|
| 126 | bool eof(void) const; |
|---|
| 127 | /// @copydoc DataStream::close |
|---|
| 128 | void close(void); |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | }; |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | #endif |
|---|