Advertisement
DOGGYWOOF

Doggy OS Bootmanager for UEFI

Jan 11th, 2025 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. -- Doggy OS Boot Manager for CC Tweaked
  2.  
  3. local function findStartupFiles()
  4. local disks = {}
  5. local diskPaths = {"/disk2", "/disk3"} -- Include only /disk2/ and /disk3/
  6.  
  7. -- Search for startup files in specified disk paths
  8. for _, diskPath in ipairs(diskPaths) do
  9. local paths = {
  10. diskPath .. "/startup",
  11. diskPath .. "/startup.lua",
  12. }
  13. for _, path in ipairs(paths) do
  14. if fs.exists(path) then
  15. table.insert(disks, {path = path, displayName = path})
  16. break
  17. end
  18. end
  19. end
  20.  
  21. -- Check /disk/ for /boot/error only
  22. if fs.exists("/disk/boot/error") then
  23. table.insert(disks, {path = "/disk/boot/error", displayName = "Doggy OS"}) -- Doggy OS Device boot file
  24. end
  25.  
  26. -- Add built-in recovery option
  27. if fs.exists("/disk/boot/Recovery.lua") then
  28. table.insert(disks, {path = "/disk/boot/Recovery.lua", displayName = "Doggy OS Recovery Environment"})
  29. end
  30.  
  31. return disks
  32. end
  33.  
  34. local function drawMenu(disks, selected, bootingMessage)
  35. local width, height = term.getSize()
  36. local menuWidth, menuHeight = 40, 10 + #disks
  37. local startX = math.floor((width - menuWidth) / 2)
  38. local startY = math.floor((height - menuHeight) / 2)
  39.  
  40. term.setBackgroundColor(colors.black)
  41. term.clear()
  42.  
  43. -- Draw centered window background
  44. term.setBackgroundColor(colors.gray)
  45. for y = 0, menuHeight do
  46. term.setCursorPos(startX, startY + y)
  47. term.write(string.rep(" ", menuWidth))
  48. end
  49.  
  50. -- Draw Header
  51. term.setCursorPos(startX + 1, startY + 1)
  52. term.setTextColor(colors.blue)
  53. term.write(" ***** Doggy OS Boot Manager ***** ")
  54.  
  55. -- Draw Instructions
  56. term.setCursorPos(startX + 1, startY + 3)
  57. term.setTextColor(colors.lightGray)
  58. term.write("Select a boot device")
  59.  
  60. term.setCursorPos(startX + 1, startY + 4)
  61. term.write(string.rep("=", menuWidth - 2))
  62.  
  63. -- Draw boot options
  64. for i, disk in ipairs(disks) do
  65. term.setCursorPos(startX + 2, startY + 5 + i)
  66. if i == selected then
  67. term.setTextColor(colors.white)
  68. term.setBackgroundColor(colors.blue)
  69. else
  70. term.setTextColor(colors.lightGray)
  71. term.setBackgroundColor(colors.gray)
  72. end
  73. term.write(" [" .. i .. "] " .. disk.displayName .. string.rep(" ", menuWidth - 8 - #disk.displayName))
  74. end
  75.  
  76. -- Draw Footer
  77. term.setCursorPos(startX + 1, startY + 6 + #disks)
  78. term.setTextColor(colors.lightGray)
  79. term.setBackgroundColor(colors.gray)
  80. term.write(string.rep("=", menuWidth - 2))
  81.  
  82. -- Display booting message if available
  83. if bootingMessage then
  84. term.setCursorPos(startX + 2, startY + 7 + #disks)
  85. term.setTextColor(colors.cyan)
  86. term.write(bootingMessage)
  87. end
  88.  
  89. -- Reset colors
  90. term.setTextColor(colors.white)
  91. term.setBackgroundColor(colors.black)
  92. end
  93.  
  94. local function main()
  95. local disks
  96. while true do
  97. disks = findStartupFiles()
  98. if #disks > 0 then
  99. break
  100. end
  101. -- No boot files found, keep searching
  102. term.clear()
  103. term.setCursorPos(1, 1)
  104. term.setTextColor(colors.red)
  105. term.setBackgroundColor(colors.black)
  106. term.write("No boot files found. Searching...")
  107. sleep(1)
  108. end
  109.  
  110. local selected = 1
  111. drawMenu(disks, selected, nil)
  112.  
  113. while true do
  114. local event, key = os.pullEvent("key")
  115. if key == keys.up then
  116. selected = (selected - 2) % #disks + 1
  117. elseif key == keys.down then
  118. selected = selected % #disks + 1
  119. elseif key == keys.enter then
  120. -- Update the GUI to show booting message
  121. drawMenu(disks, selected, "Booting from " .. disks[selected].path .. "...")
  122. sleep(1) -- Wait for a second to display the booting message
  123.  
  124. -- Set text color to white and background color to black before booting
  125. term.setTextColor(colors.white)
  126. term.setBackgroundColor(colors.black)
  127.  
  128. -- Boot the selected OS
  129. shell.run(disks[selected].path)
  130. break
  131. end
  132. drawMenu(disks, selected, nil) -- Refresh the menu without booting message
  133. end
  134. end
  135.  
  136. main()
  137.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement