Advertisement
Guest User

rd

a guest
Nov 28th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.22 KB | None | 0 0
  1. ver = "0.3.5"
  2. -- Checking for directory "Downloads/". Making it if not exists.
  3. if not fs.exists("Downloads/") then
  4.  fs.makeDir("Downloads/")
  5. end
  6. -- Loading 'modemfind'
  7. -- os.loadAPI("/lib/mf")
  8. -- Loading 'craftnet' API
  9. os.loadAPI("/lib/cn")
  10. -- This function makes first GUI.
  11. function bgd()
  12. bg = paintutils.loadImage("rd_b")
  13. paintutils.drawImage(bg, 0, 0)
  14. term.setBackgroundColor(colors.white)
  15. term.setTextColor(colors.black)
  16. term.setCursorPos(50, 1)
  17. print("RD v."..ver)
  18. paintutils.drawPixel(0, 2, colors.white)
  19. end
  20.  
  21. function clear()
  22. paintutils.drawPixel(0, 1, colors.black)
  23. term.clear()
  24. end
  25.  
  26. -- I do not want to type 'boolean' ewerywhere so I made a var
  27. s = 'boolean'
  28.  
  29. textutils.slowPrint("Loading program...")
  30. textutils.slowPrint("Opening modem...")
  31. os.loadAPI("/lib/mf")
  32. textutils.slowPrint("Connecting to the Craftnet...")
  33. ipadd = cn.getIP()
  34. if type(ipadd) == s then
  35.  textutils.slowPrint("Using standard RedNet lib.")
  36. end
  37.  
  38. bgd()
  39. print("Welcome, user! This is RD(RedNet_Downloader).")
  40. print("Version "..ver)
  41. function getid()
  42.  if type(ipadd) == s then
  43.   yourid = os.computerID()
  44.   yourid = yourid + 0
  45.  else
  46.   yourid = ipadd
  47.  end
  48. end
  49. num = 1
  50. while num <= 2 do
  51. bgd()
  52. print("Type 'exit' for exit.")
  53. print("Do you want to use CraftNet? ('yes'/'no')")
  54. useCn = read()
  55.  
  56. if useCn == "exit" then
  57.  num = num + 100
  58.  clear()
  59.  break
  60. elseif useCn == 'no' or useCn == 'n' then
  61.  ipadd=false
  62.  getid()
  63. elseif useCn == 'yes' then
  64.  ipadd=cn.getIP()
  65.  getid()
  66. end
  67. print("Your ID: "..yourid)
  68. print("'sender' or 'receiver' and 'downloads'")
  69. write("Program mode: ")
  70. mode = read()
  71. if mode == "downloads" then
  72. gt = 1
  73. while gt == 1 do
  74. bgd()
  75. shell.run("/lib/sr", "/Downloads/")
  76. sleep(0.3)
  77. print("Enter 'menu' for exit in menu.")
  78. print("Enter 'delete' for delete files.")
  79. dls = read()
  80. if dls == "menu" then
  81.  gt = 0
  82.  end
  83.  if dls == "delete" then
  84.  write("Enter name file: ")
  85.  filename = read()
  86. if not fs.exists("/Downloads/"..filename) then
  87.  print("File not found.")
  88.  sleep(1)
  89.  end
  90.  if fs.exists("/Downloads/"..filename) then
  91.  fs.delete("/Downloads/"..filename)
  92.  print("File deleted.")
  93.  sleep(1)
  94.  end
  95. end
  96. clear()
  97. end
  98. end
  99. if mode == "exit" then
  100.  num = num + 100
  101. end
  102. if mode == "sender" then
  103.  write("Enter a path to file: ")
  104.  path = read()
  105.  if type(ipadd) == s then
  106.   write("Enter receiver's ID: ")
  107.   ID = read() + 0
  108.  else
  109.   write("Enter receiver's IP: ")
  110.   ID = read()
  111.  end
  112.  f = fs.open(path, "r")
  113.  if type(ipadd) == s then
  114.   rednet.send(ID, f.readAll())
  115.  else
  116.   cn.send(ID, f.readAll())
  117.  end
  118.  print("File successfully sent!")
  119.  sleep(3)
  120. end
  121. if mode == "receiver" then
  122.  if type(ipadd) == s then
  123.   write("Enter sender's ID: ")
  124.   sID = read() + 0
  125.  else
  126.   write("Enter sender's IP: ")
  127.   sID = read()
  128.  end
  129.  write("Enter the time to listen: ")
  130.  time = read() + 0
  131.  textutils.slowPrint("Please wait "..time.." sec...")
  132.  if type(ipadd) == s then
  133.   id, msg = rednet.receive(time)
  134.  else
  135.   msg, id, _, _ = cn.receive(time)
  136.  end
  137. if id == sID then
  138.  print("Got new file!")
  139.  write("Enter a name for new file: ")
  140.  nfile = read()
  141.  d = fs.open("Downloads/"..nfile, "w")
  142.  d.writeLine(msg)
  143.  print("File successfully downloaded!")
  144.  sleep(3)
  145. else
  146.   print("No new files.")
  147.   sleep(3)
  148. end
  149. end
  150. clear()
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement