Jump to content

Make a progress bar move with download % completion?


Shyke
 Share

Recommended Posts

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"?

Link to comment
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).

Link to comment
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)
yes... but its actually a file not folder

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

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
Link to comment
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.

 

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...