Jump to content
Sign in to follow this  
AJStevens

Loops, Progress, multiple file downloads, cancel gui problem

Recommended Posts

AJStevens

Hi all, I've searched through the forum, done Autoit 123, read the helpfile, tried various examples and I'm even studying the AutoUpdateIt.au3 carefully, however I would really appreciate some help from someone, none of these examples involve multiple downloads, the ones that do, don't have a cancellation option.

I "think" the issue is because, to do multiple downloads, one after the other in a Progress and Overall Progress way requires a loop, but the program is then stuck in that loop and unable to process any GUI operations until that loop is completed, whether in "Msg Mode" or OnEventMode it seems.

I'm having trouble getting my head around this one, and could really use a small example I can incorporate or rewrite my code based on, it's already got wildly out of control.

Multiple downloads (from a 2 dimensional array)

GUI with Progress bar and a overal progress bar

Cancel button that works while downloading

I would prefer OnEventMode version preferably, it makes more sense to me, but any or both would be fantastic.

I know this sounds really newbish, but I'm sure if I can just get help with this primary concept, I'll be off and away with AutoIT.

Share this post


Link to post
Share on other sites
Bert

From the helpfile:

Remarks

Internet Explorer 3 or greater must be installed for this function to work.

The URL parameter should be in the form "http://www.somesite.com/path/file.html" - just like an address you would type into your web browser.

To use a username and password when connecting simply prefix the servername with "username:password@", e.g.

"http://myuser:mypassword@www.somesite.com"

Notes about the "background" Parameter

By default the function waits until the download has finished before returning. If the background parameter is set to 1 the function returns immediately and the download continues in the background. The function InetGetInfo() can be used to check the status of the download. It takes the handle returned from InetGet().

Multiple downloads are supported if they are started in background mode.

To abort a download call InetClose() and pass it the handle returned by InetGet().

By default AutoIt forces a connection before starting a download. For dial-up users this will prompt to go online or dial the modem (depending on how the system is configured). The options value 16 disables this behavior. Disabling the behavior can be useful for persistent connects (Broadband, LAN). However, it is also required to work around certain issues in Windows Vista and Windows 7.

Share this post


Link to post
Share on other sites
AJStevens

MPH, yeah I did read that in the helpfile, as I said.

However my issue is when you're trying to combine it all with multiple downloads (processing through an array of them), with a progress bar and and overall progress bar in a GUI, but still being able to press a cancel button that will use InetClose() to cancel the download.

Share this post


Link to post
Share on other sites
FlyinRiz

MPH, yeah I did read that in the helpfile, as I said.

However my issue is when you're trying to combine it all with multiple downloads (processing through an array of them), with a progress bar and and overall progress bar in a GUI, but still being able to press a cancel button that will use InetClose() to cancel the download.

If you use a cancel button, how are you going to choose which one is going to be cancelled? Or are you planning on cancelling them all?

-Aaron

Share this post


Link to post
Share on other sites
Tvern

Here is the thing - AutoIt is single thread, not multi thread. You may need to start up a separate process for each download.

Actually it's not that hard. I've written something like this before, Let me see if I can find it.

Share this post


Link to post
Share on other sites
FlyinRiz

Actually it's not that hard. I've written something like this before, Let me see if I can find it.

I've actually done something like this before to get around the Beep's Asynchronous limitation in AutoIt. It could proabably be easily modified for downloading files...you just need two files (the master program and the helper or secondary program) The master program would call the secondary with a parameter...

Master

Run(@ScriptDir & "\tone.exe " & $Hz)

Secondary (tone.exe)

If $CmdLine[0] <> 1 Then
    Exit
EndIf

Global $Hz = $CmdLine[1]
;...and so on...

You could use the StdIn/Out functions for communicating to the Child for info on file progress and save the PIDs for closing/cancelling the downloads. Hope all of this helps.

-Aaron

Edited by FlyinRiz

Share this post


Link to post
Share on other sites
Tvern

Here is an example of how this could work in a single process. There is still enough for you to do, but it should get you on your way.

#include <array.au3>
Global $aDownloads[1]
Global $aProgress[1]
Global $aButtons[1]
Global $aSize[1]

Opt("GuiOnEventMode",1)
Global $mainGUI = GUICreate("MultiDownload",470,40)
GUISetOnEvent(-3,"_Exit")
$ctrlAdress = GUICtrlCreateInput("",10,10,380)
GUICtrlSetResizing(-1,802) ;dockall
GUICtrlCreateButton("Download",400,10,60,20)
GUICtrlSetResizing(-1,802) ;dockall
GUICtrlSetOnEvent(-1,"_AddDownload")
GUISetState()

While 1
    Sleep(100)
    For $i = 1 To UBound($aDownloads) -1
        $Progress = InetGetInfo($aDownloads[$i],0)
        If $aSize[$i] Then
            GUICtrlSetData($aProgress[$i],($Progress/$aSize[$i])*100)
        Else
            GUICtrlSetData($aProgress[$i],50)
        EndIf
    Next
WEnd

Func _AddDownload()
    Local $sUrl = GUICtrlRead($ctrlAdress)
    Local $sPath = StringInStr($sUrl,"/",0,-1)
    $sPath = @ScriptDir & "\" & StringTrimLeft($sUrl,$sPath)
    ConsoleWrite("Saving : " & $sUrl & @CRLF & "To: " & $sPath & @CRLF)
    Local $Index = _ArrayAdd($aDownloads,InetGet($sUrl,$sPath,0,1))
    WinMove($mainGUI,"",Default,Default,Default,30*$Index + 60)
    _ArrayAdd($aProgress,GUICtrlCreateProgress(10,30*$Index+5,380))
    GUICtrlSetResizing(-1,802) ;dockall
    _ArrayAdd($aButtons,GUICtrlCreateButton("Cancel",400,30*$Index+5,60))
    GUICtrlSetOnEvent(-1,"_CancelDownload")
    GUICtrlSetResizing(-1,802) ;dockall
    _ArrayAdd($aSize,InetGetSize($sUrl))
EndFunc

Func _CancelDownload()
    Local $Index = _ArraySearch($aButtons,@GUI_CtrlId)
    InetClose($aDownloads[$Index])
EndFunc

Func _Exit()
    Exit
EndFunc

suggested improvements:

Cancel button should become an Open file button

Better solution for files with unknown size (currently shows 50% complete)

Complete downloads should be removed from the arrays

Better sulution for identical filenames (currently it overwrites without prompt)

many more.

edit:

Stop downloads before exit!!!

edit2:

fixed the cancel buttons :blink:

Edited by Tvern

Share this post


Link to post
Share on other sites
AJStevens

Thanks very much for the replies, your help is very much appreciated.

Here is the thing - AutoIt is single thread, not multi thread. You may need to start up a separate process for each download.

Yeah, so I've noticed, but it's only doing one download at a time, I think it's just structuring the loops properly, and my head is spinning reading bits here and there and not a "full picture".

If you use a cancel button, how are you going to choose which one is going to be cancelled? Or are you planning on cancelling them all?

-Aaron

Just to be clear, the downloads are processed one after another, not simultaneously, and the cancel button is to firstly cancel the current download in progress and break out of the loop and not process any others left to do.

Tvern, looked at your example, interesting... but I think like Aaron you've gone down the simultaneous route.

Basically, I've generated an array of downloads (using a process to discover these I won't bore you with), I then hope to download each of these one after the other, showing a progress bar (also showing bytes, but I can do that), and below it an "Overall Progress" (based on current commulative bytes downloaded and total size of all downloads). Oh and updating a status label with "Downloading... <filename>".

To do this I go through a For Loop for the downloads, and then inside that a Do...Until to update the progress display.

GUI:

Status Label (eg. "Downloading... <filename>"

- Current File Progress Bar -

- Overall Progress Bar -

[ Download ] [ Cancel ]

2DM Array of downloads:

$downloads =

Row Col0 Col1 etc.

[0][4]

[1]|Full Product Name|Product Description|Product Version|File Size*|DownloadURL|Product Name**|Product Base Version|Bytes Size|Filename|LocalSavePath|CommulativeTotal

[2]|Full Product Name|Product Description|Product Version|File Size*|DownloadURL|Product Name**|Product Base Version|Bytes Size|Filename|LocalSavePath|CommulativeTotal

[3]|Full Product Name|Product Description|Product Version|File Size*|DownloadURL|Product Name**|Product Base Version|Bytes Size|Filename|LocalSavePath|CommulativeTotal

* This is a label and not an accurate filesize, eg. "24 MB"

** Product name, without any version number in the name, eg. "Internet Explorer" not "Internet Explorer 8"

Example:

[1]|Microsoft Internet Explorer|Web Browser|8.0.6001.18702|32 MB|http://download.microsoft.com/internetexplorer.exe|Internet Explorer|8|33554432|iesetup.exe|C:\Temp\iesetup.exe|0

Some of that information is used to display progress (I like to show bytes process as well as percentage), and some is for information display in like a listview for the user to see what it's picked to download, and the obvious URL and Local path needed for a InetGet and a FileMove for the actual download.

Problem is, while it's processing the For..Next (downloads in the array) and inside that the Do...Until (file downloaded) the cancel won't work, it queues and waits.

I hope that's clearer.

Edited by AJStevens

Share this post


Link to post
Share on other sites
Tvern

Right. let me see if I can make an example script.

Share this post


Link to post
Share on other sites
AJStevens

Right. let me see if I can make an example script.

Excellent, thank you.

I found the script I originally based the download/update portion of mine off of. I quickly edited it to OnEventMode instead of MessageLoop, and altered the GUI, it's much simplier than what my code has turned into, there's no bytes progress, or the code to generate the download array, though there is one here, much simplier than the one mine became or the rubbish I put in there to try to get cancel to work etc. but easier to work with I think. If the cancel button can be made to work here, then I can get it to work in my code (after a complete rewrite most likely).

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

Opt("TrayMenuMode", 1)
Opt("GUIOnEventMode", 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)

$lbl_Status    = GUICtrlCreateLabel("Click Download to begin", 30, 57, 300, 16)

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

$but_Download       = GUICtrlCreateButton("Download", 80, 120, 80, 30)
GUICtrlSetOnEvent(-1, "_Download")

$but_Cancel       = GUICtrlCreateButton("Cancel", 240, 120, 80, 30)
GUICtrlSetOnEvent(-1, "_Cancel")

GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")

GUISetState(@SW_Show)

While 1

    Sleep(10)

WEnd

Func _Close()
    Exit
EndFunc   ;==>_Close

Func _Cancel()

EndFunc   ;==>_Cancel


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)

        ; Update Status
        GUICtrlSetData($lbl_Status, "Downloading..." & $DownloadArray[$i][0])

        ; 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 %")

    ; Update Status to say all downloads complete
    GUICtrlSetData($lbl_Status, "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

Share this post


Link to post
Share on other sites
Tvern

I hope this will be helpfull. Time for spareribs now! :blink:

Opt("GuiOnEventMode",1)
;example array
Local $downloads[4][10] = [["Rice 1.0","The biggest image on wikipedia!","1.0","8MB","http://upload.wikimedia.org/wikipedia/commons/6/65/Condoleezza_Rice.jpg","Rice",7866040,"Condoleezza_Rice.jpg",@ScriptDir & "\File0.jpg",31464160], ["Rice 1.0","The biggest image on wikipedia!","2.0","8MB","http://upload.wikimedia.org/wikipedia/commons/6/65/Condoleezza_Rice.jpg","Rice",7866040,"Condoleezza_Rice.jpg",@ScriptDir & "\File1.jpg",31464160], ["Rice 1.0","The biggest image on wikipedia!","3.0","8MB","http://upload.wikimedia.org/wikipedia/commons/6/65/Condoleezza_Rice.jpg","Rice",7866040,"Condoleezza_Rice.jpg",@ScriptDir & "\File2.jpg",31464160], ["Rice 1.0","The biggest image on wikipedia!","4.0","8MB","http://upload.wikimedia.org/wikipedia/commons/6/65/Condoleezza_Rice.jpg","Rice",7866040,"Condoleezza_Rice.jpg",@ScriptDir & "\File3.jpg",31464160]]
Local $hDownload ;the handle of the currently active download
Local $totalsize
Global $bSkip, $bCancel

$mainGUI = GUICreate("Multi Downloader",400,300)
GUISetOnEvent(-3,"_Exit")
$CtrlProgress1 = GUICtrlCreateProgress(10,10,300,20)
GUICtrlCreateButton("Skip",320,10,70,20)
GUICtrlSetOnEvent(-1,"_Skip")
$CtrlProgress2 = GUICtrlCreateProgress(10,40,300,20)
GUICtrlCreateButton("Cancel",320,40,70,20)
GUICtrlSetOnEvent(-1,"_Cancel")
$CtrlName = GUICtrlCreateLabel("Downloading file: ",10,70,380,20)
$CtrlDesc = GUICtrlCreateLabel("Description: ",10,100,380,20)
$CtrlVers = GUICtrlCreateLabel("Version: ",10,130,380,20)
$CtrlSize = GUICtrlCreateLabel("Size: ",10,160,380,20)
GUICtrlCreateLabel("Total amount of files: " & UBound($downloads),10,220,380,20)
GUICtrlCreateLabel("Total Size: " & Round($downloads[0][9] / (1024*1024),0) & "MB",10,250,380,20)
GUISetState()

For $i = 0 To UBound($downloads) -1
    $hDownload = InetGet($downloads[$i][4],$downloads[$i][8],1,1)
    WinSetTitle($mainGUI,"","Downloading " & $downloads[$i][7])
    GUICtrlSetData($CtrlName,"Downloading file: " & $downloads[$i][5])
    GUICtrlSetData($CtrlDesc,"Description: " & $downloads[$i][1])
    GUICtrlSetData($CtrlVers,"Version: " & $downloads[$i][2])
    GUICtrlSetData($CtrlSize,"Size: " & $downloads[$i][3])
    While 1
        If InetGetInfo($hDownload,2) Then ExitLoop ;the download is complete. NEXT!
        If $bSkip Then ;checks if the skip button is pressed
            GUICtrlSetData($CtrlProgress1,100)
            InetClose($hDownload)
            $bSkip = False
            ExitLoop
        EndIf
        If $bCancel Then ;checks if the cancel button is pressed
            GUICtrlSetData($CtrlProgress2,100)
            ExitLoop 2
        EndIf
        GUICtrlSetData($CtrlProgress1,(InetGetInfo($hDownload,0)/$downloads[$i][6])*100) ;update file progress
        $currenttotal = $totalsize + InetGetInfo($hDownload,0) ;total downloaded = current+finished
        GUICtrlSetData($CtrlProgress2,($currenttotal/$downloads[0][9])*100) ;update total progress
        Sleep(500) ;no need to update too ofter is there?
    WEnd
    $totalsize += $downloads[$i][6] ; add the size of the complete download to the total
    Sleep(500)
Next

Func _Skip()
    $bSkip = True
EndFunc

Func _Cancel()
    $bCancel = True
EndFunc

Func _Exit()
    Exit
EndFunc

Edit: P.S. I do not have a crush on her, I just needed a big file to test with.

Edited by Tvern

Share this post


Link to post
Share on other sites
FlyinRiz

Thanks very much for the replies, your help is very much appreciated.

Yeah, so I've noticed, but it's only doing one download at a time, I think it's just structuring the loops properly, and my head is spinning reading bits here and there and not a "full picture".

Just to be clear, the downloads are processed one after another, not simultaneously, and the cancel button is to firstly cancel the current download in progress and break out of the loop and not process any others left to do.

Tvern, looked at your example, interesting... but I think like Aaron you've gone down the simultaneous route.

Glad Tvern could help...guess we were both assuming a much more complicated program :blink:

Edit: P.S. I do not have a crush on her, I just needed a big file to test with.

That's funny!

Share this post


Link to post
Share on other sites
AJStevens

I hope this will be helpfull. Time for spareribs now! :blink:

<autoitcode>

Edit: P.S. I do not have a crush on her, I just needed a big file to test with.

Tvern, that's great thanks, proves it can work... however trying to do it in my current code doesn't work, here's my example I've reworked.

I must be missing something obvious here... is it because I'm inside the _Download() function? *scratches head* I'd like to understand what I'm doing wrong here.

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

Opt("TrayMenuMode", 1)
Opt("GUIOnEventMode", 1)

Local $Download ;the handle of the currently active download
Global $bCancel

$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)

$lbl_Status    = GUICtrlCreateLabel("Click Download to begin", 30, 57, 300, 16)

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

$but_Download       = GUICtrlCreateButton("Download", 80, 120, 80, 30)
GUICtrlSetOnEvent(-1, "_Download")

$but_Cancel       = GUICtrlCreateButton("Cancel", 240, 120, 80, 30)
GUICtrlSetOnEvent(-1, "_Cancel")

GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")

GUISetState(@SW_Show)

While 1

    Sleep(10)

WEnd

Func _Close()
    Exit
EndFunc   ;==>_Close

Func _Cancel()
    $bCancel = True
EndFunc   ;==>_Cancel


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"

    ; Update Status
    GUICtrlSetData($lbl_Status, "Calculating Downloads...")

    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

        ; Calculate the current file percentage
        $FileProgress       = Floor(($i / (UBound($DownloadArray)-1)) * 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 & " %")

        If $bCancel Then ExitLoop

    Next

        ; 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 %")

        Sleep(2000)

    If Not $bCancel Then

    ; Do the Downloads
    For $i = 1 To UBound($DownloadArray)-1

        ; Create download Dir
        If Not FileExists("C:\Temp\") Then DirCreate("C:\Temp")

        ; Do the download in the background
        $Download = INetGet($DownloadArray[$i][0], "C:\Temp\test" & $i & ".exe", 1, 1)

        ; Update Status
        GUICtrlSetData($lbl_Status, "Downloading..." & $DownloadArray[$i][0])

        ; 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")

            If $bCancel Then ExitLoop 2

        ; 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

    EndIf

    If Not $bCancel Then

    ; Set overall progress bar to 100% when complete
    GUICtrlSetData($pb_Overall, 100)

    ; Set overall percent label to 100% when complete
    GUICtrlSetData($lbl_OverallPercent, "100 %")

    ; Update Status to say all downloads complete
    GUICtrlSetData($lbl_Status, "All downloads complete")

    Else

    ; Update Status to say all downloads complete
    GUICtrlSetData($lbl_Status, "Download Cancelled")

    EndIf

    Sleep(2000)

    ; 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

Share this post


Link to post
Share on other sites
Tvern

I think your cancel button doesn't work because an Event will not interrupt a function called by another event, or something like that, but someone with more knowledge of the way autoit works would have to confirm that. (the events are queue'd and run one after the other)

edit:

I think this quick hack might back up my theory

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

Opt("TrayMenuMode", 1)
Opt("GUIOnEventMode", 1)

Local $Download ;the handle of the currently active download
Global $bCancel, $bRun

$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)

$lbl_Status = GUICtrlCreateLabel("Click Download to begin", 30, 57, 300, 16)

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

$but_Download   = GUICtrlCreateButton("Download", 80, 120, 80, 30)
GUICtrlSetOnEvent(-1, "_Run")

$but_Cancel     = GUICtrlCreateButton("Cancel", 240, 120, 80, 30)
GUICtrlSetOnEvent(-1, "_Cancel")

GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")

GUISetState(@SW_Show)

While 1
    Sleep(10)
    If $bRun Then
        _Download()
    EndIf
WEnd

Func _Close()
    Exit
EndFunc ;==>_Close

Func _Cancel()
    ConsoleWrite("Cancelled" & @CRLF) ;I used this to find out that this function wasn't called when the button is pressed.
    $bCancel = True
EndFunc ;==>_Cancel

Func _Run()
    $bRun = True ;this function will return almost directly, allowing the cancel button to fire.
EndFunc ;==>_Cancel


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"

    ; Update Status
    GUICtrlSetData($lbl_Status, "Calculating Downloads...")

    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

    ; Calculate the current file percentage
    $FileProgress   = Floor(($i / (UBound($DownloadArray)-1)) * 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 & " %")

    If $bCancel Then ExitLoop
    Next

    ; 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 %")

    Sleep(2000)

    If Not $bCancel Then

    ; Do the Downloads
    For $i = 1 To UBound($DownloadArray)-1

    ; Create download Dir
    If Not FileExists("C:\Temp\") Then DirCreate("C:\Temp")

    ; Do the download in the background
    $Download = INetGet($DownloadArray[$i][0], "C:\Temp\test" & $i & ".exe", 1, 1)

    ; Update Status
    GUICtrlSetData($lbl_Status, "Downloading..." & $DownloadArray[$i][0])

    ; 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")

    If $bCancel Then ExitLoop 2

    ; 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

    EndIf

    If Not $bCancel Then

    ; Set overall progress bar to 100% when complete
    GUICtrlSetData($pb_Overall, 100)

    ; Set overall percent label to 100% when complete
    GUICtrlSetData($lbl_OverallPercent, "100 %")

    ; Update Status to say all downloads complete
    GUICtrlSetData($lbl_Status, "All downloads complete")

    Else

    ; Update Status to say all downloads complete
    GUICtrlSetData($lbl_Status, "Download Cancelled")

    EndIf

    Sleep(2000)

    ; 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)
    $bRun = False
    $bCancel = False
