2

I'm writing a cross-platform game (in C++) called Bombz and I need a way to read/write users' settings etc, which will also include records of which levels have been completed. Something like an ini file parser will be fine, and it doesn't really need to be efficient and/or scaleable - I can read all the settings at start-up instead of looking up named keys on the fly.

I've found a few simple ini file parsers but they overlook the question of where to store the files and it looks like I might have to write all this stuff myself. Should I just use something like:

  • Windows: $APPDATA/realh/Bombz/config
  • Mac: $HOME/Library/Bombz/config
  • Linux etc: $HOME/.bombz/config (or use the XDG spec)

where I look up $HOME or $APPDATA with getenv()? I know there are "better approved" ways of looking that up in Windows but I'm a Linux guy and I don't want to have to deal with the Windows API directly.

Wolf
  • 9,679
  • 7
  • 62
  • 108
realh
  • 962
  • 2
  • 7
  • 22
  • Why not store the settings in the game directory folder? – Thomas Russell Jul 20 '12 at 15:49
  • 2
    @Shaktal: because that's bad pratice - you will probably not even have write access – ltjax Jul 20 '12 at 15:51
  • http://doc.trolltech.com/4.6/qdir.html#homePath if you can use QT – parapura rajkumar Jul 20 '12 at 16:11
  • 1
    I don't know Qt, but I do know glib (I'm more of a C than C++ fan) and that does provide all the functions I need to solve this problem. However, I don't want to include such a big library just for a few simple functions like this. – realh Jul 20 '12 at 19:35

1 Answers1

2

Well, it's quite interesting -- someone trying to write a game without calling OS-functions. Quite a challenge.

Other than that, if you don't want to call SHGetKnownFolderPath() then environment variables are your only bet. Although for myself, I don't even trust $HOME on Linux -- I use getpwuid_r(). And NSHomeDirectory() on MacOS.

Christian Stieber
  • 9,954
  • 24
  • 23
  • 1
    I'm using SDL which takes care of nearly everything I need for a game, but it doesn't have anything to handle settings or file locations. – realh Jul 20 '12 at 19:32
  • 5
    I think if anyone changed HOME on Linux they'd probably have a good (at least to them) reason to do so and would probably prefer a game to honour it than to insist on using what the system imposed that they evidently disliked. – realh Jul 20 '12 at 19:38