Advertisement
Corbinhol

Custom Basalt Installer

Oct 2nd, 2022
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  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. local httpReq = http.get(url, _G._GIT_API_KEY and {Authorization = "token ".._G._GIT_API_KEY})
  34. if(httpReq~=nil)then
  35. local content = httpReq.readAll()
  36. if not content then
  37. error("Could not connect to website")
  38. end
  39. local f = fs.open(file, "w")
  40. f.write(content)
  41. f.close()
  42. end
  43. end
  44.  
  45. local function downloadProject(dir, ignoreList)
  46. local projTree = createTree("https://api.github.com/repos/Pyroxenium/Basalt/git/trees/master:Basalt")
  47. local projectFiles = {base={}}
  48.  
  49. local function isFileInIgnoreList(folder, file)
  50. if(ignoreList~=nil)then
  51. if(ignoreList[folder]~=nil)then
  52. for k,v in pairs(ignoreList[folder])do
  53. if(v==file)then
  54. return true
  55. end
  56. end
  57. end
  58. end
  59. return false
  60. end
  61. for k,v in pairs(projTree)do
  62. if(k=="objects")then
  63. projectFiles.objects = {}
  64. for a,b in pairs(v)do
  65. if not(isFileInIgnoreList("objects", b))then
  66. table.insert(projectFiles.objects, b)
  67. end
  68. end
  69. elseif(k=="libraries")then
  70. projectFiles.libraries = {}
  71. for a,b in pairs(v)do
  72. if not(isFileInIgnoreList("libraries", b))then
  73. table.insert(projectFiles.libraries, b)
  74. end
  75. end
  76. else
  77. table.insert(projectFiles.base, v)
  78. end
  79. end
  80.  
  81. fs.makeDir(dir)
  82. fs.makeDir(dir.."/objects")
  83. fs.makeDir(dir.."/libraries")
  84. for _,v in pairs(projectFiles["objects"])do
  85. download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/Basalt/objects/"..v, dir.."/objects/"..v)
  86. end
  87. for _,v in pairs(projectFiles["libraries"])do
  88. download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/Basalt/libraries/"..v, dir.."/libraries/"..v)
  89. end
  90. for _,v in pairs(projectFiles["base"])do
  91. download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/Basalt/"..v, dir.."/"..v)
  92. end
  93. end
  94.  
  95. if(#args>0)then
  96. if(string.lower(args[1])=="bpm")or(string.lower(args[1])=="basaltpackagemanager")then
  97. download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/basaltPackageManager.lua", "basaltPackageManager.lua")
  98. if(args[2]=="true")then shell.run("basaltPackageManager.lua") fs.delete("basaltPackageManager.lua") end
  99. elseif(string.lower(args[1])=="packer")or(string.lower(args[1])=="basaltpacker")then
  100. download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/basaltPackager.lua", "basaltPackager.lua")
  101. if(args[2]=="true")then shell.run("basaltPackager.lua") fs.delete("basaltPackager.lua") end
  102.  
  103. elseif(string.lower(args[1])=="packed")then
  104. downloadProject(args[3] or "Basalt")
  105. download("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/basaltPackager.lua", "basaltPackager.lua")
  106. shell.run("basaltPackager.lua "..(args[3] or "Basalt").." "..(args[2] or "true").." "..(args[3]~=nil and args[3]:gsub(".lua", "")..".lua" or ""))
  107. fs.delete(args[3] or "Basalt")
  108. fs.delete("basaltPackager.lua")
  109. elseif(string.lower(args[1])=="modified")then
  110. if(args[2]~=nil)then
  111. local projDir = args[3] or "Basalt"
  112. local arg = splitString(args[2], ":")
  113. downloadProject(projDir, {
  114. objects = splitString(arg[1], "|"),
  115. libraries = splitString(arg[2], "|")
  116. })
  117. else
  118. downloadProject("Basalt")
  119. end
  120. else
  121. downloadProject(args[1] or "Basalt")
  122. end
  123. else
  124. downloadProject("Basalt")
  125. end
  126. if(fs.exists("basaltInstaller.lua"))then
  127. --fs.delete("basaltInstaller.lua")
  128. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement