Spatzenhirn123

Big Reactor - Program

May 17th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- This is the first time setup so the computer will
  2. -- Download all the required scripts.
  3. local args = { ... }
  4. running = true
  5. elements = {}
  6. -- Checking System Support
  7. if not http then
  8.   error "You Must Enable HTTP In Computer-craft Con-figs To Use The System!"
  9. end
  10.  
  11. if not term.isColor() then
  12.   error "This Computer Does Not Appear To Be Advanced, If It Is Advanced, Then Please Report This"
  13. end
  14.  
  15. function create(text, width, height, x, y, tc, bg, otc, obg, func, toggle, secBG, secTC, secText, parent) --Return the new button so it can be called later to be drawn
  16.     local new = {} --New Table To Store Details
  17.     setmetatable( new, {__index = self} ) --New Metatable To Set Index To Self
  18.     new.text = text or 'Nil Text' --Button Text
  19.     new.width = width or #text + 2  --Button width
  20.     if secText then new.secWidth = #secText + 2 else new.secWidth = #text + 2 end
  21.     new.height = height or 1 --Button Height
  22.     new.pad = pad or 2 --Padding Variable
  23.     new.x = x or 1 --Button X Positioning
  24.     new.y = y or 1 --Button Y Positioning
  25.     new.tc = tc or colors.white --Button Text Color
  26.     new.bg = bg or 128 --Button Background Color
  27.     new.otc = otc or colors.white --Original Background Color
  28.     new.obg = obg or 256 --Orignial Text Color
  29.     new.func = func or nil --Function on click
  30.     new.toggle = toggle or false --Whether the button should change state on click
  31.     new.secondaryBackground = secBG or bg --Toggle Background Color
  32.     new.secondaryTextColor = secTC or tc --Toggle Text Color
  33.     new.toggleState = 1 --Set toggle state to default
  34.     new.secondaryText = secText or text
  35.     new.visible = true
  36.     new.parent = parent or 'Nil'
  37.     return new
  38. end
  39.  
  40. function tryClick(elementTable, x, y) --On Click Check Co-Ords, If match run the function assigned to the button
  41.     if elementTable then
  42.         for i, v in ipairs(elementTable) do
  43.             if x >= v.x and x < v.x + v.width then
  44.                 if y == v.y then
  45.                     if v.visible then
  46.                         if v.toggle then element.toggle(v) end
  47.                         if v.parent then
  48.                             for i, p in ipairs(elementTable) do
  49.                                 if p.parent == v.parent then
  50.                                     if p ~= v then p.toggleState = 1 else p.toggleState = 2 end
  51.                                     draw(p)
  52.                                 end
  53.                             end
  54.                         end
  55.                         if v.func then return(v.func) end
  56.                     end
  57.                 end
  58.             end
  59.         end
  60.     end
  61. end
  62.  
  63. function eraseCurrent(elem)
  64.     if elem then
  65.         if elem.toggleState == 2 then textSpec = elem.secondaryText widthSpec = elem.secWidth else textSpec = elem.text widthSpec = elem.width end
  66.         term.setCursorPos(elem.x, elem.y)
  67.         term.setBackgroundColor(elem.obg)
  68.         if elem.width and elem.secWidth then
  69.             if elem.toggleState == 1 then
  70.                 write(string.rep(' ', elem.secWidth ))
  71.             elseif elem.toggleState == 2 then
  72.                 write(string.rep(' ', elem.width ))
  73.             end
  74.         end
  75.     end
  76. end
  77.  
  78. function draw(elem) --Visually Draw The Button Provided
  79.     if elem then eraseCurrent(elem) end
  80.     if elem.visible then
  81.         if elem.toggleState == 2 then term.setTextColor(elem.secondaryTextColor) else term.setTextColor(elem.tc) end
  82.         if elem.toggleState == 2 then term.setBackgroundColor(elem.secondaryBackground) else term.setBackgroundColor(elem.bg) end
  83.         term.setCursorPos(elem.x, elem.y)
  84.         write(string.rep(' ', elem.width )) --Create The Background Panel
  85.         if elem.toggleState == 2 then textSpec = elem.secondaryText widthSpec = elem.secWidth else textSpec = elem.text widthSpec = elem.width end
  86.         term.setCursorPos(elem.x + (widthSpec - #textSpec)/2, elem.y) --Set The Cursor Pos In The Correct Padding Pos So The Text Appears In The Correct Location
  87.         write(textSpec)--Print The Button Text On The Button
  88.     else
  89.         term.setTextColor(elem.otc)
  90.         term.setBackgroundColor(elem.obg)
  91.         term.setCursorPos(elem.x, elem.y)
  92.         write(string.rep(' ', elem.width )) --Create The Background Panel
  93.         term.setCursorPos(elem.x, elem.y) --Set The Cursor Pos In The Correct Padding Pos So The Text Appears In The Correct Location
  94.     end
  95.     term.setTextColor(elem.otc)
  96.     term.setBackgroundColor(elem.obg)
  97. end
  98.  
  99. function toggle(elem)
  100.     if elem.toggle then
  101.         if elem.toggleState == 1 then elem.toggleState = 2
  102.         elseif elem.toggleState == 2 then elem.toggleState = 1 end
  103.         draw(elem)
  104.     end
  105. end
  106.  
  107. function opacity(elem, state) --Set or toggle visibility of a button, if invisible the BG color will be what you assigned when creating the button
  108.     if elem then
  109.         if state ~= 't' then --Manual Adjust
  110.             elem.visible = state
  111.         else --Toggle Auto
  112.             if elem.visible == true then elem.visible = false else elem.visible = true end
  113.         end
  114.         draw(elem)
  115.     end
  116. end
  117.  
  118. function btnInit(btnText, btnWidth, btnHeight, btnX, btnY, btnTC, btnBG, oTC, oBG, onClick, toggle, secBG, secTC, secText) --Function to create button
  119.     local btn = create(btnText, btnWidth, btnHeight, btnX, btnY, btnTC, btnBG, oTC, oBG, onClick, toggle, secBG, secTC, secText) --Calls API to generate button
  120.     table.insert(elements, btn) --Inserts into table so it can be scanned later
  121.     opacity(btn, true) --Sets visibility to true
  122.     return btn
  123. end
  124.  
  125. function doClick(event, btn, x, y)
  126.     functionToRun = tryClick(elements, x, y)
  127.     if functionToRun then --Check click location
  128.         functionToRun()
  129.     end
  130. end
  131.  
  132. function PrintCentered(text, y)
  133.     term.setTextColor(1)
  134.     local w, h = term.getSize()
  135.     x = math.ceil(math.ceil((w / 2) - (#text / 2)), 0)+1
  136.     term.setCursorPos(x, y)
  137.     term.clearLine()
  138.     write(text)
  139. end
  140.  
  141. function initBackground(color) --Draw The Background In The Specified Color
  142.   term.setBackgroundColor(color)
  143.   term.clear()
  144. end
  145.  
  146. function drawTitleBar()
  147.   term.setBackgroundColor(128)
  148.   term.setCursorPos(1,1)
  149.   term.clearLine()
  150.   term.setTextColor(colors.cyan)
  151.   write "HbombOS Security Solutions"
  152.   term.setCursorPos(1,2)
  153.   term.clearLine()
  154.   term.setTextColor(256)
  155.   write "Installer"
  156.   term.setTextColor(1)
  157. end
  158. initBackground(256)
  159. drawTitleBar()
  160.  
  161. local function checkSite()
  162.   local response = http.get("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/version")
  163.   if response then
  164.     return true
  165.   else
  166.     return false
  167.   end
  168. end
  169.  
  170. termX, termY = term.getSize()
  171.  
  172. function start()
  173.   if args[1] == 'auto' then
  174.       return true
  175.   else
  176.       term.setBackgroundColor(256)
  177.       PrintCentered('Welcome To The', 7)
  178.       PrintCentered('Hbomb Security Suite', 8)
  179.       PrintCentered('Install Wizzard', 9)
  180.       PrintCentered('BEWARE',13)
  181.       PrintCentered('All Files Already In Destination Will Be',14)
  182.       PrintCentered('Overwritten',15)  
  183.       yes = btnInit('Install', nil, nil, termX-#'Install'-2, termY-1, 1, colors.green, 1, 256, function() os.queueEvent('continue') end, false, nil, nil, nil, nil)
  184.       no = btnInit('Dont Install', nil, nil, 2, termY-1, 1, colors.red, 1, 256, function() os.reboot() end, false, nil, nil, nil, nil)
  185.       while true do
  186.         event, btn, x, y = os.pullEvent()
  187.         if event == "mouse_click" then
  188.             doClick(event, btn, x, y)
  189.         elseif event == "continue" then
  190.             break
  191.         end
  192.       end
  193.       return true
  194.   end
  195. end
  196.  
  197. function open()
  198. start()
  199. opacity(yes ,false)
  200. opacity(no ,false)
  201. term.clear()
  202. drawTitleBar()
  203. term.setBackgroundColor(256)
  204. term.setTextColor(1)
  205.   PrintCentered("Starting Download", 6)
  206.   PrintCentered("Establishing Connection With Github", 8)
  207.   PrintCentered("Reading GitHub Repository", 18)
  208.   if not checkSite() then
  209.     PrintCentered("The GitHub Version File Does Not", 18)
  210.     PrintCentered("Appear To Be At The Destination URL", 19)
  211.     term.setTextColor(colors.red)
  212.     PrintCentered("The Installer Has Encountered An Issue!", 2)
  213.     return false
  214.   end
  215.   PrintCentered("Connection With Github Established", 8)
  216.   PrintCentered("GitHub Repository Located", 18)
  217.   sleep(1)
  218.   PrintCentered("GitHub Repository Connection Established", 18)
  219.   sleep(0)
  220.   PrintCentered("Downloading And Installing Files", 8)
  221.   PrintCentered("Starting Download Sequence", 18)
  222.   sleep(0.1)
  223.   return true
  224. end
  225.  
  226. function downloadFiles(getUrl, toPath)
  227. term.setTextColor(1)
  228. term.setBackgroundColor(256)
  229. -- Download the files and scripts from github
  230.   for i = 1, 3 do
  231.     local response = http.get(getUrl)
  232.     if response then
  233.       data = response.readAll()
  234.           if fs.exists(toPath) then
  235.           fs.delete(toPath)
  236.           PrintCentered ("Delete: "..toPath, 19)
  237.         end
  238.         if toPath then
  239.           if fs.exists(toPath) then fs.delete(toPath) end
  240.           local file = fs.open(toPath, "w")
  241.           file.write(data)
  242.           file.close()
  243.           PrintCentered ("Download: "..toPath, 19)
  244.           return true
  245.         else
  246.           print "We Believe The Path Specified Is Invalid, Report If Not Your Fault"
  247.           sleep(3)
  248.           os.shutdown()
  249.         end
  250.     else
  251.       print ("The File Or Files At: "..getUrl.." Do Not Appear To Exist! Please Report This Issue On Forums Or Through GitHub")
  252.       sleep(3)
  253.       os.shutdown()
  254.     end
  255.   end
  256.   print ("Failed To Download The File From URL: "..getUrl.." Please try again later, If this is the 2nd time you've seen this, then report it on the fourms")
  257.   sleep(3)
  258.   os.shutdown()
  259. end
  260.  
  261. function createDirectory() --Used to create directories for version 1.5 and below
  262.   fs.makeDir('/systemFiles/')
  263.   fs.makeDir('/systemFiles/Images/BootLogos/')
  264.   fs.makeDir('/systemFiles/Images/Update/')
  265.   fs.makeDir('/systemFiles/Images/progressBar/')
  266.   fs.makeDir('/systemFiles/Install/')
  267.   fs.makeDir('/api/')
  268.   fs.makeDir('/Documentation/')
  269.   fs.makeDir('/systemFiles/Programs/')
  270.   fs.makeDir('/systemFiles/Security/')
  271. end
  272.  
  273. function thanks()
  274.   term.clear()
  275.   drawTitleBar()
  276.   term.setBackgroundColor(256)
  277.   term.setTextColor(1)
  278.   PrintCentered ("Thank You For Downloading And Installing The", 6)
  279.   PrintCentered ("Latest Version Of My Security Suite", 7)
  280.   PrintCentered ("Report Any Issues You Come Across", 8)
  281.   local f = fs.open('version', 'r')
  282.   currVer = f.readLine()
  283.   f.close()
  284.   PrintCentered ("You Are Now Running The Latest Version: "..currVer, 10)
  285.   PrintCentered ("Hope You Enjoy, Click Anywhere To Get Started", 19)
  286.   if args[1] ~= 'auto' then os.pullEvent('mouse_click') else return end
  287.   os.reboot()
  288. end
  289.  
  290. function download() --Download Files From GitHub And Install Them On The Local Computer
  291. term.setBackgroundColor(256)
  292. PrintCentered ("Creating Directories... Please Wait", 19)
  293. sleep(0)
  294. createDirectory() --Creates The Directories To Stop The Program From Crashing
  295. PrintCentered ("Downloading Scripts... Please Wait", 19)
  296. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/startup", "startup")
  297. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/version", "version")
  298. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Install/installer", "systemFiles/Install/installer")
  299. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Install/updater", "systemFiles/Install/updater")
  300. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Install/setup", "systemFiles/Install/setup")
  301. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/BootLogos/boot0.nfp", "systemFiles/Images/BootLogos/boot0.nfp")
  302. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/BootLogos/boot1.nfp", "systemFiles/Images/BootLogos/boot1.nfp")
  303. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/BootLogos/boot2.nfp", "systemFiles/Images/BootLogos/boot2.nfp")
  304. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/BootLogos/boot3.nfp", "systemFiles/Images/BootLogos/boot3.nfp")
  305. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/BootLogos/boot4.nfp", "systemFiles/Images/BootLogos/boot4.nfp")
  306. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/BootLogos/boot5.nfp", "systemFiles/Images/BootLogos/boot5.nfp")
  307. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/BootLogos/boot6.nfp", "systemFiles/Images/BootLogos/boot6.nfp")
  308. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/BootLogos/boot7.nfp", "systemFiles/Images/BootLogos/boot7.nfp")
  309. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/Update/update1.nfp", "systemFiles/Images/Update/update1.nfp")
  310. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/Update/update2.nfp", "systemFiles/Images/Update/update2.nfp")
  311. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/Update/update3.nfp", "systemFiles/Images/Update/update3.nfp")
  312. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/progressBar/load0.nfp", "systemFiles/Images/progressBar/load0.nfp")
  313. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/progressBar/load1.nfp", "systemFiles/Images/progressBar/load1.nfp")
  314. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/progressBar/load2.nfp", "systemFiles/Images/progressBar/load2.nfp")
  315. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/progressBar/load3.nfp", "systemFiles/Images/progressBar/load3.nfp")
  316. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/progressBar/load4.nfp", "systemFiles/Images/progressBar/load4.nfp")
  317. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/progressBar/load5.nfp", "systemFiles/Images/progressBar/load5.nfp")
  318. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/progressBar/load6.nfp", "systemFiles/Images/progressBar/load6.nfp")
  319. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/progressBar/load7.nfp", "systemFiles/Images/progressBar/load7.nfp")
  320. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Images/progressBar/load8.nfp", "systemFiles/Images/progressBar/load8.nfp")
  321. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/api/download", "/api/download")
  322. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/api/systemCheck", "/api/systemCheck")
  323. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/api/update", "/api/update")
  324. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/api/printer", "/api/printer")
  325. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/api/titleBar", "/api/titleBar")
  326. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/api/LogFile", "/api/LogFile")
  327. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/api/element", "/api/element")
  328. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/api/uInput", "/api/uInput")
  329. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/api/errora", "/api/errora")
  330. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Programs/dualKey", "/systemFiles/Programs/dualKey")
  331. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Programs/keycard", "/systemFiles/Programs/keycard")
  332. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Programs/keycardDual", "/systemFiles/Programs/keycardDual")
  333. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Programs/pin", "/systemFiles/Programs/pin")
  334. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Programs/rangeLock", "/systemFiles/Programs/rangeLock")
  335. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Programs/reactor", "/systemFiles/Programs/reactor")
  336. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Programs/OpenPDetect", "/systemFiles/Programs/OpenPDetect")
  337. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Programs/remoteControl.lua", "/systemFiles/Programs/remoteControl.lua")
  338. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/README", "/Documentation/README")
  339. downloadFiles("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/LICENSE", "/Documentation/LICENSE")
  340. PrintCentered("Complete", 19)
  341. thanks()
  342. return
  343. end
  344.  
  345. if open() then
  346.   download()
  347.   return
  348. else
  349.   sleep(3)
  350.   os.reboot()
  351. end
Add Comment
Please, Sign In to add comment