[lokisetup] Setting the Current Path
Ryan C. Gordon
icculus at clutteredmind.org
Fri Jul 5 14:01:31 EDT 2002
> I'm using Loki Setup as the installation program for one of my games,
> and I was wondering what the common way was to get the path the game's
> installed in. My game is installed in, say, /usr/local/games/my_game,
> and I need to get data out of files in /usr/local/games/my_game/data,
> but internally, my game only has the path as "data/whatever.dat". Is
> there a function for Linux/Win32/MacOS to get the directory the binary
> is being run from, so I could set the current directory to that, or is
> there a better way to do this? Should I have Loki Setup write some sort
> of ~/.my_game/path file and grab that everytime the game starts? What is
> normally done for this?
PhysicsFS has code to determine this at runtime; you can either use that
library, or (if your program is GPL/LGPL) cut-and-paste it from PhysicsFS.
(Look at __PHYSFS_platformCalcBaseDir(). This is the internal means of
determining it under Linux. It will need argv from your main()
function to work).
PhysicsFS has ways to determine this on Win32, MacOS and BeOS, too.
Loki_setup could theoretically write out a file with path information, but
you are in the same boat still; Unix programs can be run from current
working directory that is not the base path of the program, so how would
you know what file to open?
More information about the Lokisetup