Some work on allowing a file to be locked/unlocked (#256).

Now works on all our supported platforms (i.e. Windows, Linux and OS X).