SoulofSorrow

SoulofSorrow Reactor Installer + Capacitor bank 1.7.10

Jun 4th, 2015
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.85 KB | None | 0 0
  1. -----BigReactor Control Installer
  2. -----by jaranvil aka jared314
  3.  
  4. -----feel free to use and/or modify this code
  5. -----------------------------------------------
  6.  
  7.  
  8. --Run this program to install or update either reactor or turbine control programs.
  9.  
  10.  
  11. -----------------PASTEBINs--------------------------
  12. installer = "DR9Caqc2"
  13. reactor_control_pastebin = "2KMD9qkj"
  14. reactor_control_plus_pastebin = "ud3rKwmZ"
  15. reactor_control_plus2_pastebin = "aaGuHDXY"
  16. turbine_control_pastebin = "0BgkjFdX"
  17.  
  18. reactor_startup = "AL8yGDAs"
  19. turbine_startup = "WGbnmxHx"
  20.  
  21. reactor_update_check = "FJn4fUqD"
  22. turbine_update_check = "3b02GuZf"
  23.  
  24. dev_installer = "EvF39HUJ"
  25. dev_reactor_control_pastebin = "xiEVEV9K"
  26. dev_turbine_control_pastebin = "ZJP4PNN3"
  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 & IDT", 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.setBackgroundColor(colors.black)
  170.   term.clear()
  171.   menu_bars()
  172.   draw_text_term(1, 4, "What would you like to install or update?", colors.yellow, colors.black)
  173.   draw_text_term(3, 6, "1 - Reactor Control", colors.white, colors.black)
  174.   draw_text_term(3, 7, "2 - Turbine Control", colors.white, colors.black)
  175.   draw_text_term(3, 8, "3 - Reactor Control Bank (Direwolf20 1.7.10)", colors.white, colors.black)
  176.   draw_text_term(3, 9, "4 - Reactor Control Bank (Space Astronomy 1.7.10)", colors.white, colors.black)
  177.   draw_text_term(1, 10, "Enter 1, 2 or 3:", colors.yellow, colors.black)
  178.  
  179.   term.setCursorPos(1,11)
  180.   term.setTextColor(colors.white)
  181.   input = read()
  182.  
  183.   if input == "1" then
  184.     install("reactor_control", reactor_control_pastebin)
  185.   else if input == "2" then
  186.     install("turbine_control", turbine_control_pastebin)
  187.   else if input == "3" then
  188.     install("reactor_control", reactor_control_plus_pastebin)
  189.   else if input == "4" then
  190.     install("reactor_control", reactor_control_plus2_pastebin)
  191.   else if input == "dev1" then
  192.     install("reactor_control", dev_reactor_control_pastebin)
  193.   else if input == "dev2" then
  194.     install("turbine_control", dev_turbine_control_pastebin)
  195.   else
  196.     draw_text_term(1, 12, "please enter a '1', '2' or '3'.", colors.red, colors.black)
  197.     sleep(1)
  198.     start()
  199.   end
  200.   end
  201.   end
  202.   end
  203.   end
  204.   end
  205. end
  206.  
  207. function start()
  208.   term.clear()
  209.   menu_bars()
  210.  
  211.   selectProgram()
  212.  
  213.  
  214. end
  215.  
  216. start()
Add Comment
Please, Sign In to add comment