Advertisement
nitrogenfingers

darklands installer

Mar 11th, 2013
2,379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 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.         sleep(0)
  59.     end
  60.     --print("Project constructed.")
  61. end
  62.  
  63. term.setBackgroundColor(colors.white)
  64. term.setTextColor(colors.gray)
  65. term.clear()
  66. term.setCursorPos(1, 5)
  67.  
  68. centerPrint("Installing Darklands: Tales from Transylvania")
  69. print("")
  70. centerPrint("By NitrogenFingers")
  71. print("\n")
  72. centerPrint("...")
  73.  
  74. download("http://pastebin.com/raw.php?i=GvhXmvbS", "/.temp_to_extract")
  75. extractRepository("/.temp_to_extract", shell.resolve("/"))
  76. fs.delete("/.temp_to_extract")
  77. fs.move("/rpg/rpg", "/rpg/game")
  78. for k, v in pairs(fs.list("/rpg")) do
  79.     fs.delete("/" .. v)
  80.     fs.move("/rpg/" .. v, "/" .. v)
  81. end
  82. fs.delete("/rpg")
  83. fs.move("/game", "/rpg")
  84.  
  85. local _, y = term.getCursorPos()
  86. term.setCursorPos(1, y - 1)
  87. centerPrint("Done!")
  88. sleep(2)
  89.  
  90. term.setBackgroundColor(colors.black)
  91. term.setTextColor(colors.white)
  92. term.clear()
  93. term.setCursorPos(1, 1)
  94. print("You can run the game by running /rpg.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement