Sign in to follow this  
yckx

registry vs. INI files

Recommended Posts

yckx    1298
I have an app that stores some variables (such as resolution) in an INI file using Get/WritePrivateProfileString. It works fine. But the Win32 SDK says of these functions: "This function is provided only for compatibility with 16-bit Windows-based applications. Applications should store initialization information in the registry." Now, I'm all for Doing Things Correctly, but I'm leery of messing with the Registry, because I'm not at all familiar with it. I'm willing to jump in if it's really a good idea, but I don't know if it's a good idea. Can I get some thoughts on the issue? Thanks.

Share this post


Link to post
Share on other sites
AllTheLuck    126
I don't know anything about the windows registry, but if you are concerned about portability stick with the .ini file.

I am currious what storing data in the windows registry entails.

Share this post


Link to post
Share on other sites
frob    44908
Quote:
Original post by yckx
I have an app that stores some variables (such as resolution) in an INI file using Get/WritePrivateProfileString. It works fine. But the Win32 SDK says of these functions: "This function is provided only for compatibility with 16-bit Windows-based applications. Applications should store initialization information in the registry."

Now, I'm all for Doing Things Correctly, but I'm leery of messing with the Registry, because I'm not at all familiar with it. I'm willing to jump in if it's really a good idea, but I don't know if it's a good idea. Can I get some thoughts on the issue?

Thanks.

You can do either.

Placing them in the registry isn't that hard, it's explained in MSDN.

The biggest benefits of using the registry over INI files are security and administration. It is easier for administrators to manage or restrict access to changing configurations. The user might not have permission to edit in the INI file's directory, but probably has access to their Current User registry tree.


Some benefits for INI files over the registry are that it is easier to back up, delete, or move between machines.

INI files aren't supported by the .NET framework (they might be in 2.0). There are a bunch of classes that do manual INI file processing and p/invoke INI file processing. Use google to help pick one that meets your needs. If you want to roll your own, you can p/invoke the older functions.

frob.

Share this post


Link to post
Share on other sites
KulSeran    3267
Use an INI file over the regestry.

-I like backing up my files for a game before uninstalling it. This includes saves, but it is nice if I can save my keybindings and other settings.
Some sort of settings file makes this easy.
-You can't use a regestry in Linux that I know of. So if you ever port the game...
-Info in the regestry is lost if you reinstall windows. But reinstalling windows should not mean that you must reinstall the game. If all the files are still on your computer, then why be forced to delete them and reinstall the game?

*just my 2 cents.

Share this post


Link to post
Share on other sites
yckx    1298
Quote:
Original post by TrueTom
But please put your ini-files in the users home directory (so everybody can have different settings).

Ah, good call. I hadn't thought of that. I think I'll keep the INI file, and make the change to place it in the user's home directory.

Share this post


Link to post
Share on other sites
jperalta    356
Quote:
Original post by Arild Fines
One should also note that MS themselves are now advising against the use of the registry in favour of XML-based configuration files in .NET.

Registry, I hardly knew ye.


Both methods are rather trivial tasks, however, in .NET with classes included to do the work. Also note that in the new Microsoft Command Shell you can browse the registry just like any other filesystem 'cd hkcu:' f.e. changes you to the root of HKEY_CURRENT_USER.

Share this post


Link to post
Share on other sites
Spoonbender    1258
I hate the registry. Avoid cluttering it if you possibly can. That way, the rest of us won't have to reinstall Windows every week to keep the bloat down to a manageable level. And if something goes wrong, it's a hell of a lot easier to delete a .ini file, than to trawl through the registry just to find those couple of keys left behind by your program.

I don't care what MS recommends, but I prefer programs to avoid using the registry more than neccesary.

Share this post


Link to post
Share on other sites
markr    1692
It's your program. Store your config stuff how you like, but try not to break the rules too much. Storing configuration settings in the right part of the registry, or in the *correct* place in the filesystem (which is often in the user's home directory somewhere), is fine.

As far as I'm aware, ini files are largely deprecated, probably because they can't usefully store unicode text data.

Or rather, they can't store unicode text data if you use the windows functions to read/write them. You could of course make your own ini file format which is exactly like a classic .ini file except in UTF-8.

Mark

Share this post


Link to post
Share on other sites
Anon Mike    1098
Part of the reason the registry gets a bad rap is that many (many!) programs abuse it. It's not meant to store megabytes of data. Nor are you supposed to create hundreds of entries scattered all over the place. Nor should your app crash if somebody goes and edits/deletes something.

You use the registry to override default per-user settings.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this