Advertisement
DOGGYWOOF

Untitled

Dec 22nd, 2024 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. -- Doggy OS Boot Manager for CC Tweaked (R Key to Refresh, All White Text)
  2.  
  3. local function loadingScreen(message)
  4. term.clear()
  5. term.setCursorPos(1, 1)
  6. term.setTextColor(colors.white)
  7. print("\n\n***** Doggy OS Boot Manager *****\n")
  8. print(message .. "\n")
  9. print("Loading, please wait...\n")
  10. sleep(2) -- Simulate loading time
  11. end
  12.  
  13. local function bootErrorScreen(path)
  14. term.clear()
  15. term.setCursorPos(1, 1)
  16. term.setTextColor(colors.white)
  17. print("\n\n***** Doggy OS Boot Manager *****\n")
  18. print("Error: Failed to boot from:\n")
  19. print(" " .. path .. "\n")
  20. print("Returning to boot menu...\n")
  21. sleep(3) -- Pause to show the error message
  22. end
  23.  
  24. local function findStartupFiles()
  25. local disks = {}
  26. local diskPaths = {"/disk2", "/disk3"} -- Include only /disk2/ and /disk3/
  27.  
  28. -- Search for startup files in specified disk paths
  29. for _, diskPath in ipairs(diskPaths) do
  30. local paths = {
  31. diskPath .. "/startup",
  32. diskPath .. "/startup.lua",
  33. }
  34. for _, path in ipairs(paths) do
  35. if fs.exists(path) then
  36. table.insert(disks, {path = path, displayName = path})
  37. break
  38. end
  39. end
  40. end
  41.  
  42. -- Check /disk/ for /boot/error only
  43. if fs.exists("/disk/boot/error") then
  44. table.insert(disks, {path = "/disk/boot/error", displayName = "Doggy OS"}) -- Doggy OS Device boot file
  45. end
  46.  
  47. return disks
  48. end
  49.  
  50. local function drawMenu(disks, selected, bootingMessage)
  51. term.clear()
  52. term.setCursorPos(1, 1)
  53. term.setTextColor(colors.white)
  54.  
  55. -- Header Section
  56. print("\n\n***** Doggy OS Boot Manager *****\n")
  57. print("Use Arrow keys to navigate, Enter to boot, R to refresh\n")
  58. print("======================================\n")
  59.  
  60. -- Boot options display
  61. for i, disk in ipairs(disks) do
  62. if i == selected then
  63. print("[" .. i .. "] " .. disk.displayName .. " < SELECTED >\n")
  64. else
  65. print("[" .. i .. "] " .. disk.displayName .. "\n")
  66. end
  67. end
  68.  
  69. print("======================================\n")
  70.  
  71. -- Display booting message if available
  72. if bootingMessage then
  73. print("\n" .. bootingMessage .. "\n")
  74. end
  75. end
  76.  
  77. local function main()
  78. loadingScreen("Initializing Doggy OS Boot Manager")
  79.  
  80. local selected = 1
  81. local disks = findStartupFiles()
  82.  
  83. -- Continuously update boot options in a separate coroutine
  84. local updateDisks = coroutine.create(function()
  85. while true do
  86. local newDisks = findStartupFiles()
  87. if #newDisks ~= #disks then
  88. disks = newDisks
  89. if selected > #disks then
  90. selected = 1
  91. end
  92. drawMenu(disks, selected, nil)
  93. end
  94. sleep(0.5)
  95. end
  96. end)
  97.  
  98. -- Start drawing the menu
  99. drawMenu(disks, selected, nil)
  100.  
  101. -- Run the coroutine to update disks and process user input
  102. while true do
  103. coroutine.resume(updateDisks)
  104.  
  105. local event, key = os.pullEvent("key")
  106. if key == keys.up then
  107. selected = (selected - 2) % #disks + 1
  108. elseif key == keys.down then
  109. selected = selected % #disks + 1
  110. elseif key == keys.enter and #disks > 0 then
  111. -- Show booting screen
  112. drawMenu(disks, selected, "Booting from " .. disks[selected].path .. "...\n")
  113. sleep(1) -- Pause to display booting message
  114.  
  115. -- Attempt to boot the selected OS
  116. local ok, err = pcall(function()
  117. shell.run(disks[selected].path)
  118. end)
  119.  
  120. if not ok then
  121. bootErrorScreen(disks[selected].path)
  122. drawMenu(disks, selected, nil) -- Return to menu after error
  123. else
  124. break
  125. end
  126. elseif key == keys.r then
  127. -- Manual refresh using R key
  128. disks = findStartupFiles()
  129. selected = math.min(selected, #disks) -- Ensure selected remains valid
  130. drawMenu(disks, selected, "Boot options refreshed!\n")
  131. end
  132. drawMenu(disks, selected, nil)
  133. end
  134. end
  135.  
  136. main()
  137.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement