B4J Library [B4Xlib] jAutoUpdate library

Tayfur

Well-Known Member
Licensed User
Hello all;

I coding app for my company. (I am not programmer, only for the department and jobs I work with.)
My app use on 8-10 pc on company LAN. And I publish a new version every week. it takes a lot of time to do it manually for the 8-10 computer.I decided to do an automatic update. Of course.. Before, I wanted from @Erel for IDE. ( my wish just open :);)https://www.b4x.com/android/forum/threads/update-system-like-android-app.100783/)

Finaly I added library and an example. This library support LAN and WEB download (no secure) & FTP
update : V.1.57
update "FinishDownlaod";
Now you can restart application after complate download


update : V.1.3

Adding secure FTP update.
adding CheckingResult
adding IsInitializedFTP
adding UseFTP




Author:
Tayfur
Version: 1.3

#Event:

  • DownloadError (info as String)
  • DownloadComplete (TempFolder as String, TempFile as String)
  • CheckingResult (Success As Boolean, updatetype As String)
    • Success: file found, connections is ok, everthing is ok, etc. general control
    • upodatetype : "LAN", "WEB","FTP"

#Properties:

  • FolderNameLAN as String
  • FolderNameWEB as String
  • TargetExtLAN as String
  • TargetFileLAN as String
  • VerisonLimit As Int
  • VerFractionLimit As Int
  • AppVersion as String
  • AppLogger as Boolean

#Sub & Fuctions:
  • Initialize (Callback As Object, EventName As String)
autoupdate.Initialize(Me,"autoupdate")​
  • IsInitializedWEB As Boolean
  • IsInitializedLAN As Boolean
  • IsInitializedFTP As Boolean
  • UseWEB (AnaForm As Form, Version As String,FileName As String,FileExtension As String,SourceFolder As String)
'Version : (only number and point) Own app verision. Code find upper version on WEB destination, if You use empty; The program checks the file dates. It works if the file in the destination is newer.
'FileName: its file name on destination folder. it s not inculded file extension
'FileExtension: its need for cheking file name.
'SourceFolder : Source folder on web.
'Note: be careful, have big and small character sensitivity.
autoupdate.UseWEB(MainForm,"1.1","Choqok","png","https://upload.wikimedia.org/wikipedia/tr/0/0c")​
  • UseLan (AnaForm As Form, Version As String,FileName As String,FileExtension As String,SourceFolder As String)
'Version : (only number and point) Own app verision. Code find upper version on LAN destination, if You use empty; The program checks the file dates. It works if the file in the destination is newer.
'FileName: its file name on destination folder. it s not inculded file extension
'FileExtension: its need for cheking file name.
'SourceFolder : Source folder on lan.
autoupdate.UseLan(MainForm,"1.2","test","jar","\\192.168.1.31\app\new")
  • UseFTP (Mainform As Form,Version As String,FileName As String,FileExtension As String,serverftp As String, serverfolder As String, user As String,psw As String,port As Int)
Version: your own application version. This lib searches for a larger version number.(your app 1.3, on ftp file name is SampleB4J_1.4.jar)
FileName: your target and own file name (ex: SampleB4J.jar >> SampleB4J)
FileExtension:your target and own file name extension (ex: SampleB4J.jar >> jar)
serverftp: its frtp server name or ip adress
serverfolder: its your subfolder in ftp server
user: user name for ftp connection
psw: password for ftp connection
port: port number for ftp connection​
  • StartDownlaodWEB
start download process​
  • StartDownlaodLan
start download process​
  • FinishDownlaod(aftermilisecond As Int, RunJar as Boolean, Package as String) as Boolean
After works it form closed. its will copying from temp file after close app. Re-open updated jar file (only JAVA app)
aftermilisecond : re-open delay time 5000-10000 (5-10sec)
RunJar: if you want to open downloaded file (TRUE)
Package: if you want to open downloaded , this value is your package name of download file. (b4j.example.main)​
  • CheckingLan
its cheking folder on LAN​
  • CheckingWEB
it s cheking web connection with target web site​
  • CheckingFTP
it s cheking FTP connection with target web site​
 

Attachments

Last edited:

OliverA

Expert
Licensed User

rraswisak

Active Member
Licensed User
There were people when he/she more expert they will so humble on their competency.
Thank you for sharing this
 

Tayfur

Well-Known Member
Licensed User
There were people when he/she more expert they will so humble on their competency.
Thank you for sharing this
There are many masters here. I learned a lot from the masters. My shares are lower level code. but I'm happy that the masters (like @Erel, etc..) appreciate me.
 
Last edited:

m4.s

Member
Hello @Tayfur

Nice library you've developed here, which I'm trying to use for my B4J application (using WEB download).

However, I've encountered a problem and have a few questions:

1. Issue: If/when I pass empty (either via "" or " ") as param value for autoupdate.UseWEB method, I get this run-time error:
###>> JAutoUpdate >> Target version is empty

2. Question: Once I can address #1, or use the version approach instead, how do I know or define where the newer file is downloaded?
Is the answer to set the autoupdate.FolderNameWEB property (to, say for example, "C:\Downloads" folder)?

3. Question: For your LAN .jar file example, how/where do you close the running jar (i.e. your B4J application) and auto-run the downloaded newer jar file?


{I assume since you created this as a B4X library, you're OK with B4J developers to locally modify the code if/as nec - yes?}
 

Tayfur

Well-Known Member
Licensed User
Hello @Tayfur

Nice library you've developed here, which I'm trying to use for my B4J application (using WEB download).

However, I've encountered a problem and have a few questions:

1. Issue: If/when I pass empty (either via "" or " ") as param value for autoupdate.UseWEB method, I get this run-time error:
###>> JAutoUpdate >> Target version is empty

2. Question: Once I can address #1, or use the version approach instead, how do I know or define where the newer file is downloaded?
Is the answer to set the autoupdate.FolderNameWEB property (to, say for example, "C:\Downloads" folder)?

3. Question: For your LAN .jar file example, how/where do you close the running jar (i.e. your B4J application) and auto-run the downloaded newer jar file?


{I assume since you created this as a B4X library, you're OK with B4J developers to locally modify the code if/as nec - yes?}
Do you share the code to better analyze the problem. but I'll answer it briefly
  1. Jautoupdate.IsInitializedWEB return must be TRUE(But your code return false) ; If you continue without checking it, the code will break. The webdownload method is the only way to check the new version is the file name. Because the web system is not a file system. we cant read file descriptions. therefore, a version number is required for identification. that is, the main target of the library is the version numberAfter sending the code, I'll review "run time" error.
  2. The library temporarily saves the files in the File.DirApp&"\temp_update" folder.And extension is "(targetfilename).tmp". (for each file) After download; Library start copy actions.
  3. You can use code under below; (until I update the library)
B4X:
Sub MainForm_Closed


        If  autoupdate.isDownloadComplete  then '  And autoupdate2.isDownloadComplete Then ' you must be add for each download file.
Dim x As String=""
            x=x&"@echo off"& CRLF
            x=x&"echo %time%"& CRLF
            x=x&"timeout 5 > NUL"& CRLF ' DOS mode waitinf 5 second; Bacause Main app must be close for delete/copy action.
            x=x&"echo %time%"& CRLF
            x=x&"copy "&File.dirApp&"\temp_update\YOURFILE.tmp "&File.dirApp&"\YOURFILE.jar"& CRLF
            'x=x&"copy "&File.dirApp&"\temp_update\YOURFILE2.tmp "&File.dirApp&"\YOURFILE2.note"& CRLF  'if use multiple file
            x=x&"rmdir temp_update /s /q"&CRLF 'clear all temp file.
            x=x&"YOURFILE.jar"&CRLF ' its directly run your jar file.Because its on DOS mode (CMD)
            'x=x&"Pause"& CRLF
            Log(x)
            File.WriteString(File.DirApp,"update.bat",x)
            fx.Msgbox(MainForm,"App, in 10-30sec re-open,"&CRLF&"Please wait...","UPDATING")
            Dim params As List: params.Initialize
            params.Add("/c")
            params.Add("start")
            Log(File.DirApp&"\update.bat")
            params.Add(File.DirApp&"\update.bat")
            Dim Shl As Shell
            Shl.Initialize("shl","cmd.exe",params)
            Shl.WorkingDirectory = File.DirApp
            Try
                ' Run with disabled timeout
                Shl.Run(-1)
              
            Catch
                Log(LastException.Message)
            End Try
end if
 
Last edited:

Tayfur

Well-Known Member
Licensed User
update : V.1.57
updated "FinishDownlaod"; Now you can restart application after complate download

  • FinishDownlaod(aftermilisecond As Int, RunJar as Boolean, Package as String) as Boolean
After works it form closed. its will copying from temp file after close app. Re-open updated jar file (only JAVA app)
aftermilisecond : re-open delay time 5000-10000 (5-10sec)
RunJar: if you want to open downloaded file (TRUE)
Package: if you want to open downloaded , this value is your package name of download file. (b4j.example.main)

B4X:
If  autoupdate.isDownloadComplete Then
            If autoupdate2.FinishDownlaod(5000,False,"-") Then
                Log("old file delete and new file copy after 5sec")
            Else
                Log("error")
            End If
End if

B4X:
If  autoupdate.isDownloadComplete Then
            If autoupdate2.FinishDownlaod(7000,true,"b4j.example.main") Then
                Log("old file delete and new file copy, start new jar file after 5sec")
            Else
                Log("error")
            End If
End if
 

m4.s

Member
Thank you for all this Tayfur.

I need some more time to refocus on this. I'll then provide further feedback and/or questions.
 
Top