Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Help With Progress Bar


  • Please log in to reply
28 replies to this topic

#1 Eambo

Eambo

    Seeker

  • Active Members
  • 30 posts

Posted 20 January 2011 - 12:49 PM

Hi everyone :-)

I was hoping someone could help me find where I'm going wrong. I'm literally trying to use the code listed on the help page:

Local $hDownload = InetGet("<a href='http://www.autoitscript.com/autoit3/files/beta/update.dat' class='bbc_url' title=''>http://www.autoitscript.com/autoit3/files/beta/update.dat"</a>, @TempDir & "\update.dat", 1, 1) Do     Sleep(250) Until InetGetInfo($hDownload, 2)    ; Check if the download is complete. Local $aData = InetGetInfo($hDownload)  ; Get all information. InetClose($hDownload)   ; Close the handle to release resourcs. MsgBox(0, "", "Bytes read: " & $aData[0] & @CRLF & _     "Size: " & $aData[1] & @CRLF & _     "Complete?: " & $aData[2] & @CRLF & _     "Successful?: " & $aData[3] & @CRLF & _     "@error: " & $aData[4] & @CRLF & _     "@extended: " & $aData[5] & @CRLF)


I was thinking in order to get this to work I would simply need to change the URL - however it doesn't display anything! My downloader downloads, I can watch the file downloading to the directory, however the progress never shows. Has anyone got any suggestions on why this would be?

Thank you once again for your help and support :-)







#2 JLogan3o13

JLogan3o13

    115 and holding

  • MVPs
  • 4,437 posts

Posted 20 January 2011 - 01:18 PM

I'm a bit confused by your title. You seem to be requesting help with a progress bar, but your example is using the inetget function. For inetget, there is no built in progress bar as it downloads. If you open the sample script in the help file, you'll see it downloads the file(s) and then displays the msgbox. For a progress bar you'll need to look under ProgressOn. If this is not your intent, please post some clarification so we can assist further.

If you put a million monkeys on a million keyboards, one of them will eventually write a Java program. The rest of them will write Perl programs.

 

My Scripts: SCCM UDFInclude Source with Compiled Script, Disk Maintenance for Windows XP, "Deal-A-Day" Sites, Windows Firewall UDF


#3 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,640 posts

Posted 20 January 2011 - 01:28 PM

InetGet() doesn't display anything unless you take the data that is secretly created by InetGetInfo($hDownload, 0) << this is the bytes read so far, have a look at GUICtrlCreateProgress() and GUICtrlSetData() in the Help File and have a look in the forum by searching InetGetInfo + ProgressBar.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#4 Eambo

Eambo

    Seeker

  • Active Members
  • 30 posts

Posted 20 January 2011 - 01:40 PM

ah, I think I may be confusing myself then :-)

I thought the above displayed while downloading, for example complete I figured would show no if still downloading.

I was previously toying with this scriptlet:

InetGet($FileURL,$FileName,0,1)   ProgressOn("","") While @InetGetActive     $Percentage = @InetGetBytesRead * 100 / $FileSize     ProgressSet($Percentage,"Downloaded " & @InetGetBytesRead & " of " & $FileSize & " bytes","Downloading " & $FileName)     Sleep(250) Wend ProgressOff()


But I'm assuming some of these functions have since been retired, as I couldn't get this one to work :-(

I may be looking in the wrong place, but I can't find much on ProgressOn, which is exactly what I'm looking for. Does it still exist?

#5 JLogan3o13

JLogan3o13

    115 and holding

  • MVPs
  • 4,437 posts

Posted 20 January 2011 - 02:16 PM

I've always used ProgressOn, ProgressSet and ProgressOff, but Guinness is correct that it can be done other ways as well. Below is something I located in the forums (proper credit to wakillon for this script).

Plain Text         
#include <Math.au3>     $_FinalUrl = 'http://www.birdscanfly.com/images/bcf_wallpaper_1440.jpg' $_TempPath = @TempDir & '\bcf_wallpaper_1440.jpg' $_FileSize = InetGetSize ( $_FinalUrl ) $_Gui = GUICreate ( "" ) $_ProgressBar = GUICtrlCreateProgress ( 5, 25, 350, 23 ) GUISetState ( @SW_SHOW ) $_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 ( $_ProgressBar, $_DownloadPercent )         $_Label = GUICtrlCreateLabel ( 'progress : ' & $_DownloadPercent & ' %', 5, 52, 350, 20 )       EndIf     Sleep ( 100 )     Until $_InfoData[2] = True $_Label = GUICtrlCreateLabel ( 'Download successfull !', 5, 52, 350, 20 )   Sleep ( 2000 )


I think I'm going to start using this for some of my old scripts as well. Hope it helps.

Edited by JLogan3o13, 20 January 2011 - 02:16 PM.

If you put a million monkeys on a million keyboards, one of them will eventually write a Java program. The rest of them will write Perl programs.

 

My Scripts: SCCM UDFInclude Source with Compiled Script, Disk Maintenance for Windows XP, "Deal-A-Day" Sites, Windows Firewall UDF


#6 Eambo

Eambo

    Seeker

  • Active Members
  • 30 posts

Posted 20 January 2011 - 02:49 PM

Thanks JLogan :-)

Out of interest, does ProgressOn/Off still work? It looks like a very simplistic version, pretty much perfect for me. I honestly haven't done too much with GUI and I'm not sure if I want to dive into that just yet - unless of course it's a necessity for a progress indicator.

#7 JLogan3o13

JLogan3o13

    115 and holding

  • MVPs
  • 4,437 posts

Posted 20 January 2011 - 02:55 PM

Yes, I use it often. From the help file:

ProgressOn("Progress Meter", "Increments every second", "0 percent") For $i = 10 to 100 step 10  sleep(1000)  ProgressSet( $i, $i & " percent") Next ProgressSet(100 , "Done", "Complete") sleep(500) ProgressOff()

If you put a million monkeys on a million keyboards, one of them will eventually write a Java program. The rest of them will write Perl programs.

 

My Scripts: SCCM UDFInclude Source with Compiled Script, Disk Maintenance for Windows XP, "Deal-A-Day" Sites, Windows Firewall UDF


#8 Eambo

Eambo

    Seeker

  • Active Members
  • 30 posts

Posted 20 January 2011 - 03:12 PM

I don't suppose you know what's wrong with the code I posted previously? Namely:

InetGet($FileURL,$FileName,0,1)   ProgressOn("","") While @InetGetActive     $Percentage = @InetGetBytesRead * 100 / $FileSize     ProgressSet($Percentage,"Downloaded " & @InetGetBytesRead & " of " & $FileSize & " bytes","Downloading " & $FileName)     Sleep(250) Wend ProgressOff()


When I use this, it acts exactly the same as if I remove everything but the INetGet line. Essentially it downloads, but shows no progress. I also have a msgbox after the INetGet, which doesn't kick in until the download is complete - I'm wondering if this is related? It seems as though it hits INetGet, and does not continue until the download is complete. Could this be because I haven't set the backgrounding properties correctly? I don't fully understand the backgrounding, so I didn't set any parameters for it in my own code.

Thanks for your time!

#9 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,640 posts

Posted 20 January 2011 - 06:50 PM

What Version of AutoIt are you using? Because I have V3.3.6.1 and @InetGetActive is no longer used in this Version, the clues were in JLogan3o13's Version :x

Have a look at this though :P Hope it's what you wanted?!
Function:
AutoIt         
; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _InetGetProgress ; AutoIt Version : v3.3.2.0 or higher ; Language ......: English ; Description ...: Download a file showing a progress bar using ProgressOn. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _InetGetProgress: Download a file showing a progress bar using ProgressOn. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; _ByteSuffix ......; Convert bytes to the largest measure. Thanks to Spliff69 - <a href='http://www.autoitscript.com/forum/topic/116897-folder-sync-tool/page__view__findpost__p__815328' class='bbc_url' title=''>http://www.autoitscript.com/forum/topic/116897-folder-sync-tool/page__view__findpost__p__815328</a> ; =============================================================================================================================== ; #FUNCTION# ========================================================================================================= ; Name...........: _InetGetProgress() ; Description ...: Download a file showing a progress bar using ProgressOn. ; Syntax.........: _InetGetProgress($sURL, [$sDirectory = @ScriptDir]) ;                 $sURL - A valid URL that contains the filename too. ;                 $sDirectory - [Optional] Directory of where to download to @ScriptDir ; Parameters ....: None ; Requirement(s).: v3.3.2.0 or higher ; Return values .: Success - Downloaded filename. ;                  Failure - Returns downloaded filename & sets @error = 1 ; Author ........: guinness ; Example........; Yes ;===================================================================================================================== Func _InetGetProgress($sURL, $sDirectory = @ScriptDir)     Local $hDownload, $iBytesRead = 0, $iFileSize, $iPercentage, $iSpeed = 0, $iTimer = 0, $sFilePath, $sProgressText, $sSpeed     $sFilePath = StringRegExpReplace($sURL, "^.*/", "")     If @error Then         Return SetError(1, 0, $sFilePath)     EndIf     $sDirectory = StringRegExpReplace($sDirectory, "[\\/]+\z", "") & "\" & $sFilePath     $iFileSize = InetGetSize($sURL, 1)     $hDownload = InetGet($sURL, $sDirectory, 0, 1)     If @error Then         Return SetError(1, 0, $sFilePath)     EndIf     ProgressOn("", "")     $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s"     $iTimer = TimerInit()     While InetGetInfo($hDownload, 2) = 0         $iBytesRead = InetGetInfo($hDownload, 0)         $iPercentage = $iBytesRead * 100 / $iFileSize         $sProgressText = "Downloading " & _ByteSuffix($iBytesRead, 0) & " Of " & _ByteSuffix($iFileSize, 0) & @LF & $sSpeed         ProgressSet(Round($iPercentage, 0), $sProgressText, "Downloading: " & $sFilePath)         If TimerDiff($iTimer) > 1000 Then             $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s"             $iSpeed = $iBytesRead             $iTimer = TimerInit()         EndIf         Sleep(100)     WEnd     InetClose($hDownload)     ProgressOff()     Return $sFilePath EndFunc   ;==>_InetGetProgress ; #INTERNAL_USE_ONLY#============================================================================================================ Func _ByteSuffix($iBytes, $iRound = 2)     Local $A, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"]     While $iBytes > 1023         $A += 1         $iBytes /= 1024     WEnd     Return Round($iBytes, $iRound) & $aArray[$A] EndFunc   ;==>_ByteSuffix ; #INTERNAL_USE_ONLY#============================================================================================================

Example use of Function:
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 Global $sFilePath, $sFileURL $sFileURL = "<a href='http://ftp.opera.com/pub/opera/win/1152/en/Opera_1152_en_Setup.exe' class='bbc_url' title='External link' rel='nofollow external'>http://ftp.opera.com/pub/opera/win/1152/en/Opera_1152_en_Setup.exe"</a> $sFilePath = _InetGetProgress($sFileURL, @TempDir & "\") If @error Then     MsgBox(64, "Error", "Check the URL or your Internet Connection!") Else     MsgBox(64, "Success", "Downloaded >> " & $sFilePath) EndIf

Edited by guinness, 27 October 2011 - 07:51 PM.

  • Loz likes this

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#10 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,640 posts

Posted 20 January 2011 - 07:12 PM

And an Example using a GUI. It's slightly different to >> _InetGetProgress() Also this is an example which of course can be improved upon! I hope it gives you inspiration to look into creating GUI's :x

Function:
AutoIt         
; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _InetGetGUI ; AutoIt Version : v3.3.2.0 or higher ; Language ......: English ; Description ...: Download a file updating a GUICtrlCreateProgress. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _InetGetGUI: Download a file updating a GUICtrlCreateProgress. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; _ByteSuffix ......; Convert bytes to the largest measure. Thanks to Spliff69 - http://www.autoitscript.com/forum/topic/...ync-tool/page__view__findpost_ ; =============================================================================================================================== ; #FUNCTION# ========================================================================================================= ; Name...........: _InetGetGUI() ; Description ...: Download a file updating a GUICtrlCreateProgress(). ; Syntax.........: _InetGetGUI($sURL, $iLabel, $iProgress, $iButton, [$sDirectory = @ScriptDir]) ;                 $sURL - A valid URL that contains the filename too. ;                 $iLabel - ControlID of a GUICtrlCreateLabel. ;                 $iProgress - ControlID of a GUICtrlCreateProgress. ;                 $iButton - ControlID of a GUICtrlCreateButton. ;                 $sDirectory - [Optional] Directory of where to download to. Default = @ScriptDir ; Parameters ....: None ; Requirement(s).: v3.3.2.0 or higher ; Return values .: Success - Downloaded filename. ;                  Failure - Returns downloaded filename & sets @error = 1 (@extended = 0 if internal error or @extended = 1 if cancelled was selected.) ; Author ........: guinness ; Example........; Yes ;===================================================================================================================== Func _InetGetGUI($sURL, $iLabel, $iProgress, $iButton, $sDirectory = @ScriptDir)     Local $hDownload, $iBytesRead = 0, $iError = 0, $iFileSize, $iPercentage, $iSpeed = 0, $iTimer = 0, $sFilePath, $sProgressText, $sRead = GUICtrlRead($iButton), $sSpeed     $sFilePath = StringRegExpReplace($sURL, "^.*/", "")     If @error Then         Return SetError(1, 0, $sFilePath)     EndIf     $sDirectory = StringRegExpReplace($sDirectory, "[\\/]+\z", "") & "\" & $sFilePath     $iFileSize = InetGetSize($sURL, 1)     $hDownload = InetGet($sURL, $sDirectory, 0, 1)     If @error Then         Return SetError(1, $iError, $sFilePath)     EndIf     GUICtrlSetData($iButton, "&Cancel")     $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s"     $iTimer = TimerInit()     While InetGetInfo($hDownload, 2) = 0         Switch GUIGetMsg()             Case $GUI_EVENT_CLOSE, $iButton                 GUICtrlSetData($iLabel, "Download Cancelled!")                 $iError = 1                 ExitLoop         EndSwitch         $iBytesRead = InetGetInfo($hDownload, 0)         $iPercentage = $iBytesRead * 100 / $iFileSize         $sProgressText = "Downloading " & _ByteSuffix($iBytesRead, 0) & " Of " & _ByteSuffix($iFileSize, 0) & @LF & $sSpeed         GUICtrlSetData($iLabel, $sProgressText)         GUICtrlSetData($iProgress, $iPercentage)         If TimerDiff($iTimer) > 1000 Then             $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s"             $iSpeed = $iBytesRead             $iTimer = TimerInit()         EndIf         Sleep(100)     WEnd     InetClose($hDownload)     GUICtrlSetData($iButton, $sRead)     Return SetError($iError, $iError, $sFilePath) EndFunc   ;==>_InetGetGUI ; #INTERNAL_USE_ONLY#============================================================================================================ Func _ByteSuffix($iBytes, $iRound = 2)     Local $A, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"]     While $iBytes > 1023         $A += 1         $iBytes /= 1024     WEnd     Return Round($iBytes, $iRound) & $aArray[$A] EndFunc   ;==>_ByteSuffix ; #INTERNAL_USE_ONLY#============================================================================================================

Example use of Function:
AutoIt         
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> _Main() Func _Main()     Local $sFilePathURL = "http://ftp.opera.com/pub/opera/win/1152/en/Opera_1152_en_Setup.exe"     Local $hGUI, $iButton, $iLabel, $iProgressBar, $sFilePath     $hGUI = GUICreate("_InetGetGUI()", 370, 90, -1, -1)     $iLabel = GUICtrlCreateLabel("Welcome to the simple Downloader!", 5, 5, 270, 40)     $iButton = GUICtrlCreateButton("&Download", 275, 2.5, 90, 25)     $iProgressBar = GUICtrlCreateProgress(5, 60, 360, 20)     GUISetState(@SW_SHOW, $hGUI)     While 1         Switch GUIGetMsg()             Case $GUI_EVENT_CLOSE                 Exit             Case $iButton                 $sFilePath = _InetGetGUI($sFilePathURL, $iLabel, $iProgressBar, $iButton, @ScriptDir)                 If @error Then                     Switch @extended ; Check what the actual error was by using the @extended command.                         Case 0                             MsgBox(64, "Error", "Check the URL or your Internet Connection!")                         Case 1                             MsgBox(64, "Fail", "Seems the download was canecelled, but the file was >> " & $sFilePath)                     EndSwitch                 Else                     MsgBox(64, "Success", "Downloaded >> " & $sFilePath)                 EndIf         EndSwitch     WEnd EndFunc   ;==>_Main

Edited by guinness, 27 October 2011 - 07:52 PM.

  • MrVietA2 likes this

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#11 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,640 posts

Posted 21 January 2011 - 12:21 PM

Just a couple of tweaks to the above examples, I haven't added too much because obviously you can change how you wish the Functions etc to work.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#12 FaridAgl

FaridAgl

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 726 posts

Posted 07 September 2011 - 07:08 PM

It's my code that i used some times ago to download a file with progress bar, also you can see that it check a file on the internet for updates using iniread. i hope can help.

Plain Text         
#NoTrayIcon #include <Constants.au3> Dim $Download Dim $FileName ;~ -------------------------------------------------- ;~ Get Download Info $GetInfo = InetGet("<a href='http://garena.godlike-exp.ir/info.dat' class='bbc_url' title='External link' rel='nofollow external'>http://garena.godlike-exp.ir/info.dat"</a>, @TempDir & "\info.dat", 1, 1) Do Until InetGetInfo($GetInfo, 2) InetClose($GetInfo) $Version = IniRead(@TempDir & "\info.dat", "GoDLiKe.eXp", "Version", "Can't read file.") $URL = IniRead(@TempDir & "\info.dat", "GoDLiKe.eXp", "URL", "Can't read file.") $FileSize = IniRead(@TempDir & "\info.dat", "GoDLiKe.eXp", "File Size", "Can't read file.") $ReleaseData = IniRead(@TempDir & "\info.dat", "GoDLiKe.eXp", "Release Data", "Can't read file.") $FileName = IniRead(@TempDir & "\info.dat", "GoDLiKe.eXp", "File Name", "Can't read file.") FileDelete(@TempDir & "\info.dat") If $Version = 5.3 OR $Version > 5.3 Then     Exit EndIf ;~ -------------------------------------------------- ;~ Ask User for Download $Info = "Latest Version: " & $Version & @LF & "Release Date: " & $ReleaseData & @LF & "File Size: " & $FileSize & " KB" & @LF & @LF & "Do you want to download now?" $What = MsgBox(4, "GoDLiKe.eXp Auto Updater", $Info) If $What = 7 Then     Exit EndIf ;~ -------------------------------------------------- ;~ Show Progress ProgressOn("GoDLiKe.eXp Updater", "", "Please Wait...", -1, -1, "16") ;~ Start Download $Download = InetGet($URL, $FileName, 1, 1) ;~ Downloding & Progress Bar Do     $Downloaded_B = InetGetInfo($Download, 0)     $Downloaded_KB = Round($Downloaded_B / 1024)     $Percent = Round($Downloaded_KB / $FileSize * 100)     $Status = $Downloaded_KB & " KB of " & $FileSize & " KB" & @LF & $Percent & "%" & " Downloaded."     ProgressSet($Percent, $Status, "Press Ctrl + Alt + Q to Exit.")     Sleep(100) Until InetGetInfo($Download, 2) InetClose($Download) ProgressOff() ;Download Completed. ;~ -------------------------------------------------- ;~ Show MsgBox $FinishMsg = MsgBox(36, "GoDLiKe.eXp", "Download Completed." & @LF & "Do you to install GoDLiKe.eXp " & $Version & " now?") If $FinishMsg = 6 Then     ShellExecute($FileName)     Exit EndIf

I felt in love with AutoItObject [and the new Map type!].


#13 hackersarchangel

hackersarchangel

    Seeker

  • Active Members
  • 21 posts

Posted 10 December 2011 - 09:00 PM

@guinness, I have a question.

I've been working on a program and this works wonderfully, just one thing I gotta ask: how can I have it change the name of the file it downloads to something more standard? like say the file it downloads is "testfile121011.exe" and I want it to be just "testfile.exe". I know I could pass a FileCopy() and have it change it afterwards and delete the original but I'd rather just have it do it like the code can without a progressbar. Since I'm not sure how to pass that to your function, any help would be awesome :D

#14 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,640 posts

Posted 10 December 2011 - 09:12 PM

Look at the $sFilePath parameter, I just added it to the _InetGetGUI UDF.

AutoIt         
; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _InetGetGUI ; AutoIt Version : v3.3.2.0 or higher ; Language ......: English ; Description ...: Download a file updating a GUICtrlCreateProgress. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _InetGetGUI: Download a file updating a GUICtrlCreateProgress. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; _ByteSuffix ......; Convert bytes to the largest measure. Thanks to Spliff69 - <a href='http://www.autoitscript.com/forum/topic/...ync-tool/page__view__findpost_' class='bbc_url' title=''>http://www.autoitscript.com/forum/topic/...ync-tool/page__view__findpost_</a> ; =============================================================================================================================== ; #FUNCTION# ========================================================================================================= ; Name...........: _InetGetGUI() ; Description ...: Download a file updating a GUICtrlCreateProgress(). ; Syntax.........: _InetGetGUI($sURL, $iLabel, $iProgress, $iButton, [$sDirectory = @ScriptDir, [$sFilePath = -1]]) ; $sURL - A valid URL that contains the filename too. ; $iLabel - ControlID of a GUICtrlCreateLabel. ; $iProgress - ControlID of a GUICtrlCreateProgress. ; $iButton - ControlID of a GUICtrlCreateButton. ; $sDirectory - [Optional] Directory of where to download to. Default = @ScriptDir ; $sFilePath - [Optional] FilePath to be used. Default = FileName of the original download. ; Parameters ....: None ; Requirement(s).: v3.3.2.0 or higher ; Return values .: Success - Downloaded filename. ; Failure - Returns downloaded filename & sets @error = 1 (@extended = 0 if internal error or @extended = 1 if cancelled was selected.) ; Author ........: guinness ; Example........; Yes ;===================================================================================================================== Func _InetGetGUI($sURL, $iLabel, $iProgress, $iButton, $sDirectory = @ScriptDir, $sFilePath = -1)     Local $hDownload, $iBytesRead = 0, $iError = 0, $iFileSize, $iPercentage, $iSpeed = 0, $iTimer = 0, $sProgressText, $sRead = GUICtrlRead($iButton), $sSpeed     If $sFilePath = -1 Then         $sFilePath = StringRegExpReplace($sURL, "^.*/", "")         If @error Then             Return SetError(1, 0, $sFilePath)         EndIf     EndIf     $sDirectory = StringRegExpReplace($sDirectory, "[/]+z", "") & "" & $sFilePath     $iFileSize = InetGetSize($sURL, 1)     $hDownload = InetGet($sURL, $sDirectory, 0, 1)     If @error Then         Return SetError(1, $iError, $sFilePath)     EndIf     GUICtrlSetData($iButton, "&Cancel")     $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s"     $iTimer = TimerInit()     While InetGetInfo($hDownload, 2) = 0         Switch GUIGetMsg()             Case $GUI_EVENT_CLOSE, $iButton                 GUICtrlSetData($iLabel, "Download Cancelled!")                 $iError = 1                 ExitLoop         EndSwitch         $iBytesRead = InetGetInfo($hDownload, 0)         $iPercentage = $iBytesRead * 100 / $iFileSize         $sProgressText = "Downloading " & _ByteSuffix($iBytesRead, 0) & " Of " & _ByteSuffix($iFileSize, 0) & @LF & $sSpeed         GUICtrlSetData($iLabel, $sProgressText)         GUICtrlSetData($iProgress, $iPercentage)         If TimerDiff($iTimer) > 1000 Then             $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s"             $iSpeed = $iBytesRead             $iTimer = TimerInit()         EndIf         Sleep(100)     WEnd     InetClose($hDownload)     GUICtrlSetData($iButton, $sRead)     Return SetError($iError, $iError, $sFilePath) EndFunc   ;==>_InetGetGUI ; #INTERNAL_USE_ONLY#============================================================================================================ Func _ByteSuffix($iBytes, $iRound = 2)     Local $A, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"]     While $iBytes > 1023         $A += 1         $iBytes /= 1024     WEnd     Return Round($iBytes, $iRound) & $aArray[$A] EndFunc   ;==>_ByteSuffix ; #INTERNAL_USE_ONLY#============================================================================================================

Edited by guinness, 10 December 2011 - 11:01 PM.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#15 hackersarchangel

hackersarchangel

    Seeker

  • Active Members
  • 21 posts

Posted 10 December 2011 - 10:40 PM

That actually gave me a bunch of errors, and not only that, I found a temporary method that will work in the non GUI version:

AutoIt         
;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _InetGetProgress ; AutoIt Version : v3.3.2.0 or higher ; Language ......: English ; Description ...: Download a file showing a progress bar using ProgressOn. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _InetGetProgress: Download a file showing a progress bar using ProgressOn. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; _ByteSuffix ......; Convert bytes to the largest measure. Thanks to Spliff69 - <a href='http://www.autoitscript.com/forum/topic/...ync-tool/page__view__findpost_' class='bbc_url' title=''>http://www.autoitscript.com/forum/topic/...ync-tool/page__view__findpost_</a> ; =============================================================================================================================== ; #FUNCTION# ========================================================================================================= ; Name...........: _InetGetProgress() ; Description ...: Download a file showing a progress bar using ProgressOn. ; Syntax.........: _InetGetProgress($sURL, [$sDirectory = @ScriptDir]) ;                $sURL - A valid URL that contains the filename too. ;                $sDirectory - [Optional] Directory of where to download to @ScriptDir ; Parameters ....: None ; Requirement(s).: v3.3.2.0 or higher ; Return values .: Success - Downloaded filename. ;                 Failure - Returns downloaded filename & sets @error = 1 ; Author ........: guinness ; Example........; Yes ;===================================================================================================================== Func _InetGetProgress($sURL, $sDirectory = @ScriptDir)     Local $hDownload, $iBytesRead = 0, $iFileSize, $iPercentage, $iSpeed = 0, $iTimer = 0, $sFilePath, $sProgressText, $sSpeed     $sFilePath = StringRegExpReplace($sURL, "^.*/", "")     If @error Then         Return SetError(1, 0, $sFilePath)     EndIf $sFilePath = InputBox("Need filename please.","Please enter the filename desired.","")     $sDirectory = StringRegExpReplace($sDirectory, "[\\/]+\z", "") & "\" & $sFilePath     $iFileSize = InetGetSize($sURL, 1)     $hDownload = InetGet($sURL, $sDirectory, 0, 1)     If @error Then         Return SetError(1, 0, $sFilePath)     EndIf     ProgressOn("", "")     $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s"     $iTimer = TimerInit()     While InetGetInfo($hDownload, 2) = 0         $iBytesRead = InetGetInfo($hDownload, 0)         $iPercentage = $iBytesRead * 100 / $iFileSize         $sProgressText = "Downloading " & _ByteSuffix($iBytesRead, 0) & " Of " & _ByteSuffix($iFileSize, 0) & @LF & $sSpeed         ProgressSet(Round($iPercentage, 0), $sProgressText, "Downloading: " & $sFilePath)         If TimerDiff($iTimer) > 1000 Then             $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s"             $iSpeed = $iBytesRead             $iTimer = TimerInit()         EndIf         Sleep(100)     WEnd     InetClose($hDownload)     ProgressOff()     Return $sFilePath EndFunc   ;==>_InetGetProgress ; #INTERNAL_USE_ONLY#============================================================================================================ Func _ByteSuffix($iBytes, $iRound = 2)     Local $A, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"]     While $iBytes > 1023         $A += 1         $iBytes /= 1024     WEnd     Return Round($iBytes, $iRound) & $aArray[$A] EndFunc   ;==>_ByteSuffix ; #INTERNAL_USE_ONLY#============================================================================================================



I took $sFilePath and I presently have it ask me for the name I wish to give the file. Still trying to mesh out the having it auto assigned without remaking the function for every download. I do appreciate the work you've done :D

#16 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,640 posts

Posted 10 December 2011 - 10:47 PM

Updated the UDF in the last post. You didn't really mention which UDF you were using so I presumed by what you wrote that you meant the GUI version & secondly when you say errors it's a little hard to know what exactly.

It appears you have knowledge of AutoIt so it shouldn't be hard for you to modify the UDF to suit your needs.

Edit: Just saw the InputBox, not something I would do in a Function per say.

Here's how I would do it for the ProgressOn version.
AutoIt         
; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _InetGetProgress ; AutoIt Version : v3.3.2.0 or higher ; Language ......: English ; Description ...: Download a file showing a progress bar using ProgressOn. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _InetGetProgress: Download a file showing a progress bar using ProgressOn. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; _ByteSuffix ......; Convert bytes to the largest measure. Thanks to Spliff69 - <a href='http://www.autoitscript.com/forum/topic/...ync-tool/page__view__findpost_' class='bbc_url' title=''>http://www.autoitscript.com/forum/topic/...ync-tool/page__view__findpost_</a> ; =============================================================================================================================== ; #FUNCTION# ========================================================================================================= ; Name...........: _InetGetProgress() ; Description ...: Download a file showing a progress bar using ProgressOn. ; Syntax.........: _InetGetProgress($sURL, [$sDirectory = @ScriptDir, [$sFilePath = -1]]) ;                 $sURL - A valid URL that contains the filename too. ;                 $sDirectory - [Optional] Directory of where to download to @ScriptDir ;                 $sFilePath - [Optional] FilePath to be used. Default = FileName of the original download. ; Parameters ....: None ; Requirement(s).: v3.3.2.0 or higher ; Return values .: Success - Downloaded filename. ;                  Failure - Returns downloaded filename & sets @error = 1 ; Author ........: guinness ; Example........; Yes ;===================================================================================================================== Func _InetGetProgress($sURL, $sDirectory = @ScriptDir, $sFilePath = -1)     Local $hDownload, $iBytesRead = 0, $iFileSize, $iPercentage, $iSpeed = 0, $iTimer = 0, $sProgressText, $sSpeed     If $sFilePath = -1 Then         $sFilePath = StringRegExpReplace($sURL, "^.*/", "")         If @error Then             Return SetError(1, 0, $sFilePath)         EndIf     EndIf     $sDirectory = StringRegExpReplace($sDirectory, "[/]+z", "") & "" & $sFilePath     $iFileSize = InetGetSize($sURL, 1)     $hDownload = InetGet($sURL, $sDirectory, 0, 1)     If @error Then         Return SetError(1, 0, $sFilePath)     EndIf     ProgressOn("", "")     $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s"     $iTimer = TimerInit()     While InetGetInfo($hDownload, 2) = 0         $iBytesRead = InetGetInfo($hDownload, 0)         $iPercentage = $iBytesRead * 100 / $iFileSize         $sProgressText = "Downloading " & _ByteSuffix($iBytesRead, 0) & " Of " & _ByteSuffix($iFileSize, 0) & @LF & $sSpeed         ProgressSet(Round($iPercentage, 0), $sProgressText, "Downloading: " & $sFilePath)         If TimerDiff($iTimer) > 1000 Then             $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s"             $iSpeed = $iBytesRead             $iTimer = TimerInit()         EndIf         Sleep(100)     WEnd     InetClose($hDownload)     ProgressOff()     Return $sFilePath EndFunc   ;==>_InetGetProgress ; #INTERNAL_USE_ONLY#============================================================================================================ Func _ByteSuffix($iBytes, $iRound = 2)     Local $A, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"]     While $iBytes > 1023         $A += 1         $iBytes /= 1024     WEnd     Return Round($iBytes, $iRound) & $aArray[$A] EndFunc   ;==>_ByteSuffix ; #INTERNAL_USE_ONLY#============================================================================================================

Edited by guinness, 10 December 2011 - 11:01 PM.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#17 hackersarchangel

hackersarchangel

    Seeker

  • Active Members
  • 21 posts

Posted 10 December 2011 - 11:01 PM

Oops sorry lol. A little out of practice when it comes to helping debugging.

It complained in the GUI version you updated that it was missing a WEnd and when added it then said missing EndSwitch. After figuring it out it starts the GUI but fails to download.

Edit: Yeah I was using that to help figure out where in the code did it need to grab the final name of the file. Was working on a way to pass that from the main branch of code into the function.

Edited by hackersarchangel, 10 December 2011 - 11:04 PM.


#18 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,640 posts

Posted 10 December 2011 - 11:05 PM

I just tried the _InetGetGUI I gave you with the example of downloading Opera and it works perfectly. I'm using the latest beta of AutoIt and Windows 7 x64. What are you using?

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#19 hackersarchangel

hackersarchangel

    Seeker

  • Active Members
  • 21 posts

Posted 10 December 2011 - 11:09 PM

Not the beta lol using the newest non Beta. Windows 7 x64. And after adding the requested bits from the compiler, and just tweaking the box text, I tried it and it just sat there. Should I be running the beta??

ROFL I just noticed a minor error on my part. One second.

Edited by hackersarchangel, 10 December 2011 - 11:11 PM.


#20 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,640 posts

Posted 10 December 2011 - 11:15 PM

By 'non beta' I take it you mean V3.3.6.1? As you can see from #post16 I updated the UDF _InetGetProgress to allow you to pass the filname e.g.
_InetGetProgress("<a href='http://example.com/randomfile1234.txt' class='bbc_url' title='External link' rel='nofollow external'>http://example.com/randomfile1234.txt"</a>, @ScriptDir, "RandomFile.txt")

Edited by guinness, 10 December 2011 - 11:35 PM.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users