Sub JobDone(Job As HttpJob)
ProgressDialogHide
If Job.Success Then
Dim res As String
res = Job.GetString
Log("JobName: "&Job.JobName)
If Job.JobName = "DownloadFile" Then
Dim m As String = Job.Tag
Dim OutStream As OutputStream
Log("DownloadReady: "&Job.Tag)
OutStream = File.OpenOutput(File.DirRootExternal, GetFilename(m), False)
File.Copy2(Job.GetInputStream,OutStream) ' save the file
OutStream.Close
Log(GetFilename(m)&" is written to "&File.DirRootExternal)
' Remove the first job from queue
If todownload.Size > 0 Then
todownload.RemoveAt(0)
End If
' Check if there are more files to download. If yes. Download them
If todownload.Size > 0 Then
Dim furl As String = todownload.Get(0)
Log("Download: "&furl)
Dim j As HttpJob
j.Initialize("DownloadFile",Me)
j.Tag = furl
j.Download(furl)
Else
LogColor("======================================",Colors.Green)
LogColor("===== ALL FILES FROM QUERE =======",Colors.Green)
LogColor("===== ARE FINISHED DOWNLOADING =======",Colors.Green)
LogColor("======================================",Colors.Green)
End If
End If
Else
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Sub GetFilename(fullpath As String) As String
Return fullpath.SubString(fullpath.LastIndexOf("/") + 1)
End Sub