Improve company productivity with a Business Account.Sign Up


Update system

Posted on 2006-07-23
Medium Priority
Last Modified: 2010-04-05
Hi everyone,
I am tryin to build an update system for my application.
I am just wondering the best way to go about doing it.
The basic logic for my system looks something like this:

Client click update
Connect to server
Send client version number eg 1.2.10
Compare version on server with client version
if version on server is higher then
      get server address of files to be downloaded
      for each file to be downloaded

      when finished downloading
      run installer
            for each file that was downloaded
                  rename current file as old file eg simplewriter_old.exe
                  rename downloaded file eg simplewriter_new.exe -> simplewriter.exe
                  delete simplewriter_old.exe

end else
      output 'no need to update'

But at the moment I have quite a static system that is heavily dependent on the code that is on my clients machines.
Is there anyway I can build a system where the user can connect to eg some php script and this script on the server takes care of the update for the user? Is this advised?
The reason that I am thinking to do this is because as things change so much, it would be better to have code that I can edit on the server as the changes happen rather than being dependent on the code that is comiled in the exe on the users comptuer...

What are your thoughuts?
Question by:myleseven
  • 10
  • 4

Author Comment

ID: 17164720
To help you understand what I mean, here is the PHP file that I am working on...


//Run Code

//Functions and Procs
function FileDetails()
      $newVersion = "1.2.11";
      echo "newVersion: " .$newVersion."<br>";  
      $newTotSize = "3 Mega Bytes"; //how can I make this dynamic
      echo "newTotSize: " .$newTotSize."<br>";  
      echo "<br>";

//--Note: mmFlag will let system know if it should download this file
//download details for App1
      $mmFlag = "true"; //tells client if can download this app
      echo "mmFlag: " .$mmFlag."<br>";
      $mmAppName = "App1_".$newVersion.".exe";  //tells client the name of the app
      echo "mmAppName: " .$mmAppName."<br>";
      $mmDownload = "".$newVersion."/".$mmAppName; //tells client where app is on the server
      echo "mmDownload: " .$mmDownload."<br>";
      echo "<br>";
//download details for App2
      $swFlag = "false";
      echo "swFlag: " .$swFlag."<br>";
      $swAppName = "App2_".$newVersion.".exe";
      echo "swAppName: " .$swAppName."<br>";
      $swDownload = "".$newVersion."/".$swAppName;
      echo "swDownload: " .$swDownload."<br>";
      echo "<br>";

//download details for App3
      $snFlag = "false";
      echo "snFlag: " .$snFlag."<br>";
      $snAppName = "App3_".$newVersion.".exe";
      echo "snAppName: " .$snAppName."<br>";
      $snDownload = "".$newVersion."/".$snAppName;
      echo "snDownload: " .$snDownload."<br>";
      echo "<br>";

//download details for App4
      $smFlag = "false";
      echo "smFlag: " .$smFlag."<br>";
      $smAppName = "App4_".$newVersion.".exe";
      echo "smAppName: " .$smAppName."<br>";
      $smDownload = "".$newVersion."/".$smAppName;
      echo "smDownload: " .$smDownload."<br>";
      echo "<br>";

//download details for App5
      $ssFlag = "true";
      echo "ssFlag: " .$ssFlag."<br>";
      $ssAppName = "App5_".$newVersion.".exe";
      echo "ssAppName: " .$ssAppName."<br>";
      $ssDownload = "".$newVersion."/".$ssAppName;
      echo "ssDownload: " .$ssDownload."<br>";
      echo "<br>";

//download details for App6
      $inFlag = "false";
      echo "inFlag: " .$inFlag."<br>";
      $inAppName = "App6_".$newVersion.".exe";
      echo "inAppName: " .$inAppName."<br>";
      $inDownload = "".$newVersion."/".$inAppName;
      echo "inDownload: " .$inDownload."<br>";
      echo "<br>";



Author Comment

ID: 17164729
The outputted source might look like this:

#$D#$A'newVersion: 1.2.11<br>
newTotSize: 3 Mega Bytes<br>
mmFlag: true<br>
mmAppName: App1_1.2.11.exe<br>
swFlag: false<br>
swAppName: App2_1.2.11.exe<br>
snFlag: false<br>
snAppName: App3_1.2.11.exe<br>
smFlag: false<br>
smAppName: App4_1.2.11.exe<br>
ssFlag: true<br>
ssAppName: App5_1.2.11.exe<br>
inFlag: false<br>
inAppName: App6_1.2.11.exe<br>

Author Comment

ID: 17164747
Basically after verifying that there is a newer version on the Web my updater will pull the source code from the web
and for example then call the proc: StartUpdate

function TfrmUpdate.StartUpdate(sMotherDownloadPath, sSource, sInstallerPath, sVersiononWeb : string): string;
{Begins the download process
1. Creates a logfile to record what files were downloaded
2. Prepares system to download each file if it has not been already}
{Returns: File path of the downloaded installer or c_Null if it has not yet been downloaded}
  sLocalDownloadPath,sLogPath : string;
  aTextFile : TextFile;
  g_DoDownload := true;
  sInstallerPath := c_null;

    //create a log file to store the info as to which files were  downloaded
    //each log will be unique for the download version
    //this log file will not be re writtain to but wil be appended to
    //The installer will refer to this file when installing the files....
    if  (g_DoDownload = true) then
      sLocalDownloadPath := sMotherDownloadPath + 'installer\';
      sLogPath := sLocalDownloadPath + 'log_'+ sVersiononWeb+ '.txt';
      If FileExists(sLogPath) = false then
        AssignFile(aTextFile, sLogPath);

    //prepare to download mainmenu
    //NOTE: mmFlag is the flag on the server that lets system know it needs to download this file
    if  (g_DoDownload = true) and (StrToBool(getKeyValue('mmFlag:',sSource))) then
      sLocalDownloadPath := sMotherDownloadPath + 'App1\';
    if (g_DoDownload = true) and (StrToBool(getKeyValue('swFlag:',sSource))) then
      //repare to download simplewriter
      sLocalDownloadPath := sMotherDownloadPath + 'App2\';
    if (g_DoDownload = true) and (StrToBool(getKeyValue('smFlag:',sSource))) then
      //prepare to download simplemail
      sLocalDownloadPath := sMotherDownloadPath + 'App3\';
    if (g_DoDownload = true) and (StrToBool(getKeyValue('snFlag:',sSource))) then
      //prepare to download simplenet
      sLocalDownloadPath := sMotherDownloadPath + 'App4\';
    if (g_DoDownload = true) and (StrToBool(getKeyValue('ssFlag:',sSource))) then
      //prepare to download simpleshortcut
      sLocalDownloadPath := sMotherDownloadPath + 'App5\';

    //NOTE: The installer must be downloaded last as a shortcut is placed on the desktop
    //      and if user does a partial download then we don't want the user to be able to click
    //      the shortcut to install the software if it has not all been downloaded
    if (g_DoDownload = true) and (StrToBool(getKeyValue('inFlag:',sSource))) then
      //prepare to download installer exe
      sLocalDownloadPath := sMotherDownloadPath + 'installer\';
      result := sInstallerPath;
  result := sInstallerPath;

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

ID: 17164755
function TfrmUpdate.GetKeyValue(sKey,sSource:string):string;
  iStart, iEnd : integer;
  lSource, lKey  : string ;
  lSource := lowercase(sSource);
  lKey := lowercase(sKey);
  //ensure there is a ':' at end of lKey
  if lKey[Length(lKey)] <> ':' then lKey := lKey + ':';

  iStart := PosEx(lKey,lSource) + length(lkey);
  iEnd := posex('<br>',lSource,iStart);

  result := trim(MidStr(sSource,iStart,iEnd-iStart));

Author Comment

ID: 17164760

The ,major problem is that the client code is heaveily dependent on the variables that it pulls from the webpage source

as can be seen from the delphi code:

  if (g_DoDownload = true) and (StrToBool(getKeyValue('snFlag:',sSource))) then
      //prepare to download simplenet
      sLocalDownloadPath := sMotherDownloadPath + 'App4\';

can you see how I have 'hardcoded' in the value 'snFlag'. This value is then used as the key in 'GetKeyValue' to pull the boolean value that this snFlag refers to. I have used this system throughout the client code as can be seen in the call to proc:

with snDOwnload and snAppName both 'keys' that are used to reference values in the URL source

The thing is if I add for example a completely new application then my users won't be able to download this new application as they won't have the hardcoded 'Keys'

Do you see where my problem is?
Any ideas

Author Comment

ID: 17164765
I think I need some sort of loop system to be able to pull the keys from the php page...
LVL 17

Expert Comment

ID: 17164889
(This is the question I always ask for this)
If the user is on version 1 of "SimpleWriter.exe" and the latest version is version 3
does the user
A) download "SimpleWriter.exe" version 2, runs it and checks for next update, then downloads "SimpleWriter.exe" version 3, runs it, checks for updates, sees it is the latest update, and stops.
B) download "SimpleWriter1 to SimpleWriter2.exe", then "SimpleWriter2 to SimpleWriter3.exe"
or do they just
B) download "SimpleWriter.exe" version 3 ?

Is the updater code inside "SimpleWriter.exe" or is it "MyUpdater.exe"
and can you download updates for "MyUpdater.exe"

You could have the updater, update itself first ( so it gets the new available "hardcoded" application "snFlag")
If the applications are updating 1 version at a time, you can have a version that knows about the new stuff
and runs an update again once it is installed
V1.0 knows current snFlag
V1.5 knows current snFlag, and new snFlag, and will download new snFlag stuff next time
V2.0 knows current snFlag, and new snFlag

so when you upgrade to v1.5 it learns about the new snFlag, and when it updates, it downlaods the new files for snFlag

Author Comment

ID: 17165122
Hi thanks Loki,
Yes that is a good question that you asked.
I think for general bug fixes and releases it would be ok for a user to go from version1.2.10 straight to version 1.2.13 for example
For major and minor realeases eg 1.2 move to 1.4 or 1 move to 3 I am still thinking abuot that one.
My upgrade system is reasonably primitive in that the user needs to download an entire exe for each app being upgraded so, it is probably ok to allow big jumps at this stage.
If I broke up my .exe's into .dll's etc perhaps I might need to step the user up through the version's I am not sure? as I havn't worked so much with .dll's before. What do you think?

The updater code is inside installer.exe
This file is downloaded from the server with all the latest .exe

I am thinking to have another variable inside the php code this would be a comma delimited string that holds all the flag keys
eg FlagKeys = mmFlag,snFlag,swFlag etc
downloadKeys=mmDownload,snDownload,swDownload etc

I could then pull these vars from the client side app and loop through them as needed...

what do you think?

LVL 17

Accepted Solution

TheRealLoki earned 1000 total points
ID: 17165214
I'd be tempted to use a "1_0to2_0setup.exe" file for each upgrade, for the following reasons
1) compression - at the very least you'd want to zip up SimpleWriter.exe so it doesn't take as long to upgrade. This might be all you do, so not a setup.exe as such, but just a compressed file
2) you could then upgrade any related dll's, reg/ini/xml settings
3) authentication - the setup could have a crc checksum so users are sure the upgrade has not been tampered with on teh way down.

It would be great if you could make the entire process "data-driven" by storing all the flags in a list, and making your client code work with it.
maybe you could use a TStringList.Values[] / Names[] approach


Author Comment

ID: 17165440
.zipping up the files would be great, but how can do I extract them during install, especially if the user doesn't have winzip
LVL 17

Expert Comment

ID: 17165478
you can make a self-extracting zip file (.exe)

Author Comment

ID: 17165528

Can you point me as to where I can find out how to make a self-extracting zip it sounds great!
ok I gotta go now, be back tomorrow

LVL 17

Expert Comment

ID: 17165581
I think it's a professional (ie. bought) feature, but I could be wrong
if you're using WinZip, it's Action->Make .exe
if you're using pkzip in dos mode, it's Zip2Exe

Author Comment

ID: 17220088
Thanks heaps for your help loki
I havn't tried the zip extractoin yet but I will have a look later.
Anyway the points are yours

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…
Watch the video to know the simple way to remove or recover or reset lost or forgotten passwords of Outlook PST file. With Kernel Outlook Password Recovery tool such operation is very easy to perform. It is a freeware with limitation to use with 500…

606 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question