views:

163

answers:

5

I am thinking about adding configurable settings to an application, and I think the easiest ways are an external file or win registry (its a win only app).

Which way would be better?

I was wondering, an user with not enough permissions may not be able to create/write the config file. And in the case of the registry, would todays antivirus allow me to add/edit/remove keys? Or they only monitor certain keys?

Also, if someone knows a class/lib to manage config settings (in pure win32) in vc++ please post it.

A: 

I think the new default thing is to write a configuration file in the user's "AppData" folder under the user's folder which should be safe to write/read from.

We're using a simple XML formatted file to store settings; but you could use a INI file type formatting.

Max
A: 

If you save your configuration file in the Application Data directory SHGetFolderPath() with CSIDL_COMMON_APPDATA all users will be able to see the configuration. If you use CSIDL_LOCAL_APPDATA then only the one user will be able to see the configuration. The registry is not necessarily the place to save all configuration data.

gbrandt
+3  A: 

As far as I know:

an user with not enough permissions may not be able to create/write the config file

You should be able to make files inside user's "home directory" or "application data" directory, regardless of permissions. Normally those directories should be writeable.

would todays antivirus allow me to add/edit/remove keys?

Haven't ever seen my antivirus interfere with registry manipulation. You probably will be fine as long as you aren't doing anything suspicious in registry.

Which way would be better?

It is matter of taste. I think that text file is better - allows easier migration of settings. Just don't leave junk behind after uninstall.

Also, if someone knows a class/lib to manage config settings in vc++

QSettings in Qt 4. But using entire Qt for just saving settings is definitely an overkill. You could also check configuration languages like JSON, use lua for settings (less overkill than using Qt 4) or get any XML library. Also, working with registry directly or writing configuration files using iostreams or stdio shouldn't be hard. And you can always write your own configuration library - if you feel like it.

SigTerm
John Dibling
It also depends on what language you're going to use. Pure C++ doesn't offer registry support. You're pretty much stuck reading and writing text files. Yeah you can open them with ease but the parsing and looking for values becomes a PITA if you have a large number of settings to deal with.If you have access to Win32/MFC/COM etc I would highly suggest going with the registry. It's incredibly easy to read/write from and only takes a few lines of code. Encapsulate this in a class and you've got a very elegant re-usable solution.
Justin
A: 

Is "Windows-only" a restriction or a restriction-relief? If you don't mind being cross-platform then I suggest you give boost::program_options a go. The library supports program options through commandline, through evironment-variables and through INI files. Boost's program_options also integrates and glues the various parsers very nicely with variables_map, which you can view as a map between options and their value.

wilhelmtell
+1  A: 

For simple stuff, you might as well just use the registry. However, there are many benefits to a config file... you can save/load several different configs for different uses of your app, it's easier to share or migrate settings between users or machines, etc.

If you end up going the file route, I would recommend Boost's Property Tree library:

http://www.boost.org/doc/libs/1_41_0/doc/html/property_tree.html

It has a pretty nice syntax:

boost::property_tree::ptree properties;

std::string name = properties.get<std::string>("blah.name");
int score = properties.get<int>("blah.score");

properties.put("blah.name", "Inverse");
properties.put("blah.score", 1000);

It also supports reading and writing to various formats, like xml and others.

Inverse