Recent

Author Topic: Starting a Detached Updater App  (Read 438 times)

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 60
Starting a Detached Updater App
« on: September 17, 2024, 05:33:58 am »
Hi,
I am trying to get an app I have made to self update. I have it checking a version number, then if an update is required, I want to run an updater app, close itself while the updater replaces the binary. I seem to be really struggling. Everything I try using the TProcess examples seems to close the updater app when the parent main app closes. Can some one please direct me to some TProcess examples that will actually work?

Lazarus 3.4
FPC 3.2.2
x86_64_qt5

Thanks

dsiders

  • Hero Member
  • *****
  • Posts: 1258
Re: Starting a Detached Updater App
« Reply #1 on: September 17, 2024, 05:43:31 am »
Hi,
I am trying to get an app I have made to self update. I have it checking a version number, then if an update is required, I want to run an updater app, close itself while the updater replaces the binary. I seem to be really struggling. Everything I try using the TProcess examples seems to close the updater app when the parent main app closes. Can some one please direct me to some TProcess examples that will actually work?

Lazarus 3.4
FPC 3.2.2
x86_64_qt5

Thanks

Have a look at the startlazarus.lpr application in the ide directory. It handles the restart aspects. You have to include the update aspect.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 60
Re: Starting a Detached Updater App
« Reply #2 on: September 17, 2024, 07:13:44 am »
what has startlazarus.lpr have to do with my app? I thought that was for the IDE itself?

Thaddy

  • Hero Member
  • *****
  • Posts: 15929
  • Censorship about opinions does not belong here.
Re: Starting a Detached Updater App
« Reply #3 on: September 17, 2024, 07:31:28 am »
Yes, but it is a good example of what you want, especially TLazarusManager in LazarusManager.pas.
On Windows you can start Tprocess with poDetached in the options, but I am not sure that works on Linux. This will keep the child process running even after the main app is closed.
The lazarusmanager for linux uses waitforpid (the processid of the child proc) and then kills itself through fpKill.
Just see how it is done in the LazarusManager class, which uses TProcessUTF8.

So that was actually very good advice...
« Last Edit: September 17, 2024, 07:45:01 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 60
Re: Starting a Detached Updater App
« Reply #4 on: September 17, 2024, 08:10:04 am »
Oh I wasnt trying to say is was bad advice. I just didnt understand the advice I was being given. Thanks I will take a look.

Thaddy

  • Hero Member
  • *****
  • Posts: 15929
  • Censorship about opinions does not belong here.
Re: Starting a Detached Updater App
« Reply #5 on: September 17, 2024, 08:49:39 am »
Don was a bit cryptic about the reasons. I hope my explanation helped to show that was really good advice and you should examine that code as an example on how to do that.
Your first answer was a bit, let's say, premature? You would have seen it immediately if you followed his advice.
« Last Edit: September 17, 2024, 08:53:38 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 60
Re: Starting a Detached Updater App
« Reply #6 on: September 17, 2024, 09:30:43 am »
Oh I was definitely premature in my response. I should of looked more closely. I  am surprised how complicated it is. I just thought there was a simple way to open an external application and close the parent without issues but I was very wrong.

It looks like startlazarus stays in memory and it executes the IDE. I am trying to figure out how it knows the IDE is requesting a restart as opposed to asking to close.

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 60
Re: Starting a Detached Updater App
« Reply #7 on: September 17, 2024, 10:25:02 am »
OK so I have implemented something similar. I have created a launcher that checks for a new copy of the app, if it exists it replaces the app then executes. When the app closes if a new copy exists it replaces and restarts otherwise closes. (I hope that makes sense)

Thaddy

  • Hero Member
  • *****
  • Posts: 15929
  • Censorship about opinions does not belong here.
Re: Starting a Detached Updater App
« Reply #8 on: September 17, 2024, 10:37:37 am »
That is the correct order. Mind you, the old one needs to be renamed first.
« Last Edit: September 17, 2024, 10:39:20 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

TheMouseAUS

  • Jr. Member
  • **
  • Posts: 60
Re: Starting a Detached Updater App
« Reply #9 on: September 17, 2024, 10:48:52 am »
Yes I forgot to mention that step it does rename the old one first

 

TinyPortal © 2005-2018