SirSheepe

1.16 Cobalt Installer

Jan 10th, 2021 (edited)
982
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local dlPath = "https://raw.githubusercontent.com/ebernerd/cobalt-2/master/"
  2. local args = { ... }
  3. local beta = false
  4. if args[1] == "beta" then
  5.   dlPath = "https://raw.githubusercontent.com/ebernerd/Cobalt/beta/"
  6.   beta = true
  7. end
  8.  
  9. local dx, dy = term.getSize()
  10.  
  11. fs.delete("cobalt")
  12.  
  13. local function centerPrint( text, y )
  14.     term.clear()
  15.     term.setCursorPos( 1, 1 )
  16.     if beta then
  17.         write( "Cobalt Beta Version Installer" )
  18.     end
  19.     local t = {}
  20.     for i in string.gmatch( text, "%S+" ) do
  21.         t[#t+1] = i
  22.     end
  23.     local lines = {[1] = ""}
  24.     local line = 1
  25.     for i=1, #t do
  26.         if #tostring(lines[line].." "..t[i]) > dx then
  27.             lines[line] = lines[line] .. "\n"
  28.             line = line + 1
  29.             lines[line] = " " .. t[i]
  30.         else
  31.             lines[line] = lines[line] .. " " .. t[i]
  32.         end
  33.     end
  34.     y = y or math.ceil(dy/2-#lines/2)
  35.     for i = 1, #lines do
  36.         term.setCursorPos( dx/2-#lines[i]/2, y+(i-1))
  37.         print( lines[i])
  38.     end
  39. end
  40.  
  41. local function getFile( file)
  42.     local path = "cobalt/" .. file
  43.     centerPrint( "Downloading " .. file .. " to \"" .. path .. "\"")
  44.     local dl = http.get( dlPath..file )
  45.     local h = dl.readAll()
  46.     dl.close()
  47.  
  48.     local f = fs.open( path, "w" )
  49.     f.write( h )
  50.     f.close()
  51. end
  52.  
  53. local function clear( colour )
  54.     term.setBackgroundColour( colour or term.getBackgroundColour() )
  55.     term.clear()
  56.     term.setCursorPos( 1, 1 )
  57. end
  58.  
  59. local function yn()
  60.     local l = true
  61.     while l do
  62.         local event, key = os.pullEvent()
  63.         if event == "key" then
  64.             if key == 89 then
  65.                 return true
  66.             elseif key == 78 then
  67.                 return false
  68.             end
  69.         end
  70.     end
  71. end
  72.  
  73. if beta then
  74.     term.setTextColour( colours.grey )
  75.     clear( colours.grey )
  76.     centerPrint( "Beta access is currently closed. Run again without the beta argument." )
  77.     sleep( 1 )
  78.     os.pullEvent("key_up")
  79.     clear( colours.black )
  80.    
  81. else
  82.     term.setTextColour( colours.white )
  83.     clear( colours.grey )
  84.     centerPrint( "Downloading Cobalt v2" )
  85.     sleep(0.5)
  86.     sleep(0.5)
  87.         print()
  88.         print( "Starting Cobalt-UI download...")
  89.         getFile( "init.lua" )
  90.         getFile( "lib/clasp.lua" )
  91.         getFile( "lib/surface.lua" )
  92.         getFile( "lib/modules/graphics/init.lua" )
  93.         getFile( "lib/modules/graphics/classes/Canvas.lua" )
  94.         getFile( "lib/modules/graphics/classes/Drawable.lua" )
  95.         getFile( "lib/modules/graphics/classes/Image.lua" )
  96.         getFile( "lib/modules/keyboard/init.lua" )
  97.         getFile( "lib/modules/mouse/init.lua" )
  98.         centerPrint( "Download of Cobalt complete!")
  99.         sleep(0.5)
  100.     centerPrint( "There are no other Cobalt packages as of yet. Enjoy Cobalt!")
  101.     sleep(2)
  102.     centerPrint( "Press any key to exit the installer")
  103.     os.pullEvent('key_up')
  104.     clear( colours.black )
  105. end
RAW Paste Data