Imagine what would happen if you run the program from
CD-ROM, not to mention what might happen if every stupid program could
create files everywhere in the system.
Thanks all for the comments. I was in such a hurry I didnt get a chance
to read the comments before now.
I found the same argv[0] trick you mentioned. I ended up used argv[0]
together with the getcwd and some string manipulation to figure out the
directory of the executable. I understand the format of this string is
not specified in the standard. It however works fine on the specific
platforms i need to port for.
The game writes to nad reads from the same folder as the execute is in.
This seemed like the natural thing to me. That is to keep data that are
owned by the same application together in the same place instead of
scattering it around the system.
But you do bring up an important point. I shouldnt have assumed I have
write permissions to this directory the executable is in.
So if the read/execute folder can be assumed to be the same but the
write folder cant then i need a way to configure the different write
path. I have my read / execute path and to get the write path, i could:
A Hardcoding the write path.
B get the working directory. I cant assume the working directory is the
write directory because of integration issues (the script that launches
the game, launches it from root so root will be working directory.
Since I dont own the platform so i cant change the way the script
works.)
C Game specific enviornment environment variable. Reading some game
specific enviornment variable wont do eighter, because again I do not
own the platform and am not free to install my own game specific
environment variables.
D Using user's home directory. Finding out the current user's home
directory from c++ does not sound very portable eighter. Again id
probably have to read some platform specific enviornment variable.
E Reading the write path from a file. Having a file called
writePath.txt in the same folder as the executable.
I im going to go with the last option.
Regards Patrik