18 March 2010

Downlad a web page – Scaricare una pagina web – Iron AdBlock.ini update

option explicit

' -----------------------------------------------------------------------------
' PARAMETERS
' -----------------------------------------------------------------------------
const source = "http://fanboy.co.nz/adblock/iron/adblock.ini"
const destination = "C:\Program Files (x86)\SRWare Iron\adblock.ini"
' -----------------------------------------------------------------------------


UpdateAdBlock source, destination


sub UpdateAdBlock(source, destination)
	
	' download adblock.ini
	GetHtmlPage source, destination
	
	' show message
	dim s : s = ReadFirstLines(destination, 3)
	MsgBox s, vbInformation, "Adblock updated"

end sub


sub GetHtmlPage (up_http, down_http)

	dim xmlhttp : set xmlhttp = createobject("msxml2.xmlhttp.3.0")
	xmlhttp.open "get", up_http, false
	xmlhttp.send

	dim fso : set fso = createobject ("scripting.filesystemobject")

	dim newfile : set newfile = fso.createtextfile(down_http, true)
	
	'and the text from the XMLHTTP response can then be written to the file:
	newfile.write (xmlhttp.responseText)

	'the file must then be closed:
	newfile.close

	set newfile = nothing
	set xmlhttp = nothing
	set fso = nothing

end sub


function ReadFirstLines(fileName, numberOfLines)
	
	const wChar = "§"
	dim res
	
	' open text file
	dim fso : set fso = createobject ("scripting.filesystemobject")
	dim ts : set ts = fso.OpenTextFile(fileName)
	
	' read the first x lines
	dim x
	for x = 1 to numberOfLines
		res = res & ts.ReadLine & wChar
	next
	
	ts.close
	set ts = Nothing
	set fso = Nothing
	
	' format output string
	if len(res) > 1 then
		res = left(res, len(res) - 1)
		res = replace(res, wChar, vbCrlf)
	end if
	
	ReadFirstLines = res
	
end function
Trovato qui.