-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWadFile.pas
341 lines (308 loc) · 7.09 KB
/
WadFile.pas
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
unit WadFile;
(*
Copyright 1999,2009 Csabo.
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 3 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, see <http://www.gnu.org/licenses/>.
*)
{$DEFINE FULLVERSION}
interface
Uses
SysUtils, ZipMstr, Globals, Dialogs;
Type
TFileType = ( ftWadFile, Wad2File, Wad3File, DukeFile, Duke2File, QuakeFile, UnrealFile,
SingleFile, SingleLumpFile,
PKFile, RFFFile, WolfFile, WolfAudioFile,
AdrenixFile, DarkForcesFile, DarkForcesLFDFile, LGRESFile,
PIGFile, PIG2File, HOGFile, PODFile, TLKFile, FORMFile, REZFile,
RIDFile, MTIFile, DTIFile, SNIFile, GLBFile, RBXFile, XPRFile,
EOB1File, EOB3File,
ROTH2File, ROTH5File, DASFile, LABFile, CSFile, BLOFile, WRSFile,
KTREZFile, PoziFile, AARESFile, FShockFile,
TRFile, GRFile, QNFile,
JFKWadFile,
ftAll );
Type
TWadEntry = Record
Name : String;
Position, Size : Integer;
//
EntryType : Integer;
End;
Const
MaxWadEntries = 50000;
Type
TWadEntryType = Record
Description : String;
//
FileType : TFileType; // File type
Entry : String; // name match
Size : Integer; // size match
Signature : String; // data header match
SectionStart : String; // section match
SectionEnd : String;
//
Editor : String;
EditorSubCat : String; // subcategory - for ScriptEditor
ExportMethod : String;
Icon : String;
Header : Integer;
//
ColStart : Integer;
Cols : Integer;
End;
Var
//
iWadDirPos : Integer; // file position of wad entry directory
sFileName : String; // name of open file
sEditFile : String; // | file to edit: only PK files have
// | different name than sFileName
sMainWAD : String; // path + filename of 'main' wad file
sLastModifiedDate : String;
iSel, cPos, cLen : Longint;
FileType : TFileType;
//
nWadEntries, nMainWadEntries : Longint;
WadEntries, MainWadEntries : Array [ 1 .. MaxWadEntries ] Of TWadEntry;
//
nWadEntryTypes : Integer;
WadEntryTypes : Array [ 1 .. 1024 ] Of TWadEntryType;
//
local_zipM : TZipMaster;
// ##########################################################################
Function MatchName ( s1, s2 : String ) : Boolean;
Function FindEntryType ( s : String ) : Integer;
Function FindEntryByType ( iEntryType : Integer ) : Integer;
Function FindEntry ( s : String ) : Integer;
Function FindEntryInMain ( s : String ) : Integer;
Function FindEntryInMainFrom ( s : String; iStart : Integer ) : Integer;
Procedure OpenEntry ( iEntry : Integer );
Function IsFileEditable : Boolean;
implementation
Function MatchName ( s1, s2 : String ) : Boolean;
Var
b, bAll : Boolean;
p1, p2 : Integer;
//
i : Integer;
sc, sl : String;
Begin
If s2 = '' Then
MatchName := False
Else
Begin
//
sl := s2;
bAll := False;
//
While sl <> '' Do
Begin
//
i := Pos ( ';', sl ); // check for mupltiple choices
//
If i = 0 Then i := Length ( sl ) + 1; // none found, use whole string
//
sc := Copy ( sl, 1, i - 1 );
sl := Copy ( sl, i + 1, Length ( sl ) - ( i - 1 ) );
//
b := True;
p1 := 1;
p2 := 1;
//
If Pos ( '*', sc ) = 0 Then
Begin
// longer?
If Length ( s1 ) > Length ( sc ) Then
b := False; // yes, no match
End;
//
While b And ( p2 <= Length ( sc ) ) Do
Begin
If ( p1 > Length ( s1 ) ) Then
b := False
Else
Begin
If sc [ p2 ] <> '?' Then // don't check if it's "?"
Begin
If sc [ p2 ] = '*' Then // if it's a "*"...
Begin
p1 := Length ( s1 ) - ( Length ( sc ) - p2 ); // check end of string
If p1 < 1 Then
b := False;
End
Else
Begin
If sc [ p2 ] = '#' Then // numbers only
Begin
If ( s1 [ p1 ] < '0' ) Or ( s1 [ p1 ] > '9' ) Then
Begin
b := False; // not a number
End;
End
Else
Begin
If s1 [ p1 ] <> sc [ p2 ] Then // check one character
b := False;
End;
End;
End;
Inc ( p1 );
Inc ( p2 );
End;
End;
//
bAll := bAll Or b;
End;
//
MatchName := bAll;
End;
End;
Function FindEntryType ( s : String ) : Integer;
Var
i : Integer;
b : Boolean;
Begin
s := UpperCase ( Trim ( s ) );
//
i := 1;
b := False;
While Not b And ( i < nWadEntryTypes ) Do
Begin
If WadEntryTypes [ i ].Description = s Then
b := True
Else
Inc ( i );
End;
//
If Not b Then i := 0;
FindEntryType := i;
End;
Function FindEntryByType ( iEntryType : Integer ) : Integer;
Var
i : Integer;
b : Boolean;
Begin
i := 1;
b := False;
While Not b And ( i <= nWadEntries ) Do
Begin
If WadEntries [ i ].EntryType = iEntryType Then
b := True
Else
Inc ( i );
End;
//
If Not b Then i := 0;
FindEntryByType := i;
End;
Function FindEntry ( s : String ) : Integer;
Var
i : Integer;
b : Boolean;
Begin
s := UpperCase ( Trim ( s ) );
//
i := 1;
b := False;
While Not b And ( i <= nWadEntries ) Do
Begin
If MatchName ( Trim ( WadEntries [ i ].Name ), s ) Then
b := True
Else
Inc ( i );
End;
//
If Not b Then i := 0;
FindEntry := i;
End;
Function FindEntryInMainFrom ( s : String; iStart : Integer ) : Integer;
Var
i : Integer;
b : Boolean;
Begin
s := UpperCase ( Trim ( s ) );
//
i := iStart;
b := False;
While Not b And ( i <= nMainWadEntries ) Do
Begin
If MatchName ( MainWadEntries [ i ].Name, s ) Then
b := True
Else
Inc ( i );
End;
//
If Not b Then i := 0;
FindEntryInMainFrom := i;
End;
Function FindEntryInMain ( s : String ) : Integer;
Begin
FindEntryInMain := FindEntryInMainFrom ( s, 1 );
End;
Procedure OpenEntry ( iEntry : Integer );
{$IFDEF FULLVERSION}
Var
s : String;
sNew : String;
Dummy : File;
{$ENDIF}
Begin
{$IFDEF FULLVERSION}
//
// *** PACK FILE SUPPORT ***
//
If FileType = PKFile Then
Begin
//
// Extract it from the ZIPped file
//
s := WadEntries [ iEntry ].Name;
//
local_zipM.FSpecArgs.Add ( s );
local_zipM.ExtrBaseDir := sTempFolder;
local_zipM.Extract;
//
// rename it to (xwe) in front
// so it gets deleted at the end
//
s := RemoveFolder ( s );
sNew := '(xwe)' + s;
//
If FileExists ( sTempFolder + sNew ) Then
Begin
AssignFile ( Dummy, sTempFolder + sNew );
Erase ( Dummy );
End;
//
If Not FileExists ( sTempFolder + s ) Then
Begin
ShowMessage ( 'File does not exist: ' + sTempFolder + s );
End
Else
Begin
AssignFile ( Dummy, sTempFolder + s );
Rename ( Dummy, sNew );
End;
//
sEditFile := sTempFolder + sNew;
End
Else
Begin
sEditFile := sFileName;
End;
{$ELSE}
sEditFile := sFileName; // Always the same WAD file
{$ENDIF}
End;
Function IsFileEditable : Boolean;
Begin
IsFileEditable := ( FileType = ftWadFile ) Or ( FileType = SingleLumpFile );
End;
end.