提交 4388f0c2 authored 作者: Michael Jerris's avatar Michael Jerris

make downloads work without adodb.stream in case it fails. Thanks to Dave…

make downloads work without adodb.stream in case it fails.  Thanks to Dave Horner for the inspiration on this.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2405 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 087d7313
'
' Contributor(s):
' Michael Jerris <mike@jerris.com>
' David A. Horner http://dave.thehorners.com
'----------------------------------------------
'On Error Resume Next 'On Error Resume Next
' ************** ' **************
' Initialization ' Initialization
...@@ -7,13 +13,28 @@ Set WshShell = CreateObject("WScript.Shell") ...@@ -7,13 +13,28 @@ Set WshShell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject") Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshSysEnv = WshShell.Environment("SYSTEM") Set WshSysEnv = WshShell.Environment("SYSTEM")
Set xml = CreateObject("Microsoft.XMLHTTP") Set xml = CreateObject("Microsoft.XMLHTTP")
Dim UseWgetEXE
On Error Resume Next
Set oStream = CreateObject("Adodb.Stream") Set oStream = CreateObject("Adodb.Stream")
On Error Goto 0
If Not IsObject(oStream) Then
wscript.echo("Failed to create Adodb.Stream, using alternative download method.")
UseWgetEXE=true
Else
UseWgetEXE=false
End If
Set objArgs = WScript.Arguments Set objArgs = WScript.Arguments
quote=Chr(34) quote=Chr(34)
ScriptDir=Left(WScript.ScriptFullName,Len(WScript.ScriptFullName)-Len(WScript.ScriptName)) ScriptDir=Left(WScript.ScriptFullName,Len(WScript.ScriptFullName)-Len(WScript.ScriptName))
UtilsDir=Showpath(ScriptDir) UtilsDir=Showpath(ScriptDir)
ToolsBase="http://svn.freeswitch.org/downloads/win32/" ToolsBase="http://svn.freeswitch.org/downloads/win32/"
If UseWgetEXE Then
GetWgetEXE UtilsDir
End If
GetCompressionTools UtilsDir GetCompressionTools UtilsDir
...@@ -58,6 +79,14 @@ Sub GetCompressionTools(DestFolder) ...@@ -58,6 +79,14 @@ Sub GetCompressionTools(DestFolder)
End If End If
End Sub End Sub
Sub GetWgetEXE(DestFolder)
Dim oExec
If Right(DestFolder, 1) <> "\" Then DestFolder = DestFolder & "\" End If
If Not FSO.FileExists(DestFolder & "wget.exe") Then
Slow_Wget ToolsBase & "wget.exe", DestFolder
End If
End Sub
Sub UnCompress(Archive, DestFolder) Sub UnCompress(Archive, DestFolder)
wscript.echo("Extracting: " & Archive) wscript.echo("Extracting: " & Archive)
Set MyFile = fso.CreateTextFile(UtilsDir & "tmpcmd.Bat", True) Set MyFile = fso.CreateTextFile(UtilsDir & "tmpcmd.Bat", True)
...@@ -100,19 +129,51 @@ Sub Wget(URL, DestFolder) ...@@ -100,19 +129,51 @@ Sub Wget(URL, DestFolder)
If Right(DestFolder, 1) <> "\" Then DestFolder = DestFolder & "\" End If If Right(DestFolder, 1) <> "\" Then DestFolder = DestFolder & "\" End If
Wscript.echo("Downloading: " & URL) Wscript.echo("Downloading: " & URL)
If UseWgetEXE Then
Set MyFile = fso.CreateTextFile(UtilsDir & "tmpcmd.Bat", True)
MyFile.WriteLine("@cd " & quote & DestFolder & quote)
MyFile.WriteLine("@" & quote & UtilsDir & "wget.exe" & quote & " " & URL)
MyFile.Close
Set oExec = WshShell.Exec(UtilsDir & "tmpcmd.Bat")
Do
WScript.Echo OExec.StdOut.ReadLine()
Loop While Not OExec.StdOut.atEndOfStream
Else
xml.Open "GET", URL, False xml.Open "GET", URL, False
xml.Send xml.Send
Const adTypeBinary = 1 Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2 Const adSaveCreateOverWrite = 2
Const adSaveCreateNotExist = 1 Const adSaveCreateNotExist = 1
oStream.type = adTypeBinary oStream.type = adTypeBinary
oStream.open oStream.open
oStream.write xml.responseBody oStream.write xml.responseBody
oStream.savetofile DestFolder & filename, adSaveCreateOverWrite oStream.savetofile DestFolder & filename, adSaveCreateOverWrite
oStream.close oStream.close
End If
End Sub
Sub Slow_Wget(URL, DestFolder)
StartPos = InstrRev(URL, "/", -1, 1)
strlength = Len(URL)
filename=Right(URL,strlength-StartPos)
If Right(DestFolder, 1) <> "\" Then DestFolder = DestFolder & "\" End If
Wscript.echo("Downloading: " & URL)
xml.Open "GET", URL, False
xml.Send
const ForReading = 1 , ForWriting = 2 , ForAppending = 8
Set MyFile = fso.OpenTextFile(DestFolder & filename ,ForWriting, True)
For i = 1 to lenb(xml.responseBody)
MyFile.write Chr(Ascb(midb(xml.responseBody,i,1)))
Next
MyFile.Close()
End Sub End Sub
Function Showpath(folderspec) Function Showpath(folderspec)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论