author | Periklis Ntanasis <pntanasis@gmail.com> |
Fri, 12 Jul 2013 12:00:30 +0300 | |
branch | spacecampaign |
changeset 9334 | 4bf3edc24444 |
parent 9069 | 24a2da6e5a22 |
child 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
7810 | 1 |
' w32DownloadUnzip.vbs |
2 |
' Download a zipfile and uncompress it with no external tools in Windows |
|
3 |
' |
|
4 |
' Copyright (c) 2012, Vittorio Giovara, <vittorio.giovara@gmail.com> |
|
5 |
' Redistribution and use is allowed according to the terms of the BSD license. |
|
6 |
' |
|
7 |
' References |
|
8 |
' http://superuser.com/questions/59465/is-it-possible-to-download-using-the-windows-command-line |
|
9 |
' http://stackoverflow.com/questions/1021557/how-to-unzip-a-file-using-the-command-line |
|
9069
24a2da6e5a22
windows build script, get the temp variable from environment, avoiding potential permission problems
koda
parents:
7813
diff
changeset
|
10 |
' http://stackoverflow.com/questions/424331/get-the-current-temporary-directory-path-in-vbscript |
7810 | 11 |
|
12 |
Set ArgObj = WScript.Arguments |
|
13 |
||
14 |
If (Wscript.Arguments.Count = 1) Then |
|
15 |
strFileURL = ArgObj(0) |
|
16 |
strOutputPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") |
|
17 |
Else |
|
18 |
If (Wscript.Arguments.Count = 2) Then |
|
19 |
strFileURL = ArgObj(0) |
|
20 |
strOutputPath = ArgObj(1) |
|
21 |
Else |
|
22 |
WScript.Echo ("Usage: csript.exe w32DownloadUnzip.vbs url output") |
|
23 |
WScript.Quit |
|
24 |
End if |
|
25 |
End if |
|
26 |
||
9069
24a2da6e5a22
windows build script, get the temp variable from environment, avoiding potential permission problems
koda
parents:
7813
diff
changeset
|
27 |
' Temporary directory |
24a2da6e5a22
windows build script, get the temp variable from environment, avoiding potential permission problems
koda
parents:
7813
diff
changeset
|
28 |
strHDLocation = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2) + "\hwlibtemp.zip" |
7810 | 29 |
|
30 |
' Fetch the file |
|
7813
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
7810
diff
changeset
|
31 |
WScript.Echo ( "Trying to download from " & strFileURL) |
7810 | 32 |
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") |
33 |
objXMLHTTP.open "GET", strFileURL, false |
|
34 |
objXMLHTTP.send() |
|
35 |
||
36 |
If objXMLHTTP.Status = 200 Then |
|
37 |
Set objADOStream = CreateObject("ADODB.Stream") |
|
38 |
objADOStream.Open |
|
39 |
objADOStream.Type = 1 'adTypeBinary |
|
40 |
||
41 |
objADOStream.Write objXMLHTTP.ResponseBody |
|
9069
24a2da6e5a22
windows build script, get the temp variable from environment, avoiding potential permission problems
koda
parents:
7813
diff
changeset
|
42 |
objADOStream.Position = 0 'Set the stream position to the start |
7810 | 43 |
|
44 |
Set objFSO = Createobject("Scripting.FileSystemObject") |
|
45 |
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation |
|
46 |
Set objFSO = Nothing |
|
47 |
||
48 |
objADOStream.SaveToFile strHDLocation |
|
49 |
objADOStream.Close |
|
50 |
Set objADOStream = Nothing |
|
9069
24a2da6e5a22
windows build script, get the temp variable from environment, avoiding potential permission problems
koda
parents:
7813
diff
changeset
|
51 |
Set objXMLHTTP = Nothing |
7810 | 52 |
Else |
53 |
WScript.Echo ("Error downloading file (error code: " & objXMLHTTP.Status & ")") |
|
54 |
Set objXMLHTTP = Nothing |
|
55 |
WScript.Quit |
|
56 |
End if |
|
57 |
||
58 |
WScript.Echo ( "Extracting file to " & strOutputPath) |
|
59 |
Set objShell = CreateObject( "Shell.Application" ) |
|
60 |
Set objSource = objShell.NameSpace(strHDLocation).Items() |
|
61 |
Set objTarget = objShell.NameSpace(strOutputPath) |
|
62 |
intOptions = 16 'no user prompt |
|
63 |
objTarget.CopyHere objSource, intOptions |
|
64 |
||
7813
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
7810
diff
changeset
|
65 |
WScript.Echo ( "Success!" ) |
7810 | 66 |
Set objShell = Nothing |