forked from ebernerd/Cobalt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer
106 lines (98 loc) · 2.85 KB
/
installer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
local dlPath = "https://raw.githubusercontent.com/ebernerd/Cobalt/master/"
local args = { ... }
local beta = false
if args[1] == "beta" then
dlPath = "https://raw.githubusercontent.com/ebernerd/Cobalt/beta/"
beta = true
end
local dx, dy = term.getSize()
local function centerPrint( text, y )
term.clear()
term.setCursorPos( 1, 1 )
if beta then
write( "Cobalt Beta Version Installer" )
end
local t = {}
for i in string.gmatch( text, "%S+" ) do
t[#t+1] = i
end
local lines = {[1] = ""}
local line = 1
for i=1, #t do
if #tostring(lines[line].." "..t[i]) > dx then
lines[line] = lines[line] .. "\n"
line = line + 1
lines[line] = " " .. t[i]
else
lines[line] = lines[line] .. " " .. t[i]
end
end
y = y or math.ceil(dy/2-#lines/2)
for i = 1, #lines do
term.setCursorPos( dx/2-#lines[i]/2, y+(i-1))
print( lines[i])
end
end
local function getFile( file, path )
centerPrint( "Downloading " .. file .. " to \"" .. path .. "\"")
local dl = http.get( dlPath..file )
local h = dl.readAll()
dl.close()
local f = fs.open( path, "w" )
f.write( h )
f.close()
end
local function clear( colour )
term.setBackgroundColour( colour or term.getBackgroundColour() )
term.clear()
term.setCursorPos( 1, 1 )
end
local function yn()
local l = true
while l do
local event, key = os.pullEvent()
if event == "key" then
if key == 21 then
return true
elseif key == 49 then
return false
end
end
end
end
if beta then
term.setTextColour( colours.grey )
clear( colours.grey )
centerPrint( "Beta access is currently closed. Run again without the beta argument." )
sleep( 1 )
os.pullEvent("key_up")
clear( colours.black )
else
term.setTextColour( colours.white )
clear( colours.grey )
centerPrint( "Downloading Cobalt v1.1_3" )
sleep(0.5)
getFile( "cobalt", "cobalt" )
getFile( "cobalt-lib/surface", "cobalt-lib/surface" )
sleep(0.5)
centerPrint( "Would you like to download \"Cobalt-UI\", a UI library for Cobalt? (y/n)")
if yn() then
print()
print( "Starting Cobalt-UI download...")
getFile( "cobalt-ui/init.lua", "cobalt-ui/init.lua" )
getFile( "cobalt-ui/elements/button.lua", "cobalt-ui/elements/button.lua" )
getFile( "cobalt-ui/elements/checkbox.lua", "cobalt-ui/elements/checkbox.lua" )
getFile( "cobalt-ui/elements/radio.lua", "cobalt-ui/elements/radio.lua" )
getFile( "cobalt-ui/elements/input.lua", "cobalt-ui/elements/input.lua" )
getFile( "cobalt-ui/elements/panel.lua", "cobalt-ui/elements/panel.lua" )
getFile( "cobalt-ui/elements/text.lua", "cobalt-ui/elements/text.lua" )
getFile( "cobalt-ui/elements/textarea.lua", "cobalt-ui/elements/textarea.lua" )
centerPrint( "Download of Cobalt-UI complete!")
sleep(0.5)
end
centerPrint( "There are no other Cobalt packages as of yet. Enjoy Cobalt!")
sleep(2)
centerPrint( "Press any key to exit the installer")
os.pullEvent('key_up')
clear( colours.black )
end