The function shows requesters only once per session to avoid a flood with many downloads. If you want to change that behaviour, get rid of the global variables. Maybe this could also be expanded to support all functionality of the original DownloadFile() function... but I'll just share it as it is for now.
Code: Select all
Function p_DownloadFile(url$, file$, force)
/* Synopsis: data$, count = p_DownloadFile(url$[, file$])
If a URL starts with https or ftps, the file is downloaded directly with hURL,
but otherwise it's first tried without hURL. If you don't need hURL, the plugin
isn't loaded to memory at all, and it doesn't have to be available either.
The function also checks if AmiSSL is available, and notifies if not.
If a non-secure URL fails, the function tries again with hURL. This solves issues
when a server has changed from http to https, but the program is using old URLs.
*/
Local options = {
; Add your own settings here:
; UserAgent = "MyProgram/" .. #VERSION .. " ( me@myplace.org )",
; Don't touch to this:
File = file$
}
Local err, data$, count
If StartsWith(url$, "https", False) Or StartsWith(url$, "ftps", False) Or force
Local found = HavePlugin("hurl")
If found
If Not hurl_loaded
If ?LoadPlugin("hurl")
If Not amissl_asked
If SystemRequest("Download File", "AmiSSL v4 is required for HTTPS and FTPS URLs.\nIt can be downloaded from Aminet (http://aminet.net)", "Download|OK")
OpenURL("http://aminet.net/search?query=amissl")
EndIf
amissl_asked = True
EndIf
Return("No AmiSSL!", -1)
Else
hurl_loaded = True
EndIf
EndIf
options.Adapter = "hurl"
options.SilentFail = True
data$, count = DownloadFile(url$, options)
ElseIf Not hurl_asked
If SystemRequest("Download File", "The hURL plugin is required for HTTPS and FTPS URLs.", "Download|OK")
OpenURL("https://www.hollywood-mal.com/download.html")
EndIf
hurl_asked = True
Return("No hURL!", -1)
EndIf
Else
err, data$, count = ?DownloadFile(url$, options)
If err = #ERR_UNKPROTOCOL
data$, count = p_DownloadFile(url$, file$, True)
ElseIf err
Return(GetErrorName(err), -1)
EndIf
EndIf
Return(data$, count)
EndFunction