'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim DownloadCount As Int
Dim UrlTarget As String
Dim URLSource As String
Dim URLFile As String
Dim JobStatus As String
Dim GJob As HttpJob
Dim tmr As Timer
Dim timerint As Int
Dim downloadedlength As Long
Dim contentlength As Long
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
JobStatus = "STATUS_WORKING"
Dim cn As CustomNotification
DoNotif
Initiate
End Sub
Sub Service_Destroy
End Sub
Sub startinstall(targetdir As String, targetfile As String)
JobStatus = "STATUS_NONE"
ToastMessageShow("Installing your game", True)
Dim arc As Archiver
Dim m As Map
Try
' arc.aSyncUnZip(targetdir, targetfile, targetdir, "arc")
arc.aSyncUnZip(GJob.GetInputDir, GJob.GetInputfile, targetdir, "arc")
Catch
Log(LastException.Message)
ToastMessageShow("There was a problem extracting the file", True)
End Try
End Sub
Sub arc_UnZipDone(completedWithoutError As Boolean,nbOfFiles As Int)
If completedWithoutError Then
'File.Delete(File.DirRootExternal, Main.curfile)
File.Delete(GJob.GetInputDir, GJob.GetInputfile)
ToastMessageShow("Extraction completed successfully",True)
JobStatus = "STATUS_DONE"
Else
ToastMessageShow("Extraction failed. Try again. Make sure you have enough space on your storage device", True)
JobStatus = "STATUS_DONE"
End If
End Sub
Sub DoNotif()
Dim cn As CustomNotification
cn.Initialize(3)
cn.Number = 1
cn.setIcon("icon")
cn.TickerText = "Downloading File"
cn.AutoCancel = False
cn.SetTextColor("title", Colors.Gray)
cn.SetText("title", "Downloading: " & Main.curfile)
cn.SetTextSize("title", 10)
cn.SetImage("image", LoadBitmap(File.DirAssets, "menu_info.png"))
cn.SetProgress(1, 100, 0, False)
cn.Notify(1)
End Sub
Sub JobDone(Job As HttpJob)
Select Job.JobName
Case "gDL"
If GJob.Success = False Then
ToastMessageShow("Error downloading the file.", True)
Return
End If
If GJob.Success = True Then
startinstall(UrlTarget, URLFile)
File.Copy(GJob.GetInputDir, GJob.GetInputfile, UrlTarget, URLFile)
startinstall(UrlTarget, URLFile)
End If
Return
End Select
Job.Release
End Sub
Sub Initiate ()
'GJob.Initialize("gDL", Me)
' GJob.download(URLSource)
tmr.Initialize("tmr", 200)
tmr.Interval = 200
tmr.Enabled = True
End Sub
Sub downloadProgress(tmp As ProgressStatus)
Dim progress As Int
progress=Round((tmp.downloaded*100)/tmp.total)
'cn.SetProgress(1,100,progress,False)
End Sub
Sub tmr_tick()
Dim h As HttpResponse
contentlength = HttpUtils2Service.contentLength
Dim cn As CustomNotification
cn.Initialize(3)
cn.AlertOnce = True
cn.Insistent = False
cn.Number = 1
cn.setIcon("icon")
cn.TickerText = "Downloading File"
cn.AutoCancel = False
cn.SetTextColor("title", Colors.Gray)
cn.SetText("title", "Downloading: " & Main.curfile)
cn.SetTextSize("title", 10)
cn.SetImage("image", LoadBitmap(File.DirAssets, "menu_info.png"))
cn.SetProgress(1, 100, 0, False)
cn.Notify(1)
GJob.Initialize("gDL", Me)
GJob.download(URLSource)
If File.Exists(GJob.GetInputDir, GJob.GetInputfile)=True Then
downloadedlength= File.Size(GJob.GetInputDir, GJob.GetInputfile)
End If
Dim tmp As ProgressStatus
tmp.Downloaded=downloadedlength
tmp.Total=contentlength
Dim progress As Int
progress=Round((tmp.downloaded*100)/tmp.total)
Do While progress < 100
cn.SetProgress(1,100,progress,False)
cn.Notify(1)
'DoEvents
Loop
If progress = 100 Then
JobStatus = "STATUS_DONE"
cn.Initialize(3)
cn.Number = 1
cn.TickerText = "Download Complete"
cn.AutoCancel = True
cn.SetText("title", Main.curfile & " has downloaded successfully")
cn.SetTextSize("title", 10)
cn.SetImage("image", LoadBitmap(File.DirAssets, "menu_info.png"))
cn.SetProgress(1, 100, 100, False)
cn.Notify(1)
tmr.Enabled = False
End If
End Sub