Jump to content

Stopping InetGet


Recommended Posts

InetGet("abort") doesnt seem to work? I created the following:

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

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Gamedler", 291, 236, 193, 125)
$Button1 = GUICtrlCreateButton("Button1", 200, 16, 75, 25, 0)
;left, top, width, height
$Progress1 = GUICtrlCreateProgress(20, 64, 150, 15)
$Label1 = GUICtrlCreateLabel("Label1", 32, 32, 252, 17)

$Button2 = GUICtrlCreateButton("Button2", 200, 56, 75, 25, 0)
$Button3 = GUICtrlCreateButton("Button3", 200, 96, 75, 25, 0)
$Exit = GUICtrlCreateButton("Exit", 208, 192, 51, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            $FileURL = "http://www.flx.me/installr.exe"
            $FileName = "installr.exe"
            $FileSaveLocation = FileSaveDialog("Save Location...",@ScriptDir,"All (*.*)",18,$FileName)
            $FileSize = InetGetSize($FileURL)

            InetGet($FileURL,$FileName,1,1)
            ;ProgressOn("","")
            While @InetGetActive
                $Percentage = @InetGetBytesRead * 100 / $FileSize
                $SizeMB = $FileSize / 1024 / 1024
                $StatMB = @InetGetBytesRead / 1024 / 1024
                $PercentageGUI = int(@InetGetBytesRead/$FileSize*100) & "%"
                GUICtrlSetData($Progress1, $Percentage)
                GUICtrlSetData($Label1, $PercentageGUI & "  " & int(@InetGetBytesRead/1024)&"kB of "&int($FileSize/1024)&"kB")
                Sleep(250)
            Wend
            
            ;ProgressOff()
MsgBox(0, "Done","Download Complete!")
        Case $Button2
            InetGet("abort")
        Case $Exit
            Exit
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Help is greatly appreciated ^_^

Link to comment
Share on other sites

InetGet("abort") doesnt seem to work? I created the following:

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

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Gamedler", 291, 236, 193, 125)
$Button1 = GUICtrlCreateButton("Button1", 200, 16, 75, 25, 0)
;left, top, width, height
$Progress1 = GUICtrlCreateProgress(20, 64, 150, 15)
$Label1 = GUICtrlCreateLabel("Label1", 32, 32, 252, 17)

$Button2 = GUICtrlCreateButton("Button2", 200, 56, 75, 25, 0)
$Button3 = GUICtrlCreateButton("Button3", 200, 96, 75, 25, 0)
$Exit = GUICtrlCreateButton("Exit", 208, 192, 51, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            $FileURL = "http://www.flx.me/installr.exe"
            $FileName = "installr.exe"
            $FileSaveLocation = FileSaveDialog("Save Location...",@ScriptDir,"All (*.*)",18,$FileName)
            $FileSize = InetGetSize($FileURL)

            InetGet($FileURL,$FileName,1,1)
            ;ProgressOn("","")
            While @InetGetActive
                $Percentage = @InetGetBytesRead * 100 / $FileSize
                $SizeMB = $FileSize / 1024 / 1024
                $StatMB = @InetGetBytesRead / 1024 / 1024
                $PercentageGUI = int(@InetGetBytesRead/$FileSize*100) & "%"
                GUICtrlSetData($Progress1, $Percentage)
                GUICtrlSetData($Label1, $PercentageGUI & "  " & int(@InetGetBytesRead/1024)&"kB of "&int($FileSize/1024)&"kB")
                Sleep(250)
            Wend
            
            ;ProgressOff()
MsgBox(0, "Done","Download Complete!")
        Case $Button2
            InetGet("abort")
        Case $Exit
            Exit
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEndoÝ÷ Øw¥¦+ ­æ­&©¦·«^wú®¢×¢¶Øb²Z(¥j+Þ´g­È§²'^Ö(º±#¥z-­ë)¢wm¢·ª¹ë-³bì(®H§Øb²Z(¤Ê/xÞ´g­+^±v)í¢Ø^¨§)jwb·
+Æ®¶­sevÆRæWDvWD7FfP b33cµW&6VçFvRÒæWDvWD'FW5&VB¢òb33c´fÆU6¦P b33cµ6¦TÔ"Òb33c´fÆU6¦Rò#Bò#@ b33cµ7FDÔ"ÒæWDvWD'FW5&VBò#Bò#@ b33cµW&6VçFvTuTÒçBæWDvWD'FW5&VBòb33c´fÆU6¦R£fײgV÷C²RgV÷C° uT7G&Å6WDFFb33cµ&öw&W73Âb33cµW&6VçFvR uT7G&Å6WDFFb33c´Æ&VÃÂb33cµW&6VçFvTuTfײgV÷C²gV÷C²fײçBæWDvWD'FW5&VBó#BfײgV÷C¶´"öbgV÷C²f׶çBb33c´fÆU6¦Ró#BfײgV÷C¶´"gV÷C² 6ÆVW#S¥vVæ
Link to comment
Share on other sites

Here's you part of the code of my program. I hope this helps you.

func UpdateDlg($hWnd = 0)
    
    const $timeout = 10 * 1000
    
    local $uhgui, $uprogress, $ulbfile, $ulbresult, $uicon, $ucheck, $ubdownload, $ubok, $umsg
    local $td, $cbyte, $pbyte, $size, $fn = '', $complete = 0, $error = 0, $update = 0
    local $updpath = @MyDocumentsDir
    
    $uhgui = GUICreate($Lang[13], 380, 261, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU), -1, $hWnd)

    GUISetFont(8.5, 400, 0, 'Tahoma', $uhgui)

    GUICtrlCreateGroup($Lang[14], 11, 10, 358, 208)
    GUICtrlCreateLabel($Lang[15], 115, 32, 128, 14)
    GUICtrlCreateLabel($GUI_VERSION, 245, 32, 106, 14)
    GUICtrlCreateLabel($Lang[16], 115, 54, 128, 14)
    GUICtrlCreateLabel($ActualVer, 245, 54, 106, 14)
     _DrawIcon(@ScriptFullPath, 0, 23, 30, 64, 64)
    $ucheck = GUICtrlCreateCheckbox($Lang[9], 26, 193, 328, 14)
    GUICtrlSetState(-1, ($GUI_CHECKED * (not $cUpdate)) + ($GUI_UNCHECKED * $cUpdate) + ($GUI_SHOW * ($hWnd = $Form)) + ($GUI_HIDE * (not ($hWnd = $Form))))
    $ulbfile = GUICtrlCreateLabel('', 26, 118, 328, 14)
    GUICtrlSetState(-1, $GUI_HIDE)
    $uicon = GUICtrlCreateIcon(@ScriptFullPath, -5, 94, 117, 16, 16)
    GUICtrlSetState(-1, $GUI_HIDE)
    $ulbresult = GUICtrlCreateLabel('', 115, 118, 210, 14)
    GUICtrlSetState(-1, $GUI_HIDE)
    $uprogress = GUICtrlCreateProgress(26, 135, 328, 14)
    GUICtrlSetState(-1, $GUI_HIDE)
    $ubdownload = GUICtrlCreateButton($Lang[17], 140, 158, 100, 23)
    $ubok = GUICtrlCreateButton('OK', 295, 228, 75, 23)
    GUICtrlSetState(-1, BitOR($GUI_DEFBUTTON, $GUI_FOCUS))

    GUISetState(@SW_SHOW, $uhgui)

    while 1
        if $update then
            if (@InetGetActive) and (not $error) then
                $cbyte = @InetGetBytesRead
                if $cbyte < 0 then
                    $error = 1
                else
                    if $cbyte > $pbyte then
                        $pbyte = $cbyte
                        $td = TimerInit()
                    else
                        if TimerDiff($td) > $timeout then
                            $error = 1
                        endif
                    endif
                endif
                Sleep(10)
            else
                $cbyte = @InetGetBytesRead
                if $cbyte < 0 then
                    $error = 1
                else
                    $complete = 1
                endif
            endif
            if (not $error) and (not $complete) then
                GUICtrlSetData($uprogress, $cbyte / $size * 100)
            endif
        endif
        if ($error) or ($complete) then
            InetGet('abort')
            GUICtrlSetState($ubok, $GUI_ENABLE)
            GUICtrlSetState($uprogress, $GUI_HIDE)
            GUICtrlSetState($ulbfile, $GUI_HIDE)
            if $error then
                GUICtrlSetState($uicon, $GUI_SHOW)
                GUICtrlSetData($ulbresult, $Lang[18])
                GUICtrlSetState($uicon, $GUI_SHOW)
                FileDelete($fn)
            else
                GUICtrlSetState($ubdownload, $GUI_DISABLE)
                GUICtrlSetData($ulbresult, $Lang[19])
            endif
            GUICtrlSetState($ulbresult, $GUI_SHOW)
            GUICtrlSetData($uprogress, 0)
            GUICtrlSetData($ulbfile, '')
            GUICtrlSetData($ubdownload, $Lang[17])
            $fn = ''
            $update = 0
            $complete = 0
            $error = 0
        endif
        $umsg = GUIGetMsg()
        select
            case ($umsg = $ubok) or ($umsg = $GUI_EVENT_CLOSE)
                if $update then
                    if MsgBox(48 + 4, $Lang[13], $Lang[20] & @CR & @CR & $Lang[22], 0, $uhgui) = 6 then
                        InetGet('abort')
                        FileDelete($fn)
                        exitloop
                    endif
                else
                    exitloop
                endif
            case ($umsg = $ubdownload)
                if $update then
                    InetGet('abort')
                    FileDelete($fn)
                    $fn = ''
                    GUICtrlSetState($ubok, $GUI_ENABLE)
                    GUICtrlSetState($uprogress, $GUI_HIDE)
                    GUICtrlSetState($ulbfile, $GUI_HIDE)
                    GUICtrlSetData($uprogress, 0)
                    GUICtrlSetData($ulbfile, '')
                    GUICtrlSetData($ubdownload, $Lang[17])
                    $update = 0
                else
                    $fn = FileSaveDialog($Lang[10], $updpath, $Lang[12], 1 + 2, StringTrimLeft($fUpdate, StringInStr($fUpdate, '/', 0, -1)), $uhgui)
                    if StringLen($fn) > 0 then
                        $updpath = StringMid($fn, 1, StringInStr($fn, '\', 0, -1) - 1)
                        GUICtrlSetState($uicon, $GUI_HIDE)
                        GUICtrlSetState($ulbresult, $GUI_HIDE)
                        GUICtrlSetState($ubok, $GUI_DISABLE)
                        GUICtrlSetState($uprogress, $GUI_SHOW)
                        GUICtrlSetState($ulbfile, $GUI_SHOW)
                        GUICtrlSetData($ulbresult, '')
                        GUICtrlSetData($ulbfile, _StringCut($uhgui, $ulbfile, $fn, 328))
                        GUICtrlSetData($ubdownload, $Lang[21])
                        $update = 1
                        $complete = 0
                        $cbyte = 0
                        $pbyte = 0
                        $size = InetGetSize($fUpdate)
                        if (@error) or ($size = 0) then
                            $error = 1
                        else
                            $error = 0
                            InetGet($fUpdate, $fn, 1, 1)
                            $td = TimerInit()
                        endif
                    endif
                endif
            case ($umsg = $ucheck)
                $cUpdate = not $cUpdate
        endselect
    wend

    _WinAPI_SetActiveWindow($hWnd)
    
    GUIDelete($uhgui)

endfunc; UpdateDlg
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...