Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Application Auto Update Revisited

0.00/5 (No votes)
19 Nov 2006 1  
An article on updating Windows applications through the web.

Introduction

Since my first iteration of the AutoUpdate, I noticed that I don't really need the ability to change the AutoUpdate program itself, so I don't need it. The second thing is that most of the time I don't need to update all the files.

What has changed

The AutoUpdate program (AutoUpdate.exe) is no longer required. Now, everything that is needed is in the DLL (AutoUpdate.dll). No need to touch the CommandLine anymore since everything is at the same place. The AutoUpdate doesn't need to be a class, now it is just a module, so, no need to create an AutoUpdate variable.

No need to change the AutoUpdate code. The remote path, the update file name, and the error message are now properties and the last two have default values.

The update file has a new layout, as shown:

<File Name>;<Version>   [' comments    ]
<File Name>[;<Version>] [' comments    ]

<File Name>[;?]         [' comments    ]
<File Name>[;delete]    [' comments    ]
...

And this is what it means:

  • Blank lines and comments are ignored.
  • The first line should be the current program/version.
  • From the second line to the end, the second parameter is optional.
  • If the second parameter is not specified, the file is updated.
  • If the version is specified, the update checks the version.
  • If the second parameter is an interrogation mark (?), the update checks if the file already exists, and "doesn't" upgrade if it exists.
  • If the second parameter is "delete", the system tries to delete the file.
  • "'" (chr(39)) starts a line comment (like VB).

The UpdateFiles function returns True if the AutoUpdate did the update or there was an error during the update, or False if nothing was done.

The auto update web folder

Some things never change. The auto update web folder should have a folder for each system you want to upgrade. The root folder is the one that you will refer on the RemotePath variable. Each sub folder should be named as the assembly name (normally, the program name without the extension). Inside the program folder, you save the files that you want to update and the file Update.txt (or the name that you defined in the UpdateFileName property) with the layout explained above.

Using the code

You can add the module to your project, or you can add a reference to the DLL. After that, you just need to call the UpdateFiles function. You also can change the default properties before the call.

Public Sub Main()
    ' You can set some parameters thru properties
    ' The remote path can be set thru the RemotePath property or 
    ' thru the RemotePath parameter in the function call
    ' UpdateFileName and ErrorMessages have default value so it's optional
    AutoUpdate.RemotePath = "http://www.url.com/directory/"

    ' the final location to the files will be RemotePath + AssembyName + "/" + FileName
    ' ex: http://www.url.com/directory/AutoUpdateTest/MyUpdate.dat

    AutoUpdate.UpdateFileName = "MyUpdate.dat"
    AutoUpdate.ErrorMessage = "Something funny is going on trying to auto update."

    ' test if an update is needed and quit the program if so.
    If AutoUpdate.UpdateFiles() Then Exit Sub

    ' here goes your regular code in the main sub
    Application.Run(New Form1)
End Sub

What else can be done

In the server side, you can build a service that automatically generates the update file, but this is up to you!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here