userabuser
Joined: 15 Jul 2006 Posts: 29
|
Posted: Sun Dec 30, 2007 6:09 pm Post subject: autodownloader to keep software current |
|
|
Here is something I put together some time ago. I always meant to continue with it, fancy it up. Though I do run it as a scheduled task to keep my software up to date, I've never gone back to work on it. Since it was about a year ago, I don't remember who I should be thanking for some of the code I used from this forum. (Sorry)
There are three files here. the ahk, ini, and a readme.
As you probably know, many companies try to hinder your ability to download their software. They'd rather you have to click through all the sites little windows to see the ad's.
Hopefully, you guys can make use of this and do it justice.
Autodownloader.Ahk
| Code: | #SingleInstance force ; The word Ignore skips the dialog box and leaves the old instance Running.
; In other words, attempts to launch an already-running script are ignored
SetWorkingDir, %A_ScriptDir%
Menu, Tray, NoStandard
Menu, tray, tip, Autodownloader
Menu, Tray, Add, E&xit, CloseNow
Gui, Add, Progress, vMyProgress w416
Gui, Add, Text, vMyText wp ; wp means "use width of previous".
Gui, Add, Button, gCloseNow x165 y60 w130 h30 , Cancel
Gui, +ToolWindow
Gui, Show, , Autoloader Progress Bar
IniRead, OutputFolder, AutoDownloader.ini, Setup, OutputFolder
DestDir = %OutputFolder%
URLdownload = %temp%\cvsearch_html.html
UrlFile = %temp%\cvsearch_result.txt
p = 5 ; Start Progress Bar at the 5% position
i = 0 ; Loop Counter, Begin at 0
Loop
{
i += 1
IniRead, DestFile, AutoDownloader.ini, %i%, DestFile
GuiControl, , MyProgress, %p%
p += 10
GuiControl,, MyText, Currently Downloading %DestFile%
IniRead, URL_Link, AutoDownloader.ini, %i%, URL_Link
IniRead, Solid_Link, AutoDownloader.ini, %i%, Solid_Link
If URL_Link = Error
{
If Solid_Link = Error
ExitApp
}
IniRead, StringToHunt, AutoDownloader.ini, %i%, StringToHunt
Gosub GetFile
}
TestMsg:
MsgBox, 0, ,Exiting App
Return
CloseNow:
ExitApp
Return
GetFile:
IfNotExist, %DestDir%
{
MsgBox, 4, Autodownloader , The Destination %DestDir% does not Exist! `n`nNote: you can get this message if you've not edited the autoloader.ini file. Shall we create the directory for you?
IfMsgBox, yes
FileCreateDir, %DestDir%
If ErrorLevel
;ExitApp
MsgBox, 4, Autodownloader, Directory does not Exist and I can not create it. `n Would you like to edit the autodownloader.ini file?
IfMsgBox, yes
RunWait notepad.exe autodownloader.ini
MsgBox, 0, Autodownloader , Try restarting the program. `nI'm going away now, Your stressing me out...
ExitApp
}
IniRead, Solid_Link, AutoDownloader.ini, %i%, Solid_Link, %A_Space%
If %Solid_Link%
{
URLDownloadToFile, %Solid_Link%, %DestDir%\%DestFile%
Return
}
Else
URLDownloadToFile, %URL_Link%, %URLdownload%
Loop, Read, %URLdownload%, %UrlFile%
{
URLSearchString = %A_LoopReadLine%
Gosub, URLSearch
}
FileRead, Contents, *t %UrlFile%
URLDownloadToFile, %Contents%, %DestDir%\%DestFile%
Contents = ; Free the memory.
FileDelete, %UrlFile%
URLSearch:
StringGetPos, URLStart1, URLSearchString, %StringToHunt%
; Find the left-most starting position:
URLStart = %URLStart1% ; Set starting Default.
Loop
{
; It helps performance (at least in a script with many variables) to resolve
; "URLStart%A_Index%" only once:
StringTrimLeft, ArrayElement, URLStart%A_Index%, 0
If ArrayElement = ; End of the array has been reached.
Break
If ArrayElement = -1 ; This element is disqualified.
Continue
If URLStart = -1
URLStart = %ArrayElement%
Else ; URLStart has a valid position in it, so compare it with ArrayElement.
{
If ArrayElement <> -1
If ArrayElement < %URLStart%
URLStart = %ArrayElement%
}
}
If URLStart = -1 ; No URLs Exist in URLSearchString.
Return
; Otherwise, extract this URL:
StringTrimLeft, URL, URLSearchString, %URLStart% ; Omit the beginning/irrelevant part.
Loop, Parse, URL, %A_Tab%%A_Space%<> ; Find the First Space, tab, or angle (if any).
{
URL = %A_LoopField%
Break ; i.e. perform only one loop iteration to fetch the First "field".
}
; If the above loop had zero iterations because there were no ending characters found,
; leave the contents of the URL var untouched.
; If the URL ends in a double quote, remove it. For now, StringReplace is used, but
; note that it seems that double quotes can legitimately exist inside URLs, so this
; might damage them:
StringReplace, URLCleansed, URL, ",, All
FileAppend, %URLCleansed%`n
LinkCount += 1
; See if there are any other URLs in this line:
StringLen, CharactersToOmit, URL
CharactersToOmit += %URLStart%
StringTrimLeft, URLSearchString, URLSearchString, %CharactersToOmit%
Gosub, URLSearch ; Recursive call to self.
Return
|
Readme.txt
| Code: |
Quick and Dirty application to download current versions of AVGFREE AVGTRIAL EWIDO
SPYBOT AND OTHERS.
MAKE SURE TO CHANGE THE OUTPUT FOLDER
[setup]
OutputFolder=C:\Tech\software
;OutputFolder=p:\websites\downloads
;There are two combinations you can use. SolidLink/DestFile or
;URL_Link/StringToHunt/DestFile. In other words, If you use a solid link and DestFile together,
;the program will ignore the URL_Link/StringToHunt entries
;
; Example: Solid_link
; DestFile=avast.exe
; Solid_Link=http://files.avast.com/iavs4pro/setupeng.exe
;
; Example: URL_Link
; URL_Link=http://www.avast.com/eng/download-avast-home.html ; The webpage that links to the download.
; StringToHunt=http://files.avast.com/iavs4pro/setupeng.exe ;Part of the download url
; DestFile=avast.exe ;Destination file name
What we do with URL_Link is simply download the given web page, look for a given string, then
grab the rest of the url that belongs to the string, save it to the destination folder
supplied by the .ini file (creating the folder if it doesn't already exist)
and rename it to the given name "DestFile"
MAKE SURE TO CHANGE THE OUTPUT FOLDER
[setup]
OutputFolder=C:\Tech\software
;OutputFolder=p:\websites\downloads
|
autodownloader.ini
| Code: |
;
;
;
;There are two combinations you can use. SolidLink/DestFile or
;URL_Link/StringToHunt/DestFile. In other words, If you use a solid link and DestFile together,
;the program will ignore the URL_Link/StringToHunt entries
;
; Example: Solid_link
; DestFile=avast.exe
; Solid_Link=http://files.avast.com/iavs4pro/setupeng.exe
;
; Example: URL_Link
; URL_Link=http://www.avast.com/eng/download-avast-home.html
; StringToHunt=http://files.avast.com/iavs4pro/setupeng.exe
; DestFile=avast.exe
;
;Note: If the file has a "version number" in the name, it is better to try the Url link method
;as you can leave the version info out of the "StringToHunt" line.
[setup]
OutputFolder=H:\autohotkey\software_new
;OutputFolder=p:\websites\downloads
;OutputFolder=\\Server1\Users\Rodney\My Documents\Autohotkey\software
[1]
URL_Link=http://free.grisoft.com/doc/5390/us/frt/0?prd=aff
StringToHunt=http://free.grisoft.com/softw/70free/setup/avg75free
DestFile=avgfree.exe
[2]
URL_Link=http://www.grisoft.com/doc/downloads-products/us/crp/0?prd=triavw
StringToHunt=http://www.grisoft.cz/filedir/inst/avg75avwt
DestFile=avgtrial.exe
[3]
URL_Link=http://free.grisoft.com/doc/5390/us/frt/0?prd=asf
StringToHunt=http://free.grisoft.com/filedir/inst/avgas-setup-
DestFile=avgas.exe
[4]
;URL_Link=http://www.educ.umu.se/~cobian/cobianbackup.htm
;StringToHunt=http://www.educ.umu.se/~cobian/programz/cbSetup.exe
DestFile=cobianbackup.exe
Solid_Link=http://www.educ.umu.se/~cobian/programz/cbSetup.exe
[5]
; URL_Link=http://www.avast.com/eng/download-avast-home.html
; StringToHunt=http://files.avast.com/iavs4pro/setupeng.exe
DestFile=avast.exe
Solid_Link=http://files.avast.com/iavs4pro/setupeng.exe
|
|
|