Jump to content

Getting progressbar to work with inetget?


Recommended Posts

So since my first post ive come on quite a lot, but something which im sure is very simple but can not work out is how to get a progress bar to track a downloads progress from inetget.

What i want, is basically a progress bar that when i press a button (there will be several each with different files) it downloads the file (i have got this bit done already) and then the progress bar tracks its progress.

Thanks!

Link to comment
Share on other sites

So since my first post ive come on quite a lot, but something which im sure is very simple but can not work out is how to get a progress bar to track a downloads progress from inetget.

What i want, is basically a progress bar that when i press a button (there will be several each with different files) it downloads the file (i have got this bit done already) and then the progress bar tracks its progress.

Thanks!

Hello,

Have a look at the help for INetGet and INetGetInfo. First you need to set INetGet to use background mode. Then once you've done this, do a loop which gets the bytes read from the array that INetGetInfo returns and divide it by the total file size and multiply by 100 and use that to set the progress bar percentage.

Wondered why you had multiple buttons? You could have one button that gets them all. This is what I do, and I use two progress bars, one for current file progress and one for overall progress.

NiVZ

Edited by NiVZ
Link to comment
Share on other sites

Hello,

Have a look at the help for INetGet and INetGetInfo. First you need to set INetGet to use background mode. Then once you've done this, do a loop which gets the bytes read from the array that INetGetInfo returns and divide it by the total file size and multiply by 100 and use that to set the progress bar percentage.

Wondered why you had multiple buttons? You could have one button that gets them all. This is what I do, and I use two progress bars, one for current file progress and one for overall progress.

NiVZ

Thanks, I took a look in the help section however i could not work out properly what you said... would you mind elaborating and maybe giving a few samples as to how to feed it to the progress bar? thanks!

With regards to the button question, i decided to change it to checkboxes which is just as easy to make download a file however i want to be able to tick all the checkboxes i need and then the progress bar show me the progress in the progress bar and if you could give some examples of the 1 file and then the overall that would be brilliant!!

Thanks a lot!

Link to comment
Share on other sites

Thanks, I took a look in the help section however i could not work out properly what you said... would you mind elaborating and maybe giving a few samples as to how to feed it to the progress bar? thanks!

With regards to the button question, i decided to change it to checkboxes which is just as easy to make download a file however i want to be able to tick all the checkboxes i need and then the progress bar show me the progress in the progress bar and if you could give some examples of the 1 file and then the overall that would be brilliant!!

Thanks a lot!

When I make programs like this, I usually build a 2 dimensional array which has url to download, size of file and cumulative total file size, then I loop through the array doing the downloads and then setting the progress bar(s) as I described above.

Can you post the code you have already? Most users on here won't help out unless you show us what you've gotten so far and it would probably take me longer to write an example than it would to change your code.

Thanks,

NiVZ

Link to comment
Share on other sites

sure, currently i have this

if fileexists("file1.exe") Then
        if 4 = msgbox(5, "ERROR", "File1 already exists, click Retry to delete it and re-download it") Then
        filedelete("file1.exe")
        inetget("http://www.myserver.com/file1.exe", "file1.exe", 1, 1)
    EndIf
    Else    inetget("http://www.myserver.com/file1.exe", "file1.exe", 1, 1)
  EndIf

I have them in cases for each of the checkboxes.

