Save data on Windows and OS X

Started by
7 comments, last by Oluseyi 13 years, 9 months ago
My project is concurrently being ported to the Windows, Mac OS X, and Linux (and similar *nix) platforms. On Windows and on Mac, where is the preferred place to store a game's save files? On the Linux port, it is stored in '$HOME/.appname'. On Windows, should it be stored in...

A. the game's program directory, or
B. the current user's application data directory?

I've seen both used by games, but A appears to be more common. This would allow the user to access their save data from any profile, but B would protect the user's data from other users.

Similarly, on OS X, should the save data be stored in...

A. the game's .app (which itself is a directory when you look under the hood), or
B. in something like '$HOME/.appname', like the Linux port?

I haven't used OS X enough to know these technical details, but I intend to get a Mac in the near future for game development. Until then I'm looking for help on some of these details. Any help is appreciated.
Advertisement
With regards to Windows, don't go saving anything in the program directory! Keep in mind that your application probably won't even have write access to its own folder, at least on Vista and later. The best place to store this data is in the user's data directory, which can be obtained via SHGetKnownFolderPath (also SHGetFolderPath, which is deprecated, but I don't know if the other function is available prior to Vista). As an added bonus, the user can uninstall the game but still retain their save files if they chose. I'm not sure about other platforms, but I imagine that similar rules apply.
I haven't extensively used any version of Windows after XP, but it appears that they improved security a bit on Vista if program folders are write protected by default. Would GetEnvironmentVariable(_T("APPDATA"), ...) be a good way to get the application data directory on all versions of windows?
I'd recommend just using SHGetFolderPath() - I'd stay clear of environment variables (Although I don't really know if there's any particular reason to avoid them, but I personally wouldn't trust them to stay the same across different Windows versions).
Quote:Original post by Daggerbot
Similarly, on OS X, should the save data be stored in...

A. the game's .app (which itself is a directory when you look under the hood), or
B. in something like '$HOME/.appname', like the Linux port?

$HOME/Library/<Application Name>/
Quote:Original post by Oluseyi
Quote:Original post by Daggerbot
Similarly, on OS X, should the save data be stored in...

A. the game's .app (which itself is a directory when you look under the hood), or
B. in something like '$HOME/.appname', like the Linux port?

$HOME/Library/<Application Name>/

Careful. This will fail on non-english OSX versions (the Library folder may be named differently).

Use QuerySystemFolder(kApplicationSupportFolderType) instead.
Are there any size-restrictions to what you put in these paths? Specifically, are these paths also the best option for DLC (Downloadable Content)?
Quote:Original post by Gamer Gamester
Are there any size-restrictions to what you put in these paths?

File size wise ? None that I know of.

Quote:
Specifically, are these paths also the best option for DLC (Downloadable Content)?

Typically yes. These folders have the advantage of not requiring an elevated token for write access. The main executable location should never be written to once the application was installed, except by an installer for software maintenance purposes (updating, patching, uninstalling, etc). This will require admin privileges on Vista and higher. All user content should be placed in the appropriate user data folders instead.
Quote:Original post by Yann L
Quote:Original post by Oluseyi
$HOME/Library/<Application Name>/

Careful. This will fail on non-english OSX versions (the Library folder may be named differently).

Use QuerySystemFolder(kApplicationSupportFolderType) instead.

Excellent call. Thanks.

This topic is closed to new replies.

Advertisement