Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application Settings

What is a fairly standard way for storing application settings, mainly for windows but also easy to move over to other platforms.

There's basically 4 groups of settings I want to have:

  • Global settings, affects all users, and may be moved between machines
  • Global system settings, affects all users, but specific to that system (eg defaults for that system, eg graphics options)
  • User settings, user settings that are moved between systems (eg sound volume)
  • User system settings, user settings specific to that system (eg graphics options that are hardware dependent)

Each level overrides the previous level, allowing for "global settings" to be largly the applications defaults, with user settings storing the options the user chose. The first two will basically be defaults where there is no user setting (eg for a new user).

I considered implementing a set of functions, which I could then implement for the different systems (likely to be through ini files), but is this the best way?

(c++)

namespace config
{
    void Init(const std::string &AppName);
    //updates config for keys/sections that don't exist (ie don't overwrite changes by advanced users by rewriting the entire file)
    void Defaults          (std::map<std::string,std::map<std::string,std::string> > &Map);
    void SystemDefaults    (std::map<std::string,std::map<std::string,std::string> > &Map);

    void Set               (const std::string &Section, const std::string &Key, const std::string &Value);
    void SetSystem         (const std::string &Section, const std::string &Key, const std::string &Value);

    void SetUser           (const std::string &Section, const std::string &Key, const std::string &Value);
    void SetUserSystem     (const std::string &Section, const std::string &Key, const std::string &Value);

    std::string GetValue   (const std::string &Section, const std::string &Key);
}

I know windows has a set of directories for such settings, but are these the correct dirs for my needs?

EDIT: I would rather go with files (ini or xml), rather than using say the windows registery. However wheres the best places to put these config files under each OS?

Under Vista I found these, which seem to fit my groups, however what of older windows versions (I need to support win2000, XP, etc), and does mac/linux have there own simelar folders?

  • Global settings - <SYSDRIVE>\Users\Default\Appdata\Roaming
  • Global system settings - <SYSDRIVE>\Users\Default\Appdata\Local
  • User settings - <SYSDRIVE>\Users\<USER>\AppData\Roaming
  • User system settings - <SYSDRIVE>\Users\<USER>\AppData\Local
like image 669
Fire Lancer Avatar asked Oct 16 '08 13:10

Fire Lancer


1 Answers

If you are a boost user, you might take a look at the program options library, it supports using config files as well as environment variables and (of course) command line options.

It is designed to be portable, so that should ease your cross-platform headaches.

like image 186
paxos1977 Avatar answered Nov 10 '22 17:11

paxos1977