costantino03

cc-tweaked-mqtt

Aug 27th, 2025 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. local width, height = term.getSize()
  2.  
  3. local function update(text)
  4.     term.setBackgroundColor(colors.black)
  5.     term.setTextColor(colors.white)
  6.     term.setCursorPos(1, 9)
  7.     term.clearLine()
  8.     term.setCursorPos(math.floor(width / 2 - string.len(text) / 2), 9)
  9.     write(text)
  10. end
  11.  
  12. local function bar(ratio)
  13.     term.setBackgroundColor(colors.gray)
  14.     term.setTextColor(colors.lime)
  15.     term.setCursorPos(1, 11)
  16.  
  17.     for i = 1, width do
  18.         if (i / width < ratio) then
  19.             write("]")
  20.         else
  21.             write(" ")
  22.         end
  23.     end
  24. end
  25.  
  26. local function download(path)
  27.     update("Downloading " .. path .. "...")
  28.  
  29.     term.setBackgroundColor(colors.black)
  30.     term.setTextColor(colors.white)
  31.     term.setCursorPos(1, 13)
  32.     term.clearLine()
  33.     term.setCursorPos(1, 14)
  34.     term.clearLine()
  35.     term.setCursorPos(1, 15)
  36.     term.clearLine()
  37.     term.setCursorPos(1, 16)
  38.     term.clearLine()
  39.     term.setCursorPos(1, 17)
  40.     term.clearLine()
  41.     term.setCursorPos(1, 13)
  42.  
  43.     print("Accessing https://raw.githubusercontent.com/WhyKickAmooCow/luamqtt-computercraft/release/" .. path)
  44.     local rawData = http.get("https://raw.githubusercontent.com/WhyKickAmooCow/luamqtt-computercraft/release/" .. path)
  45.     local data = rawData.readAll()
  46.     local file = fs.open(path, "w")
  47.     file.write(data)
  48.     file.close()
  49. end
  50.  
  51. function install()
  52.     term.setBackgroundColor(colors.black)
  53.     term.setTextColor(colors.yellow)
  54.     term.clear()
  55.  
  56.     local str = "LuaMQTT:ComputerCraft Installer"
  57.     term.setCursorPos(math.floor(width / 2 - #str / 2), 2)
  58.     write(str)
  59.  
  60.     local total = 13
  61.  
  62.     update("Installing...")
  63.     bar(0)
  64.  
  65.     download("LICENSE")
  66.     bar(1 / total)
  67.     download("README.md")
  68.     bar(2 / total)
  69.  
  70.     update("Creating mqtt folder...")
  71.     fs.makeDir("mqtt")
  72.     download("mqtt/bitwrap.lua")
  73.     bar(3 / total)
  74.     download("mqtt/cc_websocket.lua")
  75.     bar(4 / total)
  76.     download("mqtt/client.lua")
  77.     bar(5 / total)
  78.     download("mqtt/const.lua")
  79.     bar(6 / total)
  80.     download("mqtt/init.lua")
  81.     bar(7 / total)
  82.     download("mqtt/ioloop.lua")
  83.     bar(8 / total)
  84.     download("mqtt/luasocket.lua")
  85.     bar(9 / total)
  86.     download("mqtt/protocol.lua")
  87.     bar(10 / total)
  88.     download("mqtt/protocol4.lua")
  89.     bar(11 / total)
  90.     download("mqtt/protocol5.lua")
  91.     bar(12 / total)
  92.     download("mqtt/tools.lua")
  93.     bar(13 / total)
  94.  
  95.     update("Creating examples folder...")
  96.     fs.makeDir("examples")
  97.     download("examples/cc_websocket.lua")
  98.  
  99.     update("Installation finished!")
  100.  
  101.     sleep(1)
  102.  
  103.     term.setBackgroundColor(colors.black)
  104.     term.setTextColor(colors.white)
  105.     term.clear()
  106.  
  107.     term.setCursorPos(1, 1)
  108.     write("Finished installation!\nPress any key to close...")
  109.  
  110.     os.pullEventRaw()
  111.  
  112.     term.clear()
  113.     term.setCursorPos(1, 1)
  114. end
  115.  
  116. install()
Advertisement
Add Comment
Please, Sign In to add comment