Sign in to follow this  
Followers 0
AcidCorps

Auto Download UDF

13 posts in this topic

#1 ·  Posted (edited)

This is a little Download function I made for myself, it has a lot to it but the only variable that is not optional is the $sDownload everything else it automatically detected

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.5.0 (beta)
 Author:         Acid Corps
 Title:          Auto Download

 Script Function:
    Simplifies Downloading
    
    $sDownload = Link to file to download
                     Format http://www.example.com/file.exe
                     
    $sFilename = Name to save download file as (optional)
                     Default: Original name from download link
                     
    $sSize     = Size of file to download (optional)
                     Format: 100 or 100 KB or 100 MB or 100 GB
                     If not stated attempts to use InetGetSize (does not always work)
                     
    $sFolder   = Folder to save file to (optional)
                     Default: Script Directory
                     Format: C:\My Folder
                     
    $sProxy    = Proxy to connect to the net (optional)
                     Default: No Proxy
                     Format: Proxy:Port
                     1 = Default Proxy
                     
    $sName     = Username for download (optional)
                     For use with ftp and some http downloads
                     
    $sPass     = Password for download (optional)
                     For use with ftp and some http downloads
                     
    $sProgress = Progress bar on or off (optional)
                     Default: On
                     
    If you do not wish to use ,"", to omit variables then use ,0, and default will be used
    
    Usage: _Download($sDownload, $sFilename, $sSize, $sFolder, $sProxy, $sName, $sPass, $sProgress)

#ce ----------------------------------------------------------------------------

Func _Download($sDownload, $sFilename=0, $sSize=0, $sFolder=0, $sProxy=0, $sName=0, $sPass=0, $sProgress=0)
Opt("ExpandEnvStrings", 1)

;   Setting Proxy
    If $sProxy = 1 Then 
        HttpSetProxy(0)
        FtpSetProxy(0)
    EndIf
    
    If $sProxy <> 0 And $sProxy <> 1 And $sName <> 0 And $sPass <> 0 Then 
        HttpSetProxy(2, $sProxy, $sName, $sPass)
        FtpSetProxy(2, $sProxy, $sName, $sPass)
    EndIf
    
;  Setting Size
    If $sSize = 0 Then
        $ssSize = InetGetSize($sDownload)
    Else
        $ssSize = $sSize
    EndIf
    
    If StringRight($sSize, 2) = "kb" Then $sSizeTimes = 1024
    If StringRight($sSize, 2) = "mb" Then $sSizeTimes = 1048576
    If StringRight($sSize, 2) = "gb" Then $sSizeTimes = 1073741824
    
;   Finding Filename
    If $sFilename = 0 Then
        $ssFilename = StringTrimLeft($sDownload,StringInStr($sDownload,"/",1,-1))
    Else
        $ssFileName = $sFileName
    EndIf
    
;   Progress/Download
    If $sProgress = 0 then
         Dim $ssSize = InetGetSize($sDownload)
         INetGet($sDownload,$ssFilename)
         ProgressOn("Downloading...", "Retrieving new version.")
                 While @InetGetActive
                 Dim $p = (100 * @InetGetBytesRead) / $ssSize
                 ProgressSet($p, @InetGetBytesRead & "/" & $ssSize & " bytes", "Download in progress.")
             Sleep(250)
         ProgressOff()
     WEnd
     Else
         InetGet($sDownload, $ssFilename)

     EndIf
EndFunc

Edit: Updated script with mrRevoked's method of finding the filename

_Download.au3

Edited by AcidCorps

Share this post


Link to post
Share on other sites



Nice.. But still inetget :whistle:


-jaenster

Share this post


Link to post
Share on other sites

If StringRight($sSize, 2) = "kb" Then $sSizeTimes = 1024

If StringRight($sSize, 2) = "mb" Then $sSizeTimes = 1048576

If StringRight($sSize, 2) = "gb" Then $sSizeTimes = 1073741824

What does this do? And why?

Finding Filename

If $sFilename = 0 Then

$sFNArray = StringSplit($sDownload, "/")

$sFNArrayAmount = $sFNArray[0]

$ssFileName = $sFNArray[$sFNArrayAmount]

This is a shorter method:

StringTrimLeft($sDownload,StringInStr($sDownload,"/",1,-1))

greetings

Pascal

Share this post


Link to post
Share on other sites

What does this do? And why?

This is a shorter method:

StringTrimLeft($sDownload,StringInStr($sDownload,"/",1,-1))

greetings

Pascal

what if the file ends with "/" ?

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

What does this do? And why?

It lets you use kb, mb, and gb, abbreviations in the $sSize

This is a shorter method:

StringTrimLeft($sDownload,StringInStr($sDownload,"/",1,-1))

Updated

Edited by AcidCorps

Share this post


Link to post
Share on other sites

no progress bar no window is showed i use it like this

$LINK="http://download.lavasoft.com/public/core.zip"

_Download($LINK)

Share this post


Link to post
Share on other sites

can u set it up so i will dwonload autoit... (lates version)

all optinal stuff... cus i cant get it to work

Share this post


Link to post
Share on other sites

does anybody know where I went wrong with this code, I'm having some trouble trying to fix it

Share this post


Link to post
Share on other sites

Thats the only one I have, the only update is in a post above:

StringTrimLeft($sDownload,StringInStr($sDownload,"/",1,-1)

so I'm thinking it was buggy from the beginning and nobody noticed it till now.

Share this post


Link to post
Share on other sites

Thats the only one I have, the only update is in a post above:

StringTrimLeft($sDownload,StringInStr($sDownload,"/",1,-1)

so I'm thinking it was buggy from the beginning and nobody noticed it till now.

ok mae an excaple that downlaod autoit.exe... with all potinal stuff please

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

_Download("http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3.2.4.9-setup.exe","Autoit.exe","4.24 MB", @ScriptDir, 0, "AcidCorps", "AcidPass", 0)oÝ÷ Ùj.ÖÞÂ+ajYb­°z0z÷«².Ö¶Ø^±©jÆ®¶­seôF÷væÆöBgV÷C¶GG¢ò÷wwræWFöG67&6öÒö6vÖ&âövWFfÆRçÃöWFöC2öWFöB×c2ã"ãBã×6WGWæWRgV÷C²

Edit:missed closing autoit tag

Edited by AcidCorps

Share this post


Link to post
Share on other sites

_Download("http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3.2.4.9-setup.exe","Autoit.exe","4.24 MB", @ScriptDir, 0, "AcidCorps", "AcidPass", 0)

Would be with all inputs

However should act the same as 

[code]_Download("http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3.2.4.9-setup.exe")

ok no progress bar..

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