Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Doggy OS Full System Recovery with GUI
- -- Create a window with title
- local function createWindow(title)
- local w, h = term.getSize()
- local win = window.create(term.current(), 1, 1, w, h)
- win.setBackgroundColor(colors.black)
- win.clear()
- win.setTextColor(colors.white)
- win.setCursorPos(1, 1)
- win.write(title)
- return win
- end
- -- Show a loading screen with progress
- local function showLoadingScreen(win, message, totalSteps)
- local barLength = 30 -- Length of the loading bar
- win.clear()
- win.setCursorPos(1, 2)
- win.write(message)
- for step = 1, totalSteps do
- win.setCursorPos(1, 3)
- win.write("[")
- for i = 1, barLength do
- if i <= math.floor((step / totalSteps) * barLength) then
- win.write("=") -- Progress part of the bar
- else
- win.write(" ") -- Empty part of the bar
- end
- end
- win.write("] " .. math.floor((step / totalSteps) * 100) .. "%")
- os.sleep(0.3) -- Slow down the animation for better visual effect
- end
- end
- -- Perform an action and show success or error message
- local function performAction(action, win, successMessage, failureMessage)
- win.clear()
- local success, err = pcall(action)
- if success then
- win.setCursorPos(1, 2)
- win.write(successMessage)
- else
- win.setCursorPos(1, 2)
- win.write(failureMessage or "An error occurred: " .. err)
- end
- os.sleep(2)
- end
- -- Recovery options menu
- local function recoveryMenu(win)
- while true do
- win.clear()
- win.setCursorPos(1, 2)
- win.write("===== Recovery Options =====")
- -- Buttons for Recovery Options
- win.setCursorPos(1, 4)
- win.write("[1] Full System Recovery")
- win.setCursorPos(1, 6)
- win.write("[2] Wipe Data / Reset to Factory Defaults")
- win.setCursorPos(1, 8)
- win.write("[3] Back")
- -- Wait for a mouse click event
- local event, button = os.pullEvent("mouse_click")
- local _, y = button[1], button[2]
- -- Button clicks handling based on mouse Y position
- if y == 4 then
- fullSystemRecovery(win)
- elseif y == 6 then
- wipeDataAndResetFactoryDefaults(win)
- elseif y == 8 then
- break
- end
- end
- end
- -- Power menu for Reboot/Shutdown
- local function powerMenu(win)
- win.clear()
- win.setCursorPos(1, 2)
- win.write("===== Power Options =====")
- -- Buttons for Power Options
- win.setCursorPos(1, 4)
- win.write("[1] Reboot System")
- win.setCursorPos(1, 6)
- win.write("[2] Shutdown System")
- -- Wait for a mouse click event
- local event, button = os.pullEvent("mouse_click")
- local _, y = button[1], button[2]
- -- Button clicks handling based on mouse Y position
- if y == 4 then
- os.reboot()
- elseif y == 6 then
- os.shutdown()
- end
- end
- -- Main menu where recovery and power options are presented
- local function mainMenu()
- local w, h = term.getSize()
- local win = createWindow("Doggy OS DEV Recovery GUI")
- while true do
- win.clear()
- win.setCursorPos(1, 2)
- win.write("===== Doggy OS DEV Recovery GUI =====")
- -- Main Menu Buttons
- win.setCursorPos(1, 4)
- win.write("[1] Recovery Options")
- win.setCursorPos(1, 6)
- win.write("[2] Power Options")
- win.setCursorPos(1, 8)
- win.write("[3] Exit")
- -- Wait for a mouse click event
- local event, button = os.pullEvent("mouse_click")
- local _, y = button[1], button[2]
- -- Button clicks handling based on mouse Y position
- if y == 4 then
- recoveryMenu(win)
- elseif y == 6 then
- powerMenu(win)
- elseif y == 8 then
- break
- end
- end
- end
- -- Placeholder functions for fullSystemRecovery and wipeDataAndResetFactoryDefaults
- function fullSystemRecovery(win)
- showLoadingScreen(win, "Performing Full System Recovery...", 10)
- -- Add actual system recovery code here
- performAction(function()
- -- System recovery logic
- end, win, "Full System Recovery Completed.", "Full System Recovery Failed.")
- end
- function wipeDataAndResetFactoryDefaults(win)
- showLoadingScreen(win, "Wiping Data and Resetting to Factory Defaults...", 10)
- -- Add actual wipe/reset logic here
- performAction(function()
- -- Wipe data and reset system
- end, win, "System Reset to Factory Defaults Completed.", "System Reset Failed.")
- end
- -- Start the main menu
- mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement