Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Doggy OS Full System Recovery with Enhanced UI (Including a Loading Bar)
- local function clearScreen(message)
- term.clear()
- term.setCursorPos(1, 1)
- if message then
- print(message)
- end
- end
- local function waitForDisk(diskPath, message)
- clearScreen(message)
- while not fs.exists(diskPath) do
- sleep(1)
- end
- end
- local function promptForEnter(message)
- print(message .. " Press Enter to continue...")
- io.read() -- Wait for user to press Enter
- end
- local function askToOverride(filePath)
- clearScreen("File " .. filePath .. " already exists.\nDo you want to override it?\n1. Yes\n2. No (Skip)")
- local choice = tonumber(io.read())
- if choice == 1 then
- return true -- User wants to override
- else
- return false -- User wants to skip
- end
- end
- local function performAction(action, successMessage, failureMessage)
- clearScreen()
- local success, err = pcall(action)
- if success then
- print(successMessage)
- else
- print(failureMessage or "An error occurred: " .. err)
- promptForEnter("Error detected.")
- end
- sleep(2)
- end
- -- Define showLoadingScreen function here
- local function showLoadingScreen(message, totalSteps)
- local barLength = 30 -- Length of the loading bar
- clearScreen(message)
- for step = 1, totalSteps do
- term.setCursorPos(1, 3)
- write("[")
- for i = 1, barLength do
- if i <= math.floor((step / totalSteps) * barLength) then
- write("=") -- Progress part of the bar
- else
- write(" ") -- Empty part of the bar
- end
- end
- write("] " .. math.floor((step / totalSteps) * 100) .. "%")
- sleep(0.3) -- Slow down the animation for better visual effect
- end
- end
- local function fullSystemRecovery()
- performAction(
- function()
- -- Check for missing or corrupted files in /recovery and copy over from /recovery to /disk
- local function checkAndCopyMissingFiles()
- local function copyFileIfMissing(sourcePath, targetPath)
- -- Only copy the file if it doesn't already exist
- if not fs.exists(targetPath) then
- print("Copying missing file: " .. sourcePath)
- fs.copy(sourcePath, targetPath)
- else
- print("File already exists, skipping: " .. targetPath)
- end
- end
- -- Compare files between /recovery and /disk (except /disk/users/)
- local function checkDirectory(sourceDir, targetDir, excludeDir)
- local files = fs.list(sourceDir)
- for _, file in ipairs(files) do
- local sourcePath = fs.combine(sourceDir, file)
- local targetPath = fs.combine(targetDir, file)
- if fs.isDir(sourcePath) then
- -- Recursively check directories (except /disk/users/)
- if not sourcePath:match(excludeDir) then
- checkDirectory(sourcePath, targetPath, excludeDir)
- end
- else
- -- Check and copy missing file
- copyFileIfMissing(sourcePath, targetPath)
- end
- end
- end
- -- Start checking and copying files
- checkDirectory("/recovery", "/disk", "/disk/users")
- end
- -- Perform the recovery process
- checkAndCopyMissingFiles()
- end,
- "Full System Recovery completed."
- )
- -- Start loading bar after copying files
- showLoadingScreen("Doggy OS System Recovery...", 50) -- 50 steps of progress
- -- Once loading is done, show final message
- clearScreen("Recovery process completed.\nThe system is now restored.")
- promptForEnter("Press Enter to exit")
- end
- local function wipeDataAndResetFactoryDefaults()
- performAction(
- function()
- clearScreen("Wiping data and resetting to factory defaults...\nThis may take a while...")
- -- Delete everything in /disk/ (except for /disk/users/)
- if fs.exists("/disk") then
- local function deleteDirContent(path, exclude)
- local files = fs.list(path)
- for _, file in ipairs(files) do
- local fullPath = fs.combine(path, file)
- if fs.isDir(fullPath) then
- if exclude and fullPath:sub(1, #exclude) == exclude then
- -- Skip /disk/users/
- print("Skipping: " .. fullPath)
- else
- -- Recursively delete directories
- deleteDirContent(fullPath, exclude)
- end
- else
- fs.delete(fullPath)
- end
- end
- end
- deleteDirContent("/disk", "/disk/users")
- end
- -- Copy files from /.doggyfactorydefaults/ to /disk/
- if fs.exists("/.doggyfactorydefaults") then
- local function copyDirContent(source, destination)
- local files = fs.list(source)
- for _, file in ipairs(files) do
- local sourcePath = fs.combine(source, file)
- local destinationPath = fs.combine(destination, file)
- -- Debugging information
- print("Copying: " .. sourcePath .. " -> " .. destinationPath)
- if fs.isDir(sourcePath) then
- -- Create the directory if it doesn't exist
- if not fs.exists(destinationPath) then
- fs.makeDir(destinationPath)
- end
- -- Recursively copy directories
- copyDirContent(sourcePath, destinationPath)
- else
- fs.copy(sourcePath, destinationPath)
- end
- end
- end
- copyDirContent("/.doggyfactorydefaults", "/disk")
- else
- error("Error: /.doggyfactorydefaults not found.")
- end
- -- Simulate a more engaging loading process
- showLoadingScreen("Doggy OS Factory Reset...", 50) -- 50 steps of progress
- -- Transition animation before setup
- clearScreen("Preparing for system setup...\nPlease wait...")
- local frames = {"|", "/", "-", "\\"}
- local frameIndex = 1
- for i = 1, 10 do -- Display a spinning animation for 10 iterations
- term.setCursorPos(1, 3)
- write("Preparing for setup... " .. frames[frameIndex])
- sleep(0.3)
- frameIndex = (frameIndex % #frames) + 1 -- Cycle through the frames
- end
- -- Show completion message and return to menu
- shell.run("/disk/setup")
- end,
- "Wipe data and reset to factory defaults completed."
- )
- end
- local function recoveryMenu()
- while true do
- clearScreen("===== Recovery Options =====\n1. Full System Recovery\n2. Wipe data / Reset to factory defaults\n")
- local choice = tonumber(io.read())
- if choice == 1 then
- fullSystemRecovery()
- elseif choice == 2 then
- wipeDataAndResetFactoryDefaults()
- elseif choice == 3 then
- break
- else
- clearScreen("Invalid choice. Please try again.")
- sleep(2)
- end
- end
- end
- local function powerMenu()
- clearScreen("===== Power Options =====\n1. Reboot system\n2. Shutdown system")
- local choice = tonumber(io.read())
- if choice == 1 then
- os.reboot()
- elseif choice == 2 then
- os.shutdown()
- else
- clearScreen("Invalid choice. Please try again.")
- sleep(2)
- end
- end
- local function mainMenu()
- while true do
- clearScreen("===== Doggy OS DEV Recovery GUI =====\n1. Recovery Options\n2. Power Options\n3. Exit")
- local choice = tonumber(io.read())
- if choice == 1 then
- recoveryMenu()
- elseif choice == 2 then
- powerMenu()
- else
- clearScreen("Invalid choice. Please try again.")
- sleep(2)
- end
- end
- end
- -- Start the main menu
- mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement