Advertisement
DOGGYWOOF

Doggy OS 13.0 New Recovery

Dec 29th, 2024 (edited)
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.79 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. "Full System Recovery completed."
  106. )
  107.  
  108. -- Start loading bar after copying files
  109. showLoadingScreen("Doggy OS System Recovery...", 50) -- 50 steps of progress
  110.  
  111. -- Once loading is done, show final message
  112. clearScreen("Recovery process completed.\nThe system is now restored.")
  113. promptForEnter("Press Enter to exit")
  114. end
  115.  
  116. local function wipeDataAndResetFactoryDefaults()
  117. performAction(
  118. function()
  119. clearScreen("Wiping data and resetting to factory defaults...\nThis may take a while...")
  120.  
  121. -- Delete everything in /disk/ (except for /disk/users/)
  122. if fs.exists("/disk") then
  123. local function deleteDirContent(path, exclude)
  124. local files = fs.list(path)
  125. for _, file in ipairs(files) do
  126. local fullPath = fs.combine(path, file)
  127.  
  128. if fs.isDir(fullPath) then
  129. if exclude and fullPath:sub(1, #exclude) == exclude then
  130. -- Skip /disk/users/
  131. print("Skipping: " .. fullPath)
  132. else
  133. -- Recursively delete directories
  134. deleteDirContent(fullPath, exclude)
  135. end
  136. else
  137. fs.delete(fullPath)
  138. end
  139. end
  140. end
  141. deleteDirContent("/disk", "/disk/users")
  142. end
  143.  
  144. -- Copy files from /.doggyfactorydefaults/ to /disk/
  145. if fs.exists("/.doggyfactorydefaults") then
  146. local function copyDirContent(source, destination)
  147. local files = fs.list(source)
  148. for _, file in ipairs(files) do
  149. local sourcePath = fs.combine(source, file)
  150. local destinationPath = fs.combine(destination, file)
  151.  
  152. -- Debugging information
  153. print("Copying: " .. sourcePath .. " -> " .. destinationPath)
  154.  
  155. if fs.isDir(sourcePath) then
  156. -- Create the directory if it doesn't exist
  157. if not fs.exists(destinationPath) then
  158. fs.makeDir(destinationPath)
  159. end
  160. -- Recursively copy directories
  161. copyDirContent(sourcePath, destinationPath)
  162. else
  163. fs.copy(sourcePath, destinationPath)
  164. end
  165. end
  166. end
  167. copyDirContent("/.doggyfactorydefaults", "/disk")
  168. else
  169. error("Error: /.doggyfactorydefaults not found.")
  170. end
  171.  
  172. -- Simulate a more engaging loading process
  173. showLoadingScreen("Doggy OS Factory Reset...", 50) -- 50 steps of progress
  174.  
  175. -- Transition animation before setup
  176. clearScreen("Preparing for system setup...\nPlease wait...")
  177. local frames = {"|", "/", "-", "\\"}
  178. local frameIndex = 1
  179. for i = 1, 10 do -- Display a spinning animation for 10 iterations
  180. term.setCursorPos(1, 3)
  181. write("Preparing for setup... " .. frames[frameIndex])
  182. sleep(0.3)
  183. frameIndex = (frameIndex % #frames) + 1 -- Cycle through the frames
  184. end
  185.  
  186. -- Show completion message and return to menu
  187. shell.run("/disk/setup")
  188. end,
  189. "Wipe data and reset to factory defaults completed."
  190. )
  191. end
  192.  
  193. local function recoveryMenu()
  194. while true do
  195. clearScreen("===== Recovery Options =====\n1. Full System Recovery\n2. Wipe data / Reset to factory defaults\n")
  196. local choice = tonumber(io.read())
  197. if choice == 1 then
  198. fullSystemRecovery()
  199. elseif choice == 2 then
  200. wipeDataAndResetFactoryDefaults()
  201. elseif choice == 3 then
  202. break
  203. else
  204. clearScreen("Invalid choice. Please try again.")
  205. sleep(2)
  206. end
  207. end
  208. end
  209.  
  210. local function powerMenu()
  211. clearScreen("===== Power Options =====\n1. Reboot system\n2. Shutdown system")
  212. local choice = tonumber(io.read())
  213. if choice == 1 then
  214. os.reboot()
  215. elseif choice == 2 then
  216. os.shutdown()
  217. else
  218. clearScreen("Invalid choice. Please try again.")
  219. sleep(2)
  220. end
  221. end
  222.  
  223. local function mainMenu()
  224. while true do
  225. clearScreen("===== Doggy OS DEV Recovery GUI =====\n1. Recovery Options\n2. Power Options\n3. Exit")
  226. local choice = tonumber(io.read())
  227. if choice == 1 then
  228. recoveryMenu()
  229. elseif choice == 2 then
  230. powerMenu()
  231. else
  232. clearScreen("Invalid choice. Please try again.")
  233. sleep(2)
  234. end
  235. end
  236. end
  237.  
  238. -- Start the main menu
  239. mainMenu()
  240.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement