Jump to content

Get Transfer Speed.


AzKay
 Share

Recommended Posts

I looked at a post I had awhile ago, And Ive gotten to here:

$zSite = GUICtrlRead($Link)
            $zSize = INetGetSize($zSite)
            $LastSize = 0
            GUICtrlSetData($oSize, Round($zSize / 1024) & " KB")
            INetGet($zSite, GUICtrlRead($Dir), 1, 1)
            If @Error Then
                MsgBox(0, "Error", "Error, Something Fudged Up, Either, Try Again, Try Again Later, Or Stop Trying.")
            Else
            While @InetGetActive
                If GUICtrlRead($Progess) = 100 Then MsgBox(0, "Status", "Done")
                $zMsg = GUIGetMsg()
                    Select
                        Case $zMsg = $Cancel
                            INetGet("abort")
                            ExitLoop
                    EndSelect
                $speed = int((@InetGetBytesRead - $LastSize) /1000)
                $LastSize = @InetGetBytesRead
                GUICtrlSetData($oSpeed, $speed & " KB/s")
                GUICtrlSetData($oDownloaded, Round(@InetGetBytesRead / 1024) & " KB")
                GUICtrlSetData($Progess, Round(@InetGetBytesRead / $zSize * 100))
                 Sleep(1000) ;I dont want this here Dx
            WEnd

What im trying to do, Is, Get the transfer speed, Except, It only works right if ive got a 1 second sleep in there, But I cant have a sleep in there, or else it kinda breaks the rest of the gui.

Edited by AzKay
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

I just tryed that, Didnt work too right. Well, It did "work", But not as planned.

While @InetGetActive
                If GUICtrlRead($Progess) = 100 Then MsgBox(0, "Status", "Done")
                If GUICtrlRead($Progess) = 1 Then AdlibEnable("_Transfer", 1000)
                If GUICtrlRead($Progess) = 100 Then AdlibDisable()
                $zMsg = GUIGetMsg()
                    Select
                        Case $zMsg = $Cancel
                            INetGet("abort")
                            ExitLoop
                    EndSelect
                GUICtrlSetData($oDownloaded, Round(@InetGetBytesRead / 1024) & " KB")
                GUICtrlSetData($Progess, Round(@InetGetBytesRead / $zSize * 100))
            WEnd
;Skip some code


Func _Transfer()
    $speed = int((@InetGetBytesRead - $LastSize) /1000)
    $LastSize = @InetGetBytesRead
    GUICtrlSetData($oSpeed, $speed & " KB/s")
EndFunc
Edited by AzKay
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

  • Moderators

I looked at a post I had awhile ago, And Ive gotten to here:

$zSite = GUICtrlRead($Link)
            $zSize = INetGetSize($zSite)
            $LastSize = 0
            GUICtrlSetData($oSize, Round($zSize / 1024) & " KB")
            INetGet($zSite, GUICtrlRead($Dir), 1, 1)
            If @Error Then
                MsgBox(0, "Error", "Error, Something Fudged Up, Either, Try Again, Try Again Later, Or Stop Trying.")
            Else
            While @InetGetActive
                If GUICtrlRead($Progess) = 100 Then MsgBox(0, "Status", "Done")
                $zMsg = GUIGetMsg()
                    Select
                        Case $zMsg = $Cancel
                            INetGet("abort")
                            ExitLoop
                    EndSelect
                $speed = int((@InetGetBytesRead - $LastSize) /1000)
                $LastSize = @InetGetBytesRead
                GUICtrlSetData($oSpeed, $speed & " KB/s")
                GUICtrlSetData($oDownloaded, Round(@InetGetBytesRead / 1024) & " KB")
                GUICtrlSetData($Progess, Round(@InetGetBytesRead / $zSize * 100))
                 Sleep(1000) ;I dont want this here Dx
            WEnd
oÝ÷ ÙhZ¶)­¯(§Ú zÛazÚÚÇÞ®Ê^yÑ1qêm"Ú',(®K+mø¯z
-k[rݲW¦)íêÞëHq©í«ÞjÉ^z§¶«zÞÇ¢¶H§u¦ëy©,¶«zËh~Ø^迪ê-xz0v¨¹ìiyËm¢­¶ªºl¥çªê-ü¨¹Ú'ßÛn±ê®¢ÛbꮢØHv÷öÙ'£¶¬Âä±·jëjˬ¹©r¢çÚ[h¦º/×XäJ Ñ,M÷ßv®¶­s`vÆRæWDvWD7FfP b33c·6¦RÒçBæWDvWD'FW5&VB b33c·FÖRÒFÖW$æB buT7G&Å&VBb33cµ&övW72ÒFVâ×6t&÷ÂgV÷Cµ7FGW2gV÷C²ÂgV÷C´FöæRgV÷C² b33c·¤×6rÒuTvWD×6r 6VÆV7@ 66Rb33c·¤×6rÒb33c´6æ6VÀ æWDvWBgV÷C¶&÷'BgV÷C² WDÆö÷ VæE6VÆV7@ b33c·7VVBÒ&÷VæBçBæWDvWD'FW5&VBÒb33c·6¦Rò#BòFÖW$Ffbb33c·FÖRòÂ" uT7G&Å6WDFFb33c¶õ7VVBÂb33c·7VVBfײgV÷C²´"÷2gV÷C² uT7G&Å6WDFFb33c¶ôF÷væÆöFVBÂ&÷VæBæWDvWD'FW5&VBò#BfײgV÷C²´"gV÷C² uT7G&Å6WDFFb33cµ&övW72Â&÷VæBæWDvWD'FW5&VBòb33c·¥6¦R¢ tVæ
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Oh... and another thing... Why don't you change that :whistle: avatar, I'll not even look at another one of your posts again. That thing doesn't even let you look at your code or what you typed without wanting to puke.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Oh... and another thing... Why don't you change that :whistle: avatar, I'll not even look at another one of your posts again. That thing doesn't even let you look at your code or what you typed without wanting to puke.

Hmm, Okai, It was only supposed to be there for halloween anyway. Forgot to change it.

Your suggestion seems to work, But not really, Well, Now its changing too fast, and i do put a short sleep in there, 100 miliseconds, everytime it hits 1000, Like, 1000kb, 2000kb, etc, It goes to "0". I may aswell post my whole code then, Seeing as it should be the "working" code. (( The part im looking at is the part down the very bottom. Which would be downloading without auth or proxy checked. ))

#include <GUIConstants.au3>
#include <File.au3>
Opt("TrayMenuMode", 1)

#Region ### START Koda GUI section ### Form=
$GUI = GUICreate("[[ \\ AzKay's DownLoad3r // ]]", 289, 322, 193, 115)
$Link = GUICtrlCreateInput("http://ftp-mozilla.netscape.com/pub/mozilla.org/firefox/releases/2.0/win32/en-US/Firefox Setup 2.0.exe", 64, 8, 217, 21)
$Dir = GUICtrlCreateInput("C:\", 64, 32, 137, 21)
$Auth = GUICtrlCreateCheckbox("User Auth.", 8, 56, 89, 17)
$User = GUICtrlCreateInput("", 168, 56, 113, 21)
$Pass = GUICtrlCreateInput("", 168, 80, 113, 21, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL))
$Proxy = GUICtrlCreateCheckbox("User Proxy", 8, 104, 73, 17)
$IP = GUICtrlCreateInput("", 168, 104, 113, 21)
$Port = GUICtrlCreateInput("", 168, 128, 113, 21)
$oDownloaded = GUICtrlCreateInput("", 104, 224, 81, 21)
$oSize = GUICtrlCreateInput("", 8, 224, 81, 21)
$Progess = GUICtrlCreateProgress(8, 256, 273, 25, $PBS_SMOOTH)
GUICtrlSetData(-1, 25)
$Download = GUICtrlCreateButton("Download", 8, 288, 129, 25, 0)
$Cancel = GUICtrlCreateButton("Cancel", 152, 288, 129, 25, 0)
$CheckProxy = GUICtrlCreateButton("Check Proxy", 8, 128, 89, 17, 0)
$ProxyList = GUICtrlCreateButton("Open Proxy List ----------------------------------------------------------->", 8, 152, 273, 25, 0)
$Browse = GUICtrlCreateButton("Browse", 208, 32, 73, 17, 0)
$Url = GUICtrlCreateLabel("Address:", 8, 8, 45, 17)
$SaveTo = GUICtrlCreateLabel("Save To:", 8, 32, 48, 17)
$Username = GUICtrlCreateLabel("Username:", 112, 56, 55, 17)
$Password = GUICtrlCreateLabel("Password:", 112, 80, 53, 17)
$ProxyIP = GUICtrlCreateLabel("Proxy IP:", 112, 104, 46, 17)
$ProxyPort = GUICtrlCreateLabel("Proxy Port:", 112, 128, 55, 17)
$Size = GUICtrlCreateLabel("Size:", 8, 200, 27, 17)
$Downloaded = GUICtrlCreateLabel("Downloaded:", 104, 200, 67, 17)
$oSpeed = GUICtrlCreateInput("", 200, 224, 81, 21)
$Speed = GUICtrlCreateLabel("Speed:", 200, 200, 38, 17)
ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 6)
ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 7)
ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 9)
ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 10)
ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 11)
ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 12)
ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 21)
ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 22)
ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 23)
ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 24)
ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 27)
Dim $zDrive, $zDir, $zName, $zExt
GUISetState(@SW_SHOW)
$Hide = TrayCreateItem("Hide")
$Show = TrayCreateItem("Show")

$GUIList = GUICreate("Proxy List", 258, 290, 193, 115, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS))
$List = GUICtrlCreateEdit("", 0, 0, 257, 289, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL))
GUICtrlSetData($Progess, 0)
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
$xMsg = TrayGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $Browse
            _PathSplit(GUICtrlRead($Link), $zDrive, $zDir, $zName, $zExt)
            GUICtrlSetData($Dir, FileOpenDialog("Save To:", "", "All (*.*)", "", $zName & $zExt))
            
        Case $Auth
            If GUICtrlRead($Auth) = $GUI_UNCHECKED Then
                ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 6)
                ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 7)
                ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 21)
                ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 22)
            Else
                ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", 6)
                ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", 7)
                ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", 21)
                ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", 22)
            EndIf
        
        Case $Proxy
            If GUICtrlRead($Proxy) = $GUI_UNCHECKED Then
                ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 9)
                ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 10)
                ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 23)
                ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", 24)
            Else
                ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", 9)
                ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", 10)
                ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", 23)
                ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", 24)
            EndIf
        
        Case $ProxyList
            If ControlGetText("[[ \\ AzKay's DownLoad3r // ]]", "", 17) = _
            "Open Proxy List ----------------------------------------------------------->" Then
            ControlSetText("[[ \\ AzKay's DownLoad3r // ]]", "", 17, _
            "<----------------------------------------------------------- Close Proxy List")
            GUISetState(@SW_SHOW, $GUIList)
            Else
            GUISetState(@SW_HIDE, $GUIList)
            ControlSetText("[[ \\ AzKay's DownLoad3r // ]]", "", 17, _
            "Open Proxy List ----------------------------------------------------------->")
            EndIf
        
        Case $CheckProxy
            ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", $CheckProxy)
            TCPStartup()
            $Socket = TCPConnect(GUICtrlRead($IP), GUICtrlRead($Port))
            If @Error Then 
                MsgBox(0, "Status", GUICtrlRead($IP) & ":" & GUICtrlRead($Port) & " // Offline")
            Else
                MsgBox(0, "Status", GUICtrlRead($IP) & ":" & GUICtrlRead($Port) & " // Online")
            EndIf
            TCPShutdown()
            ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", $CheckProxy)
            
        Case $Download
            If Not GUICtrlRead($Dir) = "" Then
            If BitAND(GUICtrlRead($Auth), $GUI_CHECKED) And BitAND(GUICtrlRead($Proxy), $GUI_CHECKED) Then
            HttpSetProxy(2, GUICtrlRead($IP) & ":" & GUICtrlRead($Port))
            ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", $Download)
            If StringInStr(GUICtrlRead($Link), "http://") Then
            $oLink = StringTrimLeft(GUICtrlRead($Link), 7)
            $AuthLink = "http://" & GUICtrlRead($User) & ":" & GUICtrlRead($Pass) & "@" & $oLink
            $zSite = $AuthLink
            $zSize = INetGetSize($zSite)
            $LastSize = 0
            GUICtrlSetData($oSize, Round($zSize / 1024) & " KB")
            INetGet($zSite, GUICtrlRead($Dir), 1, 1)
            If @Error Then
                MsgBox(0, "Error", "Error, Something Fudged Up, Either, Try Again, Stop Trying, Or The Site Doesnt Support user:pass@site Format.")
            Else
            While @InetGetActive
                $zMsg = GUIGetMsg()
                    Select
                        Case $zMsg = $Cancel
                            INetGet("abort")
                    EndSelect
                $speed = int((@InetGetBytesRead - $LastSize) /1000)
                $LastSize = @InetGetBytesRead
                GUICtrlSetData($oSpeed, $speed & " KB/s")
                GUICtrlSetData($oDownloaded, Round(@InetGetBytesRead / 1024) & " KB")
                GUICtrlSetData($Progess, Round(@InetGetBytesRead / $zSize * 100))
                If GUICtrlRead($Progess) = 100 Then MsgBox(0, "Status", "Done")
                Sleep(1000)
            WEnd
            ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", $Download)
            EndIf
            Else
                MsgBox(0, "Error", "Error, Remember To Use Format http://")
                ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", $Download)
            EndIf
            HttpSetProxy(1)             

            ElseIf BitAND(GUICtrlRead($Auth),$GUI_CHECKED) And BitAND(GUICtrlRead($Proxy),$GUI_UNCHECKED) Then
            ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", $Download)
            If StringInStr(GUICtrlRead($Link), "http://") Then
            $oLink = StringTrimLeft(GUICtrlRead($Link), 7)
            $AuthLink = "http://" & GUICtrlRead($User) & ":" & GUICtrlRead($Pass) & "@" & $oLink
            $zSite = $AuthLink
            $zSize = INetGetSize($zSite)
            $LastSize = 0
            GUICtrlSetData($oSize, Round($zSize / 1024) & " KB")
            INetGet($zSite, GUICtrlRead($Dir), 1, 1)
            If @Error Then
                MsgBox(0, "Error", "Error, Something Fudged Up, Either, Try Again, Or The Site Doesnt Support user:pass@site Format.")
            Else
            While @InetGetActive
                $zMsg = GUIGetMsg()
                    Select
                        Case $zMsg = $Cancel
                            INetGet("abort")
                    EndSelect
                $speed = int((@InetGetBytesRead - $LastSize) /1000)
                $LastSize = @InetGetBytesRead
                GUICtrlSetData($oSpeed, $speed & " KB/s")
                GUICtrlSetData($oDownloaded, Round(@InetGetBytesRead / 1024) & " KB")
                GUICtrlSetData($Progess, Round(@InetGetBytesRead / $zSize * 100))
                If GUICtrlRead($Progess) = 100 Then MsgBox(0, "Status", "Done")
                Sleep(1000)
            WEnd
            ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", $Download)
            EndIf
            Else
                MsgBox(0, "Error", "Error, Remember To Use Format http://")
                ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", $Download)
            EndIf
            
            ElseIf BitAND(GUICtrlRead($Proxy),$GUI_CHECKED) And BitAND(GUICtrlRead($Auth), $GUI_UNCHECKED) Then
            HttpSetProxy(2, GUICtrlRead($IP) & ":" & GUICtrlRead($Port))
            ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", $Download)
            $zSite = GUICtrlRead($Link)
            $zSize = INetGetSize($zSite)
            $LastSize = 0
            GUICtrlSetData($oSize, Round($zSize / 1024) & " KB")
            INetGet($zSite, GUICtrlRead($Dir), 1, 1)
            
            While @InetGetActive
                $zMsg = GUIGetMsg()
                    Select
                        Case $zMsg = $Cancel
                            INetGet("abort")
                    EndSelect
                $speed = int((@InetGetBytesRead - $LastSize) /1000)
                $LastSize = @InetGetBytesRead
                GUICtrlSetData($oSpeed, $speed & " KB/s")
                GUICtrlSetData($oDownloaded, Round(@InetGetBytesRead / 1024) & " KB")
                GUICtrlSetData($Progess, Round(@InetGetBytesRead / $zSize * 100))
                If GUICtrlRead($Progess) = 100 Then MsgBox(0, "Status", "Done")
                Sleep(1000)
            WEnd
            ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", $Download)
            HttpSetProxy(1)
            
;## This section here.  
            ElseIf BitAND(GUICtrlRead($Auth),$GUI_UNCHECKED) And BitAND(GUICtrlRead($Proxy),$GUI_UNCHECKED) Then
            ControlDisable("[[ \\ AzKay's DownLoad3r // ]]", "", $Download)
            $zSite = GUICtrlRead($Link)
            $zSize = INetGetSize($zSite)
            $LastSize = 0
            GUICtrlSetData($oSize, Round($zSize / 1024) & " KB")
            INetGet($zSite, GUICtrlRead($Dir), 1, 1)
            If @Error Then
                MsgBox(0, "Error", "Error, Something Fudged Up, Either, Try Again, Try Again Later, Or Stop Trying.")
            Else
            While @InetGetActive
                $size = Int(@InetGetBytesRead)
                $time = TimerInit()
                If GUICtrlRead($Progess) = 100 Then MsgBox(0, "Status", "Done")
                $zMsg = GUIGetMsg()
                    Select
                        Case $zMsg = $Cancel
                            INetGet("abort")
                            ExitLoop
                    EndSelect
                $speed = Round(((Int(@InetGetBytesRead) - $size) / 1024) / (TimerDiff($time) / 1000), 2)
                GUICtrlSetData($oSpeed, $speed & " KB/s")
                GUICtrlSetData($oDownloaded, Round(@InetGetBytesRead / 1024) & " KB")
                GUICtrlSetData($Progess, Round(@InetGetBytesRead / $zSize * 100))
            WEnd
            ControlEnable("[[ \\ AzKay's DownLoad3r // ]]", "", $Download)
            EndIf
            Else
            MsgBox(0, "Error", "Error, Enter a directory")
            EndIf
            EndIf
    EndSwitch
WEnd
Edited by AzKay
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

  • Moderators

I use sleep 250 in my download progress loops personally, and I use a standard progress bar rather than a GUI based one.

That way I can use /AutoIt3ExecuteScript with the update loop, that doesn't effect my script at all.

Just some food for thought.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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