Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Doggy OS Boot Manager for CC Tweaked
- 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)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.blue)
- term.setBackgroundColor(colors.black)
- term.clearLine()
- term.write(" Doggy OS Boot Manager ")
- term.setCursorPos(1, 2)
- term.setTextColor(colors.lightGray)
- term.clearLine()
- term.write("Use Arrow keys to navigate, Enter to boot")
- term.setCursorPos(1, 3)
- term.setTextColor(colors.gray)
- term.clearLine()
- term.write("------------------------------------------------")
- for i, disk in ipairs(disks) do
- term.setCursorPos(1, 3 + i)
- if i == selected then
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.blue)
- else
- term.setTextColor(colors.lightGray)
- term.setBackgroundColor(colors.black)
- end
- term.clearLine()
- term.write(" [" .. i .. "] " .. disk.displayName)
- end
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- end
- local function main()
- local disks
- while true do
- disks = findStartupFiles()
- if #disks > 0 then
- break
- end
- -- No boot files found, keep searching
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.red)
- term.setBackgroundColor(colors.black)
- term.write("No boot files found. Searching...")
- sleep(1)
- end
- local selected = 1
- drawMenu(disks, selected)
- while true do
- 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 then
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.cyan)
- print("Booting from " .. disks[selected].path .. "...")
- term.setTextColor(colors.white)
- sleep(1)
- shell.run(disks[selected].path)
- break
- end
- drawMenu(disks, selected)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement