toastonrye

[CC]: Basalt - UI Framework Installer

Aug 1st, 2022
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- this file can download the project or other tools from github
  2.  
  3. local args = table.pack(...)
  4.  
  5. -- Creates a filetree based on my github project, ofc you can use this in your projects if you'd like to
  6. local function createTree(page)
  7.     local tree = {}
  8.     local request = http.get(page, _G._GIT_API_KEY and {Authorization = "token ".._G._GIT_API_KEY})
  9.     if not(page)then return end
  10.     if(request==nil)then error("To many requests! You have to wait a couple of hours.") end
  11.     for _,v in pairs(textutils.unserialiseJSON(request.readAll()).tree)do
  12.         if(v.type=="blob")then
  13.             table.insert(tree, v.path)
  14.         elseif(v.type=="tree")then
  15.             tree[v.path] = createTree(page.."/"..v.path)
  16.         end
  17.     end
  18.     return tree
  19. end
  20.  
  21. local function splitString(str, sep)
  22.     if sep == nil then
  23.             sep = "%s"
  24.     end
  25.     local t={}
  26.     for v in string.gmatch(str, "([^"..sep.."]+)") do
  27.             table.insert(t, v)
  28.     end
  29.     return t
  30. end
  31.  
  32. local function download(url, file)
  33.     print("Downloading "..url)
  34.     local httpReq = http.get(url, _G._GIT_API_KEY and {Authorization = "token ".._G._GIT_API_KEY})
  35.         if(httpReq~=nil)then
  36.         local content = httpReq.readAll()
  37.         if not content then
  38.             error("Could not connect to website")
  39.         end
  40.         local f = fs.open(file, "w")
  41.         f.write(content)
  42.         f.close()
  43.     end
  44. end
  45.  
  46. local function downloadProject(dir, ignoreList)
  47.     local projTree = createTree("https://api.github.com/repos/Pyroxenium/Basalt/git/trees/master:Basalt")
  48.     local projectFiles = {base={}}
  49.  
  50.     local function isFileInIgnoreList(folder, file)
  51.         if(ignoreList~=nil)then
  52.             if(ignoreList[folder]~=nil)then
  53.                 for k,v in pairs(ignoreList[folder])do
  54.                     if(v==file)then
  55.                         return true
  56.                     end
  57.                 end
  58.             end
  59.         end
  60.         return false
  61.     end
  62.     for k,v in pairs(projTree)do
  63.         if(k=="objects")then
  64.             projectFiles.objects = {}
  65.             for a,b in pairs(v)do
  66.                 if not(isFileInIgnoreList("objects", b))then
  67.                     table.insert(projectFiles.objects, b)
  68.                 end
  69.             end
  70.         elseif(k=="libraries")then
  71.             projectFiles.libraries = {}
  72.             for a,b in pairs(v)do
  73.                 if not(isFileInIgnoreList("libraries", b))then
  74.                     table.insert(projectFiles.libraries, b)
  75.                 end
  76.             end
  77.         else
  78.             table.insert(projectFiles.base, v)
  79.         end
  80.     end
  81.  
  82.     fs.makeDir(dir)
  83.     fs.makeDir(dir.."/objects")
  84.     fs.makeDir(dir.."/libraries")
  85.     for _,v in pairs(projectFiles["objects"])do
  86.         download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/Basalt/objects/"..v, dir.."/objects/"..v)
  87.     end
  88.     for _,v in pairs(projectFiles["libraries"])do
  89.         download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/Basalt/libraries/"..v, dir.."/libraries/"..v)
  90.     end
  91.     for _,v in pairs(projectFiles["base"])do
  92.         download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/Basalt/"..v, dir.."/"..v)
  93.     end
  94. end
  95.  
  96. if(#args>0)then
  97.     if(string.lower(args[1])=="bpm")or(string.lower(args[1])=="basaltpackagemanager")then
  98.         download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/basaltPackageManager.lua", "basaltPackageManager.lua")
  99.         if(args[2]=="true")then shell.run("basaltPackageManager.lua") fs.delete("basaltPackageManager.lua") end
  100.     elseif(string.lower(args[1])=="packer")or(string.lower(args[1])=="basaltpacker")then
  101.         download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/basaltPackager.lua", "basaltPackager.lua")
  102.         if(args[2]=="true")then shell.run("basaltPackager.lua") fs.delete("basaltPackager.lua") end
  103.        
  104.     elseif(string.lower(args[1])=="packed")then
  105.         downloadProject(args[3] or "Basalt")
  106.         download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/basaltPackager.lua", "basaltPackager.lua")
  107.         shell.run("basaltPackager.lua "..(args[3] or "Basalt").." "..(args[2] or "true").." "..(args[3]~=nil and args[3]:gsub(".lua", "")..".lua" or ""))
  108.         fs.delete(args[3] or "Basalt")
  109.         fs.delete("basaltPackager.lua")
  110.     elseif(string.lower(args[1])=="modified")then
  111.         if(args[2]~=nil)then
  112.             local projDir = args[3] or "Basalt"
  113.             local arg = splitString(args[2], ":")
  114.             downloadProject(projDir, {
  115.                 objects = splitString(arg[1], "|"),
  116.                 libraries = splitString(arg[2], "|")
  117.             })
  118.         else
  119.             downloadProject("Basalt")
  120.         end
  121.     else
  122.         print("Downloading the project...")
  123.     downloadProject(args[1] or "Basalt")
  124.     print("Done!")
  125.     end
  126. else
  127.     print("Downloading the project...")
  128.     downloadProject("Basalt")
  129.     print("Done!")
  130. end
  131. if(fs.exists("basaltInstaller.lua"))then
  132.     --fs.delete("basaltInstaller.lua")
  133. end
Add Comment
Please, Sign In to add comment