From: Ketmar Dark Date: Tue, 12 Apr 2016 04:18:10 +0000 (+0300) Subject: case-insensitive wad fopen (only filenames, pathes should be in the right case) X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=fd5ef4c3c2e4c56f7b1547318b430a5d10b6860e;p=d2df-sdl.git case-insensitive wad fopen (only filenames, pathes should be in the right case) --- diff --git a/src/sfs/sfs.pas b/src/sfs/sfs.pas index 14919a4..0f2ff81 100644 --- a/src/sfs/sfs.pas +++ b/src/sfs/sfs.pas @@ -206,6 +206,10 @@ function SFSGetLastVirtualName (const fn: TSFSString): string; // ïðåîáðàçîâàòü ÷èñëî â ñòðîêó, êðàñèâî ðàçáàâëÿÿ çàïÿòûìè function Int64ToStrComma (i: Int64): string; +// `name` will be modified +// return `true` if file was found +function sfsFindFileCI (path: string; var name: string): Boolean; + // Wildcard matching // this code is meant to allow wildcard pattern matches. tt is VERY useful // for matching filename wildcard patterns. tt allows unix grep-like pattern @@ -267,6 +271,33 @@ begin end; +// `name` will be modified +function sfsFindFileCI (path: string; var name: string): Boolean; +var + sr: TSearchRec; + bestname: string = ''; +begin + if length(path) = 0 then path := '.'; + while (length(path) > 0) and (path[length(path)] = '/') do Delete(path, length(path), 1); + if (length(path) = 0) or (path[length(path)] <> '/') then path := path+'/'; + if FileExists(path+name) then begin result := true; exit; end; + if FindFirst(path+'*', faAnyFile, sr) = 0 then + repeat + if (sr.name = '.') or (sr.name = '..') then continue; + if (sr.attr and faDirectory) <> 0 then continue; + if sr.name = name then + begin + FindClose(sr); + result := true; + exit; + end; + if (length(bestname) = 0) and SFSStrEqu(sr.name, name) then bestname := sr.name; + until FindNext(sr) <> 0; + FindClose(sr); + if length(bestname) > 0 then begin result := true; name := bestname; end else result := false; +end; + + const // character defines WILD_CHAR_ESCAPE = '\'; diff --git a/src/shared/WADEDITOR.pas b/src/shared/WADEDITOR.pas index 0a80f51..079dc7d 100644 --- a/src/shared/WADEDITOR.pas +++ b/src/shared/WADEDITOR.pas @@ -236,36 +236,49 @@ 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 SFSStrEqu(Copy(rfn, length(rfn)-3, 4), '.wad') 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 := 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 gSFSDebug then - if FileExists(rfn) then e_WriteLog(Format('TWADEditor_1.ReadFile: FOUND [%s]', [rfn]), MSG_NOTIFY); - {.$ENDIF} + 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 + 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} - if gSFSDebug then - 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 not SFSAddDataFile(rfn) then exit; + except + exit; + end; fIter := SFSFileList(rfn); if fIter = nil then Exit; fFileName := rfn;