Z1maV1

startup.bios

May 14th, 2022 (edited)
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.40 KB | None | 0 0
  1. --BIOS (diamond c. 22.1)--
  2. --non-terminate event--
  3. os.PullEvent = os.PullEventRaw
  4. --BIOS (diamond c. 22.1) now has color ob boot--
  5.  
  6. w,h = term.getSize()
  7.  
  8. nOption = 0
  9.  
  10. isTemp = false
  11.  
  12. isBooting = false
  13.  
  14. biosVer = "diamond c. 22.1"
  15.  
  16. local function printCentered(y,s,clearLine)
  17.     local x = math.floor((w - string.len(s)) / 2)
  18.     term.setCursorPos(x,y)
  19.     if clearLine == true then
  20.         term.clearLine()
  21.     end
  22.     term.write(s)
  23. end
  24.  
  25. local function Boot()
  26.     term.clear()
  27.     term.setCursorPos(1,1)
  28.     print("BIOS ("..biosVer..")")
  29.     print("Computer info: ")
  30.     write("ID: ")
  31.     term.setTextColor(colors.cyan)
  32.     print(os.getComputerID())
  33.     term.setTextColor(colors.white)
  34.     --showing label and id--
  35.     if not os.getComputerLabel() then
  36.         write("Label: ")
  37.         term.setTextColor(colors.red)
  38.         print("*NONE*")
  39.         term.setTextColor(colors.white)
  40.     else
  41.         write("Label: ")
  42.         term.setTextColor(colors.cyan)
  43.         print(os.getComputerLabel())
  44.         term.setTextColor(colors.white)
  45.     end
  46.     print"Checking boot config..."
  47.     --checking if ps supports color--
  48.     write("Color support: ")
  49.     if not term.isColor() then
  50.         term.setTextColor(colors.red)
  51.         print("*ERROR* NO COLOR SUPPORT BY COMPUTER")
  52.     else
  53.         term.setTextColor(colors.green)
  54.         print("OK")
  55.     end
  56.     term.setTextColor(colors.white)
  57.     write("Boot config: ")
  58.     --checking if ps has boot file path--
  59.     if not setting then
  60.         term.setTextColor(colors.red)
  61.         print("*ERROR* UNABLE TO GET BOOT CONFIG")
  62.         term.setTextColor(colors.white)
  63.         while true do
  64.             sleep(0)
  65.         end
  66.     end
  67.     if not fs.exists(setting) then
  68.         term.setTextColor(colors.red)
  69.         print("*ERROR RUN FILE DOES NOT EXISTS*")
  70.         term.setTextColor(colors.white)
  71.         while true do
  72.             sleep(0)
  73.         end
  74.     end
  75.     --bool file runing--
  76.    
  77.     term.setTextColor(colors.green)
  78.     print("GOT")
  79.     term.setTextColor(colors.white)
  80.     textutils.slowPrint("Running boot file...")
  81.     if isTemp == true then
  82.         settings.set("bootFile", settings.get("bootOld"))
  83.         settings.unset("bootOld")
  84.         settings.undefine("bootOld")
  85.         settings.save()
  86.     end
  87.     term.clear()
  88.     term.setCursorPos(1,1)
  89.     shell.run(setting)
  90. end
  91.  
  92. local function TimerToBoot()
  93.     while true do
  94.         local event = os.pullEvent("timer")
  95.         if event == "timer" then
  96.             isBooting = true
  97.             break
  98.         end
  99.     end
  100. end
  101.  
  102. local function PressSettingButton()
  103.     while true do
  104.         local event, key = os.pullEvent("key")
  105.         if event == "key" and isBooting ~= true then
  106.             if keys.getName(key) == "delete" then
  107.                 os.cancelTimer(timer)
  108.                 while true do
  109.                     term.clear()
  110.                     term.setCursorPos(1,1)
  111.                     print("BIOS ("..biosVer..") /// BOOT CONFIG ///")
  112.                     if nOption == 0 then
  113.                         printCentered(math.floor(h / 2) - 1, "[ Set boot file ]")
  114.                         printCentered(math.floor(h / 2) - 0, "Boot from")
  115.                         printCentered(math.floor(h / 2) + 1, "Close")
  116.                     elseif nOption == 1 then
  117.                         printCentered(math.floor(h / 2) - 1, "Set boot file")
  118.                         printCentered(math.floor(h / 2) - 0, "[ Boot from ]")
  119.                         printCentered(math.floor(h / 2) + 1, "Close")
  120.                     else
  121.                         printCentered(math.floor(h / 2) - 1, "Set boot file")
  122.                         printCentered(math.floor(h / 2) - 0, "Boot from")
  123.                         printCentered(math.floor(h / 2) + 1, "[ Close ]")
  124.                     end
  125.                     local event, key = os.pullEvent()
  126.                     if event == "key" then
  127.                         if keys.getName(key) == "up" then
  128.                             if nOption > 0 then
  129.                                 nOption = nOption - 1
  130.                             end
  131.                         elseif keys.getName(key) == "down" then
  132.                             if nOption < 2 then
  133.                                 nOption = nOption + 1
  134.                             end
  135.                         elseif keys.getName(key) == "enter" then
  136.                             if nOption == 0 then
  137.                                 term.clear()
  138.                                 term.setCursorPos(1,1)
  139.                                 print("BIOS ("..biosVer..") /// BOOT CONFIG ///")
  140.                                 print("\n\nPlease write full path to file. Current \""..setting.."\"")
  141.                                 choice = read()
  142.                                 print("Save? [Y/n]")
  143.                                 if string.lower(read()) == "y" then
  144.                                     settings.set("bootFile", choice)
  145.                                     settings.save()
  146.                                 end
  147.                             elseif nOption == 1 then
  148.                                 term.clear()
  149.                                 term.setCursorPos(1,1)
  150.                                 print("BIOS ("..biosVer..") /// BOOT CONFIG ///")
  151.                                 print("\n\nPlease write full path to file. (write 'cancel' to return)")
  152.                                 choice = read()
  153.                                 if string.lower(choice) ~= "cancel" then
  154.                                     setting = choice
  155.                                     print("Bootting...")
  156.                                     sleep(1)
  157.                                     break
  158.                                 end
  159.                             elseif nOption == 2 then
  160.                                 break
  161.                             end
  162.                         end
  163.                     end
  164.                 end
  165.                 break
  166.             end
  167.         elseif isBotting == true then
  168.             break
  169.         else
  170.             sleep(0)
  171.         end
  172.     end
  173. end
  174.  
  175. --os.pullEvent = os.pullEventRaw
  176.  
  177. --getting boot file path--
  178. settings.set("shell.allow_disk_startup", false)
  179. settings.save()
  180. setting = settings.get("bootFile")
  181. --printing lines :)--
  182. term.clear()
  183. term.setCursorPos(1,1)
  184. print("BIOS ("..biosVer..")")
  185. print("To open boot settings press DELETE...")
  186. timer = os.startTimer(3)
  187. parallel.waitForAny(PressSettingButton, TimerToBoot)
  188. Boot()
  189.  
Advertisement
Add Comment
Please, Sign In to add comment