Advertisement
DOGGYWOOF

Doggy OS beta recovery

Dec 28th, 2024 (edited)
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.38 KB | None | 0 0
  1. -- Doggy OS Recovery
  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. local function fullSystemRecovery()
  46. performAction(
  47. function()
  48. -- Check for missing or corrupted files in /recovery and copy over from /recovery to /disk
  49. local function checkAndCopyMissingFiles()
  50. local function copyFileIfMissing(sourcePath, targetPath)
  51. -- Only copy the file if it doesn't already exist
  52. if not fs.exists(targetPath) then
  53. print("Copying missing file: " .. sourcePath)
  54. fs.copy(sourcePath, targetPath)
  55. else
  56. print("File already exists, skipping: " .. targetPath)
  57. end
  58. end
  59.  
  60. -- Compare files between /recovery and /disk (except /disk/users/)
  61. local function checkDirectory(sourceDir, targetDir, excludeDir)
  62. local files = fs.list(sourceDir)
  63. for _, file in ipairs(files) do
  64. local sourcePath = fs.combine(sourceDir, file)
  65. local targetPath = fs.combine(targetDir, file)
  66.  
  67. if fs.isDir(sourcePath) then
  68. -- Recursively check directories (except /disk/users/)
  69. if not sourcePath:match(excludeDir) then
  70. checkDirectory(sourcePath, targetPath, excludeDir)
  71. end
  72. else
  73. -- Check and copy missing file
  74. copyFileIfMissing(sourcePath, targetPath)
  75. end
  76. end
  77. end
  78.  
  79. -- Start checking and copying files
  80. checkDirectory("/recovery", "/disk", "/disk/users")
  81. end
  82.  
  83. -- Perform the recovery process
  84. checkAndCopyMissingFiles()
  85. end,
  86. "Full System Recovery completed."
  87. )
  88. end
  89.  
  90. local function wipeDataAndResetFactoryDefaults()
  91. performAction(
  92. function()
  93. clearScreen("Wiping data and resetting to factory defaults...\nThis may take a while...")
  94.  
  95. -- Delete everything in /disk/ (except for /disk/users/)
  96. if fs.exists("/disk") then
  97. local function deleteDirContent(path, exclude)
  98. local files = fs.list(path)
  99. for _, file in ipairs(files) do
  100. local fullPath = fs.combine(path, file)
  101.  
  102. if fs.isDir(fullPath) then
  103. if exclude and fullPath:sub(1, #exclude) == exclude then
  104. -- Skip /disk/users/
  105. print("Skipping: " .. fullPath)
  106. else
  107. -- Recursively delete directories
  108. deleteDirContent(fullPath, exclude)
  109. end
  110. else
  111. fs.delete(fullPath)
  112. end
  113. end
  114. end
  115. deleteDirContent("/disk", "/disk/users")
  116. end
  117.  
  118. -- Copy files from /.doggyfactorydefaults/ to /disk/
  119. if fs.exists("/.doggyfactorydefaults") then
  120. local function copyDirContent(source, destination)
  121. local files = fs.list(source)
  122. for _, file in ipairs(files) do
  123. local sourcePath = fs.combine(source, file)
  124. local destinationPath = fs.combine(destination, file)
  125.  
  126. -- Debugging information
  127. print("Copying: " .. sourcePath .. " -> " .. destinationPath)
  128.  
  129. if fs.isDir(sourcePath) then
  130. -- Create the directory if it doesn't exist
  131. if not fs.exists(destinationPath) then
  132. fs.makeDir(destinationPath)
  133. end
  134. -- Recursively copy directories
  135. copyDirContent(sourcePath, destinationPath)
  136. else
  137. fs.copy(sourcePath, destinationPath)
  138. end
  139. end
  140. end
  141. copyDirContent("/.doggyfactorydefaults", "/disk")
  142. else
  143. error("Error: /.doggyfactorydefaults not found.")
  144. end
  145.  
  146. -- Simulate loading bar and notify the user
  147. clearScreen("Resetting this PC...\nPlease wait...")
  148. local barLength = 45 -- Adjusted to 45 characters
  149. for i = 1, barLength do
  150. term.setCursorPos(1, 4)
  151. write("[")
  152. for j = 1, barLength do
  153. if j <= i then
  154. write("=")
  155. else
  156. write(" ")
  157. end
  158. end
  159. write("] " .. math.floor(i / barLength * 100) .. "%")
  160. sleep(0.1) -- Slower loading bar for better UI experience
  161. end
  162. sleep(1) -- Add a small pause after the loading bar
  163.  
  164. -- Transition animation before setup
  165. clearScreen("Preparing for system setup...\nPlease wait...")
  166. local frames = {"|", "/", "-", "\\"}
  167. local frameIndex = 1
  168. for i = 1, 10 do -- Display a spinning animation for 10 iterations
  169. term.setCursorPos(1, 6)
  170. write("Preparing for setup... " .. frames[frameIndex])
  171. sleep(0.3)
  172. frameIndex = (frameIndex % #frames) + 1 -- Cycle through the frames
  173. end
  174.  
  175. -- Run the setup process
  176. shell.run("/disk/setup/")
  177. end,
  178. "Wipe data and reset to factory defaults completed."
  179. )
  180. end
  181.  
  182. local function recoveryMenu()
  183. while true do
  184. clearScreen("===== Recovery Options =====\n1. Full System Recovery\n2. Wipe data / Reset to factory defaults\n3. Back")
  185. local choice = tonumber(io.read())
  186. if choice == 1 then
  187. fullSystemRecovery()
  188. elseif choice == 2 then
  189. wipeDataAndResetFactoryDefaults()
  190. elseif choice == 3 then
  191. break
  192. else
  193. clearScreen("Invalid choice. Please try again.")
  194. sleep(2)
  195. end
  196. end
  197. end
  198.  
  199. local function powerMenu()
  200. clearScreen("===== Power Options =====\n1. Reboot system\n2. Shutdown system")
  201. local choice = tonumber(io.read())
  202. if choice == 1 then
  203. os.reboot()
  204. elseif choice == 2 then
  205. os.shutdown()
  206. else
  207. clearScreen("Invalid choice. Please try again.")
  208. sleep(2)
  209. end
  210. end
  211.  
  212. local function mainMenu()
  213. while true do
  214. clearScreen("===== Doggy OS DEV Recovery GUI =====\n1. Recovery Options\n2. Power Options\n3. Exit")
  215. local choice = tonumber(io.read())
  216. if choice == 1 then
  217. recoveryMenu()
  218. elseif choice == 2 then
  219. powerMenu()
  220. elseif choice == 3 then
  221. break
  222. else
  223. clearScreen("Invalid choice. Please try again.")
  224. sleep(2)
  225. end
  226. end
  227. end
  228.  
  229. -- Start the main menu
  230. mainMenu()
  231.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement