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:
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With