Advertisement
B00MSPL4T

Reactor/Turbine Control

May 4th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.89 KB | None | 0 0
  1. -----BigReactor Control Installer
  2. -----feel free to use and/or modify this code
  3. -----------------------------------------------
  4.  
  5.  
  6. --Run this program to install or update either reactor or turbine control programs.
  7.  
  8.  
  9. -----------------PASTEBINs--------------------------
  10. installer = "EmptETTT"
  11. reactor_control_pastebin = "RCPEHmxs"
  12. turbine_control_pastebin = "5B8h94V4"
  13.  
  14. reactor_startup = "cZUH7y6k"
  15. turbine_startup = "h0jmye6t"
  16.  
  17. reactor_update_check = "MkF2QQjH"
  18. turbine_update_check = "QP3qrzNu"
  19.  
  20. dev_installer = "mCPQQ3Ge"
  21. dev_reactor_control_pastebin = "eYwBw9a3"
  22. dev_turbine_control_pastebin = "kJHeCx0Q"
  23. ---------------------------------------------
  24.  
  25. local reactor
  26. local turbine
  27. term.clear()
  28. -------------------FORMATTING-------------------------------
  29.  
  30. function draw_text_term(x, y, text, text_color, bg_color)
  31. term.setTextColor(text_color)
  32. term.setBackgroundColor(bg_color)
  33. term.setCursorPos(x,y)
  34. write(text)
  35. end
  36.  
  37. function draw_line_term(x, y, length, color)
  38. term.setBackgroundColor(color)
  39. term.setCursorPos(x,y)
  40. term.write(string.rep(" ", length))
  41. end
  42.  
  43. function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
  44. draw_line_term(x, y, length, bg_color) --backgoround bar
  45. local barSize = math.floor((minVal/maxVal) * length)
  46. draw_line_term(x, y, barSize, bar_color) --progress so far
  47. end
  48.  
  49. function menu_bars()
  50.  
  51. draw_line_term(1, 1, 55, colors.blue)
  52. draw_text_term(10, 1, "BigReactors Control Installer", colors.white, colors.blue)
  53.  
  54. draw_line_term(1, 19, 55, colors.blue)
  55. draw_text_term(10, 19, "by NJR aka B00MSPL4T", colors.white, colors.blue)
  56. end
  57.  
  58. --------------------------------------------------------------
  59.  
  60.  
  61.  
  62. function install(program, pastebin)
  63. term.clear()
  64. menu_bars()
  65.  
  66. draw_text_term(1, 3, "Installing "..program.."...", colors.yellow, colors.black)
  67. term.setCursorPos(1,5)
  68. term.setTextColor(colors.white)
  69. sleep(0.5)
  70.  
  71. -----------------Install control program---------------
  72.  
  73.  
  74. --delete any old backups
  75. if fs.exists(program.."_old") then
  76. fs.delete(program.."_old")
  77. end
  78.  
  79. --remove old configs
  80. if fs.exists("config.txt") then
  81. fs.delete("config.txt")
  82. end
  83.  
  84. --backup current program
  85. if fs.exists(program) then
  86. fs.copy(program, program.."_old")
  87. fs.delete(program)
  88. end
  89.  
  90. --remove program and fetch new copy
  91.  
  92. shell.run("pastebin get "..pastebin.." "..program)
  93.  
  94. sleep(0.5)
  95.  
  96. ------------------Install startup script-------------
  97.  
  98. term.setCursorPos(1,8)
  99.  
  100. --delete any old backups
  101. if fs.exists("startup_old") then
  102. fs.delete("startup_old")
  103. end
  104.  
  105. --backup current program
  106. if fs.exists("startup") then
  107. fs.copy("startup", "startup_old")
  108. fs.delete("startup")
  109. end
  110.  
  111.  
  112. if program == "reactor_control" then
  113. shell.run("pastebin get "..reactor_startup.." startup")
  114. else if program == "turbine_control" then
  115. shell.run("pastebin get "..turbine_startup.." startup")
  116. end
  117. end
  118.  
  119. if fs.exists(program) then
  120. draw_text_term(1, 11, "Success!", colors.lime, colors.black)
  121. draw_text_term(1, 12, "Press Enter to reboot...", colors.gray, colors.black)
  122. wait = read()
  123. shell.run("reboot")
  124. else
  125. draw_text_term(1, 11, "Error installing file.", colors.red, colors.black)
  126. sleep(0.1)
  127. draw_text_term(1, 12, "Restoring old file...", colors.gray, colors.black)
  128. sleep(0.1)
  129. fs.copy(program.."_old", program)
  130. fs.delete(program.."_old")
  131.  
  132. draw_text_term(1, 14, "Press Enter to continue...", colors.gray, colors.black)
  133. wait = read()
  134. start()
  135. end
  136. end
  137.  
  138. -- peripheral searching thanks to /u/kla_sch
  139. -- http://pastebin.com/gTEBHv3D
  140. function reactorSearch()
  141. local names = peripheral.getNames()
  142. local i, name
  143. for i, name in pairs(names) do
  144. if peripheral.getType(name) == "BigReactors-Reactor" then
  145. return peripheral.wrap(name)
  146. else
  147. --return null
  148. end
  149. end
  150. end
  151.  
  152. function turbineSearch()
  153. local names = peripheral.getNames()
  154. local i, name
  155. for i, name in pairs(names) do
  156. if peripheral.getType(name) == "BigReactors-Turbine" then
  157. return peripheral.wrap(name)
  158. else
  159. --return null
  160. end
  161. end
  162. end
  163.  
  164. function selectProgram()
  165. term.clear()
  166. menu_bars()
  167. draw_text_term(1, 4, "What would you like to install or update?", colors.yellow, colors.black)
  168. draw_text_term(3, 6, "1 - Reactor Control", colors.white, colors.black)
  169. draw_text_term(3, 7, "2 - Turbine Control", colors.white, colors.black)
  170. draw_text_term(1, 9, "Enter 1 or 2:", colors.yellow, colors.black)
  171.  
  172. term.setCursorPos(1,10)
  173. term.setTextColor(colors.white)
  174. input = read()
  175.  
  176. if input == "1" then
  177. install("reactor_control", reactor_control_pastebin)
  178. else if input == "2" then
  179. install("turbine_control", turbine_control_pastebin)
  180. else if input == "dev1" then
  181. install("reactor_control", dev_reactor_control_pastebin)
  182. else if input == "dev2" then
  183. install("turbine_control", dev_turbine_control_pastebin)
  184. else
  185. draw_text_term(1, 12, "please enter a '1' or '2'.", colors.red, colors.black)
  186. sleep(1)
  187. start()
  188. end
  189. end
  190. end
  191. end
  192. end
  193.  
  194. function start()
  195. term.clear()
  196. menu_bars()
  197.  
  198. if fs.exists("config.txt") then
  199.  
  200. if fs.exists("reactor_control") then
  201. draw_text_term(2, 3, "Current Program:", colors.white, colors.black)
  202. draw_text_term(2, 4, "Reactor Control", colors.lime, colors.black)
  203. draw_text_term(1, 6, "Do you want to update this program? (y/n)", colors.white, colors.black)
  204. draw_text_term(1, 7, "This will delete the current program and any saved settings", colors.gray, colors.black)
  205. term.setCursorPos(1,9)
  206. term.setTextColor(colors.white)
  207. input = read()
  208. if input == "y" then
  209. install("reactor_control", reactor_control_pastebin)
  210. else if input == "n" then
  211. selectProgram()
  212. else
  213. draw_text_term(1, 10, "please enter 'y' or 'n'.", colors.red, colors.black)
  214. sleep(1)
  215. start()
  216. end
  217. end
  218.  
  219. else if fs.exists("turbine_control") then
  220. draw_text_term(2, 3, "Current Program:", colors.white, colors.black)
  221. draw_text_term(2, 4, "Turbine Control", colors.lime, colors.black)
  222. draw_text_term(1, 6, "Do you want to update this program? (y/n)", colors.white, colors.black)
  223. draw_text_term(1, 7, "This will delete the current program and any saved settings", colors.gray, colors.black)
  224. term.setCursorPos(1,9)
  225. term.setTextColor(colors.white)
  226. input = read()
  227. if input == "y" then
  228. install("turbine_control", turbine_control_pastebin)
  229. else if input == "n" then
  230. selectProgram()
  231. else
  232. draw_text_term(1, 10, "please enter 'y' or 'n'.", colors.red, colors.black)
  233. sleep(1)
  234. start()
  235. end
  236. end
  237.  
  238. end
  239. end
  240. end
  241.  
  242. selectProgram()
  243.  
  244.  
  245. end
  246.  
  247. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement