Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/14/2020 in all areas

  1. thanks for your hints! Thats what I call a productive interaction!
    1 point
  2. pixelsearch, Hurrah! And as we in Spain are now virtually confined to our houses for the next 2 weeks (at least) thanks to Covid-19 I will have plenty of time to look at any other nice little bugs you can find. Over to you! M23
    1 point
  3. Hi Melba23, Right, that line you added in the new beta solved the last issue : Func __GUIListViewEx_Array_Delete(ByRef $avArray, $iIndex, $bDelCount = False) ... ; Do not overwrite count row If $iIndex = 0 Then $iIndex = 1 Only now, both pictures posted here appear correctly : * 1st picture still shows "6" in row 0, col 0 (correct) * 2nd picture now shows "5" in row 0, col 0 (correct) and not "-1" anymore Bravo for the quick fix
    1 point
  4. pixelsearch, Fixed that one - try again! M23
    1 point
  5. Nine

    Regex get month and year

    Maybe this ? #include <Constants.au3> #include <Array.au3> Local $aTxt = ["my_business_03_2020", "03 my business 2020"] For $sTxt in $aTxt $arr = StringRegExp ($sTxt, "\D?(\d{2}|\d{4})(?=\D|$)", 3) _ArrayDisplay ($arr) Next
    1 point
  6. ahmet

    Regex get month and year

    Can this help $sTestString="my_business_032020" $btest=StringRegExp($sTestString,".*\d\d.*\d\d\d\d") MsgBox(0,"Test",($btest ? "There is" : "There is not") & " date") You can look at regex101.com for explanation
    1 point
  7. Look here at my posts about SendMessage + WM_COMMAND & Winspector:
    1 point
  8. The error described by @pixelsearch does no longer arise. So your fix seems to work .
    1 point
  9. If you ever tried to download some remote file from your script using InetGet(), InetRead() or other download functions, you probably noticed that the download speed was never as good as when you try to download the same file using a download manager. But that's over, you won't lack the high speed download capability of download managers in your AutoIt scripts, not anymore. Enjoy: #include-once #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <WinHttp.au3> ;http://www.autoitscript.com/forum/topic/84133-winhttp-functions/ #include <FileConstants.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: UrlDownloadEx ; Description ...: Download a single file by splitting it in segments and using several simultaneous connections to download these segments from a single server. ; Syntax ........: UrlDownloadEx($sUrl [, $sFileName = Default [, $iNumberOfConnections = Default [, $CallbackFunction = Default [, $vParam = 0]]]]) ; Parameters ....: $sUrl - Url of the file to download. ; $sFileName - [optional] Local filename to download to. Default is "". ; $iNumberOfConnections - [optional] Number of simultaneous connections. Default is 8. ; $CallbackFunction - [optional] An application-defined callback function to call when progress is made. Default is Null. ; $vParam - [optional] An application-defined value to be passed to the callback function. Default is 0. ; Return values .: Success - Returns a binary string if file name is not supplied. ; - Returns 1 if file name is supplied ; - @extended receives the number of received bytes. ; Failure - Returns 0 and sets @error: ; |1 - Invalid number of connections ; |2 - Invalid callback function ; |3 - Invalid url ; |4 - _WinHttpOpen failed ; |5 - _WinHttpConnect failed ; |6 - _WinHttpOpenRequest failed ; |7 - _WinHttpSendRequest failed ; |8 - _WinHttpReceiveResponse failed ; |9 - _WinHttpQueryHeaders failed ; |10 - _WinHttpOpenRequest failed, while trying to create multiple request ; |11 - _WinHttpQueryHeaders failed, while trying to prepare multiple request ; |12 - Not enough memory to allocate buffer ; |13 - _WinHttpQueryDataAvailable failed ; |14 - Download aborted, callback function returned False ; |15 - FileOpen failed ; |16 - FileWrite failed ; Author ........: FaridAgl ; Remarks .......: The Url parameter should be in the form "http://www.somesite.com/path/file.html", just like an address you would type into your web browser. ; + Please use a high number of connections with caution. Some servers may have specific limitations for a number of connections from one client, when the number of connections is high, the servers can put your computer to a black list. ; + For some connection types or for low performance computers or routers, the download speed may decrease when you increase the number of connections. ; + The callback function is called with the following parameters: $iReceivedBytes, $iTotalReceivedBytes, $iDownloadSize, $vParam ; + To continue downloading, the callback function must return True; to stop downloading, it must return False. ; Example .......: Yes ; =============================================================================================================================== Func UrlDownloadEx($sUrl, $sFileName = Default, $iNumberOfConnections = Default, $CallbackFunction = Default, $vParam = 0) If ($sFileName = Default Or $sFileName = -1) Then $sFileName = "" If ($iNumberOfConnections = Default Or $iNumberOfConnections = -1) Then $iNumberOfConnections = 8 ElseIf (IsInt($iNumberOfConnections) = 0 Or $iNumberOfConnections < 1) Then Return SetError(1, 0, 0) EndIf If ($CallbackFunction = Default Or $CallbackFunction = -1) Then $CallbackFunction = Null Else If (IsFunc($CallbackFunction) = 0) Then Return SetError(2, 0, 0) EndIf Local $avUrlComponents = _WinHttpCrackUrl($sUrl, $ICU_DECODE) If ($avUrlComponents = 0) Then Return SetError(3, 0, 0) Local Const $SERVER_NAME = $avUrlComponents[2] Local Const $OBJECT_NAME = $avUrlComponents[6] Local Const $SERVER_PORT = $avUrlComponents[3] Local Const $FLAGS = ($avUrlComponents[1] = $INTERNET_SCHEME_HTTPS) ? ($WINHTTP_FLAG_SECURE) : (0) Local $hSession = _WinHttpOpen("Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))", $WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, $WINHTTP_NO_PROXY_NAME, $WINHTTP_NO_PROXY_BYPASS, 0) If ($hSession = 0) Then Return SetError(4, 0, 0) Local $hConnect = _WinHttpConnect($hSession, $SERVER_NAME, $SERVER_PORT) If ($hConnect = 0) Then _WinHttpCloseHandle($hSession) Return SetError(5, 0, 0) EndIf Local $hRequest = _WinHttpOpenRequest($hConnect, "GET", $OBJECT_NAME, 0, $WINHTTP_NO_REFERER, $WINHTTP_DEFAULT_ACCEPT_TYPES, $FLAGS) If ($hRequest = 0) Then _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hSession) Return SetError(6, 0, 0) EndIf If (_WinHttpSendRequest($hRequest, "Range: bytes=0-0", $WINHTTP_NO_REQUEST_DATA, 0, 0) = 0) Then _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hSession) Return SetError(7, 0, 0) EndIf If (_WinHttpReceiveResponse($hRequest) = 0) Then _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hSession) Return SetError(8, 0, 0) EndIf Local $sStatusCode = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_STATUS_CODE, $WINHTTP_HEADER_NAME_BY_INDEX, $WINHTTP_NO_HEADER_INDEX) If (Int($sStatusCode, 1) <> $HTTP_STATUS_PARTIAL_CONTENT) Then _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hSession) Return SetError(9, 0, 0) EndIf Local $sContentRange = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_RANGE, $WINHTTP_HEADER_NAME_BY_INDEX, $WINHTTP_NO_HEADER_INDEX) _WinHttpCloseHandle($hRequest) Local Enum $REQUEST_HANDLE, $RECEIVED_BYTES, $DOWNLOAD_OFFSET, $BYTES_TO_DOWNLOAD Local $avConnections[$iNumberOfConnections][4] Local $iDownloadSize = Int(StringTrimLeft($sContentRange, StringLen("bytes 0-0/")), 1) Local $iDownloadSizePerConnection = Floor($iDownloadSize / $iNumberOfConnections) Local $iLastByteToDownload = 0 For $i = 0 To $iNumberOfConnections - 1 $avConnections[$i][$REQUEST_HANDLE] = _WinHttpOpenRequest($hConnect, "GET", $OBJECT_NAME, 0, $WINHTTP_NO_REFERER, $WINHTTP_DEFAULT_ACCEPT_TYPES, $FLAGS) If ($avConnections[$i][$REQUEST_HANDLE] = 0) Then For $j = $i - 1 To 0 Step -1 _WinHttpCloseHandle($avConnections[$j][$REQUEST_HANDLE]) Next _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hSession) Return SetError(10, 0, 0) EndIf $avConnections[$i][$RECEIVED_BYTES] = 0 $avConnections[$i][$DOWNLOAD_OFFSET] = $i * $iDownloadSizePerConnection If ($i <> $iNumberOfConnections - 1) Then $avConnections[$i][$BYTES_TO_DOWNLOAD] = $iDownloadSizePerConnection $iLastByteToDownload = $avConnections[$i][$DOWNLOAD_OFFSET] + $iDownloadSizePerConnection - 1 Else $avConnections[$i][$BYTES_TO_DOWNLOAD] = $iDownloadSizePerConnection + Mod($iDownloadSize, $iNumberOfConnections) $iLastByteToDownload = $iDownloadSize - 1 EndIf _WinHttpSendRequest($avConnections[$i][$REQUEST_HANDLE], "Range: bytes=" & $avConnections[$i][$DOWNLOAD_OFFSET] & "-" & $iLastByteToDownload, $WINHTTP_NO_REQUEST_DATA, 0, 0) _WinHttpReceiveResponse($avConnections[$i][$REQUEST_HANDLE]) $sStatusCode = _WinHttpQueryHeaders($avConnections[$i][$REQUEST_HANDLE], $WINHTTP_QUERY_STATUS_CODE, $WINHTTP_HEADER_NAME_BY_INDEX, $WINHTTP_NO_HEADER_INDEX) If (Int($sStatusCode, 1) <> $HTTP_STATUS_PARTIAL_CONTENT) Then For $j = $i - 1 To 0 Step -1 _WinHttpCloseHandle($avConnections[$j][$REQUEST_HANDLE]) Next _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hSession) Return SetError(11, 0, 0) EndIf Next Local $tBuffer = DllStructCreate("BYTE[" & $iDownloadSize & "]") If (@error) Then Return SetError(12, 0, 0) Local $pBuffer = DllStructGetPtr($tBuffer) Local $iTotalReceivedBytes = 0 While (True) For $i = 0 To $iNumberOfConnections - 1 If ($avConnections[$i][$RECEIVED_BYTES] = $avConnections[$i][$BYTES_TO_DOWNLOAD]) Then ContinueLoop If (_WinHttpQueryDataAvailable($avConnections[$i][$REQUEST_HANDLE]) = 1) Then $iTotalReceivedBytes += @extended _WinHttpReadData($avConnections[$i][$REQUEST_HANDLE], 2, @extended, $pBuffer + $avConnections[$i][$DOWNLOAD_OFFSET] + $avConnections[$i][$RECEIVED_BYTES]) $avConnections[$i][$RECEIVED_BYTES] += @extended If ($CallbackFunction <> Null) Then If ($CallbackFunction(@extended, $iTotalReceivedBytes, $iDownloadSize, $vParam) = False) Then For $j = 0 To $iNumberOfConnections - 1 If ($avConnections[$j][$REQUEST_HANDLE] > 0) Then _WinHttpCloseHandle($avConnections[$j][$REQUEST_HANDLE]) Next _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hSession) Return SetError(14, 0, 0) EndIf EndIf If ($avConnections[$i][$RECEIVED_BYTES] = $avConnections[$i][$BYTES_TO_DOWNLOAD]) Then _WinHttpCloseHandle($avConnections[$i][$REQUEST_HANDLE]) $avConnections[$i][$REQUEST_HANDLE] = 0 EndIf Else For $j = 0 To $iNumberOfConnections - 1 If ($avConnections[$j][$REQUEST_HANDLE] > 0) Then _WinHttpCloseHandle($avConnections[$j][$REQUEST_HANDLE]) Next _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hSession) Return SetError(13, 0, 0) EndIf Next If ($iTotalReceivedBytes = $iDownloadSize) Then _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hSession) ExitLoop EndIf WEnd If ($sFileName <> "") Then Local $hFile = FileOpen($sFileName, BitOR($FO_OVERWRITE, $FO_CREATEPATH, $FO_BINARY)) If ($hFile = -1) Then Return SetError(15, 0, 0) If (FileWrite($hFile, DllStructGetData($tBuffer, 1)) = 0) Then FileClose($hFile) Return SetError(16, 0, 0) EndIf FileClose($hFile) Return SetError(0, $iDownloadSize, 1) EndIf Return SetError(0, $iDownloadSize, DllStructGetData($tBuffer, 1)) EndFunc Example 1 - Download to a local file and use callback function to monitor and control the download progress: #include "UrlDownloadEx.au3" Global $t1 = TimerInit() Global $vResult = UrlDownloadEx("http://www.autoitscript.com/files/autoit3/autoit-v3-setup.exe", @ScriptDir & "\AutoIt 3.3.12.0.exe", Default, BytesReceived) ConsoleWrite(StringFormat("Result:\t%s\nSize:\t%u\nError:\t%u\nTimer:\t%u\n", $vResult, @extended, @error, TimerDiff($t1))) Func BytesReceived($iReceivedBytes, $iTotalReceivedBytes, $iDownloadSize, $vParam) If ($iTotalReceivedBytes >= 2 * 1024 * 1024) Then Return False ;Stop downloading ConsoleWrite(StringFormat("%u bytes received.\n%u/%u\nParam: %s\n\n", $iReceivedBytes, $iTotalReceivedBytes, $iDownloadSize, $vParam)) Return True ;Continue downloading EndFunc Example 2 - Download to memory and set the number of connections to 2: #include "UrlDownloadEx.au3" Global $t1 = TimerInit() Global $vResult = UrlDownloadEx("http://icdn4.digitaltrends.com/image/microsoft_xp_bliss_desktop_image-650x0.jpg", Default, 2) ConsoleWrite(StringFormat("Result:\t%s\nSize:\t%u\nError:\t%u\nTimer:\t%u\n", $vResult, @extended, @error, TimerDiff($t1))) You can also download all of the above scripts at once: UrlDownloadEx + Examples.zip
    1 point
×
×
  • Create New...