Jump to content

[UDF] AutoIT Get HTML source code / Download files on the Internet.


Recommended Posts

- _Download() Automatically select test and select download method.
- Support URL redirect
- Account and password

UDF:

#include-once
#include <FTPEx.au3>
#include <WinAPIEx.au3>
#include <String.au3>
#include <InetConstants.au3>
#include "WinHttp.au3"

;Opt("MustDeclareVars", 1)
Opt("TrayAutoPause", 0)
If StringInStr(@OSArch, "64") And (Not @AutoItX64) Then _WinAPI_Wow64EnableWow64FsRedirection(0)
; #CONSTANTS# ===================================================================================================================
Global Const $ViewLogConsole = 1, $bGetFieSize = 1
Global Const $OPTION_ENABLE_REDIRECTS = 6, $OPTION_USER_AGENT = 0
Global $obError = False, $oErrorHandler = ObjEvent("AutoIt.Error", "__Skip_OBJ_Error")
Global $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
Global $sUSER_AGENT = __WinHttpUA(), $TempDir = @TempDir
If Not _Directory_Is_Accessible($TempDir) Then
    $TempDir = @LocalAppDataDir & "\Temp"
    If Not _Directory_Is_Accessible($TempDir) Then $TempDir = @ScriptDir
EndIf
; ===========================================================================================

#comments-start
; Example
Global $ftpUserName = "ftpuser@files.trong.live"
Global $ftpPassword = "files.trong.live"

Global $httpUserName = 'trong'
Global $httpPassword = 'autoit'

_Download('https://files.trong.live/test.jpg', @ScriptDir & "\testA.jpg")
_Download('https://files.trong.live/prv/test.jpg', @ScriptDir & "\testA.jpg", $httpUserName, $httpPassword)
_FTP_Download('ftp://files.trong.live/prv/test.jpg', @ScriptDir & "\testB.jpg", $ftpUserName, $ftpPassword)
_Download('https://go.microsoft.com/fwlink/?LinkID=2093505', @ScriptDir & "\Microsoft_Edge_Ent_X86.msi")
_WinHttp_Download('http://go.microsoft.com/fwlink/?LinkID=2093437', @ScriptDir & "\Microsoft_Edge_Ent_X64.msi")

#comments-end

; #CURRENT# =====================================================================================================================
; _Download()
; _FTP_Download()
; _WinHttp_Download()
; ===============================================================================================================================

; #FUNCTION# ====================================================================================================================
; Author... ...........: Dao Van Trong  - TRONG.LIVE
; ===========================================================================================
Func _Download($sURL_Input, $sLocalPathSAVE, $dUserName = "anonymous", $dPassword = "")
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    $sURL_Input = StringReplace($sURL_Input, "\", "/")
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'http://' & $sURL_Input
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    If ($dProtocol = "ftp" Or $dProtocol = "sftp" Or $dProtocol = "ftps") Then
        Local $fDL = _FTP_Download($sURL_Input, $sLocalPathSAVE, $dUserName, $dPassword)
        Return SetError(@error, @extended, $fDL)
    EndIf
    If (($dUserName = Default) Or (StringStripWS($dUserName, 8) == "") Or (StringLower($dUserName) == "anonymous")) Then $dUserName = ""
    If ((StringLower($dUserName) == "anonymous") Or ($dUserName == "") And (StringLen(StringStripWS($dUser, 8)) > 1)) Then
        $dUserName = $dUser
        If (($dPassword == "") And (StringLen($dPass) > 1)) Then $dPassword = $dPass
    EndIf
    If (Not ($dUserName == '')) Then
        ;$dUserName = StringReplace($dUserName, '@', '%40')
        If ($dProtocol == 'https' And $dPort <> 443) Or ($dProtocol == 'http' And $dPort <> 80) Then
            $sURL_Input = $dProtocol & "://" & $dUserName & ":" & $dPassword & "@" & $dDomain & ":" & $dPort & $dURLFilePathName
        Else
            $sURL_Input = $dProtocol & "://" & $dUserName & ":" & $dPassword & "@" & $dDomain & $dURLFilePathName
        EndIf
    EndIf
    _LogDebug("- InetGet Download: " & $sURL_Input & " -> " & $sLocalPathSAVE & @CRLF)
    Local $dlTempFilePath
    While 1
        $dlTempFilePath = $TempDir & "\~download-" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & "-" & Random(88888888, 99999999, 1) & ".tmp"
        If (Not FileExists($dlTempFilePath)) Then ExitLoop
    WEnd
    $dUserName = StringReplace($dUserName, '%40', '@')
    Local $sURL_Rediect
    Local $urlStatus = __URL_Check($sURL_Input, $sURL_Rediect, $dUserName, $dPassword)
    If @error Then
        _LogDebug("! /!\ Test connect Error ! " & @CRLF)
        Return 0
    EndIf
    If ($sURL_Rediect == "") Then
    Else
        $sURL_Input = $sURL_Rediect
    EndIf
    HttpSetUserAgent($sUSER_AGENT)
    If $bGetFieSize Then
        _LogDebug("+ Get file size.... ")
        $dFileSize = InetGetSize($sURL_Input)
        If @error Then
            _LogDebug("  ERROR  !" & @CRLF)
        Else
            _LogDebug("  OK  ->  " & _Byte_GetDisplay($dFileSize) & "  " & @CRLF)
        EndIf
    EndIf
    _LogDebug("+ Downloading.... ")
    Local $hDownload = InetGet($sURL_Input, $dlTempFilePath, 1 + 2 + 16, 1)
    Local $Percentage = 0, $Old_Percentage = 0, $TotalToDownload = 0, $BytesDownloaded = 0, $DownloadedSoFar = 0, $pCheck = 0
    Do
        Sleep(100)
        If $dFileSize > 0 Then
            ; Get number of bytes read for current file
            $BytesDownloaded = InetGetInfo($hDownload, 0)
            ; Add this to the cumulative total
            $DownloadedSoFar = $TotalToDownload + $BytesDownloaded
            ; Calculate the current file percentage
            $Percentage = Floor(($BytesDownloaded / $dFileSize) * 100)
            ; Only update the current file percent label if it has changed to avoid flickering
            If ($Percentage - $Old_Percentage) > 4 Then
                _LogDebug($Percentage & "% ")
                $Old_Percentage = $Percentage
            EndIf
        EndIf
    Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
    ; Retrieve the number of total bytes received and the filesize.
    ;Local $iBytesSize = InetGetInfo($hDownload, $INET_DOWNLOADREAD)
    ;Local $iFileSize = FileGetSize($dlTempFilePath)
    ;ConsoleWrite("- Downloaded: " & $iBytesSize & " KB/s " & @CRLF)
    ;ConsoleWrite("- File Size: " & $iFileSize & " KB/s " & @CRLF)
    Local $aDownloadData = InetGetInfo($hDownload)
    InetClose($hDownload)
    If ($aDownloadData[$INET_DOWNLOADSUCCESS] And FileExists($dlTempFilePath)) Then
        _LogDebug("- DONE !" & @CRLF)
        __File_SAVE($dlTempFilePath, $sLocalPathSAVE)
        If FileExists($sLocalPathSAVE) Then
            _LogDebug("+ Save file to: " & $sLocalPathSAVE & " OK !" & @CRLF)
        Else
            _LogDebug("! Save file to: " & $sLocalPathSAVE & " ERROR !" & @CRLF)
        EndIf
    Else
        _LogDebug(" ERROR " & @CRLF)
        _LogDebug("- Try Download again with WinHttp !" & @CRLF)
        Return _WinHttp_Download($sURL_Input, $sLocalPathSAVE)
    EndIf
EndFunc   ;==>_Download

Func _WinHttp_Download($sURL_Input, $sLocalPathSAVE, $dUserName = "anonymous", $dPassword = "")
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'http://' & $sURL_Input
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    If ($dProtocol = "ftp" Or $dProtocol = "sftp" Or $dProtocol = "ftps") Then
        Local $fDL = _FTP_Download($sURL_Input, $sLocalPathSAVE, $dUserName, $dPassword)
        Return SetError(@error, @extended, $fDL)
    EndIf
    If (($dUserName = Default) Or (StringStripWS($dUserName, 8) == "") Or (StringLower($dUserName) == "anonymous")) Then $dUserName = ""
    If ((StringLower($dUserName) == "anonymous") Or ($dUserName == "") And (StringLen(StringStripWS($dUser, 8)) > 1)) Then
        $dUserName = $dUser
        If (($dPassword == "") And (StringLen($dPass) > 1)) Then $dPassword = $dPass
    EndIf
    _LogDebug("+ WinHttp Download: " & $sURL_Input & " -> " & $sLocalPathSAVE & @CRLF)
    Local $sURL_Rediect
    Local $urlStatus = __URL_Check($sURL_Input, $sURL_Rediect, $dUserName, $dPassword)
    If @error Then
        _LogDebug("! /!\ Test connect Error ! " & @CRLF)
        Return 0
    EndIf
    If ($sURL_Rediect == "") Then
    Else
        $sURL_Input = $sURL_Rediect
    EndIf
    Local $dlTempFilePath
    While 1
        $dlTempFilePath = $TempDir & "\~download-" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & "-" & Random(88888888, 99999999, 1) & ".tmp"
        If (Not FileExists($dlTempFilePath)) Then ExitLoop
    WEnd
    ; Initialize and get session handle
    Local $hOpen = _WinHttpOpen()
    ; Set User-Agent string
    _WinHttpSetOption($hOpen, $WINHTTP_OPTION_USER_AGENT, $sUSER_AGENT)
    ; Get connection handle
    _LogDebug("- WinHttp Connecting ...")
    Local $hConnect = _WinHttpConnect($hOpen, $dDomain)
    If @error Then
        _LogDebug(" ERROR " & @error & @CRLF)
        Return SetError(1, 0, 0)
    EndIf
    _LogDebug(" OK" & @CRLF & "- WinHttp Downloading ...")
    ; SimpleSSL-request it...
    Local $vReturned
    If (($dProtocol = "https") Or ($dPort = 443)) Then
        $vReturned = _WinHttpSimpleSSLRequest($hConnect, "GET", $dURLFilePathName, $dProtocol & "://" & $dDomain, $WINHTTP_NO_REQUEST_DATA, $WINHTTP_NO_ADDITIONAL_HEADERS, False, 2, $dUserName, $dPassword)
    Else
        $vReturned = _WinHttpSimpleRequest($hConnect, "GET", $dURLFilePathName, $dProtocol & "://" & $dDomain, $WINHTTP_NO_REQUEST_DATA, $WINHTTP_NO_ADDITIONAL_HEADERS, False, 2, $dUserName, $dPassword)
    EndIf
    If @error Then
        _LogDebug("! Request ERROR " & @error & @CRLF)
        Return SetError(2, 0, 0)
    EndIf
    _LogDebug(" OK" & @CRLF & "- Saving to file ...")
    ; Close handles
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    If FileExists($sLocalPathSAVE) Then _DelIt($sLocalPathSAVE, 1)
    Local $iDirFile = _Path_Split($sLocalPathSAVE, 6)
    If Not FileExists($iDirFile) Then DirCreate($iDirFile)
    Local $DataLen = BinaryLen($vReturned)
    Local $hFile = FileOpen($sLocalPathSAVE, 2 + 8 + 16)
    FileWrite($hFile, $vReturned)
    FileClose($hFile)
    If FileExists($sLocalPathSAVE) Then
        _LogDebug(" OK (Size: " & _Byte_GetDisplay($DataLen) & ") file: " & $sLocalPathSAVE & @CRLF)
        Return 1
    Else
        _LogDebug(" ERROR (Size: " & _Byte_GetDisplay($DataLen) & ") file: " & $sLocalPathSAVE & @CRLF)
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>_WinHttp_Download

Func _FTP_Download($sURL_Input, $sLocalPathSAVE, $dUserName = "anonymous", $dPassword = "")
    _LogDebug("+ FTP Download: " & $sURL_Input & " -> " & $sLocalPathSAVE & @CRLF)
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'ftp://' & $sURL_Input
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    #cs
        ConsoleWrite("- Protocol    : " & $dProtocol & @CRLF)
        ConsoleWrite("- Domain      : " & $dDomain & @CRLF)
        ConsoleWrite("- Port        : " & $dPort & @CRLF)
        ConsoleWrite("- User        : " & $dUser & @CRLF)
        ConsoleWrite("- Password    : " & $dPass & @CRLF)
        ConsoleWrite("- FilePathName: " & $dURLFilePathName & @CRLF)
        ConsoleWrite("- FilePath    : " & $dURLFilePath & @CRLF)
        ConsoleWrite("- FileName    : " &$dURLFileName & @CRLF)
    #ce
    If (($dUserName = Default) Or (StringStripWS($dUserName, 8) == "")) Then $dUserName = "anonymous"
    If ((StringLower($dUserName) == "anonymous") Or ($dUserName == "") And (StringLen(StringStripWS($dUser, 8)) > 1)) Then
        $dUserName = $dUser
        If (($dPassword == "") And (StringLen($dPass) > 1)) Then $dPassword = $dPass
    EndIf
    Local $Err, $sFTP_Message, $iReturn = 0, $iError = 0
    Local $dlTempFilePath = $TempDir & "\~download.tmp"
    While 1
        $dlTempFilePath = $TempDir & "\~download-" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & "-" & Random(88888888, 99999999, 1) & ".tmp"
        If (Not FileExists($dlTempFilePath)) Then ExitLoop
    WEnd
    If $bGetFieSize Then
        _LogDebug("- FTP Getting the file size... " & @CRLF)
        $dFileSize = _Byte_GetDisplay(__FTP_FileGetSize($sURL_Input, $dUserName, $dPassword))
    EndIf
    ;_LogDebug("-Protocol: " & $dProtocol & @CRLF)
    ;_LogDebug("-Server: " & $dDomain & @CRLF)
    ;_LogDebug("-User: '" & $dUserName & "'" & @CRLF)
    ;_LogDebug("-Password: '" & $dPassword & "'" & @CRLF)
    ;_LogDebug("-RemoteFile: " & $dURLFilePathName & @CRLF)
    If $dFileSize > 0 Then
        _LogDebug("- File Size: " & $dFileSize & @CRLF)
    Else
        _LogDebug("! An error occurred, Getting the file size failed!" & @CRLF)
    EndIf
    _LogDebug("- FTP Getting the file ... " & @CRLF)
    Local $hOpen = _FTP_Open('FTP_Client', $INTERNET_OPEN_TYPE_DIRECT)
    If @error Then Return SetError(1, 0, 0)
    Local $hFTPSession = _FTP_Connect($hOpen, $dDomain, $dUserName, $dPassword)
    If @error Then
        Local $WinHTTP_Error_Return = @extended
        Local $WinHTTP_Error_Name = _WinHTTP_GetName_ErrorCode($WinHTTP_Error_Return)
        _LogDebug('! _FTP_Connect Error: ' & @error & " - Extended: " & $WinHTTP_Error_Return & @CRLF)
        _LogDebug('! WinHTTP Error: ' & $WinHTTP_Error_Name & @CRLF)
        If ($WinHTTP_Error_Return = 12029) Then _LogDebug('! Error: A connection with the server could not be established' & @CRLF)
        If ($WinHTTP_Error_Return = 12014) Then _LogDebug('! Error: The request to connect and log on to an FTP server could not be completed because the supplied password is incorrect.' & @CRLF)
        Return SetError(2, $WinHTTP_Error_Return, 0)
    EndIf
    If $bGetFieSize Then
        _LogDebug("- Downloading " & $dURLFilePathName & " (" & $dFileSize & ") " & " ..." & @CRLF)
    Else
        _LogDebug("- Downloading " & $dURLFilePathName & " ...")
    EndIf
    Local $fuFunctionToCall = __FTPGetFile_UpdateProgress
    Local $iFDL = _FTP_ProgressDownload($hFTPSession, $dlTempFilePath, $dURLFilePathName, $fuFunctionToCall)
    Local $iErr, $sFTP_Message
    If (Not FileExists($dlTempFilePath)) Then
        _FTP_GetLastResponseInfo($iErr, $sFTP_Message)
        _LogDebug('! ERROR ! Code: [' & $Err & '] FTP_Message: [' & @CRLF & $sFTP_Message & "]" & @CRLF)
        _FTP_Close($hFTPSession)
        _FTP_Close($hOpen)
        $hOpen = _FTP_Open('FTP_Client', $INTERNET_OPEN_TYPE_DIRECT)
        $hFTPSession = _FTP_Connect($hOpen, $dDomain, $dUserName, $dPassword)
        If @error Then
            Local $WinHTTP_Error_Return = @extended
            Local $WinHTTP_Error_Name = _WinHTTP_GetName_ErrorCode($WinHTTP_Error_Return)
            _LogDebug('! _FTP_Connect Error: ' & @error & " - Extended: " & $WinHTTP_Error_Return & @CRLF)
            _LogDebug('! WinHTTP Error: ' & $WinHTTP_Error_Name & @CRLF)
            If ($WinHTTP_Error_Return = 12029) Then _LogDebug('! Error: A connection with the server could not be established' & @CRLF)
            If ($WinHTTP_Error_Return = 12014) Then _LogDebug('! Error: The request to connect and log on to an FTP server could not be completed because the supplied password is incorrect.' & @CRLF)
            Return SetError(2, $WinHTTP_Error_Return, 0)
        EndIf
        $iFDL = _FTP_FileGet($hFTPSession, $dURLFilePathName, $dlTempFilePath, False, Default, $FTP_TRANSFER_TYPE_BINARY)
        If (Not FileExists($dlTempFilePath)) Then
            _FTP_GetLastResponseInfo($iErr, $sFTP_Message)
            _LogDebug('! ERROR ! Code: [' & $Err & '] FTP_Message: [' & @CRLF & $sFTP_Message & "]" & @CRLF)
            _FTP_Close($hFTPSession)
            _FTP_Close($hOpen)
            Return SetError(3, 0, 0)
        Else
            _LogDebug('+ OK !' & @CRLF)
        EndIf
    Else
        _LogDebug('+ OK !' & @CRLF)
    EndIf
    _FTP_Close($hFTPSession)
    _FTP_Close($hOpen)
    __File_SAVE($dlTempFilePath, $sLocalPathSAVE)
    If FileExists($sLocalPathSAVE) Then
        _LogDebug("+ Save file to: " & $sLocalPathSAVE & " OK !" & @CRLF)
        Return SetError(0, 0, 1)
    Else
        _LogDebug("! Save file to: " & $sLocalPathSAVE & " ERROR !" & @CRLF)
        Return SetError(4, 0, 0)
    EndIf
EndFunc   ;==>_FTP_Download

Func __FTPGetFile_UpdateProgress($iPercent)
    _LogDebug(" " & Int($iPercent) & "%" & ' ')
    ;If _IsPressed("77") Then Return 0 ; Abort on F8
    Return 1     ; 1 to continue Download
EndFunc   ;==>__FTPGetFile_UpdateProgress

Func __FTP_FileGetSize($sURL_Input, $dUserName = "anonymous", $dPassword = "")
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'ftp://' & $sURL_Input
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    If (($dUserName = Default) Or (StringStripWS($dUserName, 8) == "")) Then $dUserName = "anonymous"
    If ((StringLower($dUserName) == "anonymous") Or ($dUserName == "") And (StringLen(StringStripWS($dUser, 8)) > 1)) Then
        $dUserName = $dUser
        If (($dPassword == "") And (StringLen($dPass) > 1)) Then $dPassword = $dPass
    EndIf
    Local $hOpen = _FTP_Open('FTP_Client')
    If @error Then Return SetError(1, 0, "")
    Local $hConn = _FTP_Connect($hOpen, $dDomain, $dUserName, $dPassword)
    If @error Then
        Local $WinHTTP_Error_Return = @extended
        Local $WinHTTP_Error_Name = _WinHTTP_GetName_ErrorCode($WinHTTP_Error_Return)
        _LogDebug('! _FTP_Connect Error: ' & @error & " - Extended: " & $WinHTTP_Error_Return & @CRLF)
        _LogDebug('! WinHTTP Error: ' & $WinHTTP_Error_Name & @CRLF)
        If ($WinHTTP_Error_Return = 12029) Then _LogDebug('! Error: A connection with the server could not be established' & @CRLF)
        If ($WinHTTP_Error_Return = 12014) Then _LogDebug('! Error: The request to connect and log on to an FTP server could not be completed because the supplied password is incorrect.' & @CRLF)
        Return SetError(2, $WinHTTP_Error_Return, 0)
    EndIf
    Local $iFileSize = _FTP_FileGetSize($hConn, $dURLFilePathName)
    If @error Then Return SetError(3, 0, "")
    ;ConsoleWrite('$sFilenameNext1 = ' & $dFileName & ' size = ' & $iFileSize & '  -> Error code: ' & @error & ' extended: ' & @extended & @CRLF)
    Local $iErr, $sMessage
    Local $iFtpr = _FTP_GetLastResponseInfo($iErr, $sMessage) ; no error
    ;ConsoleWrite('$sMessage = ' & $sMessage & ' err = ' & $iErr & '  -> Error code: ' & @error & ' extended: ' & @extended & @CRLF)
    Local $iFtpc = _FTP_Close($hConn)
    Local $iFtpo = _FTP_Close($hOpen)
    Return $iFileSize
EndFunc   ;==>__FTP_FileGetSize

Func __File_SAVE($dlTempFilePath, $sLocalPathSAVE)
    If Not FileExists($dlTempFilePath) Then
        _LogDebug("! Source path is not File Exists: " & $dlTempFilePath & @CRLF)
        Return SetError(1, 0, -1)
    EndIf
    _LogDebug("- Move (" & FileExists($dlTempFilePath) & ") " & $dlTempFilePath & " >TO> " & $sLocalPathSAVE & " > ")
    If FileExists($sLocalPathSAVE) Then _DelIt($sLocalPathSAVE, 1)
    Local $iDirFile = _Path_Split($sLocalPathSAVE, 6)
    If Not FileExists($iDirFile) Then DirCreate($iDirFile)
    If FileMove($dlTempFilePath, $sLocalPathSAVE, 1) Then
        _DelIt($dlTempFilePath, 1)
        _LogDebug(" Move OK" & @CRLF)
        Return 1
    Else
        _LogDebug(" ERROR !" & @CRLF & @CRLF)
        _LogDebug("- Try Copy (" & FileExists($dlTempFilePath) & ") " & $dlTempFilePath & " >TO> " & $sLocalPathSAVE & " > ")
        If FileCopy($dlTempFilePath, $sLocalPathSAVE, 1) Then
            _DelIt($dlTempFilePath, 1)
            _LogDebug(" OK" & @CRLF)
            Return 1
        Else
            _LogDebug(" ERROR !" & @CRLF & @CRLF)
            Return 0
        EndIf
    EndIf
EndFunc   ;==>__File_SAVE

Func _Encode_URL($UnicodeURL)
    Local $UnicodeBinary = StringToBinary($UnicodeURL, 4)
    Local $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1)
    Local $UnicodeBinaryLength = StringLen($UnicodeBinary2)
    Local $EncodedString, $UnicodeBinaryChar
    For $i = 1 To $UnicodeBinaryLength Step 2
        $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2)
        If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString('0x' & $UnicodeBinaryChar, 4)) Then
            $EncodedString &= BinaryToString('0x' & $UnicodeBinaryChar)
        Else
            $EncodedString &= '%' & $UnicodeBinaryChar
        EndIf
    Next
    Return $EncodedString
EndFunc   ;==>_Encode_URL

Func _Decode_URL($toDecode)
    Local $strChar = "", $iOne, $iTwo
    Local $aryHex = StringSplit($toDecode, "")
    For $i = 1 To $aryHex[0]
        If $aryHex[$i] = "%" Then
            $i = $i + 1
            $iOne = $aryHex[$i]
            $i = $i + 1
            $iTwo = $aryHex[$i]
            $strChar = $strChar & Chr(Dec($iOne & $iTwo))
        Else
            $strChar = $strChar & $aryHex[$i]
        EndIf
    Next
    Local $Process = StringToBinary(StringReplace($strChar, "+", " "))
    Local $DecodedString = BinaryToString($Process, 4)
    Return $DecodedString
EndFunc   ;==>_Decode_URL

Func __URL_Status($sURL_Input, ByRef $sURL_Rediect, $dUserName = "anonymous", $dPassword = "")
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    If (($dUserName = Default) Or (StringStripWS($dUserName, 8) == "") Or (StringLower($dUserName) == "anonymous")) Then $dUserName = ""
    If ((StringLower($dUserName) == "anonymous") Or ($dUserName == "") And (StringLen(StringStripWS($dUser, 8)) > 1)) Then
        $dUserName = $dUser
        If (($dPassword == "") And (StringLen($dPass) > 1)) Then $dPassword = $dPass
    EndIf
    If (Not ($dUserName == '')) Then
        If ($dProtocol == 'https' And $dPort <> 443) Or ($dProtocol == 'http' And $dPort <> 80) Then
            $sURL_Input = $dProtocol & "://" & $dDomain & ":" & $dPort & $dURLFilePathName
        Else
            $sURL_Input = $dProtocol & "://" & $dDomain & $dURLFilePathName
        EndIf
    EndIf
    $oHTTP.Option($OPTION_USER_AGENT) = $sUSER_AGENT
    $oHTTP.Option($OPTION_ENABLE_REDIRECTS) = False
    $oHTTP.Open("HEAD", $sURL_Input, False)
    If @error Then Return SetError(1, @error, -1)
    If (StringLen(StringStripWS($dUserName, 8)) > 1) Then $oHTTP.SetCredentials($dUserName, $dPassword, 0)
    $oHTTP.Send()
    If @error Then Return SetError(2, @error, 105) ;Error 105 (net::ERR_NAME_NOT_RESOLVED)
    Local $oStatus = $oHTTP.Status
    If @error Then Return SetError(3, @error, 118) ;Error 118 (net::ERR_CONNECTION_TIMED_OUT)
    If (($oStatus = 301) Or ($oStatus = 302)) Then
        $sURL_Rediect = $oHTTP.GetResponseHeader("Location")
        _LogDebug("! Redirect to URL: " & $sURL_Rediect & @CRLF)
    EndIf
    ;_LogDebug("+ GetResponseHeader: " & $oStatus & @CRLF)
    ;_LogDebug("- Cache-Control: " & $oHTTP.GetResponseHeader("Cache-Control") & @CRLF)
    ;_LogDebug("- Connection: " & $oHTTP.GetResponseHeader("Connection") & @CRLF)
    ;_LogDebug("- Date: " & $oHTTP.GetResponseHeader("Date") & @CRLF)
    ;_LogDebug("- Keep-Alive: " & $oHTTP.GetResponseHeader("Keep-Alive") & @CRLF)
    _LogDebug("- Content-Length: " & _Byte_GetDisplay($oHTTP.GetResponseHeader("Content-Length")) & @CRLF)
    ;_LogDebug("- Content-Type: " & $oHTTP.GetResponseHeader("Content-Type") & @CRLF)
    ;_LogDebug("- Expires: " & $oHTTP.GetResponseHeader("Expires") & @CRLF)
    ;_LogDebug("- Last-Modified: " & $oHTTP.GetResponseHeader("Last-Modified") & @CRLF)
    ;_LogDebug("- Accept-Ranges: " & $oHTTP.GetResponseHeader("Accept-Ranges") & @CRLF)
    ;_LogDebug("- Server: " & $oHTTP.GetResponseHeader("Server") & @CRLF)
    ;_LogDebug("- WWW-Authenticate: " & $oHTTP.GetResponseHeader("WWW-Authenticate") & @CRLF)
    ;_LogDebug($oHTTP.getAllResponseHeaders() & @CRLF)
    $oHTTP.Option($OPTION_ENABLE_REDIRECTS) = True
    Return SetError(0, 0, $oStatus)
EndFunc   ;==>__URL_Status

Func _Check_Connect($iDomain, $iPort = 80)
    Opt("TCPTimeout", 3000)
    TCPStartup()
    _LogDebug("- Checking Domain: " & $iDomain & " | Port: " & $iPort & " ")
    Local $sIPAddress = TCPNameToIP($iDomain)
    _LogDebug(" -> IP Address: " & $sIPAddress)
    Local $iSocket = TCPConnect($sIPAddress, $iPort)
    If $iSocket < 1 Then
        _LogDebug(" -> ERROR !" & @CRLF)
        Return SetError(1, 0, 0)
    Else
        _LogDebug(" -> SK:" & $iSocket & " OK !" & @CRLF)
        Return SetError(0, 0, 1)
    EndIf
    TCPShutdown()
    Opt("TCPTimeout", 250)
EndFunc   ;==>_Check_Connect

Func __URL_Check($sURL_Input, ByRef $sURL_Rediect, $dUserName = "anonymous", $dPassword = "")
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'http://' & $sURL_Input
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    #cs
     ConsoleWrite("- Protocol    : " & $dProtocol & @CRLF)
    ConsoleWrite("- Domain      : " & $dDomain & @CRLF)
    ConsoleWrite("- Port        : " & $dPort & @CRLF)
    ConsoleWrite("- User        : " & $dUser & @CRLF)
    ConsoleWrite("- Password    : " & $dPass & @CRLF)
    ConsoleWrite("- FilePathName: " & $dURLFilePathName & @CRLF)
    ConsoleWrite("- FilePath    : " & $dURLFilePath & @CRLF)
    ConsoleWrite("- FileName    : " &$dURLFileName & @CRLF)
    #ce
    If $dPort > 0 Then
        If _Check_Connect($dDomain, $dPort) = 0 Then Return SetError(1, 0, 0)
    Else
        Switch $dProtocol
            Case "http"
                If (_Check_Connect($dDomain, 80) = 0) Then Return SetError(1, 0, 0)
            Case "https"
                If (_Check_Connect($dDomain, 443) = 0) Then Return SetError(1, 0, 0)
            Case "ftp", "ftps"
                If (_Check_Connect($dDomain, 21) = 0) Then Return SetError(1, 0, 0)
            Case "sftp"
                If (_Check_Connect($dDomain, 22) = 0) Then Return SetError(1, 0, 0)
        EndSwitch
    EndIf
    Local $urlStatus = __URL_Status($sURL_Input, $sURL_Rediect, $dUserName, $dPassword)
    Switch $urlStatus
        Case 301, 302
            If ($sURL_Rediect == "") Then
            Else
                $sURL_Input = $sURL_Rediect
            EndIf
            _LogDebug("- URL Status: " & $urlStatus & " > Connection Successful! (URL redirect to: " & $sURL_Input & ")" & @CRLF)
            Return SetError(0, 0, __URL_Check($sURL_Input, $sURL_Rediect, $dUserName, $dPassword))
        Case 200
            _LogDebug("- URL Status: " & $urlStatus & " > Connection Successful! (URL: " & $sURL_Input & ")" & @CRLF)
            Return SetError(0, 0, $urlStatus)
        Case 401, 407
            _LogDebug("- URL Status: " & $urlStatus & " > Connection error! > Unauthorized (URL: " & $sURL_Input & ")" & @CRLF)
        Case 404
            _LogDebug("- URL Status: " & $urlStatus & " > Connection Successful! > URL Not Found: " & $sURL_Input & @CRLF)
        Case 105
            _LogDebug("- URL Status: " & $urlStatus & " > Connection error: ERR_NAME_NOT_RESOLVED > URL is Not Found: " & $sURL_Input & @CRLF)
        Case Else
            _LogDebug("- URL Status: " & $urlStatus & " > Connection error! > URL: " & $sURL_Input & @CRLF)
    EndSwitch
    Return SetError(1, 0, $urlStatus)
EndFunc   ;==>__URL_Check

Func _Byte_GetDisplay($iSize, $iPlaces = 4)
    Local $aBytes[7] = [' Bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB']
    For $i = 6 To 1 Step -1
        If $iSize >= 1024 ^ $i Then
            Return Round($iSize / 1024 ^ $i, $iPlaces) & $aBytes[$i]
        EndIf
    Next
    Return $iSize & ' Bytes'
EndFunc   ;==>_Byte_GetDisplay

Func _Convert_Size($inputSize, $inputUnit = 0, $outputPlaces = 2, $outputString = True, $inputBits = False, $outputBits = False, $outputUnit = -4)
    Local $unitNames[9] = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"]
    Local $Bytes = $inputSize * 1024 ^ $inputUnit
    Local $b = "B"
    If $inputBits Then $Bytes /= 8
    If $outputBits Then
        $Bytes *= 8
        $b = "b"
    EndIf
    If $outputUnit < 0 Then
        Local $outputMax = Abs($outputUnit)
        $outputUnit = Int(Log($Bytes) / Log(1024))
        If $outputUnit > $outputMax Then $outputUnit = $outputMax
    EndIf
    If $outputString Then
        Return String(Round($Bytes / 1024 ^ $outputUnit, $outputPlaces)) & " " & $unitNames[$outputUnit] & $b
    Else
        Return Round($Bytes / 1024 ^ $outputUnit, $outputPlaces)
    EndIf
EndFunc   ;==>_Convert_Size

Func _Path_Split($sFilePath, $sType = 0)
    Local $sDrive, $sDir, $sFileName, $sExtension, $sReturn
    Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1)
    If @error Then
        ReDim $aArray[5]
        $aArray[0] = $sFilePath
    EndIf
    $sDrive = $aArray[1]
    If StringLeft($aArray[2], 1) == "/" Then
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\/")
    Else
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\\")
    EndIf
    $aArray[2] = $sDir
    $sFileName = $aArray[3]
    $sExtension = $aArray[4]
    If $sType = 1 Then Return $sDrive
    If $sType = 2 Then Return $sDir
    If $sType = 3 Then Return $sFileName
    If $sType = 4 Then Return $sExtension
    If $sType = 5 Then Return $sFileName & $sExtension
    If $sType = 6 Then Return $sDrive & $sDir
    If $sType = 7 Then Return $sDrive & $sDir & $sFileName
    Return $aArray
EndFunc   ;==>_Path_Split

Func _IsFile($sPath)
    If (Not FileExists($sPath)) Then Return SetError(-1, 0, 0)
    If StringInStr(FileGetAttrib($sPath), 'D') <> 0 Then
        Return SetError(0, 0, 0)
    Else
        Return SetError(0, 0, 1)
    EndIf
EndFunc   ;==>_IsFile

Func _DelIt($sPath, $Fc = 1)
    If (Not FileExists($sPath)) Then Return SetError(-1, 0, 1)
    If _IsFile($sPath) Then
        Return SetError(0, 0, _DelFile($sPath, $Fc))
    Else
        Return SetError(0, 0, _RemoveDir($sPath, $Fc))
    EndIf
EndFunc   ;==>_DelIt

Func _DelFile($sPath, $Fc = 1)
    If (Not _IsFile($sPath)) Then
        Return SetError(-1, 0, 0)
    Else
        FileSetAttrib($sPath, "-RSH")
        FileDelete($sPath)
        If $Fc Then
            If FileExists($sPath) Then _TakeOwnership($sPath, "Everyone", $Fc)
            If FileExists($sPath) Then FileDelete($sPath)
            If FileExists($sPath) Then RunWait(@ComSpec & ' /c Del /f /q "' & $sPath & '"', '', @SW_HIDE)
        EndIf
        If FileExists($sPath) Then Return SetError(1, 0, 0)
        Return SetError(0, 0, 1)
    EndIf
EndFunc   ;==>_DelFile

Func _RemoveDir($sPath, $Fc = 1)
    If _IsFile($sPath) Then
        Return SetError(-1, 0, 0)
    Else
        DirRemove($sPath, $Fc)
        If FileExists($sPath) Then _TakeOwnership($sPath, "Everyone", $Fc)
        DirRemove($sPath, $Fc)
        If FileExists($sPath) Then RunWait(@ComSpec & ' /c rmdir "' & $sPath & '" /s /q ', '', @SW_HIDE)
        If FileExists($sPath) Then Return SetError(1, 0, 0)
        Return SetError(0, 0, 1)
    EndIf
EndFunc   ;==>_RemoveDir

Func _GetDomainURL($sURL_Input)
    Local $sURL_Pattern = "^(?i)(?:(?:[a-z]+):\/\/)?" & _ ; Protocol
            "(?:(?:(?:[^@:]+))" & _ ; Username
            "(?::(?:[^@]+))?@)?" & _ ; Password
            "([^\/:]+)" & _ ; Host
            "(?::(?:\d+))?" & _ ; Port
            "(?:\/(?:[^?]+)?)?" & _ ; Path
            "(?:\?\N+)?" ; Query
    Local $aHost = StringRegExp($sURL_Input, $sURL_Pattern, 1)
    If IsArray($aHost) Then Return $aHost[0]
    Return ""
EndFunc   ;==>_GetDomainURL

Func _LogDebug($iLog = "", $iLogs = "", $itype = -1)
    If (($itype = 0) And ($iLog = "") And ($iLogs = "")) Then Return 0
    If (($itype = -1) And $ViewLogConsole) Then Return ConsoleWrite($iLog)
    If ($iLogs = "") Then $iLogs = $iLog
    If ($itype = 0) Then
        If $ViewLogConsole Then ConsoleWrite("- " & $iLog & @CRLF)
        ;If $sTextColor <> $lBkColor Then
        ;$sTextColor = $lBkColor
        ;GUICtrlSetColor($labStatus, $sTextColor)
        ;EndIf
        ;GUICtrlSetData($labStatus, $iLogs)
    Else
        If $ViewLogConsole Then ConsoleWrite("! " & $iLog & @CRLF)
        ;If $sTextColor <> $sTextColorError Then
        ;$sTextColor = $sTextColorError
        ;GUICtrlSetColor($labStatus, $sTextColor)
        ;EndIf
        ;GUICtrlSetData($labStatus, $iLogs)
    EndIf
    Return 1
EndFunc   ;==>_LogDebug

Func __Skip_OBJ_Error()
    $obError = True
    ;ConsoleWrite("! " & $obError.description & @CRLF)
EndFunc   ;==>__Skip_OBJ_Error

Func _WinHttpURL_GetStatus($sURL_Input, $dUserName = "anonymous", $dPassword = "")
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'http://' & $sURL_Input
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    If (($dUserName = Default) Or (StringStripWS($dUserName, 8) == "") Or (StringLower($dUserName) == "anonymous")) Then $dUserName = ""
    If ((StringLower($dUserName) == "anonymous") Or ($dUserName == "") And (StringLen(StringStripWS($dUser, 8)) > 1)) Then
        $dUserName = $dUser
        If (($dPassword == "") And (StringLen($dPass) > 1)) Then $dPassword = $dPass
    EndIf
    ; Initialize and get session handle
    Global $hOpen = _WinHttpOpen()
    ; Get connection handle
    Global $hConnect = _WinHttpConnect($hOpen, $dDomain)
    ; Specify the reguest
    Global $hRequest = _WinHttpOpenRequest($hConnect, "HEAD", $dURLFilePathName, Default, $dProtocol & "://" & $dDomain)
    ; Set credentials
    If (StringLen(StringStripWS($dUserName, 8)) > 1) Then _WinHttpSetCredentials($hRequest, $WINHTTP_AUTH_TARGET_SERVER, $WINHTTP_AUTH_SCHEME_BASIC, $dUserName, $dPassword)
    ; Send request
    _WinHttpSendRequest($hRequest)
    ; Wait for the response
    _WinHttpReceiveResponse($hRequest)
    ; Get full header
    Global $sHeader = _WinHttpQueryHeaders($hRequest)
    ConsoleWrite($sHeader & @CRLF)
    ; Close handles
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
EndFunc   ;==>_WinHttpURL_GetStatus

Func _Directory_Is_Accessible($sPath, $iTouch = 0)
    If Not FileExists($sPath) Then DirCreate($sPath)
    If Not StringInStr(FileGetAttrib($sPath), "D", 2) Then Return SetError(1, 0, 0)
    Local $iEnum = 0, $maxEnum = 9999, $iRandom = Random(88888888, 99999999, 1)
    If $iTouch Then _TakeOwnership($sPath, "Everyone", 1)
    While FileExists($sPath & "\_IsWritable-" & $iEnum & "-" & $iRandom)
        $iEnum += 1
        If ($iEnum > $maxEnum) Then Return SetError(2, 0, 0)
    WEnd
    Local $iSuccess = DirCreate($sPath & "\_IsWritable-" & $iEnum & "-" & $iRandom)
    Switch $iSuccess
        Case 1
            $iTouch = DirRemove($sPath & "\_IsWritable-" & $iEnum & "-" & $iRandom, 1)
            Return SetError($iTouch < 1, 0, $iTouch)
        Case Else
            Return SetError(3, 0, 0)
    EndSwitch
EndFunc   ;==>_Directory_Is_Accessible

Func _File_Is_Accessible($sFile, $iTouch = 0)
    ; Returns
    ; 1 = Success, file is writeable and deletable
    ; 2 = Access Denied because of lacking access rights OR because file is open by another process
    ; 3 = File is set "Read Only" by attribute
    ; 0 = File not found or Is Directory
    If ((Not FileExists("\\?\" & $sFile)) Or StringInStr(FileGetAttrib("\\?\" & $sFile), "D", 2)) Then Return SetError(1, 0, 0)
    Local $oFileAttrib = FileGetAttrib("\\?\" & $sFile)
    If $iTouch Then
        FileSetAttrib("\\?\" & $sFile, "-RHS")
        _TakeOwnership($sFile, "Everyone", 1)
    EndIf
    If StringInStr(FileGetAttrib("\\?\" & $sFile), "R", 2) Then Return 3 ; Read-Only Flag set
    Local $hFile = _WinAPI_CreateFileEx("\\?\" & $sFile, $OPEN_EXISTING, $GENERIC_READ + $GENERIC_WRITE, $FILE_SHARE_READ + $FILE_SHARE_WRITE + $FILE_SHARE_DELETE, $FILE_FLAG_BACKUP_SEMANTICS) ;
    Local $iReturn = $hFile
    _WinAPI_CloseHandle($hFile)
    If ($iReturn = 0) Then Return 2 ; File not accessible, UAC issue?
    Return 1 ; Success
EndFunc   ;==>_File_Is_Accessible

Func _TakeOwnership($sFile, $iUserName = "Everyone", $sRecurse = 1)
    If ($iUserName = Default) Or (StringStripWS($iUserName, 8) = '') Then $iUserName = "Everyone"
    If ($sRecurse = Default) Or ($sRecurse = True) Or ($sRecurse > 0) Then
        $sRecurse = 1
    Else
        $sRecurse = 0
    EndIf
    Local $osNotIsEnglish = True
    Switch @OSLang
        Case "0009", "0409", "0809", "0C09", "1009", "1409", "1809", "1C09", "2009", "2409", "2809", "2C09", "3009", "3409", "3C09", "4009", "4409", "4809", "4C09"
            $osNotIsEnglish = False
        Case "3809", "5009", "5409", "5809", "5C09", "6009", "6409" ; new
            $osNotIsEnglish = False
    EndSwitch
    If StringInStr($iUserName, ' ') Then $iUserName = '"' & $iUserName & '"'
    If ($sRecurse = Default) Then $sRecurse = 1
    If Not FileExists($sFile) Then Return SetError(1, 0, $sFile)
    If StringInStr(FileGetAttrib($sFile), 'D') <> 0 Then
        If $sRecurse Then
            RunWait(@ComSpec & ' /c takeown /f "' & $sFile & '" /R /D Y', '', @SW_HIDE)
            If $iUserName <> 'Administrators' Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /T /C /G Administrators:F', '', @SW_HIDE)
            If $iUserName <> 'Users' Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /T /C /G Users:F', '', @SW_HIDE)
            RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /T /C /G ' & $iUserName & ':F', '', @SW_HIDE)
            If $osNotIsEnglish Then
                If ($iUserName = "Everyone") Then $iUserName = '*S-1-1-0'
                If ($iUserName = '"' & 'Authenticated Users' & '"') Then $iUserName = '*S-1-5-11'
            EndIf
            If $iUserName <> 'Administrators' Then RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant Administrators:F /T /C /Q', '', @SW_HIDE)
            If $iUserName <> 'Users' Then RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant Users:F /T /C /Q', '', @SW_HIDE)
            RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant ' & $iUserName & ':F /T /C /Q', '', @SW_HIDE)
            Return SetError(0, 0, FileSetAttrib($sFile, "-RHS", 1))
        Else
            RunWait(@ComSpec & ' /c takeown /f "' & $sFile & '" ', '', @SW_HIDE)
            If $iUserName <> 'Administrators' Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /C /G Administrators:F', '', @SW_HIDE)
            If $iUserName <> 'Users' Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /C /G Users:F', '', @SW_HIDE)
            RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /C /G ' & $iUserName & ':F', '', @SW_HIDE)
            If $osNotIsEnglish Then
                If ($iUserName = "Everyone") Then $iUserName = '*S-1-1-0'
                If ($iUserName = '"' & 'Authenticated Users' & '"') Then $iUserName = '*S-1-5-11'
            EndIf
            If $iUserName <> 'Administrators' Then RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant Administrators:F /C /Q', '', @SW_HIDE)
            If $iUserName <> 'Users' Then RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant Users:F /C /Q', '', @SW_HIDE)
            RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant ' & $iUserName & ':F /C /Q', '', @SW_HIDE)
            Return SetError(0, 0, FileSetAttrib($sFile, "-RHS", 0))
        EndIf
    Else
        RunWait(@ComSpec & ' /c takeown /f "' & $sFile & '"', '', @SW_HIDE)
        If $iUserName <> 'Administrators' Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /C /G Administrators:F', '', @SW_HIDE)
        If $iUserName <> 'Users' Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /C /G Users:F', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /C /G ' & $iUserName & ':F', '', @SW_HIDE)
        If $osNotIsEnglish Then
            If ($iUserName = "Everyone") Then $iUserName = '*S-1-1-0'
            If ($iUserName = '"' & 'Authenticated Users' & '"') Then $iUserName = '*S-1-5-11'
        EndIf
        If $iUserName <> 'Administrators' Then RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant Administrators:F /Q', '', @SW_HIDE)
        If $iUserName <> 'Users' Then RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant Users:F /Q', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant ' & $iUserName & ':F /Q', '', @SW_HIDE)
        Return SetError(0, 0, FileSetAttrib($sFile, "-RHS"))
    EndIf
    Return $sFile
EndFunc   ;==>_TakeOwnership
Func _URL_Split($sURL_Input, ByRef $sURL_Protocol, ByRef $sURL_Domain, ByRef $sURL_FilePATH, ByRef $sURL_FileName)
    Local $sURL_Protocol_Number_Pattern = '^(?s)(?i)(http|ftp|sftp|ftps|https|file)://(.*?/|.*$)(.*/){0,}(.*)$'
    Local $sURL_Pattern = "^(?i)(?:(?:[a-z]+):\/\/)?" & "(?:(?:(?:[^@:]+))" & "(?::(?:[^@]+))?@)?" & "([^\/:]+)" & "(?::(?:\d+))?" & "(?:\/(?:[^?]+)?)?" & "(?:\?\N+)?"
    Local $aURL_Pattern = StringRegExp($sURL_Input, $sURL_Protocol_Number_Pattern, 2)
    If Not IsArray($aURL_Pattern) Or UBound($aURL_Pattern) - 1 <> 4 Then Return SetError(1, 0, 0)
    If StringRight($aURL_Pattern[2], 1) = '/' Then
        $aURL_Pattern[2] = StringTrimRight($aURL_Pattern[2], 1)
        $aURL_Pattern[3] = '/' & $aURL_Pattern[3]
    EndIf
    $sURL_Protocol = $aURL_Pattern[1]
    Local $aHost = StringRegExp($sURL_Input, $sURL_Pattern, 1)
    If Not @error And IsArray($aHost) Then
        $sURL_Domain = $aHost[0]
    Else
        $sURL_Domain = $aURL_Pattern[2]
    EndIf
    $sURL_FilePATH = $aURL_Pattern[3]
    $sURL_FileName = $aURL_Pattern[4]
    Return $aURL_Pattern
EndFunc   ;==>_URL_Split
#cs
    Local $sURL_Protocol, $sURL_Protocol_Number, $sURL_Domain, $sURL_Port, $sURL_User, $sURL_Password, $sURL_FilePathName, $sURL_FilePATH, $sURL_FileName
    _WinHttp_SplitURL($sURL_Input, $sURL_Protocol, $sURL_Domain, $sURL_Port, $sURL_User, $sURL_Password, $sURL_FilePathName, $sURL_FilePATH, $sURL_FileName)
    ConsoleWrite("! URL_Input   : " & $sURL_Input & @CRLF)
    ConsoleWrite("- Protocol    : " & $sURL_Protocol & @CRLF)
    ConsoleWrite("- Domain      : " & $sURL_Domain & @CRLF)
    ConsoleWrite("- Port        : " & $sURL_Port & @CRLF)
    ConsoleWrite("- User        : " & $sURL_User & @CRLF)
    ConsoleWrite("- Password    : " & $sURL_Password & @CRLF)
    ConsoleWrite("- FilePathName: " & $sURL_FilePathName & @CRLF)
    ConsoleWrite("- FilePath    : " & $sURL_FilePath & @CRLF)
    ConsoleWrite("- FileName    : " & $sURL_FileName & @CRLF)
#ce
Func _WinHttp_SplitURL($sURL_Input, ByRef $sURL_Protocol, ByRef $sURL_Domain, ByRef $sURL_Port, ByRef $sURL_User, ByRef $sURL_Password, ByRef $sURL_FilePathName, ByRef $sURL_FilePATH, ByRef $sURL_FileName)
    If StringStripWS($sURL_Input, 8) = '' Then Return SetError(1, 0, 0)
    $sURL_Input = StringReplace($sURL_Input, "\", "/")
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'http://' & $sURL_Input
    _URL_Split($sURL_Input, $sURL_Protocol, $sURL_Domain, $sURL_FilePATH, $sURL_FileName)
    StringReplace($sURL_Input, '@', '')
    If @extended > 1 Then
        Local $sUser, $aUser = _StringBetween($sURL_Input, $sURL_Protocol & "://", '@')
        If IsArray($aUser) Then
            $sUser = $aUser[0]
            $sURL_Input = StringReplace($sURL_Input, $sURL_Protocol & "://" & $sUser & '@', $sURL_Protocol & "://" & $sUser & '%40')
        EndIf
    EndIf
    Local $ORG_URL_Protocol = $sURL_Protocol, $sFake_Protocol = 'http', $iFake_Protocol = False
    Switch $sURL_Protocol
        Case 'http', 'https', 'ftp'
        Case Else
            $iFake_Protocol = True
            $sURL_Input = StringReplace($sURL_Input, $sURL_Protocol & "://", $sFake_Protocol & "://")
    EndSwitch
    Local $aUrl = _WinHttpCrackUrl($sURL_Input)
    If IsArray($aUrl) Then
        If $iFake_Protocol Then
            $sURL_Protocol = $ORG_URL_Protocol
        Else
            $sURL_Protocol = ($aUrl[0] == '' ? $sURL_Protocol : $aUrl[0])
        EndIf
        ;$sURL_Protocol_Number = $aUrl[1]
        $sURL_Domain = ($aUrl[2] == '' ? $sURL_Domain : $aUrl[2])
        $sURL_Port = $aUrl[3]
        $sURL_User = StringReplace($aUrl[4], '%40', '@')
        $sURL_Password = $aUrl[5]
        $sURL_FilePathName = ($aUrl[6] == '' ? $sURL_FilePATH & $sURL_FileName : $aUrl[6])
        ;$sURL_ExtraInfo = $aUrl[7]
        Return $aUrl
    EndIf
    Return SetError(1, 0, "")
EndFunc   ;==>_WinHttp_SplitURL

Func _WinHTTP_GetName_ErrorCode($nErrorCode = 0)
    ; By Dao Van Trong - TRONG.LIVE
    Switch $nErrorCode
        Case 12001
            Return "ERROR_WINHTTP_OUT_OF_HANDLES"
        Case 12002
            Return "ERROR_WINHTTP_TIMEOUT"
        Case 12004
            Return "ERROR_WINHTTP_INTERNAL_ERROR"
        Case 12005
            Return "ERROR_WINHTTP_INVALID_URL"
        Case 12006
            Return "ERROR_WINHTTP_UNRECOGNIZED_SCHEME"
        Case 12007
            Return "ERROR_WINHTTP_NAME_NOT_RESOLVED"
        Case 12009
            Return "ERROR_WINHTTP_INVALID_OPTION"
        Case 12011
            Return "ERROR_WINHTTP_OPTION_NOT_SETTABLE"
        Case 12012
            Return "ERROR_WINHTTP_SHUTDOWN"
        Case 12015
            Return "ERROR_WINHTTP_LOGIN_FAILURE"
        Case 12017
            Return "ERROR_WINHTTP_OPERATION_CANCELLED"
        Case 12018
            Return "ERROR_WINHTTP_INCORRECT_HANDLE_TYPE"
        Case 12019
            Return "ERROR_WINHTTP_INCORRECT_HANDLE_STATE"
        Case 12029
            Return "ERROR_WINHTTP_CANNOT_CONNECT"
        Case 12030
            Return "ERROR_WINHTTP_CONNECTION_ERROR"
        Case 12032
            Return "ERROR_WINHTTP_RESEND_REQUEST"
        Case 12044
            Return "ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED"
        Case 12150
            Return "ERROR_WINHTTP_HEADER_NOT_FOUND"
        Case 12152
            Return "ERROR_WINHTTP_INVALID_SERVER_RESPONSE"
        Case 12153
            Return "ERROR_WINHTTP_INVALID_HEADER"
        Case 12154
            Return "ERROR_WINHTTP_INVALID_QUERY_REQUEST"
        Case 12155
            Return "ERROR_WINHTTP_HEADER_ALREADY_EXISTS"
        Case 12156
            Return "ERROR_WINHTTP_REDIRECT_FAILED"
        Case 12178
            Return "ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR"
        Case 12166
            Return "ERROR_WINHTTP_BAD_AUTO_PROXY_SCRIPT"
        Case 12167
            Return "ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT"
        Case 12176
            Return "ERROR_WINHTTP_UNHANDLED_SCRIPT_TYPE"
        Case 12177
            Return "ERROR_WINHTTP_SCRIPT_EXECUTION_ERROR"
        Case 12172
            Return "ERROR_WINHTTP_NOT_INITIALIZED"
        Case 12175
            Return "ERROR_WINHTTP_SECURE_FAILURE"
        Case 12037
            Return "ERROR_WINHTTP_SECURE_CERT_DATE_INVALID"
        Case 12038
            Return "ERROR_WINHTTP_SECURE_CERT_CN_INVALID"
        Case 12045
            Return "ERROR_WINHTTP_SECURE_INVALID_CA"
        Case 12057
            Return "ERROR_WINHTTP_SECURE_CERT_REV_FAILED"
        Case 12157
            Return "ERROR_WINHTTP_SECURE_CHANNEL_ERROR"
        Case 12169
            Return "ERROR_WINHTTP_SECURE_INVALID_CERT"
        Case 12170
            Return "ERROR_WINHTTP_SECURE_CERT_REVOKED"
        Case 12179
            Return "ERROR_WINHTTP_SECURE_CERT_WRONG_USAGE"
        Case 12180
            Return "ERROR_WINHTTP_AUTODETECTION_FAILED"
        Case 12181
            Return "ERROR_WINHTTP_HEADER_COUNT_EXCEEDED"
        Case 12182
            Return "ERROR_WINHTTP_HEADER_SIZE_OVERFLOW"
        Case 12183
            Return "ERROR_WINHTTP_CHUNKED_ENCODING_HEADER_SIZE_OVERFLOW"
        Case 12184
            Return "ERROR_WINHTTP_RESPONSE_DRAIN_OVERFLOW"
        Case 12185
            Return "ERROR_WINHTTP_CLIENT_CERT_NO_PRIVATE_KEY"
        Case 12186
            Return "ERROR_WINHTTP_CLIENT_CERT_NO_ACCESS_PRIVATE_KEY"
        Case 12187
            Return "ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED_PROXY"
        Case 12188
            Return "ERROR_WINHTTP_SECURE_FAILURE_PROXY"
        Case 12189
            Return "ERROR_WINHTTP_RESERVED_189"
        Case 12190
            Return "ERROR_WINHTTP_HTTP_PROTOCOL_MISMATCH"
        Case 12191
            Return "ERROR_WINHTTP_GLOBAL_CALLBACK_FAILED"
        Case 12192
            Return "ERROR_WINHTTP_FEATURE_DISABLED"
            Return "WINHTTP_ERROR_LAST"
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
EndFunc   ;==>_WinHTTP_GetName_ErrorCode

Func _WinInet_GetName_ErrorCode($nErrorCode = 0)
    ; By Dao Van Trong - TRONG.LIVE
    Switch $nErrorCode
        Case 12000
            Return "INTERNET_ERROR_BASE"
        Case 12001
            Return "ERROR_INTERNET_OUT_OF_HANDLES"
        Case 12002
            Return "ERROR_INTERNET_TIMEOUT"
        Case 12003
            Return "ERROR_INTERNET_EXTENDED_ERROR"
        Case 12004
            Return "ERROR_INTERNET_INTERNAL_ERROR"
        Case 12005
            Return "ERROR_INTERNET_INVALID_URL"
        Case 12006
            Return "ERROR_INTERNET_UNRECOGNIZED_SCHEME"
        Case 12007
            Return "ERROR_INTERNET_NAME_NOT_RESOLVED"
        Case 12008
            Return "ERROR_INTERNET_PROTOCOL_NOT_FOUND"
        Case 12009
            Return "ERROR_INTERNET_INVALID_OPTION"
        Case 12010
            Return "ERROR_INTERNET_BAD_OPTION_LENGTH"
        Case 12011
            Return "ERROR_INTERNET_OPTION_NOT_SETTABLE"
        Case 12012
            Return "ERROR_INTERNET_SHUTDOWN"
        Case 12013
            Return "ERROR_INTERNET_INCORRECT_USER_NAME"
        Case 12014
            Return "ERROR_INTERNET_INCORRECT_PASSWORD"
        Case 12015
            Return "ERROR_INTERNET_LOGIN_FAILURE"
        Case 12016
            Return "ERROR_INTERNET_INVALID_OPERATION"
        Case 12017
            Return "ERROR_INTERNET_OPERATION_CANCELLED"
        Case 12018
            Return "ERROR_INTERNET_INCORRECT_HANDLE_TYPE"
        Case 12019
            Return "ERROR_INTERNET_INCORRECT_HANDLE_STATE"
        Case 12020
            Return "ERROR_INTERNET_NOT_PROXY_REQUEST"
        Case 12021
            Return "ERROR_INTERNET_REGISTRY_VALUE_NOT_FOUND"
        Case 12022
            Return "ERROR_INTERNET_BAD_REGISTRY_PARAMETER"
        Case 12023
            Return "ERROR_INTERNET_NO_DIRECT_ACCESS"
        Case 12024
            Return "ERROR_INTERNET_NO_CONTEXT"
        Case 12025
            Return "ERROR_INTERNET_NO_CALLBACK"
        Case 12026
            Return "ERROR_INTERNET_REQUEST_PENDING"
        Case 12027
            Return "ERROR_INTERNET_INCORRECT_FORMAT"
        Case 12028
            Return "ERROR_INTERNET_ITEM_NOT_FOUND"
        Case 12029
            Return "ERROR_INTERNET_CANNOT_CONNECT"
        Case 12030
            Return "ERROR_INTERNET_CONNECTION_ABORTED"
        Case 12031
            Return "ERROR_INTERNET_CONNECTION_RESET"
        Case 12032
            Return "ERROR_INTERNET_FORCE_RETRY"
        Case 12033
            Return "ERROR_INTERNET_INVALID_PROXY_REQUEST"
        Case 12034
            Return "ERROR_INTERNET_NEED_UI"
        Case 12036
            Return "ERROR_INTERNET_HANDLE_EXISTS"
        Case 12037
            Return "ERROR_INTERNET_SEC_CERT_DATE_INVALID"
        Case 12038
            Return "ERROR_INTERNET_SEC_CERT_CN_INVALID"
        Case 12039
            Return "ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR"
        Case 12040
            Return "ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR"
        Case 12041
            Return "ERROR_INTERNET_MIXED_SECURITY"
        Case 12042
            Return "ERROR_INTERNET_CHG_POST_IS_NON_SECURE"
        Case 12043
            Return "ERROR_INTERNET_POST_IS_NON_SECURE"
        Case 12044
            Return "ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED"
        Case 12045
            Return "ERROR_INTERNET_INVALID_CA"
        Case 12046
            Return "ERROR_INTERNET_CLIENT_AUTH_NOT_SETUP"
        Case 12047
            Return "ERROR_INTERNET_ASYNC_THREAD_FAILED"
        Case 12048
            Return "ERROR_INTERNET_REDIRECT_SCHEME_CHANGE"
        Case 12049
            Return "ERROR_INTERNET_DIALOG_PENDING"
        Case 12050
            Return "ERROR_INTERNET_RETRY_DIALOG"
        Case 12052
            Return "ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR"
        Case 12053
            Return "ERROR_INTERNET_INSERT_CDROM"
        Case 12054
            Return "ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED"
        Case 12055
            Return "ERROR_INTERNET_SEC_CERT_ERRORS"
        Case 12056
            Return "ERROR_INTERNET_SEC_CERT_NO_REV"
        Case 12057
            Return "ERROR_INTERNET_SEC_CERT_REV_FAILED"
        Case 12060
            Return "ERROR_HTTP_HSTS_REDIRECT_REQUIRED"
        Case 12062
            Return "ERROR_INTERNET_SEC_CERT_WEAK_SIGNATURE"
        Case 12110
            Return "ERROR_FTP_TRANSFER_IN_PROGRESS"
        Case 12111
            Return "ERROR_FTP_DROPPED"
        Case 12112
            Return "ERROR_FTP_NO_PASSIVE_MODE"
        Case 12130
            Return "ERROR_GOPHER_PROTOCOL_ERROR"
        Case 12131
            Return "ERROR_GOPHER_NOT_FILE"
        Case 12132
            Return "ERROR_GOPHER_DATA_ERROR"
        Case 12133
            Return "ERROR_GOPHER_END_OF_DATA"
        Case 12134
            Return "ERROR_GOPHER_INVALID_LOCATOR"
        Case 12135
            Return "ERROR_GOPHER_INCORRECT_LOCATOR_TYPE"
        Case 12136
            Return "ERROR_GOPHER_NOT_GOPHER_PLUS"
        Case 12137
            Return "ERROR_GOPHER_ATTRIBUTE_NOT_FOUND"
        Case 12138
            Return "ERROR_GOPHER_UNKNOWN_LOCATOR"
        Case 12150
            Return "ERROR_HTTP_HEADER_NOT_FOUND"
        Case 12151
            Return "ERROR_HTTP_DOWNLEVEL_SERVER"
        Case 12152
            Return "ERROR_HTTP_INVALID_SERVER_RESPONSE"
        Case 12153
            Return "ERROR_HTTP_INVALID_HEADER"
        Case 12154
            Return "ERROR_HTTP_INVALID_QUERY_REQUEST"
        Case 12155
            Return "ERROR_HTTP_HEADER_ALREADY_EXISTS"
        Case 12156
            Return "ERROR_HTTP_REDIRECT_FAILED"
        Case 12160
            Return "ERROR_HTTP_NOT_REDIRECTED"
        Case 12161
            Return "ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION"
        Case 12162
            Return "ERROR_HTTP_COOKIE_DECLINED"
        Case 12168
            Return "ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION"
        Case 12157
            Return "ERROR_INTERNET_SECURITY_CHANNEL_ERROR"
        Case 12158
            Return "ERROR_INTERNET_UNABLE_TO_CACHE_FILE"
        Case 12159
            Return "ERROR_INTERNET_TCPIP_NOT_INSTALLED"
        Case 12163
            Return "ERROR_INTERNET_DISCONNECTED"
            Return "ERROR_INTERNET_OFFLINE"
        Case 12164
            Return "ERROR_INTERNET_SERVER_UNREACHABLE"
        Case 12165
            Return "ERROR_INTERNET_PROXY_SERVER_UNREACHABLE"
        Case 12166
            Return "ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT"
        Case 12167
            Return "ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT"
        Case 12169
            Return "ERROR_INTERNET_SEC_INVALID_CERT"
        Case 12170
            Return "ERROR_INTERNET_SEC_CERT_REVOKED"
        Case 12171
            Return "ERROR_INTERNET_FAILED_DUETOSECURITYCHECK"
        Case 12172
            Return "ERROR_INTERNET_NOT_INITIALIZED"
        Case 12173
            Return "ERROR_INTERNET_NEED_MSN_SSPI_PKG"
        Case 12174
            Return "ERROR_INTERNET_LOGIN_FAILURE_DISPLAY_ENTITY_BODY"
        Case 12175
            Return "ERROR_INTERNET_DECODING_FAILED"
        Case 12187
            Return "ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED_PROXY"
        Case 12188
            Return "ERROR_INTERNET_SECURE_FAILURE_PROXY"
        Case 12190
            Return "ERROR_INTERNET_HTTP_PROTOCOL_MISMATCH"
        Case 12191
            Return "ERROR_INTERNET_GLOBAL_CALLBACK_FAILED"
        Case 12192
            Return "ERROR_INTERNET_FEATURE_DISABLED"
            Return "INTERNET_ERROR_LAST"
        Case 12051
            Return "ERROR_INTERNET_NO_NEW_CONTAINERS"
        Case 12058
            Return "ERROR_INTERNET_SOURCE_PORT_IN_USE"
        Case 12059
            Return "ERROR_INTERNET_INSECURE_FALLBACK_REQUIRED"
        Case 12061
            Return "ERROR_INTERNET_PROXY_ALERT"
        Case 12080
            Return "ERROR_INTERNET_NO_CM_CONNECTION"
        Case 12147
            Return "ERROR_HTTP_PUSH_STATUS_CODE_NOT_SUPPORTED"
        Case 12148
            Return "ERROR_HTTP_PUSH_RETRY_NOT_SUPPORTED"
        Case 12149
            Return "ERROR_HTTP_PUSH_ENABLE_FAILED"
        Case 12189
            Return "ERROR_INTERNET_DISALLOW_INPRIVATE"
        Case 12900
            Return "INTERNET_INTERNAL_ERROR_BASE"
        Case 12901
            Return "ERROR_INTERNET_INTERNAL_SOCKET_ERROR"
        Case 12902
            Return "ERROR_INTERNET_CONNECTION_AVAILABLE"
        Case 12903
            Return "ERROR_INTERNET_NO_KNOWN_SERVERS"
        Case 12904
            Return "ERROR_INTERNET_PING_FAILED"
        Case 12905
            Return "ERROR_INTERNET_NO_PING_SUPPORT"
        Case 12906
            Return "ERROR_INTERNET_CACHE_SUCCESS"
        Case 12907
            Return "ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION_EX"
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
EndFunc   ;==>_WinInet_GetName_ErrorCode

If you do not have a WinHTTP UDF ("WinHttp.au3"), download it here: https://github.com/dragana-r/autoit-winhttp

 

Standalone  code:

Global $__g_hWinInet_FTP = -1, $__g_hCallback_FTP, $__g_bCallback_FTP = False
Global Const $STR_REGEXPARRAYGLOBALMATCH = 3, $STR_ENDISSTART = 0, $STR_ENDNOTSTART = 1, $FO_OVERWRITE = 2, $FO_BINARY = 16, $OPEN_EXISTING = 3, $FILE_SHARE_READ = 0x00000001, $FILE_SHARE_WRITE = 0x00000002, $FILE_SHARE_DELETE = 0x00000004, $GENERIC_WRITE = 0x40000000, $GENERIC_READ = 0x80000000, $INTERNET_OPEN_TYPE_DIRECT = 1, $FTP_TRANSFER_TYPE_UNKNOWN = 0, $FTP_TRANSFER_TYPE_BINARY = 2, $INTERNET_FLAG_DEFAULT = 0, $INTERNET_FLAG_PASSIVE = 0x08000000, $INTERNET_FLAG_TRANSFER_BINARY = 2, $INTERNET_SERVICE_FTP = 1, $INTERNET_FLAG_NO_CACHE_WRITE = 0x04000000, $INET_DOWNLOADCOMPLETE = 2, $INET_DOWNLOADSUCCESS = 3, $INTERNET_DEFAULT_PORT = 0, $ICU_ESCAPE = 0x80000000, $FILE_FLAG_BACKUP_SEMANTICS = 0x02000000, $WINHTTP_FLAG_ASYNC = 0x10000000, $WINHTTP_FLAG_ESCAPE_DISABLE = 0x00000040, $WINHTTP_FLAG_SECURE = 0x00800000, $WINHTTP_ACCESS_TYPE_NO_PROXY = 1, $WINHTTP_NO_PROXY_NAME = "", $WINHTTP_NO_PROXY_BYPASS = "", $WINHTTP_NO_REFERER = "", $WINHTTP_DEFAULT_ACCEPT_TYPES = 0, $WINHTTP_NO_ADDITIONAL_HEADERS = "", $WINHTTP_NO_REQUEST_DATA = "", $WINHTTP_HEADER_NAME_BY_INDEX = "", $WINHTTP_NO_HEADER_INDEX = 0, $WINHTTP_OPTION_CALLBACK = 1, $WINHTTP_OPTION_RESOLVE_TIMEOUT = 2, $WINHTTP_OPTION_CONNECT_TIMEOUT = 3, $WINHTTP_OPTION_CONNECT_RETRIES = 4, $WINHTTP_OPTION_SEND_TIMEOUT = 5, $WINHTTP_OPTION_RECEIVE_TIMEOUT = 6, $WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT = 7, $WINHTTP_OPTION_HANDLE_TYPE = 9, $WINHTTP_OPTION_READ_BUFFER_SIZE = 12, $WINHTTP_OPTION_WRITE_BUFFER_SIZE = 13, $WINHTTP_OPTION_PARENT_HANDLE = 21, $WINHTTP_OPTION_EXTENDED_ERROR = 24, $WINHTTP_OPTION_SECURITY_FLAGS = 31, $WINHTTP_OPTION_URL = 34, $WINHTTP_OPTION_SECURITY_KEY_BITNESS = 36, $WINHTTP_OPTION_PROXY = 38, $WINHTTP_OPTION_USER_AGENT = 41, $WINHTTP_OPTION_CONTEXT_VALUE = 45, $WINHTTP_OPTION_CLIENT_CERT_CONTEXT = 47, $WINHTTP_OPTION_REQUEST_PRIORITY = 58, $WINHTTP_OPTION_HTTP_VERSION = 59, $WINHTTP_OPTION_DISABLE_FEATURE = 63, $WINHTTP_OPTION_CODEPAGE = 68, $WINHTTP_OPTION_MAX_CONNS_PER_SERVER = 73, $WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER = 74, $WINHTTP_OPTION_AUTOLOGON_POLICY = 77, $WINHTTP_OPTION_SERVER_CERT_CONTEXT = 78, $WINHTTP_OPTION_ENABLE_FEATURE = 79, $WINHTTP_OPTION_WORKER_THREAD_COUNT = 80, $WINHTTP_OPTION_PASSPORT_COBRANDING_TEXT = 81, $WINHTTP_OPTION_PASSPORT_COBRANDING_URL = 82, $WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH = 83, $WINHTTP_OPTION_SECURE_PROTOCOLS = 84, $WINHTTP_OPTION_ENABLETRACING = 85, $WINHTTP_OPTION_PASSPORT_SIGN_OUT = 86, $WINHTTP_OPTION_REDIRECT_POLICY = 88, $WINHTTP_OPTION_MAX_HTTP_AUTOMATIC_REDIRECTS = 89, $WINHTTP_OPTION_MAX_HTTP_STATUS_CONTINUE = 90, $WINHTTP_OPTION_MAX_RESPONSE_HEADER_SIZE = 91, $WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE = 92, $WINHTTP_OPTION_CONNECTION_INFO = 93, $WINHTTP_OPTION_SPN = 96, $WINHTTP_OPTION_GLOBAL_PROXY_CREDS = 97, $WINHTTP_OPTION_GLOBAL_SERVER_CREDS = 98, $WINHTTP_OPTION_REJECT_USERPWD_IN_URL = 100, $WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS = 101, $WINHTTP_OPTION_UNSAFE_HEADER_PARSING = 110, $WINHTTP_OPTION_DECOMPRESSION = 118, $WINHTTP_OPTION_USERNAME = 0x1000, $WINHTTP_OPTION_PASSWORD = 0x1001, $WINHTTP_OPTION_PROXY_USERNAME = 0x1002, $WINHTTP_OPTION_PROXY_PASSWORD = 0x1003, $WINHTTP_DECOMPRESSION_FLAG_ALL = 0x00000003, $WINHTTP_AUTOLOGON_SECURITY_LEVEL_MEDIUM = 0, $WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW = 1, $WINHTTP_AUTOLOGON_SECURITY_LEVEL_HIGH = 2, $WINHTTP_ENABLE_PASSPORT_AUTH = 0x10000000, $HTTP_STATUS_DENIED = 401, $HTTP_STATUS_PROXY_AUTH_REQ = 407, $SECURITY_FLAG_IGNORE_UNKNOWN_CA = 0x00000100, $SECURITY_FLAG_IGNORE_CERT_DATE_INVALID = 0x00002000, $SECURITY_FLAG_IGNORE_CERT_CN_INVALID = 0x00001000, $SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE = 0x00000200, $WINHTTP_QUERY_CONTENT_TYPE = 1, $WINHTTP_QUERY_STATUS_CODE = 19, $WINHTTP_QUERY_RAW_HEADERS_CRLF = 22, $WINHTTP_AUTH_SCHEME_BASIC = 0x00000001, $WINHTTP_AUTH_SCHEME_PASSPORT = 0x00000004, $WINHTTP_AUTH_TARGET_SERVER = 0x00000000
Global Const $hWINHTTPDLL__WINHTTP = DllOpen("winhttp.dll")
DllOpen("winhttp.dll")

;Opt("MustDeclareVars", 1)
Opt("TrayAutoPause", 0)
If StringInStr(@OSArch, "64") And (Not @AutoItX64) Then _WinAPI_Wow64EnableWow64FsRedirection(0)
; #CONSTANTS# ===================================================================================================================
Global Const $ViewLogConsole = 1, $bGetFieSize = 1
Global Const $OPTION_ENABLE_REDIRECTS = 6, $OPTION_USER_AGENT = 0
Global $obError = False, $oErrorHandler = ObjEvent("AutoIt.Error", "__Skip_OBJ_Error")
Global $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
Global $sUSER_AGENT = __WinHttpUA(), $TempDir = @TempDir
If Not _Directory_Is_Accessible($TempDir) Then
    $TempDir = @LocalAppDataDir & "\Temp"
    If Not _Directory_Is_Accessible($TempDir) Then $TempDir = @ScriptDir
EndIf
; ===========================================================================================


; Example
Global $ftpUserName = "ftpuser@files.trong.live"
Global $ftpPassword = "files.trong.live"

Global $httpUserName = 'trong'
Global $httpPassword = 'autoit'

_Download('https://files.trong.live/test.jpg', @ScriptDir & "\testA.jpg")
_Download('https://files.trong.live/prv/test.jpg', @ScriptDir & "\testA.jpg", $httpUserName, $httpPassword)
_FTP_Download('ftp://files.trong.live/prv/test.jpg', @ScriptDir & "\testB.jpg", $ftpUserName, $ftpPassword)
_Download('https://go.microsoft.com/fwlink/?LinkID=2093505', @ScriptDir & "\Microsoft_Edge_Ent_X86.msi")
_WinHttp_Download('http://go.microsoft.com/fwlink/?LinkID=2093437', @ScriptDir & "\Microsoft_Edge_Ent_X64.msi")



; #CURRENT# =====================================================================================================================
; _Download()
; _FTP_Download()
; _WinHttp_Download()
; ===============================================================================================================================

; #FUNCTION# ====================================================================================================================
; Author... ...........: Dao Van Trong  - TRONG.LIVE
; ===========================================================================================
Func _Download($sURL_Input, $sLocalPathSAVE, $dUserName = "anonymous", $dPassword = "")
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    $sURL_Input = StringReplace($sURL_Input, "\", "/")
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'http://' & $sURL_Input
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    If ($dProtocol = "ftp" Or $dProtocol = "sftp" Or $dProtocol = "ftps") Then
        Local $fDL = _FTP_Download($sURL_Input, $sLocalPathSAVE, $dUserName, $dPassword)
        Return SetError(@error, @extended, $fDL)
    EndIf
    If (($dUserName = Default) Or (StringStripWS($dUserName, 8) == "") Or (StringLower($dUserName) == "anonymous")) Then $dUserName = ""
    If ((StringLower($dUserName) == "anonymous") Or ($dUserName == "") And (StringLen(StringStripWS($dUser, 8)) > 1)) Then
        $dUserName = $dUser
        If (($dPassword == "") And (StringLen($dPass) > 1)) Then $dPassword = $dPass
    EndIf
    If (Not ($dUserName == '')) Then
        ;$dUserName = StringReplace($dUserName, '@', '%40')
        If ($dProtocol == 'https' And $dPort <> 443) Or ($dProtocol == 'http' And $dPort <> 80) Then
            $sURL_Input = $dProtocol & "://" & $dUserName & ":" & $dPassword & "@" & $dDomain & ":" & $dPort & $dURLFilePathName
        Else
            $sURL_Input = $dProtocol & "://" & $dUserName & ":" & $dPassword & "@" & $dDomain & $dURLFilePathName
        EndIf
    EndIf
    _LogDebug("- InetGet Download: " & $sURL_Input & " -> " & $sLocalPathSAVE & @CRLF)
    Local $dlTempFilePath
    While 1
        $dlTempFilePath = $TempDir & "\~download-" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & "-" & Random(88888888, 99999999, 1) & ".tmp"
        If (Not FileExists($dlTempFilePath)) Then ExitLoop
    WEnd
    $dUserName = StringReplace($dUserName, '%40', '@')
    Local $sURL_Rediect
    Local $urlStatus = __URL_Check($sURL_Input, $sURL_Rediect, $dUserName, $dPassword)
    If @error Then
        _LogDebug("! /!\ Test connect Error ! " & @CRLF)
        Return 0
    EndIf
    If ($sURL_Rediect == "") Then
    Else
        $sURL_Input = $sURL_Rediect
    EndIf
    HttpSetUserAgent($sUSER_AGENT)
    If $bGetFieSize Then
        _LogDebug("+ Get file size.... ")
        $dFileSize = InetGetSize($sURL_Input)
        If @error Then
            _LogDebug("  ERROR  !" & @CRLF)
        Else
            _LogDebug("  OK  ->  " & _Byte_GetDisplay($dFileSize) & "  " & @CRLF)
        EndIf
    EndIf
    _LogDebug("+ Downloading.... ")
    Local $hDownload = InetGet($sURL_Input, $dlTempFilePath, 1 + 2 + 16, 1)
    Local $Percentage = 0, $Old_Percentage = 0, $TotalToDownload = 0, $BytesDownloaded = 0, $DownloadedSoFar = 0, $pCheck = 0
    Do
        Sleep(100)
        If $dFileSize > 0 Then
            ; Get number of bytes read for current file
            $BytesDownloaded = InetGetInfo($hDownload, 0)
            ; Add this to the cumulative total
            $DownloadedSoFar = $TotalToDownload + $BytesDownloaded
            ; Calculate the current file percentage
            $Percentage = Floor(($BytesDownloaded / $dFileSize) * 100)
            ; Only update the current file percent label if it has changed to avoid flickering
            If ($Percentage - $Old_Percentage) > 4 Then
                _LogDebug($Percentage & "% ")
                $Old_Percentage = $Percentage
            EndIf
        EndIf
    Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
    ; Retrieve the number of total bytes received and the filesize.
    ;Local $iBytesSize = InetGetInfo($hDownload, $INET_DOWNLOADREAD)
    ;Local $iFileSize = FileGetSize($dlTempFilePath)
    ;ConsoleWrite("- Downloaded: " & $iBytesSize & " KB/s " & @CRLF)
    ;ConsoleWrite("- File Size: " & $iFileSize & " KB/s " & @CRLF)
    Local $aDownloadData = InetGetInfo($hDownload)
    InetClose($hDownload)
    If ($aDownloadData[$INET_DOWNLOADSUCCESS] And FileExists($dlTempFilePath)) Then
        _LogDebug("- DONE !" & @CRLF)
        __File_SAVE($dlTempFilePath, $sLocalPathSAVE)
        If FileExists($sLocalPathSAVE) Then
            _LogDebug("+ Save file to: " & $sLocalPathSAVE & " OK !" & @CRLF)
        Else
            _LogDebug("! Save file to: " & $sLocalPathSAVE & " ERROR !" & @CRLF)
        EndIf
    Else
        _LogDebug(" ERROR " & @CRLF)
        _LogDebug("- Try Download again with WinHttp !" & @CRLF)
        Return _WinHttp_Download($sURL_Input, $sLocalPathSAVE)
    EndIf
EndFunc   ;==>_Download

Func _WinHttp_Download($sURL_Input, $sLocalPathSAVE, $dUserName = "anonymous", $dPassword = "")
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'http://' & $sURL_Input
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    If ($dProtocol = "ftp" Or $dProtocol = "sftp" Or $dProtocol = "ftps") Then
        Local $fDL = _FTP_Download($sURL_Input, $sLocalPathSAVE, $dUserName, $dPassword)
        Return SetError(@error, @extended, $fDL)
    EndIf
    If (($dUserName = Default) Or (StringStripWS($dUserName, 8) == "") Or (StringLower($dUserName) == "anonymous")) Then $dUserName = ""
    If ((StringLower($dUserName) == "anonymous") Or ($dUserName == "") And (StringLen(StringStripWS($dUser, 8)) > 1)) Then
        $dUserName = $dUser
        If (($dPassword == "") And (StringLen($dPass) > 1)) Then $dPassword = $dPass
    EndIf
    _LogDebug("+ WinHttp Download: " & $sURL_Input & " -> " & $sLocalPathSAVE & @CRLF)
    Local $sURL_Rediect
    Local $urlStatus = __URL_Check($sURL_Input, $sURL_Rediect, $dUserName, $dPassword)
    If @error Then
        _LogDebug("! /!\ Test connect Error ! " & @CRLF)
        Return 0
    EndIf
    If ($sURL_Rediect == "") Then
    Else
        $sURL_Input = $sURL_Rediect
    EndIf
    Local $dlTempFilePath
    While 1
        $dlTempFilePath = $TempDir & "\~download-" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & "-" & Random(88888888, 99999999, 1) & ".tmp"
        If (Not FileExists($dlTempFilePath)) Then ExitLoop
    WEnd
    ; Initialize and get session handle
    Local $hOpen = _WinHttpOpen()
    ; Set User-Agent string
    _WinHttpSetOption($hOpen, $WINHTTP_OPTION_USER_AGENT, $sUSER_AGENT)
    ; Get connection handle
    _LogDebug("- WinHttp Connecting ...")
    Local $hConnect = _WinHttpConnect($hOpen, $dDomain)
    If @error Then
        _LogDebug(" ERROR " & @error & @CRLF)
        Return SetError(1, 0, 0)
    EndIf
    _LogDebug(" OK" & @CRLF & "- WinHttp Downloading ...")
    ; SimpleSSL-request it...
    Local $vReturned
    If (($dProtocol = "https") Or ($dPort = 443)) Then
        $vReturned = _WinHttpSimpleSSLRequest($hConnect, "GET", $dURLFilePathName, $dProtocol & "://" & $dDomain, $WINHTTP_NO_REQUEST_DATA, $WINHTTP_NO_ADDITIONAL_HEADERS, False, 2, $dUserName, $dPassword)
    Else
        $vReturned = _WinHttpSimpleRequest($hConnect, "GET", $dURLFilePathName, $dProtocol & "://" & $dDomain, $WINHTTP_NO_REQUEST_DATA, $WINHTTP_NO_ADDITIONAL_HEADERS, False, 2, $dUserName, $dPassword)
    EndIf
    If @error Then
        _LogDebug("! Request ERROR " & @error & @CRLF)
        Return SetError(2, 0, 0)
    EndIf
    _LogDebug(" OK" & @CRLF & "- Saving to file ...")
    ; Close handles
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    If FileExists($sLocalPathSAVE) Then _DelIt($sLocalPathSAVE, 1)
    Local $iDirFile = _Path_Split($sLocalPathSAVE, 6)
    If Not FileExists($iDirFile) Then DirCreate($iDirFile)
    Local $DataLen = BinaryLen($vReturned)
    Local $hFile = FileOpen($sLocalPathSAVE, 2 + 8 + 16)
    FileWrite($hFile, $vReturned)
    FileClose($hFile)
    If FileExists($sLocalPathSAVE) Then
        _LogDebug(" OK (Size: " & _Byte_GetDisplay($DataLen) & ") file: " & $sLocalPathSAVE & @CRLF)
        Return 1
    Else
        _LogDebug(" ERROR (Size: " & _Byte_GetDisplay($DataLen) & ") file: " & $sLocalPathSAVE & @CRLF)
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>_WinHttp_Download

Func _FTP_Download($sURL_Input, $sLocalPathSAVE, $dUserName = "anonymous", $dPassword = "")
    _LogDebug("+ FTP Download: " & $sURL_Input & " -> " & $sLocalPathSAVE & @CRLF)
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'ftp://' & $sURL_Input
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    #cs
        ConsoleWrite("- Protocol    : " & $dProtocol & @CRLF)
        ConsoleWrite("- Domain      : " & $dDomain & @CRLF)
        ConsoleWrite("- Port        : " & $dPort & @CRLF)
        ConsoleWrite("- User        : " & $dUser & @CRLF)
        ConsoleWrite("- Password    : " & $dPass & @CRLF)
        ConsoleWrite("- FilePathName: " & $dURLFilePathName & @CRLF)
        ConsoleWrite("- FilePath    : " & $dURLFilePath & @CRLF)
        ConsoleWrite("- FileName    : " &$dURLFileName & @CRLF)
    #ce
    If (($dUserName = Default) Or (StringStripWS($dUserName, 8) == "")) Then $dUserName = "anonymous"
    If ((StringLower($dUserName) == "anonymous") Or ($dUserName == "") And (StringLen(StringStripWS($dUser, 8)) > 1)) Then
        $dUserName = $dUser
        If (($dPassword == "") And (StringLen($dPass) > 1)) Then $dPassword = $dPass
    EndIf
    Local $Err, $sFTP_Message, $iReturn = 0, $iError = 0
    Local $dlTempFilePath = $TempDir & "\~download.tmp"
    While 1
        $dlTempFilePath = $TempDir & "\~download-" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & "-" & Random(88888888, 99999999, 1) & ".tmp"
        If (Not FileExists($dlTempFilePath)) Then ExitLoop
    WEnd
    If $bGetFieSize Then
        _LogDebug("- FTP Getting the file size... " & @CRLF)
        $dFileSize = _Byte_GetDisplay(__FTP_FileGetSize($sURL_Input, $dUserName, $dPassword))
    EndIf
    ;_LogDebug("-Protocol: " & $dProtocol & @CRLF)
    ;_LogDebug("-Server: " & $dDomain & @CRLF)
    ;_LogDebug("-User: '" & $dUserName & "'" & @CRLF)
    ;_LogDebug("-Password: '" & $dPassword & "'" & @CRLF)
    ;_LogDebug("-RemoteFile: " & $dURLFilePathName & @CRLF)
    If $dFileSize > 0 Then
        _LogDebug("- File Size: " & $dFileSize & @CRLF)
    Else
        _LogDebug("! An error occurred, Getting the file size failed!" & @CRLF)
    EndIf
    _LogDebug("- FTP Getting the file ... " & @CRLF)
    Local $hOpen = _FTP_Open('FTP_Client', $INTERNET_OPEN_TYPE_DIRECT)
    If @error Then Return SetError(1, 0, 0)
    Local $hFTPSession = _FTP_Connect($hOpen, $dDomain, $dUserName, $dPassword)
    If @error Then
        Local $WinHTTP_Error_Return = @extended
        Local $WinHTTP_Error_Name = _WinHTTP_GetName_ErrorCode($WinHTTP_Error_Return)
        _LogDebug('! _FTP_Connect Error: ' & @error & " - Extended: " & $WinHTTP_Error_Return & @CRLF)
        _LogDebug('! WinHTTP Error: ' & $WinHTTP_Error_Name & @CRLF)
        If ($WinHTTP_Error_Return = 12029) Then _LogDebug('! Error: A connection with the server could not be established' & @CRLF)
        If ($WinHTTP_Error_Return = 12014) Then _LogDebug('! Error: The request to connect and log on to an FTP server could not be completed because the supplied password is incorrect.' & @CRLF)
        Return SetError(2, $WinHTTP_Error_Return, 0)
    EndIf
    If $bGetFieSize Then
        _LogDebug("- Downloading " & $dURLFilePathName & " (" & $dFileSize & ") " & " ..." & @CRLF)
    Else
        _LogDebug("- Downloading " & $dURLFilePathName & " ...")
    EndIf
    Local $fuFunctionToCall = __FTPGetFile_UpdateProgress
    Local $iFDL = _FTP_ProgressDownload($hFTPSession, $dlTempFilePath, $dURLFilePathName, $fuFunctionToCall)
    Local $iErr, $sFTP_Message
    If (Not FileExists($dlTempFilePath)) Then
        _FTP_GetLastResponseInfo($iErr, $sFTP_Message)
        _LogDebug('! ERROR ! Code: [' & $Err & '] FTP_Message: [' & @CRLF & $sFTP_Message & "]" & @CRLF)
        _FTP_Close($hFTPSession)
        _FTP_Close($hOpen)
        $hOpen = _FTP_Open('FTP_Client', $INTERNET_OPEN_TYPE_DIRECT)
        $hFTPSession = _FTP_Connect($hOpen, $dDomain, $dUserName, $dPassword)
        If @error Then
            Local $WinHTTP_Error_Return = @extended
            Local $WinHTTP_Error_Name = _WinHTTP_GetName_ErrorCode($WinHTTP_Error_Return)
            _LogDebug('! _FTP_Connect Error: ' & @error & " - Extended: " & $WinHTTP_Error_Return & @CRLF)
            _LogDebug('! WinHTTP Error: ' & $WinHTTP_Error_Name & @CRLF)
            If ($WinHTTP_Error_Return = 12029) Then _LogDebug('! Error: A connection with the server could not be established' & @CRLF)
            If ($WinHTTP_Error_Return = 12014) Then _LogDebug('! Error: The request to connect and log on to an FTP server could not be completed because the supplied password is incorrect.' & @CRLF)
            Return SetError(2, $WinHTTP_Error_Return, 0)
        EndIf
        $iFDL = _FTP_FileGet($hFTPSession, $dURLFilePathName, $dlTempFilePath, False, Default, $FTP_TRANSFER_TYPE_BINARY)
        If (Not FileExists($dlTempFilePath)) Then
            _FTP_GetLastResponseInfo($iErr, $sFTP_Message)
            _LogDebug('! ERROR ! Code: [' & $Err & '] FTP_Message: [' & @CRLF & $sFTP_Message & "]" & @CRLF)
            _FTP_Close($hFTPSession)
            _FTP_Close($hOpen)
            Return SetError(3, 0, 0)
        Else
            _LogDebug('+ OK !' & @CRLF)
        EndIf
    Else
        _LogDebug('+ OK !' & @CRLF)
    EndIf
    _FTP_Close($hFTPSession)
    _FTP_Close($hOpen)
    __File_SAVE($dlTempFilePath, $sLocalPathSAVE)
    If FileExists($sLocalPathSAVE) Then
        _LogDebug("+ Save file to: " & $sLocalPathSAVE & " OK !" & @CRLF)
        Return SetError(0, 0, 1)
    Else
        _LogDebug("! Save file to: " & $sLocalPathSAVE & " ERROR !" & @CRLF)
        Return SetError(4, 0, 0)
    EndIf
EndFunc   ;==>_FTP_Download

Func __FTPGetFile_UpdateProgress($iPercent)
    _LogDebug(" " & Int($iPercent) & "%" & ' ')
    ;If _IsPressed("77") Then Return 0 ; Abort on F8
    Return 1     ; 1 to continue Download
EndFunc   ;==>__FTPGetFile_UpdateProgress

Func __FTP_FileGetSize($sURL_Input, $dUserName = "anonymous", $dPassword = "")
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'ftp://' & $sURL_Input
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    If (($dUserName = Default) Or (StringStripWS($dUserName, 8) == "")) Then $dUserName = "anonymous"
    If ((StringLower($dUserName) == "anonymous") Or ($dUserName == "") And (StringLen(StringStripWS($dUser, 8)) > 1)) Then
        $dUserName = $dUser
        If (($dPassword == "") And (StringLen($dPass) > 1)) Then $dPassword = $dPass
    EndIf
    Local $hOpen = _FTP_Open('FTP_Client')
    If @error Then Return SetError(1, 0, "")
    Local $hConn = _FTP_Connect($hOpen, $dDomain, $dUserName, $dPassword)
    If @error Then
        Local $WinHTTP_Error_Return = @extended
        Local $WinHTTP_Error_Name = _WinHTTP_GetName_ErrorCode($WinHTTP_Error_Return)
        _LogDebug('! _FTP_Connect Error: ' & @error & " - Extended: " & $WinHTTP_Error_Return & @CRLF)
        _LogDebug('! WinHTTP Error: ' & $WinHTTP_Error_Name & @CRLF)
        If ($WinHTTP_Error_Return = 12029) Then _LogDebug('! Error: A connection with the server could not be established' & @CRLF)
        If ($WinHTTP_Error_Return = 12014) Then _LogDebug('! Error: The request to connect and log on to an FTP server could not be completed because the supplied password is incorrect.' & @CRLF)
        Return SetError(2, $WinHTTP_Error_Return, 0)
    EndIf
    Local $iFileSize = _FTP_FileGetSize($hConn, $dURLFilePathName)
    If @error Then Return SetError(3, 0, "")
    ;ConsoleWrite('$sFilenameNext1 = ' & $dFileName & ' size = ' & $iFileSize & '  -> Error code: ' & @error & ' extended: ' & @extended & @CRLF)
    Local $iErr, $sMessage
    Local $iFtpr = _FTP_GetLastResponseInfo($iErr, $sMessage) ; no error
    ;ConsoleWrite('$sMessage = ' & $sMessage & ' err = ' & $iErr & '  -> Error code: ' & @error & ' extended: ' & @extended & @CRLF)
    Local $iFtpc = _FTP_Close($hConn)
    Local $iFtpo = _FTP_Close($hOpen)
    Return $iFileSize
EndFunc   ;==>__FTP_FileGetSize

Func __File_SAVE($dlTempFilePath, $sLocalPathSAVE)
    If Not FileExists($dlTempFilePath) Then
        _LogDebug("! Source path is not File Exists: " & $dlTempFilePath & @CRLF)
        Return SetError(1, 0, -1)
    EndIf
    _LogDebug("- Move (" & FileExists($dlTempFilePath) & ") " & $dlTempFilePath & " >TO> " & $sLocalPathSAVE & " > ")
    If FileExists($sLocalPathSAVE) Then _DelIt($sLocalPathSAVE, 1)
    Local $iDirFile = _Path_Split($sLocalPathSAVE, 6)
    If Not FileExists($iDirFile) Then DirCreate($iDirFile)
    If FileMove($dlTempFilePath, $sLocalPathSAVE, 1) Then
        _DelIt($dlTempFilePath, 1)
        _LogDebug(" Move OK" & @CRLF)
        Return 1
    Else
        _LogDebug(" ERROR !" & @CRLF & @CRLF)
        _LogDebug("- Try Copy (" & FileExists($dlTempFilePath) & ") " & $dlTempFilePath & " >TO> " & $sLocalPathSAVE & " > ")
        If FileCopy($dlTempFilePath, $sLocalPathSAVE, 1) Then
            _DelIt($dlTempFilePath, 1)
            _LogDebug(" OK" & @CRLF)
            Return 1
        Else
            _LogDebug(" ERROR !" & @CRLF & @CRLF)
            Return 0
        EndIf
    EndIf
EndFunc   ;==>__File_SAVE

Func _Encode_URL($UnicodeURL)
    Local $UnicodeBinary = StringToBinary($UnicodeURL, 4)
    Local $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1)
    Local $UnicodeBinaryLength = StringLen($UnicodeBinary2)
    Local $EncodedString, $UnicodeBinaryChar
    For $i = 1 To $UnicodeBinaryLength Step 2
        $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2)
        If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString('0x' & $UnicodeBinaryChar, 4)) Then
            $EncodedString &= BinaryToString('0x' & $UnicodeBinaryChar)
        Else
            $EncodedString &= '%' & $UnicodeBinaryChar
        EndIf
    Next
    Return $EncodedString
EndFunc   ;==>_Encode_URL

Func _Decode_URL($toDecode)
    Local $strChar = "", $iOne, $iTwo
    Local $aryHex = StringSplit($toDecode, "")
    For $i = 1 To $aryHex[0]
        If $aryHex[$i] = "%" Then
            $i = $i + 1
            $iOne = $aryHex[$i]
            $i = $i + 1
            $iTwo = $aryHex[$i]
            $strChar = $strChar & Chr(Dec($iOne & $iTwo))
        Else
            $strChar = $strChar & $aryHex[$i]
        EndIf
    Next
    Local $Process = StringToBinary(StringReplace($strChar, "+", " "))
    Local $DecodedString = BinaryToString($Process, 4)
    Return $DecodedString
EndFunc   ;==>_Decode_URL

Func __URL_Status($sURL_Input, ByRef $sURL_Rediect, $dUserName = "anonymous", $dPassword = "")
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    If (($dUserName = Default) Or (StringStripWS($dUserName, 8) == "") Or (StringLower($dUserName) == "anonymous")) Then $dUserName = ""
    If ((StringLower($dUserName) == "anonymous") Or ($dUserName == "") And (StringLen(StringStripWS($dUser, 8)) > 1)) Then
        $dUserName = $dUser
        If (($dPassword == "") And (StringLen($dPass) > 1)) Then $dPassword = $dPass
    EndIf
    If (Not ($dUserName == '')) Then
        If ($dProtocol == 'https' And $dPort <> 443) Or ($dProtocol == 'http' And $dPort <> 80) Then
            $sURL_Input = $dProtocol & "://" & $dDomain & ":" & $dPort & $dURLFilePathName
        Else
            $sURL_Input = $dProtocol & "://" & $dDomain & $dURLFilePathName
        EndIf
    EndIf
    $oHTTP.Option($OPTION_USER_AGENT) = $sUSER_AGENT
    $oHTTP.Option($OPTION_ENABLE_REDIRECTS) = False
    $oHTTP.Open("HEAD", $sURL_Input, False)
    If @error Then Return SetError(1, @error, -1)
    If (StringLen(StringStripWS($dUserName, 8)) > 1) Then $oHTTP.SetCredentials($dUserName, $dPassword, 0)
    $oHTTP.Send()
    If @error Then Return SetError(2, @error, 105) ;Error 105 (net::ERR_NAME_NOT_RESOLVED)
    Local $oStatus = $oHTTP.Status
    If @error Then Return SetError(3, @error, 118) ;Error 118 (net::ERR_CONNECTION_TIMED_OUT)
    If (($oStatus = 301) Or ($oStatus = 302)) Then
        $sURL_Rediect = $oHTTP.GetResponseHeader("Location")
        _LogDebug("! Redirect to URL: " & $sURL_Rediect & @CRLF)
    EndIf
    ;_LogDebug("+ GetResponseHeader: " & $oStatus & @CRLF)
    ;_LogDebug("- Cache-Control: " & $oHTTP.GetResponseHeader("Cache-Control") & @CRLF)
    ;_LogDebug("- Connection: " & $oHTTP.GetResponseHeader("Connection") & @CRLF)
    ;_LogDebug("- Date: " & $oHTTP.GetResponseHeader("Date") & @CRLF)
    ;_LogDebug("- Keep-Alive: " & $oHTTP.GetResponseHeader("Keep-Alive") & @CRLF)
    _LogDebug("- Content-Length: " & _Byte_GetDisplay($oHTTP.GetResponseHeader("Content-Length")) & @CRLF)
    ;_LogDebug("- Content-Type: " & $oHTTP.GetResponseHeader("Content-Type") & @CRLF)
    ;_LogDebug("- Expires: " & $oHTTP.GetResponseHeader("Expires") & @CRLF)
    ;_LogDebug("- Last-Modified: " & $oHTTP.GetResponseHeader("Last-Modified") & @CRLF)
    ;_LogDebug("- Accept-Ranges: " & $oHTTP.GetResponseHeader("Accept-Ranges") & @CRLF)
    ;_LogDebug("- Server: " & $oHTTP.GetResponseHeader("Server") & @CRLF)
    ;_LogDebug("- WWW-Authenticate: " & $oHTTP.GetResponseHeader("WWW-Authenticate") & @CRLF)
    ;_LogDebug($oHTTP.getAllResponseHeaders() & @CRLF)
    $oHTTP.Option($OPTION_ENABLE_REDIRECTS) = True
    Return SetError(0, 0, $oStatus)
EndFunc   ;==>__URL_Status

Func _Check_Connect($iDomain, $iPort = 80)
    Opt("TCPTimeout", 3000)
    TCPStartup()
    _LogDebug("- Checking Domain: " & $iDomain & " | Port: " & $iPort & " ")
    Local $sIPAddress = TCPNameToIP($iDomain)
    _LogDebug(" -> IP Address: " & $sIPAddress)
    Local $iSocket = TCPConnect($sIPAddress, $iPort)
    If $iSocket < 1 Then
        _LogDebug(" -> ERROR !" & @CRLF)
        Return SetError(1, 0, 0)
    Else
        _LogDebug(" -> SK:" & $iSocket & " OK !" & @CRLF)
        Return SetError(0, 0, 1)
    EndIf
    TCPShutdown()
    Opt("TCPTimeout", 250)
EndFunc   ;==>_Check_Connect

Func __URL_Check($sURL_Input, ByRef $sURL_Rediect, $dUserName = "anonymous", $dPassword = "")
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'http://' & $sURL_Input
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    #cs
     ConsoleWrite("- Protocol    : " & $dProtocol & @CRLF)
    ConsoleWrite("- Domain      : " & $dDomain & @CRLF)
    ConsoleWrite("- Port        : " & $dPort & @CRLF)
    ConsoleWrite("- User        : " & $dUser & @CRLF)
    ConsoleWrite("- Password    : " & $dPass & @CRLF)
    ConsoleWrite("- FilePathName: " & $dURLFilePathName & @CRLF)
    ConsoleWrite("- FilePath    : " & $dURLFilePath & @CRLF)
    ConsoleWrite("- FileName    : " &$dURLFileName & @CRLF)
    #ce
    If $dPort > 0 Then
        If _Check_Connect($dDomain, $dPort) = 0 Then Return SetError(1, 0, 0)
    Else
        Switch $dProtocol
            Case "http"
                If (_Check_Connect($dDomain, 80) = 0) Then Return SetError(1, 0, 0)
            Case "https"
                If (_Check_Connect($dDomain, 443) = 0) Then Return SetError(1, 0, 0)
            Case "ftp", "ftps"
                If (_Check_Connect($dDomain, 21) = 0) Then Return SetError(1, 0, 0)
            Case "sftp"
                If (_Check_Connect($dDomain, 22) = 0) Then Return SetError(1, 0, 0)
        EndSwitch
    EndIf
    Local $urlStatus = __URL_Status($sURL_Input, $sURL_Rediect, $dUserName, $dPassword)
    Switch $urlStatus
        Case 301, 302
            If ($sURL_Rediect == "") Then
            Else
                $sURL_Input = $sURL_Rediect
            EndIf
            _LogDebug("- URL Status: " & $urlStatus & " > Connection Successful! (URL redirect to: " & $sURL_Input & ")" & @CRLF)
            Return SetError(0, 0, __URL_Check($sURL_Input, $sURL_Rediect, $dUserName, $dPassword))
        Case 200
            _LogDebug("- URL Status: " & $urlStatus & " > Connection Successful! (URL: " & $sURL_Input & ")" & @CRLF)
            Return SetError(0, 0, $urlStatus)
        Case 401, 407
            _LogDebug("- URL Status: " & $urlStatus & " > Connection error! > Unauthorized (URL: " & $sURL_Input & ")" & @CRLF)
        Case 404
            _LogDebug("- URL Status: " & $urlStatus & " > Connection Successful! > URL Not Found: " & $sURL_Input & @CRLF)
        Case 105
            _LogDebug("- URL Status: " & $urlStatus & " > Connection error: ERR_NAME_NOT_RESOLVED > URL is Not Found: " & $sURL_Input & @CRLF)
        Case Else
            _LogDebug("- URL Status: " & $urlStatus & " > Connection error! > URL: " & $sURL_Input & @CRLF)
    EndSwitch
    Return SetError(1, 0, $urlStatus)
EndFunc   ;==>__URL_Check

Func _Byte_GetDisplay($iSize, $iPlaces = 4)
    Local $aBytes[7] = [' Bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB']
    For $i = 6 To 1 Step -1
        If $iSize >= 1024 ^ $i Then
            Return Round($iSize / 1024 ^ $i, $iPlaces) & $aBytes[$i]
        EndIf
    Next
    Return $iSize & ' Bytes'
EndFunc   ;==>_Byte_GetDisplay

Func _Convert_Size($inputSize, $inputUnit = 0, $outputPlaces = 2, $outputString = True, $inputBits = False, $outputBits = False, $outputUnit = -4)
    Local $unitNames[9] = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"]
    Local $Bytes = $inputSize * 1024 ^ $inputUnit
    Local $b = "B"
    If $inputBits Then $Bytes /= 8
    If $outputBits Then
        $Bytes *= 8
        $b = "b"
    EndIf
    If $outputUnit < 0 Then
        Local $outputMax = Abs($outputUnit)
        $outputUnit = Int(Log($Bytes) / Log(1024))
        If $outputUnit > $outputMax Then $outputUnit = $outputMax
    EndIf
    If $outputString Then
        Return String(Round($Bytes / 1024 ^ $outputUnit, $outputPlaces)) & " " & $unitNames[$outputUnit] & $b
    Else
        Return Round($Bytes / 1024 ^ $outputUnit, $outputPlaces)
    EndIf
EndFunc   ;==>_Convert_Size

Func _Path_Split($sFilePath, $sType = 0)
    Local $sDrive, $sDir, $sFileName, $sExtension, $sReturn
    Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1)
    If @error Then
        ReDim $aArray[5]
        $aArray[0] = $sFilePath
    EndIf
    $sDrive = $aArray[1]
    If StringLeft($aArray[2], 1) == "/" Then
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\/")
    Else
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\\")
    EndIf
    $aArray[2] = $sDir
    $sFileName = $aArray[3]
    $sExtension = $aArray[4]
    If $sType = 1 Then Return $sDrive
    If $sType = 2 Then Return $sDir
    If $sType = 3 Then Return $sFileName
    If $sType = 4 Then Return $sExtension
    If $sType = 5 Then Return $sFileName & $sExtension
    If $sType = 6 Then Return $sDrive & $sDir
    If $sType = 7 Then Return $sDrive & $sDir & $sFileName
    Return $aArray
EndFunc   ;==>_Path_Split

Func _IsFile($sPath)
    If (Not FileExists($sPath)) Then Return SetError(-1, 0, 0)
    If StringInStr(FileGetAttrib($sPath), 'D') <> 0 Then
        Return SetError(0, 0, 0)
    Else
        Return SetError(0, 0, 1)
    EndIf
EndFunc   ;==>_IsFile

Func _DelIt($sPath, $Fc = 1)
    If (Not FileExists($sPath)) Then Return SetError(-1, 0, 1)
    If _IsFile($sPath) Then
        Return SetError(0, 0, _DelFile($sPath, $Fc))
    Else
        Return SetError(0, 0, _RemoveDir($sPath, $Fc))
    EndIf
EndFunc   ;==>_DelIt

Func _DelFile($sPath, $Fc = 1)
    If (Not _IsFile($sPath)) Then
        Return SetError(-1, 0, 0)
    Else
        FileSetAttrib($sPath, "-RSH")
        FileDelete($sPath)
        If $Fc Then
            If FileExists($sPath) Then _TakeOwnership($sPath, "Everyone", $Fc)
            If FileExists($sPath) Then FileDelete($sPath)
            If FileExists($sPath) Then RunWait(@ComSpec & ' /c Del /f /q "' & $sPath & '"', '', @SW_HIDE)
        EndIf
        If FileExists($sPath) Then Return SetError(1, 0, 0)
        Return SetError(0, 0, 1)
    EndIf
EndFunc   ;==>_DelFile

Func _RemoveDir($sPath, $Fc = 1)
    If _IsFile($sPath) Then
        Return SetError(-1, 0, 0)
    Else
        DirRemove($sPath, $Fc)
        If FileExists($sPath) Then _TakeOwnership($sPath, "Everyone", $Fc)
        DirRemove($sPath, $Fc)
        If FileExists($sPath) Then RunWait(@ComSpec & ' /c rmdir "' & $sPath & '" /s /q ', '', @SW_HIDE)
        If FileExists($sPath) Then Return SetError(1, 0, 0)
        Return SetError(0, 0, 1)
    EndIf
EndFunc   ;==>_RemoveDir

Func _GetDomainURL($sURL_Input)
    Local $sURL_Pattern = "^(?i)(?:(?:[a-z]+):\/\/)?" & _ ; Protocol
            "(?:(?:(?:[^@:]+))" & _ ; Username
            "(?::(?:[^@]+))?@)?" & _ ; Password
            "([^\/:]+)" & _ ; Host
            "(?::(?:\d+))?" & _ ; Port
            "(?:\/(?:[^?]+)?)?" & _ ; Path
            "(?:\?\N+)?" ; Query
    Local $aHost = StringRegExp($sURL_Input, $sURL_Pattern, 1)
    If IsArray($aHost) Then Return $aHost[0]
    Return ""
EndFunc   ;==>_GetDomainURL

Func _LogDebug($iLog = "", $iLogs = "", $itype = -1)
    If (($itype = 0) And ($iLog = "") And ($iLogs = "")) Then Return 0
    If (($itype = -1) And $ViewLogConsole) Then Return ConsoleWrite($iLog)
    If ($iLogs = "") Then $iLogs = $iLog
    If ($itype = 0) Then
        If $ViewLogConsole Then ConsoleWrite("- " & $iLog & @CRLF)
        ;If $sTextColor <> $lBkColor Then
        ;$sTextColor = $lBkColor
        ;GUICtrlSetColor($labStatus, $sTextColor)
        ;EndIf
        ;GUICtrlSetData($labStatus, $iLogs)
    Else
        If $ViewLogConsole Then ConsoleWrite("! " & $iLog & @CRLF)
        ;If $sTextColor <> $sTextColorError Then
        ;$sTextColor = $sTextColorError
        ;GUICtrlSetColor($labStatus, $sTextColor)
        ;EndIf
        ;GUICtrlSetData($labStatus, $iLogs)
    EndIf
    Return 1
EndFunc   ;==>_LogDebug

Func __Skip_OBJ_Error()
    $obError = True
    ;ConsoleWrite("! " & $obError.description & @CRLF)
EndFunc   ;==>__Skip_OBJ_Error

Func _WinHttpURL_GetStatus($sURL_Input, $dUserName = "anonymous", $dPassword = "")
    If (StringStripWS($sURL_Input, 8) == '') Then Return SetError(1, 0, 0)
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'http://' & $sURL_Input
    Local $dFileSize, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName
    _WinHttp_SplitURL($sURL_Input, $dProtocol, $dDomain, $dPort, $dUser, $dPass, $dURLFilePathName, $dURLFilePath, $dURLFileName)
    If (($dUserName = Default) Or (StringStripWS($dUserName, 8) == "") Or (StringLower($dUserName) == "anonymous")) Then $dUserName = ""
    If ((StringLower($dUserName) == "anonymous") Or ($dUserName == "") And (StringLen(StringStripWS($dUser, 8)) > 1)) Then
        $dUserName = $dUser
        If (($dPassword == "") And (StringLen($dPass) > 1)) Then $dPassword = $dPass
    EndIf
    ; Initialize and get session handle
    Global $hOpen = _WinHttpOpen()
    ; Get connection handle
    Global $hConnect = _WinHttpConnect($hOpen, $dDomain)
    ; Specify the reguest
    Global $hRequest = _WinHttpOpenRequest($hConnect, "HEAD", $dURLFilePathName, Default, $dProtocol & "://" & $dDomain)
    ; Set credentials
    If (StringLen(StringStripWS($dUserName, 8)) > 1) Then _WinHttpSetCredentials($hRequest, $WINHTTP_AUTH_TARGET_SERVER, $WINHTTP_AUTH_SCHEME_BASIC, $dUserName, $dPassword)
    ; Send request
    _WinHttpSendRequest($hRequest)
    ; Wait for the response
    _WinHttpReceiveResponse($hRequest)
    ; Get full header
    Global $sHeader = _WinHttpQueryHeaders($hRequest)
    ConsoleWrite($sHeader & @CRLF)
    ; Close handles
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
EndFunc   ;==>_WinHttpURL_GetStatus

Func _Directory_Is_Accessible($sPath, $iTouch = 0)
    If Not FileExists($sPath) Then DirCreate($sPath)
    If Not StringInStr(FileGetAttrib($sPath), "D", 2) Then Return SetError(1, 0, 0)
    Local $iEnum = 0, $maxEnum = 9999, $iRandom = Random(88888888, 99999999, 1)
    If $iTouch Then _TakeOwnership($sPath, "Everyone", 1)
    While FileExists($sPath & "\_IsWritable-" & $iEnum & "-" & $iRandom)
        $iEnum += 1
        If ($iEnum > $maxEnum) Then Return SetError(2, 0, 0)
    WEnd
    Local $iSuccess = DirCreate($sPath & "\_IsWritable-" & $iEnum & "-" & $iRandom)
    Switch $iSuccess
        Case 1
            $iTouch = DirRemove($sPath & "\_IsWritable-" & $iEnum & "-" & $iRandom, 1)
            Return SetError($iTouch < 1, 0, $iTouch)
        Case Else
            Return SetError(3, 0, 0)
    EndSwitch
EndFunc   ;==>_Directory_Is_Accessible

Func _File_Is_Accessible($sFile, $iTouch = 0)
    ; Returns
    ; 1 = Success, file is writeable and deletable
    ; 2 = Access Denied because of lacking access rights OR because file is open by another process
    ; 3 = File is set "Read Only" by attribute
    ; 0 = File not found or Is Directory
    If ((Not FileExists("\\?\" & $sFile)) Or StringInStr(FileGetAttrib("\\?\" & $sFile), "D", 2)) Then Return SetError(1, 0, 0)
    Local $oFileAttrib = FileGetAttrib("\\?\" & $sFile)
    If $iTouch Then
        FileSetAttrib("\\?\" & $sFile, "-RHS")
        _TakeOwnership($sFile, "Everyone", 1)
    EndIf
    If StringInStr(FileGetAttrib("\\?\" & $sFile), "R", 2) Then Return 3 ; Read-Only Flag set
    Local $hFile = _WinAPI_CreateFileEx("\\?\" & $sFile, $OPEN_EXISTING, $GENERIC_READ + $GENERIC_WRITE, $FILE_SHARE_READ + $FILE_SHARE_WRITE + $FILE_SHARE_DELETE, $FILE_FLAG_BACKUP_SEMANTICS) ;
    Local $iReturn = $hFile
    _WinAPI_CloseHandle($hFile)
    If ($iReturn = 0) Then Return 2 ; File not accessible, UAC issue?
    Return 1 ; Success
EndFunc   ;==>_File_Is_Accessible

Func _TakeOwnership($sFile, $iUserName = "Everyone", $sRecurse = 1)
    If ($iUserName = Default) Or (StringStripWS($iUserName, 8) = '') Then $iUserName = "Everyone"
    If ($sRecurse = Default) Or ($sRecurse = True) Or ($sRecurse > 0) Then
        $sRecurse = 1
    Else
        $sRecurse = 0
    EndIf
    Local $osNotIsEnglish = True
    Switch @OSLang
        Case "0009", "0409", "0809", "0C09", "1009", "1409", "1809", "1C09", "2009", "2409", "2809", "2C09", "3009", "3409", "3C09", "4009", "4409", "4809", "4C09"
            $osNotIsEnglish = False
        Case "3809", "5009", "5409", "5809", "5C09", "6009", "6409" ; new
            $osNotIsEnglish = False
    EndSwitch
    If StringInStr($iUserName, ' ') Then $iUserName = '"' & $iUserName & '"'
    If ($sRecurse = Default) Then $sRecurse = 1
    If Not FileExists($sFile) Then Return SetError(1, 0, $sFile)
    If StringInStr(FileGetAttrib($sFile), 'D') <> 0 Then
        If $sRecurse Then
            RunWait(@ComSpec & ' /c takeown /f "' & $sFile & '" /R /D Y', '', @SW_HIDE)
            If $iUserName <> 'Administrators' Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /T /C /G Administrators:F', '', @SW_HIDE)
            If $iUserName <> 'Users' Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /T /C /G Users:F', '', @SW_HIDE)
            RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /T /C /G ' & $iUserName & ':F', '', @SW_HIDE)
            If $osNotIsEnglish Then
                If ($iUserName = "Everyone") Then $iUserName = '*S-1-1-0'
                If ($iUserName = '"' & 'Authenticated Users' & '"') Then $iUserName = '*S-1-5-11'
            EndIf
            If $iUserName <> 'Administrators' Then RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant Administrators:F /T /C /Q', '', @SW_HIDE)
            If $iUserName <> 'Users' Then RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant Users:F /T /C /Q', '', @SW_HIDE)
            RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant ' & $iUserName & ':F /T /C /Q', '', @SW_HIDE)
            Return SetError(0, 0, FileSetAttrib($sFile, "-RHS", 1))
        Else
            RunWait(@ComSpec & ' /c takeown /f "' & $sFile & '" ', '', @SW_HIDE)
            If $iUserName <> 'Administrators' Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /C /G Administrators:F', '', @SW_HIDE)
            If $iUserName <> 'Users' Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /C /G Users:F', '', @SW_HIDE)
            RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /C /G ' & $iUserName & ':F', '', @SW_HIDE)
            If $osNotIsEnglish Then
                If ($iUserName = "Everyone") Then $iUserName = '*S-1-1-0'
                If ($iUserName = '"' & 'Authenticated Users' & '"') Then $iUserName = '*S-1-5-11'
            EndIf
            If $iUserName <> 'Administrators' Then RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant Administrators:F /C /Q', '', @SW_HIDE)
            If $iUserName <> 'Users' Then RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant Users:F /C /Q', '', @SW_HIDE)
            RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant ' & $iUserName & ':F /C /Q', '', @SW_HIDE)
            Return SetError(0, 0, FileSetAttrib($sFile, "-RHS", 0))
        EndIf
    Else
        RunWait(@ComSpec & ' /c takeown /f "' & $sFile & '"', '', @SW_HIDE)
        If $iUserName <> 'Administrators' Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /C /G Administrators:F', '', @SW_HIDE)
        If $iUserName <> 'Users' Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /C /G Users:F', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFile & '" /C /G ' & $iUserName & ':F', '', @SW_HIDE)
        If $osNotIsEnglish Then
            If ($iUserName = "Everyone") Then $iUserName = '*S-1-1-0'
            If ($iUserName = '"' & 'Authenticated Users' & '"') Then $iUserName = '*S-1-5-11'
        EndIf
        If $iUserName <> 'Administrators' Then RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant Administrators:F /Q', '', @SW_HIDE)
        If $iUserName <> 'Users' Then RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant Users:F /Q', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c iCacls "' & $sFile & '" /grant ' & $iUserName & ':F /Q', '', @SW_HIDE)
        Return SetError(0, 0, FileSetAttrib($sFile, "-RHS"))
    EndIf
    Return $sFile
EndFunc   ;==>_TakeOwnership
Func _URL_Split($sURL_Input, ByRef $sURL_Protocol, ByRef $sURL_Domain, ByRef $sURL_FilePATH, ByRef $sURL_FileName)
    Local $sURL_Protocol_Number_Pattern = '^(?s)(?i)(http|ftp|sftp|ftps|https|file)://(.*?/|.*$)(.*/){0,}(.*)$'
    Local $sURL_Pattern = "^(?i)(?:(?:[a-z]+):\/\/)?" & "(?:(?:(?:[^@:]+))" & "(?::(?:[^@]+))?@)?" & "([^\/:]+)" & "(?::(?:\d+))?" & "(?:\/(?:[^?]+)?)?" & "(?:\?\N+)?"
    Local $aURL_Pattern = StringRegExp($sURL_Input, $sURL_Protocol_Number_Pattern, 2)
    If Not IsArray($aURL_Pattern) Or UBound($aURL_Pattern) - 1 <> 4 Then Return SetError(1, 0, 0)
    If StringRight($aURL_Pattern[2], 1) = '/' Then
        $aURL_Pattern[2] = StringTrimRight($aURL_Pattern[2], 1)
        $aURL_Pattern[3] = '/' & $aURL_Pattern[3]
    EndIf
    $sURL_Protocol = $aURL_Pattern[1]
    Local $aHost = StringRegExp($sURL_Input, $sURL_Pattern, 1)
    If Not @error And IsArray($aHost) Then
        $sURL_Domain = $aHost[0]
    Else
        $sURL_Domain = $aURL_Pattern[2]
    EndIf
    $sURL_FilePATH = $aURL_Pattern[3]
    $sURL_FileName = $aURL_Pattern[4]
    Return $aURL_Pattern
EndFunc   ;==>_URL_Split
#cs
    Local $sURL_Protocol, $sURL_Protocol_Number, $sURL_Domain, $sURL_Port, $sURL_User, $sURL_Password, $sURL_FilePathName, $sURL_FilePATH, $sURL_FileName
    _WinHttp_SplitURL($sURL_Input, $sURL_Protocol, $sURL_Domain, $sURL_Port, $sURL_User, $sURL_Password, $sURL_FilePathName, $sURL_FilePATH, $sURL_FileName)
    ConsoleWrite("! URL_Input   : " & $sURL_Input & @CRLF)
    ConsoleWrite("- Protocol    : " & $sURL_Protocol & @CRLF)
    ConsoleWrite("- Domain      : " & $sURL_Domain & @CRLF)
    ConsoleWrite("- Port        : " & $sURL_Port & @CRLF)
    ConsoleWrite("- User        : " & $sURL_User & @CRLF)
    ConsoleWrite("- Password    : " & $sURL_Password & @CRLF)
    ConsoleWrite("- FilePathName: " & $sURL_FilePathName & @CRLF)
    ConsoleWrite("- FilePath    : " & $sURL_FilePath & @CRLF)
    ConsoleWrite("- FileName    : " & $sURL_FileName & @CRLF)
#ce
Func _WinHttp_SplitURL($sURL_Input, ByRef $sURL_Protocol, ByRef $sURL_Domain, ByRef $sURL_Port, ByRef $sURL_User, ByRef $sURL_Password, ByRef $sURL_FilePathName, ByRef $sURL_FilePATH, ByRef $sURL_FileName)
    If StringStripWS($sURL_Input, 8) = '' Then Return SetError(1, 0, 0)
    $sURL_Input = StringReplace($sURL_Input, "\", "/")
    If (Not StringInStr($sURL_Input, '://')) Then $sURL_Input = 'http://' & $sURL_Input
    _URL_Split($sURL_Input, $sURL_Protocol, $sURL_Domain, $sURL_FilePATH, $sURL_FileName)
    StringReplace($sURL_Input, '@', '')
    If @extended > 1 Then
        Local $sUser, $aUser = _StringBetween($sURL_Input, $sURL_Protocol & "://", '@')
        If IsArray($aUser) Then
            $sUser = $aUser[0]
            $sURL_Input = StringReplace($sURL_Input, $sURL_Protocol & "://" & $sUser & '@', $sURL_Protocol & "://" & $sUser & '%40')
        EndIf
    EndIf
    Local $ORG_URL_Protocol = $sURL_Protocol, $sFake_Protocol = 'http', $iFake_Protocol = False
    Switch $sURL_Protocol
        Case 'http', 'https', 'ftp'
        Case Else
            $iFake_Protocol = True
            $sURL_Input = StringReplace($sURL_Input, $sURL_Protocol & "://", $sFake_Protocol & "://")
    EndSwitch
    Local $aUrl = _WinHttpCrackUrl($sURL_Input)
    If IsArray($aUrl) Then
        If $iFake_Protocol Then
            $sURL_Protocol = $ORG_URL_Protocol
        Else
            $sURL_Protocol = ($aUrl[0] == '' ? $sURL_Protocol : $aUrl[0])
        EndIf
        ;$sURL_Protocol_Number = $aUrl[1]
        $sURL_Domain = ($aUrl[2] == '' ? $sURL_Domain : $aUrl[2])
        $sURL_Port = $aUrl[3]
        $sURL_User = StringReplace($aUrl[4], '%40', '@')
        $sURL_Password = $aUrl[5]
        $sURL_FilePathName = ($aUrl[6] == '' ? $sURL_FilePATH & $sURL_FileName : $aUrl[6])
        ;$sURL_ExtraInfo = $aUrl[7]
        Return $aUrl
    EndIf
    Return SetError(1, 0, "")
EndFunc   ;==>_WinHttp_SplitURL

Func _WinHTTP_GetName_ErrorCode($nErrorCode = 0)
    ; By Dao Van Trong - TRONG.LIVE
    Switch $nErrorCode
        Case 12001
            Return "ERROR_WINHTTP_OUT_OF_HANDLES"
        Case 12002
            Return "ERROR_WINHTTP_TIMEOUT"
        Case 12004
            Return "ERROR_WINHTTP_INTERNAL_ERROR"
        Case 12005
            Return "ERROR_WINHTTP_INVALID_URL"
        Case 12006
            Return "ERROR_WINHTTP_UNRECOGNIZED_SCHEME"
        Case 12007
            Return "ERROR_WINHTTP_NAME_NOT_RESOLVED"
        Case 12009
            Return "ERROR_WINHTTP_INVALID_OPTION"
        Case 12011
            Return "ERROR_WINHTTP_OPTION_NOT_SETTABLE"
        Case 12012
            Return "ERROR_WINHTTP_SHUTDOWN"
        Case 12015
            Return "ERROR_WINHTTP_LOGIN_FAILURE"
        Case 12017
            Return "ERROR_WINHTTP_OPERATION_CANCELLED"
        Case 12018
            Return "ERROR_WINHTTP_INCORRECT_HANDLE_TYPE"
        Case 12019
            Return "ERROR_WINHTTP_INCORRECT_HANDLE_STATE"
        Case 12029
            Return "ERROR_WINHTTP_CANNOT_CONNECT"
        Case 12030
            Return "ERROR_WINHTTP_CONNECTION_ERROR"
        Case 12032
            Return "ERROR_WINHTTP_RESEND_REQUEST"
        Case 12044
            Return "ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED"
        Case 12150
            Return "ERROR_WINHTTP_HEADER_NOT_FOUND"
        Case 12152
            Return "ERROR_WINHTTP_INVALID_SERVER_RESPONSE"
        Case 12153
            Return "ERROR_WINHTTP_INVALID_HEADER"
        Case 12154
            Return "ERROR_WINHTTP_INVALID_QUERY_REQUEST"
        Case 12155
            Return "ERROR_WINHTTP_HEADER_ALREADY_EXISTS"
        Case 12156
            Return "ERROR_WINHTTP_REDIRECT_FAILED"
        Case 12178
            Return "ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR"
        Case 12166
            Return "ERROR_WINHTTP_BAD_AUTO_PROXY_SCRIPT"
        Case 12167
            Return "ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT"
        Case 12176
            Return "ERROR_WINHTTP_UNHANDLED_SCRIPT_TYPE"
        Case 12177
            Return "ERROR_WINHTTP_SCRIPT_EXECUTION_ERROR"
        Case 12172
            Return "ERROR_WINHTTP_NOT_INITIALIZED"
        Case 12175
            Return "ERROR_WINHTTP_SECURE_FAILURE"
        Case 12037
            Return "ERROR_WINHTTP_SECURE_CERT_DATE_INVALID"
        Case 12038
            Return "ERROR_WINHTTP_SECURE_CERT_CN_INVALID"
        Case 12045
            Return "ERROR_WINHTTP_SECURE_INVALID_CA"
        Case 12057
            Return "ERROR_WINHTTP_SECURE_CERT_REV_FAILED"
        Case 12157
            Return "ERROR_WINHTTP_SECURE_CHANNEL_ERROR"
        Case 12169
            Return "ERROR_WINHTTP_SECURE_INVALID_CERT"
        Case 12170
            Return "ERROR_WINHTTP_SECURE_CERT_REVOKED"
        Case 12179
            Return "ERROR_WINHTTP_SECURE_CERT_WRONG_USAGE"
        Case 12180
            Return "ERROR_WINHTTP_AUTODETECTION_FAILED"
        Case 12181
            Return "ERROR_WINHTTP_HEADER_COUNT_EXCEEDED"
        Case 12182
            Return "ERROR_WINHTTP_HEADER_SIZE_OVERFLOW"
        Case 12183
            Return "ERROR_WINHTTP_CHUNKED_ENCODING_HEADER_SIZE_OVERFLOW"
        Case 12184
            Return "ERROR_WINHTTP_RESPONSE_DRAIN_OVERFLOW"
        Case 12185
            Return "ERROR_WINHTTP_CLIENT_CERT_NO_PRIVATE_KEY"
        Case 12186
            Return "ERROR_WINHTTP_CLIENT_CERT_NO_ACCESS_PRIVATE_KEY"
        Case 12187
            Return "ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED_PROXY"
        Case 12188
            Return "ERROR_WINHTTP_SECURE_FAILURE_PROXY"
        Case 12189
            Return "ERROR_WINHTTP_RESERVED_189"
        Case 12190
            Return "ERROR_WINHTTP_HTTP_PROTOCOL_MISMATCH"
        Case 12191
            Return "ERROR_WINHTTP_GLOBAL_CALLBACK_FAILED"
        Case 12192
            Return "ERROR_WINHTTP_FEATURE_DISABLED"
            Return "WINHTTP_ERROR_LAST"
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
EndFunc   ;==>_WinHTTP_GetName_ErrorCode

Func _WinInet_GetName_ErrorCode($nErrorCode = 0)
    ; By Dao Van Trong - TRONG.LIVE
    Switch $nErrorCode
        Case 12000
            Return "INTERNET_ERROR_BASE"
        Case 12001
            Return "ERROR_INTERNET_OUT_OF_HANDLES"
        Case 12002
            Return "ERROR_INTERNET_TIMEOUT"
        Case 12003
            Return "ERROR_INTERNET_EXTENDED_ERROR"
        Case 12004
            Return "ERROR_INTERNET_INTERNAL_ERROR"
        Case 12005
            Return "ERROR_INTERNET_INVALID_URL"
        Case 12006
            Return "ERROR_INTERNET_UNRECOGNIZED_SCHEME"
        Case 12007
            Return "ERROR_INTERNET_NAME_NOT_RESOLVED"
        Case 12008
            Return "ERROR_INTERNET_PROTOCOL_NOT_FOUND"
        Case 12009
            Return "ERROR_INTERNET_INVALID_OPTION"
        Case 12010
            Return "ERROR_INTERNET_BAD_OPTION_LENGTH"
        Case 12011
            Return "ERROR_INTERNET_OPTION_NOT_SETTABLE"
        Case 12012
            Return "ERROR_INTERNET_SHUTDOWN"
        Case 12013
            Return "ERROR_INTERNET_INCORRECT_USER_NAME"
        Case 12014
            Return "ERROR_INTERNET_INCORRECT_PASSWORD"
        Case 12015
            Return "ERROR_INTERNET_LOGIN_FAILURE"
        Case 12016
            Return "ERROR_INTERNET_INVALID_OPERATION"
        Case 12017
            Return "ERROR_INTERNET_OPERATION_CANCELLED"
        Case 12018
            Return "ERROR_INTERNET_INCORRECT_HANDLE_TYPE"
        Case 12019
            Return "ERROR_INTERNET_INCORRECT_HANDLE_STATE"
        Case 12020
            Return "ERROR_INTERNET_NOT_PROXY_REQUEST"
        Case 12021
            Return "ERROR_INTERNET_REGISTRY_VALUE_NOT_FOUND"
        Case 12022
            Return "ERROR_INTERNET_BAD_REGISTRY_PARAMETER"
        Case 12023
            Return "ERROR_INTERNET_NO_DIRECT_ACCESS"
        Case 12024
            Return "ERROR_INTERNET_NO_CONTEXT"
        Case 12025
            Return "ERROR_INTERNET_NO_CALLBACK"
        Case 12026
            Return "ERROR_INTERNET_REQUEST_PENDING"
        Case 12027
            Return "ERROR_INTERNET_INCORRECT_FORMAT"
        Case 12028
            Return "ERROR_INTERNET_ITEM_NOT_FOUND"
        Case 12029
            Return "ERROR_INTERNET_CANNOT_CONNECT"
        Case 12030
            Return "ERROR_INTERNET_CONNECTION_ABORTED"
        Case 12031
            Return "ERROR_INTERNET_CONNECTION_RESET"
        Case 12032
            Return "ERROR_INTERNET_FORCE_RETRY"
        Case 12033
            Return "ERROR_INTERNET_INVALID_PROXY_REQUEST"
        Case 12034
            Return "ERROR_INTERNET_NEED_UI"
        Case 12036
            Return "ERROR_INTERNET_HANDLE_EXISTS"
        Case 12037
            Return "ERROR_INTERNET_SEC_CERT_DATE_INVALID"
        Case 12038
            Return "ERROR_INTERNET_SEC_CERT_CN_INVALID"
        Case 12039
            Return "ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR"
        Case 12040
            Return "ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR"
        Case 12041
            Return "ERROR_INTERNET_MIXED_SECURITY"
        Case 12042
            Return "ERROR_INTERNET_CHG_POST_IS_NON_SECURE"
        Case 12043
            Return "ERROR_INTERNET_POST_IS_NON_SECURE"
        Case 12044
            Return "ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED"
        Case 12045
            Return "ERROR_INTERNET_INVALID_CA"
        Case 12046
            Return "ERROR_INTERNET_CLIENT_AUTH_NOT_SETUP"
        Case 12047
            Return "ERROR_INTERNET_ASYNC_THREAD_FAILED"
        Case 12048
            Return "ERROR_INTERNET_REDIRECT_SCHEME_CHANGE"
        Case 12049
            Return "ERROR_INTERNET_DIALOG_PENDING"
        Case 12050
            Return "ERROR_INTERNET_RETRY_DIALOG"
        Case 12052
            Return "ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR"
        Case 12053
            Return "ERROR_INTERNET_INSERT_CDROM"
        Case 12054
            Return "ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED"
        Case 12055
            Return "ERROR_INTERNET_SEC_CERT_ERRORS"
        Case 12056
            Return "ERROR_INTERNET_SEC_CERT_NO_REV"
        Case 12057
            Return "ERROR_INTERNET_SEC_CERT_REV_FAILED"
        Case 12060
            Return "ERROR_HTTP_HSTS_REDIRECT_REQUIRED"
        Case 12062
            Return "ERROR_INTERNET_SEC_CERT_WEAK_SIGNATURE"
        Case 12110
            Return "ERROR_FTP_TRANSFER_IN_PROGRESS"
        Case 12111
            Return "ERROR_FTP_DROPPED"
        Case 12112
            Return "ERROR_FTP_NO_PASSIVE_MODE"
        Case 12130
            Return "ERROR_GOPHER_PROTOCOL_ERROR"
        Case 12131
            Return "ERROR_GOPHER_NOT_FILE"
        Case 12132
            Return "ERROR_GOPHER_DATA_ERROR"
        Case 12133
            Return "ERROR_GOPHER_END_OF_DATA"
        Case 12134
            Return "ERROR_GOPHER_INVALID_LOCATOR"
        Case 12135
            Return "ERROR_GOPHER_INCORRECT_LOCATOR_TYPE"
        Case 12136
            Return "ERROR_GOPHER_NOT_GOPHER_PLUS"
        Case 12137
            Return "ERROR_GOPHER_ATTRIBUTE_NOT_FOUND"
        Case 12138
            Return "ERROR_GOPHER_UNKNOWN_LOCATOR"
        Case 12150
            Return "ERROR_HTTP_HEADER_NOT_FOUND"
        Case 12151
            Return "ERROR_HTTP_DOWNLEVEL_SERVER"
        Case 12152
            Return "ERROR_HTTP_INVALID_SERVER_RESPONSE"
        Case 12153
            Return "ERROR_HTTP_INVALID_HEADER"
        Case 12154
            Return "ERROR_HTTP_INVALID_QUERY_REQUEST"
        Case 12155
            Return "ERROR_HTTP_HEADER_ALREADY_EXISTS"
        Case 12156
            Return "ERROR_HTTP_REDIRECT_FAILED"
        Case 12160
            Return "ERROR_HTTP_NOT_REDIRECTED"
        Case 12161
            Return "ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION"
        Case 12162
            Return "ERROR_HTTP_COOKIE_DECLINED"
        Case 12168
            Return "ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION"
        Case 12157
            Return "ERROR_INTERNET_SECURITY_CHANNEL_ERROR"
        Case 12158
            Return "ERROR_INTERNET_UNABLE_TO_CACHE_FILE"
        Case 12159
            Return "ERROR_INTERNET_TCPIP_NOT_INSTALLED"
        Case 12163
            Return "ERROR_INTERNET_DISCONNECTED"
            Return "ERROR_INTERNET_OFFLINE"
        Case 12164
            Return "ERROR_INTERNET_SERVER_UNREACHABLE"
        Case 12165
            Return "ERROR_INTERNET_PROXY_SERVER_UNREACHABLE"
        Case 12166
            Return "ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT"
        Case 12167
            Return "ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT"
        Case 12169
            Return "ERROR_INTERNET_SEC_INVALID_CERT"
        Case 12170
            Return "ERROR_INTERNET_SEC_CERT_REVOKED"
        Case 12171
            Return "ERROR_INTERNET_FAILED_DUETOSECURITYCHECK"
        Case 12172
            Return "ERROR_INTERNET_NOT_INITIALIZED"
        Case 12173
            Return "ERROR_INTERNET_NEED_MSN_SSPI_PKG"
        Case 12174
            Return "ERROR_INTERNET_LOGIN_FAILURE_DISPLAY_ENTITY_BODY"
        Case 12175
            Return "ERROR_INTERNET_DECODING_FAILED"
        Case 12187
            Return "ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED_PROXY"
        Case 12188
            Return "ERROR_INTERNET_SECURE_FAILURE_PROXY"
        Case 12190
            Return "ERROR_INTERNET_HTTP_PROTOCOL_MISMATCH"
        Case 12191
            Return "ERROR_INTERNET_GLOBAL_CALLBACK_FAILED"
        Case 12192
            Return "ERROR_INTERNET_FEATURE_DISABLED"
            Return "INTERNET_ERROR_LAST"
        Case 12051
            Return "ERROR_INTERNET_NO_NEW_CONTAINERS"
        Case 12058
            Return "ERROR_INTERNET_SOURCE_PORT_IN_USE"
        Case 12059
            Return "ERROR_INTERNET_INSECURE_FALLBACK_REQUIRED"
        Case 12061
            Return "ERROR_INTERNET_PROXY_ALERT"
        Case 12080
            Return "ERROR_INTERNET_NO_CM_CONNECTION"
        Case 12147
            Return "ERROR_HTTP_PUSH_STATUS_CODE_NOT_SUPPORTED"
        Case 12148
            Return "ERROR_HTTP_PUSH_RETRY_NOT_SUPPORTED"
        Case 12149
            Return "ERROR_HTTP_PUSH_ENABLE_FAILED"
        Case 12189
            Return "ERROR_INTERNET_DISALLOW_INPRIVATE"
        Case 12900
            Return "INTERNET_INTERNAL_ERROR_BASE"
        Case 12901
            Return "ERROR_INTERNET_INTERNAL_SOCKET_ERROR"
        Case 12902
            Return "ERROR_INTERNET_CONNECTION_AVAILABLE"
        Case 12903
            Return "ERROR_INTERNET_NO_KNOWN_SERVERS"
        Case 12904
            Return "ERROR_INTERNET_PING_FAILED"
        Case 12905
            Return "ERROR_INTERNET_NO_PING_SUPPORT"
        Case 12906
            Return "ERROR_INTERNET_CACHE_SUCCESS"
        Case 12907
            Return "ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION_EX"
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
EndFunc   ;==>_WinInet_GetName_ErrorCode

Func _WinAPI_GetLastError(Const $_iCallerError = @error, Const $_iCallerExtended = @extended)
    Local $aCall = DllCall("kernel32.dll", "dword", "GetLastError")
    Return SetError($_iCallerError, $_iCallerExtended, $aCall[0])
EndFunc   ;==>_WinAPI_GetLastError
Func _WinAPI_CloseHandle($hObject)
    Local $aCall = DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hObject)
    If @error Then Return SetError(@error, @extended, False)
    Return $aCall[0]
EndFunc   ;==>_WinAPI_CloseHandle
Func _WinAPI_MakeQWord($iLoDWORD, $iHiDWORD)
    Local $tInt64 = DllStructCreate("uint64")
    Local $tDwords = DllStructCreate("dword;dword", DllStructGetPtr($tInt64))
    DllStructSetData($tDwords, 1, $iLoDWORD)
    DllStructSetData($tDwords, 2, $iHiDWORD)
    Return DllStructGetData($tInt64, 1)
EndFunc   ;==>_WinAPI_MakeQWord
Func _FTP_Close($hSession)
    If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
    Local $aCall = DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $hSession)
    If @error Or Not $aCall[0] Then Return SetError(@error + 10, _WinAPI_GetLastError(), 0)
    If $__g_bCallback_FTP = True Then DllCallbackFree($__g_hCallback_FTP)
    Return $aCall[0]
EndFunc   ;==>_FTP_Close
Func _FTP_Connect($hInternetSession, $sServerName, $sUsername, $sPassword, $iPassive = 0, $iServerPort = 0, $iService = $INTERNET_SERVICE_FTP, $iFlags = $INTERNET_FLAG_DEFAULT, $fuContext = 0)
    If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
    If $iPassive == 1 Then $iFlags = BitOR($iFlags, $INTERNET_FLAG_PASSIVE)
    Local $ai_InternetConnect = DllCall($__g_hWinInet_FTP, 'hwnd', 'InternetConnectW', 'handle', $hInternetSession, 'wstr', $sServerName, 'ushort', $iServerPort, 'wstr', $sUsername, 'wstr', $sPassword, 'dword', $iService, 'dword', $iFlags, 'dword_ptr', $fuContext)
    If @error Or $ai_InternetConnect[0] = 0 Then Return SetError(@error + 10, _WinAPI_GetLastError(), 0)
    Return $ai_InternetConnect[0]
EndFunc   ;==>_FTP_Connect
Func _FTP_FileGet($hFTPSession, $sRemoteFile, $sLocalFile, $bFailIfExists = False, $iFlagsAndAttributes = 0, $iFlags = $FTP_TRANSFER_TYPE_UNKNOWN, $iContext = 0)
    If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
    Local $ai_FTPGetFile = DllCall($__g_hWinInet_FTP, 'bool', 'FtpGetFileW', 'handle', $hFTPSession, 'wstr', $sRemoteFile, 'wstr', $sLocalFile, 'bool', $bFailIfExists, 'dword', $iFlagsAndAttributes, 'dword', $iFlags, 'dword_ptr', $iContext)
    If @error Or $ai_FTPGetFile[0] = 0 Then Return SetError(@error + 10, _WinAPI_GetLastError(), 0)
    Return $ai_FTPGetFile[0]
EndFunc   ;==>_FTP_FileGet
Func _FTP_FileGetSize($hFTPSession, $sFileName)
    If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
    Local $ai_FTPGetSizeHandle = DllCall($__g_hWinInet_FTP, 'handle', 'FtpOpenFileW', 'handle', $hFTPSession, 'wstr', $sFileName, 'dword', $GENERIC_READ, 'dword', $INTERNET_FLAG_NO_CACHE_WRITE + $INTERNET_FLAG_TRANSFER_BINARY, 'dword_ptr', 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $ai_FTPGetSizeHandle[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
    Local $ai_FTPGetFileSize = DllCall($__g_hWinInet_FTP, 'dword', 'FtpGetFileSize', 'handle', $ai_FTPGetSizeHandle[0], 'dword*', 0)
    If @error Then
        Local $iError = @error
        Local $iExtended = @extended
        DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FTPGetSizeHandle[0])
        Return SetError($iError + 10, $iExtended, 0)
    EndIf
    DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FTPGetSizeHandle[0])
    Return _WinAPI_MakeQWord($ai_FTPGetFileSize[0], $ai_FTPGetFileSize[2])
EndFunc   ;==>_FTP_FileGetSize
Func _FTP_GetLastResponseInfo(ByRef $iError, ByRef $sMessage)
    Local $ai_LastResponseInfo = DllCall($__g_hWinInet_FTP, 'bool', 'InternetGetLastResponseInfoW', 'dword*', 0, 'wstr', "", 'dword*', 4096)
    If @error Or $ai_LastResponseInfo[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
    $iError = $ai_LastResponseInfo[1]
    $sMessage = $ai_LastResponseInfo[2]
    Return $ai_LastResponseInfo[0]
EndFunc   ;==>_FTP_GetLastResponseInfo
Func _FTP_Open($sAgent, $iAccessType = $INTERNET_OPEN_TYPE_DIRECT, $sProxyName = '', $sProxyBypass = '', $iFlags = 0)
    If $__g_hWinInet_FTP = -1 Then __FTP_Init()
    Local $ai_InternetOpen = DllCall($__g_hWinInet_FTP, 'handle', 'InternetOpenW', 'wstr', $sAgent, 'dword', $iAccessType, 'wstr', $sProxyName, 'wstr', $sProxyBypass, 'dword', $iFlags)
    If @error Or $ai_InternetOpen[0] = 0 Then Return SetError(@error + 10, _WinAPI_GetLastError(), 0)
    Return $ai_InternetOpen[0]
EndFunc   ;==>_FTP_Open
Func _FTP_ProgressDownload($hFTPSession, $sLocalFile, $sRemoteFile, $hFunctionToCall = 0)
    If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
    Local $hFile = FileOpen($sLocalFile, $FO_OVERWRITE + $FO_BINARY)
    If $hFile < 0 Then Return SetError(-1, 0, 0)
    Local $iLasterror, $iError
    Local $ai_FtpOpenfile = DllCall($__g_hWinInet_FTP, 'handle', 'FtpOpenFileW', 'handle', $hFTPSession, 'wstr', $sRemoteFile, 'dword', $GENERIC_READ, 'dword', $FTP_TRANSFER_TYPE_BINARY, 'dword_ptr', 0)
    If @error Or $ai_FtpOpenfile[0] = 0 Then
        $iError = @error
        $iLasterror = _WinAPI_GetLastError()
        FileClose($hFile)
        Return SetError($iError + 10, $iLasterror, 0)
    EndIf
    Local $ai_FTPGetFileSize = DllCall($__g_hWinInet_FTP, 'dword', 'FtpGetFileSize', 'handle', $ai_FtpOpenfile[0], 'dword*', 0)
    If @error Then
        $iError = @error
        DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FtpOpenfile[0])
        FileClose($hFile)
        Return SetError($iError + 20, 0, 0)
    EndIf
    If Not IsFunc($hFunctionToCall) Then ProgressOn("FTP Download", "Downloading " & $sLocalFile)
    Local $iLen = _WinAPI_MakeQWord($ai_FTPGetFileSize[0], $ai_FTPGetFileSize[2])
    Local Const $iChunkSize = 256 * 1024
    Local $iLast = Mod($iLen, $iChunkSize)
    Local $iParts = Ceiling($iLen / $iChunkSize)
    Local $tBuffer = DllStructCreate("byte[" & $iChunkSize & "]")
    Local $aCall, $ai_FTPread, $iOut, $iRet
    Local $x = $iChunkSize
    Local $iDone = 0
    For $i = 1 To $iParts
        If $i = $iParts And $iLast > 0 Then
            $x = $iLast
        EndIf
        $ai_FTPread = DllCall($__g_hWinInet_FTP, 'bool', 'InternetReadFile', 'handle', $ai_FtpOpenfile[0], 'struct*', $tBuffer, 'dword', $x, 'dword*', $iOut)
        If @error Or $ai_FTPread[0] = 0 Then
            $iError = @error
            $iLasterror = _WinAPI_GetLastError()
            DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FtpOpenfile[0])
            FileClose($hFile)
            If Not IsFunc($hFunctionToCall) Then ProgressOff()
            Return SetError($iError + 30, $iLasterror, 0)
        EndIf
        $iRet = FileWrite($hFile, BinaryMid(DllStructGetData($tBuffer, 1), 1, $ai_FTPread[4]))
        If Not $iRet Then
            $iLasterror = _WinAPI_GetLastError()
            DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FtpOpenfile[0])
            FileClose($hFile)
            FileDelete($sLocalFile)
            If Not IsFunc($hFunctionToCall) Then ProgressOff()
            Return SetError(-7, $iLasterror, 0)
        EndIf
        $iDone += $ai_FTPread[4]
        If Not IsFunc($hFunctionToCall) Then
            ProgressSet(($iDone / $iLen) * 100)
        Else
            $iRet = $hFunctionToCall(($iDone / $iLen) * 100)
            If $iRet <= 0 Then
                $iLasterror = @error
                DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FtpOpenfile[0])
                FileClose($hFile)
                FileDelete($sLocalFile)
                If Not IsFunc($hFunctionToCall) Then ProgressOff()
                Return SetError(-6, $iLasterror, $iRet)
            EndIf
        EndIf
        Sleep(10)
    Next
    FileClose($hFile)
    If Not IsFunc($hFunctionToCall) Then ProgressOff()
    $aCall = DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FtpOpenfile[0])
    If @error Or Not $aCall[0] Then
        Return SetError(@error + 40, _WinAPI_GetLastError(), 0)
    EndIf
    Return 1
EndFunc   ;==>_FTP_ProgressDownload
Func __FTP_Init()
    $__g_hWinInet_FTP = DllOpen('wininet.dll')
EndFunc   ;==>__FTP_Init
Func _WinAPI_CreateFileEx($sFilePath, $iCreation, $iAccess = 0, $iShare = 0, $iFlagsAndAttributes = 0, $tSecurity = 0, $hTemplate = 0)
    Local $aCall = DllCall('kernel32.dll', 'handle', 'CreateFileW', 'wstr', $sFilePath, 'dword', $iAccess, 'dword', $iShare, 'struct*', $tSecurity, 'dword', $iCreation, 'dword', $iFlagsAndAttributes, 'handle', $hTemplate)
    If @error Then Return SetError(@error, @extended, 0)
    If $aCall[0] = Ptr(-1) Then Return SetError(10, _WinAPI_GetLastError(), 0)
    Return $aCall[0]
EndFunc   ;==>_WinAPI_CreateFileEx
Func _WinAPI_Wow64EnableWow64FsRedirection($bEnable)
    Local $aCall = DllCall('kernel32.dll', 'boolean', 'Wow64EnableWow64FsRedirection', 'boolean', $bEnable)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aCall[0]
EndFunc   ;==>_WinAPI_Wow64EnableWow64FsRedirection
Func _StringBetween($sString, $sStart, $sEnd, $iMode = $STR_ENDISSTART, $bCase = False)
    $sStart = $sStart ? "\Q" & $sStart & "\E" : "\A"
    If $iMode <> $STR_ENDNOTSTART Then $iMode = $STR_ENDISSTART
    If $iMode = $STR_ENDISSTART Then
        $sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z"
    Else
        $sEnd = $sEnd ? "\Q" & $sEnd & "\E" : "\z"
    EndIf
    If $bCase = Default Then
        $bCase = False
    EndIf
    Local $aRet = StringRegExp($sString, "(?s" & (Not $bCase ? "i" : "") & ")" & $sStart & "(.*?)" & $sEnd, $STR_REGEXPARRAYGLOBALMATCH)
    If @error Then Return SetError(1, 0, 0)
    Return $aRet
EndFunc   ;==>_StringBetween
Func _WinHttpCloseHandle($hInternet)
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpCloseHandle", "handle", $hInternet)
    If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
    Return 1
EndFunc   ;==>_WinHttpCloseHandle
Func _WinHttpConnect($hSession, $sServerName, $iServerPort = Default)
    Local $aURL = _WinHttpCrackUrl($sServerName), $iScheme = 0
    If @error Then
        __WinHttpDefault($iServerPort, $INTERNET_DEFAULT_PORT)
    Else
        $sServerName = $aURL[2]
        $iServerPort = $aURL[3]
        $iScheme = $aURL[1]
    EndIf
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "handle", "WinHttpConnect", "handle", $hSession, "wstr", $sServerName, "dword", $iServerPort, "dword", 0)
    If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
    _WinHttpSetOption($aCall[0], $WINHTTP_OPTION_CONTEXT_VALUE, $iScheme)
    Return $aCall[0]
EndFunc   ;==>_WinHttpConnect
Func _WinHttpCrackUrl($sURL, $iFlag = Default)
    __WinHttpDefault($iFlag, $ICU_ESCAPE)
    Local $tURL_COMPONENTS = DllStructCreate("dword StructSize;" & "ptr SchemeName;" & "dword SchemeNameLength;" & "int Scheme;" & "ptr HostName;" & "dword HostNameLength;" & "word Port;" & "ptr UserName;" & "dword UserNameLength;" & "ptr Password;" & "dword PasswordLength;" & "ptr UrlPath;" & "dword UrlPathLength;" & "ptr ExtraInfo;" & "dword ExtraInfoLength")
    DllStructSetData($tURL_COMPONENTS, 1, DllStructGetSize($tURL_COMPONENTS))
    Local $tBuffers[6]
    Local $iURLLen = StringLen($sURL)
    For $i = 0 To 5
        $tBuffers[$i] = DllStructCreate("wchar[" & $iURLLen + 1 & "]")
    Next
    DllStructSetData($tURL_COMPONENTS, "SchemeNameLength", $iURLLen)
    DllStructSetData($tURL_COMPONENTS, "SchemeName", DllStructGetPtr($tBuffers[0]))
    DllStructSetData($tURL_COMPONENTS, "HostNameLength", $iURLLen)
    DllStructSetData($tURL_COMPONENTS, "HostName", DllStructGetPtr($tBuffers[1]))
    DllStructSetData($tURL_COMPONENTS, "UserNameLength", $iURLLen)
    DllStructSetData($tURL_COMPONENTS, "UserName", DllStructGetPtr($tBuffers[2]))
    DllStructSetData($tURL_COMPONENTS, "PasswordLength", $iURLLen)
    DllStructSetData($tURL_COMPONENTS, "Password", DllStructGetPtr($tBuffers[3]))
    DllStructSetData($tURL_COMPONENTS, "UrlPathLength", $iURLLen)
    DllStructSetData($tURL_COMPONENTS, "UrlPath", DllStructGetPtr($tBuffers[4]))
    DllStructSetData($tURL_COMPONENTS, "ExtraInfoLength", $iURLLen)
    DllStructSetData($tURL_COMPONENTS, "ExtraInfo", DllStructGetPtr($tBuffers[5]))
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpCrackUrl", "wstr", $sURL, "dword", $iURLLen, "dword", $iFlag, "struct*", $tURL_COMPONENTS)
    If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
    Local $aRet[8] = [DllStructGetData($tBuffers[0], 1), DllStructGetData($tURL_COMPONENTS, "Scheme"), DllStructGetData($tBuffers[1], 1), DllStructGetData($tURL_COMPONENTS, "Port"), DllStructGetData($tBuffers[2], 1), DllStructGetData($tBuffers[3], 1), DllStructGetData($tBuffers[4], 1), DllStructGetData($tBuffers[5], 1)]
    Return $aRet
EndFunc   ;==>_WinHttpCrackUrl
Func _WinHttpOpen($sUserAgent = Default, $iAccessType = Default, $sProxyName = Default, $sProxyBypass = Default, $iFlag = Default)
    __WinHttpDefault($sUserAgent, __WinHttpUA())
    __WinHttpDefault($iAccessType, $WINHTTP_ACCESS_TYPE_NO_PROXY)
    __WinHttpDefault($sProxyName, $WINHTTP_NO_PROXY_NAME)
    __WinHttpDefault($sProxyBypass, $WINHTTP_NO_PROXY_BYPASS)
    __WinHttpDefault($iFlag, 0)
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "handle", "WinHttpOpen", "wstr", $sUserAgent, "dword", $iAccessType, "wstr", $sProxyName, "wstr", $sProxyBypass, "dword", $iFlag)
    If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
    If $iFlag = $WINHTTP_FLAG_ASYNC Then _WinHttpSetOption($aCall[0], $WINHTTP_OPTION_CONTEXT_VALUE, $WINHTTP_FLAG_ASYNC)
    Return $aCall[0]
EndFunc   ;==>_WinHttpOpen
Func _WinHttpOpenRequest($hConnect, $sVerb = Default, $sObjectName = Default, $sVersion = Default, $sReferrer = Default, $sAcceptTypes = Default, $iFlags = Default)
    __WinHttpDefault($sVerb, "GET")
    __WinHttpDefault($sObjectName, "")
    __WinHttpDefault($sVersion, "HTTP/1.1")
    __WinHttpDefault($sReferrer, $WINHTTP_NO_REFERER)
    __WinHttpDefault($iFlags, $WINHTTP_FLAG_ESCAPE_DISABLE)
    Local $pAcceptTypes
    If $sAcceptTypes = Default Or Number($sAcceptTypes) = -1 Then
        $pAcceptTypes = $WINHTTP_DEFAULT_ACCEPT_TYPES
    Else
        Local $aTypes = StringSplit($sAcceptTypes, ",", 2)
        Local $tAcceptTypes = DllStructCreate("ptr[" & UBound($aTypes) + 1 & "]")
        Local $tType[UBound($aTypes)]
        For $i = 0 To UBound($aTypes) - 1
            $tType[$i] = DllStructCreate("wchar[" & StringLen($aTypes[$i]) + 1 & "]")
            DllStructSetData($tType[$i], 1, $aTypes[$i])
            DllStructSetData($tAcceptTypes, 1, DllStructGetPtr($tType[$i]), $i + 1)
        Next
        $pAcceptTypes = DllStructGetPtr($tAcceptTypes)
    EndIf
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "handle", "WinHttpOpenRequest", "handle", $hConnect, "wstr", StringUpper($sVerb), "wstr", $sObjectName, "wstr", StringUpper($sVersion), "wstr", $sReferrer, "ptr", $pAcceptTypes, "dword", $iFlags)
    If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
    Return $aCall[0]
EndFunc   ;==>_WinHttpOpenRequest
Func _WinHttpQueryAuthSchemes($hRequest, ByRef $iSupportedSchemes, ByRef $iFirstScheme, ByRef $iAuthTarget)
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpQueryAuthSchemes", "handle", $hRequest, "dword*", 0, "dword*", 0, "dword*", 0)
    If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
    $iSupportedSchemes = $aCall[2]
    $iFirstScheme = $aCall[3]
    $iAuthTarget = $aCall[4]
    Return 1
EndFunc   ;==>_WinHttpQueryAuthSchemes
Func _WinHttpQueryDataAvailable($hRequest)
    Local $sReadType = "dword*"
    If BitAND(_WinHttpQueryOption(_WinHttpQueryOption(_WinHttpQueryOption($hRequest, $WINHTTP_OPTION_PARENT_HANDLE), $WINHTTP_OPTION_PARENT_HANDLE), $WINHTTP_OPTION_CONTEXT_VALUE), $WINHTTP_FLAG_ASYNC) Then $sReadType = "ptr"
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpQueryDataAvailable", "handle", $hRequest, $sReadType, 0)
    If @error Then Return SetError(1, 0, 0)
    Return SetExtended($aCall[2], $aCall[0])
EndFunc   ;==>_WinHttpQueryDataAvailable
Func _WinHttpQueryHeaders($hRequest, $iInfoLevel = Default, $sName = Default, $iIndex = Default)
    __WinHttpDefault($iInfoLevel, $WINHTTP_QUERY_RAW_HEADERS_CRLF)
    __WinHttpDefault($sName, $WINHTTP_HEADER_NAME_BY_INDEX)
    __WinHttpDefault($iIndex, $WINHTTP_NO_HEADER_INDEX)
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpQueryHeaders", "handle", $hRequest, "dword", $iInfoLevel, "wstr", $sName, "wstr", "", "dword*", 65536, "dword*", $iIndex)
    If @error Or Not $aCall[0] Then Return SetError(1, 0, "")
    Return SetExtended($aCall[6], $aCall[4])
EndFunc   ;==>_WinHttpQueryHeaders
Func _WinHttpQueryOption($hInternet, $iOption)
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpQueryOption", "handle", $hInternet, "dword", $iOption, "ptr", 0, "dword*", 0)
    If @error Or $aCall[0] Then Return SetError(1, 0, "")
    Local $iSize = $aCall[4]
    Local $tBuffer
    Switch $iOption
        Case $WINHTTP_OPTION_CONNECTION_INFO, $WINHTTP_OPTION_PASSWORD, $WINHTTP_OPTION_PROXY_PASSWORD, $WINHTTP_OPTION_PROXY_USERNAME, $WINHTTP_OPTION_URL, $WINHTTP_OPTION_USERNAME, $WINHTTP_OPTION_USER_AGENT, $WINHTTP_OPTION_PASSPORT_COBRANDING_TEXT, $WINHTTP_OPTION_PASSPORT_COBRANDING_URL
            $tBuffer = DllStructCreate("wchar[" & $iSize + 1 & "]")
        Case $WINHTTP_OPTION_PARENT_HANDLE, $WINHTTP_OPTION_CALLBACK, $WINHTTP_OPTION_SERVER_CERT_CONTEXT
            $tBuffer = DllStructCreate("ptr")
        Case $WINHTTP_OPTION_CONNECT_TIMEOUT, $WINHTTP_AUTOLOGON_SECURITY_LEVEL_HIGH, $WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW, $WINHTTP_AUTOLOGON_SECURITY_LEVEL_MEDIUM, $WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH, $WINHTTP_OPTION_CONNECT_RETRIES, $WINHTTP_OPTION_EXTENDED_ERROR, $WINHTTP_OPTION_HANDLE_TYPE, $WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER, $WINHTTP_OPTION_MAX_CONNS_PER_SERVER, $WINHTTP_OPTION_MAX_HTTP_AUTOMATIC_REDIRECTS, $WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, $WINHTTP_OPTION_RECEIVE_TIMEOUT, $WINHTTP_OPTION_RESOLVE_TIMEOUT, $WINHTTP_OPTION_SECURITY_FLAGS, $WINHTTP_OPTION_SECURITY_KEY_BITNESS, $WINHTTP_OPTION_SEND_TIMEOUT
            $tBuffer = DllStructCreate("int")
        Case $WINHTTP_OPTION_CONTEXT_VALUE
            $tBuffer = DllStructCreate("dword_ptr")
        Case Else
            $tBuffer = DllStructCreate("byte[" & $iSize & "]")
    EndSwitch
    $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpQueryOption", "handle", $hInternet, "dword", $iOption, "struct*", $tBuffer, "dword*", $iSize)
    If @error Or Not $aCall[0] Then Return SetError(2, 0, "")
    Return DllStructGetData($tBuffer, 1)
EndFunc   ;==>_WinHttpQueryOption
Func _WinHttpReadData($hRequest, $iMode = Default, $iNumberOfBytesToRead = Default, $pBuffer = Default)
    __WinHttpDefault($iMode, 0)
    __WinHttpDefault($iNumberOfBytesToRead, 8192)
    Local $tBuffer, $vOutOnError = ""
    If $iMode = 2 Then $vOutOnError = Binary($vOutOnError)
    Switch $iMode
        Case 1, 2
            If $pBuffer And $pBuffer <> Default Then
                $tBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]", $pBuffer)
            Else
                $tBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]")
            EndIf
        Case Else
            $iMode = 0
            If $pBuffer And $pBuffer <> Default Then
                $tBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]", $pBuffer)
            Else
                $tBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]")
            EndIf
    EndSwitch
    Local $sReadType = "dword*"
    If BitAND(_WinHttpQueryOption(_WinHttpQueryOption(_WinHttpQueryOption($hRequest, $WINHTTP_OPTION_PARENT_HANDLE), $WINHTTP_OPTION_PARENT_HANDLE), $WINHTTP_OPTION_CONTEXT_VALUE), $WINHTTP_FLAG_ASYNC) Then $sReadType = "ptr"
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpReadData", "handle", $hRequest, "struct*", $tBuffer, "dword", $iNumberOfBytesToRead, $sReadType, 0)
    If @error Or Not $aCall[0] Then Return SetError(1, 0, "")
    If Not $aCall[4] Then Return SetError(-1, 0, $vOutOnError)
    If $aCall[4] < $iNumberOfBytesToRead Then
        Switch $iMode
            Case 0
                Return SetExtended($aCall[4], StringLeft(DllStructGetData($tBuffer, 1), $aCall[4]))
            Case 1
                Return SetExtended($aCall[4], BinaryToString(BinaryMid(DllStructGetData($tBuffer, 1), 1, $aCall[4]), 4))
            Case 2
                Return SetExtended($aCall[4], BinaryMid(DllStructGetData($tBuffer, 1), 1, $aCall[4]))
        EndSwitch
    Else
        Switch $iMode
            Case 0, 2
                Return SetExtended($aCall[4], DllStructGetData($tBuffer, 1))
            Case 1
                Return SetExtended($aCall[4], BinaryToString(DllStructGetData($tBuffer, 1), 4))
        EndSwitch
    EndIf
EndFunc   ;==>_WinHttpReadData
Func _WinHttpReceiveResponse($hRequest)
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpReceiveResponse", "handle", $hRequest, "ptr", 0)
    If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
    Return 1
EndFunc   ;==>_WinHttpReceiveResponse
Func _WinHttpSendRequest($hRequest, $sHeaders = Default, $vOptional = Default, $iTotalLength = Default, $iContext = Default)
    __WinHttpDefault($sHeaders, $WINHTTP_NO_ADDITIONAL_HEADERS)
    __WinHttpDefault($vOptional, $WINHTTP_NO_REQUEST_DATA)
    __WinHttpDefault($iTotalLength, 0)
    __WinHttpDefault($iContext, 0)
    Local $pOptional = 0, $iOptionalLength = 0
    If @NumParams > 2 Then
        Local $tOptional
        $iOptionalLength = BinaryLen($vOptional)
        $tOptional = DllStructCreate("byte[" & $iOptionalLength & "]")
        If $iOptionalLength Then $pOptional = DllStructGetPtr($tOptional)
        DllStructSetData($tOptional, 1, $vOptional)
    EndIf
    If Not $iTotalLength Or $iTotalLength < $iOptionalLength Then $iTotalLength += $iOptionalLength
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpSendRequest", "handle", $hRequest, "wstr", $sHeaders, "dword", 0, "ptr", $pOptional, "dword", $iOptionalLength, "dword", $iTotalLength, "dword_ptr", $iContext)
    If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
    Return 1
EndFunc   ;==>_WinHttpSendRequest
Func _WinHttpSetCredentials($hRequest, $iAuthTargets, $iAuthScheme, $sUserName, $sPassword)
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpSetCredentials", "handle", $hRequest, "dword", $iAuthTargets, "dword", $iAuthScheme, "wstr", $sUserName, "wstr", $sPassword, "ptr", 0)
    If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
    Return 1
EndFunc   ;==>_WinHttpSetCredentials
Func _WinHttpSetOption($hInternet, $iOption, $vSetting, $iSize = Default)
    If $iSize = Default Then $iSize = -1
    If IsBinary($vSetting) Then
        $iSize = DllStructCreate("byte[" & BinaryLen($vSetting) & "]")
        DllStructSetData($iSize, 1, $vSetting)
        $vSetting = $iSize
        $iSize = DllStructGetSize($vSetting)
    EndIf
    Local $sType
    Switch $iOption
        Case $WINHTTP_OPTION_AUTOLOGON_POLICY, $WINHTTP_OPTION_CODEPAGE, $WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH, $WINHTTP_OPTION_CONNECT_RETRIES, $WINHTTP_OPTION_CONNECT_TIMEOUT, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_OPTION_ENABLE_FEATURE, $WINHTTP_OPTION_ENABLETRACING, $WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER, $WINHTTP_OPTION_MAX_CONNS_PER_SERVER, $WINHTTP_OPTION_MAX_HTTP_AUTOMATIC_REDIRECTS, $WINHTTP_OPTION_MAX_HTTP_STATUS_CONTINUE, $WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE, $WINHTTP_OPTION_MAX_RESPONSE_HEADER_SIZE, $WINHTTP_OPTION_READ_BUFFER_SIZE, $WINHTTP_OPTION_RECEIVE_TIMEOUT, $WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, $WINHTTP_OPTION_REDIRECT_POLICY, $WINHTTP_OPTION_REJECT_USERPWD_IN_URL, $WINHTTP_OPTION_REQUEST_PRIORITY, $WINHTTP_OPTION_RESOLVE_TIMEOUT, $WINHTTP_OPTION_SECURE_PROTOCOLS, $WINHTTP_OPTION_SECURITY_FLAGS, $WINHTTP_OPTION_SECURITY_KEY_BITNESS, $WINHTTP_OPTION_SEND_TIMEOUT, $WINHTTP_OPTION_SPN, $WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS, $WINHTTP_OPTION_WORKER_THREAD_COUNT, $WINHTTP_OPTION_WRITE_BUFFER_SIZE, $WINHTTP_OPTION_DECOMPRESSION, $WINHTTP_OPTION_UNSAFE_HEADER_PARSING
            $sType = "dword*"
            $iSize = 4
        Case $WINHTTP_OPTION_CALLBACK, $WINHTTP_OPTION_PASSPORT_SIGN_OUT
            $sType = "ptr*"
            $iSize = 4
            If @AutoItX64 Then $iSize = 8
            If Not IsPtr($vSetting) Then Return SetError(3, 0, 0)
        Case $WINHTTP_OPTION_CONTEXT_VALUE
            $sType = "dword_ptr*"
            $iSize = 4
            If @AutoItX64 Then $iSize = 8
        Case $WINHTTP_OPTION_PASSWORD, $WINHTTP_OPTION_PROXY_PASSWORD, $WINHTTP_OPTION_PROXY_USERNAME, $WINHTTP_OPTION_USER_AGENT, $WINHTTP_OPTION_USERNAME
            $sType = "wstr"
            If (IsDllStruct($vSetting) Or IsPtr($vSetting)) Then Return SetError(3, 0, 0)
            If $iSize < 1 Then $iSize = StringLen($vSetting)
        Case $WINHTTP_OPTION_CLIENT_CERT_CONTEXT, $WINHTTP_OPTION_GLOBAL_PROXY_CREDS, $WINHTTP_OPTION_GLOBAL_SERVER_CREDS, $WINHTTP_OPTION_HTTP_VERSION, $WINHTTP_OPTION_PROXY
            $sType = "ptr"
            If Not (IsDllStruct($vSetting) Or IsPtr($vSetting)) Then Return SetError(3, 0, 0)
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch
    If $iSize < 1 Then
        If IsDllStruct($vSetting) Then
            $iSize = DllStructGetSize($vSetting)
        Else
            Return SetError(2, 0, 0)
        EndIf
    EndIf
    Local $aCall
    If IsDllStruct($vSetting) Then
        $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpSetOption", "handle", $hInternet, "dword", $iOption, $sType, DllStructGetPtr($vSetting), "dword", $iSize)
    Else
        $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpSetOption", "handle", $hInternet, "dword", $iOption, $sType, $vSetting, "dword", $iSize)
    EndIf
    If @error Or Not $aCall[0] Then Return SetError(4, 0, 0)
    Return 1
EndFunc   ;==>_WinHttpSetOption
Func _WinHttpSimpleFormFill_SetUploadCallback($vCallback = Default, $iNumChunks = 100)
    If $iNumChunks <= 0 Then $iNumChunks = 100
    Local Static $vFunc = Default, $iParts = $iNumChunks
    If $vCallback <> Default Then
        $vFunc = $vCallback
        $iParts = Ceiling($iNumChunks)
    ElseIf $vCallback = 0 Then
        $vFunc = Default
        $iParts = 1
    EndIf
    Local $aOut[2] = [$vFunc, $iParts]
    Return $aOut
EndFunc   ;==>_WinHttpSimpleFormFill_SetUploadCallback
Func _WinHttpSimpleReadData($hRequest, $iMode = Default)
    If $iMode = Default Then
        $iMode = 0
        If __WinHttpCharSet(_WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_TYPE)) = 65001 Then $iMode = 1
    Else
        __WinHttpDefault($iMode, 0)
    EndIf