Configuration/Setting Data In Reg or File?

Blitz3D Forums/Blitz3D Beginners Area/Configuration/Setting Data In Reg or File?

_PJ_(Posted 2011) [#1]
Sorry for the title.
I am wondering what's the "best" method to retain settings / configuration data, for example, last-opened filenames or resolution settings etc.

Generally, programs tend to either save a file with these settings, or store them in the registry.

To my knowledge, the associated advantage/disadvantages are:

1) Registry: Ought to be quicker than writing to HD?
2) Registry: Safer?
3) File: Easier for user to modify if required?
4) File: Data is not limited to specific fields
5) Registry: Separate specifics can be altered without re-writing entirety

I hope they are understandable enough. Are there any other (more technical, perhaps?) reasons why one could be preferable to another? Are my presumptions above correct?

Admittedly, the amount and type of information that might be stored is a factor, for example, where multiple "player profiles" may be stored, each with unique names, perhaps retrieving them from files would be a lot simpler logisytically etc.


Warner(Posted 2011) [#2]
Personally, I'd prefer a file over the registry. Why would it be safer?
I thinking about the following points:
1. portability - application folder can be moved at any time
2. support - in case of invalid settings, user needs only to remove the file
3. future proof - who knows? maybe security settings change over time
4. less clutter - often uninstalling programs leave registry settings
But then again, I've never been a huge fan of the default stuff. I never make installers, since people need admin right to use them. Software setup and removal shouldn't come with too much hassle, in my opinion.


Rob the Great(Posted 2011) [#3]
In my opinion, either can work just the same, and there doesn't seem to be any real advantage one has over the other. The only thing I can think of is that the registry offers automatic start-with-windows options. If you're designing, say, an online interactive game and you want a tray program which alerts the user when one of their friends is online, you would want that to start with the computer turning on, and I would say that the registry would be the way to go in that situation. Other than that, I don't see a lot of advantages or disadvantages to either.


SLotman(Posted 2011) [#4]
I prefer files a thousand times - then users can modify them without the fear of 'hacking the registry' and 'breaking something in the computer'.

Also, if you plan to port to mac or linux, there's no 'registry' there.


Zethrax(Posted 2011) [#5]
Personally I'd rather not have programs dicking around in my computer's registry unless absolutely necessary. It's simple enough to store the data to a file, and I doubt that storing data in the registry is any quicker or safer.

If you need to store secure data, then I'd look at some sort of encoding. You may also want to look at storing the file in the Application Data folder for the user's account.

Last edited 2011


_PJ_(Posted 2011) [#6]
What if only one value out of xxx is changed? Is there a way to only modify a few bytes of a file without having to re-write the entire file?


Warner(Posted 2011) [#7]
Yes, I believe it is possible. You should open the file using OpenFile, rather than WriteFile. Then, use SeekFile and WriteByte etc. It is a bit more complicated than using WriteFile, because you can overwrite existing data, such as line ends. That will mess up the data in the file a bit. So you can use it mainly to replace data by other data of the same size. Ie: int->int float->float and string[10]->string[10].


_PJ_(Posted 2011) [#8]
Thanks Warner - sounds like Files are the way to go then!