cyber_Ahn

DownloadManager for cawOS

Jul 29th, 2016
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.13 KB | None | 0 0
  1. --Download Manager for cawOS 2.0
  2. --load api
  3. os.loadAPI("caAPI")
  4.  
  5. --set monitor
  6. function set_monitor()
  7. local monitor_number = caAPI.get_hardware("monitor")
  8. local found = fs.exists("config/monitor.cfg")
  9. if found == true then
  10. file = fs.open("config/monitor.cfg","r")
  11. local fileData = {}
  12. local line = file.readLine()
  13. repeat
  14. table.insert(fileData,line)
  15. line = file.readLine()
  16. until line == nil
  17. file.close()
  18. monitor_number = fileData[1]
  19. radio_number = fileData[3]
  20. end
  21. mon = peripheral.wrap(monitor_number)
  22. end
  23.  
  24. --download
  25. function download(name,id)
  26. mon.setCursorPos(3,22)
  27. mon.write("Start Download")
  28. sleep(1)
  29. mon.setCursorPos(3,23)
  30. shell.run("delete "..name)
  31. shell.run("pastebin get "..id.." "..name)
  32. sleep(1)
  33. draw_screen()
  34. end
  35.  
  36. --uninstall
  37. function delete(name)
  38. mon.setCursorPos(3,22)
  39. mon.write("Uninstall Programm")
  40. sleep(1)
  41. mon.setCursorPos(3,23)
  42. shell.run("delete "..name)
  43. sleep(1)
  44. draw_screen()
  45. end
  46.  
  47. --enter paste
  48. function past()
  49. mon.setCursorPos(3,22)
  50. mon.write("Input Pastebin Code:")
  51. id = read()
  52. mon.setCursorPos(3,23)
  53. mon.write("Input ProgramName:")
  54. name = read()
  55. sleep(1)
  56. mon.setCursorPos(3,23)
  57. download(name,id)
  58. end
  59.  
  60. --draw screen
  61. function draw_screen()
  62. mon.setBackgroundColor(colors.white)
  63. mon.setTextColor(colors.white)
  64. mon.clear()
  65. mon.setBackgroundColor(colors.white)
  66. mon.setCursorPos(1,1)
  67. mon.setBackgroundColor(colors.blue)
  68. mon.write("Program Download Manager 1.0                            ")
  69. mon.setCursorPos(50,1)
  70. mon.setBackgroundColor(colors.red)
  71. mon.setTextColor(colors.black)
  72. mon.write("X")
  73. mon.setCursorPos(1,3)
  74. mon.setBackgroundColor(colors.black)
  75. mon.setTextColor(colors.black)
  76. mon.write("                                                  ")
  77. mon.setCursorPos(1,26)
  78. mon.write("                                                  ")
  79. mon.setCursorPos(1,5)
  80. mon.write("                                                  ")
  81. for yi = 4,25 do
  82. mon.setCursorPos(1,yi)
  83. mon.write(" ")
  84. mon.setCursorPos(50,yi)
  85. mon.write(" ")
  86. yi = yi + 1
  87. end
  88. mon.setCursorPos(3,4)
  89. mon.setBackgroundColor(colors.white)
  90. mon.setTextColor(colors.black)
  91. mon.write("Name")
  92. mon.setCursorPos(26,4)
  93. mon.write("Genere")
  94. mon.setCursorPos(42,4)
  95. mon.write("State")
  96. mon.setCursorPos(2,2)
  97. mon.setTextColor(colors.green)
  98. mon.write("Download with Pastebin code")
  99. mon.setTextColor(colors.black)
  100. --list
  101. mon.setCursorPos(3,6)
  102. mon.write("Open FM Radio")
  103. mon.setCursorPos(26,6)
  104. mon.write("Audio")
  105. mon.setCursorPos(3,7)
  106. mon.write("Command Remote")
  107. mon.setCursorPos(26,7)
  108. mon.write("Control")
  109. mon.setCursorPos(3,8)
  110. mon.write("Train Control")
  111. mon.setCursorPos(26,8)
  112. mon.write("Control")
  113. mon.setCursorPos(3,9)
  114. mon.write("Cable Remote")
  115. mon.setCursorPos(26,9)
  116. mon.write("Control")
  117. mon.setCursorPos(3,10)
  118. mon.write("Stargate")
  119. mon.setCursorPos(26,10)
  120. mon.write("Play")
  121. mon.setCursorPos(3,11)
  122. mon.write("Nitrosoft Games")
  123. mon.setCursorPos(26,11)
  124. mon.write("Games")
  125. mon.setCursorPos(3,12)
  126. mon.write("FileManager")
  127. mon.setCursorPos(26,12)
  128. mon.write("Office")
  129. mon.setCursorPos(3,13)
  130. mon.write("NPaintTurtle")
  131. mon.setCursorPos(26,13)
  132. mon.write("3D Print")
  133. mon.setCursorPos(3,14)
  134. mon.write("NPaintPro")
  135. mon.setCursorPos(26,14)
  136. mon.write("Office/3D Print")
  137. mon.setCursorPos(3,15)
  138. mon.write("BigReactor Control")
  139. mon.setCursorPos(26,15)
  140. mon.write("Control")
  141. mon.setCursorPos(3,16)
  142. mon.write("BigReactor Status")
  143. mon.setCursorPos(26,16)
  144. mon.write("Info")
  145. mon.setCursorPos(3,17)
  146. mon.write("SteelTank Status")
  147. mon.setCursorPos(26,17)
  148. mon.write("Info")
  149. mon.setCursorPos(3,18)
  150. mon.write("ME Bridge")
  151. mon.setCursorPos(26,18)
  152. mon.write("Info")
  153. mon.setCursorPos(3,19)
  154. mon.write("Energy Cell")
  155. mon.setCursorPos(26,19)
  156. mon.write("Info")
  157. mon.setCursorPos(3,20)
  158. mon.write("Mekanism Reactor")
  159. mon.setCursorPos(26,20)
  160. mon.write("Control")
  161.  
  162.  
  163. --state
  164. fDir = shell.programs()
  165. programs = {}
  166. for i=1,#fDir do
  167. if(fDir[i] == "Radio") or (fDir[i] == "Command_Remote") or (fDir[i] == "Train_Control") or (fDir[i] == "Cable_Remote") or (fDir[i] == "Stargate") or (fDir[i] == "Nitrosoft_Games") or (fDir[i] == "FileManager") or (fDir[i] == "NPaintTurtle") or (fDir[i] == "NPaintPro") or (fDir[i] == "BigReactor_Control") or (fDir[i] == "BigReactor_Status") or (fDir[i] == "SteelTank_Status") or (fDir[i] == "ME_Bridge") or (fDir[i] == "Energy_Cell") or (fDir[i] == "Mekanism_Reactor")then
  168. table.insert(programs, fDir[i])
  169. end
  170. end
  171. mon.setCursorPos(41,6)
  172. if caAPI.in_table(programs, "Radio") == true then
  173. mon.setTextColor(colors.red)
  174. mon.write("Update")
  175. mon.setCursorPos(2,6)
  176. mon.write("X")
  177. else
  178. mon.setTextColor(colors.green)
  179. mon.write("Download")
  180. end
  181. mon.setCursorPos(41,7)
  182. if caAPI.in_table(programs, "Command_Remote") == true then
  183. mon.setTextColor(colors.red)
  184. mon.write("Update")
  185. mon.setCursorPos(2,7)
  186. mon.write("X")
  187. else
  188. mon.setTextColor(colors.green)
  189. mon.write("Download")
  190. end
  191. mon.setCursorPos(41,8)
  192. if caAPI.in_table(programs, "Train_Control") == true then
  193. mon.setTextColor(colors.red)
  194. mon.write("Update")
  195. mon.setCursorPos(2,8)
  196. mon.write("X")
  197. else
  198. mon.setTextColor(colors.green)
  199. mon.write("Download")
  200. end
  201. mon.setCursorPos(41,9)
  202. if caAPI.in_table(programs, "Cable_Remote") == true then
  203. mon.setTextColor(colors.red)
  204. mon.write("Update")
  205. mon.setCursorPos(2,9)
  206. mon.write("X")
  207. else
  208. mon.setTextColor(colors.green)
  209. mon.write("Download")
  210. end
  211. mon.setCursorPos(41,10)
  212. if caAPI.in_table(programs, "Stargate") == true then
  213. mon.setTextColor(colors.red)
  214. mon.write("Update")
  215. mon.setCursorPos(2,10)
  216. mon.write("X")
  217. else
  218. mon.setTextColor(colors.green)
  219. mon.write("Download")
  220. end
  221. mon.setCursorPos(41,11)
  222. if caAPI.in_table(programs, "Nitrosoft_Games") == true then
  223. mon.setTextColor(colors.red)
  224. mon.write("Update")
  225. mon.setCursorPos(2,11)
  226. mon.write("X")
  227. else
  228. mon.setTextColor(colors.green)
  229. mon.write("Download")
  230. end
  231. mon.setCursorPos(41,12)
  232. if caAPI.in_table(programs, "FileManager") == true then
  233. mon.setTextColor(colors.red)
  234. mon.write("Update")
  235. mon.setCursorPos(2,12)
  236. mon.write("X")
  237. else
  238. mon.setTextColor(colors.green)
  239. mon.write("Download")
  240. end
  241. mon.setCursorPos(41,13)
  242. if caAPI.in_table(programs, "NPaintTurtle") == true then
  243. mon.setTextColor(colors.red)
  244. mon.write("Update")
  245. mon.setCursorPos(2,13)
  246. mon.write("X")
  247. else
  248. mon.setTextColor(colors.green)
  249. mon.write("Download")
  250. end
  251. mon.setCursorPos(41,14)
  252. if caAPI.in_table(programs, "NPaintPro") == true then
  253. mon.setTextColor(colors.red)
  254. mon.write("Update")
  255. mon.setCursorPos(2,14)
  256. mon.write("X")
  257. else
  258. mon.setTextColor(colors.green)
  259. mon.write("Download")
  260. end
  261. mon.setCursorPos(41,15)
  262. if caAPI.in_table(programs, "BigReactor_Control") == true then
  263. mon.setTextColor(colors.red)
  264. mon.write("Update")
  265. mon.setCursorPos(2,15)
  266. mon.write("X")
  267. else
  268. mon.setTextColor(colors.green)
  269. mon.write("Download")
  270. end
  271. mon.setCursorPos(41,16)
  272. if caAPI.in_table(programs, "BigReactor_Status") == true then
  273. mon.setTextColor(colors.red)
  274. mon.write("Update")
  275. mon.setCursorPos(2,16)
  276. mon.write("X")
  277. else
  278. mon.setTextColor(colors.green)
  279. mon.write("Download")
  280. end
  281. mon.setCursorPos(41,17)
  282. if caAPI.in_table(programs, "SteelTank_Status") == true then
  283. mon.setTextColor(colors.red)
  284. mon.write("Update")
  285. mon.setCursorPos(2,17)
  286. mon.write("X")
  287. else
  288. mon.setTextColor(colors.green)
  289. mon.write("Download")
  290. end
  291. mon.setCursorPos(41,18)
  292. if caAPI.in_table(programs, "ME_Bridge") == true then
  293. mon.setTextColor(colors.red)
  294. mon.write("Update")
  295. mon.setCursorPos(2,18)
  296. mon.write("X")
  297. else
  298. mon.setTextColor(colors.green)
  299. mon.write("Download")
  300. end
  301. mon.setCursorPos(41,19)
  302. if caAPI.in_table(programs, "Energy_Cell") == true then
  303. mon.setTextColor(colors.red)
  304. mon.write("Update")
  305. mon.setCursorPos(2,19)
  306. mon.write("X")
  307. else
  308. mon.setTextColor(colors.green)
  309. mon.write("Download")
  310. end
  311. mon.setCursorPos(41,20)
  312. if caAPI.in_table(programs, "Mekanism_Reactor") == true then
  313. mon.setTextColor(colors.red)
  314. mon.write("Update")
  315. mon.setCursorPos(2,20)
  316. mon.write("X")
  317. else
  318. mon.setTextColor(colors.green)
  319. mon.write("Download")
  320. end
  321. --end
  322. touch()
  323. end
  324.  
  325. function touch()
  326. db_power = true
  327. while db_power == true do
  328. event,side,x,y = os.pullEvent()
  329. if event == "monitor_touch" then
  330. if x == 50 and y == 1 then
  331. db_power = false
  332. shell.run("clear")
  333. end
  334. if y == 2 then
  335. db_power = false
  336. past()
  337. end
  338. if x == 2 and y == 6 then
  339. delete("Radio")
  340. end
  341. if y == 6 then
  342. db_power = false
  343. download("Radio","j5ZUCFLA")
  344. end
  345. if x == 2 and y == 7 then
  346. delete("Command_Remote")
  347. end
  348. if y == 7 then
  349. db_power = false
  350. download("Command_Remote","QVwJs5kw")
  351. end
  352. if x == 2 and y == 8 then
  353. delete("Train_Control")
  354. end
  355. if y == 8 then
  356. db_power = false
  357. download("Train_Control","vXs3xKVK")
  358. end
  359. if x == 2 and y == 9 then
  360. delete("Cable_Remote")
  361. end
  362. if y == 9 then
  363. db_power = false
  364. download("Cable_Remote","1Uj9ttEB")
  365. end
  366. if x == 2 and y == 10 then
  367. delete("Stargate")
  368. end
  369. if y == 10 then
  370. db_power = false
  371. download("Stargate","m7iwSETt")
  372. end
  373. if x == 2 and y == 11 then
  374. delete("Nitrosoft_Games")
  375. end
  376. if y == 11 then
  377. db_power = false
  378. download("Nitrosoft_Games","KZsuv1pc")
  379. end
  380. if x == 2 and y == 12 then
  381. delete("FileManager")
  382. end
  383. if y == 12 then
  384. db_power = false
  385. download("FileManager","CTrCeDBt")
  386. end
  387. if x == 2 and y == 13 then
  388. delete("NPaintTurtle")
  389. end
  390. if y == 13 then
  391. db_power = false
  392. download("NPaintTurtle","tzw1Sw78")
  393. end
  394. if x == 2 and y == 14 then
  395. delete("NPaintPro")
  396. end
  397. if y == 14 then
  398. db_power = false
  399. download("NPaintPro","pzWSRqNF")
  400. end
  401. if x == 2 and y == 15 then
  402. delete("BigReactor_Control")
  403. end
  404. if y == 15 then
  405. db_power = false
  406. download("BigReactor_Control","0Jru5EvU")
  407. end
  408. if x == 2 and y == 16 then
  409. delete("BigReactor_Status")
  410. end
  411. if y == 16 then
  412. db_power = false
  413. download("BigReactor_Status","exMX8gSW")
  414. end
  415. if x == 2 and y == 17 then
  416. delete("SteelTank_Status")
  417. end
  418. if y == 17 then
  419. db_power = false
  420. download("SteelTank_Status","4d0WZkrZ")
  421. end
  422. if x == 2 and y == 18 then
  423. delete("ME_Bridge")
  424. end
  425. if y == 18 then
  426. db_power = false
  427. download("ME_Bridge","DVD7pcce")
  428. end
  429. if x == 2 and y == 19 then
  430. delete("Energy_Cell")
  431. end
  432. if y == 19 then
  433. db_power = false
  434. download("Energy_Cell","QYx2d1be")
  435. end
  436. if x == 2 and y == 20 then
  437. delete("Mekanism_Reactor")
  438. end
  439. if y == 20 then
  440. db_power = false
  441. download("Mekanism_Reactor","LSd82qiF")
  442. end
  443. end
  444. end
  445. end
  446.  
  447. --start program
  448. set_monitor()
  449. draw_screen()
Add Comment
Please, Sign In to add comment