MarcosKoco

TRC_OS_Installer

Jun 5th, 2021 (edited)
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.26 KB | None | 0 0
  1. local System = os -- Used for System things like os.time() to System.time()
  2. local Screen = term -- Used for Screen thing on the turtle or computer like term.clear() to Screen.clear()
  3. local Per = peripheral -- Used shortcut for peripheral
  4. local Text = textutils -- Used shortcut for textilils
  5. local Pack = Text.serialize -- Makes a new command for packing ( shortcut used from local Text)
  6. local UnPack = Text.unserialize -- Makes a new command for unpacking ( shortcut used from local Text)
  7.  
  8. local Disk = "/disk"
  9.  
  10. if pocket then
  11.    
  12.     Disk = ""
  13.    
  14. end
  15.  
  16. local file = fs.exists(Disk.."/API/Logo.lua")
  17. local file0 = fs.exists(Disk.."/API/Functions.lua")
  18.  
  19. local Monitor = {}
  20. Monitor[0] = Screen
  21.  
  22. if not(file) then
  23.  
  24.     shell.run("pastebin get s3aBGUVr "..Disk.."/API/Logo.lua")
  25.    
  26.     Monitor[0].clear()
  27.     Monitor[0].setCursorPos(1,1)
  28.    
  29. end
  30.  
  31. if not(file0) then
  32.    
  33.     shell.run("pastebin get sujHjqXC "..Disk.."/API/Functions.lua")
  34.    
  35.     Monitor[0].clear()
  36.     Monitor[0].setCursorPos(1,1)
  37.    
  38. end
  39.  
  40. System.loadAPI(Disk.."/API/Logo.lua")
  41. System.loadAPI(Disk.."/API/Functions.lua")
  42.  
  43. local w, h = Monitor[0].getSize()
  44.  
  45. Monitor[0].clear()
  46.  
  47. Logo.drawLogo(Monitor[0], "Head", math.floor(w/2)-6, math.floor(h/2)-4)
  48.  
  49. local W_Modem = Functions.FindWirelessModem()
  50.  
  51. sleep(1)
  52.  
  53. Monitor = Functions.FindMonitor()
  54.  
  55. local Status = true
  56.  
  57. function Startup()
  58.    
  59.     sleep(1)
  60.    
  61.     Monitor[0].clear()
  62.     Monitor[0].setCursorPos(1, 1)
  63.    
  64.     Logo.drawLogo(Monitor[0], "Sub", 1, 1)
  65.    
  66.     Functions.printCentered(Monitor[0], 6,"Welcome to Turtle Remote Control (TRC) installer.")
  67.     Functions.printCentered(Monitor[0], 8,"Press a key to continue or Q to quit.")
  68.    
  69.     local Event, p1, p2, p3 = System.pullEvent("key")
  70.    
  71.     Monitor[0].clear()
  72.     Monitor[0].setCursorPos(1, 1)
  73.    
  74.     if p1 == keys.q then
  75.         error()
  76.     end
  77.    
  78. end
  79.  
  80. Startup()
  81.  
  82. local NameLen = 17
  83. local nOption = 1
  84. local MaxOptions
  85.  
  86. if turtle or pocket then
  87.    
  88.     MaxOptions = 2
  89.    
  90. else
  91.    
  92.     MaxOptions = 4
  93.    
  94. end
  95.  
  96. function drawMenu()
  97.    
  98.     Monitor[0].clear()
  99.     Monitor[0].setCursorPos(1, 1)
  100.     Monitor[0].write("Setup Menu")
  101.    
  102.     Monitor[0].setCursorPos(w-(NameLen+3), 1)
  103.    
  104.     if turtle then
  105.        
  106.         if nOption == 1 then
  107.        
  108.             Monitor[0].write("Setup TRC Turtle OS")
  109.            
  110.         elseif nOption == 2 then
  111.            
  112.             Monitor[0].write("Cancel")
  113.            
  114.         end
  115.        
  116.     elseif pocket then
  117.        
  118.         if nOption == 1 then
  119.            
  120.             Monitor[0].write("Setup TRC Computer OS")
  121.            
  122.         elseif nOption == 2 then
  123.            
  124.             Monitor[0].write("Cancel")
  125.            
  126.         end
  127.        
  128.     else
  129.        
  130.         if nOption == 1 then
  131.            
  132.             Monitor[0].write("Setup TRC Server OS")
  133.            
  134.         elseif nOption == 2 then
  135.            
  136.             Monitor[0].write("Setup TRC Computer OS")
  137.            
  138.         elseif nOption == 3 then
  139.            
  140.             Monitor[0].write("Setup GPS Computer")
  141.            
  142.         elseif nOption == 4 then
  143.            
  144.             Monitor[0].write("Cancel")
  145.            
  146.         end
  147.        
  148.     end
  149.    
  150. end
  151.  
  152. function drawFrontend()
  153.    
  154.     Functions.printCentered(Monitor[0], math.floor(h/2) -3, "")
  155.     Functions.printCentered(Monitor[0], math.floor(h/2) -2, Functions.PadString("  Setup Menu",NameLen))
  156.     Functions.printCentered(Monitor[0], math.floor(h/2) -1, "")
  157.    
  158.     if turtle then
  159.        
  160.         Functions.printCentered(Monitor[0], math.floor(h/2) +0, ((nOption == 1) and string.format("%s%s",Functions.PadString("[ Turtle OS",NameLen-1),"]") or Functions.PadString("  Turtle OS",NameLen)))
  161.         Functions.printCentered(Monitor[0], math.floor(h/2) +1, ((nOption == 2) and string.format("%s%s",Functions.PadString("[ Cancel",NameLen-1),"]") or Functions.PadString("  Cancel",NameLen)))
  162.        
  163.     elseif pocket then
  164.        
  165.         Functions.printCentered(Monitor[0], math.floor(h/2) +0, ((nOption == 1) and string.format("%s%s",Functions.PadString("[ Computer OS",NameLen-1),"]") or Functions.PadString("  Computer OS",NameLen)))
  166.         Functions.printCentered(Monitor[0], math.floor(h/2) +1, ((nOption == 2) and string.format("%s%s",Functions.PadString("[ Cancel",NameLen-1),"]") or Functions.PadString("  Cancel",NameLen)))
  167.        
  168.     else
  169.        
  170.         Functions.printCentered(Monitor[0], math.floor(h/2) +0, ((nOption == 1) and string.format("%s%s",Functions.PadString("[ Server OS",NameLen-1),"]") or Functions.PadString("  Server OS",NameLen)))
  171.         Functions.printCentered(Monitor[0], math.floor(h/2) +1, ((nOption == 2) and string.format("%s%s",Functions.PadString("[ Computer OS",NameLen-1),"]") or Functions.PadString("  Computer OS",NameLen)))
  172.         Functions.printCentered(Monitor[0], math.floor(h/2) +2, ((nOption == 3) and string.format("%s%s",Functions.PadString("[ GPS OS",NameLen-1),"]") or Functions.PadString("  GPS OS",NameLen)))
  173.         Functions.printCentered(Monitor[0], math.floor(h/2) +3, ((nOption == 4) and string.format("%s%s",Functions.PadString("[ Cancel",NameLen-1),"]") or Functions.PadString("  Cancel",NameLen)))
  174.        
  175.     end
  176.    
  177. end
  178.  
  179. function onEnter()
  180.    
  181.     if turtle then
  182.        
  183.         if nOption == 1 then
  184.            
  185.             if not(W_Modem) then
  186.                
  187.                 Screen.clear()
  188.                 Functions.printCentered(Monitor[0], 1, "No WirelessModem Found !")
  189.                 Functions.printCentered(Monitor[0], 2, "Turtle Needs A WirelessModem !")
  190.                 error()
  191.                
  192.             end
  193.            
  194.             file = fs.exists(Disk.."/Setup/SetupTurtle.lua")
  195.            
  196.             if not(file) then
  197.                 shell.run("pastebin get CMLmkdxx "..Disk.."/Setup/SetupTurtle.lua")
  198.             end
  199.            
  200.             shell.run(Disk.."/Setup/SetupTurtle.lua")
  201.            
  202.             Monitor[0].clear()
  203.             Monitor[0].setCursorPos(1,1)
  204.             print("Done")
  205.             Status = false
  206.            
  207.         elseif nOption == 2 then
  208.            
  209.             Status = false
  210.            
  211.         end
  212.        
  213.     elseif pocket then
  214.        
  215.         if nOption == 1 then
  216.            
  217.             if not(W_Modem) then
  218.                
  219.                 Screen.clear()
  220.                 Functions.printCentered(Monitor[0], 1, "No WirelessModem Found !")
  221.                 Functions.printCentered(Monitor[0], 2, "Pocket Computer Needs A WirelessModem !")
  222.                 error()
  223.                
  224.             end
  225.            
  226.             file = fs.exists(Disk.."/Setup/SetupComputer.lua")
  227.            
  228.             if not(file) then
  229.                 shell.run("pastebin get jGUi9Jui "..Disk.."/Setup/SetupComputer.lua")
  230.             end
  231.            
  232.             shell.run(Disk.."/Setup/SetupComputer.lua")
  233.            
  234.             Monitor[0].clear()
  235.             Monitor[0].setCursorPos(1,1)
  236.             print("Done")
  237.             Status = false
  238.            
  239.         elseif nOption == 2 then
  240.            
  241.             Status = false
  242.            
  243.         end
  244.        
  245.     else
  246.        
  247.         if nOption ~= 4 then
  248.            
  249.             if not(W_Modem) then
  250.                
  251.                 Screen.clear()
  252.                 Functions.printCentered(Monitor[0], 1, "No WirelessModem Found !")
  253.                 Functions.printCentered(Monitor[0], 2, "The Computer Needs A WirelessModem !")
  254.                 error()
  255.                
  256.             end
  257.            
  258.         end
  259.        
  260.         if nOption == 1 then
  261.            
  262.             if #Monitor < 0 then
  263.                
  264.                 Functions.printCentered(Monitor[0], 1, "No Monitor Found !")
  265.                 Functions.printCentered(Monitor[0], 2, "The Server Computer Needs A Monitor !")
  266.                 error()
  267.                
  268.             end
  269.            
  270.             file = fs.exists(Disk.."/Setup/SetupServer.lua")
  271.            
  272.             if not(file) then
  273.                 shell.run("pastebin get DW0yxZhw "..Disk.."/Setup/SetupServer.lua")
  274.             end
  275.            
  276.             shell.run(Disk.."/Setup/SetupServer.lua")
  277.            
  278.             Monitor[0].clear()
  279.             Monitor[0].setCursorPos(1,1)
  280.             print("Done")
  281.             Status = false
  282.            
  283.         elseif nOption == 2 then
  284.            
  285.             file = fs.exists(Disk.."/Setup/SetupComputer.lua")
  286.            
  287.             if not(file) then
  288.                 shell.run("pastebin get jGUi9Jui "..Disk.."/Setup/SetupComputer.lua")
  289.             end
  290.            
  291.             shell.run(Disk.."/Setup/SetupComputer.lua")
  292.            
  293.             Monitor[0].clear()
  294.             Monitor[0].setCursorPos(1,1)
  295.             print("Done")
  296.             Status = false
  297.            
  298.         elseif nOption == 3 then
  299.            
  300.             file = fs.exists("/StartUp.lua")
  301.            
  302.             if file then
  303.                
  304.                 fs.delete("/StartUp.lua")
  305.                
  306.             end
  307.            
  308.             file = fs.exists("/GPS_IMAGE.nfp")
  309.            
  310.             if file then
  311.                
  312.                 fs.delete("/GPS_IMAGE.nfp")
  313.                
  314.             end
  315.            
  316.             shell.run("pastebin get VpR0dk64 /StartUp.lua")
  317.             shell.run("pastebin get fvvt8ZFe /GPS_IMAGE.nfp")
  318.            
  319.             Monitor[0].clear()
  320.             Monitor[0].setCursorPos(1,1)
  321.             print("Done")
  322.             Status = false
  323.            
  324.         elseif nOption == 4 then
  325.            
  326.             Status = false
  327.            
  328.         end
  329.        
  330.     end
  331.    
  332. end
  333.  
  334. while Status do
  335.    
  336.     drawMenu()
  337.     drawFrontend()
  338.    
  339.     local Event, p1, p2, p3, p4, p5 = System.pullEvent()
  340.    
  341.     if Event == "key" then
  342.        
  343.         if p1 == keys.up or p1 == keys.numPad8 then
  344.            
  345.             if nOption > 1 then
  346.                
  347.                 nOption = nOption - 1
  348.                
  349.             end
  350.            
  351.         elseif p1 == keys.down or p1 == keys.numPad2 then
  352.            
  353.             if nOption < MaxOptions then
  354.                
  355.                 nOption = nOption + 1
  356.                
  357.             end
  358.            
  359.         elseif p1 == keys.enter or p1 == keys.numPadEnter then
  360.            
  361.             onEnter()
  362.            
  363.         end
  364.        
  365.     end
  366.    
  367. end
  368.  
  369. print("Eject disk and reboot!")
Add Comment
Please, Sign In to add comment