Sign in Join
Wiki copytemporary

LazAutoUpdater: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Summary
22
33- LazAutoUpdate is a visual drop-in component for the Lazarus/FPC IDE to make updating your application from an online source easier and smarter.
44- When making an app for distribution, coding an update process for users can be a bother, yet users appreciate the facility (so long as it's not forced on them!) and support is easier if you know that the user always has the most up-to-date version of your app. LazAutoUpdate is designed to integrate well with your SourceForge or GitHub version control ensuring a trouble-free experience for you and your users.
55- LazAutoUpdate downloads via a background thread so the user can continue using your app without interruption
66 - This means for example, your app can 'check for updates' at startup without the app becoming unresponsive.
77- It is aimed at Lazarus Windows and Linux developers who host their project in SourceForge or GitHub.
88- Drop-in the component, set a couple of properties (your SourceForge project name, or some GitHub properties) and call one simple method:
99 - **LazAutoUpdate.AutoUpdate**
1010- You (the developer) have plenty of control over how the component behaves, yet it is simple to use.
1111- End-users see the updating process as simple and transparent
1212- Tested and developed in Windows 10 64/32-bit and Linux 64/32-bit
1313
1414![](/wiki-images/9/94/Lauobjinsp1.jpg) ![](/wiki-images/1/18/Lauobjinsp2.jpg)
1515
1616------------------------------------------------------------------------
1717
1818## Download
1919
2020- LazAutoUpdate suite installer (Windows) or zip (Linux) can be downloaded from the [SourceForge project site](http://sourceforge.net/projects/lazautoupdate/)
2121- The Lazarus OnlinePackager also contains LazAutoUpdate
2222
2323------------------------------------------------------------------------
2424
2525## Installation
2626
2727- Download the Windows setup file or the linuxbinaries zip
2828- Windows: Install, Linux: Unzip in a spare folder
2929- Use the UpdatePack to make and distribute your update files
3030- Use the LazAutoUpdate component to add update functionality to your Lazarus app
3131 - **You will need to distribute updatehm\<os\>(.exe) with your application for LazAutoUpdate to work correctly**
3232 - **Don't forget to set VersionInfo numbers in your Lazarus Project options**
3333
3434------------------------------------------------------------------------
3535
3636## Example application
3737
3838- In the download package is the project 'TestApp'
3939- Compile and run TestApp (remembering to compile+copy the appropriate console updater (updatehm_xxx) to the executable folder)
4040 - It should update itself 'out-of-the-box'
4141- Check out the source code of TestApp to get an idea of how to use LazAutoUpdate to its full potential
4242
4343------------------------------------------------------------------------
4444
4545## Internationalisation
4646
4747- i8n: LazAutoUpdate has a 'locale' folder with all the .po files needed for translation. The base language is English
4848
4949------------------------------------------------------------------------
5050
5151## Use
5252
5353- Set a version number for your app in Project/Options/Versioninfo
5454- Drop the component onto the main form of your application
5555- Set the SFProjectName property to your SourceForge project name (the same text as appears in the URL for your project page)
5656- or.. Set the GitHub properties:
5757 - GitHubProjectname: Username or Organisation
5858 - GitHubRepositoryName: Your project/repository
5959 - GitHubBranchOrTag: 'master' for the root or the GitHub Branch name **or** Tag name
6060- In both cases set the UpdatesFolder to the location of your update files (you can leave it blank)
6161- Use the UpdatePack to upload your app to the internet (SourceForge, GitHub etc)
6262- **Then let the component take care of the details. Just use (perhaps as a Help menu item 'Check for updates')**
6363
6464``` pascal
6565LazAutoUpdate1.AutoUpdate;
6666```
6767
6868- You don't want the user to close your application in the middle of an update! Use this code in the Form.CloseQuery handler:
6969
7070``` pascal
7171If LazAutoUpdate1.DownloadInProgress Then
7272 Begin
7373 CanClose := False;
7474 ShowMessage('Please wait. Download is still progress.');
7575 End;
7676```
7777
7878- After an update your app can show 'What's new' automatically. Put this line into your Form's OnShow event:
7979
8080``` pascal
8181LazAutoUpdate1.ShowWhatsNewIfAvailable;
8282```
8383
8484- This gives you the 'bare bones' of the update code for your application. As you can see, it's all pretty automatic and simple.
8585
8686### More control
8787
8888- Decide if you want your app to check for updates on startup. If so, in your form.activate handler:
8989
9090``` pascal
9191If LazAutoUpdate1.NewVersionAvailable Then
9292 MessageDlg(Application.Title, 'A new version of ' + Application.Title +
9393 ' is available.' + LineEnding +
9494 'Click ''Check for new version'' in Help menu to update', mtConfirmation,
9595 [mbOK], 0);
9696```
9797
9898- If you do not use the AutoUpdate method, you have control over the update process in stages via the functions:
9999
100100``` pascal
101101If LazAutoUpdate1.NewVersionAvailable then ..... else ...
102102```
103103
104104``` pascal
105105If LazAutoUpdate1.DownloadNewVersion then ..... else ...
106106```
107107
108108``` pascal
109109If LazAutoUpdate1.UpdateToNewVersion then ..... else ...
110110```
111111
112112### Debugging
113113
114114- If you set
115115
116116``` pascal
117117LazAutoUpdate1.DebugMode:=TRUE;
118118```
119119
120120then you can use the built-in OnDebugEvent method to log activity:
121121
122122``` pascal
123123procedure TForm1.LazAutoUpdate1DebugEvent(Sender: TObject; lauMethodName,
124124 lauMessage: string);
125125begin
126126// Use TEventLog
127127 Logger.Info('('+lauMethodName+') - ' + lauMessage);
128128end;
129129```
130130
131131There are also events fired: OnDownloaded and OnNewVersionAvailable and the property LastError with info that you might use for debugging.
132132
133133------------------------------------------------------------------------
134134
135135## Support
136136
137137- LazAutoUpdate is supported via the Lazarus forum [here](http://forum.lazarus.freepascal.org/index.php/topic,25444.0.html).
138138
139139------------------------------------------------------------------------
140140
141141## License
142142
143143- LazaAutoUpdate: LGPLv2 (same as Lazarus components)
144144- Update Pack: GPLv2
145145
146146------------------------------------------------------------------------
147147
148148## Deploying your Application with LazAutoUpdate
149149
150150- Use UpdatePack to manage the process.
151151 - UpdatePack is a GUI application that makes the update files accurately and quickly, and even gives you the corresponding LazAutoUpdate code for your app.
152152 - It uses 'profiles' that enable you to deploy future updates by simply updating the version number and clicking 'Create Update Pack'.
153153 - Your app users will benefit from having the latest version of your software always available
154154- When testing, remember your testing app should be a lower version number than your 'update' app stored online :)
155155- If you want to make up (or add to) the update zip yourself, it should contain the App **and** the text file 'whatsnew.txt' as a minimum.
156156
157157![](/wiki-images/d/d4/Updatepack1.jpg)
158158
159159![](/wiki-images/3/30/Updatepack2.jpg)
160160
161161------------------------------------------------------------------------
162162
163163## Using auOtherSourceFilename and auOtherSourceURL
164164
165165- When ProjectType is set to auOther, LazAutoUpdate will use these properties for all the Methods. See example application in the SVN archive.
166166
167167------------------------------------------------------------------------
168168
169169## LazAutoUpdate Systray Application
170170
171171- This can be found in the /trayicon folder of the source.
172172- When this is run, it sits in the system tray area and silently checks for updates via a schedule (developer and user configurable)
173173 - If it finds a new version it pops up a notification to the user to update:
174174 - If the app not running, the update is done silently in the background
175175 - If the app is running it closes it and then does the update. The app will then restart
176176- Systray updater has a right-click menu:
177177 - Configure:
178178 - The user can edit the schedule - each app has a 'profile'
179179 - Runs at startup (Windows):
180180 - The systray loads silently at each Windows boot
181181- Systray (lautraynotify) picks up entries from apps that use LazAutoupdate automatically, so it never needs to be configured - simply installed once and forgotten.
182182- The schedule is flexible, from once every day to once every month
183183 - The UpdatePack takes care of producing the systray configuration file for your app. The default is to check every Monday at 9am.
184184- The systray app works in both Windows and Linux - all you need to do is deploy it.
185185
186186------------------------------------------------------------------------
187187
188188## Making a generic online installer/updater
189189
190190- Once a LazAutoUpdate component has been dropped onto a form, it can be used for multiple updates, downloads etc. (see '/testinstaller' in package source)
191191- For a generic installer/updater you need to set:
192192 - VersionsINIFilename
193193 - ZipFilename
194194 - AppFileWithPath
195195 - AppVersion
196196- By setting these properties dynamically (perhaps via a menu) you can enable the user to update multiple applications hosted on a SourceForge/GitHub project site (or any site using auOther settings - see above)
197197
198198- Here's example code to use LazAutoUpdate to download then run an application.
199199- The zipped files for the application (including 'whatsnew.txt') and the file 'mywizzyapp.ini' are located in the /updates subdirectory of the SourceForge project 'mywizzy'
200200- The executable 'updatehm(ostype)(.exe)' is in the same directory as your updater app
201201 - ostype=\[win32\|win64\|linux32\|linux64\]
202202 - Windows ext=(.exe)
203203- The user would download a small InnoSetup installer with just the online installer/updater, which in turn would download application(s) and supporting files.
204204 - Of course, the "installer" could **be** your main application, with sister applications installable via a menu or some such.
205205
206206``` pascal
207207procedure TForm1.Button1Click(Sender: TObject);
208208// Uses SysUtils,LazFileUtils,ulazautoupdate etc..
209209Var sDirectoryToInstallTo: string;
210210begin
211211sDirectoryToInstallTo := ProgramDirectory + 'installed';
212212Application.Title:='My whizzy app'
213213LazAutoUpdate1.WorkingMode := lauInstall;
214214LazAutoUpdate1.ProjectType := auSourceForge;
215215LazAutoUpdate1.SFProjectname:='mywizzy';
216216LazAutoUpdate1.VersionsININame:='mywizzyapp.ini';
217217LazAutoUpdate1.ZipfileName:='mywizzyapp.zip';
218218LazAutoUpdate1.AppFileWithPath := sDirectoryToInstallTo + DirectorySeparator + 'mywizzyapp.exe';
219219// Our responsibility to make the folder
220220if not DirectoryExistsUTF8(sDirectoryToInstallTo) then ForceDirectoriesUTF8(sDirectoryToInstallTo);
221221LazAutoUpdate1.Appversion:='0.0.0.0';
222222If LazAutoUpdate1.DownloadNewVersion then
223223 begin
224224 If LazAutoUpdate1.UpdateToNewVersion then
225225 begin
226226 LazAutoUpdate1.ShortCut.Category := scUtility;
227227 LazAutoUpdate1.ShortCut.Target := LazAutoUpdate1.AppFileWithPath;
228228 LazAutoUpdate1.ShortCut.ShortcutName := Application.Title;
229229 LazAutoUpdate1.MakeShortCut; // makes a desktop shortcut and a Start menu entry in Windows
230230 end;
231231 end;
232232end;
233233```
234234
235235- You can then programatically run the installed app easily enough:
236236
237237``` pascal
238238// Uses asyncprocess
239239procedure TForm1.RunInstalledApp;
240240var
241241 AProcess: TAsyncProcess;
242242begin
243243 if not FileExistsUTF8(LazAutoUpdate1.AppFileWithPath) then
244244 begin
245245 ShowMessageFmt('%s does not exist! Install it first.',
246246 [LazAutoUpdate1.AppFileWithPath]);
247247 Exit;
248248 end;
249249 AProcess := TAsyncProcess.Create(nil);
250250 try
251251 AProcess.Executable := LazAutoUpdate1.AppFileWithPath;
252252 AProcess.Execute;
253253 finally
254254 Aprocess.Free;
255255 end;
256256end;
257257```
258258
259259------------------------------------------------------------------------
260260
261261## Public Methods List
262262
263263- Function NewVersionAvailable: Boolean;
264264- Function DownloadNewVersion: Boolean;
265265- Function UpdateToNewVersion: Boolean;
266266- Procedure ShowWhatsNewIfAvailable;
267267- Procedure AutoUpdate;
268268- function AppIsActive
269269- procedure ResetAppVersion;
270270
271271------------------------------------------------------------------------
272272
273273## Non-published Properties list
274274
275275- GUIOnlineVersion: String
276276- ReturnCode: Integer
277277- DownloadInprogress: Boolean
278278- AppFileWithPath: String
279279- AppVersion: String
280280- LastError: String;
281281- DebugMode: boolean
282282- LCLVersion: string
283283- WidgetSet: string
284284- FPCVersion: string
285285- LastCompiled: string
286286- TargetOS: string
287287- WindowsAdminCheck: boolean
288288
289289------------------------------------------------------------------------
290290
291291## Deploying multiple updates in a single project
292292
293293- By default, the ZipFilename is the same as your application, but you can set it to a unique value, and deploy it to your Online Files/updates irectory
294294- Each application to be updated should have a unique name for the versions.ini file. Set the VersionsINIFilename property.
295295
296296------------------------------------------------------------------------
297297
298298## In case the download takes to long
299299
300300- VersionCountLimit property determines how long LazAutoUpdate will check for a new version before timing out.
301301- DownloadCountLimit property determines how long LazAutoUpdate will try downloading the new version before timing out.
302302
303303------------------------------------------------------------------------
304304
305305## Versions.ini
306306
307307The format is as follows:
308308
309-`;LazAutoUpdate versions file`\
310-`[versions]`\
311-`GUI=0.0.2`
309+```text
310+;LazAutoUpdate versions file
311+[versions]
312+GUI=0.0.2
313+```
312314
313315- The file is small so that it is very quick to download
314316
315317------------------------------------------------------------------------
316318
317319## Source Code and latest versions
318320
319321- [Project Page](https://sourceforge.net/projects/lazautoupdate/)
320322- [SVN HTTP Checkout](https://svn.code.sf.net/p/lazarus-ccr/svn/components/lazautoupdate/latest_stable)
321323
322324------------------------------------------------------------------------
323325
324326## Security
325327
326328### Windows 10
327329
328330- Windows 10 security will not allow a non-admin user to update applications from the internet (unless it's a Windows Store App). This is a sensible policy in my opinion, and LazAutoUpdate adheres to it.
329331 - If an 'ordinary user' tries to update an app using LazAutoUpdate, all will go smoothly until the final 'Update app' phase. At that point LazAutoUpdate will pop up a dialog informing the user that an administrator account is needed for the actual update.
330332 - For an 'admin user', LazAutoUpdate will pop up a UAC dialog (the same as any installer) and proceed upon clicking 'yes' to do the update.
331333 - If you wish to circumvent this (perhaps with a manifest) LazAutoUpdate has the public property 'WindowsAdminCheck' which you can set to FALSE and avoid the dialog.
332334
333335### Linux
334336
335337- Linux will do the update without even showing the update console, and the user gets a seamless experience.
336338
337339------------------------------------------------------------------------
338340
339341## Workflow
340342
341343(Technical explanation)
342344
343345The Lazarus Auto-Updater workflow for updating a running application is as follows:
344346
345347- App downloads a small 'version.ini' file from sourceforge or github with version info (it can do this at start-up)
346348- App compares with its own internal version
347349- If new version available
348350 - App deletes any contents of local /updates folder
349351 - App downloads then unzips it from the web into a local /updates folder
350352- App uses TAsyncProcess to start the console updater.exe, passing it the name of the file to be updated in the command line
351353- updater.exe copies a downloaded 'whatsnew.txt' into the App folder and enters Sleep for a few seconds
352354- Meanwhile App has entered loop checking whether a 'whatsnew.txt' file has been copied into it's directory
353355- App detects 'whatsnew.txt' and Closes. (in other words the TProcess has started successfully)
354356- Updater copies /updates/UpdatedApp to App directory.
355357- Updater uses TProcess to start the updated app
356358- On Form.Show, App displays 'whatsnew.txt' then deletes it
357359
358360The User sees:
359361
360362- Dialog: 'There's a new version of xxx available. Would you like to download it?' Yes/No
361363- If Yes clicked:
362364 - Download happens in the background (via a background thread) Optional 'download counter' is shown to indicate progress.
363365 - User is prevented from closing the app whilst the download is in progress (in Form.CloseQuery)
364366 - Dialog: 'The update is downloaded. Click OK to install it and restart xxx now' OK
365367 - User clicks OK
366368 - A console (DOS window in Windows) opens automatically and the Application closes. The console says 'Please wait updating xxx'
367369 - After a couple of seconds the console disappears, and the new version of the App starts
368370 - As soon as the main window is shown, a 'What's New' info box is shown with an OK button
369371 - User clicks OK button, and never sees the info again
370372
371373------------------------------------------------------------------------
372374
373375Minesadorada
374376
375377---
376378*From the Free Pascal wiki, page "LazAutoUpdater", as it stood on 2022-01-07 after a change by FTurtle, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history