Advertisement
DOGGYWOOF

Doggy OS Smart Switch

Feb 6th, 2025 (edited)
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. -- WARNING: Use this script at your own risk.
  2. -- Ensure you have a backup before running it.
  3.  
  4. -- Doggy OS Smart Switch - User Data Transfer Utility
  5.  
  6. -- Function to clear the screen and set up UI
  7. local function setupUI(title, subtitle)
  8. term.clear()
  9. term.setCursorPos(1, 1)
  10. term.setTextColor(colors.white)
  11. term.setBackgroundColor(colors.black)
  12. term.clear()
  13.  
  14. -- Center the title
  15. local w, h = term.getSize()
  16. local x = math.floor((w - #title) / 2)
  17. term.setCursorPos(x, 2)
  18. term.setTextColor(colors.cyan)
  19. print(title)
  20.  
  21. -- Subtitle below the title
  22. local x_subtitle = math.floor((w - #subtitle) / 2)
  23. term.setCursorPos(x_subtitle, 4)
  24. term.setTextColor(colors.lightGray)
  25. print(subtitle)
  26.  
  27. -- Draw horizontal line for separation
  28. term.setCursorPos(1, 6)
  29. term.setTextColor(colors.gray)
  30. print(string.rep("-", w))
  31. end
  32.  
  33. -- Function to recursively collect user data
  34. local function collectUserData(path, userData, basePath)
  35. for _, file in pairs(fs.list(path)) do
  36. local fullPath = fs.combine(path, file)
  37. local relativePath = fullPath:sub(#basePath + 1)
  38. if fs.isDir(fullPath) then
  39. userData[relativePath] = "DIR"
  40. collectUserData(fullPath, userData, basePath)
  41. else
  42. local f = fs.open(fullPath, "r")
  43. if f then
  44. userData[relativePath] = f.readAll()
  45. f.close()
  46. end
  47. end
  48. end
  49. end
  50.  
  51. -- Function to restore user data from received table
  52. local function restoreUserData(userData)
  53. fs.delete("/disk/users/")
  54. fs.makeDir("/disk/users/")
  55.  
  56. for path, content in pairs(userData) do
  57. local fullPath = fs.combine("/disk/users/", path)
  58. if content == "DIR" then
  59. fs.makeDir(fullPath)
  60. else
  61. local file = fs.open(fullPath, "w")
  62. if file then
  63. file.write(content)
  64. file.close()
  65. end
  66. end
  67. end
  68. end
  69.  
  70. -- Function to receive user data via rednet
  71. local function receiveUserData()
  72. setupUI("Doggy OS Smart Switch", "Waiting for user data from sender...")
  73. rednet.open("top")
  74.  
  75. while true do
  76. local senderID, message = rednet.receive("DoggyOS_SmartSwitch")
  77. if message == "CONFIRM" then
  78. rednet.send(senderID, "CONFIRMED", "DoggyOS_SmartSwitch")
  79. elseif type(message) == "table" then
  80. restoreUserData(message)
  81. setupUI("Doggy OS Smart Switch", "User data received and restored!")
  82. print("Transfer complete.")
  83. os.sleep(2)
  84. break
  85. end
  86. end
  87. rednet.close("top")
  88. end
  89.  
  90. -- Function to send user data via rednet
  91. local function sendUserData()
  92. setupUI("Doggy OS Smart Switch", "Enter receiver's ID:")
  93. term.setCursorPos(3, 8)
  94. local receiverID = tonumber(read())
  95.  
  96. if not receiverID then
  97. setupUI("Doggy OS Smart Switch", "Invalid receiver ID.")
  98. os.sleep(2)
  99. return
  100. end
  101.  
  102. setupUI("Doggy OS Smart Switch", "Waiting for receiver confirmation...")
  103. rednet.open("top")
  104. rednet.send(receiverID, "CONFIRM", "DoggyOS_SmartSwitch")
  105. local senderID, response = rednet.receive("DoggyOS_SmartSwitch", 10)
  106.  
  107. if response == "CONFIRMED" then
  108. setupUI("Doggy OS Smart Switch", "Sending user data...")
  109. local userData = {}
  110. collectUserData("/disk/users/", userData, "/disk/users/")
  111. rednet.send(receiverID, userData, "DoggyOS_SmartSwitch")
  112. setupUI("Doggy OS Smart Switch", "User data sent successfully!")
  113. os.sleep(2)
  114. else
  115. setupUI("Doggy OS Smart Switch", "Receiver did not confirm.")
  116. os.sleep(2)
  117. end
  118. rednet.close("top")
  119. end
  120.  
  121. -- Function to start the data transfer process
  122. local function startSmartSwitch()
  123. setupUI("Doggy OS Smart Switch", "Transfer your data to a new Doggy OS device")
  124.  
  125. term.setCursorPos(3, 8)
  126. print("1. Send user data to another Doggy OS device")
  127. term.setCursorPos(3, 9)
  128. print("2. Receive user data from another Doggy OS device")
  129. term.setCursorPos(3, 11)
  130. write("Choose an option: ")
  131. local choice = read()
  132.  
  133. if choice == "2" then
  134. receiveUserData()
  135. elseif choice == "1" then
  136. sendUserData()
  137. else
  138. setupUI("Doggy OS Smart Switch", "Invalid selection. Restarting...")
  139. os.sleep(2)
  140. startSmartSwitch()
  141. end
  142. end
  143.  
  144. -- Main program
  145. startSmartSwitch()
  146.  
  147. setupUI("Running Doggy OS", "Please wait...")
  148. shell.run("/disk/boot/error")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement