Advertisement
DOGGYWOOF

Bootloader (WARNING FLASHING LIGHTS!!)

Aug 7th, 2024 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. -- Function to check if a file exists
  2. local function fileExists(path)
  3. local file = fs.open(path, "r")
  4. if file then
  5. file.close()
  6. return true
  7. else
  8. return false
  9. end
  10. end
  11.  
  12. -- Function to clear the screen
  13. local function clearScreen()
  14. term.clear()
  15. term.setCursorPos(1, 1)
  16. end
  17.  
  18. -- Function to create a glitchy effect
  19. local function glitchyEffect()
  20. local width, height = term.getSize()
  21. local colors = {colors.white, colors.gray, colors.red, colors.blue, colors.green, colors.yellow}
  22.  
  23. for _ = 1, 10 do
  24. term.setBackgroundColor(colors[math.random(#colors)])
  25. term.setTextColor(colors[math.random(#colors)])
  26. term.setCursorPos(math.random(1, width), math.random(1, height))
  27. print(string.char(math.random(32, 126)))
  28. sleep(0.05) -- Adjust the speed of the glitch effect here
  29. clearScreen()
  30. end
  31. end
  32.  
  33. -- Function to display the Doggy OS boot manager GUI with glitchy effect
  34. local function displayGUI(message, options)
  35. clearScreen()
  36. glitchyEffect()
  37. -- Ensure the screen is cleared and set to default colors before showing the menu
  38. term.setTextColor(colors.white)
  39. term.setBackgroundColor(colors.black)
  40. clearScreen() -- Clear any remnants of the glitch effect
  41. term.setCursorPos(1, 1)
  42. print("Doggy OS Boot Manager")
  43. print("====================")
  44. print()
  45. print(message)
  46. print()
  47.  
  48. for i, option in ipairs(options) do
  49. print(i .. ". " .. option)
  50. end
  51. end
  52.  
  53. -- Function to shutdown the system
  54. local function shutdownSystem()
  55. clearScreen()
  56. displayGUI("Shutting down the system...", {})
  57. sleep(2) -- Simulate shutdown process
  58. os.shutdown()
  59. end
  60.  
  61. -- Function to handle user choice
  62. local function getUserChoice(numOptions)
  63. local choice
  64. repeat
  65. term.setCursorPos(1, 10 + numOptions)
  66. print("Enter choice (1-" .. numOptions .. "): ")
  67. choice = tonumber(read())
  68. until choice and choice >= 1 and choice <= numOptions
  69. return choice
  70. end
  71.  
  72. -- Main program logic
  73. local function main()
  74. local devCfgPath = "dev.cfg"
  75. local biosPath = "/disk/boot/BIOS"
  76.  
  77. -- Check if dev.cfg exists
  78. if not fileExists(devCfgPath) then
  79. displayGUI("dev.cfg not found.", {"Run BIOS"})
  80. if fileExists(biosPath) then
  81. shell.run(biosPath)
  82. else
  83. print("Error: BIOS file not found.")
  84. end
  85. return
  86. end
  87.  
  88. -- The disk paths to check
  89. local diskPath = "/disk2/startup"
  90. local startupFileFound = false
  91.  
  92. -- Check if startup file exists on /disk2
  93. if fileExists(diskPath) or fileExists(diskPath .. ".lua") then
  94. startupFileFound = true
  95. end
  96.  
  97. if startupFileFound then
  98. displayGUI("Boot Device found on /disk2.", {"Boot", "Shutdown system", "Reboot"})
  99. local choice = getUserChoice(3)
  100.  
  101. if choice == 1 then
  102. clearScreen()
  103. if fileExists(diskPath .. ".lua") then
  104. shell.run(diskPath .. ".lua")
  105. elseif fileExists(diskPath) then
  106. shell.run(diskPath)
  107. end
  108. elseif choice == 2 then
  109. shutdownSystem()
  110. elseif choice == 3 then
  111. clearScreen()
  112. displayGUI("Rebooting...", {})
  113. shutdownSystem()
  114. end
  115. else
  116. displayGUI("No boot device found on /disk2.", {"Run BIOS"})
  117. if fileExists(biosPath) then
  118. shell.run(biosPath)
  119. else
  120. print("Error: BIOS file not found.")
  121. end
  122. end
  123. end
  124.  
  125. -- Run the main function
  126. main()
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement