-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.lua
116 lines (93 loc) · 3.01 KB
/
update.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
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
VERSION = '0.7.0'
local args = {...};
-- old pastebin version
--[[
local files = {
hPuYQY5V = 'lib.lua',
tM7zrqc1 = 'tetris.lua',
}
if args[1] == true then -- updater
print('Tetris updater\n');
term.setCursorBlink(true);
for link,name in pairs(files) do
local res = http.get('https://pastebin.com/raw/'..link);
local code, msg = res.getResponseCode();
if code == 200 then
local handle = fs.open(name,'w');
handle.write(res.readAll());
handle.close();
print('Downloaded '..name);
else
print('Failed to download '..name..': '..msg);
end
res.close();
end
print('\nUpdate complete');
else -- installer
print('Tetris installer\n');
term.setCursorBlink(true);
if fs.exists('lib.lua') then
print('deleting lib.lua');
fs.copy('lib.lua','lib.lua.bak_'..tostring(os.epoch()));
fs.delete('lib.lua');
end
shell.run('pastebin get hPuYQY5V lib.lua');
if fs.exists('tetris.lua') then
print('deleting tetris.lua');
fs.copy('tetris.lua','tetris.lua.bak_'..tostring(os.epoch()));
fs.delete('tetris.lua');
end
shell.run('pastebin get tM7zrqc1 tetris.lua');
print('\nInstallation complete');
print('Type tetris to start playing');
end
]]
local files = {
'lib.lua',
'tetris.lua',
}
if args[1] == true then -- updater
print('Tetris updater\n');
term.setCursorBlink(true);
for _,name in pairs(files) do
local res = http.get('https://raw.githubusercontent.com/ChickChicky/CC_Tetris/main/'..name);
local code, msg = res.getResponseCode();
if code == 200 then
local handle = fs.open(name,'w');
handle.write(res.readAll());
handle.close();
term.setTextColor(colors.green) print('Downloaded '..name);
else
term.setTextColor(colors.red) print('Failed to download '..name..': '..msg);
end
res.close();
end
term.setTextColor(colors.white);
print('\nUpdate complete');
else -- installer
print('Tetris installer\n');
term.setCursorBlink(true);
for _,name in pairs(files) do
local res = http.get('https://raw.githubusercontent.com/ChickChicky/CC_Tetris/main/'..name);
local code, msg = res.getResponseCode();
if code == 200 then
local handle = fs.open(name,'w');
handle.write(res.readAll());
handle.close();
print('Downloaded '..name);
else
print('Failed to download '..name..': '..msg);
end
res.close();
end
print('\nInstallation complete');
print('Type tetris to start playing');
end
local completion = require('cc.shell.completion');
shell.setCompletionFunction(
'tetris.lua',
completion.build(
{completion.choice, {"update"}}
)
);
print();