Implement an auto update system

2 Comments

Auto update is widely used in modern software development. It simplifies and speeds up product upgrade to enhance features and fix problems. I have been working on an application which is still in alpha version and testers need to update it incrementally and frequently. The testers are not computer professionals, so I have to make the update process as easy as possible. Below is the basic design and code. The toolkit that’s being used is QT 4.5. But the concept is universal.

To design such system, the following steps are considered:

  1. A server that contains the latest version and a list of updated files.
  2. The application should connect to the server to retrieve the list and compare the versions.
  3. If there is a new version, download the updated files to replace the new ones.
  4. Clean up.

Let’s work on it step-by-step. To save space, I will only post relevant code:

1. Server Side

The directory set up is as the following:
dir_structure
I used an XML file latest.xml to store the version and file list. It’s pretty self-explanatory.

1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE XML>
<appname>
	<version>
		<version value="0.5.1" />
	</version>
	<files>
		<file value="app.exe" />
                <file value="some.dll" />
                <file value="another.dll" />
	</files>
</appname>

Pages: 1 2 3 4

RSSSubscribe to the RSS feed to receive more useful tips. Filed under: How-To,Programming

2 Responses to “Implement an auto update system”

  1. kaleem ullah khan
    April 29th, 2009 at 3:15 AM

    Hi Roland, I like the article, I have a small concern i am a C # developer, so i was looking at the code not very througly, I could not understand a part ,
    I understood that we created a temp folder and downloaded latest files in them, we also copied all current files to a new folder for backup how can i rename the current files to .old extension these files are already in use and also how i am going to tell my icon for instance to load from temp folder where new files are present.

    thanks

  2. rolandli
    April 29th, 2009 at 10:01 AM

    Hi Kaleem,

    I’m not too familiar with C#, but I will try my best to answer your question.

    Files which are in use cannot be deleted, but they can be renamed. In the example above, there is a vector filelist that stores a list of files to be updated. So just loop through it to and rename all the existing files in it.

    As far as I know, there is a function in C# is good for this purpose: System.IO.File.Move(@”C:\From.txt”, @”C:\TO.txt”);. Use it to add “.old” to all the existing files.

    After that, you can copy the newly downloaded files into the working folder since there is no file overwriting issue.

    In order for the new files to take effect, the program MUST be restarted. And in your main loop, before anything else take place, check if the working folder has any “.old” file, if so, delete them all.

    I hope that answers your question.

Leave a comment