Advertisement
DOGGYWOOF

DOGGY OS BOOT MANAGER

Oct 13th, 2024 (edited)
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 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, bootingMessage)
  30. term.clear()
  31. term.setCursorPos(1, 1)
  32. term.setTextColor(colors.blue)
  33. term.setBackgroundColor(colors.black)
  34.  
  35. -- Draw Header
  36. term.setCursorPos(1, 1)
  37. term.write(" ***** Doggy OS Boot Manager ***** ")
  38.  
  39. term.setCursorPos(1, 3)
  40. term.setTextColor(colors.lightGray)
  41. term.write("Use Arrow keys to navigate, Enter to boot")
  42.  
  43. term.setCursorPos(1, 5)
  44. term.setTextColor(colors.gray)
  45. term.write("======================================")
  46.  
  47. -- Draw boot options
  48. for i, disk in ipairs(disks) do
  49. term.setCursorPos(1, 6 + i)
  50. if i == selected then
  51. term.setTextColor(colors.white)
  52. term.setBackgroundColor(colors.blue)
  53. else
  54. term.setTextColor(colors.lightGray)
  55. term.setBackgroundColor(colors.black)
  56. end
  57. term.write(" [" .. i .. "] " .. disk.displayName)
  58. term.setTextColor(colors.white) -- Reset text color after writing
  59. end
  60.  
  61. term.setTextColor(colors.white)
  62. term.setBackgroundColor(colors.black)
  63.  
  64. term.setCursorPos(1, 6 + #disks + 7)
  65. term.setTextColor(colors.gray)
  66. term.write("======================================")
  67.  
  68. -- Display booting message if available
  69. if bootingMessage then
  70. term.setCursorPos(1, 8 + #disks + 7)
  71. term.setTextColor(colors.cyan)
  72. term.write(bootingMessage)
  73. end
  74. end
  75.  
  76. local function main()
  77. local disks
  78. while true do
  79. disks = findStartupFiles()
  80. if #disks > 0 then
  81. break
  82. end
  83. -- No boot files found, keep searching
  84. term.clear()
  85. term.setCursorPos(1, 1)
  86. term.setTextColor(colors.red)
  87. term.setBackgroundColor(colors.black)
  88. term.write("No boot files found. Searching...")
  89. sleep(1)
  90. end
  91.  
  92. local selected = 1
  93. drawMenu(disks, selected, nil)
  94.  
  95. while true do
  96. local event, key = os.pullEvent("key")
  97. if key == keys.up then
  98. selected = (selected - 2) % #disks + 1
  99. elseif key == keys.down then
  100. selected = selected % #disks + 1
  101. elseif key == keys.enter then
  102. -- Update the GUI to show booting message
  103. drawMenu(disks, selected, "Booting from " .. disks[selected].path .. "...")
  104. sleep(1) -- Wait for a second to display the booting message
  105.  
  106. -- Set text color to white and background color to black before booting
  107. term.setTextColor(colors.white)
  108. term.setBackgroundColor(colors.black)
  109.  
  110. -- Boot the selected OS
  111. shell.run(disks[selected].path)
  112. break
  113. end
  114. drawMenu(disks, selected, nil) -- Refresh the menu without booting message
  115. end
  116. end
  117.  
  118. main()
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement