Visualization LibraryA lightweight C++ OpenGL middleware for 2D/3D graphics |
[Home] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://www.visualizationlibrary.com */ 00005 /* */ 00006 /* Copyright (c) 2005-2010, Michele Bosi */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without modification, */ 00010 /* are permitted provided that the following conditions are met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, this */ 00013 /* list of conditions and the following disclaimer. */ 00014 /* */ 00015 /* - Redistributions in binary form must reproduce the above copyright notice, this */ 00016 /* list of conditions and the following disclaimer in the documentation and/or */ 00017 /* other materials provided with the distribution. */ 00018 /* */ 00019 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ 00020 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 00021 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ 00022 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */ 00023 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ 00024 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 00025 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ 00026 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ 00027 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 00028 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00029 /* */ 00030 /**************************************************************************************/ 00031 00032 #ifndef ZippedFile_INCLUDE_ONCE 00033 #define ZippedFile_INCLUDE_ONCE 00034 00035 #include <vlCore/VirtualFile.hpp> 00036 struct z_stream_s; 00037 00038 namespace vl 00039 { 00040 //--------------------------------------------------------------------------- 00041 // ZippedFileInfo 00042 //--------------------------------------------------------------------------- 00046 class ZippedFileInfo: public Object 00047 { 00048 friend class ZippedFile; 00049 friend class ZippedDirectory; 00050 00051 public: 00052 virtual const char* className() { return "vl::ZippedFileInfo"; } 00053 00054 ZippedFileInfo() 00055 { 00056 mVersionNeeded = 0; 00057 mGeneralPurposeFlag = 0; 00058 mCompressionMethod = 0; 00059 mCRC32 = 0; 00060 mCompressedSize = 0; 00061 mUncompressedSize = 0; 00062 mFileNameLength = 0; 00063 mExtraFieldLength = 0; 00064 mSecond = 0; 00065 mMinute = 0; 00066 mHour = 0; 00067 mDay = 0; 00068 mMonth = 0; 00069 mYear = 0; 00070 mZippedFileOffset = 0; 00071 } 00072 00073 public: 00074 unsigned short versionNeeded() const { return mVersionNeeded; } 00075 unsigned short generalPurposeFlag() const { return mGeneralPurposeFlag; } 00076 unsigned short compressionMethod() const { return mCompressionMethod; } 00077 unsigned int crc32() const { return mCRC32; } 00078 unsigned int compressedSize() const { return mCompressedSize; } 00079 unsigned int uncompressedSize() const { return mUncompressedSize; } 00080 unsigned short fileNameLength() const { return mFileNameLength; } 00081 unsigned short extraFieldLength() const { return mExtraFieldLength; } 00082 int second() const { return mSecond; } 00083 int minute() const { return mMinute; } 00084 int hour() const { return mHour; } 00085 int day() const { return mDay; } 00086 int month() const { return mMonth; } 00087 int year() const { return mYear; } 00088 const String& path() const { return mFileName; } 00089 // offset of the compressed data in the source zip file 00090 unsigned int zippedFileOffset() const { return mZippedFileOffset; } 00091 // source stream used to seek and read the compressed zip data 00092 VirtualFile* sourceZipFile() const { return mSourceZipFile.get(); } 00093 void setSourceZipFile(VirtualFile* file) { mSourceZipFile = file; } 00094 00095 public: 00096 unsigned short mVersionNeeded; 00097 unsigned short mGeneralPurposeFlag; 00098 unsigned short mCompressionMethod; 00099 unsigned int mCRC32; 00100 unsigned int mCompressedSize; 00101 unsigned int mUncompressedSize; 00102 unsigned short mFileNameLength; 00103 unsigned short mExtraFieldLength; 00104 int mSecond; 00105 int mMinute; 00106 int mHour; 00107 int mDay; 00108 int mMonth; 00109 int mYear; 00110 String mFileName; 00111 // offset of the compressed data in the zip file 00112 unsigned int mZippedFileOffset; 00113 // source stream used to seek and read the compressed zip data 00114 ref<VirtualFile> mSourceZipFile; 00115 }; 00116 //--------------------------------------------------------------------------- 00117 // ZippedFile 00118 //--------------------------------------------------------------------------- 00132 class VLCORE_EXPORT ZippedFile: public VirtualFile 00133 { 00134 00135 // Lower this if you need to limit the amount of data allocated to the stack, for example to 16K. 00136 static const int CHUNK_SIZE = 128*1024; 00137 00138 public: 00139 virtual const char* className() { return "vl::ZippedFile"; } 00140 00141 ZippedFile(); 00142 ~ZippedFile(); 00143 00144 ZippedFileInfo* zippedFileInfo() const; 00145 00146 void setZippedFileInfo(ZippedFileInfo* info); 00147 00150 virtual bool exists() const; 00151 00152 virtual bool open(EOpenMode mode); 00153 00154 virtual bool isOpen() const; 00155 00156 virtual void close(); 00157 00158 virtual long long size() const; 00159 00160 bool extract(char* destination, bool check_sum = true); 00161 00162 ZippedFile& operator=(const ZippedFile& other) 00163 { 00164 close(); 00165 VirtualFile::operator=(other); 00166 mZippedFileInfo = new ZippedFileInfo(*other.mZippedFileInfo); 00167 if (mZippedFileInfo->sourceZipFile()) 00168 { 00169 ref<VirtualFile> src_zip_copy = mZippedFileInfo->sourceZipFile()->clone(); 00170 mZippedFileInfo->setSourceZipFile(src_zip_copy.get()); 00171 } 00172 return *this; 00173 } 00174 00175 virtual ref<VirtualFile> clone() const; 00176 00177 void resetStream(); 00178 00179 protected: 00180 virtual long long read_Implementation(void* buffer, long long bytes_to_read); 00181 00182 virtual long long write_Implementation(const void* /*buffer*/, long long /*byte_count*/) { return 0; } // not supported yet 00183 00184 virtual bool fillUncompressedBuffer(); 00185 00186 virtual long long position_Implementation() const { return mReadBytes; } 00187 00188 virtual bool seekSet_Implementation(long long); 00189 00190 protected: 00191 ref<ZippedFileInfo> mZippedFileInfo; 00192 long long mReadBytes; 00193 00194 z_stream_s* mZStream; 00195 unsigned char mZipBufferIn[CHUNK_SIZE]; 00196 unsigned char mZipBufferOut[CHUNK_SIZE]; 00197 std::vector<char> mUncompressedBuffer; 00198 int mUncompressedBufferPtr; 00199 }; 00200 } 00201 00202 #endif