Advertisement
DOGGYWOOF

Doggy OS new Recovery system

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