Code: Select all
local sDownloadStart
on OpenStack
set the visible of scrollbar "Progressbar" to false
set the visible of fld "ProgressField" to false
set the cursor to watch
wait 1.2 seconds
put "1.0.0.1" into tVersion
put "http:...../Version.txt" into uVersion
put URL uVersion into UrlData
wait 50 millisec
if UrlData is "" or len(UrlData) >11 then
set the cursor to arrow
--Answer error "Failed to connect to update. Make sure you are connected to the internet and try again."
Else if UrlData is not tVersion then
set the cursor to arrow
answer information "There is an update available:" & CR & "Current Version: " & tVersion & CR & "New Version: " & UrlData with "Update Now" or "Cancel"
if it is "Update Now" then
-- put the address of the file we want to download into a variable
put "http://www..whaterver.com../NameOfTheUpdatedStack.rev" into tDownloadLink
libURLSetStatusCallback "showProgress", the long name of me
hide scrollbar "ProgressBar"
hide fld "ProgressField"
put empty into fld "ProgressField"
put the seconds into sDownloadStart
set the itemDel to slash
put (item 1 to -2 of the effective filename of this stack) & slash before tPath
-- start the download process, telling Rev to call the "downloadComplete" handler when finished
load stack URL tDownloadLink with message "downloadComplete"
End if
End If
end OpenStack
command showProgress pURL, pStatus
if the number of items in pStatus = 3 then
if the visible of scrollbar "Progressbar" = false then
put the last item of pStatus into tTotalBytes
set the startValue of scrollbar "Progressbar" to 0
set the endValue of scrollbar "Progressbar" to tTotalBytes
show scrollbar "Progressbar"
show fld "ProgressField"
end if
set the thumbPosition of scrollbar "Progressbar" to item 2 of pStatus
end if
-- better text information
if the number of items in pStatus = 3 then
put item 2 of pStatus into tBytesReceived
put item 3 of pStatus into tTotalBytes
-- this gives very large numbers that are not easily read, so convert to KB
put tBytesReceived div 1024 into tKBreceived
put tTotalBytes div 1024 into tTotalKB
-- calculate speed
put the seconds - sDownloadStart into tElapsedSeconds
if tElapsedSeconds = 0 then
-- make sure we don't divide by zero at the start
put "unknown" into tKBperSecond
else
put round(tKBreceived / tElapsedSeconds, 1) into tKBperSecond
end if
put "Received " & tKBreceived & " KB of " & tTotalKB & " KB at " into fld "ProgressField"
put tKBperSecond & " KB/sec" after fld "ProgressField"
end if
end showProgress
command downloadComplete pURL, pStatus
hide scrollbar "ProgressBar"
-- check if there was a problem with the download
if pStatus = "error" or pStatus = "timeout" then
answer error "The file could not be downloaded."
else
set the itemDel to slash
put last item of pURL into tFilename
put (item 1 to -2 of the effective filename of this stack) & slash before tFileName
put URL pURL into URL ("binfile:" & tFileName)
unload pURL
hide me
go stack tFileName
end if
end downloadComplete