Sign in Join
Wiki copytemporary

LazAutoUpdater: what changed

Revision 1 to 2. 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
157-<figure>
158-<img src="updatepack1.jpg" title="updatepack1.jpg" />
159-<figcaption>updatepack1.jpg</figcaption>
160-</figure>
157+![](/wiki-images/d/d4/Updatepack1.jpg)
161158
162-<figure>
163-<img src="updatepack2.jpg" title="updatepack2.jpg" />
164-<figcaption>updatepack2.jpg</figcaption>
165-</figure>
159+![](/wiki-images/3/30/Updatepack2.jpg)
166160
167161------------------------------------------------------------------------
168162
169163## Using auOtherSourceFilename and auOtherSourceURL
170164
171165- When ProjectType is set to auOther, LazAutoUpdate will use these properties for all the Methods. See example application in the SVN archive.
172166
173167------------------------------------------------------------------------
174168
175169## LazAutoUpdate Systray Application
176170
177171- This can be found in the /trayicon folder of the source.
178172- When this is run, it sits in the system tray area and silently checks for updates via a schedule (developer and user configurable)
179173 - If it finds a new version it pops up a notification to the user to update:
180174 - If the app not running, the update is done silently in the background
181175 - If the app is running it closes it and then does the update. The app will then restart
182176- Systray updater has a right-click menu:
183177 - Configure:
184178 - The user can edit the schedule - each app has a 'profile'
185179 - Runs at startup (Windows):
186180 - The systray loads silently at each Windows boot
187181- Systray (lautraynotify) picks up entries from apps that use LazAutoupdate automatically, so it never needs to be configured - simply installed once and forgotten.
188182- The schedule is flexible, from once every day to once every month
189183 - The UpdatePack takes care of producing the systray configuration file for your app. The default is to check every Monday at 9am.
190184- The systray app works in both Windows and Linux - all you need to do is deploy it.
191185
192186------------------------------------------------------------------------
193187
194188## Making a generic online installer/updater
195189
196190- Once a LazAutoUpdate component has been dropped onto a form, it can be used for multiple updates, downloads etc. (see '/testinstaller' in package source)
197191- For a generic installer/updater you need to set:
198192 - VersionsINIFilename
199193 - ZipFilename
200194 - AppFileWithPath
201195 - AppVersion
202196- 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)
203197
204198- Here's example code to use LazAutoUpdate to download then run an application.
205199- 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'
206200- The executable 'updatehm(ostype)(.exe)' is in the same directory as your updater app
207201 - ostype=\[win32\|win64\|linux32\|linux64\]
208202 - Windows ext=(.exe)
209203- The user would download a small InnoSetup installer with just the online installer/updater, which in turn would download application(s) and supporting files.
210204 - Of course, the "installer" could **be** your main application, with sister applications installable via a menu or some such.
211205
212206``` pascal
213207procedure TForm1.Button1Click(Sender: TObject);
214208// Uses SysUtils,LazFileUtils,ulazautoupdate etc..
215209Var sDirectoryToInstallTo: string;
216210begin
217211sDirectoryToInstallTo := ProgramDirectory + 'installed';
218212Application.Title:='My whizzy app'
219213LazAutoUpdate1.WorkingMode := lauInstall;
220214LazAutoUpdate1.ProjectType := auSourceForge;
221215LazAutoUpdate1.SFProjectname:='mywizzy';
222216LazAutoUpdate1.VersionsININame:='mywizzyapp.ini';
223217LazAutoUpdate1.ZipfileName:='mywizzyapp.zip';
224218LazAutoUpdate1.AppFileWithPath := sDirectoryToInstallTo + DirectorySeparator + 'mywizzyapp.exe';
225219// Our responsibility to make the folder
226220if not DirectoryExistsUTF8(sDirectoryToInstallTo) then ForceDirectoriesUTF8(sDirectoryToInstallTo);
227221LazAutoUpdate1.Appversion:='0.0.0.0';
228222If LazAutoUpdate1.DownloadNewVersion then
229223 begin
230224 If LazAutoUpdate1.UpdateToNewVersion then
231225 begin
232226 LazAutoUpdate1.ShortCut.Category := scUtility;
233227 LazAutoUpdate1.ShortCut.Target := LazAutoUpdate1.AppFileWithPath;
234228 LazAutoUpdate1.ShortCut.ShortcutName := Application.Title;
235229 LazAutoUpdate1.MakeShortCut; // makes a desktop shortcut and a Start menu entry in Windows
236230 end;
237231 end;
238232end;
239233```
240234
241235- You can then programatically run the installed app easily enough:
242236
243237``` pascal
244238// Uses asyncprocess
245239procedure TForm1.RunInstalledApp;
246240var
247241 AProcess: TAsyncProcess;
248242begin
249243 if not FileExistsUTF8(LazAutoUpdate1.AppFileWithPath) then
250244 begin
251245 ShowMessageFmt('%s does not exist! Install it first.',
252246 [LazAutoUpdate1.AppFileWithPath]);
253247 Exit;
254248 end;
255249 AProcess := TAsyncProcess.Create(nil);
256250 try
257251 AProcess.Executable := LazAutoUpdate1.AppFileWithPath;
258252 AProcess.Execute;
259253 finally
260254 Aprocess.Free;
261255 end;
262256end;
263257```
264258
265259------------------------------------------------------------------------
266260
267261## Public Methods List
268262
269263- Function NewVersionAvailable: Boolean;
270264- Function DownloadNewVersion: Boolean;
271265- Function UpdateToNewVersion: Boolean;
272266- Procedure ShowWhatsNewIfAvailable;
273267- Procedure AutoUpdate;
274268- function AppIsActive
275269- procedure ResetAppVersion;
276270
277271------------------------------------------------------------------------
278272
279273## Non-published Properties list
280274
281275- GUIOnlineVersion: String
282276- ReturnCode: Integer
283277- DownloadInprogress: Boolean
284278- AppFileWithPath: String
285279- AppVersion: String
286280- LastError: String;
287281- DebugMode: boolean
288282- LCLVersion: string
289283- WidgetSet: string
290284- FPCVersion: string
291285- LastCompiled: string
292286- TargetOS: string
293287- WindowsAdminCheck: boolean
294288
295289------------------------------------------------------------------------
296290
297291## Deploying multiple updates in a single project
298292
299293- 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
300294- Each application to be updated should have a unique name for the versions.ini file. Set the VersionsINIFilename property.
301295
302296------------------------------------------------------------------------
303297
304298## In case the download takes to long
305299
306300- VersionCountLimit property determines how long LazAutoUpdate will check for a new version before timing out.
307301- DownloadCountLimit property determines how long LazAutoUpdate will try downloading the new version before timing out.
308302
309303------------------------------------------------------------------------
310304
311305## Versions.ini
312306
313307The format is as follows:
314308
315309`;LazAutoUpdate versions file`\
316310`[versions]`\
317311`GUI=0.0.2`
318312
319313- The file is small so that it is very quick to download
320314
321315------------------------------------------------------------------------
322316
323317## Source Code and latest versions
324318
325319- [Project Page](https://sourceforge.net/projects/lazautoupdate/)
326320- [SVN HTTP Checkout](https://svn.code.sf.net/p/lazarus-ccr/svn/components/lazautoupdate/latest_stable)
327321
328322------------------------------------------------------------------------
329323
330324## Security
331325
332326### Windows 10
333327
334328- 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.
335329 - 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.
336330 - 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.
337331 - 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.
338332
339333### Linux
340334
341335- Linux will do the update without even showing the update console, and the user gets a seamless experience.
342336
343337------------------------------------------------------------------------
344338
345339## Workflow
346340
347341(Technical explanation)
348342
349343The Lazarus Auto-Updater workflow for updating a running application is as follows:
350344
351345- App downloads a small 'version.ini' file from sourceforge or github with version info (it can do this at start-up)
352346- App compares with its own internal version
353347- If new version available
354348 - App deletes any contents of local /updates folder
355349 - App downloads then unzips it from the web into a local /updates folder
356350- App uses TAsyncProcess to start the console updater.exe, passing it the name of the file to be updated in the command line
357351- updater.exe copies a downloaded 'whatsnew.txt' into the App folder and enters Sleep for a few seconds
358352- Meanwhile App has entered loop checking whether a 'whatsnew.txt' file has been copied into it's directory
359353- App detects 'whatsnew.txt' and Closes. (in other words the TProcess has started successfully)
360354- Updater copies /updates/UpdatedApp to App directory.
361355- Updater uses TProcess to start the updated app
362356- On Form.Show, App displays 'whatsnew.txt' then deletes it
363357
364358The User sees:
365359
366360- Dialog: 'There's a new version of xxx available. Would you like to download it?' Yes/No
367361- If Yes clicked:
368362 - Download happens in the background (via a background thread) Optional 'download counter' is shown to indicate progress.
369363 - User is prevented from closing the app whilst the download is in progress (in Form.CloseQuery)
370364 - Dialog: 'The update is downloaded. Click OK to install it and restart xxx now' OK
371365 - User clicks OK
372366 - A console (DOS window in Windows) opens automatically and the Application closes. The console says 'Please wait updating xxx'
373367 - After a couple of seconds the console disappears, and the new version of the App starts
374368 - As soon as the main window is shown, a 'What's New' info box is shown with an OK button
375369 - User clicks OK button, and never sees the info again
376370
377371------------------------------------------------------------------------
378372
379373Minesadorada
380374
381375---
382376*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