Advertisement
Guest User

Untitled

a guest
Mar 25th, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 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/<Your public Dropbox folder>"
  12.  
  13. if not http then print("HTTP is not enabled") os.shutdown() end
  14. screenX, screenY = term.getSize()
  15.  
  16. function wrap(str, limit, indent, indent1)
  17.  
  18. indent = indent or ""
  19. indent1 = indent1 or indent
  20. limit = limit or 72
  21. local here = 1-#indent1
  22. return indent1..str:gsub("(%s+)()(%S+)()",
  23. function(sp, st, word, fi)
  24. if fi-here > limit then
  25. here = st - #indent
  26. return "\n"..indent..word
  27. end
  28. end)
  29. end
  30. function updateScript(n)
  31. if n == "Exit" then
  32. print("")
  33. else
  34. print(s[n])
  35. local response = http.get(baseLink..s[n])
  36.  
  37. if response then
  38. print("Huzzaaa we got the script")
  39. else
  40. print("You broke it.... shutting down")
  41. os.shutdown()
  42. end
  43.  
  44. local script = response.readAll()
  45. response.close()
  46.  
  47. local file = fs.open(s[n], "w")
  48. file.write(script)
  49. file.close()
  50. print("script updated")
  51. end
  52. end
  53. function menu(m)
  54. n=1
  55. l=#m
  56. while true do
  57. term.clear()
  58. term.setCursorPos(1,1)
  59. if term.isColor() == true then
  60. term.setTextColor(colors.cyan)
  61. term.write("###################################################")
  62. term.setCursorPos(1,2)
  63. term.write("# ")
  64. term.setTextColor(colors.blue)
  65. term.write("THUNDERGROOVE's Script updater")
  66. term.setTextColor(colors.cyan)
  67. term.write(" #")
  68. term.setCursorPos(1,3)
  69. term.setTextColor(colors.cyan)
  70. term.write("###################################################")
  71. else
  72. print("#######################################")
  73. print("# THUNDERGROOVE's Script updater #")
  74. print("#######################################")
  75. end
  76. -- Get longest key
  77. local longestLen = 0
  78. for i=1, l do
  79. if #m[i] > longestLen then longestLen = #m[i] end
  80. end
  81. for i=1, l do
  82. if i==n then
  83. spaceCount = #m[i] - longestLen
  84. if spaceCount < 0 then spaceCount = -(spaceCount) end
  85. printStr = i.." [ "..m[i]
  86. for k = 1,spaceCount do
  87. printStr = printStr.." "
  88. end
  89. printStr = printStr.." ]"
  90. oldX, oldY = term.getCursorPos()
  91. term.setTextColor(colors.cyan)
  92. term.setCursorPos(1, 17)
  93. print(wrap(d[i],45,"",""))
  94. term.setCursorPos(oldX,oldY)
  95. term.setTextColor(colors.blue)
  96. else
  97. printStr = i.." "..m[i]
  98. end
  99. if term.isColor() == true then term.setTextColor(colors.lightBlue) end
  100.  
  101. print(printStr)
  102. end
  103. if term.isColor() == true then term.setTextColor(colors.yellow) end
  104. print("Select script to update.")
  105. -- print("LongestStr:"..LongestStr)
  106. -- print("longestLen:"..spaceCount)
  107. a, b= os.pullEventRaw()
  108. if a == "key" then
  109. if b==200 and n>1 then n=n-1 end
  110. if b==208 and n<l then n=n+1 end
  111. if b==28 then break end
  112. end
  113. end
  114. term.clear() term.setCursorPos(1,1)
  115. return n
  116. end
  117.  
  118.  
  119. print("Grabbing list of scripts...")
  120. local response = http.get(baseLink.."scripts")
  121.  
  122. if response then
  123. print("Huzzaaa we got the scripts list")
  124. else
  125. print("You broke it.... shutting down")
  126. os.shutdown()
  127. end
  128.  
  129. local scripts = response.readAll()
  130. response.close()
  131.  
  132. local file = fs.open("scripts", "w")
  133. file.write(scripts)
  134. file.close()
  135.  
  136. shell.run("scripts")
  137.  
  138. option = menu(n)
  139. if option == #s then
  140. error()
  141. else
  142. updateScript(option)
  143. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement