Thursday, June 25, 2009

Now Using peerblock.conf (r44)

In SVN r44 (at Google Code), I just implemented use of a peerblock.conf file for PeerBlock configuration. This should work well with the recent renaming of the program files to peerblock.exe and pbfilter.sys, as you can now install PeerBlock into the same directory as PG2 - without overwriting any files - and it will be able to work without affecting PG2's operation. If peerblock.conf doesn't exist, it will instead load pg2.conf (assuming it exists) and then save the settings to a new peerblock.conf file when you exit the program.

Technical Details

If all you're interested in is the user-visible side of things, you can stop reading now. This "Technical Details" section is where I plan on putting the more code-specific stuff; for my own future reference, or for anyone following along with the code at home.

The configuration-file loading routines live in configuration.cpp/.h. I added a parameterized LoadFile() routine that accepts the name of the file you'd like to load, and returns true if it successfully loaded or false if not. Load() now calls into this routine to first attempt to load peerblock.conf from the directory the program is located in, and if it cannot it then tries to load pg2.conf as a backup.

When the program exits, it will save its settings out to peerblock.conf. Note that this appears to be the only time the code saves the settings, and I didn't feel like changing it. Might be worth changing it to save whenever you update settings though, just in case the program crashes after you've updated settings but before you've exited safely . . . then again maybe this is by design, in case one of your new settings is what caused the crash?

Added tracelog statements at Info level. Since Release mode builds will log at Info level we'll see these messages whenever the program is run, but this should be okay since we really shouldn't be calling into the routines all that often.

No comments:

Post a Comment