Jump to content

FileHippo Download and retrieve version V2.13


storme
 Share

Recommended Posts

G'day all

This has come in useful in a few projects now so I thought I'd release it and maybe it'll be useful for others.

The usage is straight froward and all in the header so I haven't included a test file. If you need help let me know.

I've had help writing this but can't remember who. If you've helped me on this let me know (IM) and I'll add your name.

If you have any advice or improvements please let me know.

Example

ProgressOn("FileHippo Download", "Downloading : malwarebytes_anti_malware")
$test = _FileHippoDownload("malwarebytes_anti_malware", @ScriptDir & "\downloads\", "", True, True, "_UpdateProgress")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $test = ' & $test & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ProgressOff()
_ArrayDisplay($test)
Exit
#include <Misc.au3>
Func _UpdateProgress($Percentage)
    ProgressSet($Percentage, $Percentage & "%")
    If _IsPressed("77") Then Return False ; Abort on F8
    Return True ; bei 1 Fortsetzten
EndFunc   ;==>_UpdateProgress

#cs
ConsoleWrite("Start: malwarebytes_anti_malware")
$MWB_down = _FileHippoDownload("malwarebytes_anti_malware", @ScriptDir & "\file_includes", "install_malware.exe", True)
If @error Then
MsgBox(0, "Error", @error)
EndIf
ConsoleWrite("End: malwarebytes_anti_malware")
ConsoleWrite("Start: avg_antivirus_32")
$AVG32_down = _FileHippoDownload("avg_antivirus_32", @ScriptDir & "\file_includes", "install_avg_32.exe", True)
If @error Then
MsgBox(0, "Error", @error)
EndIf
ConsoleWrite("End: avg_antivirus_32")
ConsoleWrite("Start: avg_antivirus_64")
$AVG64_down = _FileHippoDownload("avg_antivirus_64", @ScriptDir & "\file_includes", "install_avg_64.exe", True)
If @error Then
MsgBox(0, "Error", @error)
EndIf
ConsoleWrite("End: avg_antivirus_64")
;#AutoIt3Wrapper_Run_Debug_Mode=y
ProgressOn("FileHippo Download", "Downloading : Firefox")
$test = _FileHippoDownload("firefox", @ScriptDir & "\downloads\", "", True, False, "_UpdateProgress")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $test = ' & $test & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ProgressOff()
_ArrayDisplay($test)
Exit
#include <Misc.au3>
Func _UpdateProgress($Percentage)
ProgressSet($Percentage, $Percentage & "%")
If _IsPressed("77") Then Return False ; Abort on F8
Return True ; bei 1 Fortsetzten
EndFunc   ;==>_UpdateProgress
#ce
#include-once
#include <array.au3>
; #FUNCTION# ====================================================================================================================
; Name...........: _FileHippoDownload
; Description ...: Downloads the designated file from FileHippo and/or returns the latest verison number
; Syntax.........: _FileHippoDownload($sProgramTitle, $sDownloadFolder[, $sDownloadFileName = ""][, $bDownload = True][,$bSkipBeta = True][, $FunctionToCall = ""])
; Parameters ....: $sProgramTitle    - the title of the program as it appears in the URL
;                                         - "malwarebytes_anti_malware" from http://filehippo.com/download_malwarebytes_anti_malware/
;                 $sDownloadFolder   - the full path for the file to be downloaded to
;                 $sDownloadFileName - the filename of the file to be downloaded
;                                    - if filename = "" use filename from filehippo
;                 $bDownload         - [optional] True = program will be downloaded  False = return Version number ONLY
;                                                 $bSkipBeta                 - [optional] True = BETA copies will not be downloaded  False = latest version will be downloaded
;                 $FunctionToCall    - [optional] A function which can update a Progressbar and react on UserInput like Click on Abort or Close App.
;                                    - If "$FunctionToCall" returns False abort download
;                                     -    Func _UpdateProgress($Percentage)
;                                   -      ProgressSet($Percentage,$Percentage &"%")
;                                     -    If _IsPressed("77") Then Return False ; Abort on F8
;                                     -    Return True ; ALL OK Continue download
;                                     -    Endfunc
; Return values .: Success - returns a 2D array containing technical details about the file (eg Filename, author, etc)
;                         - element [0][0] contains row count
;               Failure - ""
;                  @error = 1 - Unable to download programs/description page
;                  @error = 2 - Unable to read programs/description page
;                  @error = 3 - Unable to read download page
;                  @error = 4 - Unable to read URL to download program
;                  @error = 5 - Unable to download program
;                  @error = 6 - Destination not reachable
;                  @error = 7 - Aborted by $FunctionToCall
;                  @error = 8 - $FunctionToCall doesn't exist
;                  @error = 9 - $bSkipBeta=TRUE however there are no NON-Beta files to download
; Author ........: John Morrison aka Storm-E
; Modified.......: V2.0  Added details from TECH tab
;               : V2.1  Added create destination folder and error code if it can't be created @error = 6
;               :      Changed InetGet to work in the backgroud and added sleep to give script time to do things (eg for adlib)
;               :    Changed returned array to return row count in element 0,0
;               :      Added "Latest Version" number to array (element[1][1] (left it out in V2.0 OOPS
;               : V2.11 Added Progress function $FunctionToCall
;               : V2.12 Added check if $FunctionToCall function exists
;               : V2.121 Minor fix for properties that may not exist (Author & HomePage) Thanks 'Chimaera'
;               : V2.13 Added option to ignore BETA copies "$bSkipBeta"
;               : V2.14 Change on FileHippo site messed up site scape Thanks engjcowi
; Remarks .......: Thanks to skin27 for your suggestion to add details and auto filename from filehippo
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _FileHippoDownload($sProgramTitle, $sDownloadFolder, $sDownloadFileName = "", $bDownload = True, $bSkipBeta = True, $FunctionToCall = "")
            Local $DownloadUrl, $asDownloadUrl
            Local $sCurrentVersion, $asCurrentVersion
            Local $sBaseSite = 'http://filehippo.com'
            Local $sBaseFolder = '/download_' & $sProgramTitle & '/'
            Local $sVersionFolder = "" ; for Beta rejection


            ;String trailing slash "\"
            If StringRight($sDownloadFolder, 1) = "\" Then StringLeft($sDownloadFolder, StringLen($sDownloadFolder) - 1)
            If DirCreate($sDownloadFolder) = 0 Then Return SetError(6, 0, "") ; destination unreachable

            ;Get source for program page
            Local $sPageSource = _GetSourceCode($sBaseSite & $sBaseFolder)
If @error Then
                        ;Failed to get programs page
                        Return SetError(1, 0, "")
            EndIf
            ;Latest Version<br/><b>Malwarebytes Anti-Malware 1.51.1</b><br/><br/>Old Versions
            $asCurrentVersion = StringRegExp($sPageSource, '(?s)(?i)Latest Version<br(.*?)</b><br/><br/>Old Versions', 3)
            If @error Then
                        Return SetError(2, 0, "")
            EndIf
            $sCurrentVersion = StringMid($asCurrentVersion[0], StringInStr($asCurrentVersion[0], " ", 0, -1) + 1)

            ;Check for BETA copy rejection
            If $bSkipBeta And StringInStr($asCurrentVersion[0], "beta") <> 0 Then
                        ;Get table of old versions
                        $asCurrentVersion = StringRegExp($sPageSource, '(?s)(?i)>Old Versions<(.*?)download_firefox/history/', 3)
                        If @error Then
                                    Return SetError(2, 0, "")
                        EndIf

                        ; Break table into array
                        $asCurrentVersion = StringRegExp($asCurrentVersion[0], '(?s)(?i)<a href="/download_firefox/(.*?)/">(.*?)</a>', 3)
                        If @error Then
                                    Return SetError(2, 0, "")
                        EndIf

                        ;search array for NON beta version
                        For $iItem = 1 To UBound($asCurrentVersion) - 1 Step 2
                                    If StringInStr($asCurrentVersion[$iItem], "beta") = 0 Then
                                                $sVersionFolder = $asCurrentVersion[$iItem - 1] & "/"
                                                $sCurrentVersion = StringMid($asCurrentVersion[$iItem], StringInStr($asCurrentVersion[$iItem], " ", 0, -1) + 1)
                                                ExitLoop
                                    EndIf
                        Next

                        If $sVersionFolder = "" Then
                                    ;NO NON BETA version available
                                    Return SetError(9, 0, "")
                        Else
                                    ;Found non beta

                                    ;Get source for non beta program page
                                    Local $sPageSource = _GetSourceCode($sBaseSite & $sBaseFolder & $sVersionFolder)
                                    If @error Then
                                                ;Failed to get programs page
                                                Return SetError(1, 0, "")
                                    EndIf
                        EndIf
            EndIf

            ;Get download URL
            $asDownloadUrl = StringRegExp($sPageSource, '(?s)(?i)<a href="' & $sBaseFolder & 'download/(.*?)/">', 3)
            If @error Then
                        Return SetError(2, 0, "")
            EndIf
            $_DownloadUrl1 = $asDownloadUrl[0]

            ;Get source for details page
            Local $sPageSource = _GetSourceCode($sBaseSite & $sBaseFolder & 'tech/')
            If @error Then
                        ;Failed to get programs page
                        Return SetError(1, 0, "")
            EndIf

            ;Get Details/description Table
            ;$asDescTable = StringRegExp($sPageSource, '(?s)(?i)<div class="desc">.*?<table>(.*?)</table>', 3)
            $asDescTable = StringRegExp($sPageSource, '(?s)(?i)<div id="txt">.*?<table>(.*?)</table>', 3)
            If @error Then
                        Return SetError(2, 0, "")
            EndIf
            $sDescTable = $asDescTable[0]

            ;Split up table
            $asDescTable = StringRegExp($sDescTable, '(?s)(?i)<tr><td><b>(.*?):</b></td><td>(.*?)</td></tr>', 3)
            If @error Then
                        Return SetError(2, 0, "")
            EndIf

            ;Convert to 2D array
            Dim $_FileDetails[UBound($asDescTable) / 2 + 2][2]
            $_FileDetails[0][0] = UBound($asDescTable) / 2 ; number of rows in array
            $_FileDetails[2][0] = $asDescTable[0]
            $_FileDetails[2][1] = $asDescTable[1]
            For $item = 2 To UBound($asDescTable) - 1 Step 2
                        $_FileDetails[$item / 2 + 2][0] = $asDescTable[$item]
                        $_FileDetails[$item / 2 + 2][1] = $asDescTable[$item + 1]
            Next

            ;Cleanup Author
            Local $iIndex = _ArraySearch($_FileDetails, "Author")
            If Not @error Then
                        $_FileDetails[$iIndex][1] = StringLeft($_FileDetails[$iIndex][1], StringInStr($_FileDetails[$iIndex][1], "<") - 1)
            EndIf

            ;Cleanup HomePage
            $iIndex = _ArraySearch($_FileDetails, "HomePage")
            If Not @error Then
                        $_FileDetails[$iIndex][1] = StringMid($_FileDetails[$iIndex][1], StringInStr($_FileDetails[$iIndex][1], "href=") + 6)
                        $_FileDetails[$iIndex][1] = StringMid($_FileDetails[$iIndex][1], 1, StringInStr($_FileDetails[$iIndex][1], '"') - 1)
            EndIf

            $_FileDetails[1][0] = "Latest Version"
            $_FileDetails[1][1] = $sCurrentVersion

            If $bDownload Then
                        ;<a href="/download_malwarebytes_anti_malware/download/f9c81a8e689661f472f47aa7a0b12ada/"><img src="http://cache.filehippo.com/img/down5.png" alt="Download"/></a>
                        ;Get source for download page
                        $sPageSource = _GetSourceCode($sBaseSite & $sBaseFolder & 'download/' & $_DownloadUrl1) ; downlaod page
                        If @error Then
                                    ;Failed to get programs page
                                    Return SetError(3, 0, "")
                        EndIf
                        ;<a id="_ctl0_contentMain_lnkURL" class="black" href="/download/file/de709ff1117ec419609d7fceecd86e625fe523b1385fa00515aa824249206a40/">If not then please click this link</a>
                        $asDownloadUrl = StringRegExp($sPageSource, '(?s)(?i)href="/download/file/(.*?)/">', 3)
                        If @error Then
                                    Return SetError(4, 0, "")
                        EndIf
                        $DownloadUrl = "/download/file/" & $asDownloadUrl[0] & "/"

                        If $sDownloadFileName = "" Then
                                    ;Use FileHippo filename
                                    $sDownloadFileName = $_FileDetails[_ArraySearch($_FileDetails, "Filename")][1]
                        EndIf

                        ; DOWNLOAD FILE
                        Local $iFileSize = InetGetSize($sBaseSite & $DownloadUrl, 1)
                        Local $DownloadedSoFar = 0 ; howmany bytes of the file have been downloaded
                        Local $bRtn = True ; Progress function return OK
                        Local $hDownload = InetGet($sBaseSite & $DownloadUrl, $sDownloadFolder & "\" & $sDownloadFileName, 1, 1)
                        Do
                                    If $FunctionToCall <> "" Then
                                                $bRtn = Call($FunctionToCall, Floor((InetGetInfo($hDownload, 0) / $iFileSize) * 100))
                                                If @error Then
                                                            InetClose($hDownload) ; Close the handle to release resourcs.
                                                            Return SetError(8, 0, "")
                                                EndIf
                                    EndIf
                                    Sleep(250)
                        Until InetGetInfo($hDownload, 2) Or $bRtn = False ; Check if the download is complete.
                        Local $nBytes = InetGetInfo($hDownload, 0)
                        InetClose($hDownload) ; Close the handle to release resourcs.
                        If @error Then
                                    Return SetError(5, 0, "")
                        EndIf
                        If $bRtn = False Then
                                    ;Download aborted by $FunctionToCall
                                    Return SetError(7, 0, "")
                        EndIf
            EndIf
            Return $_FileDetails
EndFunc   ;==>_FileHippoDownload

Func _GetSourceCode($_Url)
            Local $_InetRead = InetRead($_Url)
            If Not @error Then
                        Local $_BinaryToString = BinaryToString($_InetRead)
                        If Not @error Then Return $_BinaryToString
            EndIf
EndFunc   ;==>_GetSourceCode

Edits

12/08/2011 V2.0 added details from FileHippo site returned as a 2D array, also if filename is blank will use file name from FileHippo

14/08/2011 V2.1 Added create destination folder and error code if it can't be created @error = 6

- Changed InetGet to work in the backgroud and added sleep to give script time to do things (eg for adlib)

- Changed returned array to return row count in element 0,0

- Other minor changes

14/08/2011 V2.11 Added progress bar function call

16/08/2011 V2.12 Added check if $FunctionToCall function exists

17/08/2011 V2.121 Minor fix for properties that may not exist (Author HomePage) Thanks 'Chimaera'

18/02/2012 V2.13 Added option to ignore BETA copies "$bSkipBeta"

18/04/2012 V2.14 Change on FileHippo site messed up site scrape Thanks engjcowi

Edited by storme
Link to comment
Share on other sites

WebSite has added an "Update Checker".

It will scan computer for installed software, check the versions and then send this information to FileHippo.com to see if there are any newer releases.

Yep like many web download sites and they can be very useful if updating existing software is what your interested in.

This script is more for the situation where the scripter wants to download it him/herself for install or updateing

OR they want to control what versions are installed.

OR this is the ONLY program they want to update on a client computer.

Thanks for the info.

John Morrison

Link to comment
Share on other sites

Storme thanks for sharing. Nice function if you're working with a script with files hosted on filehippo (a lot).

Is there a chance you could retrieve the filename of the file to download, because now you have to know the extension of the file before downloading.Such functions would be nice for more sites like download.com, sourceforge etc than it would be easier to do simple package management in autoit.

Link to comment
Share on other sites

Storme thanks for sharing. Nice function if you're working with a script with files hosted on filehippo (a lot).

Is there a chance you could retrieve the filename of the file to download, because now you have to know the extension of the file before downloading.Such functions would be nice for more sites like download.com, sourceforge etc than it would be easier to do simple package management in autoit.

I looked into retrieving the filename but there is some "Internet-e-stuff" (Tech term :mellow:) that gives the browser the final name of the file.

For my purposes I already new the name and wanted it to be the same name every time to simplify the rest of the script.

If it's a new program you do the first download manually and that gives you everything from then on.

The extension should always be ".exe" for an installer from these sites (well maybe ".msi").

I may bring out other downloaders as they are mostly variations on this theme. But it'll be when I need them. I don't have time to work/debug code I wont' be using myself. :)

I'm sure I'll run into sourceforge sometime though, it's a great site. :)

Thanks for the feedback!

John Morrison

BTW if you find out how to get the final name let me know and I'll see if I can incorporate it into the script.

Link to comment
Share on other sites

BTW if you find out how to get the final name let me know and I'll see if I can incorporate it into the script.

This worked for me, you may have a look at it

; #FUNCTION# ====================================================================================================================
; Name...........: _FileHippoDownload
; Description ...: Downloads the designated file from FileHippo and/or returns the latest verison number
; Syntax.........: _FileHippoDownload($sProgramTitle, $sDownloadPathAndName, $bDownload = True)
; Parameters ....: $sProgramTitle        - the title of the program as it appears in the URL
;                                        - "malwarebytes_anti_malware" from http://filehippo.com/download_malwarebytes_anti_malware/
;                  $sDownloadPathAndName - the full path or the file to be downloaded to
;                  $bDownload            - True = program will be downloaded
;                                        - False = return Version number ONLY
; Return values .: Success - returns the latest version number
;                  Failure - ""
;                   @error = 1 - Unable to read programs page
;                   @error = 2 - Unable to read URL to download page
;                   @error = 3 - Unable to read download page
;                   @error = 4 - Unable to read URL to download program
;                   @error = 5 - Unable to download program
; Author ........: John Morrison aka Storm-E
; Modified.......: 13-08 by skin27
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _FileHippoDownload($sProgramTitle, $sDownloadPath, $bDownload = True)
    Local $_DownloadUrl1, $asDownloadUrl, $asFilename, $Filename
    Local $sCurrentVersion, $asCurrentVersion
    Local $sBaseSite = 'http://filehippo.com'
    Local $sBaseFolder = '/download_' & $sProgramTitle & '/'
    Local $sBaseFolderDetails = '/download_' & $sProgramTitle & '/tech/'

    ;Get source for program page
    Local $sPageSource = _GetSourceCode($sBaseSite & $sBaseFolder)
    Local $sPageSourceDetails = _GetSourceCode($sBaseSite & $sBaseFolderDetails)
    If @error Then
        ;Failed to get programs page
        Return SetError(1, 0, "")
    EndIf

    ;Latest Version<br/><b>Malwarebytes Anti-Malware 1.51.1</b><br/><br/>Old Versions
    $asCurrentVersion = StringRegExp($sPageSource, '(?s)(?i)Latest Version<br(.*?)</b><br/><br/>Old Versions', 3)
    If @error Then
        Return SetError(2, 0, "")
    EndIf
    $sCurrentVersion = StringMid($asCurrentVersion[0], StringInStr($asCurrentVersion[0], " ", 0, -1) + 1)

    If $bDownload Then
        ;<a href="/download_malwarebytes_anti_malware/download/f9c81a8e689661f472f47aa7a0b12ada/"><img src="http://cache.filehippo.com/img/down5.png" alt="Download"/></a>
        $asDownloadUrl = StringRegExp($sPageSource, '(?s)(?i)<a href="' & $sBaseFolder & 'download/(.*?)/">', 3)
        If @error Then
            Return SetError(2, 0, "")
        EndIf
        $_DownloadUrl1 = $asDownloadUrl[0]

        ;<a href="/download_malwarebytes_anti_malware/download/f9c81a8e689661f472f47aa7a0b12ada/"><img src="http://cache.filehippo.com/img/down5.png" alt="Download"/></a>
        $asFilename = StringRegExp($sPageSourceDetails, '(?s)(?i)Filename:</b></td><td>(.*?)</td></tr><tr><td><b>File size', 3)
        If @error Then
            Return SetError(2, 0, "")
        EndIf
        $Filename = $asFilename[0]

        ;Get source for download page
        $sPageSource = _GetSourceCode($sBaseSite & $sBaseFolder & 'download/' & $_DownloadUrl1) ; downlaod page
        If @error Then
            ;Failed to get programs page
            Return SetError(3, 0, "")
        EndIf
        ;<a id="_ctl0_contentMain_lnkURL" class="black" href="/download/file/de709ff1117ec419609d7fceecd86e625fe523b1385fa00515aa824249206a40/">If not then please click this link</a>
        $asDownloadUrl = StringRegExp($sPageSource, '(?s)(?i)href="/download/file/(.*?)/">', 3)
        If @error Then
            Return SetError(4, 0, "")
        EndIf
        $_DownloadUrl1 = "/download/file/" & $asDownloadUrl[0] & "/"

       ; DOWNLOAD FILE
        Local $hDownload = InetGet($sBaseSite & $_DownloadUrl1, $sDownloadPath & "\" & $Filename, 1, 0)
        If @error Then
            Return SetError(5, 0, "")
        EndIf
    EndIf
    Return $sCurrentVersion

EndFunc   ;==>_FileHippoDownload

Func _GetSourceCode($_Url)
    Local $_InetRead = InetRead($_Url)
    If Not @error Then
        Local $_BinaryToString = BinaryToString($_InetRead)
        If Not @error Then Return $_BinaryToString
    EndIf
EndFunc   ;==>_GetSourceCode
Link to comment
Share on other sites

Note that when using my solution then I think it would be better to have an extra parameter "filename". When this parameter empty it could retrieve the default filename from the website, otherwise it takes the users input. The tech site adds some other interesting information about filesize, orignial website. Maybe this information could returned with the latest version in an array.

Link to comment
Share on other sites

Note that when using my solution then I think it would be better to have an extra parameter "filename". When this parameter empty it could retrieve the default filename from the website, otherwise it takes the users input. The tech site adds some other interesting information about filesize, orignial website. Maybe this information could returned with the latest version in an array.

Thanks for pointing out the &%&$%&*& obvious...sigh :mellow:

I must have clicked on that "tech" tab when I first found Filehippo but I've got so used to seeing the page I've just ignored it since.

I'll defiantly implement your suggestions, but it may take a while keep an eye on this topic. :)

I haven't looked into the Tech page source yet but first thoughts are

The returned Array will probably be a 2D array with column 0 containing the rows description and column 1 containing the information

Like this

Title, Malwarebytes Anti-Malware 1.51.1 
Filename, mbam-setup-1.51.1.1800.exe 
File size, 9.03MB (9,466,208 bytes) 
Requirements, Windows 2000 / XP / Vista / Windows7 / XP64 / Vista64 / Windows7 64 
Languages, Multiple languages 
License, Shareware 
Date added, July 15, 2011 
Author, Malwarebytes

It's easy to search using array search or if you know the index just use it directly.

AND

If I can workout a Table -> Array method it won't have to be updated if Filehippo adds new sections to the details.

Thanks for the suggestions!

John Morrison

Link to comment
Share on other sites

I agree with you on the things that you want in 2d array. A table would of course be great. Hereunder I added an example for sourceforge (this works a little different, namely by projectname)

; #FUNCTION# ====================================================================================================================
; Name...........: _SourceDownload
; Description ...: Downloads the featured downloadfile from Sourceforge and/or returns the filename
; Syntax.........: _SourceforgeDownload($sProgramTitle, $sDownloadPathAndName, $bDownload = True)
; Parameters ....: $sProgramTitle        - the title of the program as it appears in the URL
;                                        - "projectname" from http://sourceforge.net/projects/projectname/
;                  $sDownloadPath - the full path to be downloaded to
;                  $bDownload            - True = program will be downloaded
;                                        - False = return Version number ONLY
; Return values .: Success - returns the latest version number
;                  Failure - ""
;                   @error = 1 - Unable to read programs page
;                   @error = 2 - Unable to read URL to download page
;                   @error = 3 - Unable to download program

; Author ........: Storme
; Modified.......: skin27
; Remarks .......: 
; Related .......: _FileHippoDownload
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _SourceforgeDownload($sProgramTitle, $sDownloadPath, $bDownload = True)
    Local $_DownloadUrl1, $asFilename, $Filename
    Local $sCurrentFile, $asCurrentFile
    Local $sBaseSite = 'http://sourceforge.net'
    Local $sBaseFolder = '/projects/' & $sProgramTitle & '/'

    ;Get source for program page
    Local $sPageSource = _GetSourceCode($sBaseSite & $sBaseFolder)
    If @error Then
        ;Failed to get programs page
        Return SetError(1, 0, "")
    EndIf

    ;get latest file to download
    $asCurrentFile = StringRegExp($sPageSource, '(?s)(?i)title="Download /(.*?)from', 3)
    If @error Then
        Return SetError(2, 0, "")
    EndIf
    $sCurrentFile = $asCurrentFile[0]

    If $bDownload Then
        $_DownloadUrl1 = $sBaseSite & $sBaseFolder & '/' & $sCurrentFile & '/download/'

       ; DOWNLOAD FILE
        Local $hDownload = InetGet($_DownloadUrl1, $sDownloadPath & "\" & $sCurrentFile, 1, 0)
        If @error Then
            Return SetError(3, 0, "")
        EndIf
    EndIf

    Return $sCurrentFile

EndFunc


Func _GetSourceCode($_Url)
    Local $_InetRead = InetRead($_Url)
    If Not @error Then
        Local $_BinaryToString = BinaryToString($_InetRead)
        If Not @error Then Return $_BinaryToString
    EndIf
EndFunc   ;==>_GetSourceCode
Link to comment
Share on other sites

I agree with you on the things that you want in 2d array. A table would of course be great. Hereunder I added an example for sourceforge (this works a little different, namely by projectname)

Looks good!

Have look at the Version 2.0 of the FileHippo function in the first post and see if that meets everything you wanted.

If it does and you match up the interface of your function with mine (ie return a 2D array) maybe we could combine them into a little UDF.

??SiteDownloaderUDF.Au3??

But the interfaces should be consistant so users don't have deal with different function calls for each site.

BTW I have another function for the "protableapps" site primitive compared to the current one but I'll fix it up when we have this one cleaned up.

Thanks for the feedback and help!

John Morrison

Link to comment
Share on other sites

Version 2.0 works very good (and fast!). Some small remarks for the cleanup:

1) Can you still add the version number as a separate entry in the array

2) I think that you add in array[0] the size of the array (Ubound). This is kind of standard.

3) Check line 113 (still a debug message left)

4) $sDownloadFolder is clearer than $sDownloadPath (as this may get confused to the download url)

I was thinking about a good name for the UDF too and didn't come up with a good name also as "DownloadSoftwareFromDownloadWebsites_UDF" is a bit long :mellow: .

Link to comment
Share on other sites

Just curious is there a way to add a progress bar within it?

Very good stuff this should help lots so thanks again

Is it for more than filehippo then?, is that why the name needs to be changed ..

Chimaera

Link to comment
Share on other sites

Is it for more than filehippo then?, is that why the name needs to be changed ..

Chimaera

The function is site-pecific, because it uses the source of the website. You can use it for other download websites as well by modifying the code (see my Sourceforge example).

Here is an example of the function:

#include <Array.au3>

;example 1: download ccleaner with the default filename to the desktop
_FileHippoDownload("ccleaner", @DesktopDir,"", true)

;example 2: get info about the download
$info = _FileHippoDownload("ccleaner", @DesktopDir,"", false)
_ArrayDisplay($info)

;example 3download ccleaner with a specified name to the desktop and retrieve the homepage of the software publisher
$info = _FileHippoDownload("ccleaner", @DesktopDir,"CleanerTool.exe", true)
MsgBox(0,"Homepage",$info[8][1])
Link to comment
Share on other sites

I have it working just didnt realise it could be used for other sites

Is there a way to make the downloads wait until one is finished before it goes after the next?

I tried sleep see eg below but it dosent hold it off correctly, and when several get going it makes the gui twitchy or non responsive

Can RunWait or similar be used or something like that?

$MWB_down = _FileHippoDownload("malwarebytes_anti_malware",  @ScriptDir & "\file_includes" , "install_malware.exe", True)
    Sleep(1500)
    $AVG32_down = _FileHippoDownload("avg_antivirus_32",  @ScriptDir & "\file_includes" , "install_avg_32.exe", True)
    Sleep(1500)
    $AVG64_down = _FileHippoDownload("avg_antivirus_64",  @ScriptDir & "\file_includes" , "install_avg_64.exe", True)

Edit: Typo

Edited by Chimaera
Link to comment
Share on other sites

I have it working just didnt realise it could be used for other sites

Is there a way to make the downloads wait until one is finished before it goes after the next?

I tried sleep see eg below but it dosent hold it off correctly, and when several get going it makes the gui twitchy or non responsive

Can RunWait or similar be used or something like that?

$MWB_down = _FileHippoDownload("malwarebytes_anti_malware",  @ScriptDir & "\file_includes" , "install_malware.exe", True)
    Sleep(1500)
    $AVG32_down = _FileHippoDownload("avg_antivirus_32",  @ScriptDir & "\file_includes" , "install_avg_32.exe", True)
    Sleep(1500)
    $AVG64_down = _FileHippoDownload("avg_antivirus_64",  @ScriptDir & "\file_includes" , "install_avg_64.exe", True)

Edit: Typo

The samples were more for general use. About the wait function you may try to loop until the downloaded file exist. Something like this:

While FileExists (@ScriptDir & "\file_includes\install_malware.exe") = 0
   Sleep(100)
Wend
Link to comment
Share on other sites

I have it working just didnt realise it could be used for other sites

Is there a way to make the downloads wait until one is finished before it goes after the next?

The function does wait untill the download is complete.

the heart of the function is

Local $hDownload = InetGet($sBaseSite & $DownloadUrl, $sDownloadPath & "\" & $sDownloadFileName , 1, 0)

The zero at the end means "0 = (default) Wait until the download is complete before continuing."

Check the return values @error. You maybe hitting an error (eg destination folder doesn't exist - I've just added an check for that)

Try somthing like this

ConsoleWrite("Start: malwarebytes_anti_malware")
$MWB_down = _FileHippoDownload("malwarebytes_anti_malware", @ScriptDir & "\file_includes", "install_malware.exe", True)
If @error Then
    MsgBox(0, "Error", @error)
EndIf
ConsoleWrite("End: malwarebytes_anti_malware")

ConsoleWrite("Start: avg_antivirus_32")
$AVG32_down = _FileHippoDownload("avg_antivirus_32", @ScriptDir & "\file_includes", "install_avg_32.exe", True)
If @error Then
    MsgBox(0, "Error", @error)
EndIf
ConsoleWrite("End: avg_antivirus_32")

ConsoleWrite("Start: avg_antivirus_64")
$AVG64_down = _FileHippoDownload("avg_antivirus_64", @ScriptDir & "\file_includes", "install_avg_64.exe", True)
If @error Then
    MsgBox(0, "Error", @error)
EndIf
ConsoleWrite("End: avg_antivirus_64")

Let me know how it goes.

I tried sleep see eg below but it dosent hold it off correctly, and when several get going it makes the gui twitchy or non responsive

My guess is when this is running your GUI will be totally non responsive until the download is done.

<EDIT> I just changed it so the "InetGet" runs in the background and there is a do-until with a a sleep (used the code from help used the code from "HELP" (yes I do read it :mellow:)

That 'should' give the rest of the script a bit of time to do things. BUT remember the function is "blocking" and nothing will happen till the function exits.

Hope that helps!

John Morrison

New Update on it's way 2.1

Edited by storme
Link to comment
Share on other sites

Just curious is there a way to add a progress bar within it?

I wouldn't want progress bar to be created by the function because it will almost never fit with the calling program.

However, if a reference is passed to the function for a progress bar it could be updated by the function.

As of V2.1 the download is running in the background so a progress bar could be updated in the do-until loop.

It's not a priority for me at the moment. Remind me later when it's settled down and I'll add it. :mellow:

Keep the ideas coming

John Morrison

Link to comment
Share on other sites

1) Can you still add the version number as a separate entry in the array

Done V2.1....... element [0][0]...... sorry I missed it

2) I think that you add in array[0] the size of the array (Ubound). This is kind of standard.

Done V2.1....... Personally I don't like it but it can come

3) Check line 113 (still a debug message left)

OOPS! Done V2.1

4) $sDownloadFolder is clearer than $sDownloadPath (as this may get confused to the download url)

Point taken DONE V2.1

I was thinking about a good name for the UDF too and didn't come up with a good name also as "DownloadSoftwareFromDownloadWebsites_UDF" is a bit long :mellow: .

YEP!

I ended up with similarly rediculious names. :)

Maybe just SoftwareArchivesDownloaders_UDF (well it's a little shorter. :)

John

Link to comment
Share on other sites

How about _FileDownloader ? or _AutoDownloader ?

thats kinda what it does.

Edit

Just tried 2.1 Clever Stuff M8 :mellow:

Edited by Chimaera
Link to comment
Share on other sites

How about _FileDownloader ? or _AutoDownloader ?

thats kinda what it does.

Yep.... But what we were talking about was expanding it so that we had routines for other download archives.

This was a name for the whole package/UDF. :)

Just tried 2.1 Clever Stuff M8 :mellow:

If you mean the function call...I stole that from _ftp_download (in the help file, Yes I'm admiting I read it :))

I thought this approach should do everything you want and maybe a bit more. :)

Let me know if it does what you need.

John Morrison

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