/
dd_wad.cpp
203 lines (187 loc) · 5.65 KB
/
dd_wad.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/**
* @file dd_wad.cpp
*
* Wrapper API for accessing data stored in DOOM WAD files.
*
* @ingroup resource
*
* @author Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright © 2006-2012 Daniel Swanson <danij@dengine.net>
* @author Copyright © 1993-1996 by id Software, Inc.
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#include <ctime>
#include "de_base.h"
#include "de_console.h"
#include "de_filesys.h"
#include "lumpindex.h"
using namespace de;
#if _DEBUG
# define W_Error Con_Error
#else
# define W_Error Con_Message
#endif
size_t W_LumpLength(lumpnum_t absoluteLumpNum)
{
try
{
lumpnum_t lumpNum = absoluteLumpNum;
return App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).info().size;
}
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_LumpLength: Invalid lumpnum %i.", absoluteLumpNum);
}
return 0;
}
AutoStr* W_LumpName(lumpnum_t absoluteLumpNum)
{
try
{
lumpnum_t lumpNum = absoluteLumpNum;
String const& name = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).name();
QByteArray nameUtf8 = name.toUtf8();
return AutoStr_FromTextStd(nameUtf8.constData());
}
catch(FS1::NotFoundError const&)
{
W_Error("W_LumpName: Invalid lumpnum %i.", absoluteLumpNum);
}
return AutoStr_NewStd();
}
uint W_LumpLastModified(lumpnum_t absoluteLumpNum)
{
try
{
lumpnum_t lumpNum = absoluteLumpNum;
return App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).info().lastModified;
}
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_LumpLastModified: Invalid lumpnum %i.", absoluteLumpNum);
}
return 0;
}
AutoStr* W_LumpSourceFile(lumpnum_t absoluteLumpNum)
{
try
{
lumpnum_t lumpNum = absoluteLumpNum;
de::File1 const& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum);
QByteArray path = lump.container().composePath().toUtf8();
return AutoStr_FromText(path.constData());
}
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_LumpSourceFile: Invalid lumpnum %i.", absoluteLumpNum);
}
return AutoStr_NewStd();
}
boolean W_LumpIsCustom(lumpnum_t absoluteLumpNum)
{
try
{
lumpnum_t lumpNum = absoluteLumpNum;
de::File1 const& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum);
return lump.container().hasCustom();
}
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_LumpIsCustom: Invalid lumpnum %i.", absoluteLumpNum);
}
return false;
}
lumpnum_t W_CheckLumpNumForName2(char const* name, boolean silent)
{
lumpnum_t lumpNum;
if(!name || !name[0])
{
if(!silent)
VERBOSE2( Con_Message("Warning: W_CheckLumpNumForName: Empty name, returning invalid lumpnum.\n") )
return -1;
}
lumpNum = App_FileSystem()->lumpNumForName(name);
if(!silent && lumpNum < 0)
VERBOSE2( Con_Message("Warning: W_CheckLumpNumForName: Lump \"%s\" not found.\n", name) )
return lumpNum;
}
lumpnum_t W_CheckLumpNumForName(char const* name)
{
return W_CheckLumpNumForName2(name, (verbose < 2));
}
lumpnum_t W_GetLumpNumForName(char const* name)
{
lumpnum_t lumpNum = W_CheckLumpNumForName(name);
if(lumpNum < 0)
{
W_Error("W_GetLumpNumForName: Lump \"%s\" not found.", name);
}
return lumpNum;
}
size_t W_ReadLump(lumpnum_t absoluteLumpNum, uint8_t* buffer)
{
try
{
lumpnum_t lumpNum = absoluteLumpNum;
de::File1& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum);
return lump.read(buffer, 0, lump.size());
}
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_ReadLump: Invalid lumpnum %i.", absoluteLumpNum);
}
return 0;
}
size_t W_ReadLumpSection(lumpnum_t absoluteLumpNum, uint8_t* buffer, size_t startOffset, size_t length)
{
try
{
lumpnum_t lumpNum = absoluteLumpNum;
de::File1& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum);
return lump.read(buffer, startOffset, length);
}
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_ReadLumpSection: Invalid lumpnum %i.", absoluteLumpNum);
}
return 0;
}
uint8_t const* W_CacheLump(lumpnum_t absoluteLumpNum)
{
try
{
lumpnum_t lumpNum = absoluteLumpNum;
return App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).cache();
}
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_CacheLump: Invalid lumpnum %i.", absoluteLumpNum);
}
return NULL;
}
void W_UnlockLump(lumpnum_t absoluteLumpNum)
{
try
{
lumpnum_t lumpNum = absoluteLumpNum;
App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).unlock();
}
catch(LumpIndex::NotFoundError const&)
{
W_Error("W_UnlockLump: Invalid lumpnum %i.", absoluteLumpNum);
}
return;
}