EndFunc
Edited by Tvern

Share this post


Link to post
Share on other sites
AJStevens

Tvern, that's great, thanks that works.

However, trying to put it into my own code... it's still not having it.

I thought it might have been because I call a function from within the function, so I tried a basic nest, no problem there.

I thought it might be because I'm reusing buttons (turning Check into Cancel, then into Download, then into Cancel again), so implemented those bits into that example and it still works.

So... I'm building a second script, moving in a piece at a time, trying to see where I've gone wrong... I've now got everything in there, except the Download function (still doing the cutepdf test downloads).

Either I'll figure it out, or will have written a new script and chalk it upto some minute oversight somewhere in my original script.

I'll post again after integrating the slightly enhanced download function, hopefully it'll still be working.

Edited by AJStevens

Share this post


Link to post
Share on other sites
Tvern

When you run into unexpected behavior like this it often helps to make the program report what it is doing.

Adding trace lines (from the tools menu in Scite if you have the full package), or using the debug console can help with this.

Share this post


Link to post
Share on other sites
NiVZ

Excellent, thank you.

I found the script I originally based the download/update portion of mine off of. I quickly edited it to OnEventMode instead of MessageLoop, and altered the GUI, it's much simplier than what my code has turned into, there's no bytes progress, or the code to generate the download array, though there is one here, much simplier than the one mine became or the rubbish I put in there to try to get cancel to work etc. but easier to work with I think. If the cancel button can be made to work here, then I can get it to work in my code (after a complete rewrite most likely).

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

Opt("TrayMenuMode", 1)
Opt("GUIOnEventMode", 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)

$lbl_Status    = GUICtrlCreateLabel("Click Download to begin", 30, 57, 300, 16)

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

$but_Download       = GUICtrlCreateButton("Download", 80, 120, 80, 30)
GUICtrlSetOnEvent(-1, "_Download")

$but_Cancel       = GUICtrlCreateButton("Cancel", 240, 120, 80, 30)
GUICtrlSetOnEvent(-1, "_Cancel")

GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")

GUISetState(@SW_Show)

While 1

    Sleep(10)

WEnd

Func _Close()
    Exit
EndFunc   ;==>_Close

Func _Cancel()

EndFunc   ;==>_Cancel


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)

        ; Update Status
        GUICtrlSetData($lbl_Status, "Downloading..." & $DownloadArray[$i][0])

        ; 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 %")

    ; Update Status to say all downloads complete
    GUICtrlSetData($lbl_Status, "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

Haha thought that _Download() code looked familiar, I'd recognise those comments anywhere ;)

This is possible to do - I've got another program which does multiple downloads sequentially (one after the other) from an Array and you can cancel it.

I think I had to change it back out of GUIOnEventMode while it's doing the downloads.

EDIT: Just saw your post in my original thread - yes you can make a progress bar for when it's getting the filesizes too. If I get a chance I'll see if I can put something together.

NiVZ

Edited by NiVZ

Share this post


Link to post
Share on other sites
NiVZ

Hello,

I found one that was very close so put it into the previous example. This one has a cancel button (plus a confirm cancel) and it shows a progress bar while getting filesizes (just used progresson function for quickness)

Only thing it doesn't do is reset the gui if you cancel - wasn't sure what you wanted to do if they cancel. It should get you on your way though.

For the Kb/Mb/Gb etc you need to use InetGetInfo($Download, 0) to get the bytes transferred and then just do a calculation (ie if it's less than 1024 use bytes, less than 1024*1024 use kB, less than 1024*1024*1024 use Mb, etc), and if you want average data transfer rate, use TimerInit before you start the download and then divide the amount you've downloaded by the time it's taken (you can also use that to give an estimated time remaining - in Microsoft minutes!)

NiVZ

#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()
    
    ; Change the Download Button to CANCEL
    GUICtrlSetData($but_download, "Cancel")
    
    ; 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"

    ; Use quick progresson function for when we are calculating filesizes
    ProgressOn("Downloader", "")

    For $i = 1 To UBound($DownloadArray)-1
        
        ; Calculate the percentage of the way through the file sizes we are
        $Percent = Round($i / (UBound($DownloadArray)-1) * 100)
        
        ; Update the progress display
        ProgressSet($Percent, $Percent & " %", "Getting size of file " & $i & " of " & 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
        
    ; Turn the progress off
    ProgressOff()
    
    ; Set cancel pressed to False
    $CancelPressed = False
    
    ; Do the Downloads
    For $i = 1 To UBound($DownloadArray)-1
        
        ; Do the download in the background
        $Download = INetGet($DownloadArray[$i][0], "C:\test" & $i & ".exe", 1, 1)
        
        ; Loop to update progress
        Do
            ; Check to see if any buttons have been pressed during download
            $nMsg = GUIGetMsg()
            
            ; If they pressed cancel 
            If $nMsg = $but_download Then
                
                ; Ask for confirmation to cancel in case they pressed it by mistake
                $ConfirmCancel = MsgBox(4, "Cancel Downloads?", "Do You Want To Cancel All Downloads?", -1, $Form1)
                
                ; Check if they said Yes to confirm cancel
                If $ConfirmCancel = 6 Then
                    ; Abort the current download
                    INetClose($Download)
                    
                    ; Set Cancel Pressed to true so we can exit the outer loop
                    $CancelPressed = True
                    
                    ; Exit the inner loop for the current download
                    ExitLoop
                EndIf
            
            EndIf
            
            ; 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)

        ; If CancelPressed is true then exit outer loop to abort all downloads
        If $CancelPressed Then ExitLoop
        
        ; 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

    ; If Cancel was pressed then leave progress bars alone
    If $CancelPressed Then
        MsgBox(64, "Cancelled", "All Downloads Cancelled", -1, $Form1)
        
    Else
        ; 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 %")
    EndIf
    
    ; Change the button back to DOWNLOAD
    GUICtrlSetData($but_download, "Download")
    
EndFunc
Edited by NiVZ

Share this post


Link to post
Share on other sites
AJStevens

When you run into unexpected behavior like this it often helps to make the program report what it is doing.

Adding trace lines (from the tools menu in Scite if you have the full package), or using the debug console can help with this.

Yep, I've got Console("Debug: " & "Notes" & $val & @CRLF) or MsgBox all over the place... wish I had a key to just paste that in on the line I'm on and a Tidy option to find them all and remove before compiling (I usually forget one somewhere.

Haha thought that _Download() code looked familiar, I'd recognise those comments anywhere ;)

This is possible to do - I've got another program which does multiple downloads sequentially (one after the other) from an Array and you can cancel it.

I think I had to change it back out of GUIOnEventMode while it's doing the downloads.

EDIT: Just saw your post in my original thread - yes you can make a progress bar for when it's getting the filesizes too. If I get a chance I'll see if I can put something together.

NiVZ

Hi NiVZ, yeah excellent example, helped me alot, I managed to achieve this finally (I think, some testing to do.. yesterday it was locking up doing a lot of filesize checks, for say downloading 30 files). Fortunately, I'm able to use GUIOnEventMode all the time.

I have percent labels, but the progress bars operate on the filesizes, I thought that would be better.

Hello,

I found one that was very close so put it into the previous example. This one has a cancel button (plus a confirm cancel) and it shows a progress bar while getting filesizes (just used progresson function for quickness)

Only thing it doesn't do is reset the gui if you cancel - wasn't sure what you wanted to do if they cancel. It should get you on your way though.

For the Kb/Mb/Gb etc you need to use InetGetInfo($Download, 0) to get the bytes transferred and then just do a calculation (ie if it's less than 1024 use bytes, less than 1024*1024 use kB, less than 1024*1024*1024 use Mb, etc), and if you want average data transfer rate, use TimerInit before you start the download and then divide the amount you've downloaded by the time it's taken (you can also use that to give an estimated time remaining - in Microsoft minutes!)

NiVZ

<code snipped>

Cool, still a very useful example that should be in the helpfile I think.

Mine resets, after a couple of seconds sleep, just so the user can see what happened.

Yep, done that, it also helps "decide" on the label, eg. KB, MB, GB as it increases.

Hmm.. transfer rate... hadn't thought about that... and Microsoft minutes estimated time... I might add that if it's desired, but seeing the data and percent progress is probably enough, lol. I'll have to read up on TimerInit, not used it yet.

I also had to do some registry work to get around the new behaviour for IE with username:password in URLS... what fun, this forum is an excellent resource.

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  

×