Skip to content

Commit 04ec0d6

Browse files
committed
Updated Installer
1 parent 73519b4 commit 04ec0d6

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

scmInstaller.lua

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
---@class SCMInstaller
33
local SCMInstaller = {}
44

5-
6-
local files = {}
7-
local source = "raw.githubusercontent.com/mc-cc-scripts/script-manager/Issue-30-Spilt-SCM/"
8-
9-
10-
function SCMInstaller:getFilesTxt()
11-
http.get(source .. "files.txt", nil, function(response)
12-
local file = response.readLine()
13-
while file ~= nil do
14-
table.insert(files, file)
15-
file = response.readLine()
16-
end
17-
response.close()
18-
end)
5+
function SCMInstaller:getFilesTxt(source)
6+
local files = {}
7+
print("Downloading from " .. source .. "files.txt")
8+
local response = http.get(source .. "files.txt")
9+
if response == nil or response.getResponseCode() ~= 200 then
10+
error("Failed to download files.txt")
11+
end
12+
local file = response.readLine()
13+
while file ~= nil do
14+
table.insert(files, file)
15+
file = response.readLine()
16+
end
17+
response.close()
18+
return files
1919
end
2020

21-
function SCMInstaller:delteFiles()
21+
function SCMInstaller:deleteFiles(files)
2222
for _, value in ipairs(files) do
2323
print("Deleting File " .. value)
2424
if fs.exists(value) then
@@ -28,15 +28,17 @@ function SCMInstaller:delteFiles()
2828
end
2929

3030
-- download the files
31-
function SCMInstaller:downloadFiles()
31+
function SCMInstaller:downloadFiles(source, files)
3232
for index, value in ipairs(files) do
33-
http.get(source .. value, nil, function(response)
34-
print('Downloading ' .. index .. ' of ' .. #files .. ' files: ' .. value)
35-
local file = fs.open(value, "w")
36-
file.write(response.readAll())
37-
file.close()
38-
response.close()
39-
end)
33+
print('Downloading ' .. index .. ' of ' .. #files .. ' files: ' .. value)
34+
local response = http.get(source .. value)
35+
if not response or response.getResponseCode() ~= 200 then
36+
error("Failed to download " .. value)
37+
end
38+
local file = fs.open(value, "w")
39+
file.write(response.readAll())
40+
file.close()
41+
response.close()
4042
end
4143
end
4244

0 commit comments

Comments
 (0)