dacman9

DacInstallerRaw

Jan 31st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Vars
  2. local install = {
  3.     {id="DacLauncher",dl="d3WS3gJw",type="pb",desc="A local file browser built for CC. Can also access files stored online through a proprietary format."},
  4.     {id="DacStorage",dl="Ct3qAdnM",type="pb",desc="A cloud-based file backup solution using the DacPages login server. The online counterpart can be found at https://dacpages.tk/files."}
  5. }
  6. local w,h = term.getSize()
  7. local scroll = 0
  8. --Functions
  9. local center = function(txt,width,auto,cy)
  10.     if not width then
  11.         width = w
  12.     end
  13.     if auto then
  14.         if not cy then
  15.             _,cy = term.getCursorPos()
  16.         end
  17.         term.setCursorPos((width-#txt)/2+1,cy)
  18.         term.write(txt)
  19.     else
  20.         return (width-#txt)/2+1
  21.     end
  22. end
  23. local drawBars = function()
  24.     paintutils.drawLine(1,1,w,1,colors.red)
  25.     term.setBackgroundColor(colors.red)
  26.     term.setTextColor(colors.white)
  27.     term.setCursorPos(2,1)
  28.     term.write("DacInstaller")
  29.     paintutils.drawLine(1,h,w,h,colors.lime)
  30.     term.setBackgroundColor(colors.lime)
  31.     center("Install Selected",w,true,h)
  32. end
  33. local drawOptions = function()
  34.     for i = 1,h-2 do
  35.         if true then
  36.             if i == 1 and scroll > 0 then
  37.                 term.setBackgroundColor(colors.gray)
  38.                 paintutils.drawLine(1,2,w,2,colors.gray)
  39.                 center("^",w,true,2)
  40.             elseif i == h-2 and #install-(h-2)-scroll > 0 then
  41.                 term.setBackgroundColor(colors.gray)
  42.                 paintutils.drawLine(1,h-1,w,h-1,colors.gray)
  43.                 center("^",w,true,h-1)
  44.             elseif install[i] then
  45.                 local c
  46.                 if install[i].select then
  47.                     c = colors.gray
  48.                     term.setBackgroundColor(colors.gray)
  49.                 else
  50.                     c = colors.black
  51.                     term.setBackgroundColor(colors.black)
  52.                 end
  53.                 paintutils.drawLine(1,i+1,w,i+1,c)
  54.                 term.setCursorPos(2,i+1)
  55.                 term.write(install[i].id)
  56.                 term.setCursorPos(w-2,i+1)
  57.                 term.write("[i]")
  58.             else
  59.                 paintutils.drawLine(1,i+1,w,i+1,colors.black)
  60.             end
  61.         end
  62.     end
  63. end
  64. local info = function(title,info)
  65.     term.setBackgroundColor(colors.black)
  66.     term.clear()
  67.     term.setBackgroundColor(colors.red)
  68.     paintutils.drawLine(1,1,w,1,colors.red)
  69.     center(title,w,true,1)
  70.     term.setBackgroundColor(colors.black)
  71.     term.setCursorPos(1,2)
  72.     print(info)
  73.     term.setBackgroundColor(colors.red)
  74.     paintutils.drawLine(1,h,w,h,colors.red)
  75.     center("Close",w,true,h)
  76.     while true do
  77.         local e,a,b,c = os.pullEvent("mouse_click")
  78.         if c == h then
  79.             drawBars()
  80.             drawOptions()
  81.             break
  82.         end
  83.     end
  84. end
  85. --Code
  86. drawBars()
  87. drawOptions()
  88. while true do
  89.     local e,a,b,c = os.pullEvent()
  90.     if e == "mouse_click" then
  91.         if c == 2 and scroll > 0 then
  92.             scroll = scroll - 1
  93.             drawOptions()
  94.         elseif c == h-1 and #install-(h-2)-scroll > 0 then
  95.             scroll = scroll + 1
  96.             drawOptions()
  97.         elseif c > 1 and c < h then
  98.             if (b > w-3) then
  99.                 info(install[c-1+scroll].id,install[c-1+scroll].desc)
  100.             else
  101.                 install[c-1+scroll].select = not install[c-1+scroll].select
  102.                 drawOptions()
  103.             end
  104.         elseif c == h then
  105.             break
  106.         end
  107.     end
  108. end
  109. term.setBackgroundColor(colors.black)
  110. term.clear()
  111. local count = 0
  112. for i = 1,#install do
  113.     if install[i].select then
  114.         count = count + 1
  115.     end
  116. end
  117. local total = count
  118. for i = 1,#install do
  119.     if install[i].select then
  120.         term.clear()
  121.         term.setCursorPos(1,1)
  122.         term.write("Installing... ("..count.." / "..total..")")
  123.         if install[i].type == "pb" then
  124.             term.setCursorPos(1,2)
  125.             shell.run("pastebin","get",install[i].dl,install[i].id)
  126.         end
  127.     end
  128. end
Add Comment
Please, Sign In to add comment