Streetboy_xD

fileclient.install

Oct 25th, 2014
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.66 KB | None | 0 0
  1. dir = "/"
  2. dirText = "X | Downloads"
  3.  
  4. modemside = side
  5. color = colors.lightGray
  6. coloritems = colors.white
  7. textcolor = colors.black
  8.  
  9. id = idnumber
  10.  
  11. minnumber = 2
  12. maxnumber = 18
  13. minnum = 2
  14. maxnum = 18
  15. timeout = 0.5
  16. downloadList = {}
  17.  
  18. rednet.open(modemside)
  19.  
  20. fs.makeDir("Downloads")
  21.  
  22. while true do
  23.  
  24. function design()
  25. paint = paintutils.loadImage("FileDesign")
  26. paintutils.drawImage(paint,1,1)
  27. end
  28. term.clear()
  29. design()
  30. term.setTextColor(textcolor)
  31. term.setBackgroundColor(color)
  32. term.setCursorPos(9,1)
  33. term.write("| PC |")
  34. term.setCursorPos(36,1)
  35. term.write("| SERVER |")
  36. term.setCursorPos(1,1)
  37. term.write("v^")
  38. term.setCursorPos(29,1)
  39. term.write("v^")
  40. term.setCursorPos(51,19)
  41. term.write("$")
  42. term.setCursorPos(1,19)
  43. term.write(dirText)
  44. term.setBackgroundColor(colors.red)
  45. term.setCursorPos(51,1)
  46. term.write("X")
  47. term.setBackgroundColor(color)
  48. term.setCursorPos(1,1)
  49.  
  50. function scrolldown()
  51.  
  52. minnumber = minnumber + 1
  53. maxnumber = maxnumber + 1
  54.  
  55. end
  56.  
  57. function scrollup()
  58.  
  59. minnumber = minnumber - 1
  60. maxnumber = maxnumber - 1
  61.  
  62. end
  63.  
  64. function scrolldowndownload()
  65.  
  66. minnum = minnum + 1
  67. maxnum = maxnum + 1
  68.  
  69. end
  70.  
  71. function scrollupdownload()
  72.  
  73. minnum = minnum - 1
  74. maxnum = maxnum - 1
  75.  
  76. end
  77.  
  78. function changeDir()
  79.  
  80. if dir == "/" then
  81. dir = "Downloads/"
  82. dirText = "X | Hauptverzeichnis"
  83. else
  84. dir = "/"
  85. dirText = "X | Downloads "
  86. end
  87.  
  88. end
  89.  
  90. function createAuswahlUpload( ypos )
  91.  
  92. if listedPrograms[ypos + minnumber - 2] then
  93. term.setBackgroundColor(color)
  94. term.setCursorPos(15,6)
  95. term.write(" ")
  96. term.setCursorPos(15,7)
  97. term.write(" ")
  98. term.setCursorPos(15,8)
  99. term.write(" ")
  100. term.setCursorPos(15,9)
  101. term.write(" ")
  102. term.setCursorPos(15,10)
  103. term.write(" ")
  104. term.setCursorPos(16,6)
  105. term.write("Name: ")
  106. term.write(listedPrograms[ypos + minnumber - 2])
  107. term.setBackgroundColor(coloritems)
  108. term.setCursorPos(16,7)
  109. term.write(" ")
  110. term.setCursorPos(16,8)
  111. term.write(" Speichern ")
  112. term.setCursorPos(16,9)
  113. term.write(" ")
  114. term.setBackgroundColor(coloritems)
  115.  
  116. event, side, x, y = os.pullEvent("mouse_click")
  117.  
  118. if x >= 16 and x <= 37 and y >= 7 and y <= 9 then
  119.  
  120. program = fs.open(listedPrograms[ypos + minnumber - 2],"r")
  121. programdata = program.readAll()
  122. program.close()
  123. rednet.send(id,"U;"..listedPrograms[ypos + minnumber - 2].."$;"..programdata)
  124. a,b,c = rednet.receive(timeout)
  125. if a == nil then
  126. term.setBackgroundColor(color)
  127. term.setCursorPos(1,19)
  128. term.write("Keine Verbindung zum Server!")
  129. sleep(1)
  130. else
  131. term.setBackgroundColor(color)
  132. term.setCursorPos(1,19)
  133. term.write(b)
  134. sleep(1)
  135. end
  136.  
  137. end
  138. end
  139.  
  140. end
  141.  
  142.  
  143. function createAuswahlDownload( ypos )
  144.  
  145. if downloadList[ypos + minnum - 2] then
  146. term.setBackgroundColor(color)
  147. term.setCursorPos(15,5)
  148. term.write(" ")
  149. term.setCursorPos(15,6)
  150. term.write(" ")
  151. term.setCursorPos(15,7)
  152. term.write(" ")
  153. term.setCursorPos(15,8)
  154. term.write(" ")
  155. term.setCursorPos(15,9)
  156. term.write(" ")
  157. term.setCursorPos(15,10)
  158. term.write(" ")
  159. term.setCursorPos(15,11)
  160. term.write(" ")
  161. term.setCursorPos(16,5)
  162. term.write("Name: ")
  163. term.write(downloadList[ypos + minnum - 2])
  164. term.setBackgroundColor(coloritems)
  165. term.setCursorPos(16,6)
  166. term.write(" ")
  167. term.setCursorPos(16,7)
  168. term.write(" Download ")
  169. term.setCursorPos(16,8)
  170. term.write(" ")
  171. term.setCursorPos(16,9)
  172. term.write(" Delete ")
  173. term.setCursorPos(16,10)
  174. term.write(" ")
  175. term.setBackgroundColor(color)
  176.  
  177. event, side, x, y = os.pullEvent("mouse_click")
  178.  
  179. if x >= 16 and x <= 37 and y == 7 then
  180.  
  181. rednet.send(id,"D;"..downloadList[ypos + minnum - 2])
  182. a, b, c = rednet.receive(timeout)
  183. if a == nil then
  184. term.setBackgroundColor(color)
  185. term.setCursorPos(1,19)
  186. term.write("Keine Verbindung zum Server!")
  187. else
  188. if not fs.exists("Downloads/"..downloadList[ypos + minnum - 2]) then
  189. File = fs.open("Downloads/"..downloadList[ypos + minnum - 2],"w")
  190. File.write(b)
  191. File.close()
  192. term.setCursorPos(1,19)
  193. term.write("Erfolreich heruntergeladen")
  194. sleep(1)
  195. else
  196. term.setCursorPos(1,19)
  197. term.write("Datei existiert bereits!")
  198. sleep(1)
  199. end
  200. end
  201.  
  202. elseif x >= 16 and x <= 37 and y == 9 then
  203.  
  204. rednet.send(id,"B;"..downloadList[ypos + minnum - 2])
  205. a,b,c = rednet.receive(timeout)
  206.  
  207. if a == nil then
  208. term.setBackgroundColor(color)
  209. term.setCursorPos(1,19)
  210. term.write("Keine Verbindung zum Server!")
  211. sleep(1)
  212. else
  213. term.setBackgroundColor(color)
  214. term.setCursorPos(1,19)
  215. term.write(b)
  216. sleep(1)
  217. end
  218.  
  219. end
  220.  
  221. end
  222.  
  223.  
  224. end
  225.  
  226. -- Variablen
  227.  
  228. ItemDownloadVisible = 2
  229. ItemDownloadInvisible = 2
  230. y = 2
  231. visible = 2
  232. invisible = 2
  233. items = ";"
  234. listedPrograms = {}
  235.  
  236. -- Tabellen
  237.  
  238. rednet.send(id,"L;")
  239. a, dL, c = rednet.receive(timeout)
  240. if a == nil then
  241. term.setBackgroundColor(coloritems)
  242. term.setCursorPos(32,2)
  243. term.write("Keine Verbindung")
  244. term.setCursorPos(32,3)
  245. term.write("zum Server!")
  246. else
  247.  
  248. while string.find(dL,";") do
  249.  
  250. findNew = string.find(dL.."",";")
  251. downloadList[ItemDownloadVisible] = string.sub(dL,1,findNew-1)
  252.  
  253. dL = string.sub(dL,string.find(dL.."",";")+1)
  254.  
  255. if ItemDownloadVisible >= minnum and ItemDownloadVisible <= maxnum then
  256. term.setBackgroundColor(coloritems)
  257. term.setCursorPos(32,ItemDownloadInvisible)
  258. term.write(downloadList[ItemDownloadVisible])
  259. ItemDownloadInvisible = ItemDownloadInvisible + 1
  260. end
  261.  
  262. ItemDownloadVisible = ItemDownloadVisible + 1
  263.  
  264. end
  265. end
  266.  
  267. progs = fs.list(dir)
  268.  
  269. for index, sItem in pairs(progs) do
  270. if fs.isDir(sItem)~=true then
  271.  
  272. listedPrograms[visible] = sItem
  273. if visible >= minnumber and visible <= maxnumber then
  274. term.setBackgroundColor(coloritems)
  275. term.setCursorPos(3,invisible)
  276. term.write(listedPrograms[visible])
  277. invisible = invisible + 1
  278. end
  279. visible = visible + 1
  280.  
  281. end
  282.  
  283. end
  284.  
  285. event, side, x, y = os.pullEvent()
  286.  
  287. if event == "mouse_click" then
  288.  
  289. if x > 3 and x < 25 and y > 1 and y < 19 then
  290.  
  291. createAuswahlUpload(y)
  292.  
  293.  
  294. elseif x > 32 and x < 46 and y > 1 and y < 19 then
  295.  
  296. createAuswahlDownload(y)
  297.  
  298. elseif x == 51 and y == 1 then
  299.  
  300. term.setBackgroundColor(colors.black)
  301. term.clear()
  302. term.setCursorPos(1,1)
  303. break
  304.  
  305. elseif x == 51 and y == 19 then
  306.  
  307. shell.run(shell.getRunningProgram())
  308.  
  309. elseif x == 1 and y == 1 and maxnumber < visible-1 and minnumber < visible then
  310.  
  311. scrolldown()
  312.  
  313. elseif x == 2 and y == 1 and maxnumber > 18 and minnumber > 2 then
  314.  
  315. scrollup()
  316.  
  317. elseif x == 29 and y == 1 and maxnum < ItemDownloadVisible-1 and minnum < ItemDownloadVisible then
  318.  
  319. scrolldowndownload()
  320.  
  321. elseif x == 30 and y == 1 and maxnum > 18 and minnum > 2 then
  322.  
  323. scrollupdownload()
  324.  
  325. elseif x == 1 and y == 19 then
  326.  
  327. changeDir()
  328.  
  329. end
  330.  
  331. elseif event == "mouse_scroll" then
  332.  
  333. if side == 1 and maxnumber < visible - 1 and minnumber < visible then
  334.  
  335. scrolldown()
  336. sleep(0.08)
  337.  
  338. elseif side == -1 and maxnumber > 18 and minnumber > 2 then
  339.  
  340. scrollup()
  341. sleep(0.08)
  342.  
  343. elseif side == 1 and maxnum < ItemDownloadVisible-1 and minnum < ItemDownloadVisible then
  344.  
  345. scrolldowndownload()
  346. sleep(0.08)
  347.  
  348. elseif side == -1 and maxnum > 18 and minnum > 2 then
  349.  
  350. scrollupdownload()
  351. sleep(0.08)
  352.  
  353. end
  354.  
  355. end
  356. end
  357.  
  358.  
  359. -- Scripted by Streetboy_xD
  360. -- Please keep this text in the program.
Advertisement
Add Comment
Please, Sign In to add comment