Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local repoCode = "t5zqJg6U"
- local lpath = shell.resolve("nitrochess")
- print("NitroChess Installer")
- print("A chess game for 2 players local or network")
- local function printC(str, col)
- if col and term.isColour() then
- term.setTextColour(col)
- end
- print(str)
- term.setTextColour(colours.white)
- end
- local function extractRepository(cpfDir, destDir)
- print("\nConstructing project...")
- local f1 = fs.open(shell.resolve("temprepo"), "r")
- local f2 = nil
- local fcount = 0
- local line = f1.readLine()
- while line do
- if string.sub(line,1,5) == "MKDIR" then
- fs.makeDir(shell.resolve(string.sub(line,7)))
- elseif string.sub(line,1,5) == "MKFIL" then
- fcount = fcount + 1
- f2 = fs.open(shell.resolve(string.sub(line, 7)), "w")
- elseif string.sub(line,1,5) == "WRITE" then
- count = tonumber(string.sub(line,7))
- while count > 0 do
- f2.writeLine(f1.readLine())
- count = count - 1
- end
- f2.close()
- end
- line = f1.readLine()
- end
- f1.close()
- printC("Project constructed. "..fcount.." files created")
- end
- if not http then
- printC("\nHTTP not enabled on this computer. Installation aborted.", colours.red)
- return 2
- end
- if fs.exists(lpath) then
- printC("\n/"..lpath.." already exists. Rename or use another directory to install.", colours.red)
- return 1
- end
- print("\nInstalling to the following directory:")
- if term.isColour() then term.setTextColour(colours.yellow) end
- print(" /"..lpath.."\n")
- term.setTextColour(colours.white)
- term.write("Ready to install? Y/N: ")
- while true do
- local _,p1 = os.pullEvent("key")
- if p1 == keys.y then
- printC("Y\n", colours.lime)
- break
- elseif p1 == keys.n then
- printC("N\n", colours.red)
- printC("Installation cancelled!")
- return 1
- end
- end
- local trval = ""
- if (fs.exists(shell.resolve("temprepo"))) then
- trval = 0
- while (fs.exists(shell.resolve("temprepo"..trval))) do
- trval = trval + 1
- end
- end
- print("Downloading repo "..repoCode.."...")
- if not shell.run("pastebin", "get", repoCode, "temprepo"..trval) then
- print("Installation failed; could not access pastebin", colours.red)
- return 2
- end
- extractRepository(shell.resolve("temprepo"..trval), shell.resolve("."))
- fs.delete(shell.resolve("temprepo"..trval))
- if term.isColour() then term.setTextColour(colours.lime) end
- print("Installation complete!")
- return 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement