THUNDERGROOVE

Untitled

Mar 14th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. -- Script updater by THUNDERGROOVE
  2.  
  3. args = {...}
  4.  
  5. local updateAll = false
  6.  
  7. if args[1] == "--all" then
  8. updateAll = true
  9. end
  10.  
  11. local baseLink = "http://dl.dropbox.com/u/51472257/code/ComputerCraft%20scripts/updater/"
  12.  
  13. if not http then print("HTTP is not enabled") os.shutdown() end
  14.  
  15. function updateScript(n)
  16. if n == "Exit Updater" then
  17. print("")
  18. else
  19. local response = http.get(baseLink..s[n])
  20.  
  21. if response then
  22. print("Huzzaaa we got the script")
  23. else
  24. print("You broke it.... shutting down")
  25. os.shutdown()
  26. end
  27.  
  28. local script = response.readAll()
  29. response.close()
  30.  
  31. local file = fs.open(s[n], "w")
  32. file.write(script)
  33. file.close()
  34. print("script updated")
  35. end
  36. end
  37. function menu(m)
  38. n=1
  39. l=#m
  40. while true do
  41. term.clear()
  42. term.setCursorPos(1,2)
  43. for i=1, l, 1 do
  44. if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
  45. end
  46. print("Select script to update.")
  47. a, b= os.pullEventRaw()
  48. if a == "key" then
  49. if b==200 and n>1 then n=n-1 end
  50. if b==208 and n<=l then n=n+1 end
  51. if b==28 then break end
  52. end
  53. end
  54. term.clear() term.setCursorPos(1,1)
  55. return n
  56. end
  57.  
  58.  
  59. print("Grabbing list of scripts...")
  60. local response = http.get(baseLink.."scripts")
  61.  
  62. if response then
  63. print("Huzzaaa we got the scripts list")
  64. else
  65. print("You broke it.... shutting down")
  66. os.shutdown()
  67. end
  68.  
  69. local scripts = response.readAll()
  70. response.close()
  71.  
  72. local file = fs.open("scripts", "w")
  73. file.write(scripts)
  74. file.close()
  75.  
  76. shell.run("scripts")
  77. if updateAll == false then
  78. option = menu(s)
  79. if option == #s then
  80. error()
  81. else
  82. updateScript(option)
  83. end
  84. else
  85. for k,v in pairs(s) do
  86. updateScripts(v)
  87. end
  88. end
Advertisement
Add Comment
Please, Sign In to add comment