Advertisement
alesandreo

Install.lua

Aug 11th, 2021 (edited)
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.61 KB | None | 0 0
  1. -- https://pastebin.com/hGkQUxWF
  2. if not fs then
  3.     fs = {
  4.         exists = function (file_path)
  5.             local file_handle
  6.             file_handle = io.open(file_path, 'r')
  7.             if file_handle then
  8.                 io.close(file_handle)
  9.                 return true
  10.             end
  11.             return false
  12.         end,
  13.         delete = function (file_path)
  14.             return os.remove(file_path)
  15.         end
  16.     }
  17. end
  18. if not shell then
  19.     shell = {
  20.         run = function (cli)
  21.             print(cli)
  22.         end
  23.     }
  24. end
  25. Library = {
  26.     full_path = "",
  27.     path = "",
  28.     ext = "",
  29.     filename = "",
  30.     paste_bin = "",
  31. }
  32.  
  33. Library.__index = Library
  34.  
  35. function Library:new(library_data)
  36.     library_data = library_data or {}
  37.  
  38.     local library = {}
  39.     setmetatable(library, Library)
  40.     local path_data = self.get_file_path(library_data.file_path)
  41.     library.paste_bin = library_data.paste_bin or nil
  42.     library.path = path_data.path
  43.     library.full_path = path_data.full_path
  44.     library.filename = path_data.filename
  45.     library.ext = path_data.ext
  46.     return library
  47. end
  48.  
  49. function Library.get_file_path(path)
  50.     local directory, filename, extension = string.match(path, "(.-)([^\\/]-%.?([^%.\\/]*))$")
  51.     return {
  52.         path = directory,
  53.         file = filename,
  54.         ext = extension,
  55.         full_path = directory..filename
  56.     }
  57. end
  58.  
  59. function Library:exists()
  60.     return fs.exists(self.full_path)
  61. end
  62.  
  63. function Library:delete()
  64.     if self:exists() then
  65.         fs.delete(self.full_path)
  66.     end
  67.     return true
  68. end
  69.  
  70. function Library:download()
  71.     fs.makeDir(self.path)
  72.     local cli = "pastebin get "..self.paste_bin.." "..self.full_path
  73.     print(cli)
  74.     shell.run(cli)
  75. end
  76.  
  77. function Library:refresh()
  78.     return self:install(true)
  79. end
  80.  
  81.  
  82. function Library:install(refresh)
  83.     if not refresh then refresh = false end
  84.     if refresh then
  85.         self:delete()
  86.     end
  87.     self:download()
  88. end
  89. Libraries = {
  90.     {
  91.         file_path = "lib/ale/mock/mock.lua",
  92.         paste_bin = "LJnVWtiw"
  93.     },
  94.     {
  95.         file_path = "lib/ale/turtle/blocklist.lua",
  96.         paste_bin = "tnXQrtpQ"
  97.     },
  98.     {
  99.         file_path = "lib/ale/turtle/history.lua",
  100.         paste_bin = "TFLLgAK5"
  101.     },
  102.     {
  103.         file_path = "lib/ale/turtle/inventory.lua",
  104.         paste_bin = "Xt9Z2Dk8"
  105.     },
  106.     {
  107.         file_path = "lib/ale/turtle/miner.lua",
  108.         paste_bin = "tgD36Vx7"
  109.     },
  110.     {
  111.         file_path = "lib/ale/turtle/position.lua",
  112.         paste_bin = "xzFNmXX1"
  113.     },
  114.     {
  115.         file_path = "lib/ale/turtle/turtle.lua",
  116.         paste_bin = "iEcuJ70J"
  117.     },
  118.     {
  119.         file_path = "lib/ale/ar.lua",
  120.         paste_bin = "vr5qBvMP"
  121.     },
  122.     {
  123.         file_path = "lib/ale/ale.lua",
  124.         paste_bin = "x1LfzQNz"
  125.     },
  126.     {
  127.         file_path = "lib/ale/config.lua",
  128.         paste_bin = "w0T3h4a8"
  129.     },
  130.     {
  131.         file_path = "lib/ale/crafty.lua",
  132.         paste_bin = "MqCphaSj"
  133.     },
  134.     {
  135.         file_path = "lib/ale/logger.lua",
  136.         paste_bin = "wy7Vut3x"
  137.     },
  138.     {
  139.         file_path = "lib/ale/turtle.lua",
  140.         paste_bin = "mZYfaWLA"
  141.     },
  142.     {
  143.         file_path = "lib/ale/utils.lua",
  144.         paste_bin = "PEVfiaAa"
  145.     },
  146.     {
  147.         file_path = "install.lua",
  148.         paste_bin = "hGkQUxWF"
  149.     },
  150.     {
  151.         file_path = 'LICENSE',
  152.         paste_bin = 'L5wNeEVv'
  153.     }
  154. }
  155.  
  156. for k, lib in pairs(Libraries) do
  157.     Lib = Library:new(lib)
  158.     Lib:refresh()
  159. end
  160.  
  161. if not require('lib.ale.ale') then
  162.     error("Failed to properly install.")
  163. end
  164.  
  165. fs.makeDir("configs")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement