DOGGYWOOF

Dskmanager

Oct 12th, 2024 (edited)
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. -- Doggy OS USB Disk Management System for CC Tweaked
  2.  
  3.  
  4. local function autoDetectDisk()
  5. local disks = {}
  6. for i = 2, 4 do -- Assuming a maximum of 3 disk slots (disk2, disk3, disk4)
  7. local diskPath = "/disk" .. i
  8. if fs.exists(diskPath) then
  9. table.insert(disks, diskPath)
  10. end
  11. end
  12. return disks
  13. end
  14.  
  15. local function createInstallDisk()
  16. print("Enter the path of the file to add to the disk:")
  17. local filePath = read()
  18.  
  19. print("Enter a label for the disk:")
  20. local label = read()
  21.  
  22. local disks = autoDetectDisk()
  23. if #disks == 0 then
  24. print("No disks found. Please insert a disk.")
  25. return
  26. end
  27.  
  28. print("Found disks: ")
  29. for i, disk in ipairs(disks) do
  30. print(i .. ". " .. disk)
  31. end
  32.  
  33. print("Select a disk (1-" .. #disks .. "):")
  34. local choice = tonumber(read())
  35. local selectedDisk = disks[choice]
  36.  
  37. if not selectedDisk or not fs.exists(filePath) then
  38. print("Invalid selection or file does not exist.")
  39. return
  40. end
  41.  
  42. -- Create a directory on the disk if it doesn't exist
  43. if not fs.exists(selectedDisk .. "/" .. label) then
  44. fs.makeDir(selectedDisk .. "/" .. label)
  45. end
  46.  
  47. -- Copy the required files to the selected disk with the specified label
  48. local installDiskFile = selectedDisk .. "/" .. label .. "/DGY Installdsk"
  49. fs.copy(filePath, installDiskFile)
  50. print("Install file created successfully on " .. selectedDisk .. " with label: " .. label)
  51. end
  52.  
  53. local function installFromDisk()
  54. local disks = autoDetectDisk()
  55. if #disks == 0 then
  56. print("No disks found. Please insert a disk.")
  57. return
  58. end
  59.  
  60. print("Found disks: ")
  61. for i, disk in ipairs(disks) do
  62. print(i .. ". " .. disk)
  63. end
  64.  
  65. print("Select a disk (1-" .. #disks .. "):")
  66. local choice = tonumber(read())
  67. local selectedDisk = disks[choice]
  68.  
  69. if not selectedDisk then
  70. print("Invalid selection.")
  71. return
  72. end
  73.  
  74. print("Enter the name you want to save the file as:")
  75. local saveFileName = read()
  76.  
  77. print("Enter the path to save the file (e.g., /home/username/):")
  78. local savePath = read()
  79.  
  80. local installFilePath = selectedDisk .. "/" .. fs.getName(saveFileName) -- Path of the file to copy from the disk
  81. if fs.exists(installFilePath) then
  82. print("Copying from disk " .. selectedDisk .. " to " .. savePath .. saveFileName)
  83. fs.copy(installFilePath, savePath .. saveFileName)
  84. print("Installation successful. File saved as: " .. savePath .. saveFileName)
  85. else
  86. print("Install file not found on " .. selectedDisk)
  87. end
  88. end
  89.  
  90. local function encryptDisk()
  91. print("Enter password for encryption:")
  92. local password = read()
  93.  
  94. local disks = autoDetectDisk()
  95. if #disks == 0 then
  96. print("No disks found. Please insert a disk.")
  97. return
  98. end
  99.  
  100. print("Found disks: ")
  101. for i, disk in ipairs(disks) do
  102. print(i .. ". " .. disk)
  103. end
  104.  
  105. print("Select a disk (1-" .. #disks .. "):")
  106. local choice = tonumber(read())
  107. local selectedDisk = disks[choice]
  108.  
  109. if not selectedDisk then
  110. print("Invalid selection.")
  111. return
  112. end
  113.  
  114. -- Implement encryption logic here
  115. local encryptionKey = computer.getPCID() .. password -- Simple example
  116. fs.write(selectedDisk .. "/encryption_key", encryptionKey)
  117. print("Disk " .. selectedDisk .. " encrypted successfully.")
  118. end
  119.  
  120. local function decryptDisk()
  121. print("Enter password for decryption:")
  122. local password = read()
  123.  
  124. local disks = autoDetectDisk()
  125. if #disks == 0 then
  126. print("No disks found. Please insert a disk.")
  127. return
  128. end
  129.  
  130. print("Found disks: ")
  131. for i, disk in ipairs(disks) do
  132. print(i .. ". " .. disk)
  133. end
  134.  
  135. print("Select a disk (1-" .. #disks .. "):")
  136. local choice = tonumber(read())
  137. local selectedDisk = disks[choice]
  138.  
  139. if not selectedDisk then
  140. print("Invalid selection.")
  141. return
  142. end
  143.  
  144. local encryptionKeyPath = selectedDisk .. "/encryption_key"
  145. if fs.exists(encryptionKeyPath) then
  146. local encryptionKey = fs.read(encryptionKeyPath)
  147. -- Implement decryption logic here
  148. print("Disk " .. selectedDisk .. " decrypted successfully.")
  149. else
  150. print("No encryption key found on " .. selectedDisk)
  151. end
  152. end
  153.  
  154. -- Main menu
  155. while true do
  156. print("Doggy OS USB Disk Management")
  157. print("1. Create Install Disk")
  158. print("2. Install from Disk")
  159. print("3. Encrypt Disk")
  160. print("4. Decrypt Disk")
  161. print("5. Exit")
  162.  
  163. local choice = tonumber(read())
  164. if choice == 1 then
  165. createInstallDisk()
  166. elseif choice == 2 then
  167. installFromDisk()
  168. elseif choice == 3 then
  169. encryptDisk()
  170. elseif choice == 4 then
  171. decryptDisk()
  172. elseif choice == 5 then
  173. break
  174. else
  175. print("Invalid choice. Please try again.")
  176. end
  177. end
  178.  
Add Comment
Please, Sign In to add comment