Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define GUI colors
- local bgColor = colors.black
- local fgColor = colors.white
- local buttonColor = colors.blue
- local buttonTextColor = colors.white
- local errorColor = colors.red
- local boxBgColor = colors.gray
- local primaryDiskFile = "/disk/primary_disk.txt"
- -- Function to clear the screen and set background color
- local function clearScreen()
- term.setBackgroundColor(bgColor)
- term.setTextColor(fgColor)
- term.clear()
- term.setCursorPos(1, 1)
- end
- -- Function to draw the title bar
- local function drawTitleBar()
- term.setBackgroundColor(colors.cyan)
- term.setTextColor(colors.white)
- term.setCursorPos(1, 1)
- term.clearLine()
- term.write("Doggy OS Legacy Bootloader")
- term.setBackgroundColor(bgColor)
- term.setTextColor(fgColor)
- term.setCursorPos(1, 2)
- end
- -- Function to draw a message box
- local function drawMessageBox(title, message, buttonText)
- term.setBackgroundColor(bgColor)
- term.setTextColor(fgColor)
- local width, height = term.getSize()
- -- Draw the box
- local boxWidth = width - 4
- local boxHeight = 5
- local boxX = 2
- local boxY = math.floor((height - boxHeight) / 2)
- paintutils.drawFilledBox(boxX, boxY, boxX + boxWidth, boxY + boxHeight, boxBgColor)
- term.setBackgroundColor(boxBgColor)
- term.setTextColor(fgColor)
- term.setCursorPos(boxX + 2, boxY + 1)
- term.write(title)
- term.setBackgroundColor(boxBgColor)
- term.setTextColor(fgColor)
- term.setCursorPos(boxX + 2, boxY + 2)
- term.write(message)
- term.setBackgroundColor(buttonColor)
- term.setTextColor(buttonTextColor)
- term.setCursorPos(boxX + 2, boxY + boxHeight - 1)
- term.write(" " .. buttonText .. " ")
- end
- -- Function to show the boot menu
- local function showBootMenu(bootOptions)
- clearScreen()
- drawTitleBar()
- term.setBackgroundColor(boxBgColor)
- term.setTextColor(fgColor)
- local width, height = term.getSize()
- local menuX = 2
- local menuY = 3
- local boxWidth = width - 4
- local boxHeight = #bootOptions + 4
- paintutils.drawFilledBox(menuX, menuY, menuX + boxWidth, menuY + boxHeight, boxBgColor)
- term.setCursorPos(menuX + 2, menuY + 1)
- term.write("Boot Menu")
- for i, option in ipairs(bootOptions) do
- term.setCursorPos(menuX + 2, menuY + i + 1)
- term.write(i .. ". " .. option.name)
- end
- term.setCursorPos(menuX + 2, menuY + boxHeight)
- term.write("Select an option: ")
- local selectedOption = tonumber(read())
- if selectedOption and selectedOption >= 1 and selectedOption <= #bootOptions then
- local selectedDisk = bootOptions[selectedOption].disk
- local bootPath = bootOptions[selectedOption].path
- -- Save selected disk as primary
- fs.delete(primaryDiskFile) -- Remove old primary disk file if exists
- local file = fs.open(primaryDiskFile, "w")
- file.write(selectedDisk)
- file.close()
- -- Run the boot file
- shell.run(bootPath)
- else
- drawMessageBox("Invalid Option", "Selected option is not valid.", "Press enter to return...")
- read() -- Wait for user input to return
- bootloader()
- end
- end
- -- Function to determine the primary disk
- local function getPrimaryDisk()
- if fs.exists(primaryDiskFile) then
- local file = fs.open(primaryDiskFile, "r")
- local disk = file.readAll()
- file.close()
- return disk
- end
- return "/disk" -- Default to /disk if no primary disk file exists
- end
- -- Main bootloader function
- local function bootloader()
- clearScreen()
- drawTitleBar()
- drawMessageBox("Booting...", "Attempting to boot your OS.", "Please wait...")
- sleep(0.7)
- -- Simulated boot process
- sleep(2)
- local primaryDisk = getPrimaryDisk()
- local bootOptions = {}
- local diskPaths = {primaryDisk.."/boot", "/disk2/boot"}
- for _, path in ipairs(diskPaths) do
- if fs.exists(path.."/error") then
- table.insert(bootOptions, {name = "Error", path = path.."/error", disk = path:match("/disk%d?")})
- end
- if fs.exists(path.."/startup") then
- table.insert(bootOptions, {name = "Startup", path = path.."/startup", disk = path:match("/disk%d?")})
- end
- if fs.exists(path.."/startup.lua") then
- table.insert(bootOptions, {name = "Startup.lua", path = path.."/startup.lua", disk = path:match("/disk%d?")})
- end
- end
- if #bootOptions == 0 then
- clearScreen()
- drawTitleBar()
- drawMessageBox("Startup Error", "No boot files detected.", "Press enter to reboot...")
- read() -- Wait for user input to reboot
- os.reboot()
- elseif #bootOptions == 1 then
- shell.run(bootOptions[1].path)
- else
- showBootMenu(bootOptions)
- end
- end
- bootloader()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement