Advertisement
DOGGYWOOF

Untitled

Dec 29th, 2024
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.81 KB | None | 0 0
  1. -- Doggy OS Full System Recovery with Enhanced UI (Including a Loading Bar)
  2.  
  3. local function clearScreen(message)
  4. term.clear()
  5. term.setCursorPos(1, 1)
  6. if message then
  7. print(message)
  8. end
  9. end
  10.  
  11. local function waitForDisk(diskPath, message)
  12. clearScreen(message)
  13. while not fs.exists(diskPath) do
  14. sleep(1)
  15. end
  16. end
  17.  
  18. local function promptForEnter(message)
  19. print(message .. " Press Enter to continue...")
  20. io.read() -- Wait for user to press Enter
  21. end
  22.  
  23. local function askToOverride(filePath)
  24. clearScreen("File " .. filePath .. " already exists.\nDo you want to override it?\n1. Yes\n2. No (Skip)")
  25. local choice = tonumber(io.read())
  26. if choice == 1 then
  27. return true -- User wants to override
  28. else
  29. return false -- User wants to skip
  30. end
  31. end
  32.  
  33. local function performAction(action, successMessage, failureMessage)
  34. clearScreen()
  35. local success, err = pcall(action)
  36. if success then
  37. print(successMessage)
  38. else
  39. print(failureMessage or "An error occurred: " .. err)
  40. promptForEnter("Error detected.")
  41. end
  42. sleep(2)
  43. end
  44.  
  45. -- Define showLoadingScreen function here
  46. local function showLoadingScreen(message, totalSteps)
  47. local barLength = 30 -- Length of the loading bar
  48. clearScreen(message)
  49. for step = 1, totalSteps do
  50. term.setCursorPos(1, 3)
  51. write("[")
  52. for i = 1, barLength do
  53. if i <= math.floor((step / totalSteps) * barLength) then
  54. write("=") -- Progress part of the bar
  55. else
  56. write(" ") -- Empty part of the bar
  57. end
  58. end
  59. write("] " .. math.floor((step / totalSteps) * 100) .. "%")
  60. sleep(0.3) -- Slow down the animation for better visual effect
  61. end
  62. end
  63.  
  64. local function fullSystemRecovery()
  65. performAction(
  66. function()
  67. -- Check for missing or corrupted files in /recovery and copy over from /recovery to /disk
  68. local function checkAndCopyMissingFiles()
  69. local function copyFileIfMissing(sourcePath, targetPath)
  70. -- Only copy the file if it doesn't already exist
  71. if not fs.exists(targetPath) then
  72. print("Copying missing file: " .. sourcePath)
  73. fs.copy(sourcePath, targetPath)
  74. else
  75. print("File already exists, skipping: " .. targetPath)
  76. end
  77. end
  78.  
  79. -- Compare files between /recovery and /disk (except /disk/users/)
  80. local function checkDirectory(sourceDir, targetDir, excludeDir)
  81. local files = fs.list(sourceDir)
  82. for _, file in ipairs(files) do
  83. local sourcePath = fs.combine(sourceDir, file)
  84. local targetPath = fs.combine(targetDir, file)
  85.  
  86. if fs.isDir(sourcePath) then
  87. -- Recursively check directories (except /disk/users/)
  88. if not sourcePath:match(excludeDir) then
  89. checkDirectory(sourcePath, targetPath, excludeDir)
  90. end
  91. else
  92. -- Check and copy missing file
  93. copyFileIfMissing(sourcePath, targetPath)
  94. end
  95. end
  96. end
  97.  
  98. -- Start checking and copying files
  99. checkDirectory("/recovery", "/disk", "/disk/users")
  100. end
  101.  
  102. -- Perform the recovery process
  103. checkAndCopyMissingFiles()
  104. end,
  105.  
  106.  
  107. -- Start loading bar after copying files
  108. showLoadingScreen("Doggy OS System Recovery...", 50) -- 50 steps of progress
  109.  
  110. -- Once loading is done, show final message
  111. clearScreen("Recovery process completed.\nThe system is now restored.")
  112. promptForEnter("Press Enter to exit")
  113. end
  114.  
  115. local function wipeDataAndResetFactoryDefaults()
  116. performAction(
  117. function()
  118. clearScreen("Wiping data and resetting to factory defaults...\nThis may take a while...")
  119.  
  120. -- Delete everything in /disk/ (except for /disk/users/)
  121. if fs.exists("/disk") then
  122. local function deleteDirContent(path, exclude)
  123. local files = fs.list(path)
  124. for _, file in ipairs(files) do
  125. local fullPath = fs.combine(path, file)
  126.  
  127. if fs.isDir(fullPath) then
  128. if exclude and fullPath:sub(1, #exclude) == exclude then
  129. -- Skip /disk/users/
  130. print("Skipping: " .. fullPath)
  131. else
  132. -- Recursively delete directories
  133. deleteDirContent(fullPath, exclude)
  134. end
  135. else
  136. fs.delete(fullPath)
  137. end
  138. end
  139. end
  140. deleteDirContent("/disk", "/disk/users")
  141. end
  142.  
  143. -- Copy files from /.doggyfactorydefaults/ to /disk/
  144. if fs.exists("/.doggyfactorydefaults") then
  145. local function copyDirContent(source, destination)
  146. local files = fs.list(source)
  147. for _, file in ipairs(files) do
  148. local sourcePath = fs.combine(source, file)
  149. local destinationPath = fs.combine(destination, file)
  150.  
  151. -- Debugging information
  152. print("Copying: " .. sourcePath .. " -> " .. destinationPath)
  153.  
  154. if fs.isDir(sourcePath) then
  155. -- Create the directory if it doesn't exist
  156. if not fs.exists(destinationPath) then
  157. fs.makeDir(destinationPath)
  158. end
  159. -- Recursively copy directories
  160. copyDirContent(sourcePath, destinationPath)
  161. else
  162. fs.copy(sourcePath, destinationPath)
  163. end
  164. end
  165. end
  166. copyDirContent("/.doggyfactorydefaults", "/disk")
  167. else
  168. error("Error: /.doggyfactorydefaults not found.")
  169. end
  170.  
  171. -- Simulate a more engaging loading process
  172. showLoadingScreen("Doggy OS Factory Reset...", 50) -- 50 steps of progress
  173.  
  174. -- Transition animation before setup
  175. clearScreen("Preparing for system setup...\nPlease wait...")
  176. local frames = {"|", "/", "-", "\\"}
  177. local frameIndex = 1
  178. for i = 1, 10 do -- Display a spinning animation for 10 iterations
  179. term.setCursorPos(1, 3)
  180. write("Preparing for setup... " .. frames[frameIndex])
  181. sleep(0.3)
  182. frameIndex = (frameIndex % #frames) + 1 -- Cycle through the frames
  183. end
  184.  
  185. -- Show completion message and return to menu
  186. shell.run("/disk/setup")
  187. end,
  188. "Wipe data and reset to factory defaults completed."
  189. )
  190. end
  191.  
  192. local function recoveryMenu()
  193. while true do
  194. clearScreen("===== Recovery Options =====\n1. Full System Recovery\n2. Wipe data / Reset to factory defaults\n3. Back")
  195. local choice = tonumber(io.read())
  196. if choice == 1 then
  197. fullSystemRecovery()
  198. elseif choice == 2 then
  199. wipeDataAndResetFactoryDefaults()
  200. elseif choice == 3 then
  201. break
  202. else
  203. clearScreen("Invalid choice. Please try again.")
  204. sleep(2)
  205. end
  206. end
  207. end
  208.  
  209. local function powerMenu()
  210. clearScreen("===== Power Options =====\n1. Reboot system\n2. Shutdown system")
  211. local choice = tonumber(io.read())
  212. if choice == 1 then
  213. os.reboot()
  214. elseif choice == 2 then
  215. os.shutdown()
  216. else
  217. clearScreen("Invalid choice. Please try again.")
  218. sleep(2)
  219. end
  220. end
  221.  
  222. local function mainMenu()
  223. while true do
  224. clearScreen("===== Doggy OS DEV Recovery GUI =====\n1. Recovery Options\n2. Power Options\n3. Exit")
  225. local choice = tonumber(io.read())
  226. if choice == 1 then
  227. recoveryMenu()
  228. elseif choice == 2 then
  229. powerMenu()
  230. elseif choice == 3 then
  231. break
  232. else
  233. clearScreen("Invalid choice. Please try again.")
  234. sleep(2)
  235. end
  236. end
  237. end
  238.  
  239. -- Start the main menu
  240. mainMenu()
  241.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement