Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Doggy OS Boot Manager for CC Tweaked (R Key to Refresh, All White Text)
- local function loadingScreen(message)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.white)
- print("\n\n***** Doggy OS Boot Manager *****\n")
- print(message .. "\n")
- print("Loading, please wait...\n")
- sleep(2) -- Simulate loading time
- end
- local function bootErrorScreen(path)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.white)
- print("\n\n***** Doggy OS Boot Manager *****\n")
- print("Error: Failed to boot from:\n")
- print(" " .. path .. "\n")
- print("Returning to boot menu...\n")
- sleep(3) -- Pause to show the error message
- end
- local function findStartupFiles()
- local disks = {}
- local diskPaths = {"/disk2", "/disk3"} -- Include only /disk2/ and /disk3/
- -- Search for startup files in specified disk paths
- for _, diskPath in ipairs(diskPaths) do
- local paths = {
- diskPath .. "/startup",
- diskPath .. "/startup.lua",
- }
- for _, path in ipairs(paths) do
- if fs.exists(path) then
- table.insert(disks, {path = path, displayName = path})
- break
- end
- end
- end
- -- Check /disk/ for /boot/error only
- if fs.exists("/disk/boot/error") then
- table.insert(disks, {path = "/disk/boot/error", displayName = "Doggy OS"}) -- Doggy OS Device boot file
- end
- return disks
- end
- local function drawMenu(disks, selected, bootingMessage)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.white)
- -- Header Section
- print("\n\n***** Doggy OS Boot Manager *****\n")
- print("Use Arrow keys to navigate, Enter to boot, R to refresh\n")
- print("======================================\n")
- -- Boot options display
- for i, disk in ipairs(disks) do
- if i == selected then
- print("[" .. i .. "] " .. disk.displayName .. " < SELECTED >\n")
- else
- print("[" .. i .. "] " .. disk.displayName .. "\n")
- end
- end
- print("======================================\n")
- -- Display booting message if available
- if bootingMessage then
- print("\n" .. bootingMessage .. "\n")
- end
- end
- local function main()
- loadingScreen("Initializing Doggy OS Boot Manager")
- local selected = 1
- local disks = findStartupFiles()
- -- Continuously update boot options in a separate coroutine
- local updateDisks = coroutine.create(function()
- while true do
- local newDisks = findStartupFiles()
- if #newDisks ~= #disks then
- disks = newDisks
- if selected > #disks then
- selected = 1
- end
- drawMenu(disks, selected, nil)
- end
- sleep(0.5)
- end
- end)
- -- Start drawing the menu
- drawMenu(disks, selected, nil)
- -- Run the coroutine to update disks and process user input
- while true do
- coroutine.resume(updateDisks)
- local event, key = os.pullEvent("key")
- if key == keys.up then
- selected = (selected - 2) % #disks + 1
- elseif key == keys.down then
- selected = selected % #disks + 1
- elseif key == keys.enter and #disks > 0 then
- -- Show booting screen
- drawMenu(disks, selected, "Booting from " .. disks[selected].path .. "...\n")
- sleep(1) -- Pause to display booting message
- -- Attempt to boot the selected OS
- local ok, err = pcall(function()
- shell.run(disks[selected].path)
- end)
- if not ok then
- bootErrorScreen(disks[selected].path)
- drawMenu(disks, selected, nil) -- Return to menu after error
- else
- break
- end
- elseif key == keys.r then
- -- Manual refresh using R key
- disks = findStartupFiles()
- selected = math.min(selected, #disks) -- Ensure selected remains valid
- drawMenu(disks, selected, "Boot options refreshed!\n")
- end
- drawMenu(disks, selected, nil)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement