The Unofficial Newsletter of Delphi Users - by Robert Vivrette


     
Auto Upgrading!

by Daniel J. Wojcik - wojcik@liaeur.21taacom.army.mil

I sit in my little office waaaaay over here and write applications for all of those people waaaay over there in entirely too many different offices.  Well, I'm much too lazy to visit them and reload their systems every time I make a change to the apps I write.

Luckily, we're all on the network, and I've come up with a fairly simple way of giving them updates as needed.

I created a small application whose sole purpose in life is to copy newer versions of the main app from a network server.  Here's a skeleton of my main apps' DPR file:

You'll have to put in the Windows, since Delphi doesn't normally include it in a DPR file.  The '...' is where all the forms you've created go, of course. Use FileAge to check the dates...it doesn't mind UNC paths & filenames... why hard-code a drive letter, if you don't have to? Run the upgrade mini-app (which must be in the same directory as the main app).  If it starts,  exit from this copy of the main app.  Since Application.Initialize hasn't been called yet, there be shouldn't anything to clean up, resources-wise. Of course, if the mini-app doesn't start for some reason, tell the user they'll have to get the newer version the old-fashioned way.  I still exit the main app to give them the opportunity to do so.  However, just take out the exit in the next block to continue loading the current version of the app if you'd rather. The upgrade mini-app is a console application, so be sure to set the Linker option to Generate Console Application. Use CopyFile to copy the new version...just like FileAge, it doesn't mind UNC paths & filenames. Once the new version of the main app has been copied, attempt to run it.  No reason it shouldn't run, so I didn't do any error checking in this block.  The worst that would happen is the user will be forced to run the app as they normally do. Notice there isn't any Application.Initialize or Application.Run in this little app.

These methods can be extended to check for and copy newer versions of the Help file (use GetWindowsDir or GetWindowsDirectory  and append "Help" to it in the upgrade app) or even newer versions of the upgrade app.

The adventurous can make a universal upgrade app using commandline parameters instead of the hard-coded filenames I use.