Advertisement
nitrogenfingers

vaultinstall

Sep 11th, 2014
2,312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.15 KB | None | 0 0
  1. local function extractRepository(cpfDir, destDir)
  2.         print("Constructing project...")
  3.         local file = io.open(cpfDir, "r")
  4.         local cFile = nil
  5.         local lc = 0
  6.                 local total = 0
  7.                 local ox,oy = term.getCursorPos()
  8.                
  9.         for line in file:lines() do
  10.                 if lc > 0 then
  11.                         cFile:write(line.."\n")
  12.                         lc = lc-1
  13.                                                 term.clearLine()
  14.                                                 term.setCursorPos(ox,oy)
  15.                         if lc == 0 then
  16.                                 cFile:close()
  17.                                 print("File write complete.")
  18.                         else
  19.                                                         term.write(((total-lc)/total * 100).."%")
  20.                                                 end
  21.                 elseif string.find(line, "MKDIR") == 1 then
  22.                         local newDirPath = destDir.."/"..string.sub(line, 7)
  23.                         if fs.exists(newDirPath) then fs.delete(newDirPath) end
  24.                         fs.makeDir(newDirPath)
  25.                         print("Created dir "..newDirPath)
  26.                 elseif string.find(line, "MKFIL") == 1 then
  27.                         local newFilPath = destDir.."/"..string.sub(line, 7)
  28.                         if fs.exists(newFilPath) then fs.delete(newFilPath) end
  29.                         cFile = io.open(newFilPath, "w")
  30.                         print("Created file "..newFilPath)
  31.                                                 ox,oy = term.getCursorPos()
  32.                 elseif string.find(line, "WRITE") == 1 then
  33.                         lc = tonumber(string.sub(line, 7))
  34.                                                 total = lc
  35.                 end
  36.                                 sleep(0)
  37.         end
  38.         print("Project constructed.")
  39. end
  40.  
  41. local lpath = shell.resolve(".").."/vault"
  42.  
  43. local repoCode = "1Jwzsjkt"
  44.  
  45. if fs.exists(lpath) then
  46.         print(lpath.." already exists. Rename or use another directory to install.")
  47.         return
  48. end
  49.  
  50. print("Bank Vault Installer")
  51. print("Includes exe and 3 level packs")
  52. print("\nInstalling to the following directory:")
  53. term.setTextColour(colours.yellow)
  54. print("  "..lpath.."\n")
  55. term.setTextColour(colours.white)
  56. term.write("Ready to install? Y/N: ")
  57.  
  58. while true do
  59.         local _,p1 = os.pullEvent("key")
  60.         if p1 == keys.y then
  61.                 term.setTextColour(colours.lime)
  62.                 print("Y\n")
  63.                 break
  64.         elseif p1 == keys.n then
  65.                 term.setTextColour(colours.red)
  66.                 print("N\n")
  67.                                 os.pullEvent()
  68.                 return
  69.         end
  70. end
  71.  
  72. term.setTextColour(colours.white)
  73. print("Downloading "..repoCode.."... ")
  74. if not shell.run("pastebin", "get", repoCode, "glrepo") then
  75.         term.setTextColour(colours.red)
  76.         print("failed!")
  77.         return
  78. end
  79.  
  80. extractRepository(shell.resolve(".").."/glrepo", shell.resolve("."))
  81. print("Deleting archive...")
  82. fs.delete(shell.resolve(".").."/glrepo")
  83.  
  84. print("Installation complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement