Not everyone in this world knows how to setup CVS or SVN to track changes in files. It would be horrendous if a non-technical person is required to install such a system everytime a file needs to be shared and co-edited in some way. The worst part of it is that in the real world, people do share files and co-edit them in many ways. The most common example is sharing Excel files for all the possible reasons (accounting, logistics, scheduling, etc.). Although Microsoft provides an automatic mechanism that notifies if a document is being modified at the same time if two persons try to edit it simultaneously, this only applies to Office documents.
So here lies the big problem - the pain of data corruption when people overwrite one another's files.
The inspiration to create this tool comes from the need to co-share and edit a special file format which is foreign to Microsoft Office. Microsoft provides a useful API for monitoring file system changes in .NET under
System.IO.FileSystemWatcher class. There are assisted call-backs when the file referenced by an object from this class changes. The nice part of this is it works across LAN so in a private company network or even via VPN when someone is in different parts of the world, one can keep monitoring shared file changes.
// Imports System.IO
// Public Class Main
// Dim fsw As FileSystemWatcher // // Dim fw As StreamWriter
// // Private Sub File_Created(ByVal obj As Object, ByVal e As FileSystemEventArgs)
// // // End Sub
// Private Sub File_Deleted(ByVal obj As Object, ByVal e As FileSystemEventArgs)
// // // MsgBox("Someone has deleted the file you are tracking!
// Please alert the Administrator immediately!")
// End Sub
// Private Sub File_Changed(ByVal obj As Object, ByVal e As FileSystemEventArgs)
// // // fsw.EnableRaisingEvents = False
// // // Dim objFileInfo As FileInfo = New FileInfo(OpenFileDialog1.FileName)
// If objFileInfo.Exists = False Then
// Return // End If
// MsgBox("File has been changed. Please save your current work _
// and close it before proceeding to reload the file.")
// // // Start(OpenFileDialog1.FileName)
// Dim bgImage As Bitmap = New Bitmap_
// Button4.BackgroundImage = bgImage
// Catch ArgException As System.ArgumentException
// MessageBox.Show(Me, "There was an error getting your resource. _
// The resource name is most likely not correct.")
// End Try
// // Invoke(Renew)
// End Sub
Points of Interest
Instead of just a code snippet that works, this small application can run minimized in your icon tray. So it is non-obtrusive to your desktop or the way you work. And it alerts when something happens to the file you are tracking.
This tool does not help you to merge your file differences. When changes are tracked while you are editing it, you are responsible to keep your current copy of the file (in whichever format it is) and merge it yourself in the appropriate way with the existing version.
A NSIS installer script is provided for those who know how to setup and create an installer using the Nullsoft system. This would be more user-friendly instead of distributing a raw EXE which may not run sometimes if the associated files are missed out.
- 19th June, 2009: Initial version