Sign in to follow this  
Followers 0
HAL9000

How to show a progress bar during download?

9 posts in this topic

How to show a progress bar during download?

with old version of autoit, i used

$size = InetGetSize("link")
While @InetGetActive
GUICtrlSetData ($progressbar,Ceiling((@InetGetBytesRead/$size)*100))
Wend

but with new version i have problems to do the same thing with InetGetInfo

Share this post


Link to post
Share on other sites



How to show a progress bar during download?

with old version of autoit, i used

$size = InetGetSize("link")
While @InetGetActive
GUICtrlSetData ($progressbar,Ceiling((@InetGetBytesRead/$size)*100))
Wend

but with new version i have problems to do the same thing with InetGetInfo

$handle = InetGet("link")
InetGetSize("link") = InetGetInfo($handle,1)
@InetGetActive = InetGetInfo($handle,2)
@InetGetBytesRead = InetGetInfo($handle,0)

This was all in the help file and explained very well. If you need more info on this, I would start there. I've never actually used these functions before and was able to find the info in under 60 seconds. So in the future, I would do a little leg work before you ask someone to help you. That will make people want to help you more, knowing that you've actually tried first.

-Aaron

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Not sure if this is the best, most efficient way to do it, but here's what I've done:

ProgressOn("Download", "Downloading...", "0%")
$url= "http://www.domain.com/folder/file.txt" ;Set URL
$folder = @MyDocumentsDir & "\downloads\" ;Set folder
$hInet = InetGet($url, $folder, 1, 1) ;Forces a reload from the remote site and return immediately and download in the background
$FileSize = InetGetSize($url) ;Get file size
While Not InetGetInfo($hInet, 2) ;Loop until download is finished
    Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
    $BytesReceived = InetGetInfo($hInet, 0) ;Get bytes received
    $Pct = Int($BytesReceived / $FileSize * 100) ;Calculate percentage
    ProgressSet($Pct, $Pct & "%") ;Set progress bar
WEnd
ProgressOff()
Edited by GMK

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

How to show a progress bar during download?

For example...

#include <Math.au3> 
    
$_FinalUrl = 'http://www.birdscanfly.com/images/bcf_wallpaper_1440.jpg'
$_TempPath = @TempDir & '\bcf_wallpaper_1440.jpg'
$_FileSize = InetGetSize ( $_FinalUrl )
$_Gui = GUICreate ( "" )
$_ProgressBar = GUICtrlCreateProgress ( 5, 25, 350, 23 )
GUISetState ( @SW_SHOW )
$_Download = InetGet ( $_FinalUrl, $_TempPath, 1, 1 )
Local $_InfoData
Do
    $_InfoData = InetGetInfo ( $_Download )
    If Not @error Then
        $_InetGet = $_InfoData[0]
        $_DownloadPercent = Round ( ( 100 * $_InetGet ) / $_FileSize )
        $_DownloadPercent = _Min ( _Max ( 1, $_DownloadPercent ), 99 )
        GUICtrlSetData ( $_ProgressBar, $_DownloadPercent )
        $_Label = GUICtrlCreateLabel ( 'progress : ' & $_DownloadPercent & ' %', 5, 52, 350, 20 )  
    EndIf
    Sleep ( 100 )    
Until $_InfoData[2] = True
$_Label = GUICtrlCreateLabel ( 'Download successfull !', 5, 52, 350, 20 )  
Sleep ( 2000 )

sorry GMK, i doesn't see your post ! Posted Image

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

@FlyinRiz - seems you have an old version of AutoIt as @InetGetActive and @InetGetBytesRead were removed in V3.3.4.0

This was pulled from the HelpFile, but the examples shown above seem to do the trick.

#Alternate
Local $hDownload = InetGet("http://www.autoitscript.com/autoit3/files/beta/update.dat", @TempDir & "\update.dat", 1, 1)
Do
    Sleep(250)
Until InetGetInfo($hDownload, 2)    ; Check if the download is complete.
Local $aData = InetGetInfo($hDownload)  ; Get all information.
InetClose($hDownload)   ; Close the handle to release resourcs.
MsgBox(0, "", "Bytes read: " & $aData[0] & @CRLF & _
    "Size: " & $aData[1] & @CRLF & _
    "Complete?: " & $aData[2] & @CRLF & _
    "Successful?: " & $aData[3] & @CRLF & _
    "@error: " & $aData[4] & @CRLF & _
    "@extended: " & $aData[5] & @CRLF)

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Not sure if this is the best, most efficient way to do it, but here's what I've done:

ProgressOn("Download", "Downloading...", "0%")
$url= "http://www.domain.com/folder/file.txt" ;Set URL
$folder = @MyDocumentsDir & "\downloads\" ;Set folder
$hInet = InetGet($url, $folder, 1, 1) ;Forces a reload from the remote site and return immediately and download in the background
$FileSize = InetGetSize($url) ;Get file size
While Not InetGetInfo($hInet, 2) ;Loop until download is finished
    Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
    $BytesReceived = InetGetInfo($hInet, 0) ;Get bytes received
    $Pct = Int($BytesReceived / $FileSize * 100) ;Calculate percentage
    ProgressSet($Pct, $Pct & "%") ;Set progress bar
WEnd
ProgressOff()
works :-)

Share this post


Link to post
Share on other sites

For example...

#include <Math.au3> 
    
$_FinalUrl = 'http://www.birdscanfly.com/images/bcf_wallpaper_1440.jpg'
$_TempPath = @TempDir & '\bcf_wallpaper_1440.jpg'
$_FileSize = InetGetSize ( $_FinalUrl )
$_Gui = GUICreate ( "" )
$_ProgressBar = GUICtrlCreateProgress ( 5, 25, 350, 23 )
GUISetState ( @SW_SHOW )
$_Download = InetGet ( $_FinalUrl, $_TempPath, 1, 1 )
Local $_InfoData
Do
    $_InfoData = InetGetInfo ( $_Download )
    If Not @error Then
        $_InetGet = $_InfoData[0]
        $_DownloadPercent = Round ( ( 100 * $_InetGet ) / $_FileSize )
        $_DownloadPercent = _Min ( _Max ( 1, $_DownloadPercent ), 99 )
        GUICtrlSetData ( $_ProgressBar, $_DownloadPercent )
        $_Label = GUICtrlCreateLabel ( 'progress : ' & $_DownloadPercent & ' %', 5, 52, 350, 20 )  
    EndIf
    Sleep ( 100 )    
Until $_InfoData[2] = True
$_Label = GUICtrlCreateLabel ( 'Download successfull !', 5, 52, 350, 20 )  
Sleep ( 2000 )

sorry GMK, i doesn't see your post ! Posted Image

also this works but i have changed the code

#include <Math.au3> 
$_DownloadPercent=0
$_Gui = GUICreate ( "" )
$_ProgressBar = GUICtrlCreateProgress ( 5, 25, 350, 23 )
$_Label = GUICtrlCreateLabel ($_DownloadPercent & ' %', 360, 30, 40,20 ) 
GUISetState ( @SW_SHOW ) 
$_FinalUrl = 'http://www.shapecollage.com/2.5/ShapeCollage-2.5-Setup.exe'
$_TempPath = @scriptDir & "\ShapeCollage-2.5-Setup.exe"
$_FileSize = InetGetSize ( $_FinalUrl )
$_Download = InetGet ( $_FinalUrl, $_TempPath, 1, 1 )
Local $_InfoData
Do
     Sleep ( 500 ) 
    $_InfoData = InetGetInfo ( $_Download )
    If Not @error Then
        $_InetGet = $_InfoData[0]
        $_DownloadPercent = Round ( ( 100 * $_InetGet ) / $_FileSize )
        $_DownloadPercent = _Min ( _Max ( 1, $_DownloadPercent ), 99 )
        GUICtrlSetData ( $_ProgressBar, $_DownloadPercent )
        GUICtrlSetData ( $_Label, $_DownloadPercent & ' %')  
    EndIf
      
Until $_InfoData[2] = True
GUICtrlCreateLabel ( 'Download successfull !', 5, 52, 350, 20 )  
Sleep ( 2000 )

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

$handle = InetGet("link")
InetGetSize("link") = InetGetInfo($handle,1)
@InetGetActive = InetGetInfo($handle,2)
@InetGetBytesRead = InetGetInfo($handle,0)

This was all in the help file and explained very well. If you need more info on this, I would start there. I've never actually used these functions before and was able to find the info in under 60 seconds. So in the future, I would do a little leg work before you ask someone to help you. That will make people want to help you more, knowing that you've actually tried first.

-Aaron

Yes I know, I am a stupid boy, sorry Edited by HAL9000

Share this post


Link to post
Share on other sites

The main thing is that it works!

glad I could help Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0