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
9 #include "IReadFile.h"
\r
10 #include "irrArray.h"
\r
11 #include "irrString.h"
\r
12 #include "IFileSystem.h"
\r
13 #include "CFileList.h"
\r
19 // set if the file is encrypted
\r
20 const s16 ZIP_FILE_ENCRYPTED = 0x0001;
\r
21 // the fields crc-32, compressed size and uncompressed size are set to
\r
22 // zero in the local header
\r
23 const s16 ZIP_INFO_IN_DATA_DESCRIPTOR = 0x0008;
\r
25 // byte-align structures
\r
26 #include "irrpack.h"
\r
28 struct SZIPFileDataDescriptor
\r
32 u32 UncompressedSize;
\r
35 struct SZIPFileHeader
\r
37 u32 Sig; // 'PK0304' little endian (0x04034b50)
\r
38 s16 VersionToExtract;
\r
40 s16 CompressionMethod;
\r
41 s16 LastModFileTime;
\r
42 s16 LastModFileDate;
\r
43 SZIPFileDataDescriptor DataDescriptor;
\r
45 s16 ExtraFieldLength;
\r
46 // filename (variable size)
\r
47 // extra field (variable size )
\r
50 struct SZIPFileCentralDirFileHeader
\r
52 u32 Sig; // 'PK0102' (0x02014b50)
\r
54 u16 VersionToExtract;
\r
56 u16 CompressionMethod;
\r
57 u16 LastModFileTime;
\r
58 u16 LastModFileDate;
\r
61 u32 UncompressedSize;
\r
63 u16 ExtraFieldLength;
\r
64 u16 FileCommentLength;
\r
65 u16 DiskNumberStart;
\r
66 u16 InternalFileAttributes;
\r
67 u32 ExternalFileAttributes;
\r
68 u32 RelativeOffsetOfLocalHeader;
\r
70 // filename (variable size)
\r
71 // extra field (variable size)
\r
72 // file comment (variable size)
\r
76 struct SZIPFileCentralDirEnd
\r
78 u32 Sig; // 'PK0506' end_of central dir signature // (0x06054b50)
\r
79 u16 NumberDisk; // number of this disk
\r
80 u16 NumberStart; // number of the disk with the start of the central directory
\r
81 u16 TotalDisk; // total number of entries in the central dir on this disk
\r
82 u16 TotalEntries; // total number of entries in the central dir
\r
83 u32 Size; // size of the central directory
\r
84 u32 Offset; // offset of start of centraldirectory with respect to the starting disk number
\r
85 u16 CommentLength; // zipfile comment length
\r
86 // zipfile comment (variable size)
\r
89 struct SZipFileExtraHeader
\r
95 struct SZipFileAESExtraData
\r
99 u8 EncryptionStrength;
\r
100 s16 CompressionMode;
\r
107 EGZF_EXTRA_FIELDS = 4,
\r
108 EGZF_FILE_NAME = 8,
\r
112 struct SGZIPMemberHeader
\r
115 u8 compressionMethod; // 8 = deflate
\r
118 u8 extraFlags; // slow compress = 2, fast compress = 4
\r
119 u8 operatingSystem;
\r
122 // Default alignment
\r
123 #include "irrunpack.h"
\r
125 //! Contains extended info about zip files in the archive
\r
126 struct SZipFileEntry
\r
128 //! Position of data in the archive file
\r
131 //! The header for this file containing compression info etc
\r
132 SZIPFileHeader header;
\r
135 //! Archiveloader capable of loading ZIP Archives
\r
136 class CArchiveLoaderZIP : public IArchiveLoader
\r
141 CArchiveLoaderZIP(io::IFileSystem* fs);
\r
143 //! returns true if the file maybe is able to be loaded by this class
\r
144 //! based on the file extension (e.g. ".zip")
\r
145 bool isALoadableFileFormat(const io::path& filename) const override;
\r
147 //! Check if the file might be loaded by this class
\r
148 /** Check might look into the file.
\r
149 \param file File handle to check.
\r
150 \return True if file seems to be loadable. */
\r
151 bool isALoadableFileFormat(io::IReadFile* file) const override;
\r
153 //! Check to see if the loader can create archives of this type.
\r
154 /** Check based on the archive type.
\r
155 \param fileType The archive type to check.
\r
156 \return True if the archile loader supports this type, false if not */
\r
157 bool isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const override;
\r
159 //! Creates an archive from the filename
\r
160 /** \param file File handle to check.
\r
161 \return Pointer to newly created archive, or 0 upon error. */
\r
162 IFileArchive* createArchive(const io::path& filename, bool ignoreCase, bool ignorePaths) const override;
\r
164 //! creates/loads an archive from the file.
\r
165 //! \return Pointer to the created archive. Returns 0 if loading failed.
\r
166 io::IFileArchive* createArchive(io::IReadFile* file, bool ignoreCase, bool ignorePaths) const override;
\r
169 io::IFileSystem* FileSystem;
\r
173 Zip file Reader written April 2002 by N.Gebhardt.
\r
175 class CZipReader : public virtual IFileArchive, virtual CFileList
\r
180 CZipReader(IFileSystem* fs, IReadFile* file, bool ignoreCase, bool ignorePaths, bool isGZip=false);
\r
183 virtual ~CZipReader();
\r
185 //! opens a file by file name
\r
186 IReadFile* createAndOpenFile(const io::path& filename) override;
\r
188 //! opens a file by index
\r
189 IReadFile* createAndOpenFile(u32 index) override;
\r
191 //! returns the list of files
\r
192 const IFileList* getFileList() const override;
\r
194 //! get the archive type
\r
195 E_FILE_ARCHIVE_TYPE getType() const override;
\r
197 //! return the id of the file Archive
\r
198 const io::path& getArchiveName() const override {return Path;}
\r
202 //! reads the next file header from a ZIP file, returns false if there are no more headers.
\r
203 /* if ignoreGPBits is set, the item will be read despite missing
\r
204 file information. This is used when reading items from the central
\r
206 bool scanZipHeader(bool ignoreGPBits=false);
\r
208 //! the same but for gzip files
\r
209 bool scanGZipHeader();
\r
211 bool scanCentralDirectoryHeader();
\r
213 io::IFileSystem* FileSystem;
\r
216 // holds extended info about files
\r
217 core::array<SZipFileEntry> FileInfo;
\r
223 } // end namespace io
\r
224 } // end namespace irr
\r
226 #endif // __C_ZIP_READER_H_INCLUDED__
\r