In this blog post, we will take a look at how to add Auto Update support to small & medium level desktop applications. This blog post will cover why an update is necessary and will give you an overview of setting up the update process. Future blog posts will focus on controlled updates.
Why is an update necessary?
Unlike Web applications, a desktop application requires a well-defined update process in place. Rolling out a new update for a Web application only requires an update on the Web server, resulting in all connected users starting to receive the updated version of the application. Any standalone desktop application may be required to be updated depending upon several factors such as bug-fixes and addition of new features. A seamless and graceful update process is required to roll out a new release of any application.
Ways to update a desktop application:
There are several ways to roll out new enhancements/fixes for the users already using your desktop application:
- Sending the update installer to each individual user: This is the simplest option one can think of, but it does not seem too promising when there are lots of users.
- Keeping the update installer on a well-known and accessible location on a Web server. (Optionally, the download could also be protected by some kind of authentication).
- Setting up a process where the distributed application will itself check for new and available updates, download them and will get updated itself. This blog post will focus on this particular way of updating a desktop application. The following two features can be added to the application for this:
- Manually triggering the update process: The user will initiate the check for updates and the application will then check, download, and install the new updates.
- The application automatically checking for updates: The application will keep polling the server at certain intervals for new updates and if available, it will download and install the updates.
Prerequisites for adding Auto-Update support to desktop applications:
- Maintain proper versioning for releases/updates.
- Set up a web-service (such as getLatestVersion()) which provides the application’s latest version number available on the server.
- The application designed to check and download the new updates. Alternatively, this feature can be integrated into the main, parent application. Let’s name this parent application as application.exe for this discussion.
- The application designed to run the actual update process on the user’s machine according to a preconfigured rule. The update process is entirely specific to the application’s and the user’s needs. Let’s name this updater application as update.exe for further discussions.
Steps to add the Auto-Update support to the application:
- Define the steps and activities that will happen during the update process on the client’s machine. Build separate executable (i.e., update.exe) serving these steps and activities. update.exe will be responsible for the following activities:
- After prompting the user and receiving his go-ahead, it will close the running application and related processes before updating the application with new files. If the user has declined the update, the parent application may ask the user for the update to be applied at a later time.
- After taking a backup of the current files, the updater will move the newly downloaded files to their correct locations and make the required configuration changes, including dll registrations, if required. This is because if the updater encounters any issues during the update process, it can revert the application back to its last working state using the backed-up files.
- Once the update is applied, the updater will launch the application and exit.
- Include update.exe as a standard part of the update files to control the update process.
- Make the required changes in the parent application (application.exe) to check the availability of new updates on the update server at preconfigured intervals. If updates are available, then the updater will download the updates, replace the old update.exe with the new update.exe, and will launch the new update.exe. This activity to check and download the new updates can either be a part of the main application, or can be in a separate executable which runs as a System Tray application, or as a Windows service. An alternative approach could be checking and downloading the updates whenever the main application is launched.
The following diagram explains the process involved in automatically updating an application:
A quick walkthrough of the update process:
- To initiate a new release, the server administrator deploys the update files on the Web server.
- He then configures the Web service (getLatestVersion) to send the updated application’s version number to the application presently running on the user’s machine.
- On the user’s machine, the running application will invoke the Web service to obtain the latest application’s version number from the server. The service will check if this version is newer than the current one and if it is, a message can be displayed to the user about its availability along with asking his permissions to proceed with the update. If the user agrees to the update, then the updater will begin downloading the relevant files.
- Once all the files are downloaded, the updater will check the integrity of the downloaded files. The best way to do this is to provide the checksum of the update files which can then be revalidated with the downloaded files. After a successful validation, the updater will replace the old update.exe with the newer one and will then launch the new update.exe.
- update.exe will then close the main application and its associated processes and will update the old application with the new downloaded files. After this process, it will launch the main application again.
The update process we have gone through above is a custom process to update a desktop application. There are several other ways to add update support to your application using tools specifically designed for this:
- ClickOnce: This is a Microsoft technology providing a simple ‘deploy and update’ experience. It allows you to create self-updating Windows-based applications which can be installed and run with minimal user interaction. It is tightly integrated into .NET and Visual Studio.
- WiX (Windows Installer XML): WiX is Microsoft’s open source software to create Windows installation packages from XML source code. This tool offers several features, such as integration with Visual Studio.