From: Ketmar Dark Date: Sun, 17 Apr 2016 04:02:59 +0000 (+0300) Subject: network fix: proper wad searching, case-insensitive names for POSIX systems X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=17c0529fabf8840719502baca9da24e5c14678ae;p=d2df-sdl.git network fix: proper wad searching, case-insensitive names for POSIX systems --- diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index b24022f..ad92f47 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -256,7 +256,7 @@ uses Math, ENet, e_input, e_fixedbuffer, e_graphics, e_log, g_textures, g_gfx, g_sound, g_console, g_basic, g_options, g_main, g_game, g_player, g_map, g_panel, g_items, g_weapons, g_phys, g_gui, - g_language, g_monsters, g_netmaster, + g_language, g_monsters, g_netmaster, sfs, WADEDITOR, MAPDEF; const @@ -2846,11 +2846,21 @@ end; function ReadFile(const FileName: TFileName): AByte; var FileStream : TFileStream; + fname: string; begin + e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName]), MSG_NOTIFY); + fname := findDiskWad(FileName); + if length(fname) = 0 then + begin + e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName]), MSG_FATALERROR); + SetLength(Result, 0); + exit; + end; + e_WriteLog(Format('NETWORK: found file "%s"', [fname]), MSG_NOTIFY); Result := nil; - FileStream:= TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); + FileStream:= TFileStream.Create(fname, fmOpenRead or {fmShareDenyWrite}fmShareDenyNone); try - if FileStream.Size>0 then + if FileStream.Size > 0 then begin SetLength(Result, FileStream.Size); FileStream.Read(Result[0], FileStream.Size); diff --git a/src/shared/WADEDITOR.pas b/src/shared/WADEDITOR.pas index 5c9ca4f..7a4c59e 100644 --- a/src/shared/WADEDITOR.pas +++ b/src/shared/WADEDITOR.pas @@ -49,6 +49,9 @@ const procedure g_ProcessResourceStr (ResourceStr: String; var FileName, SectionName, ResourceName: String); overload; procedure g_ProcessResourceStr (ResourceStr: String; FileName, SectionName, ResourceName: PString); overload; +// return fixed string or empty string +function findDiskWad (fname: string): string; + implementation @@ -56,6 +59,41 @@ uses SysUtils, Classes, BinEditor, e_log, g_options; +function findDiskWad (fname: string): string; +var + path, rfn: string; +begin + result := ''; + path := ExtractFilePath(fname); + rfn := ExtractFileName(fname); + if not sfsFindFileCI(path, rfn) then + begin + //e_WriteLog(Format('TWADEditor_1.ReadFile: error looking for [%s] [%s]', [path, ExtractFileName(fname)]), MSG_NOTIFY); + if SFSStrEqu(ExtractFileExt(fname), '.wad') then + begin + rfn := ChangeFileExt(ExtractFileName(fname), '.pk3'); + //e_WriteLog(Format(' looking for [%s] [%s]', [path, rfn]), MSG_NOTIFY); + if not sfsFindFileCI(path, rfn) then + begin + //e_WriteLog(Format(' looking for [%s] [%s]', [path, rfn]), MSG_NOTIFY); + rfn := ChangeFileExt(ExtractFileName(fname), '.zip'); + if not sfsFindFileCI(path, rfn) then exit; + end; + end + else + begin + exit; + end; + //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; + result := path+rfn; +end; + + procedure g_ProcessResourceStr (ResourceStr: String; var FileName, SectionName, ResourceName: String); var a, i: Integer; @@ -243,37 +281,16 @@ begin Result := False; //e_WriteLog(Format('TWADEditor_1.ReadFile: [%s]', [FileName]), MSG_NOTIFY); FreeWAD(); - path := ExtractFilePath(FileName); - rfn := ExtractFileName(FileName); - if not sfsFindFileCI(path, rfn) then + rfn := findDiskWad(FileName); + if length(rfn) = 0 then begin - //{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 - 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); + e_WriteLog(Format('TWADEditor_1.ReadFile: error looking for [%s]', [FileName]), MSG_NOTIFY); + exit; end; {$IFDEF SFS_DWFAD_DEBUG} if gSFSDebug then e_WriteLog(Format('TWADEditor_1.ReadFile: FOUND [%s]', [rfn]), MSG_NOTIFY); {$ENDIF} // cache this wad - rfn := path+rfn; try if gSFSFastMode then begin @@ -290,17 +307,8 @@ begin 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); + 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;