uses "Console"
uses "iNet"
uses "OS"
printl "Connect to Firefox web site, determine latest Firefox version and download it"
'---Check if computer is connected to internet
if INET_GetState Then
'---Get Firefox web site page
string Firefox_Info_Page = INET_UrlGetString("https://www.mozilla.org/en-US/firefox/new/")
'---Get Firefox available version
string Firefox_Available_Version = grab$(Firefox_Info_Page, "data-latest-firefox=""", """")
'---Get Win64 direct download url
string Firefox_DownLoad_Url_Win64 = grab$(Firefox_Info_Page, "<div id=""other-platforms"">", "</div>")
Firefox_DownLoad_Url_Win64 = grab$(Firefox_DownLoad_Url_Win64, "<li class=""os_win64"">", "</li>")
Firefox_DownLoad_Url_Win64 = grab$(Firefox_DownLoad_Url_Win64, "<a href=""", """")
printl "Firefox available version...:", Firefox_Available_Version
printl "Firefox Download url........:", Firefox_DownLoad_Url_Win64
'---Download
string sLocalFile = APP_SourcePath + "Firefox Setup " + Firefox_Available_Version + ".exe"
printl "Downlaoding to", sLocalFile, "..."
INET_UrlDownload(Firefox_DownLoad_Url_Win64, sLocalFile)
printl "File downlaoded."
printl
printl "Press ESC to end or any other key within 10 secs to execute setup"
'---Ask if execute setup
string sUserReply = WaitKey(10)
if sUserReply <> "[ESC]" and sUserReply <> "[TIMEOUT]" Then
printl "Executing " + sLocalFile
OS_Shell(sLocalFile, %OS_WNDSTYLE_NORMAL, %OS_SHELL_SYNC)
Else
printl "No execution. Execute manually if needed."
end If
Else
printl "! it seems you are not connected to internet." in %CCOLOR_FLIGHTRED
end If
printl "---All done, press a key to end or wait 5 secs---"
WaitKey(5)
'[todo] To add async download with any progress info ...
' Install thinBasic and see example at \thinBasic\SampleScripts\INet\Internet_FileDownload.tbasic