Advertisement
DOGGYWOOF

Untitled

Oct 13th, 2024 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 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. return disks
  27. end
  28.  
  29. local function drawMenu(disks, selected)
  30. term.clear()
  31. term.setCursorPos(1, 1)
  32. term.setTextColor(colors.blue)
  33. term.setBackgroundColor(colors.black)
  34. term.clearLine()
  35. term.write(" Doggy OS Boot Manager ")
  36.  
  37. term.setCursorPos(1, 2)
  38. term.setTextColor(colors.lightGray)
  39. term.clearLine()
  40. term.write("Use Arrow keys to navigate, Enter to boot")
  41.  
  42. term.setCursorPos(1, 3)
  43. term.setTextColor(colors.gray)
  44. term.clearLine()
  45. term.write("------------------------------------------------")
  46.  
  47. for i, disk in ipairs(disks) do
  48. term.setCursorPos(1, 3 + i)
  49. if i == selected then
  50. term.setTextColor(colors.white)
  51. term.setBackgroundColor(colors.blue)
  52. else
  53. term.setTextColor(colors.lightGray)
  54. term.setBackgroundColor(colors.black)
  55. end
  56. term.clearLine()
  57. term.write(" [" .. i .. "] " .. disk.displayName)
  58. end
  59.  
  60. term.setTextColor(colors.white)
  61. term.setBackgroundColor(colors.black)
  62. end
  63.  
  64. local function main()
  65. local disks
  66. while true do
  67. disks = findStartupFiles()
  68. if #disks > 0 then
  69. break
  70. end
  71. -- No boot files found, keep searching
  72. term.clear()
  73. term.setCursorPos(1, 1)
  74. term.setTextColor(colors.red)
  75. term.setBackgroundColor(colors.black)
  76. term.write("No boot files found. Searching...")
  77. sleep(1)
  78. end
  79.  
  80. local selected = 1
  81. drawMenu(disks, selected)
  82.  
  83. while true do
  84. local event, key = os.pullEvent("key")
  85. if key == keys.up then
  86. selected = (selected - 2) % #disks + 1
  87. elseif key == keys.down then
  88. selected = selected % #disks + 1
  89. elseif key == keys.enter then
  90. term.clear()
  91. term.setCursorPos(1, 1)
  92. term.setTextColor(colors.cyan)
  93. print("Booting from " .. disks[selected].path .. "...")
  94. term.setTextColor(colors.white)
  95. sleep(1)
  96. shell.run(disks[selected].path)
  97. break
  98. end
  99. drawMenu(disks, selected)
  100. end
  101. end
  102.  
  103. main()
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement