X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fgame%2Fg_main.pas;h=0e349afbbdc61f35e582f3c00d6bf7bcaf147bae;hb=97d60066e65ea8b2377a2a7137c3a0c3cb5d63a4;hp=b0648049143f24291d0b00ea063294c3b5a4df70;hpb=c7827dd408b445f025117f2c5df2a3c0f4622298;p=d2df-sdl.git diff --git a/src/game/g_main.pas b/src/game/g_main.pas index b064804..0e349af 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -29,7 +29,7 @@ procedure CharPress (C: AnsiChar); var {--- TO REMOVE ---} - GameDir: string; + //GameDir: string; {-----------------} {--- Read-only dirs ---} @@ -57,6 +57,9 @@ uses {$INCLUDE ../nogl/noGLuses.inc} {$IFDEF ENABLE_HOLMES} g_holmes, sdlcarcass, fui_ctls, fui_wadread, fui_style, fui_gfx_gl, +{$ENDIF} +{$IFDEF LINUX} + BaseUnix, {$ENDIF} wadreader, e_log, g_window, e_graphics, e_input, g_game, g_console, g_gui, @@ -69,24 +72,109 @@ uses var charbuff: packed array [0..15] of AnsiChar; + binPath: AnsiString = ''; + forceCurrentDir: Boolean = false; + + +function GetBinaryPath (): AnsiString; +{$IFDEF LINUX} +var + //cd: AnsiString; + sl: AnsiString; +{$ENDIF} +begin + result := ExtractFilePath(ParamStr(0)); + {$IFDEF LINUX} + // it may be a symlink; do some guesswork here + sl := fpReadLink(ExtractFileName(ParamStr(0))); + if (sl = ParamStr(0)) then + begin + // use current directory, as we don't have anything better + //result := '.'; + GetDir(0, result); + end; + {$ENDIF} + result := fixSlashes(result); + if (length(result) > 0) and (result[length(result)] <> '/') then result := result+'/'; +end; + procedure InitPath; var i: Integer; rwdir, rodir: AnsiString; + //first: Boolean = true; + + procedure xput (s: AnsiString); + { + var + f: TextFile; + begin + AssignFile(f, 'zzz.log'); + if (first) then + begin + Rewrite(f); + first := false; + end + else + begin + Append(f); + end; + writeln(f, s); + CloseFile(f); + end; + } + begin + end; - procedure AddPath (var arr: SSArray; str: AnsiString); + procedure AddPath (var arr: SSArray; str: AnsiString; usecwd: Boolean=true); + var + ss: ShortString; begin - SetLength(arr, Length(arr) + 1); - arr[High(arr)] := ExpandFileName(str) + if (length(str) = 0) then exit; + //writeln('NEW PATH(0): ['+str+']'); + if (forceCurrentDir or usecwd) then + begin + str := fixSlashes(ExpandFileName(str)); + end + else + begin + str := fixSlashes(str); + if (not isAbsolutePath(str)) then str := binPath+str; + while (length(str) > 0) do + begin + if (isRootPath(str)) then exit; + if (str[length(str)] = '/') then begin Delete(str, length(str), 1); continue; end; + if (length(str) >= 2) and (Copy(str, length(str)-1, 2) = '/.') then begin Delete(str, length(str)-1, 2); continue; end; + break; + end; + end; + if (length(str) = 0) then exit; + if (length(str) > 255) then + begin + xput('path too long: ['+str+']'); + raise Exception.Create(Format('path "%s" too long', [str])); + end; + for ss in arr do + begin + //writeln('<<<', ss, '>>> : [', str, ']'); + if (ss = str) then exit; + end; + SetLength(arr, Length(arr)+1); + //arr[High(arr)] := ExpandFileName(str); + arr[High(arr)] := str; + //writeln('NEW PATH(1): ['+str+']'); end; procedure AddDef (var arr: SSArray; str: AnsiString); begin - if arr = nil then - AddPath(arr, str) + if (length(arr) = 0) then AddPath(arr, str, false) end; begin - GetDir(0, GameDir); + //GetDir(0, GameDir); + binPath := GetBinaryPath(); + xput('binPath=['+binPath+']'); + + for i := 1 to ParamCount do if (ParamStr(i) = '--cwd') then begin forceCurrentDir := true; break; end; i := 1; while i < ParamCount do @@ -138,7 +226,7 @@ begin AddDef(CacheDirs, 'data/cache'); AddDef(ConfigDirs, '.'); AddDef(MapDownloadDirs, 'maps/downloads'); - AddDef(WadDownloadDirs, 'wad/downloads'); + AddDef(WadDownloadDirs, 'wads/downloads'); AddDef(ScreenshotDirs, 'screenshots'); for i := 0 to High(MapDirs) do @@ -157,7 +245,9 @@ begin LogFileName := e_Catpath(rwdir, 'Doom2DF.log'); {$ENDIF} end - end + end; + + xput('binPath=['+binPath+']'); end; procedure Main(); @@ -171,10 +261,6 @@ begin e_InitLog(LogFileName, TWriteMode.WM_NEWFILE); e_InitWritelnDriver(); - GameWAD := e_FindWad(DataDirs, 'GAME'); - assert(GameWad <> '', 'GAME.WAD not installed?'); - - // e_InitLog(GameDir + '/' + LogFileName, TWriteMode.WM_NEWFILE); e_WriteLog( @@ -187,6 +273,11 @@ begin TMsgType.Notify ); + e_LogWritefln('BINARY PATH: [%s]', [binPath], TMsgType.Notify); + + GameWAD := e_FindWad(DataDirs, 'GAME'); + assert(GameWad <> '', 'GAME.WAD not installed?'); + {$IFDEF HEADLESS} conbufDumpToStdOut := true; {$ENDIF} @@ -266,7 +357,7 @@ begin if assigned(oglInitCB) then oglInitCB; {$ENDIF} - //g_Res_CreateDatabases(); // it will be done before connecting to the server for the first time + //g_Res_CreateDatabases(true); // it will be done before connecting to the server for the first time e_WriteLog('Entering SDLMain', TMsgType.Notify);