X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fshared%2FWADEDITOR.pas;h=5c9ca4f35a593c0b9691cce39096edf87f02a547;hb=6dc6f21202599fba3f371fadd612747402776f5f;hp=8da2b385e77822c8b8254564f25dd420f993c973;hpb=74b8cc24c941b92453f71fa9c912db10119acf81;p=d2df-sdl.git diff --git a/src/shared/WADEDITOR.pas b/src/shared/WADEDITOR.pas index 8da2b38..5c9ca4f 100644 --- a/src/shared/WADEDITOR.pas +++ b/src/shared/WADEDITOR.pas @@ -1,6 +1,6 @@ unit WADEDITOR; -{.$DEFINE SFS_DWFAD_DEBUG} +{$DEFINE SFS_DWFAD_DEBUG} interface @@ -53,7 +53,7 @@ procedure g_ProcessResourceStr (ResourceStr: String; FileName, SectionName, Reso implementation uses - SysUtils, Classes, BinEditor, e_log; + SysUtils, Classes, BinEditor, e_log, g_options; procedure g_ProcessResourceStr (ResourceStr: String; var FileName, SectionName, ResourceName: String); @@ -138,22 +138,39 @@ begin end; +function removeExt (s: string): string; +var + i: Integer; +begin + i := length(s)+1; + while (i > 1) and (s[i-1] <> '.') and (s[i-1] <> '/') do Dec(i); + if (i > 1) and (s[i-1] = '.') then + begin + //writeln('[', s, '] -> [', Copy(s, 1, i-2), ']'); + s := Copy(s, 1, i-2); + end; + result := s; +end; + function TWADEditor_1.GetResource (Section, Resource: string; var pData: Pointer; var Len: Integer): Boolean; var f: Integer; fi: TSFSFileInfo; fs: TStream; + fpp: Pointer; //fn: string; begin Result := False; if not isOpen or (fIter = nil) then Exit; + if length(Resource) = 0 then Exit; // just in case if (length(Section) <> 0) and (Section[length(Section)] <> '/') then Section := Section+'/'; - for f := 0 to fIter.Count-1 do + // backwards, due to possible similar names and such + for f := fIter.Count-1 downto 0 do begin fi := fIter.Files[f]; if fi = nil then continue; - //e_WriteLog(Format('DFWAD: searching for [%s : %s] in [%s]; current is [%s : %s] (%d, %d)', [Section, Resource, fFileName, fi.path, fi.name, SFSStrComp(fi.path, Section), SFSStrComp(fi.name, Resource)]), MSG_NOTIFY); - if (SFSStrComp(fi.path, Section) = 0) and (SFSStrComp(fi.name, Resource) = 0) then + //e_WriteLog(Format('DFWAD: searching for [%s : %s] in [%s]; current is [%s : %s]', [Section, Resource, fFileName, fi.path, fi.name]), MSG_NOTIFY); + if {SFSStrEqu}SFSDFPathEqu(fi.path, Section) and SFSStrEqu(removeExt(fi.name), Resource) then begin // i found her! //fn := fFileName+'::'+fi.path+fi.name; @@ -170,10 +187,22 @@ begin end; Len := Integer(fs.size); GetMem(pData, Len); - fs.ReadBuffer(pData^, Len); - fs.Free; + fpp := pData; + try + fs.ReadBuffer(pData^, Len); + fpp := nil; + finally + if fpp <> nil then + begin + FreeMem(fpp); + pData := nil; + Len := 0; + end; + fs.Free; + end; result := true; {$IFDEF SFS_DWFAD_DEBUG} + if gSFSDebug then e_WriteLog(Format('DFWAD: file [%s%s] FOUND in [%s]; size is %d bytes', [Section, Resource, fFileName, Len]), MSG_NOTIFY); {$ENDIF} exit; @@ -195,10 +224,11 @@ begin begin fi := fIter.Files[f]; if fi = nil then continue; - if SFSStrComp(fi.path, Section) = 0 then + if length(fi.name) = 0 then continue; + if {SFSStrEqu}SFSDFPathEqu(fi.path, Section) then begin SetLength(result, Length(result)+1); - result[high(result)] := fi.name; + result[high(result)] := removeExt(fi.name); end; end; end; @@ -206,38 +236,71 @@ end; function TWADEditor_1.ReadFile (FileName: string): Boolean; var - rfn: string; + rfn, path: string; + //f: Integer; + //fi: TSFSFileInfo; begin Result := False; //e_WriteLog(Format('TWADEditor_1.ReadFile: [%s]', [FileName]), MSG_NOTIFY); FreeWAD(); - rfn := FileName; - if not FileExists(rfn) then + path := ExtractFilePath(FileName); + rfn := ExtractFileName(FileName); + if not sfsFindFileCI(path, rfn) then begin - //if length(rfn) >= 4 then e_WriteLog(Format('XXXX TWADEditor_1.ReadFile: [%s] [%s]', [Copy(rfn, length(rfn)-3, 4), Copy(rfn, 1, length(rfn)-4)]), MSG_NOTIFY); - if (length(rfn) >= 4) and (SFSStrComp(Copy(rfn, length(rfn)-3, 4), '.wad') = 0) then + //{if gSFSDebug then} e_WriteLog(Format('TWADEditor_1.ReadFile: error looking for [%s] [%s]', [path, ExtractFileName(FileName)]), MSG_NOTIFY); + if SFSStrEqu(ExtractFileExt(FileName), '.wad') then + begin + rfn := ChangeFileExt(ExtractFileName(FileName), '.pk3'); + //{if gSFSDebug then} e_WriteLog(Format(' looking for [%s] [%s]', [path, rfn]), MSG_NOTIFY); + if not sfsFindFileCI(path, rfn) then + begin + //{if gSFSDebug then} e_WriteLog(Format(' looking for [%s] [%s]', [path, rfn]), MSG_NOTIFY); + rfn := ChangeFileExt(ExtractFileName(FileName), '.zip'); + if not sfsFindFileCI(path, rfn) then exit; + end; + end + else begin - rfn := Copy(rfn, 1, length(rfn)-4); - if FileExists(rfn+'.pk3') then rfn := rfn+'.pk3' - else if FileExists(rfn+'.zip') then rfn := rfn+'.zip' - else rfn := FileName; - {.$IFDEF SFS_DWFAD_DEBUG} - if FileExists(rfn) then e_WriteLog(Format('TWADEditor_1.ReadFile: FOUND [%s]', [rfn]), MSG_NOTIFY); - {.$ENDIF} + exit; end; + //{if gSFSDebug then} e_WriteLog(Format('TWADEditor_1.ReadFile: FOUND [%s]', [rfn]), MSG_NOTIFY); + end + else + begin + //if rfn <> ExtractFileName(FileName) then e_WriteLog(Format('TWADEditor_1.ReadFile: FOUND [%s]', [rfn]), MSG_NOTIFY); end; - if not FileExists(rfn) then exit; {$IFDEF SFS_DWFAD_DEBUG} - e_WriteLog(Format('TWADEditor_1.ReadFile: FOUND [%s]', [rfn]), MSG_NOTIFY); + if gSFSDebug then e_WriteLog(Format('TWADEditor_1.ReadFile: FOUND [%s]', [rfn]), MSG_NOTIFY); {$ENDIF} // cache this wad - SFSAddDataFile(rfn); + rfn := path+rfn; + try + if gSFSFastMode then + begin + if not SFSAddDataFile(rfn, true) then exit; + end + else + begin + if not SFSAddDataFileTemp(rfn, true) then exit; + end; + except + exit; + end; fIter := SFSFileList(rfn); if fIter = nil then Exit; fFileName := rfn; {$IFDEF SFS_DWFAD_DEBUG} + if gSFSDebug then e_WriteLog(Format('TWADEditor_1.ReadFile: [%s] opened', [fFileName]), MSG_NOTIFY); {$ENDIF} + { + for f := 0 to fIter.Count-1 do + begin + fi := fIter.Files[f]; + if fi = nil then continue; + e_WriteLog(Format('[%s]: [%s : %s] %u', [fFileName, fi.path, fi.name, fi.size]), MSG_NOTIFY); + end; + } Result := True; end; @@ -247,7 +310,6 @@ var function TWADEditor_1.ReadMemory (Data: Pointer; Len: LongWord): Boolean; var - Signature: array[0..4] of Char; fn: string; st: TStream = nil; //f: Integer; @@ -269,7 +331,7 @@ begin try st := TSFSMemoryStreamRO.Create(Data, Len); - if not SFSAddSubDataFile(fn, st) then + if not SFSAddSubDataFile(fn, st, true) then begin st.Free; Exit;