Jump to content

Unable to abort a download, need help...


MarioX
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Developers

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

Comment it out and try again...

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...