Thanks :(

Edited by omnomnom
Link to comment
Share on other sites

sure, currently i have this

if fileexists("file1.exe") Then
        if 4 = msgbox(5, "ERROR", "File1 already exists, click Retry to delete it and re-download it") Then
        filedelete("file1.exe")
        inetget("http://www.myserver.com/file1.exe", "file1.exe", 1, 1)
    EndIf
    Else    inetget("http://www.myserver.com/file1.exe", "file1.exe", 1, 1)
  EndIf

I have them in cases for each of the checkboxes.

Thanks :(

Hello,

Sorry one other question - at the moment, it looks as if you are downloading in the background and as you're doing more than one file it'll be doing them all at once (as it supports downloading multiple files) - my programs so far do everything sequentially, ie download one complete file and then start the next.

So the question is, do you need them all downloading together or are you happy to do them one after the other?

And it would've been nice if you included your GUI :)

NiVZ

Edited by NiVZ
Link to comment
Share on other sites

OK, here's a quick example of how I do progress bars.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>

Opt("TrayMenuMode", 1)

$Form1              = GUICreate("Downloader", 400, 170, -1, -1)

$pb_File            = GUICtrlCreateProgress(30, 30, 300, 20, $PBS_SMOOTH)
$lbl_FilePercent    = GUICtrlCreateLabel("0 %", 335, 32, 35, 16, $SS_RIGHT)

$pb_Overall         = GUICtrlCreateProgress(30, 80, 300, 20, $PBS_SMOOTH)
$lbl_OverallPercent = GUICtrlCreateLabel("0 %", 335, 82, 35, 16, $SS_RIGHT)

$but_Download       = GUICtrlCreateButton("Download", 160, 120, 80, 30)

GUISetState(@SW_Show)

While 1
    
    $nMsg = GUIGetMsg()
    
    If $nMsg = $GUI_EVENT_CLOSE Then EXIT
        
    If $nMsg = $but_Download Then _Download()
    
WEnd


Func _Download()
    
    ; Disable the download button
    GUICtrlSetState($but_Download, $GUI_DISABLE)
    
    ; Reset total filesize to download
    $TotalToDownload = 0
    
    Dim $DownloadArray[8][3]
    
    ; Setup the URL's to download - i'm using CutePDF 7 times to demonstrate
    $DownloadArray[1][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[2][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[3][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[4][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[5][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[6][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[7][0] = "http://www.cutepdf.com/download/CuteWriter.exe"

    For $i = 1 To UBound($DownloadArray)-1
        
        ; Get the File size
        $FileSize = INetGetSize($DownloadArray[$i][0])
        
        ; Current File Size
        $DownloadArray[$i][1] = $FileSize
        
        ; Cumulative Total
        $DownloadArray[$i][2] = $TotalToDownload
        
        ; Add the current file size to the total
        $TotalToDownload += $FileSize
    Next
    
    ; Do the Downloads
    For $i = 1 To UBound($DownloadArray)-1
        
        ; Dow the download in the background
        $Download = INetGet($DownloadArray[$i][0], "C:\test" & $i & ".exe", 1, 1)
        
        ; Loop to update progress
        Do
            ; Get number of bytes read for current file
            $BytesDownloaded    = INetGetInfo($Download, 0)
            
            ; Add this to the cumulative total
            $DownloadedSoFar    = $DownloadArray[$i][2] + $BytesDownloaded
            
            ; Calculate the current file percentage
            $FileProgress       = Floor(($BytesDownloaded / $DownloadArray[$i][1]) * 100)
            
            ; Calculate the overall percentage
            $OverallProgress    = Floor(($DownloadedSoFar / $TotalToDownload) * 100)
            
            ; Update the Current FIle progress bar
            GUICtrlSetData($pb_File, $FileProgress)
            
            ; Only update the current file percent label if it has changed to avoid flickering
            If GUICtrlRead($lbl_FilePercent) <> $FileProgress & " %" Then GUICtrlSetData($lbl_FilePercent, $FileProgress & " %")
            
            ; Update the overall progress bar
            GUICtrlSetData($pb_Overall, $OverallProgress)

            ; Only update the overall file percent label if it has changed to avoid flickering
            If GUICtrlRead($lbl_OverallPercent) <> $OverallProgress & " %" Then GUICtrlSetData($lbl_OverallPercent, $OverallProgress & " %")
            
            ; Only update the title bar (overall) percent label if it has changed to avoid flickering
            If WinGetTitle($Form1, "") <> $OverallProgress & " % - Downloader" Then WinSetTitle($Form1, "", $OverallProgress & " % - Downloader")
        
        ; Continue loop until download is complete
        Until InetGetInfo($Download, 2)
        
        ; Set current file progress bar to 100% when complete
        GUICtrlSetData($pb_File, 100)
        
        ; Set current file percent label to 100% when complete
        GUICtrlSetData($lbl_FilePercent, "100 %")
    
    Next

    ; Set overall progress bar to 100% when complete
    GUICtrlSetData($pb_Overall, 100)
    
    ; Set overall percent label to 100% when complete
    GUICtrlSetData($lbl_OverallPercent, "100 %")
    
    ; Display message box to say all downloads complete
    MsgBox(64, "Downloader", "All downloads complete")
    
    ; Reset GUI
    WinSetTitle($Form1, "", "Downloader")
    
    GUICtrlSetData($pb_File, 0)
    GUICtrlSetData($lbl_FilePercent, "0 %")
    
    GUICtrlSetData($pb_Overall, 0)
    GUICtrlSetData($lbl_OverallPercent, "0 %")
    
    ; Enable the download button
    GUICtrlSetState($but_Download, $GUI_ENABLE)
    
EndFunc
Link to comment
Share on other sites

OK, here's a quick example of how I do progress bars.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>

Opt("TrayMenuMode", 1)

$Form1              = GUICreate("Downloader", 400, 170, -1, -1)

$pb_File            = GUICtrlCreateProgress(30, 30, 300, 20, $PBS_SMOOTH)
$lbl_FilePercent    = GUICtrlCreateLabel("0 %", 335, 32, 35, 16, $SS_RIGHT)

$pb_Overall         = GUICtrlCreateProgress(30, 80, 300, 20, $PBS_SMOOTH)
$lbl_OverallPercent = GUICtrlCreateLabel("0 %", 335, 82, 35, 16, $SS_RIGHT)

$but_Download       = GUICtrlCreateButton("Download", 160, 120, 80, 30)

GUISetState(@SW_Show)

While 1
    
    $nMsg = GUIGetMsg()
    
    If $nMsg = $GUI_EVENT_CLOSE Then EXIT
        
    If $nMsg = $but_Download Then _Download()
    
WEnd


Func _Download()
    
    ; Disable the download button
    GUICtrlSetState($but_Download, $GUI_DISABLE)
    
    ; Reset total filesize to download
    $TotalToDownload = 0
    
    Dim $DownloadArray[8][3]
    
    ; Setup the URL's to download - i'm using CutePDF 7 times to demonstrate
    $DownloadArray[1][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[2][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[3][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[4][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[5][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[6][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[7][0] = "http://www.cutepdf.com/download/CuteWriter.exe"

    For $i = 1 To UBound($DownloadArray)-1
        
        ; Get the File size
        $FileSize = INetGetSize($DownloadArray[$i][0])
        
        ; Current File Size
        $DownloadArray[$i][1] = $FileSize
        
        ; Cumulative Total
        $DownloadArray[$i][2] = $TotalToDownload
        
        ; Add the current file size to the total
        $TotalToDownload += $FileSize
    Next
    
    ; Do the Downloads
    For $i = 1 To UBound($DownloadArray)-1
        
        ; Dow the download in the background
        $Download = INetGet($DownloadArray[$i][0], "C:\test" & $i & ".exe", 1, 1)
        
        ; Loop to update progress
        Do
            ; Get number of bytes read for current file
            $BytesDownloaded    = INetGetInfo($Download, 0)
            
            ; Add this to the cumulative total
            $DownloadedSoFar    = $DownloadArray[$i][2] + $BytesDownloaded
            
            ; Calculate the current file percentage
            $FileProgress       = Floor(($BytesDownloaded / $DownloadArray[$i][1]) * 100)
            
            ; Calculate the overall percentage
            $OverallProgress    = Floor(($DownloadedSoFar / $TotalToDownload) * 100)
            
            ; Update the Current FIle progress bar
            GUICtrlSetData($pb_File, $FileProgress)
            
            ; Only update the current file percent label if it has changed to avoid flickering
            If GUICtrlRead($lbl_FilePercent) <> $FileProgress & " %" Then GUICtrlSetData($lbl_FilePercent, $FileProgress & " %")
            
            ; Update the overall progress bar
            GUICtrlSetData($pb_Overall, $OverallProgress)

            ; Only update the overall file percent label if it has changed to avoid flickering
            If GUICtrlRead($lbl_OverallPercent) <> $OverallProgress & " %" Then GUICtrlSetData($lbl_OverallPercent, $OverallProgress & " %")
            
            ; Only update the title bar (overall) percent label if it has changed to avoid flickering
            If WinGetTitle($Form1, "") <> $OverallProgress & " % - Downloader" Then WinSetTitle($Form1, "", $OverallProgress & " % - Downloader")
        
        ; Continue loop until download is complete
        Until InetGetInfo($Download, 2)
        
        ; Set current file progress bar to 100% when complete
        GUICtrlSetData($pb_File, 100)
        
        ; Set current file percent label to 100% when complete
        GUICtrlSetData($lbl_FilePercent, "100 %")
    
    Next

    ; Set overall progress bar to 100% when complete
    GUICtrlSetData($pb_Overall, 100)
    
    ; Set overall percent label to 100% when complete
    GUICtrlSetData($lbl_OverallPercent, "100 %")
    
    ; Display message box to say all downloads complete
    MsgBox(64, "Downloader", "All downloads complete")
    
    ; Reset GUI
    WinSetTitle($Form1, "", "Downloader")
    
    GUICtrlSetData($pb_File, 0)
    GUICtrlSetData($lbl_FilePercent, "0 %")
    
    GUICtrlSetData($pb_Overall, 0)
    GUICtrlSetData($lbl_OverallPercent, "0 %")
    
    ; Enable the download button
    GUICtrlSetState($but_Download, $GUI_ENABLE)
    
EndFunc

Thats great, however after a little experimenting i cant work out how to change it so that it only downloads the required files (set by the checkboxes). Also, these checkboxes are on two different tabs would that make a difference?

part from that, i could generally understand your code but its somewhat complicated. Is there a much simpler way to do it? =)

Thanks a lot!

Edited by omnomnom
Link to comment
Share on other sites

Simple: ProgressOn, ProgressSet, ProgressOff. Get that working then switch to your own control using the same working logic.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Thats great, however after a little experimenting i cant work out how to change it so that it only downloads the required files (set by the checkboxes). Also, these checkboxes are on two different tabs would that make a difference?

part from that, i could generally understand your code but its somewhat complicated. Is there a much simpler way to do it? =)

Thanks a lot!

To get that working, you'd need to wait til they press the button, then check if each of the checkboxes are ticked or unticked, and if they are ticked then add the corresponding URL to the array. Doesn't matter that they're on different tabs.

NiVZ

Link to comment
Share on other sites

  • 3 weeks later...

Func _DownloadProgress($FileURL, $FileName, $ProgramName)
    $FileSaveLocation = @TempDir & "\" & $FileName
    $FileSize = InetGetSize($FileURL)
    $FileDownload = InetGet($FileURL, $FileSaveLocation, 0, 1)
    ProgressOn("", "", "", -1, 5, 18)
    Do
        $Percentage = InetGetInfo($FileDownload, 0) * 100 / $FileSize
        ProgressSet($Percentage, Round($Percentage, 0) & "% Downloaded " & Round(InetGetInfo($FileDownload, 0) / 1048576, 2) & " of " & Round($FileSize / 1048576, 2) & " MB", "Downloading " & $ProgramName)
        Sleep(250)
    Until InetGetInfo($FileDownload, 2)

EndFunc   ;==>_DownloadProgress

invoked using

$FileURL1 = "http://download.macromedia.com/pub/flashplayer/current/uninstall_flash_player.exe"
$FileName1 = "uninstall_flash_player.exe"
$Program1 = "Flash uninstall"
_DownloadProgress($FileURL1, $FileName1, $Program1)
Link to comment
Share on other sites

  • 3 months later...

OK, here's a quick example of how I do progress bars.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>

Opt("TrayMenuMode", 1)

$Form1              = GUICreate("Downloader", 400, 170, -1, -1)

$pb_File            = GUICtrlCreateProgress(30, 30, 300, 20, $PBS_SMOOTH)
$lbl_FilePercent    = GUICtrlCreateLabel("0 %", 335, 32, 35, 16, $SS_RIGHT)

$pb_Overall         = GUICtrlCreateProgress(30, 80, 300, 20, $PBS_SMOOTH)
$lbl_OverallPercent = GUICtrlCreateLabel("0 %", 335, 82, 35, 16, $SS_RIGHT)

$but_Download       = GUICtrlCreateButton("Download", 160, 120, 80, 30)

GUISetState(@SW_Show)

While 1
    
    $nMsg = GUIGetMsg()
    
    If $nMsg = $GUI_EVENT_CLOSE Then EXIT
        
    If $nMsg = $but_Download Then _Download()
    
WEnd


Func _Download()
    
    ; Disable the download button
    GUICtrlSetState($but_Download, $GUI_DISABLE)
    
    ; Reset total filesize to download
    $TotalToDownload = 0
    
    Dim $DownloadArray[8][3]
    
    ; Setup the URL's to download - i'm using CutePDF 7 times to demonstrate
    $DownloadArray[1][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[2][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[3][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[4][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[5][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[6][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[7][0] = "http://www.cutepdf.com/download/CuteWriter.exe"

    For $i = 1 To UBound($DownloadArray)-1
        
        ; Get the File size
        $FileSize = INetGetSize($DownloadArray[$i][0])
        
        ; Current File Size
        $DownloadArray[$i][1] = $FileSize
        
        ; Cumulative Total
        $DownloadArray[$i][2] = $TotalToDownload
        
        ; Add the current file size to the total
        $TotalToDownload += $FileSize
    Next
    
    ; Do the Downloads
    For $i = 1 To UBound($DownloadArray)-1
        
        ; Dow the download in the background
        $Download = INetGet($DownloadArray[$i][0], "C:\test" & $i & ".exe", 1, 1)
        
        ; Loop to update progress
        Do
            ; Get number of bytes read for current file
            $BytesDownloaded    = INetGetInfo($Download, 0)
            
            ; Add this to the cumulative total
            $DownloadedSoFar    = $DownloadArray[$i][2] + $BytesDownloaded
            
            ; Calculate the current file percentage
            $FileProgress       = Floor(($BytesDownloaded / $DownloadArray[$i][1]) * 100)
            
            ; Calculate the overall percentage
            $OverallProgress    = Floor(($DownloadedSoFar / $TotalToDownload) * 100)
            
            ; Update the Current FIle progress bar
            GUICtrlSetData($pb_File, $FileProgress)
            
            ; Only update the current file percent label if it has changed to avoid flickering
            If GUICtrlRead($lbl_FilePercent) <> $FileProgress & " %" Then GUICtrlSetData($lbl_FilePercent, $FileProgress & " %")
            
            ; Update the overall progress bar
            GUICtrlSetData($pb_Overall, $OverallProgress)

            ; Only update the overall file percent label if it has changed to avoid flickering
            If GUICtrlRead($lbl_OverallPercent) <> $OverallProgress & " %" Then GUICtrlSetData($lbl_OverallPercent, $OverallProgress & " %")
            
            ; Only update the title bar (overall) percent label if it has changed to avoid flickering
            If WinGetTitle($Form1, "") <> $OverallProgress & " % - Downloader" Then WinSetTitle($Form1, "", $OverallProgress & " % - Downloader")
        
        ; Continue loop until download is complete
        Until InetGetInfo($Download, 2)
        
        ; Set current file progress bar to 100% when complete
        GUICtrlSetData($pb_File, 100)
        
        ; Set current file percent label to 100% when complete
        GUICtrlSetData($lbl_FilePercent, "100 %")
    
    Next

    ; Set overall progress bar to 100% when complete
    GUICtrlSetData($pb_Overall, 100)
    
    ; Set overall percent label to 100% when complete
    GUICtrlSetData($lbl_OverallPercent, "100 %")
    
    ; Display message box to say all downloads complete
    MsgBox(64, "Downloader", "All downloads complete")
    
    ; Reset GUI
    WinSetTitle($Form1, "", "Downloader")
    
    GUICtrlSetData($pb_File, 0)
    GUICtrlSetData($lbl_FilePercent, "0 %")
    
    GUICtrlSetData($pb_Overall, 0)
    GUICtrlSetData($lbl_OverallPercent, "0 %")
    
    ; Enable the download button
    GUICtrlSetState($but_Download, $GUI_ENABLE)
    
EndFunc

NiVZ, excellent code thank you, I've been struggling with my download progress code, and rewrote it based off yours.

I like the fact you've gone very detailed with it, although I want a little bit more. I want a # / # KB/MB/GB counters as well as percentages, I currently use another text label as a "current status" which says "Download: $filename and am trying to add it to that, oh and a cancellation method! I've got a cancel button, but everything I've tried doesn't seem to stop and cancel it.

Oh and when you're downloading lots of files, it appears to sit there while it's getting the file sizes, would be great if progress can be shown for this also.

Can you help? Thanks

Edited by AJStevens
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...