Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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"] = "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"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement