Adding automatic update support to your application
Submitted on March 25, 2003
Don't miss the Updating your application via the Internet article.
Currently the newer version of the Clever Internet Suite 6.2 is available. This version includes the Web Update component. Also please check the How to migrate to the Clever Internet Suite Version 5.0 article.
We would like to introduce a simple component which retrieves version information from the website and if there is a newer version available it will download update files via HTTP/HTTPS/FTP and run the update.
For your convenience we provide following downloads:
There are many algorithms of automating the process of receiving web updates.
Also there are some additional requirements for web update process:
To implement the first step of web update we need to place some resource (file for example), which contains information about last update, on the website. In our case we use XML-based resource file webupdate.xml. If you like you can use old fashioned TXT file instead of fancy XML format - this is just a matter of your personal preferences.
The main reason why we use XML format is simplicity of parsing information. Since we need to check for matching between your actual program version and version of update available on the web (step 2) we have to save and store information about last update to the local disk.
There are two methods for loading and storing of update information by using the Microsoft Document Object Model (DOM) library:
Here are the ActualInfo and the UpdateInfo properties which represent structures corresponding to current application version and version of update available on the web. If the downloading process has been completed successfully the update information has been saved to the local file (lastupdate.xml by default). So if you want to run web update one more time using our demo programs (demo1src.zip, demo2src.zip) you may delete this file or modify the version parameter to the previous value (in our case just replace the version attribute with the "1.0" value).
After the whole update info is received we need to compare versions and determine whether should we download and finally apply the update available on the web. If you are using simple enumeration for your updates (like 1, 2, 3 .... ) then the comparing method looks very simple:
This function returns True if the web version is up-to-date and needed to be downloaded.
This function converts each component version to the corresponding tens place:
After all checks completed and web update is up-to-date then the update file downloading process begins. In order to perform the downloading in the background mode without interfering with main application process we use the Clever Downloader component from the Clever Internet Suite library. Following code sample shows how easy downloading process can be implemented:
Since the Start downloader method is called with Async parameter which equal to True the component returns control immediately after calling of this method. So to find out the time when the downloading process is completed we use the OnProcessCompleted downloader event.
To process downloaded update file(s) we implement simple algorithm with using of ShellExecute WinApi function. So if you are about to extract archived update files you can simple call this function as follows:
This function opens your archive with application which assigned as default one for such a file type. If you have WinZip installed and it is assigned as default application for the '*.zip' files then the webupdate.zip archive will be opened and unpacked. You can specify your own method of handling and applying updates to suit your own needs.
Full component source code is available at component.zip and allows you to customize the executing process with specifying the run application and its run parameters. This can be useful if you want to run a custom application with its specific command line parameters.
It's well known that to replace running application you have to terminate it before. You can make the update process more comfortable and include the code which closes the application just after ShellExecute call:
You must have installed the Internet Explorer version 3.0 or higher on the client computer.
This code is constantly improved and your comments and suggestions are always welcome.
With best regards,