Sign in to follow this  
Followers 0
Shyke

Make a progress bar move with download % completion?

11 posts in this topic

This is another one of the things that I have never known how to do... make a progress bar move to the percentage of the file downloaded. Can anyone clue me in on how to do this without saying "Go look at the AutoIt update au3 file"?

Share this post


Link to post
Share on other sites



Ultra-simplified example:

$size = InetGetSize("http://www.website.com/file.ext")
InetGet("http://www.website.com/file.ext","C:\directory\file.ext",0,1)

While @InetGetActive
    GUICtrlSetData($progressbar,@InetGetBytesRead/$size)
WEnd

The main point is that you get the total size of the file, then download it in background mode and update the progress bar with the ratio of bytes downloaded to bytes total (progress bars take percentage values for data setting).

Share this post


Link to post
Share on other sites

Hey sorry for this question. but, say, you were making a downloader, and you ask the user to input the file URL and the folder for download, say these are variabls $URL and $Folder

would you have this...

$size = InetGetSize($URL)
InetGet($URL,$Folder,0,1)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hey sorry for this question. but, say, you were making a downloader, and you ask the user to input the file URL and the folder for download, say these are variabls $URL and $Folder

would you have this...

$size = InetGetSize($URL)
InetGet($URL,$Folder,0,1)
yes... but its actually a file not folder

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

oh i see now thanks

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I have:

$size = InetGetSize($link)
    InetGet($link, $Path & "test.zip", 1, 1)
    
    While @InetGetActive
        GUICtrlSetData($DownloadBar, @InetGetBytesRead / $size)
    WEnd

And it doesn't work for some reason... anyone help?

EDIT: I think it could hgave something to do with the additional code right under that:

Do
        $bartest = GUICtrlRead($DownloadBar)
        If $bartest = 100 Then
            $bar = 1
            GUICtrlSetState($DownloadBar, $GUI_Hide)
            GUICtrlSetState($DownloadDone, $GUI_Show)
        EndIf
        WorkIt()
    Until $bar = 1

EDIT: I put WorkIt() inside the If so now it doesn't spam, lol

Edited by Shyke

Share this post


Link to post
Share on other sites

Can no one help?

Note: I only double posted because I really don't know...

Share this post


Link to post
Share on other sites

I'm a bit confused by a couple of the things that you have posted. Could you please post a complete piece of code and explain what's wrong?

Share this post


Link to post
Share on other sites

Hey sorry for this question. but, say, you were making a downloader, and you ask the user to input the file URL and the folder for download, say these are variabls $URL and $Folder

would you have this...

$size = InetGetSize($URL)
InetGet($URL,$Folder,0,1)

As Valuater posted earlier, might be a good idea to take a look at Small download tool


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

As Valuater posted earlier, might be a good idea to take a look at Small download tool

Threw this together real quick. Its probably dirty as hell but I'm still learning AutoIt. This will download and execute the file and immediately exit out of itself. If you can figure out how to put the percentage inside the bar without interferring with the bar and not having to use a Beta of autoit let me know :P Try it out.

#include <GUIConstants.au3>
#include <array.au3>
#include <file.au3>
#include <inet.au3>
#include <process.au3>

GUICreate("Download", 250, 250, 300, 100)
GUICtrlCreateLabel("Path", 20, 10, 50, 20)
$path = GUICtrlCreateInput("", 50, 10, 170, 15, $ES_AUTOHSCROLL, "")
GUICtrlCreateLabel("Save: ", 20, 30, 50, 20)
$save = GUICtrlCreateInput("", 50, 30, 170, 15, $ES_AUTOHSCROLL, "")
$Download = GUICtrlCreateProgress(30, 160, 180, 20, "",$PBS_SMOOTH)
GUICtrlCreateGroup("Status ", 20, 60, 200, 135)
GUICtrlCreateLabel("File Remaining: ", 25, 85, 140, 20)
GUICtrlCreateLabel("Percent done: ", 25, 110, 120, 20)
GUICtrlCreateLabel("Size: ", 25, 135, 75, 20)
$btn = GUICtrlCreateButton("Download", 90, 205, 60, 20, $BS_DEFPUSHBUTTON)
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            $size = InetGetSize(GUICtrlRead($path))
            InetGet(GUICtrlRead($path), GUICtrlRead($save), 1, 1)
            GUICtrlCreateLabel(Round(StringTrimRight("" & $size / 1024, 3)) & " KB", 60, 135, 75, 25)
            While @InetGetActive
                For $i = @InetGetBytesRead To $size
                    GUICtrlCreateLabel(StringTrimRight("" & $size - @InetGetBytesRead, 6) & " MB", 110, 85, 35, 35)
                    $i_StatusPercent = (@InetGetBytesRead / $size * 100)
                    GUICtrlCreateLabel(Round($i_StatusPercent) & "%", 100, 110, 25, 15, $SS_CENTER)
                    GUICtrlSetData($Download, $i_StatusPercent)
                    Sleep(400)
                    If round($i_statuspercent) = "100" Then
                     ExitLoop   
                    EndIf
                Next
                Run(guictrlread($save))
                Exit
            WEnd
        EndSelect
WEnd
Exit
Edited by powaking

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