Advertisement
DOGGYWOOF

Untitled

Jul 25th, 2024 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. -- Define GUI colors
  2. local bgColor = colors.black
  3. local fgColor = colors.white
  4. local buttonColor = colors.blue
  5. local buttonTextColor = colors.white
  6. local errorColor = colors.red
  7. local boxBgColor = colors.gray
  8. local primaryDiskFile = "/disk/primary_disk.txt"
  9.  
  10. -- Function to clear the screen and set background color
  11. local function clearScreen()
  12. term.setBackgroundColor(bgColor)
  13. term.setTextColor(fgColor)
  14. term.clear()
  15. term.setCursorPos(1, 1)
  16. end
  17.  
  18. -- Function to draw the title bar
  19. local function drawTitleBar()
  20. term.setBackgroundColor(colors.cyan)
  21. term.setTextColor(colors.white)
  22. term.setCursorPos(1, 1)
  23. term.clearLine()
  24. term.write("Doggy OS Legacy Bootloader")
  25. term.setBackgroundColor(bgColor)
  26. term.setTextColor(fgColor)
  27. term.setCursorPos(1, 2)
  28. end
  29.  
  30. -- Function to draw a message box
  31. local function drawMessageBox(title, message, buttonText)
  32. term.setBackgroundColor(bgColor)
  33. term.setTextColor(fgColor)
  34. local width, height = term.getSize()
  35.  
  36. -- Draw the box
  37. local boxWidth = width - 4
  38. local boxHeight = 5
  39. local boxX = 2
  40. local boxY = math.floor((height - boxHeight) / 2)
  41.  
  42. paintutils.drawFilledBox(boxX, boxY, boxX + boxWidth, boxY + boxHeight, boxBgColor)
  43. term.setBackgroundColor(boxBgColor)
  44. term.setTextColor(fgColor)
  45. term.setCursorPos(boxX + 2, boxY + 1)
  46. term.write(title)
  47.  
  48. term.setBackgroundColor(boxBgColor)
  49. term.setTextColor(fgColor)
  50. term.setCursorPos(boxX + 2, boxY + 2)
  51. term.write(message)
  52.  
  53. term.setBackgroundColor(buttonColor)
  54. term.setTextColor(buttonTextColor)
  55. term.setCursorPos(boxX + 2, boxY + boxHeight - 1)
  56. term.write(" " .. buttonText .. " ")
  57. end
  58.  
  59. -- Function to show the boot menu
  60. local function showBootMenu(bootOptions)
  61. clearScreen()
  62. drawTitleBar()
  63. term.setBackgroundColor(boxBgColor)
  64. term.setTextColor(fgColor)
  65. local width, height = term.getSize()
  66. local menuX = 2
  67. local menuY = 3
  68. local boxWidth = width - 4
  69. local boxHeight = #bootOptions + 4
  70.  
  71. paintutils.drawFilledBox(menuX, menuY, menuX + boxWidth, menuY + boxHeight, boxBgColor)
  72. term.setCursorPos(menuX + 2, menuY + 1)
  73. term.write("Boot Menu")
  74.  
  75. for i, option in ipairs(bootOptions) do
  76. term.setCursorPos(menuX + 2, menuY + i + 1)
  77. term.write(i .. ". " .. option.name)
  78. end
  79.  
  80. term.setCursorPos(menuX + 2, menuY + boxHeight)
  81. term.write("Select an option: ")
  82.  
  83. local selectedOption = tonumber(read())
  84. if selectedOption and selectedOption >= 1 and selectedOption <= #bootOptions then
  85. local selectedDisk = bootOptions[selectedOption].disk
  86. local bootPath = bootOptions[selectedOption].path
  87. -- Save selected disk as primary
  88. fs.delete(primaryDiskFile) -- Remove old primary disk file if exists
  89. local file = fs.open(primaryDiskFile, "w")
  90. file.write(selectedDisk)
  91. file.close()
  92. -- Run the boot file
  93. shell.run(bootPath)
  94. else
  95. drawMessageBox("Invalid Option", "Selected option is not valid.", "Press enter to return...")
  96. read() -- Wait for user input to return
  97. bootloader()
  98. end
  99. end
  100.  
  101. -- Function to determine the primary disk
  102. local function getPrimaryDisk()
  103. if fs.exists(primaryDiskFile) then
  104. local file = fs.open(primaryDiskFile, "r")
  105. local disk = file.readAll()
  106. file.close()
  107. return disk
  108. end
  109. return "/disk" -- Default to /disk if no primary disk file exists
  110. end
  111.  
  112. -- Main bootloader function
  113. local function bootloader()
  114. clearScreen()
  115. drawTitleBar()
  116. drawMessageBox("Booting...", "Attempting to boot your OS.", "Please wait...")
  117. sleep(0.7)
  118.  
  119. -- Simulated boot process
  120. sleep(2)
  121.  
  122. local primaryDisk = getPrimaryDisk()
  123. local bootOptions = {}
  124. local diskPaths = {primaryDisk.."/boot", "/disk2/boot"}
  125.  
  126. for _, path in ipairs(diskPaths) do
  127. if fs.exists(path.."/error") then
  128. table.insert(bootOptions, {name = "Error", path = path.."/error", disk = path:match("/disk%d?")})
  129. end
  130. if fs.exists(path.."/startup") then
  131. table.insert(bootOptions, {name = "Startup", path = path.."/startup", disk = path:match("/disk%d?")})
  132. end
  133. if fs.exists(path.."/startup.lua") then
  134. table.insert(bootOptions, {name = "Startup.lua", path = path.."/startup.lua", disk = path:match("/disk%d?")})
  135. end
  136. end
  137.  
  138. if #bootOptions == 0 then
  139. clearScreen()
  140. drawTitleBar()
  141. drawMessageBox("Startup Error", "No boot files detected.", "Press enter to reboot...")
  142. read() -- Wait for user input to reboot
  143. os.reboot()
  144. elseif #bootOptions == 1 then
  145. shell.run(bootOptions[1].path)
  146. else
  147. showBootMenu(bootOptions)
  148. end
  149. end
  150.  
  151. bootloader()
  152.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement