QuickMuffin8782-Alt

Untitled

Nov 8th, 2020 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function drawProgBar(done, max)
  2.  
  3. local value = done / max
  4. local _, y = term.getCursorPos()
  5. local wide, _ = term.getSize()
  6. term.setCursorPos(1,y)
  7. term.clearLine()
  8. term.write(("="):rep(math.floor(value * (wide - 6))))
  9. term.setCursorPos(math.floor(value * (wide - 6)), y)
  10. term.write(">")
  11. term.setCursorPos(wide - 6, y)
  12. term.write("]")
  13. term.setCursorPos(1, y)
  14. term.write("[")
  15. term.setCursorPos(wide - 5, y)
  16. term.write("     ")
  17.  
  18. local percent = math.floor(value * 100) .. "%"
  19. term.setCursorPos(wide - percent:len(),y)
  20. term.write(percent)
  21.  
  22. end
  23.  
  24. local function extractRepository(cpfDir, destDir)
  25.         print("Constructing project...")
  26.         local file = io.open(cpfDir, "r")
  27.         local cFile = nil
  28.         local lc = 0
  29.         local total = 0
  30.         local ox,oy = term.getCursorPos()
  31.        
  32.         for line in file:lines() do
  33.                 if lc > 0 then
  34.                         cFile:write(line.."\n")
  35.                         lc = lc-1
  36.                         term.clearLine()
  37.                         term.setCursorPos(ox,oy)
  38.                         if lc == 0 then
  39.                                 cFile:close()
  40.                 drawProgBar(total-lc, total)
  41.                 print()
  42.                                 print("File write complete.")
  43.                         else
  44.                             drawProgBar(total-lc, total)
  45.                         end
  46.                 elseif string.find(line, "MKDIR") == 1 then
  47.                         local newDirPath = destDir.."/"..string.sub(line, 7)
  48.                         if fs.exists(newDirPath) then fs.delete(newDirPath) end
  49.                         fs.makeDir(newDirPath)
  50.                         print("Created dir "..newDirPath)
  51.                 elseif string.find(line, "MKFIL") == 1 then
  52.                         local newFilPath = destDir.."/"..string.sub(line, 7)
  53.                         if fs.exists(newFilPath) then fs.delete(newFilPath) end
  54.                         cFile = io.open(newFilPath, "w")
  55.                         print("Created file "..newFilPath)
  56.                         ox,oy = term.getCursorPos()
  57.                 elseif string.find(line, "WRITE") == 1 then
  58.                         lc = tonumber(string.sub(line, 7))
  59.                         total = lc
  60.                 end
  61.                 sleep(0)
  62.         end
  63.         print("Project constructed.")
  64. end
  65.  
  66. local lpath = "/"
  67.  
  68. local repoCode = "Pht0fFEU"
  69.  
  70. if fs.exists(lpath .. "startup.lua") then
  71.         print(lpath.." already exists. Rename or use another directory to install.")
  72.         return
  73. end
  74.  
  75. print("iGP OS Installer")
  76. print("Beta version 1.x.x")
  77. print("\nInstalling to the following directory:")
  78. term.setTextColour(colours.yellow)
  79. print("  "..lpath.."\n")
  80. term.setTextColour(colours.white)
  81. term.write("Ready to install? Y/N: ")
  82.  
  83. while true do
  84.         local _,p1 = os.pullEvent("key")
  85.         if p1 == keys.y then
  86.                 term.setTextColour(colours.lime)
  87.                 print("Y\n")
  88.                 break
  89.         elseif p1 == keys.n then
  90.                 term.setTextColour(colours.red)
  91.                 print("N\n")
  92.                 os.pullEvent()
  93.                 return
  94.         end
  95. end
  96.  
  97. term.setTextColour(colours.white)
  98. print("Downloading "..repoCode.."... ")
  99. if not shell.run("pastebin", "get", repoCode, "glrepo") then
  100.         term.setTextColour(colours.red)
  101.         print("failed!")
  102.         return
  103. end
  104.  
  105. extractRepository(shell.resolve(".").."/glrepo", shell.resolve("."))
  106. print("Deleting archive...")
  107. fs.delete(shell.resolve(".").."/glrepo")
  108.  
  109. print("Installation complete!")
Add Comment
Please, Sign In to add comment