Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/src/msvc/util.vbs @ 4:26cd8f1ef0b1
import spandsp-0.0.6pre17
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 15:50:58 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:c6c5a16ce2f2 | 4:26cd8f1ef0b1 |
---|---|
1 ' | |
2 ' Contributor(s): | |
3 ' Michael Jerris <mike@jerris.com> | |
4 ' David A. Horner http://dave.thehorners.com | |
5 '---------------------------------------------- | |
6 | |
7 'On Error Resume Next | |
8 ' ************** | |
9 ' Initialization | |
10 ' ************** | |
11 | |
12 Set WshShell = CreateObject("WScript.Shell") | |
13 Set FSO = CreateObject("Scripting.FileSystemObject") | |
14 Set WshSysEnv = WshShell.Environment("SYSTEM") | |
15 Set xml = CreateObject("Microsoft.XMLHTTP") | |
16 Dim UseWgetEXE | |
17 | |
18 On Error Resume Next | |
19 Set oStream = CreateObject("Adodb.Stream") | |
20 On Error Goto 0 | |
21 | |
22 If Not IsObject(oStream) Then | |
23 wscript.echo("Failed to create Adodb.Stream, using alternative download method.") | |
24 UseWgetEXE=true | |
25 Else | |
26 UseWgetEXE=false | |
27 End If | |
28 Randomize | |
29 Set objArgs = WScript.Arguments | |
30 quote=Chr(34) | |
31 ScriptDir=Left(WScript.ScriptFullName,Len(WScript.ScriptFullName)-Len(WScript.ScriptName)) | |
32 UtilsDir=Showpath(ScriptDir) | |
33 ToolsBase="http://files.freeswitch.org/downloads/win32/" | |
34 | |
35 If UseWgetEXE Then | |
36 GetWgetEXE UtilsDir | |
37 End If | |
38 | |
39 GetCompressionTools UtilsDir | |
40 | |
41 | |
42 If objArgs.Count >=3 Then | |
43 Select Case objArgs(0) | |
44 Case "Get" | |
45 Wget objArgs(1), Showpath(objArgs(2)) | |
46 Case "GetUnzip" | |
47 WgetUnCompress objArgs(1), Showpath(objArgs(2)) | |
48 End Select | |
49 End If | |
50 | |
51 | |
52 ' ******************* | |
53 ' Utility Subroutines | |
54 ' ******************* | |
55 | |
56 | |
57 Sub WgetUnCompress(URL, DestFolder) | |
58 If Right(DestFolder, 1) <> "\" Then DestFolder = DestFolder & "\" End If | |
59 StartPos = InstrRev(URL, "/", -1, 1) | |
60 strlength = Len(URL) | |
61 filename=Right(URL,strlength-StartPos) | |
62 NameEnd = InstrRev(filename, ".",-1, 1) | |
63 filestrlength = Len(filename) | |
64 filebase = Left(filename,NameEnd) | |
65 fileext = Right(filename, Len(filename) - NameEnd) | |
66 Wget URL, DestFolder | |
67 If fileext = "zip" Then | |
68 UnCompress Destfolder & filename, DestFolder & filebase | |
69 Else | |
70 UnCompress Destfolder & filename, DestFolder | |
71 End If | |
72 End Sub | |
73 | |
74 Sub GetCompressionTools(DestFolder) | |
75 Dim oExec | |
76 If Right(DestFolder, 1) <> "\" Then DestFolder = DestFolder & "\" End If | |
77 If Not FSO.FileExists(DestFolder & "7za.exe") Then | |
78 If Not FSO.FileExists(DestFolder & "7za.tag") Then | |
79 Set MyFile = fso.CreateTextFile(DestFolder & "7za.tag", True) | |
80 MyFile.WriteLine("This file marks a pending download for 7za.exe so we don't download it twice at the same time") | |
81 MyFile.Close | |
82 | |
83 Wget ToolsBase & "7za.exe", DestFolder | |
84 | |
85 FSO.DeleteFile DestFolder & "7za.tag" ,true | |
86 Else | |
87 WScript.Sleep(5000) | |
88 End If | |
89 End If | |
90 End Sub | |
91 | |
92 Sub GetWgetEXE(DestFolder) | |
93 Dim oExec | |
94 If Right(DestFolder, 1) <> "\" Then DestFolder = DestFolder & "\" End If | |
95 If Not FSO.FileExists(DestFolder & "wget.exe") Then | |
96 Slow_Wget ToolsBase & "wget.exe", DestFolder | |
97 End If | |
98 End Sub | |
99 | |
100 Sub UnCompress(Archive, DestFolder) | |
101 batname = "tmp" & CStr(Int(10000*Rnd)) & ".bat" | |
102 wscript.echo("Extracting: " & Archive) | |
103 Set MyFile = fso.CreateTextFile(UtilsDir & batname, True) | |
104 MyFile.WriteLine("@" & quote & UtilsDir & "7za.exe" & quote & " x " & quote & Archive & quote & " -y -o" & quote & DestFolder & quote ) | |
105 MyFile.Close | |
106 Set oExec = WshShell.Exec(UtilsDir & batname) | |
107 Do | |
108 WScript.Echo OExec.StdOut.ReadLine() | |
109 Loop While Not OExec.StdOut.atEndOfStream | |
110 If FSO.FileExists(Left(Archive, Len(Archive)-3))Then | |
111 Set MyFile = fso.CreateTextFile(UtilsDir & batname, True) | |
112 MyFile.WriteLine("@" & quote & UtilsDir & "7za.exe" & quote & " x " & quote & Left(Archive, Len(Archive)-3) & quote & " -y -o" & quote & DestFolder & quote ) | |
113 MyFile.Close | |
114 Set oExec = WshShell.Exec(UtilsDir & batname) | |
115 Do | |
116 WScript.Echo OExec.StdOut.ReadLine() | |
117 Loop While Not OExec.StdOut.atEndOfStream | |
118 WScript.Sleep(500) | |
119 FSO.DeleteFile Left(Archive, Len(Archive)-3) ,true | |
120 End If | |
121 If FSO.FileExists(Left(Archive, Len(Archive)-3) & "tar")Then | |
122 Set MyFile = fso.CreateTextFile(UtilsDir & batname, True) | |
123 MyFile.WriteLine("@" & quote & UtilsDir & "7za.exe" & quote & " x " & quote & Left(Archive, Len(Archive)-3) & "tar" & quote & " -y -o" & quote & DestFolder & quote ) | |
124 MyFile.Close | |
125 Set oExec = WshShell.Exec(UtilsDir & batname) | |
126 Do | |
127 WScript.Echo OExec.StdOut.ReadLine() | |
128 Loop While Not OExec.StdOut.atEndOfStream | |
129 WScript.Sleep(500) | |
130 FSO.DeleteFile Left(Archive, Len(Archive)-3) & "tar",true | |
131 End If | |
132 | |
133 WScript.Sleep(500) | |
134 If FSO.FileExists(UtilsDir & batname)Then | |
135 FSO.DeleteFile UtilsDir & batname, True | |
136 End If | |
137 End Sub | |
138 | |
139 Sub Wget(URL, DestFolder) | |
140 StartPos = InstrRev(URL, "/", -1, 1) | |
141 strlength = Len(URL) | |
142 filename=Right(URL,strlength-StartPos) | |
143 If Right(DestFolder, 1) <> "\" Then DestFolder = DestFolder & "\" End If | |
144 | |
145 Wscript.echo("Downloading: " & URL) | |
146 | |
147 If UseWgetEXE Then | |
148 batname = "tmp" & CStr(Int(10000*Rnd)) & ".bat" | |
149 Set MyFile = fso.CreateTextFile(UtilsDir & batname, True) | |
150 MyFile.WriteLine("@cd " & quote & DestFolder & quote) | |
151 MyFile.WriteLine("@" & quote & UtilsDir & "wget.exe" & quote & " " & URL) | |
152 MyFile.Close | |
153 Set oExec = WshShell.Exec(UtilsDir & batname) | |
154 Do | |
155 WScript.Echo OExec.StdOut.ReadLine() | |
156 Loop While Not OExec.StdOut.atEndOfStream | |
157 | |
158 Else | |
159 xml.Open "GET", URL, False | |
160 xml.Send | |
161 | |
162 Const adTypeBinary = 1 | |
163 Const adSaveCreateOverWrite = 2 | |
164 Const adSaveCreateNotExist = 1 | |
165 | |
166 oStream.type = adTypeBinary | |
167 oStream.open | |
168 oStream.write xml.responseBody | |
169 oStream.savetofile DestFolder & filename, adSaveCreateOverWrite | |
170 oStream.close | |
171 End If | |
172 | |
173 End Sub | |
174 | |
175 Sub Slow_Wget(URL, DestFolder) | |
176 StartPos = InstrRev(URL, "/", -1, 1) | |
177 strlength = Len(URL) | |
178 filename=Right(URL,strlength-StartPos) | |
179 If Right(DestFolder, 1) <> "\" Then DestFolder = DestFolder & "\" End If | |
180 | |
181 Wscript.echo("Downloading: " & URL) | |
182 xml.Open "GET", URL, False | |
183 xml.Send | |
184 | |
185 const ForReading = 1 , ForWriting = 2 , ForAppending = 8 | |
186 Set MyFile = fso.OpenTextFile(DestFolder & filename ,ForWriting, True) | |
187 For i = 1 to lenb(xml.responseBody) | |
188 MyFile.write Chr(Ascb(midb(xml.responseBody,i,1))) | |
189 Next | |
190 MyFile.Close() | |
191 | |
192 End Sub | |
193 | |
194 Function Showpath(folderspec) | |
195 Set f = FSO.GetFolder(folderspec) | |
196 showpath = f.path & "\" | |
197 End Function | |
198 | |
199 |