Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/12/2011 in all areas

  1. guinness

    Help With Progress Bar

    What Version of AutoIt are you using? Because I have V3.3.6.1 and @InetGetActive is no longer used in this Version, the clues were in JLogan3o13's Version Have a look at this though Hope it's what you wanted?! Function: ; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _InetGetProgress ; AutoIt Version : v3.3.2.0 or higher ; Language ......: English ; Description ...: Download a file showing a progress bar using ProgressOn. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _InetGetProgress: Download a file showing a progress bar using ProgressOn. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; _ByteSuffix ......; Convert bytes to the largest measure. Thanks to Spliff69 - http://www.autoitscript.com/forum/topic/116897-folder-sync-tool/page__view__findpost__p__815328 ; =============================================================================================================================== ; #FUNCTION# ========================================================================================================= ; Name...........: _InetGetProgress() ; Description ...: Download a file showing a progress bar using ProgressOn. ; Syntax.........: _InetGetProgress($sURL, [$sDirectory = @ScriptDir]) ; $sURL - A valid URL that contains the filename too. ; $sDirectory - [Optional] Directory of where to download to @ScriptDir ; Parameters ....: None ; Requirement(s).: v3.3.2.0 or higher ; Return values .: Success - Downloaded filename. ; Failure - Returns downloaded filename & sets @error = 1 ; Author ........: guinness ; Example........; Yes ;===================================================================================================================== Func _InetGetProgress($sURL, $sDirectory = @ScriptDir) Local $hDownload, $iBytesRead = 0, $iFileSize, $iPercentage, $iSpeed = 0, $iTimer = 0, $sFilePath, $sProgressText, $sSpeed $sFilePath = StringRegExpReplace($sURL, "^.*/", "") If @error Then Return SetError(1, 0, $sFilePath) EndIf $sDirectory = StringRegExpReplace($sDirectory, "[\\/]+\z", "") & "\" & $sFilePath $iFileSize = InetGetSize($sURL, 1) $hDownload = InetGet($sURL, $sDirectory, 0, 1) If @error Then Return SetError(1, 0, $sFilePath) EndIf ProgressOn("", "") $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s" $iTimer = TimerInit() While InetGetInfo($hDownload, 2) = 0 $iBytesRead = InetGetInfo($hDownload, 0) $iPercentage = $iBytesRead * 100 / $iFileSize $sProgressText = "Downloading " & _ByteSuffix($iBytesRead, 0) & " Of " & _ByteSuffix($iFileSize, 0) & @LF & $sSpeed ProgressSet(Round($iPercentage, 0), $sProgressText, "Downloading: " & $sFilePath) If TimerDiff($iTimer) > 1000 Then $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s" $iSpeed = $iBytesRead $iTimer = TimerInit() EndIf Sleep(100) WEnd InetClose($hDownload) ProgressOff() Return $sFilePath EndFunc ;==>_InetGetProgress ; #INTERNAL_USE_ONLY#============================================================================================================ Func _ByteSuffix($iBytes, $iRound = 2) Local $A, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"] While $iBytes > 1023 $A += 1 $iBytes /= 1024 WEnd Return Round($iBytes, $iRound) & $aArray[$A] EndFunc ;==>_ByteSuffix ; #INTERNAL_USE_ONLY#============================================================================================================Example use of Function: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 Global $sFilePath, $sFileURL $sFileURL = "http://ftp.opera.com/pub/opera/win/1152/en/Opera_1152_en_Setup.exe" $sFilePath = _InetGetProgress($sFileURL, @TempDir & "\") If @error Then MsgBox(64, "Error", "Check the URL or your Internet Connection!") Else MsgBox(64, "Success", "Downloaded >> " & $sFilePath) EndIf
    1 point
×
×
  • Create New...