-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate.lua
More file actions
149 lines (136 loc) · 3.41 KB
/
Copy pathupdate.lua
File metadata and controls
149 lines (136 loc) · 3.41 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
local function clear()
term.clear()
term.setCursorPos(1, 1)
end
local function get(user, repo, bran, path, save)
if not user or not repo or not bran or not path then
error("not enough arguments, expected 4 or 5", 2)
end
local url = "https://raw.github.com/"..user.."/"..repo.."/"..bran.."/"..path
local remote = http.get(url)
if not remote then
return false
end
local text = remote.readAll()
remote.close()
if save then
local file = fs.open(save, "w")
file.write(text)
file.close()
return true
end
return text
end
local function yesno(text, title, start)
local function clear()
term.clear()
term.setCursorPos(1, 1)
end
local function drawButton(buttonText, x, y, x2, y2, enabled)
if enabled then
term.setBackgroundColor(colors.white)
else
if term.isColor() then
term.setBackgroundColor(colors.gray)
end
end
term.setCursorPos(x, y)
for _y = y, y2 do
for _x = x, x2 do
term.setCursorPos(_x, _y)
write(" ")
end
end
term.setCursorPos(x+math.floor((x2-x)/2)-math.floor(buttonText:len()/2), y+math.floor((y2-y+1)/2))
term.setTextColor(colors.black)
write(buttonText)
term.setTextColor(colors.white)
term.setBackgroundColor(colors.black)
end
local function cprint(text)
local x, y = term.getCursorPos()
local w, h = term.getSize()
term.setCursorPos(math.floor(w/2)-math.floor(text:len()/2), y)
print(text)
end
local selected = true
local function redraw()
clear()
cprint(title)
term.setCursorPos(1, 3)
print(text)
local w, h = term.getSize()
drawButton("Yes", 2, h-1, math.floor(w/2)-1, h-1, selected)
drawButton("No", math.floor(w/2)+1, h-1, w-1, h-1, not selected)
end
if start ~= nil and type(start) == "boolean" then
selected = start
end
while true do
redraw()
local eventData = {os.pullEventRaw()}
if eventData[1] == "terminate" then
clear()
return
elseif eventData[1] == "key" then
if eventData[2] == keys.up or eventData[2] == keys.down or eventData[2] == keys.left or eventData[2] == keys.right then
selected = not selected
elseif eventData[2] == keys.enter then
clear()
return selected
end
end
sleep(0)
end
end
local function getFile(file, target)
return get("jordyvl", "dual-network-printer", "master", file, target)
end
shell.setDir("")
clear()
print("Network Printing Install or Update")
print("Getting files...")
local files = {
["Print"] = "Dualprint/print",
["pview"] = "Dualprint/Connected",
["update.lua"] = "Dualprint/update",
}
local fileCount = 0
for _ in pairs(files) do
fileCount = fileCount + 1
end
local filesDownloaded = 0
local w, h = term.getSize()
local pb
if ui and term.isColor() and ui.progressBar then
pb = ui.progressBar(1,h-2,w,colors.green,true)
end
for k, v in pairs(files) do
term.setTextColor(colors.black)
term.setBackgroundColor(colors.white)
clear()
term.setCursorPos(2, 2)
print("DualPrint Update!")
term.setCursorPos(2, 4)
print("File: "..v)
term.setCursorPos(2, h - 1)
if pb then
pb.percent = math.floor(filesDownloaded / fileCount * 100)
pb:draw()
else
print(tostring(math.floor(filesDownloaded / fileCount * 100)).."% - "..tostring(filesDownloaded + 1).."/"..tostring(fileCount))
end
local ok = getFile(k, v)
if not ok then
if term.isColor() then
term.setTextColor(colors.red)
end
term.setCursorPos(2, 6)
print("Error.")
sleep(1)
end
filesDownloaded = filesDownloaded + 1
end
term.clear()
term.setCursorPos(1,1)
print"Install Completed"