B4J Question App simply exits on httpjob

techknight

Well-Known Member
Licensed User
Longtime User
I am trying to create a simple App Updating method in my B4J App.

Ultimately, it works fine up until I get to the point where it download the exe. The app simply exits with no error on the line that says: Wait For (http2) JobDone(http2 As HttpJob)

I tried moving it into its own sub declared as a resumable sub, and on its own. Soon as it gets to Wait For, the app simply closes.

I dont know why, there is no stacktrace.

Thoughts?

B4X:
Sub CheckForUpdates As ResumableSub
    Dim tempfrm As Form
    Dim http As HttpJob
    Dim VersionInfo As String
    http.Initialize("", Me)
    http.Username = "updater"
    http.Password = "scoreboardapkupdate"
    http.Download(UpdateURL & "version.txt")
    Wait For (http) JobDone(http As HttpJob)
    If http.Success = True Then
        VersionInfo = http.GetString
        http.Release 'Make sure to call this here, or we can end up with a memory leak. Dont want that.
        If Left(VersionInfo, 7) <> "version" Then 'Invalid File Format
            Return True
        End If
        Dim Args() As String = Regex.Split(",", VersionInfo)
        Dim V() As String = Regex.Split("=", Args(0)) 'Get Version Info
        If Val(V(1)) > CurrentAppVersion Then 'There is a newer version
            Dim Active() As String = Regex.Split("=", Args(1)) 'Get Active Update state
            If Active(1) <> "true" Then Return True 'the newer update is not currently active yet
            Dim Forced() As String = Regex.Split("=", Args(2)) 'Check to see if this update is required for operation.
            Dim Changelog() As String = Regex.Split("=", Args(3)) 'Get the changelog information
            Dim ChangelogData() As String = Regex.Split(";", Changelog(1)) 'Get the changelog data block
            Dim I As Int = 0
            Dim Count As Int = 0
            Dim ChangeLogPrompt As String
            For I = 0 To ChangelogData.Length-1 'Go through each item in the change log and display only what is relevant to us.
                Dim Arr() As String = Regex.Split(":", ChangelogData(I))
                If Val(Arr(0)) >= CurrentAppVersion Then 'Display the information if its current to our version and newer. Dont display irrelevent information.
                    If Count = 0 Then 'First entry valid to our version, which is our current version.
                        ChangeLogPrompt = ChangeLogPrompt & Arr(1) & " - Your Version" & Chr(13)
                    Else if I = Changelog.Length Then
                        ChangeLogPrompt = ChangeLogPrompt & Arr(1) & " - Current Version" & Chr(13)
                    Else
                        ChangeLogPrompt = ChangeLogPrompt & Arr(1) & Chr(13)
                    End If
                    ChangeLogPrompt = ChangeLogPrompt & Arr(2) & Chr(13) & Chr(13) 'double space
                    Count = Count + 1
                End If
            Next
            tempfrm.Initialize("tempfrm", 600, 600)
            CenterForm(tempfrm, False)
            If fx.Msgbox2(tempfrm, "There is a software update available for download. Do you wish to update?" & Chr(10) & Chr(13) & "Changelog:" & Chr(13) & ChangeLogPrompt, _
            "Software Update", "Yes", "", "No", fx.MSGBOX_CONFIRMATION) = fx.DialogResponse.POSITIVE Then
                Dim http2 As HttpJob
                http2.Initialize("", Me)
                http2.Username = "updater"
                http2.Password = "scoreboardapkupdate"
                http2.Download(UpdateURL & "installer.exe") '<-- Tried version.txt again to eliminate potential AV or file size issue.
                Wait For (http2) JobDone(http2 As HttpJob) '<-- App drops out here
                If http2.Success = True Then
                    Log("ok")
                    Dim out As OutputStream = File.OpenOutput(File.DirTemp, "installer.exe", False)
                    File.Copy2(http2.GetInputStream, out)
                    out.Close
                    http2.Release
                    Dim sh1 As Shell
                    sh1.Initialize("sh1", File.Combine(File.DirTemp, "installer.exe"), Null)
                    sh1.Run(-1)
                    Return False
                Else
                    http2.Release
                    Log("Failed to download setup file")
                    Return True
                End If
            Else
                If Forced(1) = "true" Then 'Deny program access until the update is complete
                    fx.Msgbox(tempfrm, "You must perform the software update before you can continue to run this software", "Update REQUIRED")
                    Return False
                End If
                Log("Update Cancelled")
                Return True
            End If
        End If
    End If
    http.Release
    Return True
End Sub
 
Last edited:

techknight

Well-Known Member
Licensed User
Longtime User
Possibly, I dont know. What I do know, is this works:

B4X:
    MainForm.SetFormStyle("TRANSPARENT")
    MainForm.BackColor = fx.Colors.Transparent
    MainForm.RootPane.Alpha = 0
    MainForm.Show
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…