Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function drawProgBar(done, max, x, y, wide, colorBright, colorDark)
- local oldX, oldY = term.getCursorPos()
- local oldBC = term.getBackgroundColor()
- local oldTC = term.getTextColor()
- local val = done / max
- term.setBackgroundColor(colors.black)
- term.setTextColour(colors.black)
- if oldBC == colors.black then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.gray)
- end
- term.setCursorPos(x,y)
- write((string.char(153)):rep(wide))
- term.setTextColor(colorDark)
- term.setBackgroundColor(colorBright)
- term.setCursorPos(x,y)
- write((string.char(153)):rep(math.floor(val
- * wide)))
- term.setBackgroundColor(oldBC)
- term.setTextColour(oldTC)
- term.setCursorPos(oldX, oldY)
- end
- function calcPercent(done, max)
- local val = done / max
- local per = math.floor(val * 100)
- return per
- end
- function tableCount(t)
- local table = t
- local count = 0
- for _ in pairs(table) do
- count = count + 1
- end
- return count
- end
- function smoothAdd(fromNum, toNum, speed)
- return ((toNum - fromNum) / (speed or 10))
- end
- function cwrite(txt, y)
- local w, h = term.getSize()
- if type(y) ~= "number" then error("y coordinate expected, got " .. type(y), 2) end
- if type(y) ~= "string" and type(y) ~= "number" then error("string or number expected for the text, got " .. type(txt), 2) end
- term.setCursorPos((w/2)-(#txt/2), y)
- term.write(txt)
- end
- function getVersion()
- local verNum = {1,0,0}
- return "v" .. verNum[1] .. "." .. verNum[2] .. "." .. verNum[3]
- end
- function showTitle(subtitle, txt, prog, progMax)
- local w, h = term.getSize()
- local showProg = false
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.clear()
- local t1, t2 = (txt and txt or ""), (subtitle and subtitle or "")
- if prog and progMax then showProg = true end
- term.setTextColor(colors.blue)
- term.setBackgroundColor(colors.white)
- term.setCursorPos(1, (h/2)-1)
- term.clearLine()
- cwrite("CCManger " .. getVersion(), (h/2)-1)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.lightBlue)
- cwrite(t2, (h/2))
- term.setTextColor(colors.white)
- cwrite(t1, (h/2) + 2)
- if showProg then
- drawProgBar(prog, progMax, (w/2)-(((w/4)*3)/2), (h/2)+3, ((w/4)*3), colors.white, colors.white)
- end
- end
- local function get(sUrl)
- -- Check if the URL is valid
- local ok, err = http.checkURL(url)
- if not ok then
- return nil
- end
- local response = http.get(sUrl , nil , true)
- if not response then
- return nil
- end
- local sResponse = response.readAll()
- response.close()
- return sResponse
- end
- local dataDir = {
- "config/",
- "misc/",
- "misc/rednet",
- "api/"
- }
- local apiDir = {
- ["zipmenu.lua"] = "https://pastebin.com/raw/c0xg0m8Z"
- }
- local diskDrives = {}
- if fs.exists("/disk*/") then
- diskDrives = fs.find("/disk*/")
- end
- showTitle("Welcome to CCManage!")
- sleep(2)
- showTitle("Welcome to CCManage!", "Press any key to start!")
- os.pullEvent("key")
- for a, b in pairs(dataDir) do
- showTitle("Checking for data directory...", b .. " (" .. a .. "/" .. #dataDir .. ")", a, #dataDir)
- if not fs.exists(".ccmanage/" .. b) then fs.makeDir(".ccmanage/" .. b) end
- sleep(0.1)
- end
- local i = 1
- for a, b in pairs(apiDir) do
- local txt = nil
- parallel.waitForAny(function()
- repeat
- txt = --[[nil]] get(b)
- sleep(0.1)
- until txt ~= nil
- end, function()
- for j = 1, 15 do
- showTitle("Downloading needed api(s)...", "Downloading " .. a, i - 1, #apiDir)
- sleep(0.3)
- showTitle("Downloading needed api(s)...", "Downloading " .. a, i, #apiDir)
- sleep(0.3)
- end
- while true do
- showTitle("Downloading needed api(s)...", "Check your connection, is it on?", i - 1, #apiDir)
- sleep(0.3)
- showTitle("Downloading needed api(s)...", "Check your connection, is it on?", i, #apiDir)
- sleep(0.3)
- end
- end)
- local f = io.open(".ccmanage/api/" .. a, "w")
- f:write(txt)
- f:close()
- i = i + 1
- end
- local i = nil
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
Add Comment
Please, Sign In to add comment