Sign in to follow this  
Followers 0
MarioX

Unable to abort a download, need help...

5 posts in this topic

#1 ·  Posted (edited)

I'm unable to stop a download in progress and quit the program...

I know that the function to stop a download is InetGet("abort")

How to correctly setup the abort routine ?

Thanks for any advice

Mario

#include <GUIConstants.au3>
GUICreate("Autoit download", 200, 100)
$label = GUICtrlCreateLabel("Write here filename(with "".exe""):", 10, 10, 200, 20)
$file = GUICtrlCreateInput("", 10, 30, 180, 20)
$okbutton = GUICtrlCreateButton("Download", 10, 60, 60, 30)
$quitbutton = GUICtrlCreateButton(" Quit ", 90, 60, 30)
$read = GUICtrlCreateLabel("Bytes: ", 150, 60, 100, 40)
GUISetState()
While 1
$msg = GUIGetMsg()
If $msg = $okbutton Then
If GUICtrlRead($file) = "" Then
MsgBox(48, "AutoIt Download", "Please give an place to download to")
Else
GUISetState(@SW_DISABLE)
GUICtrlSetData($label, "Downloading...")
$size = InetGetSize("http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe")
$inet = InetGet("http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe", GUICtrlRead($file), 0, 1) 

While @InetGetActive
$ToDown = $size - @InetGetBytesRead
GUICtrlSetData($read, "Bytes to download: " &$ToDown)
If $msg = $GUI_EVENT_CLOSE Then InetGet("abort")
Sleep(125)
Wend
GUICtrlSetData($label, "File downloaded!")
GUISetState(@SW_ENABLE)
EndIf
EndIf
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Edited by MarioX

Share this post


Link to post
Share on other sites



You are not updating $msg in your download loop so it never detects $GUI_EVENT_CLOSE.

Try:

While @InetGetActive
$ToDown = $size - @InetGetBytesRead
GUICtrlSetData($read, "Bytes to download: " &$ToDown)
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then InetGet("abort")
Wend

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks JdeB, I've added your code, but if I press the "X" close GUI the download is not stopped. The same happen if I change the code to use the Quit button:

If $msg = $GUI_EVENT_CLOSE Then InetGet("abort")

to

If $msg = $quitbutton Then InetGet("abort")

What's wrong ?

Thanks again

#include <GUIConstants.au3>
GUICreate("Autoit download", 200, 100)
$label = GUICtrlCreateLabel("Write here filename(with "".exe""):", 10, 10, 200, 20)
$file = GUICtrlCreateInput("", 10, 30, 180, 20)
$okbutton = GUICtrlCreateButton("Download", 10, 60, 60, 30)
$quitbutton = GUICtrlCreateButton(" Quit ", 90, 60, 30)
$read = GUICtrlCreateLabel("Bytes: ", 150, 60, 100, 40)
GUISetState()
While 1
$msg = GUIGetMsg()
If $msg = $okbutton Then
If GUICtrlRead($file) = "" Then
MsgBox(48, "AutoIt Download", "Please give an place to download to")
Else
GUISetState(@SW_DISABLE)
GUICtrlSetData($label, "Downloading...")
$size = InetGetSize("http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe")
$inet = InetGet("http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe", GUICtrlRead($file), 0, 1) 

While @InetGetActive
$ToDown = $size - @InetGetBytesRead
GUICtrlSetData($read, "Bytes to download: " &$ToDown)
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then InetGet("abort")
Wend
GUICtrlSetData($label, "File downloaded!")
GUISetState(@SW_ENABLE)
EndIf
EndIf
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Edited by MarioX

Share this post


Link to post
Share on other sites

Well what do you expect after you have done this command ? : GUISetState(@SW_DISABLE) B)

Comment it out and try again...


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Well what do you expect after you have done this command ? : GUISetState(@SW_DISABLE) B)

Oh yes, after fixed the GUISetState now everything work fine, thanks for your help, really appreciated.

Mario

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  
Followers 0