forked from Quenty/NevermoreEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall.lua
272 lines (232 loc) · 9.15 KB
/
Install.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
-- Universal Github Installer
-- @see Validark
-- function GitHub:Install(Link, Parent)
-- @returns <Folder/LuaSourceContainer> from Link found starting at Link into Parent
local function GetFirstChild(Parent, Name, Class)
if Parent then -- GetFirstChildWithNameOfClass
local Objects = Parent:GetChildren()
for a = 1, #Objects do
local Object = Objects[a]
if Object.Name == Name and Object.ClassName == Class then
return Object
end
end
end
local Child = Instance.new(Class)
Child.Name = Name
Child.Parent = Parent
return Child, true
end
-- Services
local HttpService = game:GetService("HttpService")
-- Module
local GitHub = {}
local DataSources = {}
-- Helper Functions
local ScriptTypes = {
[""] = "ModuleScript";
["local"] = "LocalScript";
["module"] = "ModuleScript";
["mod"] = "ModuleScript";
["loc"] = "LocalScript";
}
local function UrlDecode(Character)
return string.char(tonumber(Character, 16))
end
local OpenGetRequests = 0
local function GetAsync(...)
repeat until OpenGetRequests == 0 or not wait()
local Success, Data = pcall(HttpService.GetAsync, HttpService, ...)
if Success then
return Data
elseif Data:find("HTTP 429") or Data:find("Number of requests exceeded limit") then
wait(math.random(5))
warn("Too many requests")
return GetAsync(...)
elseif Data:find("Http requests are not enabled") then
OpenGetRequests = OpenGetRequests + 1
require(script.Parent.UI):CreateSnackbar(Data)
repeat
local Success, Data = pcall(HttpService.GetAsync, HttpService, ...)
until Success and not Data:find("Http requests are not enabled") or require(script.Parent.UI):CreateSnackbar(Data) or not wait(1)
OpenGetRequests = 0
return GetAsync(...)
else
error(Data .. (...), 0)
end
end
local function GiveSourceToScript(Link, Script)
DataSources[Script] = Link
Script.Source = GetAsync(Link)
end
local function InstallRepo(Link, Directory, Parent, Routines, TypesSpecified)
local Value = #Routines + 1
Routines[Value] = false
local MainExists
local ScriptCount = 0
local Scripts = {}
local FolderCount = 0
local Folders = {}
for Link in GetAsync(Link):gmatch("<tr class=\"js%-navigation%-item\">.-<a class=\"js%-navigation%-open\" title=\"[^\"]+\" id=\"[^\"]+\"%s*href=\"([^\"]+)\".-</tr>") do
if Link:find("/[^/]+/[^/]+/tree") then
FolderCount = FolderCount + 1
Folders[FolderCount] = Link
elseif Link:find("/[^/]+/[^/]+/blob.+%.lua$") then
local ScriptName, ScriptClass = Link:match("([%w-_%%]+)%.?(%l*)%.lua$")
if ScriptName:lower() ~= "install" then
if ScriptClass == "mod" or ScriptClass == "module" then TypesSpecified = true end
if ScriptName == "_" or ScriptName:lower() == "main" then
ScriptCount = ScriptCount + 1
for a = ScriptCount, 2, -1 do
Scripts[a] = Scripts[a - 1]
end
Scripts[1] = Link
MainExists = true
else
ScriptCount = ScriptCount + 1
Scripts[ScriptCount] = Link
end
end
end
end
if ScriptCount > 0 then
local ScriptLink = Scripts[1]
local ScriptName, ScriptClass = ScriptLink:match("([%w-_%%]+)%.?(%l*)%.lua$")
ScriptName = ScriptName:gsub("Library$", "", 1):gsub("%%(%x%x)", UrlDecode)
local Sub = Link:sub(19)
local Link = Sub:gsub("^(/[^/]+/[^/]+)/tree/[^/]+", "%1", 1)
local LastFolder = Link:match("[^/]+$")
LastFolder = LastFolder:match("^RBX%-(.-)%-Library$") or LastFolder
if MainExists then
local Directory = LastFolder:gsub("%%(%x%x)", UrlDecode)
ScriptName, ScriptClass = Directory:match("([%w-_%%]+)%.?(%l*)%.lua$")
if not ScriptName then ScriptName = Directory:match("^RBX%-(.-)%-Library$") or Directory end
if ScriptClass == "mod" or ScriptClass == "module" then TypesSpecified = true end
end
-- if MainExists or ScriptCount ~= 1 or ScriptName ~= (LastFolder:match("^RBX%-(.-)%-Library$") or LastFolder) then
if MainExists then Directory = Directory + 1 end -- :gsub("[^/]+$", "", 1) end
local Count = 0
local function LocateFolder(FolderName)
Count = Count + 1
if Count > Directory then
Directory = Directory + 1
FolderName = FolderName:gsub("Engine$", "")
if (Parent and Parent.Name) ~= FolderName and "Modules" ~= FolderName then
local Success, Service = pcall(game.GetService, game, FolderName)
if FolderName ~= "Lighting" and Success and Service then
Parent = Service
else
local Generated
Parent, Generated = GetFirstChild(Parent, FolderName, "Folder")
if Generated then
if not Routines[1] then Routines[1] = Parent end
DataSources[Parent] = "https://github.com" .. (Sub:match(("/[^/]+"):rep(Directory > 2 and Directory + 2 or Directory)) or warn("[1]", Sub, Directory > 1 and Directory + 2 or Directory) or "")
end
end
end
end
end
Link:gsub("[^/]+$", ""):gsub("[^/]+", LocateFolder)
if MainExists or ScriptCount ~= 1 or ScriptName ~= LastFolder then
LocateFolder(LastFolder)
end
local Script = GetFirstChild(Parent, ScriptName, ScriptTypes[ScriptClass or TypesSpecified and "" or "mod"])
if not Routines[1] then Routines[1] = Script end
coroutine.resume(coroutine.create(GiveSourceToScript), "https://raw.githubusercontent.com" .. ScriptLink:gsub("(/[^/]+/[^/]+/)blob/", "%1", 1), Script)
if MainExists then
Parent = Script
end
for a = 2, ScriptCount do
local Link = Scripts[a]
local ScriptName, ScriptClass = Link:match("([%w-_%%]+)%.?(%l*)%.lua$")
local Script = GetFirstChild(Parent, ScriptName:gsub("Library$", "", 1):gsub("%%(%x%x)", UrlDecode), ScriptTypes[ScriptClass or TypesSpecified and "" or "mod"])
coroutine.resume(coroutine.create(GiveSourceToScript), "https://raw.githubusercontent.com" .. Link:gsub("(/[^/]+/[^/]+/)blob/", "%1", 1), Script)
end
end
for a = 1, FolderCount do
local Link = Folders[a]
coroutine.resume(coroutine.create(InstallRepo), "https://github.com" .. Link, Directory, Parent, Routines, TypesSpecified)
end
Routines[Value] = true
end
function GitHub:Install(Link, Parent, RoutineList)
-- Installs Link into Parent
if Link:byte(-1) == 47 then --gsub("/$", "")
Link = Link:sub(1, -2)
end
-- Extract Link Data
local Organization, Repository, Tree, ScriptName, ScriptClass
local Website, Directory = Link:match("^(https://[raw%.]*github[usercontent]*%.com/)(.+)")
Organization, Directory = (Directory or Link):match("^/?([%w-_%.]+)/?(.*)")
Repository, Directory = Directory:match("^([%w-_%.]+)/?(.*)")
if Website == "https://raw.githubusercontent.com/" then
if Directory then
Tree, Directory = Directory:match("^([^/]+)/(.+)")
if Directory then
ScriptName, ScriptClass = Directory:match("([%w-_%%]+)%.?(%l*)%.lua$")
end
end
elseif Directory then
local a, b = Directory:find("^[tb][rl][eo][eb]/[^/]+")
if a and b then
Tree, Directory = Directory:sub(6, b), Directory:sub(b + 1)
if Directory == "" then Directory = nil end
if Directory and Link:find("blob") then
ScriptName, ScriptClass = Directory:match("([%w-_%%]+)%.?(%l*)%.lua$")
end
else
Directory = nil
end
end
if not Website then Website = "https://github.com/" end
Directory = Directory and ("/" .. Directory):gsub("^//", "/") or ""
-- Threads
local Routines = RoutineList or {false}
local Value = #Routines + 1
Routines[Value] = false
local Garbage
if ScriptName then
Link = "https://raw.githubusercontent.com/" .. Organization .. "/" .. Repository .. "/" .. (Tree or "master") .. Directory
local Source = GetAsync(Link)
local Script = GetFirstChild(Parent and not RoutineList and Repository ~= ScriptName and Parent.Name ~= ScriptName and GetFirstChild(Parent, Repository, "Folder") or Parent, ScriptName:gsub("Library$", "", 1):gsub("%%(%x%x)", UrlDecode), ScriptTypes[ScriptClass or "mod"])
DataSources[Script] = Link
if not Routines[1] then Routines[1] = Script end
Script.Source = Source
elseif Repository then
Link = Website .. Organization .. "/" .. Repository .. ((Tree or Directory ~= "") and ("/tree/" .. (Tree or "master") .. Directory) or "")
if not Parent then Parent, Garbage = Instance.new("Folder"), true end
coroutine.resume(coroutine.create(InstallRepo), Link, 1, Parent, Routines) -- "/" .. Repository .. Directory
elseif Organization then
Link = Website .. Organization
local Data = GetAsync(Link .. "?tab=repositories")
local Object = GetFirstChild(Parent, Organization, "Folder")
if not Routines[1] then Routines[1] = Object end
for Link, Data in Data:gmatch('<a href="(/' .. Organization .. '/[^/]+)" itemprop="name codeRepository">(.-)</div>') do
if not Data:match("Forked from") and not Link:find("Plugin") then
GitHub:Install(Link, Object, Routines)
end
end
end
Routines[Value] = true
if not RoutineList then
repeat
local Done = 0
local Count = #Routines
for a = 1, Count do
if Routines[a] then
Done = Done + 1
end
end
until Done == Count or not wait()
local Object = Routines[1]
if Garbage then
Object.Parent = nil
Parent:Destroy()
end
DataSources[Object] = Link
return Object
end
end
GitHub:Install("https://github.com/Quenty/NevermoreEngine/tree/version2/Modules", game:GetService("ServerScriptService")).Name = "Nevermore"
GitHub:Install("https://github.com/Quenty/NevermoreEngine/blob/version2/App/Nevermore.lua").Parent = game:GetService("ReplicatedStorage")
HttpService.HttpEnabled = ...