Click here to Skip to main content
14,870,596 members
Articles / Desktop Programming / MFC
Article
Posted 10 Nov 2003

Stats

145.4K views
2.2K downloads
65 bookmarked

Simple update check function

Rate me:
Please Sign up or sign in to vote.
4.47/5 (14 votes)
10 Nov 2003CPOL3 min read
An aasy way to implement an online Update-check to your application

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Alexander Bischofberger
Web Developer
Germany Germany
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.

Comments and Discussions

 
GeneralGood submission, it works Pin
conrad Braam5-Nov-09 12:14
Memberconrad Braam5-Nov-09 12:14 
GeneralRe: Good submission, it works Pin
jcdids5-Nov-12 12:44
Memberjcdids5-Nov-12 12:44 
QuestionMore generic programming? Pin
MaartenEngels18-Aug-07 4:55
MemberMaartenEngels18-Aug-07 4:55 
GeneralCheckForUpdates - Security / Legal aspects Pin
Yogesh Dhakad1-Feb-07 19:42
MemberYogesh Dhakad1-Feb-07 19:42 
GeneralRe: CheckForUpdates - Security / Legal aspects Pin
Yogesh Dhakad1-Feb-07 19:50
MemberYogesh Dhakad1-Feb-07 19:50 
GeneralRe: CheckForUpdates - Security / Legal aspects Pin
Alexander Bischofberger4-Feb-07 0:04
MemberAlexander Bischofberger4-Feb-07 0:04 
GeneralRe: CheckForUpdates - Security / Legal aspects Pin
Yogesh Dhakad7-Feb-07 8:36
MemberYogesh Dhakad7-Feb-07 8:36 
GeneralExcellent, slight fix though Pin
John-Lucas Brown30-Jan-07 5:59
MemberJohn-Lucas Brown30-Jan-07 5:59 
GeneralRe: Excellent, slight fix though Pin
Alexander Bischofberger30-Jan-07 7:53
MemberAlexander Bischofberger30-Jan-07 7:53 
GeneralRe: Excellent, slight fix though Pin
John-Lucas Brown30-Jan-07 22:32
MemberJohn-Lucas Brown30-Jan-07 22:32 
GeneralVery good code! Very simple, easy for implement and use! Pin
kstoychev17-Apr-06 7:39
Memberkstoychev17-Apr-06 7:39 
GeneralJuande Pin
jdmanjon23-Nov-03 21:53
Memberjdmanjon23-Nov-03 21:53 
GeneralShameless plug for Web Update Wizard Pin
peterboulton18-Nov-03 7:02
professionalpeterboulton18-Nov-03 7:02 
GeneralRe: Shameless plug for Web Update Wizard Pin
mier18-Nov-03 23:27
Membermier18-Nov-03 23:27 
GeneralRe: Shameless plug for Web Update Wizard Pin
peterboulton19-Nov-03 0:08
professionalpeterboulton19-Nov-03 0:08 
GeneralRe: Shameless plug for Web Update Wizard Pin
Sean O'Brien22-Nov-03 12:12
MemberSean O'Brien22-Nov-03 12:12 
GeneralRe: Shameless plug for Web Update Wizard Pin
peterboulton23-Nov-03 2:09
professionalpeterboulton23-Nov-03 2:09 
GeneralRe: Shameless plug for Web Update Wizard Pin
Sean O'Brien23-Nov-03 10:36
MemberSean O'Brien23-Nov-03 10:36 
GeneralRe: Shameless plug for Web Update Wizard Pin
peterboulton23-Nov-03 22:05
professionalpeterboulton23-Nov-03 22:05 
GeneralRe: Shameless plug for Web Update Wizard Pin
alex.barylski15-May-04 20:46
Memberalex.barylski15-May-04 20:46 
GeneralRe: Shameless plug for Web Update Wizard Pin
peterboulton16-May-04 4:21
professionalpeterboulton16-May-04 4:21 
GeneralRe: Shameless plug for Web Update Wizard Pin
alex.barylski16-May-04 5:03
Memberalex.barylski16-May-04 5:03 
peterboulton wrote:
I've already apologised for any offense caused by my posting

Yeah your right...so I suppose I should appologize Smile | :)

My sincere appologies Smile | :)

However I didn't really mean my remark to come across like it obviosuly did...I would make shameless plugs too (if I had a product to push). It was more of a tisk tisk kinda remark...and the fact you appologized helped...I hate it when people post ads in the forums and just ignore criticism...

When I read posts i'm 99% of the time looking for FREE answers to a problem, not some commercial bulls*it...i'm a very impatient programmer, wanting answers now Smile | :)

peterboulton wrote:
I am not an axe murderer, I am kind to children and old ladies. Give me a break!

<br/> There you go Smile | :)

A bit of HTML humor to lesson any grief I may have caused you...(it's even xhtml compliant)

peterboulton wrote:
wholly reasonable people have stated that the posting at least helped increase their awareness of the range of available options

IHMO just don't do it again (this way)...there are much better ways to do it...like the old advertising adage goes...one negative customer is worse than something...something... Confused | :confused: Cool | :cool:

Personally I have looked into doing what you have done I just haven;'t gotten around to it yet... Smile | :) so it wouldn't be much good to me, but obviously some people appreciated it!!!

If you want to advertise a product like yours on CP do like I will eventually do...have a link inside your sig and become highly active in the CP community...look at Mike Dunn for an example...he's helpful, knowledgable, written tons of high quality articles and every time he makes a post he makes an incognito plug for his products

He's a smart dude... Smile | :)

What you could do is post the LCS code (w/ LCS tutorial) you use to differentiate your two files as an article on CP (there are already a few, so read them and make yours better)

That'll guarunteed get people checking out your product and it's considered ethical on CP (so i've noticed)

Anyways man, I appologize for any feelings I may have disturbed and I really didn't mean it that way, it was just me browsing the bowels of CP at 4 in the morning with nothing else to do...

Cheers Smile | :)

How do I print my voice mail?
GeneralRe: Shameless plug for Web Update Wizard Pin
Alexander Bischofberger26-Nov-03 0:35
MemberAlexander Bischofberger26-Nov-03 0:35 
GeneralRe: Shameless plug for Web Update Wizard Pin
peterboulton26-Nov-03 2:54
professionalpeterboulton26-Nov-03 2:54 
GeneralRe: Shameless plug for Web Update Wizard Pin
leotta24-Jan-04 15:58
Memberleotta24-Jan-04 15:58 

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.