Sub DownloadAndSaveFile (Link As String, sFile As String)
Dialog.Title = sNomAPP & " NUEVA VERSION"
Dim rs As ResumableSub = Dialog.Show("Hay una Nueva Versión Disponoble. ¿Quieres Instalarla?", "", "", "")'SI "" NO
Dialog.GetButton(xui.DialogResponse_Positive).TextColor = xui.Color_Green
Dialog.GetButton(xui.DialogResponse_Cancel).TextColor = xui.Color_Red
Wait For (rs) Complete (pp As Int)
If pp = xui.DialogResponse_Positive Then
ProgressBarTrackDownload.Progress = 0
LblTrackDownload.Text = 0
LblTrackDownloadTotal.Text = 0
MostrarPanel2(PnlTrackDownload, PnlCaja)
Wait For (DownloadAndTrackProgress(Link, sFile)) Complete (Success As Boolean)
If Success Then
Sleep(1000)
PnlTrackDownload.Visible = False
'***** BLUR
BlurScreen(False, PnlCaja)
'***** BLUR
'**********************************************************
'EJECUTAR LA INSTALACION DESDE EL SHELL.
'AÑADIR JSHELL EN LAS LIBRERIAS
' Dim shell As Shell
'
' shell.Initialize("shell", File.DirTemp & "\" & sFile, Null)
' shell.WorkingDirectory = File.DirTemp
' shell.Run(-1)
'EJECUTAR LA INSTALACION DESDE EL SHELL.
'**********************************************************
'**********************************************************
'SALVA EL ARCHIVO DONDE QUIERA EL USUARIO PARA LUEGO INSTALARLO
' Dim f As String
' Dim path As String
' Dim sNombre As String
' Dim FileSaved As FileChooser
' FileSaved.Initialize
' FileSaved.Title = "Guardar Fichero de Actualización"
' FileSaved.SetExtensionFilter("Guardar Actualizacion", Array As String("*.exe"))
' FileSaved.InitialFileName = sFile
' f = FileSaved.ShowSave(MainForm)
' If f = "" Then Return
' path = f.SubString2(0, f.LastIndexOf("\"))
' sNombre = f.SubString(f.LastIndexOf("\") + 1)
' File.Copy(File.DirTemp, sFile, path, sNombre)
'SALVA EL ARCHIVO DONDE QUIERA EL USUARIO PARA LUEGO INSTALARLO
'**********************************************************
fx.ShowExternalDocument(File.GetUri(File.DirTemp, sFile))
ExitApplication
Else
'ERROR
Dialog.Title = sNomAPP
Dialog.ButtonsTextColor = xui.Color_Red
Dialog.Show("Ha Ocurrido un Error en la Descarga. Inténtelo Más Tarde", "", "", "")
End If
End If
End Sub
Private Sub DownloadAndTrackProgress (url As String, sFile As String) As ResumableSub
'***************************************************************************************************
'PARA USARLO HAY QUE AÑADIR "HU2_PUBLIC" A SIMBOLOS CONDICIONALES EN LA CONFIGURACION DEL COMPILADOR
'***************************************************************************************************
Dim j As HttpJob
j.Initialize("", Me)
j.Download(url)
Sleep(0) 'SI QUITO ESTO NO FUNCIONA!!!!
Dim TaskToJob As Map = HttpUtils2Service.TaskIdToJob
Do While HttpUtils2Service.TaskIdToJob.IsInitialized = False
Sleep(30)
Loop
Dim TaskId As Int
For Each id As Int In TaskToJob.Keys
If TaskToJob.Get(id) = j Then
TaskId = id
Exit
End If
Next
Dim b() As Boolean = Array As Boolean(False)
TrackProgress(j, b, TaskId)
Wait For (j) JobDone (j As HttpJob)
b(0) = True
'SALVA EL FICHERO
If j.Success Then
LblTrackDownload.Text = LblTrackDownloadTotal.Text
ProgressBarTrackDownload.Progress = 100
Dim out As OutputStream = File.OpenOutput(File.DirTemp, sFile, False)
File.Copy2(j.GetInputStream, out)
out.Close '<------ very important
End If
'SALVA EL FICHERO
j.Release
Return j.Success
End Sub
Private Sub TrackProgress (j As HttpJob, Stop() As Boolean, TaskId As Int)
Do While Stop(0) = False
If j.Out.IsInitialized Then
Dim TotalLength As Long = j.Response.ContentLength
Dim size As Long = File.Size(HttpUtils2Service.TempFolder, TaskId)
ProgressBarTrackDownload.Progress = 100 * size / TotalLength
LblTrackDownload.Text = size
LblTrackDownloadTotal.Text = TotalLength
'Log(size & ", " & TotalLength)
End If
Sleep(100)
Loop
End Sub
Sub MostrarPanel2 (PanelMostrar As B4XView, PanelOrigen As B4XView)
Dim a As Int = 30
PanelOrigen.Enabled = False
PanelMostrar.Visible = True
PanelMostrar.Top = (MainForm.RootPane.Top + (MainForm.RootPane.Height - PanelMostrar.Height) / 2) - a'ANTES 80
PanelMostrar.Left = (MainForm.RootPane.Left + (MainForm.RootPane.Width - PanelMostrar.Width) / 2)
BlurScreen(True, PanelOrigen)
End Sub