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
64 // return fixed AnsiString or empty AnsiString
68 var
73 implementation
75 uses
80 begin
83 begin
84 //e_WriteLog(Format('findDiskWad: error looking for [%s]', [fname]), MSG_NOTIFY);
86 begin
88 //e_WriteLog(Format(' looking for [%s]', [fname]), MSG_NOTIFY);
90 begin
92 //e_WriteLog(Format(' looking for [%s]', [fname]), MSG_NOTIFY);
95 end
96 else
97 begin
98 exit;
101 //e_WriteLog(Format('findDiskWad: FOUND [%s]', [fname]), MSG_NOTIFY);
107 var
109 begin
115 var
117 begin
119 begin
121 begin
126 exit;
133 var
135 begin
137 begin
139 begin
141 exit;
148 var
150 begin
154 begin
157 begin
159 begin
163 exit;
170 var
172 begin
176 begin
179 begin
181 exit;
188 var
190 begin
193 begin
195 begin
198 exit;
207 { TWADFile }
209 begin
215 begin
222 begin
228 begin
230 //if fFileName <> '' then e_WriteLog(Format('TWADFile.ReadFile: [%s] closed', [fFileName]), MSG_NOTIFY);
235 var
238 begin
243 try
247 except
249 exit;
255 var
257 begin
261 begin
262 //writeln('[', s, '] -> [', Copy(s, 1, i-2), ']');
268 function TWADFile.GetResourceEx (name: AnsiString; wantMap: Boolean; var pData: Pointer; var Len: Integer): Boolean;
269 var
277 begin
284 begin
289 begin
292 end
293 else
294 begin
297 // backwards, due to possible similar names and such
299 begin
303 begin
304 // i found her (maybe)
306 begin
309 begin
311 end
312 else
313 begin
315 if not StrEquCI1251(Copy(fi.path, length(fi.path)+1-length(rpath), length(fi.path)), rpath) then continue; // alas
318 try
320 except
324 begin
327 break;
329 // if we want only maps, check if this is map
330 {$IFDEF SFS_MAPDETECT_FX}
332 begin
334 //e_WriteLog(Format('DFWAD: checking for good map in wad [%s], file [%s] (#%d)', [fFileName, fi.fname, f]), MSG_NOTIFY);
335 try
338 {
339 if goodMap then
340 e_WriteLog(Format(' GOOD map in wad [%s], file [%s] (#%d)', [fFileName, fi.fname, f]), MSG_NOTIFY)
341 else
342 e_WriteLog(Format(' BAD map in wad [%s], file [%s] (#%d)', [fFileName, fi.fname, f]), MSG_NOTIFY);
343 }
344 except
347 begin
348 //e_WriteLog(Format(' not a map in wad [%s], file [%s] (#%d)', [fFileName, fi.fname, f]), MSG_NOTIFY);
350 continue;
354 {$ENDIF}
358 try
361 finally
363 begin
370 {$IFNDEF SFS_MAPDETECT_FX}
372 begin
375 begin
380 begin
381 //e_WriteLog(Format(' not a map in wad [%s], file [%s] (#%d)', [fFileName, fi.fname, f]), MSG_NOTIFY);
385 continue;
388 {$ENDIF}
390 {$IFDEF SFS_DFWAD_DEBUG}
392 e_WriteLog(Format('DFWAD: file [%s] FOUND in [%s]; size is %d bytes', [name, fFileName, Len]), MSG_NOTIFY);
393 {$ENDIF}
394 exit;
400 function TWADFile.GetResource (name: AnsiString; var pData: Pointer; var Len: Integer): Boolean;
401 begin
405 function TWADFile.GetMapResource (name: AnsiString; var pData: Pointer; var Len: Integer): Boolean;
406 begin
411 var
415 begin
419 begin
423 //e_WriteLog(Format('DFWAD: checking for map in wad [%s], file [%s] (#%d)', [fFileName, fi.fname, f]), MSG_NOTIFY);
425 begin
429 begin
434 begin
444 var
446 //f: Integer;
447 //fi: TSFSFileInfo;
448 begin
450 //e_WriteLog(Format('TWADFile.ReadFile: [%s]', [FileName]), MSG_NOTIFY);
454 begin
456 exit;
458 {$IFDEF SFS_DFWAD_DEBUG}
460 {$ENDIF}
461 // cache this wad
462 try
464 begin
466 end
467 else
468 begin
471 except
472 exit;
477 {$IFDEF SFS_DFWAD_DEBUG}
478 if wadoptDebug then e_WriteLog(Format('TWADFile.ReadFile: [%s] opened', [fFileName]), MSG_NOTIFY);
479 {$ENDIF}
484 var
488 var
491 //f: Integer;
492 //fi: TSFSFileInfo;
493 begin
497 begin
499 Exit;
504 {$IFDEF SFS_DFWAD_DEBUG}
506 {$ENDIF}
508 try
511 begin
513 Exit;
515 except
517 Exit;
524 {$IFDEF SFS_DFWAD_DEBUG}
525 if wadoptDebug then e_WriteLog(Format('TWADFile.ReadMemory: [%s] opened', [fFileName]), MSG_NOTIFY);
526 {$ENDIF}
528 {
529 for f := 0 to fIter.Count-1 do
530 begin
531 fi := fIter.Files[f];
532 if fi = nil then continue;
533 st := fIter.volume.OpenFileByIndex(f);
534 if st = nil then
535 begin
536 e_WriteLog(Format('[%s]: [%s : %s] CAN''T OPEN', [fFileName, fi.path, fi.name]), MSG_NOTIFY);
537 end
538 else
539 begin
540 e_WriteLog(Format('[%s]: [%s : %s] %u', [fFileName, fi.path, fi.name, st.size]), MSG_NOTIFY);
541 st.Free;
542 end;
543 end;
544 //fIter.volume.OpenFileByIndex(0);
545 }
551 begin