开发者

What alternatives to the Windows registry exist to store software configuration settings [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

Closed 9 years ago.

Improve this question

I have a C++ MFC app that stores all of its system wide configuration settings to the registry. Previously, we used .INI files, and changed over to using the registry some years back using

SetRegistryKey("MyCompanyName");

We now get regular support calls from users having difficulty migrating from PC and Windows version to another, and I've come to the conclusion that using the registry causes many more problems than it solves. I don't particularly want to go back to .INI files either as I'd like to store settings per user, so the plan is to write my own versions of the GetProfile... and SetProfile... functions to work with a database. Has anybody done this already, and does anyone know of an existing drop in replacement library for registry usage that wouldn't require too much code modification? Ideally, I'd also like it to hav开发者_开发问答e options to read initial values from the registry to support existing users.


Boost has a library called Boost.PropertyTree that abstracts settings into a hierarchical structure. It can be serialized to a number of formats, such as XML, JSON, and INI.

Store these files in %APPDATA%. Storing them in the same directory as the executable is not a good idea, as %PROGRAMFILES% is not writable by regular users from XP on.


I suggest moving over to an XML file in the same location as the executable. One benefit is that XML is portable across non-Windows machines (and even between Windows versions).

Edit: The idea behind an XML configuration file in the same location as the executable is that the configuration file is for program configurations (not user) and for encapsulation / data hiding (not to pollute global file system directories). User configuration data should be in another file in a directory of the user or user's choice.


You could store a separate INI file for each user though - although I don't know if this is directly supported by WinAPI. At least a lot of applications do this (e.g. TotalCommander).

Update: apparently it is supported by the API.


You can build a system similar to .Net's Isolated Storage, where a configuration file is located in a safe directory, then you can use GetPrivateProfileString to access it.


You could switch to a XML/INI configuration file that's stored in the user's application data folder, or possibly even the My Documents folder. This way the user can copy the file over to preserve their settings.


I stopped using the registry with my last desktop app project and use an INI file stored in the user's %APPDATA% folder instead. If you're only storing strings and integers then an INI file does the job and is easy to edit in Notepad.


Apple uses plist files which basically are XML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