file/zip/codec.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004-2005 by Reality Rift Studios                       *
00003  *   http://www.realityrift.com  -  mattias@realityrift.com                *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #ifndef neo_file_zip_codec_h
00022 #define neo_file_zip_codec_h
00023 
00029 #include "../../core/platform.h"
00030 
00031 #if NEO_ENABLE_FILE_ZIP
00032 
00033 #include "../package.h"
00034 #include "../bufferstream.h"
00035 
00036 namespace neo {
00037 namespace file {
00038 namespace zip {
00039 
00040 class Package;
00041 
00042 struct EndOfCD
00043 {
00044     public:
00045 
00046     char                                                    _signature[4];
00047     uint16_t                                                _disc;
00048     uint16_t                                                _discCD;
00049     uint16_t                                                _numEntries;
00050     uint16_t                                                _numEntriesTotal;
00051     uint32_t                                                _sizeCD;
00052     uint32_t                                                _offsetCD;
00053     uint16_t                                                _sizeComment;
00054 };
00055 
00056 struct CDFileHeader
00057 {
00058     public:
00059 
00060     char                                                    _signature[4];
00061     uint16_t                                                _versionMade;
00062     uint16_t                                                _versionExtract;
00063     uint16_t                                                _flags;
00064     uint16_t                                                _compression;
00065     uint16_t                                                _modTime;
00066     uint16_t                                                _modDate;
00067     uint32_t                                                _crc32;
00068     uint32_t                                                _sizeCompressed;
00069     uint32_t                                                _sizeUncompressed;
00070     uint16_t                                                _sizeFilename;
00071     uint16_t                                                _sizeExtra;
00072     uint16_t                                                _sizeComment;
00073     uint16_t                                                _disc;
00074     uint16_t                                                _attribInternal;
00075     uint32_t                                                _attribExternal;
00076     uint32_t                                                _offset;
00077 };
00078 
00079 struct LocalHeader
00080 {
00081     public:
00082 
00083     char                                                    _signature[4];
00084     uint16_t                                                _versionExtract;
00085     uint16_t                                                _flags;
00086     uint16_t                                                _compression;
00087     uint16_t                                                _modTime;
00088     uint16_t                                                _modDate;
00089     uint32_t                                                _crc32;
00090     uint32_t                                                _sizeCompressed;
00091     uint32_t                                                _sizeUncompressed;
00092     uint16_t                                                _sizeFilename;
00093     uint16_t                                                _sizeExtra;
00094 };
00095 
00101 class BufferStream : public file::BufferStream
00102 {
00103     public:
00104 
00106 
00110                                                             BufferStream( Package* p_package, CDFileHeader* p_header, const std::string& path, unsigned int mode );
00111 
00113     virtual                                                ~BufferStream();
00114     
00115     BufferStream*                                           clone() const;
00116     
00117     protected:
00118     
00120     Package*                                                _p_package;
00121 
00123     CDFileHeader*                                           _p_header;
00124 };
00125 
00131 class Package : public file::Package
00132 {
00133     public:
00134 
00135                                                             Package( const std::string& path, file::IOStream* p_stream, bool writeenable );
00136     virtual                                                ~Package();
00137     
00139 
00141     std::string                                             parse();
00142     
00143     virtual IOStream*                                       openFile( const std::string& path, unsigned int mode );
00144     virtual bool                                            hasDirectory( const std::string& path );
00145     virtual void                                            getFiles( const std::string& path, core::Array< std::string >* p_array );
00146     virtual void                                            getSubdirs( const std::string& path, core::Array< std::string >* p_array );
00147     virtual bool                                            isFile( const std::string& path );
00148     virtual bool                                            removeFile( const std::string& path );
00149     virtual bool                                            removeDirectory( const std::string& path );
00150     virtual bool                                            isValid() const;
00151 
00153 
00160     void                                                    updateArchive( CDFileHeader* p_file, int method, const unsigned char* p_buffer, unsigned int sizeCompressed, unsigned int sizeUncompressed, unsigned int crc );
00161 
00163 
00164     inline IOStream*                                        getStream() { return _p_stream; }
00165 
00166     private:
00167 
00169     bool                                                    _valid;
00170     
00172     EndOfCD                                                 _eocd;
00173 
00175     core::HashTable< std::string, CDFileHeader* >           _files;
00176 };
00177 
00183 class Codec : public neo::file::PackageCodec
00184 {
00185 
00186     public:
00187 
00188                                                             Codec();
00189     virtual                                                ~Codec();
00190 
00191     virtual file::Package*                                  allocate( const std::string& path, file::IOStream* p_stream, bool writeenable );
00192 };
00193 
00194 
00195 }
00196 }
00197 }
00198 
00199 #endif
00200 
00201 #endif

Generated on Sat Feb 17 20:50:48 2007 for NeoEngine 2 - Evolution by  doxygen 1.5.1