#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>

DirCreate(@ScriptDir & "\Downloads")
AdlibRegister ( "_Progress" , 500 )
AdlibRegister ( "_time" , 500 )


$download=InetGet("http://download.mozilla.org/?product=firefox-6.0.2&os=win&lang=de",@ScriptDir & "\Downloads\test_firefox.de",1,1) ;der download
$gui=GUICreate("Test",1020,80)
$progressbar=GUICtrlCreateProgress(10,30,1000,20)

$kb_and_procent_label = GuiCtrlCreateLabel("0 kb von 0 kb; 0 % von 100 %" ,10 ,60 ,1000 ,20)
$time_label=GUICtrlCreateLabel("Verbleibende Zeit: ---Wird Berechnet--- ;Geschwindigkeit: ---Wird Berechnet---" ,10 ,10 ,1000 ,20)
$timer = 0
$timer_start = False
$time = 0

GUISetState() ;Gui Erstellung



While 1


	$msg=GUIGetMsg()

	If $msg = $GUI_EVENT_CLOSE Then Exit




WEnd


Func _time()

	If InetGetInfo($download, 2) = False Then

		If InetGetInfo($download,0) > 0 And $timer_start = False Then
			$timer = TimerInit()
			$timer_start = True
		EndIf

		$time_calc = int((int(InetGetInfo($download,1)/1024)-(InetGetInfo($download,0)/1024)) _
			/int((InetGetInfo($download,0) / 1024) / (TimerDiff($timer) / 1000)))

		$Geschwindigkeit_calc = int(InetGetInfo($download,0) / (TimerDiff($timer) / 1000))



		If $time_calc <= 60 Then

			If $time_calc = 1 Then
				$time = " 1 Sekunde"
			Else
				$time = $time_calc & " Sekunden"
			EndIf

		EndIf


		If $time_calc > 60 Then

			If int($time_calc/60) = 1 Then
				$time = " 1 Minute"
			Else
				$time = int($time_calc/60) & " Minuten"
			EndIf

		EndIf

		If $time_calc/60 > 60 Then

			If int(($time_calc/60)/60) = 1 Then
				$time = " 1 Tag"
			Else
				$time = int(($time_calc/60)/60) & " Tage"
			EndIf

		EndIf



		If int($Geschwindigkeit_calc) <= 1024 Then

				$Geschwindigkeit = int($Geschwindigkeit_calc) & " Byte/Sekunde"

		EndIf

		If int($Geschwindigkeit_calc) > 1024 Then

				$Geschwindigkeit = int($Geschwindigkeit_calc/1024) & " Kilobyte/Sekunde"

		EndIf

		If int($Geschwindigkeit_calc/1024) > 1024 Then

				$Geschwindigkeit = int(($Geschwindigkeit_calc/1024)/1024) & " Megabyte/Sekunde"

		EndIf

		If int(($Geschwindigkeit_calc/1024)/1024) > 1024 Then

				$Geschwindigkeit = int((($Geschwindigkeit_calc/1024)/1024)/1024) & " Gigabyte/Sekunde"

		EndIf

		GUICtrlSetData($time_label, "Verbleibende Zeit: " &	$time & "; Geschwindigkeit: " & $Geschwindigkeit)

	Else
			GUICtrlSetData($time_label, "Verbleibende Zeit: 0 Sekunden ;Geschwindigkeit: 0 Kilobytes/Sekunde")
			Exit
	EndIf

EndFunc

Func _Progress()

	GUICtrlSetData($progressbar, int((InetGetInfo($download,0)/InetGetInfo($download,1))*100)) ;aktualiesierung des Progresses
	GUICtrlSetData($kb_and_procent_label ,int(InetGetInfo($download,0)/1024) & " kb von " & int( _
	InetGetInfo($download,1)/1024)&" kb; "&int((InetGetInfo($download,0)/InetGetInfo($download,1))*100)&" % von 100 %") ;aktualiesierung des $$kb_and_procent_labels

EndFunc