summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9dc9fb8)
raw | patch | inline | side by side (parent: 9dc9fb8)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Tue, 12 Apr 2016 04:18:10 +0000 (07:18 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Tue, 12 Apr 2016 04:18:10 +0000 (07:18 +0300) |
src/sfs/sfs.pas | patch | blob | history | |
src/shared/WADEDITOR.pas | patch | blob | history |
diff --git a/src/sfs/sfs.pas b/src/sfs/sfs.pas
index 14919a4cb2f1f8df67e57cd56554a5d719bf4dc9..0f2ff81379c0802bb6936867fa1ee693d17dc1e5 100644 (file)
--- a/src/sfs/sfs.pas
+++ b/src/sfs/sfs.pas
// ïðåîáðàçîâàòü ÷èñëî â ñòðîêó, êðàñèâî ðàçáàâëÿÿ çàïÿòûìè
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
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 = '\';
index 0a80f51d4d43091f3be64900719c3180a498e588..079dc7d508d3464e1328a72496cc24c7e5699b62 100644 (file)
--- a/src/shared/WADEDITOR.pas
+++ b/src/shared/WADEDITOR.pas
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;