Jump to content
Sign in to follow this  
bordomavi

InetClose error

Recommended Posts

bordomavi

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <Math.au3>

#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Form1", 616, 194, 544, 139)
$gProgress = GUICtrlCreateProgress(56, 120, 473, 49)
$download = GUICtrlCreateButton("download", 160, 40, 265, 49)
$cancel = GUICtrlCreateButton("cancel", 552, 120, 49, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $download
            _Download("https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/win32/tr/Firefox%20Setup%2032.0.exe", @TempDir & "\Setup.exe")
        Case $cancel
            _cancel()
    EndSwitch
WEnd

Func _cancel()
    Local $hhdownload = InetGet("https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/win32/tr/Firefox%20Setup%2032.0.exe", @TempDir & "\Setup.exe", 1, 1)
    InetClose($hhDownload)
    FileDelete(@TempDir & "\Setup.exe")
EndFunc

Func _Download($address, $dest)
$_FinalUrl = 'https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/win32/tr/Firefox%20Setup%2032.0.exe'
$_TempPath = @TempDir & '\setup.exe'
$_FileSize = InetGetSize ( $_FinalUrl )
$_Download = InetGet ( $_FinalUrl, $_TempPath, 1, 1 )
Local $_InfoData
Do
    $_InfoData = InetGetInfo ( $_Download )
    If Not @error Then
        $_InetGet = $_InfoData[0]
        $_DownloadPercent = Round ( ( 100 * $_InetGet ) / $_FileSize )
        $_DownloadPercent = _Min ( _Max ( 1, $_DownloadPercent ), 99 )
        GUICtrlSetData ( $gProgress, $_DownloadPercent )
        $_Label = GUICtrlCreateLabel ( 'Mozilla downloading... : ' & ' %' & $_DownloadPercent, 142, 355, 212, 12)
    EndIf
    Sleep ( 100 )
Until $_InfoData[2] = True
EndFunc

why cancel button doesn't work?

Share this post


Link to post
Share on other sites
bordomavi

Why start download then cancel in _cancel function.

it is not my answer

Share this post


Link to post
Share on other sites
JohnOne

Well the answer to you rather vague question is that your cancel button works just fine.

But I think you'll need to wait until a download actually starts before you can cancel it.

Example might be to alter the function...

#include <InetConstants.au3>
Func _cancel()
    Local $hhdownload = InetGet("https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/win32/tr/Firefox%20Setup%2032.0.exe", @TempDir & "\Setup.exe", 1, 1)

    Do
        Sleep(250)
    Until InetGetInfo($hhdownload, $INET_DOWNLOADREAD) > 0

    InetClose($hhDownload)
    FileDelete(@TempDir & "\Setup.exe")
EndFunc

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
bordomavi

 

Well the answer to you rather vague question is that your cancel button works just fine.

But I think you'll need to wait until a download actually starts before you can cancel it.

Example might be to alter the function...

#include <InetConstants.au3>
Func _cancel()
    Local $hhdownload = InetGet("https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/win32/tr/Firefox%20Setup%2032.0.exe", @TempDir & "\Setup.exe", 1, 1)

    Do
        Sleep(250)
    Until InetGetInfo($hhdownload, $INET_DOWNLOADREAD) > 0

    InetClose($hhDownload)
    FileDelete(@TempDir & "\Setup.exe")
EndFunc

Tried. not working

Share this post


Link to post
Share on other sites
bordomavi

OS? OSArch? Build? Autoit Version?

Windows7 x64 latest autoit

Share this post


Link to post
Share on other sites
bordomavi

same as me and it works great for me.

is it stops download while downloading?

Share this post


Link to post
Share on other sites
bordomavi

It stops the download that is started in the _Cancel function.

It cannot stop the one which is started in the _Download function.

it must stops the one which is started in the _download() function

Share this post


Link to post
Share on other sites
JohnOne

Well you have a number of problems with that. First and foremost, when that download begins it is then stuck in a Do...Until loop until it finished.

There are a number of ways you can fix this, one being to check the Gui msg in that loop and another is to check the download status in the main GUI loop.

And for sanity sake, remove the download you start in the _cancel function.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
kylomas

implementing J1's suggestion...

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <Math.au3>

#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Form1", 616, 194, 544, 139)
$gProgress = GUICtrlCreateProgress(56, 120, 473, 49)
$download = GUICtrlCreateButton("download", 160, 40, 265, 49)
$cancel = GUICtrlCreateButton("cancel", 552, 120, 49, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $download
            _Download("https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/win32/tr/Firefox%20Setup%2032.0.exe", @TempDir & "\Setup.exe")
    EndSwitch
WEnd

Func _Download($address, $dest)
    $_FinalUrl = 'https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/win32/tr/Firefox%20Setup%2032.0.exe'
    $_TempPath = @TempDir & '\setup.exe'
    $_FileSize = InetGetSize($_FinalUrl)
    $_Download = InetGet($_FinalUrl, $_TempPath, 1, 1)
    Local $_InfoData
    Do
        If GUIGetMsg() = $cancel Then
            InetClose($_Download)
            FileDelete(@TempDir & "\Setup.exe")
            ConsoleWrite('Download cancelled' & @CRLF)
            Return
        EndIf
        $_InfoData = InetGetInfo($_Download)
        If Not @error Then
            $_InetGet = $_InfoData[0]
            $_DownloadPercent = Round((100 * $_InetGet) / $_FileSize)
            $_DownloadPercent = _Min(_Max(1, $_DownloadPercent), 99)
            GUICtrlSetData($gProgress, $_DownloadPercent)
            $_Label = GUICtrlCreateLabel('Mozilla downloading... : ' & ' %' & $_DownloadPercent, 142, 355, 212, 12)
        EndIf
        Sleep(100)
    Until $_InfoData[2] = True
EndFunc   ;==>_Download

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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  

×