Click here to Skip to main content
14,334,763 members

CWebUpdate 1.0 - An MFC Update class

Rate this:
4.94 (18 votes)
Please Sign up or sign in to vote.
4.94 (18 votes)
25 Jun 2005
An easy updating method with a small foot print.

Image 1


While creating an application, I needed to implement some kind of update system. It needed to be modular so I could add and modify existing parts. I also wanted to mould it exactly how I wanted. CWebUpdate is the result.

How does it work?

Right, well, CWebUpdate's core revolves around some kind of update file, in the format of:

[filename] [sha-1 hash]
[filename] [sha-1 hash]

which looks a bit like this:

readme.txt 59c23b37d5f063e2a01938d3d06583dc2ea0a933

You can generate SHA-1 hashes for files using CHash's demo project.

So, when CWebUpdate is told to check for updates, it downloads this file. It then scans a directory for files in this list. It keeps an internal array of missing files and updated files (each is hashed with SHA-1 and compared).

In this way, you can easily ascertain if files have been added and updated, and then update them.

What's going on behind the scene?

CWebUpdate uses URLDownloadToFile to download files, in a thread. This allows the dialog to be unfrozen while downloads take place.

SHA-1 is used to check file's integrities and that they are the same/different to the ones in the update. The code for this is taken from CHash.

Putting CWebUpdate to use

CWebUpdate is easy to implement (or so I think). Step by step guide to setting up an update system:

  • Include CWebUpdate.h in your project somewhere.
  • Declare a CWebUpdate object.
  • Set the remote URL and update URL.
  • Set the local directory to be downloaded to (this can be found automatically by CWebUpdate if necessary).
  • Search for updates.
  • Check if any were found, present them to the user (if you want) and update them if necessary..

Right, now, a code sample:

CWebUpdate updObj;

// Have CWebUpdate get this exe's path
updObj.SetLocalDirectory("", true);
// Set the URL for the update file and where downloads are stored

// Check for updates

// If a new file called "important.exe" was found, download it
for (int i = 0; i < updObj.GetNumberMissing(); i++)
    if (updObj.GetMissingAt(i) == "important.exe");

CWebUpdate reference

Setting up the class

  • CString GetLocalDirectory()

    Returns the current directory files will be downloaded to.

  • CString GetRemoteURL()

    Returns the current URL files will be downloaded from.

  • CString GetUpdateFileURL()

    Returns the current update file URL.

  • void SetLocalDirectory(LPCSTR pathTo, bool generate)

    Sets the directory files will be downloaded to. If generate is true, the path will be the directory the exe is running from.

  • void SetRemoteURL(LPCSTR url)

    Sets the URL files will be downloaded from.

  • void SetUpdateFileURL(LPCSTR url)

    Sets the current update file URL.

Checking for updates

  • bool DoUpdateCheck()

    Returns true if an update file was found and parsed, otherwise false.

  • int GetNumberDifferent()

    Returns the number of different files found.

  • int GetNumberMissing()

    Returns the number of missing/new files found.

  • int GetNumberSuccessful()

    Returns the number of up to date files found.

  • CString GetDifferentAt(int i)

    Returns the filename of a different file at a location.

  • CString GetMissingAt(int i)

    Returns the filename of a missing/new file at a location.

  • CString GetSuccessfulAt(int i)

    Returns the filename of an up to date file at a location.

Downloading updates

  • bool DownloadMissing(int i)

    Returns true if the missing file at 'i' location was downloaded.

  • bool DownloadDifferent(int i)

    Returns true if the different/updated file at 'i' location was downloaded.

The demo project contains a full example of implementing CWebUpdate.


  • 25th June 2005: First release. (I sense another imminent one.)


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


About the Author

United States United States
No Biography provided

Comments and Discussions

QuestionCWebUpdate 1.0 - An MFC Update class Pin
1animefinder29-Feb-16 2:04
member1animefinder29-Feb-16 2:04 
QuestionSubfolders. Pin
Member 789920710-Jul-11 9:39
memberMember 789920710-Jul-11 9:39 
GeneralVersioning Pin
.dan.g.27-Jun-05 14:00
professional.dan.g.27-Jun-05 14:00 
GeneralRe: Versioning Pin
Anonymous27-Jun-05 20:47
memberAnonymous27-Jun-05 20:47 
GeneralRe: Versioning Pin
mkcx28-Jun-05 22:28
membermkcx28-Jun-05 22:28 
GeneralRe: Versioning Pin
.rich.w29-Jun-05 4:14 4:14 
GeneralRe: Versioning Pin
Member 44580906-Mar-08 0:16
memberMember 44580906-Mar-08 0:16 
GeneralComments Pin
Ravi Bhavnani26-Jun-05 5:41
professionalRavi Bhavnani26-Jun-05 5:41 
GeneralRe: Comments Pin
.rich.w26-Jun-05 5:58 5:58 
GeneralRe: Comments Pin
Ravi Bhavnani26-Jun-05 6:05
professionalRavi Bhavnani26-Jun-05 6:05 
GeneralRe: Comments Pin
.rich.w26-Jun-05 6:06 6:06 
GeneralSetLocalDirectory() Pin
Ravi Bhavnani26-Jun-05 6:47
professionalRavi Bhavnani26-Jun-05 6:47 
GeneralRe: Comments Pin
cmckni319-Aug-08 9:11
membercmckni319-Aug-08 9:11 
GeneralRe: Comments Pin
Ravi Bhavnani19-Aug-08 10:44
professionalRavi Bhavnani19-Aug-08 10:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 25 Jun 2005


89 bookmarked