1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __C_ZIP_READER_H_INCLUDED__
\r
6 #define __C_ZIP_READER_H_INCLUDED__
\r
8 #include "IrrCompileConfig.h"
\r
10 #include "IReadFile.h"
\r
11 #include "irrArray.h"
\r
12 #include "irrString.h"
\r
13 #include "IFileSystem.h"
\r
14 #include "CFileList.h"
\r
20 // set if the file is encrypted
\r
21 const s16 ZIP_FILE_ENCRYPTED = 0x0001;
\r
22 // the fields crc-32, compressed size and uncompressed size are set to
\r
23 // zero in the local header
\r
24 const s16 ZIP_INFO_IN_DATA_DESCRIPTOR = 0x0008;
\r
26 // byte-align structures
\r
27 #include "irrpack.h"
\r
29 struct SZIPFileDataDescriptor
\r
33 u32 UncompressedSize;
\r
36 struct SZIPFileHeader
\r
38 u32 Sig; // 'PK0304' little endian (0x04034b50)
\r
39 s16 VersionToExtract;
\r
41 s16 CompressionMethod;
\r
42 s16 LastModFileTime;
\r
43 s16 LastModFileDate;
\r
44 SZIPFileDataDescriptor DataDescriptor;
\r
46 s16 ExtraFieldLength;
\r
47 // filename (variable size)
\r
48 // extra field (variable size )
\r
51 struct SZIPFileCentralDirFileHeader
\r
53 u32 Sig; // 'PK0102' (0x02014b50)
\r
55 u16 VersionToExtract;
\r
57 u16 CompressionMethod;
\r
58 u16 LastModFileTime;
\r
59 u16 LastModFileDate;
\r
62 u32 UncompressedSize;
\r
64 u16 ExtraFieldLength;
\r
65 u16 FileCommentLength;
\r
66 u16 DiskNumberStart;
\r
67 u16 InternalFileAttributes;
\r
68 u32 ExternalFileAttributes;
\r
69 u32 RelativeOffsetOfLocalHeader;
\r
71 // filename (variable size)
\r
72 // extra field (variable size)
\r
73 // file comment (variable size)
\r
77 struct SZIPFileCentralDirEnd
\r
79 u32 Sig; // 'PK0506' end_of central dir signature // (0x06054b50)
\r
80 u16 NumberDisk; // number of this disk
\r
81 u16 NumberStart; // number of the disk with the start of the central directory
\r
82 u16 TotalDisk; // total number of entries in the central dir on this disk
\r
83 u16 TotalEntries; // total number of entries in the central dir
\r
84 u32 Size; // size of the central directory
\r
85 u32 Offset; // offset of start of centraldirectory with respect to the starting disk number
\r
86 u16 CommentLength; // zipfile comment length
\r
87 // zipfile comment (variable size)
\r
90 struct SZipFileExtraHeader
\r
96 struct SZipFileAESExtraData
\r
100 u8 EncryptionStrength;
\r
101 s16 CompressionMode;
\r
108 EGZF_EXTRA_FIELDS = 4,
\r
109 EGZF_FILE_NAME = 8,
\r
113 struct SGZIPMemberHeader
\r
116 u8 compressionMethod; // 8 = deflate
\r
119 u8 extraFlags; // slow compress = 2, fast compress = 4
\r
120 u8 operatingSystem;
\r
123 // Default alignment
\r
124 #include "irrunpack.h"
\r
126 //! Contains extended info about zip files in the archive
\r
127 struct SZipFileEntry
\r
129 //! Position of data in the archive file
\r
132 //! The header for this file containing compression info etc
\r
133 SZIPFileHeader header;
\r
136 //! Archiveloader capable of loading ZIP Archives
\r
137 class CArchiveLoaderZIP : public IArchiveLoader
\r
142 CArchiveLoaderZIP(io::IFileSystem* fs);
\r
144 //! returns true if the file maybe is able to be loaded by this class
\r
145 //! based on the file extension (e.g. ".zip")
\r
146 bool isALoadableFileFormat(const io::path& filename) const override;
\r
148 //! Check if the file might be loaded by this class
\r
149 /** Check might look into the file.
\r
150 \param file File handle to check.
\r
151 \return True if file seems to be loadable. */
\r
152 bool isALoadableFileFormat(io::IReadFile* file) const override;
\r
154 //! Check to see if the loader can create archives of this type.
\r
155 /** Check based on the archive type.
\r
156 \param fileType The archive type to check.
\r
157 \return True if the archile loader supports this type, false if not */
\r
158 bool isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const override;
\r
160 //! Creates an archive from the filename
\r
161 /** \param file File handle to check.
\r
162 \return Pointer to newly created archive, or 0 upon error. */
\r
163 IFileArchive* createArchive(const io::path& filename, bool ignoreCase, bool ignorePaths) const override;
\r
165 //! creates/loads an archive from the file.
\r
166 //! \return Pointer to the created archive. Returns 0 if loading failed.
\r
167 io::IFileArchive* createArchive(io::IReadFile* file, bool ignoreCase, bool ignorePaths) const override;
\r
170 io::IFileSystem* FileSystem;
\r
174 Zip file Reader written April 2002 by N.Gebhardt.
\r
176 class CZipReader : public virtual IFileArchive, virtual CFileList
\r
181 CZipReader(IFileSystem* fs, IReadFile* file, bool ignoreCase, bool ignorePaths, bool isGZip=false);
\r
184 virtual ~CZipReader();
\r
186 //! opens a file by file name
\r
187 IReadFile* createAndOpenFile(const io::path& filename) override;
\r
189 //! opens a file by index
\r
190 IReadFile* createAndOpenFile(u32 index) override;
\r
192 //! returns the list of files
\r
193 const IFileList* getFileList() const override;
\r
195 //! get the archive type
\r
196 E_FILE_ARCHIVE_TYPE getType() const override;
\r
198 //! return the id of the file Archive
\r
199 const io::path& getArchiveName() const override {return Path;}
\r
203 //! reads the next file header from a ZIP file, returns false if there are no more headers.
\r
204 /* if ignoreGPBits is set, the item will be read despite missing
\r
205 file information. This is used when reading items from the central
\r
207 bool scanZipHeader(bool ignoreGPBits=false);
\r
209 //! the same but for gzip files
\r
210 bool scanGZipHeader();
\r
212 bool scanCentralDirectoryHeader();
\r
214 io::IFileSystem* FileSystem;
\r
217 // holds extended info about files
\r
218 core::array<SZipFileEntry> FileInfo;
\r
224 } // end namespace io
\r
225 } // end namespace irr
\r
227 #endif // __C_ZIP_READER_H_INCLUDED__
\r