CCHacker132

InstallProgram

Nov 30th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. term.setBackgroundColor(colors.cyan)
  2. term.clear()
  3. local inputname
  4. local inputcode
  5. function redrawlines()
  6.     paintutils.drawLine(2,6,50,6,colors.lightGray)
  7.     paintutils.drawLine(2,10,50,10,colors.lightGray)
  8.     inputname = ''
  9.     inputcode = ''
  10. end
  11. redrawlines()
  12. redrawlines()
  13. term.setBackgroundColor(colors.cyan)
  14. term.setCursorPos(3,5)
  15. write('Program Name')
  16. term.setCursorPos(3,9)
  17. write('Pastebin Code')
  18. term.setCursorPos(22,13)
  19. term.setBackgroundColor(colors.blue)
  20. term.setTextColor(colors.black)
  21. write('Install')
  22. term.setCursorPos(50,2)
  23. term.setBackgroundColor(colors.red)
  24. term.setTextColor(colors.black)
  25. write('X')
  26. local stop = false
  27. repeat
  28.     term.setBackgroundColor(colors.blue)
  29.     term.setTextColor(colors.black)
  30.     term.setCursorPos(22,13)
  31.     write('Install')
  32.     local _, m, x, y = os.pullEvent('mouse_click')
  33.     term.setBackgroundColor(colors.lightGray)
  34.     term.setTextColor(colors.gray)
  35.     if y == 6 then
  36.         term.setCursorPos(2,6)
  37.         inputname = read()
  38.     elseif y == 10 then
  39.         term.setCursorPos(2,10)
  40.         inputcode = read()
  41.     elseif y == 13 and x >= 22 and x <= 29 then
  42.         if inputname == '' then
  43.             term.setCursorPos(3,11)
  44.             term.setBackgroundColor(colors.cyan)
  45.             term.setTextColor(colors.red)
  46.             write('Please insert a file name!')
  47.         elseif inputcode == '' then
  48.             term.setCursorPos(3,11)
  49.             term.setBackgroundColor(colors.cyan)
  50.             term.setTextColor(colors.red)
  51.             write('Please insert a pastebin code!')
  52.         else
  53.             term.setCursorPos(1,11)
  54.             term.setBackgroundColor(colors.cyan)
  55.             term.setTextColor(colors.lime)
  56.             print('Installing Program...')
  57.             if fs.exists('programs/'..inputname) then
  58.                 fs.delete('programs/'..inputname)
  59.             end
  60.             shell.run('pastebin get '..inputcode..' '..'programs/'..inputname)
  61.             if fs.exists('programs/'..inputname) then
  62.                 local oldtext = {}
  63.                 local file = fs.open('programlist','r')
  64.                 repeat
  65.                     local text = file.readLine()
  66.                     if text ~= nil then
  67.                         table.insert(oldtext,text)
  68.                     end
  69.                 until text == nil
  70.                 file.close()
  71.                 local file = fs.open('programlist','w')
  72.                 for i,v in ipairs(oldtext) do
  73.                     file.writeLine(v)
  74.                 end
  75.                 local color1 = math.random(0,15)
  76.                 local color2 = math.random(0,14)
  77.                 if color2 >= color1 then
  78.                     color2 = color2 + 1
  79.                 end
  80.                 local count = #fs.list('programs/')
  81.                 local x = math.floor((count/7)+1)
  82.                 local y = count%7
  83.                 file.writeLine(x*2)
  84.                 file.writeLine(y*2)
  85.                 file.writeLine(2^color1)
  86.                 file.writeLine(2^color2)
  87.                 file.writeLine(string.byte(string.sub(inputname,1,1)))
  88.                 file.writeLine(inputname)
  89.             end
  90.         end
  91.         sleep(2)
  92.         term.setBackgroundColor(colors.cyan)
  93.         paintutils.drawFilledBox(1,11,51,19,colors.cyan)
  94.         redrawlines()
  95.     elseif y == 2 and x == 50 then
  96.         stop = true
  97.     end
  98. until stop
Add Comment
Please, Sign In to add comment