Advertisement
DOGGYWOOF

Untitled

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