SHARE
TWEET

Cobalt Installer

CCCoder Jun 30th, 2016 (edited) 814 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local dlPath = "https://raw.githubusercontent.com/ebernerd/Cobalt/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. local function centerPrint( text, y )
  12.     term.clear()
  13.     term.setCursorPos( 1, 1 )
  14.     if beta then
  15.         write( "Cobalt Beta Version Installer" )
  16.     end
  17.     local t = {}
  18.     for i in string.gmatch( text, "%S+" ) do
  19.         t[#t+1] = i
  20.     end
  21.     local lines = {[1] = ""}
  22.     local line = 1
  23.     for i=1, #t do
  24.         if #tostring(lines[line].." "..t[i]) > dx then
  25.             lines[line] = lines[line] .. "\n"
  26.             line = line + 1
  27.             lines[line] = " " .. t[i]
  28.         else
  29.             lines[line] = lines[line] .. " " .. t[i]
  30.         end
  31.     end
  32.     y = y or math.ceil(dy/2-#lines/2)
  33.     for i = 1, #lines do
  34.         term.setCursorPos( dx/2-#lines[i]/2, y+(i-1))
  35.         print( lines[i])
  36.     end
  37. end
  38.  
  39. local function getFile( file, path )
  40.     centerPrint( "Downloading " .. file .. " to \"" .. path .. "\"")
  41.     local dl = http.get( dlPath..file )
  42.     local h = dl.readAll()
  43.     dl.close()
  44.  
  45.     local f = fs.open( path, "w" )
  46.     f.write( h )
  47.     f.close()
  48. end
  49.  
  50. local function clear( colour )
  51.     term.setBackgroundColour( colour or term.getBackgroundColour() )
  52.     term.clear()
  53.     term.setCursorPos( 1, 1 )
  54. end
  55.  
  56. local function yn()
  57.     local l = true
  58.     while l do
  59.         local event, key = os.pullEvent()
  60.         if event == "key" then
  61.             if key == 21 then
  62.                 return true
  63.             elseif key == 49 then
  64.                 return false
  65.             end
  66.         end
  67.     end
  68. end
  69.  
  70. if beta then
  71.     term.setTextColour( colours.grey )
  72.     clear( colours.grey )
  73.     centerPrint( "Beta access is currently closed. Run again without the beta argument." )
  74.     sleep( 1 )
  75.     os.pullEvent("key_up")
  76.     clear( colours.black )
  77.    
  78. else
  79.     term.setTextColour( colours.white )
  80.     clear( colours.grey )
  81.     centerPrint( "Downloading Cobalt v1.1_3" )
  82.     sleep(0.5)
  83.     getFile( "cobalt", "cobalt" )
  84.     getFile( "cobalt-lib/surface", "cobalt-lib/surface" )
  85.     sleep(0.5)
  86.     centerPrint( "Would you like to download \"Cobalt-UI\", a UI library for Cobalt? (y/n)")
  87.     if yn() then
  88.         print()
  89.         print( "Starting Cobalt-UI download...")
  90.         getFile( "cobalt-ui/init.lua", "cobalt-ui/init.lua" )
  91.         getFile( "cobalt-ui/elements/button.lua", "cobalt-ui/elements/button.lua" )
  92.         getFile( "cobalt-ui/elements/checkbox.lua", "cobalt-ui/elements/checkbox.lua" )
  93.         getFile( "cobalt-ui/elements/radio.lua", "cobalt-ui/elements/radio.lua" )
  94.         getFile( "cobalt-ui/elements/input.lua", "cobalt-ui/elements/input.lua" )
  95.         getFile( "cobalt-ui/elements/panel.lua", "cobalt-ui/elements/panel.lua" )
  96.         getFile( "cobalt-ui/elements/text.lua", "cobalt-ui/elements/text.lua" )
  97.         getFile( "cobalt-ui/elements/textarea.lua", "cobalt-ui/elements/textarea.lua" )
  98.         centerPrint( "Download of Cobalt-UI complete!")
  99.         sleep(0.5)
  100.     end
  101.     centerPrint( "There are no other Cobalt packages as of yet. Enjoy Cobalt!")
  102.     sleep(2)
  103.     centerPrint( "Press any key to exit the installer")
  104.     os.pullEvent('key_up')
  105.     clear( colours.black )
  106. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top