Advertisement
FFGFlash

NekOS_Installer.lua

Oct 13th, 2022 (edited)
1,289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.69 KB | None | 0 0
  1. if http then
  2.   local function download(user, repo, dpath, rpath, branch, extract)
  3.     if repo == nil or user == nil then return false,"User and Repo required" end
  4.     if rpath == nil then rpath = "" end
  5.     if dpath == nil then dpath = "/Downloads/" end
  6.     if branch == nil then branch = "main" end
  7.     if extract == nil then extract = false end
  8.  
  9.     local function downloadManager(path, files, dirs)
  10.       if not files then files = {} end
  11.       if not dirs then dirs = {} end
  12.       local fType,fPath,fName,cPath = {},{},{},{}
  13.       local res = http.get("https://cc-nekos.herokuapp.com/api/github/"..user.."/"..repo.."/content?branch="..branch.."&path="..path)
  14.       if not res then return false,"Can't Resolve Download URL" end
  15.       res = res.readAll()
  16.       if res ~= nil then
  17.         for str in res:gmatch('"type":"(%w+)"') do table.insert(fType, str) end
  18.         for str in res:gmatch('"path":"([^\"]+)"') do table.insert(fPath, str) end
  19.         for str in res:gmatch('"name":"([^\"]+)"') do table.insert(fName, str) end
  20.       end
  21.       for i,data in pairs(fType) do
  22.         local path = dpath.."/"
  23.         if not extract then
  24.           path = path..repo.."/"
  25.         end
  26.         if data == "file" then
  27.           cPath = http.get("https://cc-nekos.herokuapp.com/api/github/"..user.."/"..repo.."/"..branch.."?path="..fPath[i])
  28.           if cPath == nil then fPath[i] = fPath[i].."/"..fName[i] end
  29.           path = path..fPath[i]
  30.           if not files[path] then
  31.             files[path] = { "https://cc-nekos.herokuapp.com/api/github/"..user.."/"..repo.."/"..branch.."?path="..fPath[i], fName[i] }
  32.           end
  33.         elseif data == "dir" then
  34.           path = path..fPath[i]
  35.           if not dirs[path] then
  36.             dirs[path] = { "https://cc-nekos.herokuapp.com/api/github/"..user.."/"..repo.."/"..branch.."?path="..fPath[i], fName[i] }
  37.             downloadManager(fPath[i], files, dirs)
  38.           end
  39.         end
  40.       end
  41.       return {files=files, dirs=dirs}
  42.     end
  43.  
  44.     local function downloadFile(path, url, name)
  45.       local dirPath = path:gmatch('([%w%_%.% %-%+%,%;%:%*%#%=%/]+)/'..name..'$')()
  46.       if dirPath ~= nil and not fs.isDir(dirPath) then fs.makeDir(dirPath) end
  47.       local content = http.get(url)
  48.       local file = fs.open(path,"w")
  49.       file.write(content.readAll())
  50.       file.close()
  51.     end
  52.  
  53.     local res,err = downloadManager(rpath)
  54.     if not res then return res,err end
  55.     for i,data in pairs(res.files) do downloadFile(i, table.unpack(data)) end
  56.  
  57.     return true
  58.   end
  59.  
  60.   local res,err = download("FFGFlash", "NekOS", "/", nil, nil, true)
  61.   if not res then return print(err) end
  62.   os.reboot()
  63. else
  64.   print("You need to enable the HTTP API!")
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement