Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.83 KB | None | 0 0
  1. forceCScriptExecution
  2.  
  3. dim steampath
  4. dim steampaths(20)
  5. steampath = readfromRegistry("HKEY_CURRENT_USER\Software\Valve\Steam\SteamPath", "")
  6.  
  7. dim oShell, appDataLocation
  8. Set oShell = CreateObject( "WScript.Shell" )
  9. appDataLocation=oShell.ExpandEnvironmentStrings("%APPDATA%")
  10.  
  11. dim count
  12. count = 0
  13. steampaths(count) = steampath
  14. count = count + 1
  15.  
  16. if steampath = "" then
  17. wscript.echo "Failed to find the steam directory. If you're sure steam is installed, follow the manual installation."
  18. GoSleep(3)
  19. wscript.quit(1)
  20. end if
  21.  
  22. 'dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
  23. dim xHttp: Set xHttp = createobject("MSXML2.ServerXMLHTTP.6.0")
  24. dim bStrm: Set bStrm = createobject("Adodb.Stream")
  25. xHttp.Open "GET", "http://getdotastats.com/d2mods/api/lobby_version.txt", False
  26. 'xHttp.Open "GET", "https://github.com/GetDotaStats/GetDotaLobby/raw/master/version.txt", False
  27. xHttp.Send
  28.  
  29. dim latestVer, currentVer
  30. latestVer = CDbl(xHttp.responseText)
  31. currentVer = 0.00
  32.  
  33. dim verFile
  34. Set objFSO = CreateObject("Scripting.FileSystemObject")
  35. If (objFSO.FileExists(appDataLocation & "\version.txt")) Then
  36. Set verFile = objFSO.OpenTextFile(appDataLocation & "\version.txt",1)
  37. currentVer = CDbl(verFile.ReadAll())
  38. verFile.Close
  39. Set verFile = Nothing
  40. End If
  41.  
  42. Wscript.echo "Latest Version: " & latestVer & " -- Current Version: " & currentVer
  43.  
  44. If (currentVer >= latestVer) Then
  45. Wscript.echo "Your Lobby Explorer is up to date. No update will be performed"
  46. GoSleep(2)
  47. Wscript.quit(0)
  48. End If
  49.  
  50. Wscript.echo "Your Lobby Explorer is not up to date. Downloading new version. Please wait."
  51. Set xHttp = createobject("MSXML2.ServerXMLHTTP.6.0")
  52. Set bStrm = createobject("Adodb.Stream")
  53. 'xHttp.Open "GET", "https://github.com/GetDotaStats/GetDotaLobby/raw/lobbybrowser/play_weekend_tourney.zip", False
  54. xHttp.Open "GET", "https://github.com/GetDotaStats/GetDotaLobby/raw/master/play_weekend_tourney.zip", False
  55. xHttp.Send
  56.  
  57. with bStrm
  58. .type = 1 '//binary
  59. .open
  60. .write xHttp.responseBody
  61. .savetofile appDataLocation & "\lx.zip", 2 '//overwrite
  62. end with
  63.  
  64. Wscript.echo "Download complete. Finding your steam directory paths."
  65.  
  66. Set objFile = objFSO.OpenTextFile(steampath & "\config\config.vdf", 1)
  67.  
  68. dim line
  69. Set myRegExp = New RegExp
  70. myRegExp.IgnoreCase = True
  71. myRegExp.Global = True
  72. myRegExp.Pattern = """BaseInstallFolder_.+""[^""]+""(.*)"""
  73.  
  74. i = 0
  75. Do Until objFile.AtEndOfStream
  76. line = objFile.ReadLine
  77. if InStr(line, """BaseInstallFolder_") <> 0 then
  78. Set mc = myRegExp.Execute(line)
  79. if mc.Count = 0 then
  80. wscript.echo "Couldn't find steam base install path in config.vdf"
  81. else
  82.  
  83. Set match = mc.Item(0)
  84.  
  85. steampaths(count) = match.SubMatches.Item(0)
  86. count = count + 1
  87. end if
  88. end if
  89. i = i + 1
  90. Loop
  91. objFile.Close
  92.  
  93. dim found
  94. found = False
  95.  
  96. Wscript.echo "INSTALLING LOBBY EXPLORER"
  97. For each path In steampaths
  98. if path <> "" then
  99. if objFSO.FolderExists(path & "\steamapps\common\dota 2 beta\") then
  100. found = True
  101. Wscript.echo "Installing in path: " & path & "\steamapps\common\dota 2 beta\resource\flash3"
  102.  
  103. Dim objShell
  104. Set objShell = WScript.CreateObject ("WScript.shell")
  105. objShell.run "cmd /c mkdir """ & path & "\steamapps\common\dota 2 beta\dota\resource\flash3""", 7, true
  106. 'objShell.run "xcopy resource """ & path & "\steamapps\common\dota 2 beta\dota\resource""" & " /Y /E ", 7, true
  107. Set objShell = Nothing
  108.  
  109. UnzipFiles objFSO.GetAbsolutePathName(path & "\steamapps\common\dota 2 beta\dota\resource\flash3"), objFSO.GetAbsolutePathName(appDataLocation & "\lx.zip")
  110. end if
  111. end if
  112. Next
  113.  
  114. if found then
  115. Wscript.echo "DONE INSTALLING"
  116. else
  117. Wscript.echo "Unable to find dota directory. Installation failed."
  118. GoSleep(3)
  119. wscript.quit(0)
  120. end if
  121.  
  122. ' Write out the version.txt since the update suceeded
  123. Set verFile = objFSO.OpenTextFile(appDataLocation & "\version.txt",2,true)
  124. verFile.WriteLine(latestVer)
  125. verFile.Close
  126. Set verFile = Nothing
  127.  
  128. GoSleep(2)
  129.  
  130. wscript.quit(0)
  131.  
  132.  
  133. Function GoSleep(seconds)
  134.  
  135. wsv = WScript.Version
  136.  
  137. if wsv >= "5.1" then
  138. WScript.Sleep(seconds * 1000)
  139. else
  140.  
  141. startTime = Time() ' gets the current time
  142. endTime = TimeValue(startTime) + TimeValue(elapsed) ' calculates when time is up
  143.  
  144. While endTime > Time()
  145.  
  146. DoEvents
  147. Wend
  148. end if
  149. End Function
  150.  
  151. Sub forceCScriptExecution
  152. Dim Arg, Str
  153. If Not LCase( Right( WScript.FullName, 12 ) ) = "\cscript.exe" Then
  154. For Each Arg In WScript.Arguments
  155. If InStr( Arg, " " ) Then Arg = """" & Arg & """"
  156. Str = Str & " " & Arg
  157. Next
  158. CreateObject( "WScript.Shell" ).Run _
  159. "cscript //nologo """ & _
  160. WScript.ScriptFullName & _
  161. """ " & Str
  162. WScript.Quit
  163. End If
  164. End Sub
  165.  
  166. function readFromRegistry (strRegistryKey, strDefault )
  167. Dim WSHShell, value
  168.  
  169. On Error Resume Next
  170. Set WSHShell = CreateObject("WScript.Shell")
  171. value = WSHShell.RegRead( strRegistryKey )
  172.  
  173. if err.number <> 0 then
  174. readFromRegistry= strDefault
  175. else
  176. readFromRegistry=value
  177. end if
  178.  
  179. set WSHShell = nothing
  180. end function
  181.  
  182. '========================
  183. 'Sub: UnzipFiles
  184. 'Language: vbscript
  185. 'Usage: UnzipFiles("C:\dir", "extract.zip")
  186. 'Definition: UnzipFiles([Directory where zip is located & where files will be extracted], [zip file name])
  187. '========================
  188. Sub UnzipFiles(folder, file)
  189. Dim sa, filesInzip, zfile, fso, i : i = 1
  190. Set sa = CreateObject("Shell.Application")
  191. Set fso = CreateObject("Scripting.FileSystemObject")
  192. 'WScript.echo folder
  193. 'WScript.echo file
  194. Set filesInzip=sa.NameSpace(file).Items()
  195. For Each zfile In filesInzip
  196. If Not fso.FileExists(folder & zfile) Then
  197. sa.NameSpace(folder).CopyHere zfile, 20
  198. i = i + 1
  199. End If
  200. If i = 99 Then
  201. zCleanup file, i
  202. i = 1
  203. End If
  204. Next
  205. If i > 1 Then
  206. zCleanup file, i
  207. End If
  208. 'fso.DeleteFile(folder&file)
  209. End Sub
  210.  
  211. '========================
  212. 'Sub: zCleanup
  213. 'Language: vbscript
  214. 'Usage: zCleanup("filename.zip", 4)
  215. 'Definition: zCleanup([Filename of Zip previously extracted], [Number of files within zip container])
  216. '========================
  217. Sub zCleanUp(file, count)
  218. 'Clean up
  219. Dim i, fso
  220. Set fso = CreateObject("Scripting.FileSystemObject")
  221. For i = 1 To count
  222. If fso.FolderExists(fso.GetSpecialFolder(2) & "\Temporary Directory " & i & " for " & file) = True Then
  223. text = fso.DeleteFolder(fso.GetSpecialFolder(2) & "\Temporary Directory " & i & " for " & file, True)
  224. Else
  225. Exit For
  226. End If
  227. Next
  228. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement