This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
YAGUI_downloader.lua
66 lines (57 loc) · 1.71 KB
/
YAGUI_downloader.lua
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
local repo = 'https://raw.githubusercontent.com/Marco4413/YAGUI/'
local master = repo..'master/'
local PROGRAMS = {
{
NAME = 'YAGUI', -- Name to be displayed
URL = master..'YAGUI-mini.lua', -- URL to the file
PATH = '/YAGUI.lua' -- Path where to save the file
},
{
NAME = 'WSS_Client',
URL = master..'examples/WSS_Client.lua',
PATH = '/WSS_Client.lua'
},
{
NAME = 'HPainter',
URL = master..'examples/HPainter.lua',
PATH = '/HPainter.lua'
},
{
NAME = 'Note',
URL = master..'examples/Note-mini.lua',
PATH = '/Note.lua'
}
}
local function better_print(text, fg, bg)
local old_fg = term.getTextColor()
local old_bg = term.getBackgroundColor()
if fg then term.setTextColor(fg); end
if bg then term.setBackgroundColor(bg); end
if text then print(text); end
term.setTextColor(old_fg)
term.setBackgroundColor(old_bg)
end
local function download_as(URL, PATH)
local text = http.get(URL).readAll()
local file = fs.open(PATH, 'w')
file.write(text)
file.close()
end
local function download_programs()
for _, program in next, PROGRAMS do
download_as(program.URL, program.PATH)
better_print(program.NAME..' was downloaded!', colors.green)
end
end
local function remove_programs()
for _, program in next, PROGRAMS do
if fs.exists(program.PATH) then
fs.delete(program.PATH)
better_print(program.NAME..' was removed.', colors.red)
end
end
end
better_print('Removing old Programs...', colors.orange)
remove_programs()
better_print('Downloading Programs...', colors.orange)
download_programs()