SHOW:
|
|
- or go back to the newest paste.
1 | local function ReadFile(path) | |
2 | local f = fs.open(path, "r") | |
3 | local data = f.readAll() | |
4 | f.close() | |
5 | return data | |
6 | end | |
7 | ||
8 | local function WriteFile(path, data) | |
9 | local f = fs.open(path, "w") | |
10 | f.write(data) | |
11 | f.close() | |
12 | end | |
13 | ||
14 | local function getpastebin(paste) | |
15 | local response = http.get( | |
16 | "http://pastebin.com/raw/"..textutils.urlEncode( paste ) | |
17 | ) | |
18 | ||
19 | if response then | |
20 | local sResponse = response.readAll() | |
21 | response.close() | |
22 | return true, sResponse | |
23 | else | |
24 | return false | |
25 | end | |
26 | end | |
27 | ||
28 | local function CheckAPI(name, pastebin, required, downloadfilename) | |
29 | local path = settings.get(name, nil) | |
30 | if path ~= nil then | |
31 | if fs.exists(path) then | |
32 | os.loadAPI(path) | |
33 | return true | |
34 | else | |
35 | if http then | |
36 | local suc, paste = getpastebin(pastebin) | |
37 | if suc then | |
38 | WriteFile(path, paste) | |
39 | os.loadAPI(path) | |
40 | return true | |
41 | else | |
42 | - | if required then error(name .. " API not found and was not able to download! specify path to " .. name .. " API in settings, do 'set " .. name .. " <path>' to set path") |
42 | + | print("Failed to download") |
43 | if required then error(name .. " API not found and was not able to download! specify path to " .. name .. " API in settings, do 'set " .. name .. " <path>' to set path") end | |
44 | end | |
45 | - | if required then error(name .. " API not found and was not able to download! specify path to " .. name .. " API in settings, do 'set " .. name .. " <path>' to set path") |
45 | + | |
46 | print("Http disabled") | |
47 | if required then error(name .. " API not found and was not able to download! specify path to " .. name .. " API in settings, do 'set " .. name .. " <path>' to set path") end | |
48 | end | |
49 | end | |
50 | else | |
51 | print("Settings for API path not found") | |
52 | if fs.exists(name) then | |
53 | os.loadAPI(name) | |
54 | return true | |
55 | else | |
56 | if http then | |
57 | local suc, paste = getpastebin(pastebin) | |
58 | if suc then | |
59 | if downloadfilename then | |
60 | WriteFile(downloadfilename, paste) | |
61 | settings.set(name, downloadfilename) | |
62 | os.loadAPI(downloadfilename) | |
63 | else | |
64 | WriteFile(name, paste) | |
65 | os.loadAPI(name) | |
66 | - | if required then error(name .. " API not found and was not able to download! specify path to " .. name .. " API in settings, do 'set " .. name .. " <path>' to set path") |
66 | + | |
67 | return true | |
68 | else | |
69 | - | if required then error(name .. " API not found and was not able to download! specify path to " .. name .. " API in settings, do 'set " .. name .. " <path>' to set path") |
69 | + | print("Failed to download") |
70 | if required then error(name .. " API not found and was not able to download! specify path to " .. name .. " API in settings, do 'set " .. name .. " <path>' to set path") end | |
71 | end | |
72 | else | |
73 | print("Http disabled") | |
74 | if required then error(name .. " API not found and was not able to download! specify path to " .. name .. " API in settings, do 'set " .. name .. " <path>' to set path") end | |
75 | end | |
76 | end | |
77 | end | |
78 | return false | |
79 | end |