Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Helper function to display loading bar
- local function displayLoadingBar(message, duration)
- -- Clear the screen and set up colors
- term.clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- -- Define the width and height of the screen
- local width, height = term.getSize()
- -- Center the message above the loading bar
- local function centerText(y, text, textColor)
- local x = math.floor((width - #text) / 2)
- term.setCursorPos(x, y)
- term.setTextColor(textColor)
- term.write(text)
- end
- -- Display the message
- -- Loading bar variables
- local barWidth = math.floor(width * 0.6)
- local startX = math.floor((width - barWidth) / 2)
- local barY = height // 2
- local loadingSteps = 20
- local timePerStep = duration / loadingSteps
- -- Draw loading bar
- for i = 1, loadingSteps do
- term.setCursorPos(startX, barY)
- term.write("[")
- term.setCursorPos(startX + barWidth - 1, barY)
- term.write("]")
- -- Draw the loading progress
- local progress = math.floor((i / loadingSteps) * (barWidth - 2))
- term.setCursorPos(startX + 1, barY)
- term.write(string.rep("=", progress))
- -- Pause for visual effect
- sleep(timePerStep)
- end
- end
- -- Repair Bootloader Function with Loading Bar
- local function repairBootloader()
- displayLoadingBar("Repairing System Bootloader...", 10)
- -- Delete existing startup and no-os files
- fs.delete("/startup")
- fs.delete("/no-os")
- -- Copy the recovery files to the root directory
- fs.copy("/recovery/boot/error", "/startup")
- fs.copy("/recovery/bootloader/no-os.lua", "/no-os")
- -- Display the "Repair Completed. Rebooting..." message in white
- displayMessage("Repair Completed. Rebooting...")
- -- Wait for 3 seconds before rebooting
- sleep(3)
- -- Reboot the system
- os.reboot()
- end
- -- Recovery from /recovery Function with Loading Bar
- local function recoverFromRecovery()
- displayLoadingBar("Repairing File System...", 10)
- -- Delete existing disk directory and copy files from /recovery
- fs.delete("/disk/")
- fs.copy("/recovery/", "/disk/")
- -- Display the "Recovery Completed. Rebooting..." message in white
- displayMessage("Recovery Completed. Rebooting...")
- -- Wait for 3 seconds before rebooting
- sleep(3)
- -- Reboot the system
- os.reboot()
- end
- -- Recovery from External Source Function with Loading Bar
- local function recoverFromExternalSource()
- displayLoadingBar("Installing System Update from /disk2/", 10)
- -- Check if /disk2 exists before copying
- if fs.exists("/disk2/") then
- fs.delete("/disk/")
- fs.copy("/disk2/", "/disk/")
- -- Display the "Update Completed. Rebooting..." message in white
- displayMessage("Update Completed. Rebooting...")
- else
- -- Display an error message if /disk2 does not exist
- displayMessage("Error: /disk2 does not exist.", colors.red)
- end
- -- Wait for 3 seconds before rebooting
- sleep(3)
- -- Reboot the system
- os.reboot()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement