Download might fail if on a slow connection,so take note, I HAVE.
Code: Select all
MsgBox, % GetLatestGithubRelease("aria2", "aria2", "zip", "64bit", "win") ;only gets latest url
MsgBox, % GetLatestGithubRelease("aria2", "aria2", "zip", "64bit", "win", 1) ;gets lates url & downloads it
GetLatestGithubRelease(user, repository, releaseExt:="zip", releaseArch:="64",releaseOS:="win", downloadFile:=0){
dlink:=""
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", "https://github.com/" . user . "/" . repository . "/releases/latest", true)
whr.SetTimeouts(0, 60000, 30000, 90000) ; last parameter is ReceiveTimeout
whr.Send()
; Using 'true' above and the call below allows the script to remain responsive.
whr.WaitForResponse(90) ; only in async mode
page := whr.ResponseText
;MsgBox, % page
Loop, Parse, page, `n
IfInString, A_LoopField, %releaseOS%
IfInString, A_LoopField, .%releaseExt%
IfInString, A_LoopField, %releaseArch%
dlink .= A_LoopField "`n"
Loop, Parse, dlink, `"
If A_Index = 2
dLinkActual := "https://github.com" . A_LoopField
If downloadFile ;download the file & return success or failure
{
SplitPath, dLinkActual, fileName
IfNotExist, %A_ScriptDir%\%fileName%
UrlDownloadToFile, %dLinkActual%, %fileName%
If !ErrorLevel
Return, True ;download succeded
}
Else ;return url
Return, dLinkActual
}