-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImportFile.lua
44 lines (44 loc) · 1.4 KB
/
ImportFile.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
local function ImportFile(ziel)
url = "https://raw.githubusercontent.com/Norcim133/MCTurtles/main/NewMine.lua"
option = "-f"
if type(url) ~= "string" and type(ziel) ~= "string" then
return
elseif type(option) == "string" and option ~= "-f" and type(url) == "string" then
ziel = url
url = option
end
if http.checkURL(url) then
if fs.exists(ziel) and option ~= "-f" then
printError("<Error> Target exists already")
return
else
term.write("Downloading ... ")
local timer = os.startTimer(60)
http.request(url)
while true do
local event, id, data = os.pullEvent()
if event == "http_success" then
print("success")
local f = io.open(ziel, "w")
f:write(data.readAll())
f:close()
data:close()
print("Saved as " .. ziel)
return true
elseif event == "timer" and timer == id then
printError("<Error> Timeout")
return
elseif event == "http_failure" then
printError("<Error> Download")
os.cancelAlarm(timer)
return
end
end
end
else
printError("<Error> URL")
return
end
end
args = {...}
ImportFile(args[1])