B4J Question Program auto update to new version

seems like someone has done this before but i cant find it. i need a way to automatically detect that a new version of the program is available, download into the same folder as the old program. kill the old program process, delete the old program and start the new program. i thinking about a small app that just watchs for a signal that a new program exists. kills the old program process, delete the old program files, download the new program into the old programs folder. start the new program. anyone seen any code like that. saw that on the b4a side they have appautoupdater but thats android. or does someone have a better way ?
 

udg

Expert
Licensed User
Longtime User
What about a batch file created as a last step by the old version once the newer is downloaded and ready to start?
The batch will have a line to kill the current process (the old version of the sw) and a line to start the sw again (this time it will be the newer version of it)
A good precaution could be to just rename the old version file instead of deleting it, so if anything goes wrong you still have that old copy.
 
Upvote 0
sometimes i look at a problem and i think its going to be really hard and i look for the complicated solutions and miss the simple answer. thank you. i'll give it a try.
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Sounds a bit dangerous to me...
Suppose we are working in B4J and @Erel implemented this "auto update" feature. He would close our B4J sessions - hopefully saving our work that was open, install the new B4J version based on last registry entry - then re-open a blank session? I don't think so...

If your app was in the middle of something (like updating a database), user typing a long message, etc... danger, danger....
What if the update failed? Where is the user's installer?
However, I have no idea what your app does (non-ui?).

I do use the autoupdater in B4A - and it works well. Also, it only checks when a user is logged out - so no danger of corruption.
It also requires the user "Install" the new found update. That is an Android Permission thing - and rightfully so.

My 2 peso's...
 
Upvote 0

AHilton

Active Member
Licensed User
Longtime User
There are many many ways of doing this, michaelleewebb. As always, it depends on your app and what/if it connects to anything else.

The way one of our larger, distributed B4J apps does it is like this ...

- StarterApp is what the user 'runs' first. It's what they think is the main app. This app downloads resource files, any updates, gives a splash screen, terms of service, and generally gets things ready and starts the MainApp. We used to call this the "kickstarter" decades ago.
- MainApp checks for a file on a webserver on a timer.
- MainApp sees that there's an update. It notifies user.
- User stops MainApp whenever they want.
- User starts it back up again (StarterApp ... see above) and the StarterApp does the old switcheroo of swapping the old MainApp with the new MainApp and starts the MainApp.


For a Client/Server app (both B4J) of ours that is a SAAS product using a constant websocket connection , it's a little cleaner because when the MainApp connects to the ServerApp backend, it transmits its' version. The ServerApp then does the checking of each clients' version and requirements against the 'current' version and then notifies the MainApp when an update is ready. The MainApp, again, waits for the user to accept the update (although sometimes it's a critical update and forces them to finish what they're doing and won't let them continue ... your requirements may vary) then downloads the new version of MainApp for them and the StarterApp does the same as above.

And, yes, Erel, it CAN BE very much worth the effort. Lots of different requirements out there in the world
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
The way one of our larger, distributed B4J apps does it is like this ...

@AHilton , WOW, the ends of the earth can be achieved... although seems complicated - from line 1 of code...

However, without a code example - how can one comprehend what you just stated ?
We / us are very lacking here. A simple demo project may help explain.

I know this is tasking your time, but important for us.
Maybe supply as "B4J code snippets" or something...

Thanks for your efforts...
 
Upvote 0

amorosik

Expert
Licensed User
@AHilton , WOW, the ends of the earth can be achieved... although seems complicated - from line 1 of code...

However, without a code example - how can one comprehend what you just stated ?
We / us are very lacking here. A simple demo project may help explain.

I know this is tasking your time, but important for us.
Maybe supply as "B4J code snippets" or something...

Thanks for your efforts...

I agree
Is a code fragment that all of us need
 
Upvote 0
"code fragment that all of us need" thats what i though from the beginning. i've looked all around but its seems no one has ever posted an example code fragment. would be most helpful.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
would be most helpful
How will you recognize a Task of java.exe or javaw.exe running to be the app you want to update? No problem if only one java task is running.
It will be a difficult task.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
I didn't check, but usually I use the following code in non-UI apps' AppStart sub:
B4X:
'write PID on the filesystem
    Dim jo As JavaObject
    jo.InitializeStatic("java.lang.management.ManagementFactory")
    Dim pid As String = jo.RunMethodJO("getRuntimeMXBean",Null).RunMethod("getName",Null)
    File.WriteString(File.DirApp,"servicepid.txt","PID: "& pid.SubString2(0,pid.IndexOf("@")))
It should be the PID of the java instance you want to kill.

ps: I may be wrong; it should be carefully checked (expecially if used on different OSes)
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
You may be able to use the jar uf command to update the jar file, then on restart it would use the new code.
I experimented a while back updating a jar with classes I had changed instead of downloading the whole jar again. This saves some time as classes tend to be tiny compared to the jar itself.
Once you get your head around the sequence needed its really simple.

Basically the command is
Jar uf YourCurrentJarfile.jar my/new/newclass1.class my/new/newclass2.class

This will replace the classes if they exist in the jar or add them to the jar if they dont exist
 
Upvote 0
Top