1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE a_modes.inc}
19 {$DEFINE SFS_DFWAD_DEBUG}
20 {$DEFINE SFS_MAPDETECT_FX}
22 interface
24 uses
28 type
32 private
39 function GetResourceEx (name: AnsiString; wantMap: Boolean; var pData: Pointer; var Len: Integer): Boolean;
41 public
54 // returns `nil` if file wasn't found
67 // return fixed AnsiString or empty AnsiString
71 var
76 implementation
78 uses
83 begin
86 begin
87 //e_WriteLog(Format('findDiskWad: error looking for [%s]', [fname]), MSG_NOTIFY);
89 begin
91 //e_WriteLog(Format(' looking for [%s]', [fname]), MSG_NOTIFY);
93 begin
95 //e_WriteLog(Format(' looking for [%s]', [fname]), MSG_NOTIFY);
98 end
99 else
100 begin
101 exit;
104 //e_WriteLog(Format('findDiskWad: FOUND [%s]', [fname]), MSG_NOTIFY);
110 var
112 begin
118 var
120 begin
122 begin
124 begin
129 exit;
136 var
138 begin
140 begin
142 begin
144 exit;
151 var
153 begin
157 begin
160 begin
162 begin
166 exit;
173 var
175 begin
179 begin
182 begin
184 exit;
191 var
193 begin
196 begin
198 begin
201 exit;
210 { TWADFile }
212 begin
218 begin
225 begin
231 begin
233 //if fFileName <> '' then e_WriteLog(Format('TWADFile.ReadFile: [%s] closed', [fFileName]), MSG_NOTIFY);
238 //FIXME: detect text maps properly here
240 var
243 begin
247 try
252 except
254 exit;
260 // returns `nil` if file wasn't found
262 var
265 begin
267 // backwards, due to possible similar names and such
269 begin
273 begin
274 try
276 except
286 var
288 begin
292 begin
293 //writeln('[', s, '] -> [', Copy(s, 1, i-2), ']');
300 function TWADFile.GetResourceEx (name: AnsiString; wantMap: Boolean; var pData: Pointer; var Len: Integer): Boolean;
301 var
309 begin
316 begin
321 begin
324 end
325 else
326 begin
329 // backwards, due to possible similar names and such
331 begin
335 begin
336 // i found her (maybe)
338 begin
341 begin
343 end
344 else
345 begin
347 if not StrEquCI1251(Copy(fi.path, length(fi.path)+1-length(rpath), length(fi.path)), rpath) then continue; // alas
350 try
352 except
356 begin
359 break;
361 // if we want only maps, check if this is map
362 {$IFDEF SFS_MAPDETECT_FX}
364 begin
366 {$IF DEFINED(D2D_NEW_MAP_READER_DBG)}
367 e_LogWritefln('DFWAD: checking for good map in wad [%s], file [%s] (#%d)', [fFileName, fi.fname, f]);
368 {$ENDIF}
369 try
373 {$IF DEFINED(D2D_NEW_MAP_READER_DBG)}
376 else
378 {$ENDIF}
379 except
382 begin
383 {$IF DEFINED(D2D_NEW_MAP_READER_DBG)}
385 {$ENDIF}
387 continue;
391 {$ENDIF}
395 try
398 finally
400 begin
407 {$IFNDEF SFS_MAPDETECT_FX}
409 begin
412 begin
417 begin
418 //e_WriteLog(Format(' not a map in wad [%s], file [%s] (#%d)', [fFileName, fi.fname, f]), MSG_NOTIFY);
422 continue;
425 {$ENDIF}
427 {$IFDEF SFS_DFWAD_DEBUG}
429 e_WriteLog(Format('DFWAD: file [%s] FOUND in [%s]; size is %d bytes', [name, fFileName, Len]), MSG_NOTIFY);
430 {$ENDIF}
431 exit;
437 function TWADFile.GetResource (name: AnsiString; var pData: Pointer; var Len: Integer): Boolean;
438 begin
442 function TWADFile.GetMapResource (name: AnsiString; var pData: Pointer; var Len: Integer): Boolean;
443 begin
448 var
452 begin
456 begin
460 {$IF DEFINED(D2D_NEW_MAP_READER)}
461 //e_LogWritefln('DFWAD: checking for map in wad [%s], file [%s] (#%d)', [fFileName, fi.fname, f]);
462 {$ENDIF}
464 begin
468 begin
473 begin
483 var
485 //f: Integer;
486 //fi: TSFSFileInfo;
487 begin
489 //e_WriteLog(Format('TWADFile.ReadFile: [%s]', [FileName]), MSG_NOTIFY);
493 begin
495 exit;
497 {$IFDEF SFS_DFWAD_DEBUG}
499 {$ENDIF}
500 // cache this wad
501 try
503 begin
505 end
506 else
507 begin
510 except
511 exit;
516 {$IFDEF SFS_DFWAD_DEBUG}
517 if wadoptDebug then e_WriteLog(Format('TWADFile.ReadFile: [%s] opened', [fFileName]), MSG_NOTIFY);
518 {$ENDIF}
523 var
527 var
530 //f: Integer;
531 //fi: TSFSFileInfo;
532 begin
536 begin
538 Exit;
543 {$IFDEF SFS_DFWAD_DEBUG}
545 {$ENDIF}
547 try
550 begin
552 Exit;
554 except
556 Exit;
563 {$IFDEF SFS_DFWAD_DEBUG}
564 if wadoptDebug then e_WriteLog(Format('TWADFile.ReadMemory: [%s] opened', [fFileName]), MSG_NOTIFY);
565 {$ENDIF}
567 {
568 for f := 0 to fIter.Count-1 do
569 begin
570 fi := fIter.Files[f];
571 if fi = nil then continue;
572 st := fIter.volume.OpenFileByIndex(f);
573 if st = nil then
574 begin
575 e_WriteLog(Format('[%s]: [%s : %s] CAN''T OPEN', [fFileName, fi.path, fi.name]), MSG_NOTIFY);
576 end
577 else
578 begin
579 e_WriteLog(Format('[%s]: [%s : %s] %u', [fFileName, fi.path, fi.name, st.size]), MSG_NOTIFY);
580 st.Free;
581 end;
582 end;
583 //fIter.volume.OpenFileByIndex(0);
584 }
590 begin