Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Installer for NitrogenFingers' RPG Darklands: Tales from Transylvania
- local function centerPrint(text, y)
- if type(text) == "table" then for _, v in pairs(text) do centerPrint(v) end
- else
- local x, y = term.getCursorPos()
- local w, h = term.getSize()
- term.setCursorPos(w/2 - text:len()/2, ny or y)
- print(text)
- end
- end
- local function download(url, path)
- for i = 1, 3 do
- local response = http.get(url)
- if response then
- local data = response.readAll()
- response.close()
- if path then
- local f = io.open(path, "w")
- f:write(data)
- f:close()
- end
- return true
- end
- end
- return false
- end
- function extractRepository(cpfDir, destDir)
- --print("Constructing project...")
- local file = io.open(cpfDir, "r")
- local cFile = nil
- local lc = 0
- for line in file:lines() do
- if lc > 0 then
- cFile:write(line.."\n")
- lc = lc-1
- if lc == 0 then
- cFile:close()
- --print("File write complete.")
- end
- elseif string.find(line, "MKDIR") == 1 then
- local newDirPath = destDir.."/"..string.sub(line, 7)
- if fs.exists(newDirPath) then fs.delete(newDirPath) end
- fs.makeDir(newDirPath)
- --print("Created dir "..newDirPath)
- elseif string.find(line, "MKFIL") == 1 then
- local newFilPath = destDir.."/"..string.sub(line, 7)
- if fs.exists(newFilPath) then fs.delete(newFilPath) end
- cFile = io.open(newFilPath, "w")
- --print("Created file "..newFilPath)
- elseif string.find(line, "WRITE") == 1 then
- lc = tonumber(string.sub(line, 7))
- end
- end
- --print("Project constructed.")
- end
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.gray)
- term.clear()
- term.setCursorPos(1, 5)
- centerPrint("Installing Darklands: Tales from Transylvania")
- print("")
- centerPrint("By NitrogenFingers")
- print("\n")
- centerPrint("...")
- download("http://pastebin.com/raw.php?i=GvhXmvbS", "/.temp_to_extract")
- extractRepository("/.temp_to_extract", shell.resolve("/"))
- fs.delete("/.temp_to_extract")
- fs.move("/rpg/rpg", "/rpg/game")
- for k, v in pairs(fs.list("/rpg")) do
- fs.delete("/" .. v)
- fs.move("/rpg/" .. v, "/" .. v)
- end
- fs.delete("/rpg")
- fs.move("/game", "/rpg")
- local _, y = term.getCursorPos()
- term.setCursorPos(1, y - 1)
- centerPrint("Done!")
- sleep(2)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- print("You can run the game by running /rpg.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement