Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Getting progressbar to work with inetget?


  • Please log in to reply
11 replies to this topic

#1 omnomnom

omnomnom

    Seeker

  • Active Members
  • 42 posts

Posted 10 April 2010 - 01:07 PM

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!







#2 NiVZ

NiVZ

    Adventurer

  • Active Members
  • PipPip
  • 105 posts

Posted 10 April 2010 - 03:17 PM

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, 10 April 2010 - 03:18 PM.


#3 omnomnom

omnomnom

    Seeker

  • Active Members
  • 42 posts

Posted 10 April 2010 - 03:32 PM

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!

#4 NiVZ

NiVZ

    Adventurer

  • Active Members
  • PipPip
  • 105 posts

Posted 10 April 2010 - 04:09 PM

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

#5 omnomnom

omnomnom

    Seeker

  • Active Members
  • 42 posts

Posted 10 April 2010 - 04:30 PM

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("<a href='http://www.myserver.com/file1.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.myserver.com/file1.exe"</a>, "file1.exe", 1, 1)     EndIf     Else    inetget("<a href='http://www.myserver.com/file1.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.myserver.com/file1.exe"</a>, "file1.exe", 1, 1)   EndIf



I have them in cases for each of the checkboxes.

Thanks :(

Edited by omnomnom, 10 April 2010 - 04:31 PM.


#6 NiVZ

NiVZ

    Adventurer

  • Active Members
  • PipPip
  • 105 posts

Posted 10 April 2010 - 06:02 PM

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("<a href='http://www.myserver.com/file1.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.myserver.com/file1.exe"</a>, "file1.exe", 1, 1)     EndIf     Else    inetget("<a href='http://www.myserver.com/file1.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.myserver.com/file1.exe"</a>, "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, 10 April 2010 - 06:34 PM.


#7 NiVZ

NiVZ

    Adventurer

  • Active Members
  • PipPip
  • 105 posts

Posted 10 April 2010 - 08:25 PM

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

Plain Text         
#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] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[2][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[3][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[4][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[5][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[6][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[7][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     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


#8 omnomnom

omnomnom

    Seeker

  • Active Members
  • 42 posts

Posted 10 April 2010 - 08:38 PM

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

Plain Text         
#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] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[2][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[3][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[4][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[5][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[6][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[7][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     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, 10 April 2010 - 08:41 PM.


#9 jchd

jchd

    Whatever your capacity, resistance is futile.

  • MVPs
  • 5,228 posts

Posted 10 April 2010 - 10:38 PM

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

SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!

SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)

An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.

 

SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.

 

PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

RegExp tutorial: enough to get started

Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.


#10 NiVZ

NiVZ

    Adventurer

  • Active Members
  • PipPip
  • 105 posts

Posted 10 April 2010 - 11:34 PM

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

#11 ChrisBair

ChrisBair

    Seeker

  • Active Members
  • 13 posts

Posted 30 April 2010 - 04:07 PM

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 = "<a href='http://download.macromedia.com/pub/flashplayer/current/uninstall_flash_player.exe' class='bbc_url' title='External link' rel='nofollow external'>http://download.macromedia.com/pub/flashplayer/current/uninstall_flash_player.exe"</a> $FileName1 = "uninstall_flash_player.exe" $Program1 = "Flash uninstall" _DownloadProgress($FileURL1, $FileName1, $Program1)


#12 AJStevens

AJStevens

    Wayfarer

  • Active Members
  • Pip
  • 59 posts

Posted 31 July 2010 - 09:33 AM

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

AutoIt         
#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] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[2][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[3][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[4][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[5][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[6][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     $DownloadArray[7][0] = "<a href='http://www.cutepdf.com/download/CuteWriter.exe' class='bbc_url' title='External link' rel='nofollow external'>http://www.cutepdf.com/download/CuteWriter.exe"</a>     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, 31 July 2010 - 09:40 AM.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users