5,557,174 members and growing! (16,934 online)
Email Password   helpLost your password?
Languages » C / C++ Language » General     Intermediate

Simple update check function

By Alexander Bischofberger

An aasy way to implement an online Update-check to your application
VC6, C++Windows, WinXP, Visual Studio, MFC, Dev

Posted: 10 Nov 2003
Updated: 10 Nov 2003
Views: 68,105
Bookmarked: 39 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
12 votes for this Article.
Popularity: 4.44 Rating: 4.12 out of 5
0 votes, 0.0%
1
3 votes, 25.0%
2
1 vote, 8.3%
3
3 votes, 25.0%
4
5 votes, 41.7%
5

Introduction

Almost all programs that are available today have a feature that checks for software updates using the internet. This is a convenient way for both the user and the developer: You don't have to contact all the users (if you know them...) when a new version is available. And the user can be sure to always have the newest version.

In this article I'd like to focus on small programs (e.g. only 1 executable and no nescessary installation program) and developers who have just a simple web space without the possibility to use scripts (only static web pages). Also this code only shows a web page and does not automatically download or install files.

The basic thing we have to do is very simple: Connect to a web site, ask for the newest version, compare it to the current version, and in case there is an update ask the user to download it. You - as the developer - have to use correct version information in your code and update the internet file whenever an update is available.

Program version

Ever looked at the version block of your code in the resource file? This resource consists of two major blocks: A language-independent information on the top containing file version etc. and some blocks where text information can be stored like the copyright. This code only uses the fixed block (FILEVERSION) at the top of this resource. Please be sure to update this block any time you want to release a new version!

What this class does

The new class CUpdateCheck has 1 main function: download a web site and check for updates! If you don't want to change any behaviour you simply use the class "as is" - that's all (besides adding the language-dependant strings). The class has two helper function GetFileVersion()to get the applications File version and GotoURL() which simply opens a web page in the default browser. I got the code for GotoURL() somewhere on the web, so when you are the author please inform me to put your names to the credits.

Using the code, allow auto-updates

[1]: Add a new menu item to your application and handle it in your CWinApp drived class. This could look like this:
void CMyApp::OnAppCheckupdate()
{
  CUpdateCheck checkUpdate;
  checkUpdate.Check(IDS_UPDATE);
}
where the string IDS_UPDATE is e.g. http://www.mywebsite.xxx/update.txt

In case you want to check automatically for updates each time the user start your application put the lines above in the InitInstance function. Or write the last date you checked for updates to the registry and only check once each week. ....

[2]: Add a few strings to the string table:
IDS_UPDATE_AVAILABLE You currently use version %u.%u of this program. The newest version %u.%u is available online. Do you want to see more information?
IDS_UPDATE_NO No Updates available.
IDS_UPDATE_NOCHECK Unable to check for updates.

[3]: Put a file on your webspace (located as referred in IDS_UPDATE) which has the following syntax:

Major Version|Minor Version|URL for Update page
So when your program has currently the version 1,1,0,0 and you want to offer an update to 3,4,0,0 which is available for download at http://www.mydomain.com/updateinfo.html the file should be
3|4|http://www.mydomain.com/updateinfo.html

Limitations

  • The file on your web site has to be less than 512 characters
  • Only the two leftmost parts of the version info are used. The lower two numbers are normally used as a "Build number" and have no effect on this class
  • No automatic download is offered, the user has to download the files from your site and copy/install them

History

01.11.2003: Initial release

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

About the Author

Alexander Bischofberger


Ok, a few words about me:

I started programming on the C64 by the "trial and error" method. Years later my parents got their first PC (Atari PC4, AT 8 MHz) where I started with Turbo Pascal. The next steps led to Turbo Pascal for Windows, Visual C++ 1.52c, and finally Visual C++ 6.

I had several chances to code larger projects, e.g.
* stand-alone disc copy station software (Win 3.1) with automatic reboot, disc encryption, ...
* government-used strategic decision system
* MLM marketing tool (www.upline.de)
* maintenance for show planning system and other TV software (www.hse24.de)

A lot of code, tipps and help came from this site for my later projects. Thanks again to all who helped me, even if they don't know it. I'm trying to share code (which is worth sharing) so others can get the help I got (and still need) for everyday problems.

Well, I think that's enough.


Occupation: Web Developer
Location: Germany Germany

Other popular C / C++ Language articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 39 (Total in Forum: 39) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralMore generic programming?memberMaartenEngels5:55 18 Aug '07  
GeneralCheckForUpdates - Security / Legal aspectsmemberYogesh P. Dhakad20:42 1 Feb '07  
GeneralRe: CheckForUpdates - Security / Legal aspectsmemberYogesh P. Dhakad20:50 1 Feb '07  
GeneralRe: CheckForUpdates - Security / Legal aspectsmemberAlexander Bischofberger1:04 4 Feb '07  
GeneralRe: CheckForUpdates - Security / Legal aspectsmemberYogesh P. Dhakad9:36 7 Feb '07  
GeneralExcellent, slight fix thoughmemberJohn-Lucas Brown6:59 30 Jan '07  
GeneralRe: Excellent, slight fix thoughmemberAlexander Bischofberger8:53 30 Jan '07  
GeneralRe: Excellent, slight fix thoughmemberJohn-Lucas Brown23:32 30 Jan '07  
GeneralVery good code! Very simple, easy for implement and use!memberkrasi_top8:39 17 Apr '06  
GeneralJuandememberjdmanjon22:53 23 Nov '03  
GeneralShameless plug for Web Update Wizardmemberpeterboulton8:02 18 Nov '03  
GeneralRe: Shameless plug for Web Update Wizardmembermier0:27 19 Nov '03  
GeneralRe: Shameless plug for Web Update Wizardmemberpeterboulton1:08 19 Nov '03  
GeneralRe: Shameless plug for Web Update WizardmemberSean O'Brien13:12 22 Nov '03  
GeneralRe: Shameless plug for Web Update Wizardmemberpeterboulton3:09 23 Nov '03  
GeneralRe: Shameless plug for Web Update WizardmemberSean O'Brien11:36 23 Nov '03  
GeneralRe: Shameless plug for Web Update Wizardmemberpeterboulton23:05 23 Nov '03  
GeneralRe: Shameless plug for Web Update WizardmemberHockey21:46 15 May '04  
GeneralRe: Shameless plug for Web Update Wizardmemberpeterboulton5:21 16 May '04  
GeneralRe: Shameless plug for Web Update WizardmemberHockey6:03 16 May '04  
GeneralRe: Shameless plug for Web Update WizardsussAlexander Bischofberger1:35 26 Nov '03  
GeneralRe: Shameless plug for Web Update Wizardmemberpeterboulton3:54 26 Nov '03  
GeneralRe: Shameless plug for Web Update WizardmemberTony Leotta16:58 24 Jan '04  
GeneralRe: Shameless plug for Web Update WizardsussJohn Marino23:27 20 Apr '04  
GeneralRe: Shameless plug for Web Update WizardmemberThe Bug2:40 5 Oct '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 10 Nov 2003
Editor: Rob Manderson
Copyright 2003 by Alexander Bischofberger
Everything else Copyright © CodeProject, 1999-2008
Web19 | Advertise on the Code Project