]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CZipReader.h
Reduce IrrCompileConfig usage to files that actually need it
[irrlicht.git] / source / Irrlicht / CZipReader.h
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
4 \r
5 #ifndef __C_ZIP_READER_H_INCLUDED__\r
6 #define __C_ZIP_READER_H_INCLUDED__\r
7 \r
8 \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
14 \r
15 namespace irr\r
16 {\r
17 namespace io\r
18 {\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
24 \r
25 // byte-align structures\r
26 #include "irrpack.h"\r
27 \r
28         struct SZIPFileDataDescriptor\r
29         {\r
30                 u32 CRC32;\r
31                 u32 CompressedSize;\r
32                 u32 UncompressedSize;\r
33         } PACK_STRUCT;\r
34 \r
35         struct SZIPFileHeader\r
36         {\r
37                 u32 Sig;                                // 'PK0304' little endian (0x04034b50)\r
38                 s16 VersionToExtract;\r
39                 s16 GeneralBitFlag;\r
40                 s16 CompressionMethod;\r
41                 s16 LastModFileTime;\r
42                 s16 LastModFileDate;\r
43                 SZIPFileDataDescriptor DataDescriptor;\r
44                 s16 FilenameLength;\r
45                 s16 ExtraFieldLength;\r
46                 // filename (variable size)\r
47                 // extra field (variable size )\r
48         } PACK_STRUCT;\r
49 \r
50         struct SZIPFileCentralDirFileHeader\r
51         {\r
52                 u32 Sig;        // 'PK0102' (0x02014b50)\r
53                 u16 VersionMadeBy;\r
54                 u16 VersionToExtract;\r
55                 u16 GeneralBitFlag;\r
56                 u16 CompressionMethod;\r
57                 u16 LastModFileTime;\r
58                 u16 LastModFileDate;\r
59                 u32 CRC32;\r
60                 u32 CompressedSize;\r
61                 u32 UncompressedSize;\r
62                 u16 FilenameLength;\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
69 \r
70                 // filename (variable size)\r
71                 // extra field (variable size)\r
72                 // file comment (variable size)\r
73 \r
74         } PACK_STRUCT;\r
75 \r
76         struct SZIPFileCentralDirEnd\r
77         {\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
87         } PACK_STRUCT;\r
88 \r
89         struct SZipFileExtraHeader\r
90         {\r
91                 s16 ID;\r
92                 s16 Size;\r
93         } PACK_STRUCT;\r
94 \r
95         struct SZipFileAESExtraData\r
96         {\r
97                 s16 Version;\r
98                 u8 Vendor[2];\r
99                 u8 EncryptionStrength;\r
100                 s16 CompressionMode;\r
101         } PACK_STRUCT;\r
102 \r
103         enum E_GZIP_FLAGS\r
104         {\r
105                 EGZF_TEXT_DAT      = 1,\r
106                 EGZF_CRC16         = 2,\r
107                 EGZF_EXTRA_FIELDS  = 4,\r
108                 EGZF_FILE_NAME     = 8,\r
109                 EGZF_COMMENT       = 16\r
110         };\r
111 \r
112         struct SGZIPMemberHeader\r
113         {\r
114                 u16 sig; // 0x8b1f\r
115                 u8  compressionMethod; // 8 = deflate\r
116                 u8  flags;\r
117                 u32 time;\r
118                 u8  extraFlags; // slow compress = 2, fast compress = 4\r
119                 u8  operatingSystem;\r
120         } PACK_STRUCT;\r
121 \r
122 // Default alignment\r
123 #include "irrunpack.h"\r
124 \r
125         //! Contains extended info about zip files in the archive\r
126         struct SZipFileEntry\r
127         {\r
128                 //! Position of data in the archive file\r
129                 s32 Offset;\r
130 \r
131                 //! The header for this file containing compression info etc\r
132                 SZIPFileHeader header;\r
133         };\r
134 \r
135         //! Archiveloader capable of loading ZIP Archives\r
136         class CArchiveLoaderZIP : public IArchiveLoader\r
137         {\r
138         public:\r
139 \r
140                 //! Constructor\r
141                 CArchiveLoaderZIP(io::IFileSystem* fs);\r
142 \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
146 \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
152 \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
158 \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
163 \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
167 \r
168         private:\r
169                 io::IFileSystem* FileSystem;\r
170         };\r
171 \r
172 /*!\r
173         Zip file Reader written April 2002 by N.Gebhardt.\r
174 */\r
175         class CZipReader : public virtual IFileArchive, virtual CFileList\r
176         {\r
177         public:\r
178 \r
179                 //! constructor\r
180                 CZipReader(IFileSystem* fs, IReadFile* file, bool ignoreCase, bool ignorePaths, bool isGZip=false);\r
181 \r
182                 //! destructor\r
183                 virtual ~CZipReader();\r
184 \r
185                 //! opens a file by file name\r
186                 IReadFile* createAndOpenFile(const io::path& filename) override;\r
187 \r
188                 //! opens a file by index\r
189                 IReadFile* createAndOpenFile(u32 index) override;\r
190 \r
191                 //! returns the list of files\r
192                 const IFileList* getFileList() const override;\r
193 \r
194                 //! get the archive type\r
195                 E_FILE_ARCHIVE_TYPE getType() const override;\r
196 \r
197                 //! return the id of the file Archive\r
198                 const io::path& getArchiveName() const override {return Path;}\r
199 \r
200         protected:\r
201 \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
205                 directory. */\r
206                 bool scanZipHeader(bool ignoreGPBits=false);\r
207 \r
208                 //! the same but for gzip files\r
209                 bool scanGZipHeader();\r
210 \r
211                 bool scanCentralDirectoryHeader();\r
212 \r
213                 io::IFileSystem* FileSystem;\r
214                 IReadFile* File;\r
215 \r
216                 // holds extended info about files\r
217                 core::array<SZipFileEntry> FileInfo;\r
218 \r
219                 bool IsGZip;\r
220         };\r
221 \r
222 \r
223 } // end namespace io\r
224 } // end namespace irr\r
225 \r
226 #endif // __C_ZIP_READER_H_INCLUDED__\r