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-2005 The OGRE Team
|
---|
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 | */
|
---|
25 | #ifndef __Zip_H__
|
---|
26 | #define __Zip_H__
|
---|
27 |
|
---|
28 | #include "OgrePrerequisites.h"
|
---|
29 |
|
---|
30 | #include "OgreArchive.h"
|
---|
31 | #include "OgreArchiveFactory.h"
|
---|
32 |
|
---|
33 | // Forward declaration for zziplib to avoid header file dependency.
|
---|
34 | typedef struct zzip_dir ZZIP_DIR;
|
---|
35 | typedef struct zzip_file ZZIP_FILE;
|
---|
36 |
|
---|
37 | namespace Ogre {
|
---|
38 |
|
---|
39 | /** Specialisation of the Archive class to allow reading of files from a zip
|
---|
40 | format source archive.
|
---|
41 | @remarks
|
---|
42 | This archive format supports all archives compressed in the standard
|
---|
43 | zip format, including iD pk3 files.
|
---|
44 | */
|
---|
45 | class _OgreExport ZipArchive : public Archive
|
---|
46 | {
|
---|
47 | protected:
|
---|
48 | /// Handle to root zip file
|
---|
49 | ZZIP_DIR* mZzipDir;
|
---|
50 | /// Handle any errors from zzip
|
---|
51 | void checkZzipError(int zzipError, const String& operation) const;
|
---|
52 | /// File list (since zziplib seems to only allow scanning of dir tree once)
|
---|
53 | FileInfoList mFileList;
|
---|
54 | public:
|
---|
55 | ZipArchive(const String& name, const String& archType );
|
---|
56 | ~ZipArchive();
|
---|
57 | /// @copydoc Archive::isCaseSensitive
|
---|
58 | bool isCaseSensitive(void) const { return false; }
|
---|
59 |
|
---|
60 | /// @copydoc Archive::load
|
---|
61 | void load();
|
---|
62 | /// @copydoc Archive::unload
|
---|
63 | void unload();
|
---|
64 |
|
---|
65 | /// @copydoc Archive::open
|
---|
66 | DataStreamPtr open(const String& filename) const;
|
---|
67 |
|
---|
68 | /// @copydoc Archive::list
|
---|
69 | StringVectorPtr list(bool recursive = true );
|
---|
70 |
|
---|
71 | /// @copydoc Archive::listFileInfo
|
---|
72 | FileInfoListPtr listFileInfo(bool recursive = true );
|
---|
73 |
|
---|
74 | /// @copydoc Archive::find
|
---|
75 | StringVectorPtr find(const String& pattern, bool recursive = true);
|
---|
76 |
|
---|
77 | /// @copydoc Archive::findFileInfo
|
---|
78 | FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true);
|
---|
79 |
|
---|
80 | /// @copydoc Archive::exists
|
---|
81 | bool exists(const String& filename);
|
---|
82 | };
|
---|
83 |
|
---|
84 | /** Specialisation of ArchiveFactory for Zip files. */
|
---|
85 | class _OgrePrivate ZipArchiveFactory : public ArchiveFactory
|
---|
86 | {
|
---|
87 | public:
|
---|
88 | virtual ~ZipArchiveFactory() {}
|
---|
89 | /// @copydoc FactoryObj::getType
|
---|
90 | const String& getType(void) const;
|
---|
91 | /// @copydoc FactoryObj::createInstance
|
---|
92 | Archive *createInstance( const String& name )
|
---|
93 | {
|
---|
94 | return new ZipArchive(name, "Zip");
|
---|
95 | }
|
---|
96 | /// @copydoc FactoryObj::destroyInstance
|
---|
97 | void destroyInstance( Archive* arch) { delete arch; }
|
---|
98 | };
|
---|
99 |
|
---|
100 | /** Specialisation of DataStream to handle streaming data from zip archives. */
|
---|
101 | class _OgrePrivate ZipDataStream : public DataStream
|
---|
102 | {
|
---|
103 | protected:
|
---|
104 | ZZIP_FILE* mZzipFile;
|
---|
105 | /// Temporary zip copy area
|
---|
106 | char mZipTmpArea[OGRE_STREAM_TEMP_SIZE];
|
---|
107 | public:
|
---|
108 | /// Unnamed constructor
|
---|
109 | ZipDataStream(ZZIP_FILE* zzipFile, size_t uncompressedSize);
|
---|
110 | /// Constructor for creating named streams
|
---|
111 | ZipDataStream(const String& name, ZZIP_FILE* zzipFile, size_t uncompressedSize);
|
---|
112 | ~ZipDataStream();
|
---|
113 | /// @copydoc DataStream::read
|
---|
114 | size_t read(void* buf, size_t count);
|
---|
115 | /// @copydoc DataStream::read
|
---|
116 | size_t readLine(char* buf, size_t maxCount, const String& delim = "\n");
|
---|
117 | /// @copydoc DataStream::skipLine
|
---|
118 | size_t skipLine(const String& delim = "\n");
|
---|
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
|
---|