Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ver = "0.3.5"
- -- Checking for directory "Downloads/". Making it if not exists.
- if not fs.exists("Downloads/") then
- fs.makeDir("Downloads/")
- end
- -- Loading 'modemfind'
- -- os.loadAPI("/lib/mf")
- -- Loading 'craftnet' API
- os.loadAPI("/lib/cn")
- -- This function makes first GUI.
- function bgd()
- bg = paintutils.loadImage("rd_b")
- paintutils.drawImage(bg, 0, 0)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(50, 1)
- print("RD v."..ver)
- paintutils.drawPixel(0, 2, colors.white)
- end
- function clear()
- paintutils.drawPixel(0, 1, colors.black)
- term.clear()
- end
- -- I do not want to type 'boolean' ewerywhere so I made a var
- s = 'boolean'
- textutils.slowPrint("Loading program...")
- textutils.slowPrint("Opening modem...")
- os.loadAPI("/lib/mf")
- textutils.slowPrint("Connecting to the Craftnet...")
- ipadd = cn.getIP()
- if type(ipadd) == s then
- textutils.slowPrint("Using standard RedNet lib.")
- end
- bgd()
- print("Welcome, user! This is RD(RedNet_Downloader).")
- print("Version "..ver)
- function getid()
- if type(ipadd) == s then
- yourid = os.computerID()
- yourid = yourid + 0
- else
- yourid = ipadd
- end
- end
- num = 1
- while num <= 2 do
- bgd()
- print("Type 'exit' for exit.")
- print("Do you want to use CraftNet? ('yes'/'no')")
- useCn = read()
- if useCn == "exit" then
- num = num + 100
- clear()
- break
- elseif useCn == 'no' or useCn == 'n' then
- ipadd=false
- getid()
- elseif useCn == 'yes' then
- ipadd=cn.getIP()
- getid()
- end
- print("Your ID: "..yourid)
- print("'sender' or 'receiver' and 'downloads'")
- write("Program mode: ")
- mode = read()
- if mode == "downloads" then
- gt = 1
- while gt == 1 do
- bgd()
- shell.run("/lib/sr", "/Downloads/")
- sleep(0.3)
- print("Enter 'menu' for exit in menu.")
- print("Enter 'delete' for delete files.")
- dls = read()
- if dls == "menu" then
- gt = 0
- end
- if dls == "delete" then
- write("Enter name file: ")
- filename = read()
- if not fs.exists("/Downloads/"..filename) then
- print("File not found.")
- sleep(1)
- end
- if fs.exists("/Downloads/"..filename) then
- fs.delete("/Downloads/"..filename)
- print("File deleted.")
- sleep(1)
- end
- end
- clear()
- end
- end
- if mode == "exit" then
- num = num + 100
- end
- if mode == "sender" then
- write("Enter a path to file: ")
- path = read()
- if type(ipadd) == s then
- write("Enter receiver's ID: ")
- ID = read() + 0
- else
- write("Enter receiver's IP: ")
- ID = read()
- end
- f = fs.open(path, "r")
- if type(ipadd) == s then
- rednet.send(ID, f.readAll())
- else
- cn.send(ID, f.readAll())
- end
- print("File successfully sent!")
- sleep(3)
- end
- if mode == "receiver" then
- if type(ipadd) == s then
- write("Enter sender's ID: ")
- sID = read() + 0
- else
- write("Enter sender's IP: ")
- sID = read()
- end
- write("Enter the time to listen: ")
- time = read() + 0
- textutils.slowPrint("Please wait "..time.." sec...")
- if type(ipadd) == s then
- id, msg = rednet.receive(time)
- else
- msg, id, _, _ = cn.receive(time)
- end
- if id == sID then
- print("Got new file!")
- write("Enter a name for new file: ")
- nfile = read()
- d = fs.open("Downloads/"..nfile, "w")
- d.writeLine(msg)
- print("File successfully downloaded!")
- sleep(3)
- else
- print("No new files.")
- sleep(3)
- end
- end
- clear()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement