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.

Bora
  • 39
  • 1
  • 1
  • 2
  • 1
    Related: [INI files or Registry or personal files?](http://programmers.stackexchange.com/questions/144238/ini-files-or-registry-or-personal-files). YAML, INI and XML are all good choices. – yannis Mar 21 '13 at 12:30
  • I think I will go for INI files – Bora Mar 21 '13 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. – CodesInChaos Mar 22 '13 at 12:06

3 Answers3

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)

jk.
  • 10,216
  • 1
  • 33
  • 43
  • 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 Mar 22 '13 at 05: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.

pdr
  • 53,387
  • 14
  • 137
  • 224
  • +1 for suggesting to provide a user interface instead. –  Mar 21 '13 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? – Jimmy Hoffa Mar 21 '13 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 Mar 21 '13 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.

Wyatt Barnett
  • 20,685
  • 50
  • 69
  • +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. Mar 22 '13 at 11:47