Win32 Application Online Update (Manually)

Anyone knows that updating such that distributed application is a boring activity, especially for those who have tons of PCs. It can make peoples from IT department wasting their times to upgrading client application. Moreover, looking forward email contain application attachment from software vendor also can bring much troubles for wide company and I mean this is an old-fashioned way. Why don’t you just suggest the vendor to change the update method with an online way? But for this, you need to make sure that the client PCs has internet capability so that you only have to tell the operator to download the update.

The update method is very simple and I did this to one of my client across Jakarta. It’s easy for them to update and me as the software developer to publish the application. Any latest update, I just store it to my domain immediately. How to do that? Look at image simulate the process below:



The process is quite plain; just tell the application to generate a link in any latest version available from web server, but simply ignore the priors so that it will only show the fresh version link. Got that? Ok, let say that you have an online web server named abc.com. Next, prepare a single web based script to generate a link if there is any newest version on hand (on this example, I used PHP script and named it with app.php). Now, the question is, how the scripts can detect and compare between current version and others up-to-date? Well, it’s as simply as that app.php needs to catch what the current application version is. This means that you need to retrieve current version number from the program and make it as a parameter when the URL has navigated to app.php. In case I used Borland Delphi for this test, so I drop-in a TWebBrowser component in a form and let it navigate to http://www.abc.com/app.php?v=1. The "1" number refers to current version application.


const InfoNum = 10;
InfoStr: array[1..InfoNum] of string = ('CompanyName', 'FileDescription', 'FileVersion', 'InternalName', 'LegalCopyright', 'LegalTradeMarks', 'OriginalFileName', 'ProductName', 'ProductVersion', 'Comments');


procedure TFAbout.FormShow(Sender: TObject);
var S: string;
n, Len, i: DWORD;
Buf: PChar;
Value: PChar;
Begin
S := Application.ExeName;
n := GetFileVersionInfoSize(PChar(S), n);
if n > 0 then
begin
Buf := AllocMem(n);
Memo1.Lines.Add('VersionInfoSize = ' + IntToStr(n));
GetFileVersionInfo(PChar(S), 0, n, Buf);
for i := 3 to 3 do
if VerQueryValue(Buf, PChar('StringFileInfo\040904E4\' + InfoStr[i]), Pointer(Value), Len) then
WebBrowser1.Navigate('http://www.abc.com/app.php?v='+Value);
FreeMem(Buf, n);
end;
end;


Done with client application, now it turns to PHP script app.php. The app.php consist of comparison between both current version (delivered from client via TWebBrowser component) and others up-to-date version. Take a look at completely app.php below:

<?
$v=$_GET['v'];
?>
<html>
<head>
<title>Download Update</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#E4E4E4">
<em>Current Version: <?=$v?></em><strong><br>Download Update</strong>:<br>

<?php
$wrong=0;
$right=0;
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file !="app.php") {
$file_zip = substr($file,0,1);
$file_tmp = substr($file,1,1);
if ($file_tmp>$v && $file_zip=="v")
{
$right++;
echo "&#8226; <a href='$file'>$file_tmp</a> (" . filesize($file)/1000 . " Kb)<br>";
}
else $wrong++;
}
}
closedir($handle);
}
if ($right==0 && $wrong>0) echo "-"; // shows �-� if no update available
?>
</body>
</html>



Store both of app.php and latest zipped application (v2.zip on sample) in a same path over the web server. At last, try to do a test.



Voila, those little scripts now works helping IT department from updating application task over the internet and buried the ancient way. The above scripts can be expanded to do various things for your Win32 application. Good day and don’t forget to leave your comment here.

Labels: , , , , , ,


PS: If you've benefit from this blog,
you can support it by making a small contribution.

Enter your email address to receive feed update from this blog:

Post a Comment

 

  1. Anonymous Henk said,

    Friday, November 13, 2009 6:13:00 PM

    Hi Eko,

    Thank you for unselfishly providing that wonderful online update example. That probably can easily be upgraded to automatic update using a service or on the application startup.

    Henk

  2. Blogger Eko Wahyudiharto said,

    Saturday, November 14, 2009 9:20:00 AM

    @Henk: Yups, your right bro... This current article purposed to updating a software over manually technique. On next month, I'll try to post an automatic way.

    So, please stay tuned on this channel... ;-)

Post a Comment

Leave comments here...