Jump to content
Sign in to follow this  
sandman

The little current progress bar, and the overall progress

Recommended Posts

sandman

You know in installers how they sometimes show in one progress bar, the overall progress of the installation, and in the other, the current progress of the current step? Well I am trying to replicate that here. Here's my script:

$ovrprog = GUICtrlCreateProgress(20, 150, 530, 15)
$curprog = GUICtrlCreateProgress(20, 180, 530, 15)
GUISetState(@SW_SHOW, $win)
InetGet("tookoutdownloadlocationbwhahaahah", "tookoutdownloadlocationbwhahaahah", 0, 1)

While @InetGetActive = 1
    $size = InetGetSize("tookoutdownloadlocationbwhahaahah")
    $prog = $size / @InetGetBytesRead
    $progress = Round($prog, 0)
    GUICtrlSetData($curprog, $progress)
    $overall = $progress / 2
    GUICtrlSetData($ovrprog, Round($overall, 0))
WEnd

But for some reason $curprog does not move at all, and neither does $ovrprog. I have tried changing things with macros like "While @InetGetActive" to "While @InetGetActive = 1", but no luck (i didnt think that would work anyway :rambo: ) I also used to have the last line as "GUICtrlSetData($ovrprog, Round($progress / 2, 0))", and same thing with the other GUICtrlSetData, and split it apart to test that out, but it works fine. Notice in the InetGet I DO have it running in the background. I made that mistake already and found it :rolleyes:

So does anyone know why the progress bar(s) aren't updating?

Thanks,

SANDMAN!


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites
-Ultima-

1) I don't see why you're attempting to read the file size every single time through the loop. InetGetSize() won't change so long as the server is sending the same data.

2) Dividing the total size by the number of bytes read is the WRONG way of dividing. You're supposed to be dividing the number of bytes read by the total size.

3) Progress controls need data to be set in percentages. You're working in decimals. You need to multiply by 100 and Int() the product, or something.

4) If the progressbar isn't moving, then my guess is that InetGetSize() is failing to get the size of the file. Probably depends on the server (you'll notice that that's mentioned in the remarks for InetGetSize() too). The odd thing is, this seems to be failing for *most* servers I try it on.

Edit: Here's a messy but working example. It might not fill the progress fully all the time if @InetGetActive gets set to 0 before it does the last update.

#include <GUIConstants.au3>
$url = "ftp://slackware.cs.utah.edu/pub/slackware/slackware-11.0-iso/slackware-11.0-install-d1.iso"

$win = GUICreate("o hai", 600, 300)

$curprog = GUICtrlCreateProgress(5, 5, 530, 15, $PBS_SMOOTH )
$label = GUICtrlCreateLabel("", 5, 30, 530)

$size = InetGetSize($url)
If @error Or $size = 0 Then
    MsgBox(0,"o noz","invisible size")
    Exit
endif

GUISetState(@SW_SHOW, $win)

InetGet($url, "slack.iso", 0, 1)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

    If @InetGetActive = 1 Then
        $bytes = @InetGetBytesRead
        $prog = ($bytes / $size)*100
        GUICtrlSetData($curprog, $prog)
        GUICtrlSetData($label, $prog & "%" & " = " & $bytes & "/" & $size)
    EndIf
WEnd
Edited by -Ultima-

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

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  

×