aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CWADReader.cpp
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CWADReader.cpp
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CWADReader.cpp526
1 files changed, 263 insertions, 263 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CWADReader.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CWADReader.cpp
index 9945fc8..9ba9d87 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CWADReader.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CWADReader.cpp
@@ -1,263 +1,263 @@
1// Copyright (C) 2002-2012 Thomas Alten 1// Copyright (C) 2002-2012 Thomas Alten
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4// Code contributed by skreamz 4// Code contributed by skreamz
5 5
6#include "IrrCompileConfig.h" 6#include "IrrCompileConfig.h"
7 7
8#ifdef __IRR_COMPILE_WITH_WAD_ARCHIVE_LOADER_ 8#ifdef __IRR_COMPILE_WITH_WAD_ARCHIVE_LOADER_
9 9
10#include "CWADReader.h" 10#include "CWADReader.h"
11#include "os.h" 11#include "os.h"
12#include "coreutil.h" 12#include "coreutil.h"
13 13
14namespace irr 14namespace irr
15{ 15{
16namespace io 16namespace io
17{ 17{
18 18
19//! Constructor 19//! Constructor
20CArchiveLoaderWAD::CArchiveLoaderWAD( io::IFileSystem* fs) 20CArchiveLoaderWAD::CArchiveLoaderWAD( io::IFileSystem* fs)
21: FileSystem(fs) 21: FileSystem(fs)
22{ 22{
23 #ifdef _DEBUG 23 #ifdef _DEBUG
24 setDebugName("CArchiveLoaderWAD"); 24 setDebugName("CArchiveLoaderWAD");
25 #endif 25 #endif
26} 26}
27 27
28 28
29//! returns true if the file maybe is able to be loaded by this class 29//! returns true if the file maybe is able to be loaded by this class
30bool CArchiveLoaderWAD::isALoadableFileFormat(const io::path& filename) const 30bool CArchiveLoaderWAD::isALoadableFileFormat(const io::path& filename) const
31{ 31{
32 return core::hasFileExtension ( filename, "wad" ); 32 return core::hasFileExtension ( filename, "wad" );
33} 33}
34 34
35 35
36//! Creates an archive from the filename 36//! Creates an archive from the filename
37/** \param file File handle to check. 37/** \param file File handle to check.
38\return Pointer to newly created archive, or 0 upon error. */ 38\return Pointer to newly created archive, or 0 upon error. */
39IFileArchive* CArchiveLoaderWAD::createArchive(const io::path& filename, bool ignoreCase, bool ignorePaths) const 39IFileArchive* CArchiveLoaderWAD::createArchive(const io::path& filename, bool ignoreCase, bool ignorePaths) const
40{ 40{
41 IFileArchive *archive = 0; 41 IFileArchive *archive = 0;
42 io::IReadFile* file = FileSystem->createAndOpenFile(filename); 42 io::IReadFile* file = FileSystem->createAndOpenFile(filename);
43 43
44 if (file) 44 if (file)
45 { 45 {
46 archive = createArchive ( file, ignoreCase, ignorePaths ); 46 archive = createArchive ( file, ignoreCase, ignorePaths );
47 file->drop (); 47 file->drop ();
48 } 48 }
49 49
50 return archive; 50 return archive;
51} 51}
52 52
53//! creates/loads an archive from the file. 53//! creates/loads an archive from the file.
54//! \return Pointer to the created archive. Returns 0 if loading failed. 54//! \return Pointer to the created archive. Returns 0 if loading failed.
55IFileArchive* CArchiveLoaderWAD::createArchive(io::IReadFile* file, bool ignoreCase, bool ignorePaths) const 55IFileArchive* CArchiveLoaderWAD::createArchive(io::IReadFile* file, bool ignoreCase, bool ignorePaths) const
56{ 56{
57 IFileArchive *archive = 0; 57 IFileArchive *archive = 0;
58 if ( file ) 58 if ( file )
59 { 59 {
60 file->seek ( 0 ); 60 file->seek ( 0 );
61 archive = new CWADReader(file, ignoreCase, ignorePaths); 61 archive = new CWADReader(file, ignoreCase, ignorePaths);
62 } 62 }
63 return archive; 63 return archive;
64} 64}
65 65
66 66
67//! Check if the file might be loaded by this class 67//! Check if the file might be loaded by this class
68/** Check might look into the file. 68/** Check might look into the file.
69\param file File handle to check. 69\param file File handle to check.
70\return True if file seems to be loadable. */ 70\return True if file seems to be loadable. */
71bool CArchiveLoaderWAD::isALoadableFileFormat(io::IReadFile* file) const 71bool CArchiveLoaderWAD::isALoadableFileFormat(io::IReadFile* file) const
72{ 72{
73 SWADFileHeader header; 73 SWADFileHeader header;
74 memset(&header, 0, sizeof(header)); 74 memset(&header, 0, sizeof(header));
75 75
76 file->read( &header.tag, 4 ); 76 file->read( &header.tag, 4 );
77 77
78 return !strncmp ( header.tag, "WAD2", 4 ) || !strncmp ( header.tag, "WAD3", 4 ); 78 return !strncmp ( header.tag, "WAD2", 4 ) || !strncmp ( header.tag, "WAD3", 4 );
79} 79}
80 80
81//! Check to see if the loader can create archives of this type. 81//! Check to see if the loader can create archives of this type.
82bool CArchiveLoaderWAD::isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const 82bool CArchiveLoaderWAD::isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const
83{ 83{
84 return fileType == EFAT_WAD; 84 return fileType == EFAT_WAD;
85} 85}
86 86
87void createDir ( const c8 *full ); 87void createDir ( const c8 *full );
88 88
89 89
90/*! 90/*!
91 WAD Reader 91 WAD Reader
92*/ 92*/
93CWADReader::CWADReader(IReadFile* file, bool ignoreCase, bool ignorePaths) 93CWADReader::CWADReader(IReadFile* file, bool ignoreCase, bool ignorePaths)
94: CFileList((file ? file->getFileName() : io::path("")), ignoreCase, ignorePaths), File(file) 94: CFileList((file ? file->getFileName() : io::path("")), ignoreCase, ignorePaths), File(file)
95{ 95{
96 #ifdef _DEBUG 96 #ifdef _DEBUG
97 setDebugName("CWADReader"); 97 setDebugName("CWADReader");
98 #endif 98 #endif
99 99
100 if (File) 100 if (File)
101 { 101 {
102 File->grab(); 102 File->grab();
103 103
104 Base = File->getFileName(); 104 Base = File->getFileName();
105 Base.replace ( '\\', '/' ); 105 Base.replace ( '\\', '/' );
106 106
107 // scan local headers 107 // scan local headers
108 scanLocalHeader(); 108 scanLocalHeader();
109 109
110 sort(); 110 sort();
111 } 111 }
112 112
113#if 0 113#if 0
114 for ( u32 i = 0; i < FileList.size(); ++i ) 114 for ( u32 i = 0; i < FileList.size(); ++i )
115 { 115 {
116 SWADFileEntry &e = FileList[i]; 116 SWADFileEntry &e = FileList[i];
117 char buf[128]; 117 char buf[128];
118 snprintf ( buf, 128, "c:\\h2\\%s", e.wadFileName.c_str() ); 118 snprintf ( buf, 128, "c:\\h2\\%s", e.wadFileName.c_str() );
119 119
120 createDir ( buf ); 120 createDir ( buf );
121 FILE * f = fopen ( buf, "wb" ); 121 FILE * f = fopen ( buf, "wb" );
122 if ( 0 == f ) 122 if ( 0 == f )
123 continue; 123 continue;
124 124
125 u8 * mem = new u8 [ e.header.disksize ]; 125 u8 * mem = new u8 [ e.header.disksize ];
126 File->seek ( e.header.filepos ); 126 File->seek ( e.header.filepos );
127 File->read ( mem, e.header.disksize ); 127 File->read ( mem, e.header.disksize );
128 fwrite ( mem, e.header.disksize, 1, f ); 128 fwrite ( mem, e.header.disksize, 1, f );
129 delete [] mem; 129 delete [] mem;
130 fclose ( f ); 130 fclose ( f );
131 } 131 }
132#endif 132#endif
133 133
134} 134}
135 135
136 136
137CWADReader::~CWADReader() 137CWADReader::~CWADReader()
138{ 138{
139 if (File) 139 if (File)
140 File->drop(); 140 File->drop();
141} 141}
142 142
143 143
144//! return the id of the file Archive 144//! return the id of the file Archive
145const io::path& CWADReader::getArchiveName () const 145const io::path& CWADReader::getArchiveName () const
146{ 146{
147 return Base; 147 return Base;
148} 148}
149 149
150const IFileList* CWADReader::getFileList() const 150const IFileList* CWADReader::getFileList() const
151{ 151{
152 return this; 152 return this;
153} 153}
154 154
155 155
156//! scans for a local header, returns false if there is no more local file header. 156//! scans for a local header, returns false if there is no more local file header.
157bool CWADReader::scanLocalHeader() 157bool CWADReader::scanLocalHeader()
158{ 158{
159 SWADFileEntryOriginal entry; 159 SWADFileEntryOriginal entry;
160 SWADFileEntry save; 160 SWADFileEntry save;
161 161
162 memset(&Header, 0, sizeof(SWADFileHeader)); 162 memset(&Header, 0, sizeof(SWADFileHeader));
163 File->read(&Header, sizeof(SWADFileHeader)); 163 File->read(&Header, sizeof(SWADFileHeader));
164 164
165 if ( 0 == strncmp ( Header.tag, "WAD2", 4 ) ) 165 if ( 0 == strncmp ( Header.tag, "WAD2", 4 ) )
166 WadType = WAD_FORMAT_QUAKE2; 166 WadType = WAD_FORMAT_QUAKE2;
167 else 167 else
168 if ( 0 == strncmp ( Header.tag, "WAD3", 4 ) ) 168 if ( 0 == strncmp ( Header.tag, "WAD3", 4 ) )
169 WadType = WAD_FORMAT_HALFLIFE; 169 WadType = WAD_FORMAT_HALFLIFE;
170 else 170 else
171 WadType = WAD_FORMAT_UNKNOWN; 171 WadType = WAD_FORMAT_UNKNOWN;
172 172
173 if ( WadType == WAD_FORMAT_UNKNOWN ) 173 if ( WadType == WAD_FORMAT_UNKNOWN )
174 return false; 174 return false;
175 175
176#ifdef __BIG_ENDIAN__ 176#ifdef __BIG_ENDIAN__
177 Header.numlumps = os::Byteswap::byteswap(Header.numlumps); 177 Header.numlumps = os::Byteswap::byteswap(Header.numlumps);
178 Header.infotableofs = os::Byteswap::byteswap(Header.infotableofs); 178 Header.infotableofs = os::Byteswap::byteswap(Header.infotableofs);
179#endif 179#endif
180 180
181 File->seek ( Header.infotableofs ); 181 File->seek ( Header.infotableofs );
182 182
183 c8 buf[16]; 183 c8 buf[16];
184 for ( u32 i = 0; i < Header.numlumps; ++i ) 184 for ( u32 i = 0; i < Header.numlumps; ++i )
185 { 185 {
186 // read entry 186 // read entry
187 File->read(&entry, sizeof ( SWADFileEntryOriginal )); 187 File->read(&entry, sizeof ( SWADFileEntryOriginal ));
188 entry.name[ sizeof ( entry.name ) - 1 ] = 0; 188 entry.name[ sizeof ( entry.name ) - 1 ] = 0;
189 189
190 save.header = entry; 190 save.header = entry;
191 save.wadFileName = "/"; 191 save.wadFileName = "/";
192 save.wadFileName += entry.name; 192 save.wadFileName += entry.name;
193 193
194 if ( WadType == WAD_FORMAT_HALFLIFE ) 194 if ( WadType == WAD_FORMAT_HALFLIFE )
195 { 195 {
196 // don't know about the types! i'm guessing 196 // don't know about the types! i'm guessing
197 switch ( entry.type ) 197 switch ( entry.type )
198 { 198 {
199 case WAD_TYP_MIPTEX_HALFLIFE: 199 case WAD_TYP_MIPTEX_HALFLIFE:
200 save.wadFileName += ".wal2"; 200 save.wadFileName += ".wal2";
201 break; 201 break;
202 default: 202 default:
203 snprintf ( buf, 16, ".%02d", entry.type ); 203 snprintf ( buf, 16, ".%02d", entry.type );
204 save.wadFileName += buf; 204 save.wadFileName += buf;
205 break; 205 break;
206 } 206 }
207 } 207 }
208 else 208 else
209 if ( WadType == WAD_FORMAT_QUAKE2 ) 209 if ( WadType == WAD_FORMAT_QUAKE2 )
210 { 210 {
211 switch ( entry.type ) 211 switch ( entry.type )
212 { 212 {
213 case WAD_TYP_MIPTEX: save.wadFileName += ".miptex"; break; 213 case WAD_TYP_MIPTEX: save.wadFileName += ".miptex"; break;
214 case WAD_TYP_SOUND: save.wadFileName += ".sound"; break; 214 case WAD_TYP_SOUND: save.wadFileName += ".sound"; break;
215 case WAD_TYP_PALETTE: save.wadFileName += ".palette"; break; 215 case WAD_TYP_PALETTE: save.wadFileName += ".palette"; break;
216 case WAD_TYP_QTEX: save.wadFileName += ".qtex"; break; 216 case WAD_TYP_QTEX: save.wadFileName += ".qtex"; break;
217 case WAD_TYP_QPIC: save.wadFileName += ".qpic"; break; 217 case WAD_TYP_QPIC: save.wadFileName += ".qpic"; break;
218 case WAD_TYP_FONT: save.wadFileName += ".font"; break; 218 case WAD_TYP_FONT: save.wadFileName += ".font"; break;
219 default: 219 default:
220 snprintf ( buf, 16, ".%02d", entry.type ); 220 snprintf ( buf, 16, ".%02d", entry.type );
221 save.wadFileName += buf; 221 save.wadFileName += buf;
222 break; 222 break;
223 } 223 }
224 } 224 }
225 225
226 // add file to list 226 // add file to list
227 addItem(save.wadFileName,save.header.filepos, save.header.disksize, false ); 227 addItem(save.wadFileName,save.header.filepos, save.header.disksize, false );
228 //FileInfo.push_back(save); 228 //FileInfo.push_back(save);
229 } 229 }
230 return true; 230 return true;
231} 231}
232 232
233 233
234//! opens a file by file name 234//! opens a file by file name
235IReadFile* CWADReader::createAndOpenFile(const io::path& filename) 235IReadFile* CWADReader::createAndOpenFile(const io::path& filename)
236{ 236{
237 s32 index = findFile(filename, false); 237 s32 index = findFile(filename, false);
238 238
239 if (index != -1) 239 if (index != -1)
240 return createAndOpenFile(index); 240 return createAndOpenFile(index);
241 241
242 return 0; 242 return 0;
243} 243}
244 244
245 245
246//! opens a file by index 246//! opens a file by index
247IReadFile* CWADReader::createAndOpenFile(u32 index) 247IReadFile* CWADReader::createAndOpenFile(u32 index)
248{ 248{
249 if (index >= Files.size() ) 249 if (index >= Files.size() )
250 return 0; 250 return 0;
251 251
252 const SFileListEntry &entry = Files[index]; 252 const SFileListEntry &entry = Files[index];
253 return createLimitReadFile( entry.FullName, File, entry.Offset, entry.Size ); 253 return createLimitReadFile( entry.FullName, File, entry.Offset, entry.Size );
254} 254}
255 255
256 256
257 257
258} // end namespace io 258} // end namespace io
259} // end namespace irr 259} // end namespace irr
260 260
261 261
262#endif // __IRR_COMPILE_WITH_WAD_ARCHIVE_LOADER_ 262#endif // __IRR_COMPILE_WITH_WAD_ARCHIVE_LOADER_
263 263