-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRRComputer.lua
More file actions
214 lines (183 loc) · 4.86 KB
/
RRComputer.lua
File metadata and controls
214 lines (183 loc) · 4.86 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
-- Computer Program Agent
-- By RlonRyan
--
-- UgW5W9FM
--
-- This program allows for the easy setup of RR|Programs (for ComputerCraft).
-- It will also attempt to update RR|Programs when run.
-- It uses the RR|Programs list found on github to find programs.
--
-- Dependencies:
-- (All dependencies will auto-download and install)
--
-- Installation instructions:
-- Use: pastebin get UgW5W9FM RR|Computer
--
-- Install disk instructions:
-- Save the line:
-- shell.run("pastebin get UgW5W9FM RR|Computer")
-- To disk/autorun
--
-- Run instructions:
-- Use: RR|Computer
local path = shell.getRunningProgram() .. "Resources"
local overwrite = true
function output(text, color)
color = color or colors.white
term.setTextColor(color)
write(text)
term.setTextColor(colors.white)
end
function outputln(text, color) -- Dirty Funtion.
color = color or colors.white
term.setTextColor(color)
print(text)
term.setTextColor(colors.white)
end
function bar()
outputln("================", colors.lightGray)
end
function br()
print()
end
function err(...)
-- TODO: Add Error formatter.
br()
bar()
for line in args do
outputln(text, colors.red)
end
bar()
br()
end
function reset()
term.clear()
term.setCursorPos(1,1)
outputln("RR|Program Setup", colors.green)
bar()
br()
end
function validate(filepath)
--print(string.match(filepath, "%a+"))
if(string.find(filepath, "/") and not fs.exists(string.match(filepath, "%a+"))) then
fs.makeDir(string.match(filepath, "%a+"))
return true
elseif(not fs.exists(filepath)) then
return true
elseif(not checkversion) then
fs.delete(filepath)
return true
elseif(overwrite) then
fs.delete(filepath)
return true
else
err("Bad filepath: " .. filepath)
return false
end
end
function downloadPaste(paste, filepath)
if(not validate(filepath)) then
return false
else
return shell.run("pastebin", "get", paste, filepath)
end
end
function downloadHttp(address, filepath)
if(not validate(filepath)) then
err("Could not download: " .. address .. " to: " .. filepath)
return false
else
outputln("Installing:", colors.gray)
outputln("\tFrom: " .. address, colors.gray)
outputln("\tTo: " .. filepath, colors.gray)
temp = http.get(address)
if(temp) then
content = temp.readAll()
temp.close()
temp = fs.open(filepath, "w")
if(not temp) then
err("Cannot write file: " .. filepath)
return false
end
temp.write(content)
temp.close()
return true
else
err("Unable to fetch file. Is the internet down?", "Or have you not yet enabled http for computercraft?")
return false
end
end
end
function getManifest(address)
temp = http.get(address .. "/manifest.mf")
if(temp) then
manifest = textutils.unserialize(temp.readAll())
temp.close()
return manifest
else
err("Unable to fetch file. Is the internet down?", "Or have you not yet enabled http for computercraft?")
return false
end
end
reset()
print("Validating Directories.")
fs.delete(path)
fs.makeDir(path)
reset()
print("Updating programs list.")
programs = getManifest("https://raw.githubusercontent.com/RlonRyan/RRComputerCraft/master")
reset()
outputln("Updating installation agent.")
br()
bar()
br()
downloadHttp("https://raw.githubusercontent.com/RlonRyan/RRComputerCraft/master/RRDownloader.lua", path .. "/RRDownloader")
reset()
outputln("Obtaining Dependencies.")
reset()
outputln("Initialization Completed.")
br()
bar()
br()
output("Press any key to continue.")
io.read()
reset()
outputln("Available Programs")
bar()
menu = {}
i = 1
for k,v in pairs(programs) do
menu[i] = k
output(i .. ".) ", colors.yellow)
output(k, colors.lightBlue)
output(" by ", colors.lightGray)
outputln(v["author"], colors.cyan)
i = i + 1
end
br()
bar()
outputln("Select Programs: ")
bar()
for selection in string.gmatch((io.read()), "[^%s]+") do
selection = tonumber(selection)
src = string.lower(programs[menu[selection]]["source"])
if (src == "pastebin" or src == "paste") then
shell.run(path .. "/RRDownloader", "pastebin", programs[menu[selection]]["paste"], programs[menu[selection]]["program"])
elseif (src == "gist") then
shell.run(path .. "/RRDownloader", "gist", programs[menu[selection]]["gist"], programs[menu[selection]]["program"])
elseif (src == "http") then
shell.run(path .. "/RRDownloader", "http", programs[menu[selection]]["address"], programs[menu[selection]]["program"])
elseif (src == "github" or src == "git") then
shell.run(path .. "/RRDownloader", "github", programs[menu[selection]]["author"], programs[menu[selection]]["repo"], programs[menu[selection]]["branch"], programs[menu[selection]]["file"], programs[menu[selection]]["program"])
end
i = i + 1
end
reset()
outputln("Action(s) Completed.")
br()
bar()
br()
output("Press any key to continue.")
io.read()
term.clear()
term.setCursorPos(1,1)