Advertisement
GravityScore

Darklands Installer

Mar 11th, 2013
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.40 KB | None | 0 0
  1. --  Installer for NitrogenFingers' RPG Darklands: Tales from Transylvania
  2.  
  3. local function centerPrint(text, y)
  4.     if type(text) == "table" then for _, v in pairs(text) do centerPrint(v) end
  5.     else
  6.         local x, y = term.getCursorPos()
  7.         local w, h = term.getSize()
  8.         term.setCursorPos(w/2 - text:len()/2, ny or y)
  9.         print(text)
  10.     end
  11. end
  12.  
  13. local function download(url, path)
  14.     for i = 1, 3 do
  15.         local response = http.get(url)
  16.         if response then
  17.             local data = response.readAll()
  18.             response.close()
  19.             if path then
  20.                 local f = io.open(path, "w")
  21.                 f:write(data)
  22.                 f:close()
  23.             end
  24.             return true
  25.         end
  26.     end
  27.  
  28.     return false  
  29. end
  30.  
  31. function extractRepository(cpfDir, destDir)
  32.     --print("Constructing project...")
  33.     local file = io.open(cpfDir, "r")
  34.     local cFile = nil
  35.     local lc = 0
  36.    
  37.     for line in file:lines() do
  38.         if lc > 0 then
  39.             cFile:write(line.."\n")
  40.             lc = lc-1
  41.             if lc == 0 then
  42.                 cFile:close()
  43.                 --print("File write complete.")
  44.             end
  45.         elseif string.find(line, "MKDIR") == 1 then
  46.             local newDirPath = destDir.."/"..string.sub(line, 7)
  47.             if fs.exists(newDirPath) then fs.delete(newDirPath) end
  48.             fs.makeDir(newDirPath)
  49.             --print("Created dir "..newDirPath)
  50.         elseif string.find(line, "MKFIL") == 1 then
  51.             local newFilPath = destDir.."/"..string.sub(line, 7)
  52.             if fs.exists(newFilPath) then fs.delete(newFilPath) end
  53.             cFile = io.open(newFilPath, "w")
  54.             --print("Created file "..newFilPath)
  55.         elseif string.find(line, "WRITE") == 1 then
  56.             lc = tonumber(string.sub(line, 7))
  57.         end
  58.     end
  59.     --print("Project constructed.")
  60. end
  61.  
  62. term.setBackgroundColor(colors.white)
  63. term.setTextColor(colors.gray)
  64. term.clear()
  65. term.setCursorPos(1, 5)
  66.  
  67. centerPrint("Installing Darklands: Tales from Transylvania")
  68. print("")
  69. centerPrint("By NitrogenFingers")
  70. print("\n")
  71. centerPrint("...")
  72.  
  73. download("http://pastebin.com/raw.php?i=GvhXmvbS", "/.temp_to_extract")
  74. extractRepository("/.temp_to_extract", shell.resolve("/"))
  75. fs.delete("/.temp_to_extract")
  76. fs.move("/rpg/rpg", "/rpg/game")
  77. for k, v in pairs(fs.list("/rpg")) do
  78.     fs.delete("/" .. v)
  79.     fs.move("/rpg/" .. v, "/" .. v)
  80. end
  81. fs.delete("/rpg")
  82. fs.move("/game", "/rpg")
  83.  
  84. local _, y = term.getCursorPos()
  85. term.setCursorPos(1, y - 1)
  86. centerPrint("Done!")
  87. sleep(2)
  88.  
  89. term.setBackgroundColor(colors.black)
  90. term.setTextColor(colors.white)
  91. term.clear()
  92. term.setCursorPos(1, 1)
  93. print("You can run the game by running /rpg.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement