3

I want to create a configuration file (text file preferred) that can be modified by user. A windows service will read from that file and behave accordingly. Can you recommend a file format for this kind of process? What I have in my is a config file like the game config files, but could not imagine how to read from it.

My question is very similar to INI files or Registry or personal files?, but my question is different because I need to consider user editing.

3
  • 1
    Related: INI files or Registry or personal files?. YAML, INI and XML are all good choices.
    – yannis
    Commented Mar 21, 2013 at 12:30
  • I think I will go for INI files
    – Bora
    Commented Mar 21, 2013 at 12:39
  • One important question is where you want to store this file. Since you're talking about a service, you probably don't want unprivileged users to be able to change the file, else you get the risk of a privilege escalation vulnerability. Commented Mar 22, 2013 at 12:06

3 Answers 3

4

Personally I'd use Settings, its xml based, but the real benefit is that MS have already done all the coding for you for most types (including both global settings and per user overrides), so it really simple to use. as Wyatt points out in his answer it is also possible to extend using custom configuration sections (personally I find this overkill for most configuration needs, but its nice to have available when you do have a complex configuration scenario).

Depending on how tech savvy the users are you could use Settings and allow the user to edit the xml themselves.

If the users are not tech savvy then I'd suggest you provide a GUI to allow editing anyway as otherwise you will quickly find you have support calls about corrupt config files (regardless of what format you use)

1
  • 1
    +1 for the GUI recommendation: there are often business rules regarding what values are reasonable / valid. Configuration errors can also be extremely cryptic, e.g. a recent issue in an XML config file was reported by .Net as "The application has failed to start because its side-by-side configuration is incorrect". Googling this leads you to believe that your .Net installation is corrupt. In the end, it was just a missing character in the config file - spare your users and support staff the pain and give them a GUI.
    – Daniel B
    Commented Mar 22, 2013 at 5:53
2

Writing a simple DSL in Boo is an excellent solution for this kind of problem and near-infinitely extensible as the rules get more complicated. You can even, without too much effort, give the user basic Intellisense by shamelessly reusing a bit of SharpDevelop. And you can easily validate the rules they create.

However, seriously consider providing a user interface. It's more work on your side to develop but it's less work later to support.

3
  • +1 for suggesting to provide a user interface instead.
    – user53019
    Commented Mar 21, 2013 at 13:44
  • Not a fan of ConfigSections? I'm really surprised not to see custom ConfigSection suggested, moreover by you who (I presume?) has experience with them... care to mention why you wouldn't go that route for this? Commented Mar 21, 2013 at 19:19
  • @JimmyHoffa: Certainly not for user-editable settings, no. Not ever. Personally, I'm not a fan of coding in XML anyway; it's just something I tolerate cause I like .NET generally and it's kind of endemic. I would love to convince the world that Boo has a place.
    – pdr
    Commented Mar 21, 2013 at 19:50
2

For .NET you might as well create your own custom configuration section. In terms of having users update it, you'd probably want to write a tool but that is relatively easy -- the configuration APIs make it easy to modify the settings without writing alot of code.

If you wish to avoid XML, there are lots of options. Most of those game config files you see are lua scripts. Some other interesting options would be ruby or python -- both of which have CLR implementations as IronRuby and IronPython and would be fairly straightforward to implement.

1
  • +1 Custom config sections are pretty useful for complex configuration, 99% can be done with the vanilla Settings that you get out of the box though.
    – jk.
    Commented Mar 22, 2013 at 11:47

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.