View difference between Paste ID: SSty2Ms5 and iAeub14a
SHOW: | | - or go back to the newest paste.
1
function drawProgBar(done, max, x, y, wide, colorBright, colorDark)
2
  local oldX, oldY = term.getCursorPos()
3
  local oldBC = term.getBackgroundColor()
4
  local oldTC = term.getTextColor()
5
  local val = done / max
6
  term.setBackgroundColor(colors.black)
7
  term.setTextColour(colors.black)
8
  if oldBC == colors.black then
9
      term.setBackgroundColor(colors.black)
10
      term.setTextColor(colors.gray)
11
  end
12
  term.setCursorPos(x,y)
13
  write((string.char(153)):rep(wide))
14
  term.setTextColor(colorDark)
15
  term.setBackgroundColor(colorBright)
16
  term.setCursorPos(x,y)
17
  write((string.char(153)):rep(math.floor(val
18
   * wide)))
19
  term.setBackgroundColor(oldBC)
20
  term.setTextColour(oldTC)
21
  term.setCursorPos(oldX, oldY)
22
end
23
24
function calcPercent(done, max)
25
  local val = done / max
26
  local per = math.floor(val * 100)
27
  return per
28
end
29
30
function tableCount(t)
31
  local table = t
32
  local count = 0
33
  for _ in pairs(table) do
34
      count = count + 1
35
  end
36
  return count
37
end
38
39
function smoothAdd(fromNum, toNum, speed)
40
return ((toNum - fromNum) / (speed or 10))
41
end
42
43
function cwrite(txt, y)
44
  local w, h = term.getSize()
45
  if type(y) ~= "number" then error("y coordinate expected, got " .. type(y), 2) end
46
  if type(y) ~= "string" and type(y) ~= "number" then error("string or number expected for the text, got " .. type(txt), 2) end
47
  term.setCursorPos((w/2)-(#txt/2), y)
48
  term.write(txt)
49
end
50
51
function getVersion()
52
  local verNum = {1,0,0}
53
  return "v" .. verNum[1] .. "." .. verNum[2] .. "." .. verNum[3]
54
end
55
56
function showTitle(subtitle, txt, prog, progMax)
57
  local w, h = term.getSize()
58
  local showProg = false
59
  term.setBackgroundColor(colors.gray)
60
  term.setTextColor(colors.white)
61
  term.clear()
62
  local t1, t2 = (txt and txt or ""), (subtitle and subtitle or "")
63
  if prog and progMax then showProg = true end
64
  term.setTextColor(colors.blue)
65
  term.setBackgroundColor(colors.white)
66
  term.setCursorPos(1, (h/2)-1)
67
  term.clearLine()
68
  cwrite("CCManger " .. getVersion(), (h/2)-1)
69
  term.setBackgroundColor(colors.gray)
70
  term.setTextColor(colors.lightBlue)
71
  cwrite(t2, (h/2))
72
  term.setTextColor(colors.white)
73
  cwrite(t1, (h/2) + 2)
74
  if showProg then
75
    drawProgBar(prog, progMax, (w/2)-(((w/4)*3)/2), (h/2)+3, ((w/4)*3), colors.white, colors.white)
76
  end
77
end
78
79
local function get(sUrl)
80
  -- Check if the URL is valid
81
  local ok, err = http.checkURL(url)
82
  if not ok then
83
      return nil
84
  end
85
86
  local response = http.get(sUrl , nil , true)
87
  if not response then
88
      return nil
89
  end
90
91
  local sResponse = response.readAll()
92
  response.close()
93
  return sResponse
94
end
95
96
local dataDir = {
97
  "config/",
98
  "misc/",
99
  "misc/rednet",
100
  "api/"
101
}
102
103
local apiDir = {
104
  ["zipmenu.lua"] = "https://pastebin.com/raw/c0xg0m8Z"
105
}
106
107
local diskDrives = {}
108
109
if fs.exists("/disk*/") then
110
  diskDrives = fs.find("/disk*/")
111
end
112
113
showTitle("Welcome to CCManage!")
114
sleep(2)
115
showTitle("Welcome to CCManage!", "Press any key to start!")
116
os.pullEvent("key")
117
118
for a, b in pairs(dataDir) do
119
  showTitle("Checking for data directory...", b .. " (" .. a .. "/" .. #dataDir .. ")", a, #dataDir)
120
  if not fs.exists(".ccmanage/" .. b) then fs.makeDir(".ccmanage/" .. b) end
121
  sleep(0.1)
122
end
123
124
local i = 1
125
for a, b in pairs(apiDir) do
126
  local txt = nil
127
  parallel.waitForAny(function()
128
    repeat
129
      txt = --[[nil]] get(b)
130
      sleep(0.1)
131
    until txt ~= nil
132
  end, function()
133
    for j = 1, 15 do
134
      showTitle("Downloading needed api(s)...", "Downloading " .. a, i - 1, #apiDir)
135
      sleep(0.3)
136
      showTitle("Downloading needed api(s)...", "Downloading " .. a, i, #apiDir)
137
      sleep(0.3)
138
    end
139
    while true do
140
      showTitle("Downloading needed api(s)...", "Check your connection, is it on?", i - 1, #apiDir)
141
      sleep(0.3)
142
      showTitle("Downloading needed api(s)...", "Check your connection, is it on?", i, #apiDir)
143
      sleep(0.3)
144
    end
145
  end)
146
  local f = io.open(".ccmanage/api/" .. a, "w")
147
  f:write(txt)
148
  f:close()
149
  i = i + 1
150
end
151
local i = nil
152
153
term.setBackgroundColor(colors.black)
154
term.clear()
155
term.setCursorPos(1,1)
156