Sign in to follow this  
Followers 0
yucatan

progress bar

6 posts in this topic

hello guys i wanne make a progras bar of a file transfer

for example this is the total bytes :27253985

my progras write's this

5505024 62% 5.22MB/s 0:00:00

5505024 62% 5.22MB/s 0:00:00|

8742784 100% 5.48MB/s 0:00:01 (xfer#1, to-check=28/30)

this is the number of bytes that has been done

"5505024"

"8742784"

so i wanne do "27253985" is 100 %

if i get 5505024 from my program that is the amount of data that has been done

so 27253985 - 5505024 = ....%

so that if i do 27253985 - 5505024 then the transfer is on ... %

how should i calculate this?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

hello guys i wanne make a progras bar of a file transfer

for example this is the total bytes :27253985

my progras write's this

5505024 62% 5.22MB/s 0:00:00

5505024 62% 5.22MB/s 0:00:00|

8742784 100% 5.48MB/s 0:00:01 (xfer#1, to-check=28/30)

this is the number of bytes that has been done

"5505024"

"8742784"

so i wanne do "27253985" is 100 %

if i get 5505024 from my program that is the amount of data that has been done

so 27253985 - 5505024 = ....%

so that if i do 27253985 - 5505024 then the transfer is on ... %

how should i calculate this?

Hi,

you should calculate it like this:

% done = bytes done / total bytes * 100

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites

can u maby give me a sample because i do not fully understand.

Thx

Share this post


Link to post
Share on other sites

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

$MaxPercent = 1000

$Form1 = GUICreate("", 116, 66, 192, 124)
$Label1 = GUICtrlCreateLabel("0", 20, 40, 30, 17)
$Button1 = GUICtrlCreateButton("+1", 8, 8, 99, 25, $WS_GROUP)
$Label2 = GUICtrlCreateLabel("0%", 80, 40, 30, 17)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlSetData($Label1, GUICtrlRead($Label1) + 1)
            GUICtrlSetData($Label2, GUICtrlRead($Label1) * 100 / $MaxPercent & "%")
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Hi there!

I dont know if is this that you are looking for, but i tried to make it simple, then i excited myself and made this :)

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiStatusBar.au3>
#Region ### START Koda GUI section ### Form=

dim $total, $prepercent, $percent, $Filedisk
$Filedisk = 0
$fdownload = "http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-sfx.exe"
$last = StringSplit($fdownload, "/")
$limit = UBound($last)
$file = $last[$limit-1]
;ConsoleWrite($file & @CRLF)

$Form1 = GUICreate("Downloader", 521, 200, 192, 124)
;$url = GUICtrlCreateInput("", 80, 20, 400, 25)
$Progress1 = GUICtrlCreateProgress(48, 140, 401, 25, BitOR($PBS_SMOOTH,$WS_BORDER), $WS_EX_CLIENTEDGE)
$Button1 = GUICtrlCreateButton("Check Size", 292, 60, 81, 41, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Download", 164, 60, 81, 41, $WS_GROUP)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1
            check()
        case $Button2
            download()
    EndSwitch
WEnd

func check()
    $total = InetGetSize($fdownload)
    _GUICtrlStatusBar_SetText($StatusBar1, $file & " size is : " & Round($total/1048576, 1) & " MB.")
EndFunc

func download()
    $total = InetGetSize($fdownload)
    $download = InetGet($fdownload, @DesktopDir & "\autoit-v3-sfx.exe", 1, 1)
    while 1
        $status = @InetGetBytesRead
        Select
            case @InetGetActive = 1
                $prepercent = $status*100/$total;/1024
                $percent = Int($prepercent)
                GUICtrlSetData($Progress1, $percent)
                _GUICtrlStatusBar_SetText($StatusBar1, "Downloading : " & Round($Status/1048576, 1) & " MB. of " & $file)

            case @InetGetActive = 0
                $Filedisk = FileGetSize(@DesktopDir & "\autoit-v3-sfx.exe")/1048576
                _GUICtrlStatusBar_SetText($StatusBar1, $file & " download completed. " & Round($total/1048576, 1) & " MB downloaded.")
                ExitLoop
            case $status = -1
                _GUICtrlStatusBar_SetText($StatusBar1, "Download Error.")
                ExitLoop
        EndSelect
        sleep(50)
    WEnd
    GUICtrlSetData($Progress1, 0)
    Return
EndFunc

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I use this, maybe you can use it.

$FileCopy = _CopyWithProgress("c:\file.txt", "d:\file.txt")

; Check return code to see if file copied correctly
If $FileCopy = 0 Then
    MsgBox(0,"Copy Complete", "File Copy Successful.")
Else
    MsgBox(16,"Copy Complete", "File Copy Failed.")
EndIf 
Func _CopyWithProgress($inSource, $inDest) 
; Create dll hooks for Progress Update
    If Not IsDeclared("callback") Then Local $callback = DllCallbackRegister('__Progress', 'int', 'uint64;uint64;uint64;uint64;dword;dword;ptr;ptr;str')
    If Not IsDeclared("ptr") Then Local $ptr = DllCallbackGetPtr($callback)
; Check that file open was successful
    If Not FileExists($inSource) Then
        MsgBox(16, "Error", "Unable to open source file: " & $inSource)
        Exit
    EndIf ; Get Destination Directory - without filename
    $DestDir = StringLeft($inDest, StringInStr($inDest, "\", "", -1))
; Check destination directory exists and create it if it doesn't try to create it
    If Not FileExists($DestDir) Then
        $DirCreate = DirCreate($DestDir)
        If $DirCreate = 0 Then MsgBox(16, "Error", "Could not create destination directory: " & $DestDir)
    EndIf ; Show the progress bar
    ProgressOn("File Copy", "Copying...", "Source: " & $inSource & @LF & "Dest:  " & $inDest)   $ret = DllCall('kernel32.dll', 'int', 'CopyFileExA', 'str', $inSource, 'str', $inDest, 'ptr', $ptr, 'str', '', 'int', 0, 'int', 0) ; Hide the progress bar
    ProgressOff()   If $ret[0] <> 0 Then
    ; Success
        Return 0
    Else
    ; Fail
        Return 1
    EndIf EndFunc 
Func __Progress($FileSize, $BytesTransferred, $StreamSize, $StreamBytesTransferred, $dwStreamNumber, $dwCallbackReason, $hSourceFile, $hDestinationFile, $lpData)   ProgressSet(Round($BytesTransferred / $FileSize * 100, 0)) EndFunc
Edited by SnArF

My scripts: _ConsoleWriteLog | _FileArray2D

 

 

 

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