Const INTERNET_OPEN_TYPE_DIRECT
= 1
Const INTERNET_DEFAULT_HTTP_PORT
= 80 Const INTERNET_DEFAULT_HTTPS_PORT
= 443
Const INTERNET_SERVICE_HTTP
= 3
'Flags
Const INTERNET_FLAG_SECURE
= &H00800000 Const INTERNET_FLAG_RELOAD
= &H80000000
Const HTTP_QUERY_CONTENT_LENGTH
= 5
'CONST FALSE = 0
DownloadLink link, filename
URLFile = URL
hsession = InternetOpen(0, INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0)
Print "Error : InternetOpen", ErrorMessage
(GetLastError
) InternetCloseHandle hsession
httpsession
= InternetConnect
(hsession
, _Offset(intURL
), INTERNET_DEFAULT_HTTPS_PORT
, 0, 0, INTERNET_SERVICE_HTTP
, 0, 0) Print "Error : Internet Connect", ErrorMessage
(GetLastError
) InternetCloseHandle hsession
sessiontype
= "GET" + Chr$(0) accepttypes
= "*/*" + Chr$(0) httpRequest
= HTTPOpenRequest
(httpsession
, _Offset(sessiontype
), _Offset(location
), 0, 0, _Offset(accepttypes
), INTERNET_FLAG_RELOAD
Or INTERNET_FLAG_SECURE
, 0) Print "Error : HTTPOpenRequest", ErrorMessage
(GetLastError
) InternetCloseHandle hsession
headers = ""
sendrequest = HTTPSendRequest(httpRequest, 0, 0, 0, 0)
Print "Error : HTTPSendRequest", ErrorMessage
(GetLastError
) InternetCloseHandle hsession
querylen
= Len(queryinfo
) - 1
query
= HTTPQueryInfo
(httpRequest
, HTTP_QUERY_CONTENT_LENGTH
, _Offset(queryinfo
), _Offset(querylen
), 0) Print "Error : HTTPQueryInfo", ErrorMessage
(GetLastError
) InternetCloseHandle hsession
bytesToRead
= Val(queryinfo
)
a
= InternetReadFile
(httpRequest
, _Offset(szBuffer
), Len(szBuffer
) - 1, _Offset(dwRead
)) errr = GetLastError
filedownload
= Mid$(szBuffer
, 1, dwRead
) bytesRead = bytesRead + dwRead
bytesForRate = bytesForRate + dwRead
ratetime = timeElapsedSince(x!)
Rate! = (bytesForRate / ratetime) / 1024
bytesForRate = 0
Print "Downloading to " + File
Print Using "####.## KB downloaded of ";
(bytesRead
/ 1024);
Case Is < (1024 ^ 3) And bytesRead
>= (1024 ^ 2) Print Using "####.## MB downloaded of ";
(bytesRead
/ (1024 ^ 2));
Case Is < (1024 ^ 4) And bytesRead
>= (1024 ^ 3) Print Using "####.## GB downloaded of ";
(bytesRead
/ (1024 ^ 3));
Case Is < (1024 ^ 3) And bytesToRead
>= (1024 ^ 2) Print Using "####.## MB";
(bytesToRead
/ (1024 ^ 2)) Case Is < (1024 ^ 4) And bytesToRead
>= (1024 ^ 3) Print Using "####.## GB";
(bytesToRead
/ (1024 ^ 3)) Print Using "###.##%"; bytesRead
/ bytesToRead
* 100 Print Using "####.## KB downloaded";
(bytesRead
/ 1024) Case Is < (1024 ^ 3) And bytesRead
>= (1024 ^ 2) Print Using "####.## MB downloaded";
(bytesRead
/ (1024 ^ 2)) Case Is < (1024 ^ 4) And bytesRead
>= (1024 ^ 3) Print Using "####.## GB downloaded";
(bytesRead
/ (1024 ^ 3)) Print Using "Rate: ####.## MBps"; Rate!
/ (1024 ^ 2) Print Using "Rate: ####.## GBps"; Rate!
/ (1024 ^ 3) 'Print "Rate="; _Round(Rate!); "KBps"
Print "Error downloading file:"; errr
InternetCloseHandle hsession
InternetCloseHandle hsession
Print Using "####.## KB downloaded of ";
(bytesRead
/ 1024);
Case Is < (1024 ^ 3) And bytesRead
>= (1024 ^ 2) Print Using "####.## MB downloaded of ";
(bytesRead
/ (1024 ^ 2));
Case Is < (1024 ^ 4) And bytesRead
>= (1024 ^ 3) Print Using "####.## GB downloaded of ";
(bytesRead
/ (1024 ^ 3));
Case Is < (1024 ^ 3) And bytesToRead
>= (1024 ^ 2) Print Using "####.## MB";
(bytesToRead
/ (1024 ^ 2)) Case Is < (1024 ^ 4) And bytesToRead
>= (1024 ^ 3) Print Using "####.## GB";
(bytesToRead
/ (1024 ^ 3)) Print Using "###.##%"; bytesRead
/ bytesToRead
* 100 Print "Downloaded to " + File
If startTime!
> Timer Then startTime!
= startTime!
- 86400 timeElapsedSince!
= Timer - startTime!
Const FORMAT_MESSAGE_ALLOCATE_BUFFER
= &H00000100 Const FORMAT_MESSAGE_FROM_SYSTEM
= &H00001000 Const FORMAT_MESSAGE_IGNORE_INSERTS
= &H00000200
Const LANG_NEUTRAL
= &H00 Const SUBLANG_DEFAULT
= &H01
msg
= FormatMessage
(FORMAT_MESSAGE_ALLOCATE_BUFFER
Or _
FORMAT_MESSAGE_FROM_SYSTEM
Or _
FORMAT_MESSAGE_IGNORE_INSERTS, _
0, _
errCode, _
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), _
0, 0)
ErrorMessage = pointerToString(lpMsgBuf)
_MemGet pString
, pString.OFFSET
, ret
pointerToString = ret