-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscmInstaller.lua
More file actions
44 lines (40 loc) · 1.25 KB
/
scmInstaller.lua
File metadata and controls
44 lines (40 loc) · 1.25 KB
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
--installs the scm files into the game
---@class SCMInstaller
local SCMInstaller = {}
function SCMInstaller:getFilesTxt(source)
local files = {}
print("Downloading from " .. source .. "files.txt")
local response = http.get(source .. "files.txt")
if response == nil or response.getResponseCode() ~= 200 then
error("Failed to download files.txt")
end
local file = response.readLine()
while file ~= nil do
table.insert(files, file)
file = response.readLine()
end
response.close()
return files
end
function SCMInstaller:deleteFiles(files)
for _, value in ipairs(files) do
print("Deleting File " .. value)
if fs.exists(value) then
fs.delete(value)
end
end
end
function SCMInstaller:downloadFiles(source, files)
for index, value in ipairs(files) do
print('Downloading ' .. index .. ' of ' .. #files .. ' files: ' .. value)
local response = http.get(source .. value)
if not response or response.getResponseCode() ~= 200 then
error("Failed to download " .. value)
end
local file = fs.open(value, "w")
file.write(response.readAll())
file.close()
response.close()
end
end
return SCMInstaller