Xelostar

PineStore Gallery Installer

Jul 14th, 2025
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.10 KB | None | 0 0
  1. local width, height = term.getSize()
  2.  
  3. local totalDownloaded = 0
  4.  
  5. local function update(text)
  6.     term.setBackgroundColor(colors.black)
  7.     term.setTextColor(colors.white)
  8.     term.setCursorPos(1, 9)
  9.     term.clearLine()
  10.     term.setCursorPos(math.floor(width/2 - string.len(text)/2 + 0.5), 9)
  11.     write(text)
  12. end
  13.  
  14. local function bar(ratio)
  15.     term.setBackgroundColor(colors.gray)
  16.     term.setTextColor(colors.lime)
  17.     term.setCursorPos(1, 11)
  18.  
  19.     for i = 1, width do
  20.         if (i/width < ratio) then
  21.             write("]")
  22.         else
  23.             write(" ")
  24.         end
  25.     end
  26. end
  27.  
  28. local function download(path, attempt)
  29.     local rawData = http.get("https://raw.githubusercontent.com/Xella37/PineStoreGallery/refs/heads/main/"..path)
  30.     update("Downloaded " .. path .. "!")
  31.     if not rawData then
  32.         if attempt == 3 then
  33.             error("Failed to download " .. path .. " after 3 attempts!")
  34.         end
  35.         update("Failed to download " .. path .. ". Trying again (attempt " .. (attempt+1) .. "/3)")
  36.         return download(path, attempt+1)
  37.     end
  38.     local data = rawData.readAll()
  39.     local file = fs.open(path, "w")
  40.     file.write(data)
  41.     file.close()
  42. end
  43.  
  44. local function downloadAll(downloads, total)
  45.     local nextFile = table.remove(downloads, 1)
  46.     if nextFile then
  47.         sleep(0.1)
  48.         parallel.waitForAll(function()
  49.             downloadAll(downloads, total)
  50.         end, function()
  51.             download(nextFile, 1)
  52.             totalDownloaded = totalDownloaded + 1
  53.             bar(totalDownloaded / total)
  54.         end)
  55.     end
  56. end
  57.  
  58. local function install()
  59.     term.setBackgroundColor(colors.black)
  60.     term.setTextColor(colors.orange)
  61.     term.clear()
  62.  
  63.     local str = "PineStore Gallary Installer"
  64.     term.setCursorPos(math.floor(width/2 - #str / 2 + 0.5), 2)
  65.     write(str)
  66.  
  67.     update("Installing...")
  68.     bar(0)
  69.  
  70.     local downloads = {
  71.         "gallery.lua",
  72.         "betterblittle.lua",
  73.     }
  74.  
  75.     local total = #downloads
  76.     downloadAll(downloads, total)
  77.  
  78.     update("Installation finished!")
  79.  
  80.     sleep(1)
  81.  
  82.     term.setBackgroundColor(colors.black)
  83.     term.setTextColor(colors.white)
  84.     term.clear()
  85.  
  86.     term.setCursorPos(1, 1)
  87.     write("Finished installation!\nPress any key to close...")
  88.  
  89.     os.pullEventRaw()
  90.  
  91.     term.clear()
  92.     term.setCursorPos(1, 1)
  93. end
  94.  
  95. install()
  96.  
Advertisement
Add Comment
Please, Sign In to add comment