Advertisement
bob558

Big Reactors Controller

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