Difference between revisions of "LazAutoUpdater"

From Free Pascal wiki
Jump to navigationJump to search
m (Changed a heading)
(Added example of application code)
Line 80: Line 80:
 
*The application installer (Inno Setup?) goes into your Files section as normal
 
*The application installer (Inno Setup?) goes into your Files section as normal
 
**The Users should only have to download the installer once.  All the subsequent versions will go into the /updates folder as above
 
**The Users should only have to download the installer once.  All the subsequent versions will go into the /updates folder as above
 +
<br>
 +
----
 +
===In-Application Code===
 +
*Here's what a typical 'Check for Updates' handler would look like:
 +
  if LazAutoUpdater.NewVersionAvailable then
 +
  begin
 +
    if MessageDlg(Application.Title, 'A new version of ' + Application.Title +
 +
      ' is available.' + LineEnding + 'Would you like to download it?',
 +
      mtConfirmation, [mbYes, mbNo], 0) = mrYes then
 +
      if LazAutoUpdater.DownloadNewVersion then
 +
        LazAutoUpdater.UpdateToNewVersion
 +
      else
 +
        MessageDlg(Application.Title,
 +
          'Update cancelled', mtInformation, [mbOK], 0);
 +
  end
 +
  else
 +
  begin
 +
    MessageDlg(Application.Title,
 +
      'Your current version is fully up-to-date',
 +
      mtInformation,
 +
      [mbOK], 0);
 +
  end;
 
<br>
 
<br>
 
----
 
----
Line 88: Line 110:
 
*Write full documentation so that the process is as painless as possible for developers
 
*Write full documentation so that the process is as painless as possible for developers
 
*Make the LazAutoUpdate itself auto-updateable via SourceForge
 
*Make the LazAutoUpdate itself auto-updateable via SourceForge
<br>
+
 
----
 
 
...work-in-progress
 
...work-in-progress
  
 
[[User:Minesadorada|Minesadorada]]
 
[[User:Minesadorada|Minesadorada]]

Revision as of 21:23, 30 July 2014

Lazarus Auto-Updater

SourceForge Project



Workflow

The Laz AutoUpdater workflow for updating a running application is as follows:

  • App downloads a small 'version.xml' file from sourceforge with version info (it can do this at start-up)
  • App compares with its own internal version
  • If new version available
    • App deletes any contents of local /updates folder
    • App downloads then unzips it from Sourceforge into a local /updates folder
  • App uses TAsyncProcess to start the console updater.exe, passing it the name of the file to be updated in the command line
  • updater.exe copies a downloaded 'whatsnew.txt' into the App folder and enters Sleep for a few seconds
  • Meanwhile App has entered loop checking whether a 'whatsnew.txt' file has been copied into it's directory
  • App detects 'whatsnew.txt' and Closes. (in other words the TProcess has started successfully)
  • Updater copies /updates/UpdatedApp to App directory.
  • Updater uses TProcess to start the updated app
  • On Form.Show, App displays 'whatsnew.txt' then deletes it

The User sees:

  • Dialog: 'There's a new version of xxx available. Would you like to download it?' Yes/No
  • If Yes clicked:
    • Download happens in the background (via a background thread) Optional 'download counter' is shown to indicate progress.
    • User is prevented from closing the app whilst the download is in progress (in Form.CloseQuery)
    • Dialog: 'The update is downloaded. Click OK to install it and restart xxx now' OK
    • User clicks OK
    • A console (DOS window in Windows) opens automatically and the Application closes. The console says 'Please wait updating xxx'
    • After a couple of seconds the console disappears, and the new version of the App starts
    • As soon as the main window is shown, a 'What's New' info box is shown with an OK button
    • User clicks OK button, and never sees the info again



Version.xml

The format is as follows:

<?xml version="1.0" encoding="utf-8"?>
<APPCONFIG>
  <ProgramInfo>
    <Version GUI="0.0.2" OtherModule="0.1.0"/>
  </ProgramInfo>
</APPCONFIG>

The code to create it:

uses XMLConf
Var XMLConfig1:TXMLConfig; 
begin
 XMLConfig1.Clear;
 XMLConfig1.RootName := 'APPCONFIG';
 XMLConfig1.Filename := 'version.xml';
 XMLConfig1.OpenKey('ProgramInfo/Version');
 XMLConfig1.SetValue('GUI', '0.0.2');
 XMLConfig1.SetValue('OtherModule', '0.1.0');
 XMLConfig1.CloseKey;
 XMLConfig1.Flush;
end;

The code to read it:

uses XMLConf
Var XMLConfig1 :TXMLConfig; 
    szAppVer :String;
    szOtherMouleVer :String;
begin
 XMLConfig1.Clear;
 XMLConfig1.RootName := 'APPCONFIG';
 XMLConfig1.Filename := 'version.xml';
 XMLConfig1.OpenKey('ProgramInfo/Version');
 szAppVer:= XMLConfig1.GetValue('GUI', '0.0.0'); // Default is '0.0.0'
 szOtherMouleVer:= XMLConfig1.GetValue('OtherModule', '0.0.0'); // Default is '0.0.0'
 XMLConfig1.CloseKey;



Deploying an update

  • In the SourceForge project Files section, make a folder called 'updates'
  • Upload 'version.xml' into it
  • Upload the zip file containing your updated EXE and the file 'whatsnew.txt'
  • The application installer (Inno Setup?) goes into your Files section as normal
    • The Users should only have to download the installer once. All the subsequent versions will go into the /updates folder as above



In-Application Code

  • Here's what a typical 'Check for Updates' handler would look like:
 if LazAutoUpdater.NewVersionAvailable then
 begin
   if MessageDlg(Application.Title, 'A new version of ' + Application.Title +
     ' is available.' + LineEnding + 'Would you like to download it?',
     mtConfirmation, [mbYes, mbNo], 0) = mrYes then
     if LazAutoUpdater.DownloadNewVersion then
       LazAutoUpdater.UpdateToNewVersion
     else
       MessageDlg(Application.Title,
         'Update cancelled', mtInformation, [mbOK], 0);
 end
 else
 begin
   MessageDlg(Application.Title,
     'Your current version is fully up-to-date',
     mtInformation,
     [mbOK], 0);
 end;



Roadmap

  • Wrap as much as possible into a single visual component that a developer can drop onto their form, and set properties
  • Enable (Console) update.exe to deal with multiple files to update
  • Enable (Console) update.exe to deal with updates to subdirectories of the application
  • Write full documentation so that the process is as painless as possible for developers
  • Make the LazAutoUpdate itself auto-updateable via SourceForge

...work-in-progress

Minesadorada