views:

461

answers:

9

Hi there,

I'm building an application that is targeting Windows, Mac and Linux soon. I was wondering where should I keep application data such as settings, etc.

Application's installation folder is the easiest choice, but I think that might be a problem with new Vista security model. Besides, users might want different settings.

Is it C:\Documents and Settings\username\MyApp good for both Vista and XP? Is it /home/username/.MyApp good for Linux and Macs?

Any ideas and/or links to best practices much appreciated.

Thanks!

Juan

+11  A: 

Each platform has its own API for finding the user's home folder, or documents folder, or preferences folder.

  • Windows: SHGetFolderPath() or SHGetKnownFolderPath()
  • Mac OS X and iPhone OS: NSSearchPathForDirectoriesInDomains()
  • Unix: $HOME environment variable

Don't hardcode specific paths or just tack a prefix and suffix on the user's name. Also, try to follow whatever conventions there are for the platform for naming the files.

Kristopher Johnson
+2  A: 

Hi,

I'm not :)

I'm using USERPROFILE in Windows and HOME in Mac/Linux. But even so, I need to know that those are the right places.

Thanks!

Zárate
+1  A: 

In windows you need to go another level deep than just the user profile. Use the Application Data folder.

Joel Coehoorn
+1  A: 

Never, ever store user data in the application folder. It's just a bad idea.

Most operating systems have a $HOME (or %HOME%) environment variable. That would be the first place to look.

If you want to cleanly support multiple operating systems, though, you're going to have to have some OS-specific code for each that figures out exactly where things need to go. (~/Library for Mac OS, ~/.config for GNOME-based systems, %HOME%/Application Data for Windows, etc.).

Darcy Casselman
+1  A: 

On Windows I use APPDATA,and on Linux I use HOME.

brian newman
+5  A: 

In regards to best practices, Jeff posted an article on polluting user space that you might find useful: Don't Pollute User Space

Rhett D
Very nice link, thanks. Fun thing is that I'm subscribed to Jeff's blog, I just didn't remember that post. Thanks again!
Zárate
+3  A: 

As a general point, I'd recommend abstracting the implementation of your settings into a 'Settings Provider' and provide different providers for each platform. That way, you can implement the storage of the settings in the manner that best suits the target platforms (for example, a file on Linux or the Windows Registry).

Don't simply adopt the 'lowest common denominator'. Where you have content that must be explicity stored in files, have your settings provider expose the platform-specific location for those files.

Steve Morgan
+2  A: 

For Linux/BSD/Solaris: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

dsvensson
+1  A: 

What language are you planning to use? Java, for example, has a dedicated Preference API.

Michael Borgwardt