Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Doggy OS Pocket Recovery Client
- local modemSide = "right" -- Change this to the side where the wireless modem is attached
- local serverID
- local function loadConfig()
- local configFilePath = "/config.txt"
- if fs.exists(configFilePath) then
- local file = fs.open(configFilePath, "r")
- serverID = file.readAll()
- file.close()
- return true
- else
- return false
- end
- end
- local function requestFile(path)
- local modem = peripheral.wrap(modemSide)
- modem.transmit(tonumber(serverID), os.getComputerID(), "GET " .. path)
- local _, _, _, _, response = os.pullEvent("modem_message")
- return response
- end
- local function copyFilesFromServer()
- local diskContents = requestFile("/disk/")
- if diskContents then
- local diskFile = fs.open("/disk/", "w")
- diskFile.write(diskContents)
- diskFile.close()
- local recoveryContents = requestFile("/recovery/")
- if recoveryContents then
- local recoveryFile = fs.open("/recovery/", "w")
- recoveryFile.write(recoveryContents)
- recoveryFile.close()
- print("Files copied successfully!")
- sleep(2)
- else
- print("Failed to copy recovery files.")
- sleep(2)
- end
- else
- print("Failed to copy disk files.")
- sleep(2)
- end
- end
- local function recoverDevice()
- print("Please insert device into Doggy OS disk drive.")
- sleep(2)
- end
- local function registerServer()
- print("Enter the Doggy OS Computer ID:")
- local newServerID = read()
- local configFilePath = "/config.txt"
- local file = fs.open(configFilePath, "w")
- file.write(newServerID)
- file.close()
- print("Server registered successfully!")
- sleep(2)
- end
- -- Main Program
- if loadConfig() then
- print("Doggy OS Pocket Recovery Client")
- print("1. Recover Device")
- print("2. Exit")
- write("Select an option: ")
- local option = tonumber(read())
- if option == 1 then
- copyFilesFromServer()
- elseif option == 2 then
- -- Do nothing, exit
- else
- print("Invalid option. Please try again.")
- sleep(2)
- end
- else
- print("Doggy OS Pocket Recovery Client (Not Registered)")
- print("1. Register Recovery Server")
- print("2. Connect to Server")
- print("3. Exit")
- write("Select an option: ")
- local option = tonumber(read())
- if option == 1 then
- registerServer()
- elseif option == 2 then
- print("Enter the Doggy OS Computer ID to connect:")
- serverID = read()
- copyFilesFromServer()
- elseif option == 3 then
- -- Do nothing, exit
- else
- print("Invalid option. Please try again.")
- sleep(2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement