PDA

Click to See Complete Forum and Search --> : Saving and Retreiving Program Settings


GamerMax5
Aug 28th, 2007, 01:09 AM
I've been curious as to how to save and retreive program settings utilizing other methods that are more efficent than storing them in a plain text file. For instance, say I wanted to use a configuration file, how would I read and write to a file like that? I'd imagine that I'd have to write code that would read the file at program boot and adjust the settings of the program accordingly. But more or less I'm wondering if there are any more efficent methods than reading and writing to text files. Thanks in advance.

tr333
Aug 28th, 2007, 02:07 AM
The only other methods I can think of are serializing an internal data structure and writing this to a binary file, or using an XML file for the preferences. Most languages should have the capability to parse XML files, so this should be faster than using a standard text file (ala .ini files).

Hack
Aug 28th, 2007, 06:03 AM
We used to use the registry, but more and more, our customer's IT shops started rolling out desktops and laptops to their employee's with lock down registrys.

That prompted us to switch to using a user preference table in our backend database and this has worked very well. One of the things people like about it is that is stored per user Id (windows login) so the settings "rove". Because the settings are available in a DB table, they are set regardless of what machine the user logs into.

GamerMax5
Aug 28th, 2007, 09:55 AM
The only other methods I can think of are serializing an internal data structure and writing this to a binary file, or using an XML file for the preferences. Most languages should have the capability to parse XML files, so this should be faster than using a standard text file (ala .ini files).

Now that you mention it, I was thinking about this the other day. Since I'm writing the program in Java, storing the configuration in an XML format would be most ideal.


That prompted us to switch to using a user preference table in our backend database and this has worked very well. One of the things people like about it is that is stored per user Id (windows login) so the settings "rove". Because the settings are available in a DB table, they are set regardless of what machine the user logs into.

That's very interesting. As a really cheesy example, you could have User1 logon to ComputerA and set up a desktop wallpaper. Then you have User1 logon to ComputerH and the desktop wallpaper would apply there as well because the settings aren't restricted by the local machine. Very nice. I definitely want to look into that.

tr333
Aug 28th, 2007, 11:30 AM
Since I'm writing the program in Java, storing the configuration in an XML format would be most ideal.
I haven't touched Java for a while, but a quick search of the API docs found the following which may be useful for serializing a class to a file:

Serializable (http://www.cse.unsw.edu.au/~java/documentation/jdk1.5.0/api/java/io/Serializable.html)
Externalizable (http://www.cse.unsw.edu.au/~java/documentation/jdk1.5.0/api/java/io/Externalizable.html)
ObjectOutputStream (http://www.cse.unsw.edu.au/~java/documentation/jdk1.5.0/api/java/io/ObjectOutputStream.html)

Serializing would be useful if you have an internal preferences class, since it is quick and easy. Probably not as portable as the database method though.

GamerMax5
Aug 30th, 2007, 10:45 AM
Here's my question though. Would it be more portable to use XML or serialization? I would imagine XML since it can be parsed by a number of programs and that's what I'm needing is portable configurations.

EDIT:

Although the database method is very interesting, it's way too much work for the small user base of my application so it's out of the question. It's a very innovative method however.

tr333
Aug 30th, 2007, 09:22 PM
Here's my question though. Would it be more portable to use XML or serialization? I would imagine XML since it can be parsed by a number of programs and that's what I'm needing is portable configurations.

With .NET serialization can be binary or XML. I'm not sure if the same applies to Java, but binary serialization would (possibly) result in smaller file sizes and also prevent users from editing the settings file directly. I would think it's easier and better to allow users to edit the preferences directly from a text editor if they have to, unless there is some need to hide this from users. This would place XML at the top of my list.