Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to check if a file exists
- local function fileExists(path)
- local file = fs.open(path, "r")
- if file then
- file.close()
- return true
- else
- return false
- end
- end
- -- Function to clear the screen
- local function clearScreen()
- term.clear()
- term.setCursorPos(1, 1)
- end
- -- Function to display a styled message
- local function displayMessage(message)
- clearScreen()
- term.setTextColor(colors.lightGray)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, 1)
- print("Doggy OS Developer System Bootloader")
- print("===================================")
- print()
- term.setTextColor(colors.red)
- print("WARNING: UNSTABLE DEVELOPER BUILD")
- term.setTextColor(colors.white)
- print("This bootloader is intended for modifying and testing Doggy OS.")
- print()
- print(message)
- print()
- end
- -- Function to display the GUI
- local function displayGUI(message, options)
- displayMessage(message)
- term.setTextColor(colors.cyan)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, 8)
- print("Select an option:")
- term.setTextColor(colors.yellow)
- local maxOptionWidth = 0
- for _, option in ipairs(options) do
- local optionText = string.format(" %d. %s", _, option)
- if #optionText > maxOptionWidth then
- maxOptionWidth = #optionText
- end
- end
- local baseLine = 9
- for i, option in ipairs(options) do
- local optionText = string.format(" %d. %s", i, option)
- term.setCursorPos(1, baseLine + i)
- print(optionText .. string.rep(" ", maxOptionWidth - #optionText + 2))
- end
- end
- -- Function to shutdown the system
- local function shutdownSystem()
- clearScreen()
- displayMessage("Shutting down the system...")
- sleep(2) -- Simulate shutdown process
- os.shutdown()
- end
- -- Function to handle user choice
- local function getUserChoice(numOptions)
- local choice
- repeat
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, 11 + numOptions)
- print("Enter choice (1-" .. numOptions .. "): ")
- term.setTextColor(colors.yellow)
- choice = tonumber(read())
- until choice and choice >= 1 and choice <= numOptions
- return choice
- end
- -- Main program logic
- local function main()
- local devCfgPath = "dev.cfg"
- local biosPath = "/disk/boot/BIOS"
- -- Check if dev.cfg exists
- if not fileExists(devCfgPath) then
- displayGUI("dev.cfg not found. Please select an option below:", {"Run BIOS"})
- if fileExists(biosPath) then
- shell.run(biosPath)
- else
- displayMessage("Error: BIOS file not found.")
- end
- return
- end
- -- The disk paths to check
- local startupFilePath = "startup"
- local startupFileFound = false
- -- Check if startup file exists
- if fileExists(startupFilePath) or fileExists(startupFilePath .. ".lua") then
- startupFileFound = true
- end
- if startupFileFound then
- displayGUI("Boot Device found. Select an option below:", {"Boot", "Shutdown system"})
- local choice = getUserChoice(2)
- if choice == 1 then
- clearScreen()
- if fileExists(startupFilePath .. ".lua") then
- shell.run(startupFilePath .. ".lua")
- elseif fileExists(startupFilePath) then
- shell.run(startupFilePath)
- end
- elseif choice == 2 then
- shutdownSystem()
- end
- else
- displayGUI("No boot device found. Please select an option below:", {"Run BIOS"})
- if fileExists(biosPath) then
- shell.run(biosPath)
- else
- displayMessage("Error: BIOS file not found.")
- end
- end
- end
- -- Run the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement