source: GTP/trunk/Lib/Geom/OgreStuff/include/OgreZip.h @ 1809

Revision 1809, 4.4 KB checked in by gumbau, 18 years ago (diff)
RevLine 
[1809]1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://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.
34typedef struct zzip_dir         ZZIP_DIR;
35typedef struct zzip_file        ZZIP_FILE;
36
37namespace 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    public:
106        /// Unnamed constructor
107        ZipDataStream(ZZIP_FILE* zzipFile, size_t uncompressedSize);
108        /// Constructor for creating named streams
109        ZipDataStream(const String& name, ZZIP_FILE* zzipFile, size_t uncompressedSize);
110                ~ZipDataStream();
111        /// @copydoc DataStream::read
112        size_t read(void* buf, size_t count);
113        /// @copydoc DataStream::skip
114        void skip(long count);
115        /// @copydoc DataStream::seek
116        void seek( size_t pos );
117        /// @copydoc DataStream::seek
118        size_t tell(void) const;
119        /// @copydoc DataStream::eof
120        bool eof(void) const;
121        /// @copydoc DataStream::close
122        void close(void);
123
124
125    };
126
127
128}
129
130#endif
Note: See TracBrowser for help on using the repository browser.