Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Download Manager Client by PaymentOption for NeXuS
- VERSION = 1.4
- -----------------------------------------------------
- rednet.open("top")
- rednet.open("right")
- rednet.open("left")
- rednet.open("back")
- rednet.open("bottom")
- shell.run("mkdir", "NeXuS/Downloads")
- shell.run("mkdir", "NeXuS/Files")
- shell.run("mkdir", "NeXuS/Settings/DownloadServer/")
- selection = 1
- serverID = 0
- if fs.exists("NeXuS/Settings/DownloadServer/serverID") then
- local file = fs.open("NeXuS/Settings/DownloadServer/serverID", "r")
- local fileContents = file.readAll()
- file.close()
- serverID = tonumber(fileContents)
- else
- local file = fs.open("NeXuS/Settings/DownloadServer/serverID", "w")
- file.write(tonumber(serverID))
- file.close()
- end
- function cPrint(height, string)
- local w, h = term.getSize()
- local xPosition = w/2 - string.len(string)/2
- term.setCursorPos(xPosition, height)
- term.write(string)
- end
- function rPrint(height, string)
- local w,h = term.getSize()
- local xPos = w - string.len(string)
- term.setCursorPos(xPos, height)
- term.write(string)
- end
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function printMenu()
- printHeader()
- if selection == 1 then cPrint(7, " [ Download ] ")
- else cPrint(7, " Download ") end
- if selection == 2 then cPrint(8, " [ Upload ] ")
- else cPrint(8, " Upload ") end
- if selection == 3 then cPrint(9, " [ Downloads ] ")
- else cPrint(9, " Downloads ") end
- if selection == 4 then cPrint(10, " [ New Server ]")
- else cPrint(10, " New Server ") end
- if selection == 5 then cPrint(11, " [ Exit ] ")
- else cPrint(11, " Exit ") end
- end
- function printHeader()
- cPrint(1, "NeXuS Download Manager")
- rPrint(1, "Version: "..VERSION)
- end
- function changeServer()
- clear()
- cPrint(6, "Enter new ServerID: ")
- serverID = tonumber(read())
- clear()
- fs.delete("NeXuS/Settings/DownloadServer/serverID")
- local file = fs.open("NeXuS/Settings/DownloadServer/serverID", "w")
- file.write(serverID)
- file.close()
- end
- function download()
- clear()
- rednet.send(serverID, "files")
- sender, files = rednet.receive(0.8)
- term.setCursorPos(1,1)
- print("Available Files::")
- print(files)
- cPrint(6, "FileName: ")
- local filename = read()
- clear()
- cPrint(6, "Download As: ")
- local newfilename = read()
- newfilename = "NeXuS/Downloads/"..newfilename
- clear()
- cPrint(6, "Sending request...")
- sleep(0.5)
- rednet.send(serverID, "download")
- sender, message = rednet.receive(5)
- if sender == serverID and message == "ready" then
- rednet.send(serverID, filename)
- sender, fileContents = rednet.receive(0.8)
- if sender == serverID and fileContents ~= "failed" then
- file = fs.open(newfilename, "w")
- file.write(fileContents)
- file.close()
- cPrint(7, "Success!")
- sleep(1.3)
- clear()
- end
- else cPrint(7, "Failure: Request not acknowledged."); sleep(1.3); clear() end
- end
- function upload()
- clear()
- term.setCursorPos(1, 17)
- write("*Must be in: NeXuS/Downloads!")
- cPrint(6, "FileName: ")
- local filename = read()
- clear()
- cPrint(6, "Sending request...")
- rednet.send(serverID, "upload")
- sender, message = rednet.receive(0.8)
- if sender == serverID and message == "ready" then
- rednet.send(serverID, tostring(filename))
- sender, message = rednet.receive(0.8)
- if sender == serverID and message == "ready" then
- local file = fs.open("NeXuS/Downloads/"..filename, "r")
- local fileContents = file.readAll()
- file.close()
- rednet.send(serverID, tostring(fileContents))
- cPrint(7, "Success!"); sleep(1.3)
- else cPrint(7, "Failure: Request no acknowledged."); sleep(1.3); end
- else cPrint(7, "Failure: Request no acknowledged."); sleep(1.3); end
- end
- function viewDownloads()
- clear()
- print("Download Folder: \n\n")
- rPrint(14, "[ Exit ]")
- term.setCursorPos(1, 3)
- for k, v in ipairs(fs.list("NeXuS/Downloads")) do
- print(v)
- end
- event, key = os.pullEvent("key")
- if key == 28 then end
- end
- function printLogo()
- term.clear(); term.setCursorPos(1,1)
- print(" _______ ____ ___ _________")
- print(" \\ \\ ____ \\ \\/ /__ __/ _____/")
- print(" / | \\_/ __ \\ \\ /| | \\_____ \\ ")
- print(" / | \\ ___/ / \\| | / \\")
- print(" \\____|__ /\\___ >/___/\\ \\____/_______ /")
- print(" \\/ \\/ \\_/ \\/ ")
- cPrint(15, "File Client by PaymentOption"); sleep(3)
- end
- printLogo()
- while true do
- clear()
- printHeader()
- printMenu()
- event, key = os.pullEvent("key")
- if key == 200 and selection > 1 then selection = selection-1
- elseif key == 208 and selection < 5 then selection = selection+1
- end
- if selection == 1 and key == 28 then download()
- elseif selection == 2 and key == 28 then upload()
- elseif selection == 3 and key == 28 then viewDownloads()
- elseif selection == 4 and key == 28 then changeServer()
- elseif selection == 5 and key == 28 then clear(); break
- end
- end
Add Comment
Please, Sign In to add comment