Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo
I am developing a Notepad++ plugin, it needs a configuration file. At the moment I can consider any file format, including XML, INI and CSV.
I have several related question about handling config files:
1. How do other plugins read their config files?
2. Does Notepad++ have any inbuilt utilities for reading config files?
3. What other libraries are recommended for handling config files?
4. How do plugins report errors in their config files?
Hope this helps! :)
Thank you, Dial, for the information. I was hoping to get a little more in the way of recommendations on what to use for configuration file handling.
This is highly dependent on what type of file you go with and what language you plan on programming in. You could read and write directly to a file with your own custom format using ordinary file IO operations.
For INI files you can use the Windows API for WritePrivateProfileString and GetPrivateProfileString or the multiple related functions. You can see an example usage of these here. There are also other third party libraries for INI handling.
TinyXML seems popular for XML files and I'm sure there are many others.
Same goes for CSV and other popular formats.
You can also look at other plugin's source code to see how they do it too.
INI files are often used when a plugin is written in the same style as N++, ie. raw Win32 C++. If you're working in another language (for instance .NET), then you've got a lot more options. INI files have the advantage (as dail8859 mentioned) of having simple native APIs to read and write values. The disadvantage, is they only work for simple values (so nested trees of configuration isn't going to work very well), and if you're reading a lot of values they are relatively slow. Note the emphasis on relatively there, realistically, you're not going to notice reading 20-30 options in at startup. As a comparison, Python Script has it's own format for it's startup configuration file, because it wants to load all values in, and do it as quickly as possible, as it affects N++ startup time. Realisitically, it probably doesn't make any difference, but felt like the right thing to do at the time.
What is more important, is how you handle your configuration. Definitely use NPPM_GETPLUGINSCONFIGDIR to get the directory where you should store the config. Do you really need the configuration to work, or will a default do most of the time? Message boxes are OK, but it's sometimes better not to irritate the user until they want to use your plugin. XML Tools changes it's menu items when it's not installed properly, I think it's ASpell that does this when it's not configured correctly (it needs a path setup). This is quite easy to do (just check your configuration and give back a different response in getPluginMenuItems).
Whatever format you go with, I'd recommend adding some kind of version number to your config. That makes it easy to notice if someone had an old version, and perform an upgrade.
There's some further notes on http://www.brotherstone.co.uk/octopress/blog/2012/08/20/top-10-hints-for-writing-a-notepad-plus-plus-plugin/ that may or may not be useful.