Advertisement
Aidan428

ReactorController

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