SHOW:
|
|
- or go back to the newest paste.
1 | - | local FILENAME = '/pos.lua' |
1 | + | local FILENAME = '/test.lua' |
2 | local internet = require("internet") | |
3 | ||
4 | local cacheBreak = tostring(math.random(0, 99999)) | |
5 | - | res, err = http.get('https://gist.githubusercontent.com/Michael-Reeves808/825a0f20b4cce7c7b5b55f79944d1d44/raw/pos.lua?breaker=' .. cacheBreak) |
5 | + | |
6 | - | if not res then error(err) end |
6 | + | local response = internet.request('https://raw.githubusercontent.com/MrRiptide/OpenComputers/master/test.lua?breaker=' .. cacheBreak) |
7 | local code = "" | |
8 | - | local code = res.readAll() |
8 | + | |
9 | for chunk in response do | |
10 | code = code .. chunk | |
11 | - | if not(fs.exists(FILENAME)) |
11 | + | end |
12 | ||
13 | - | local newHarvest = fs.open(FILENAME, 'w') |
13 | + | if not(filesystem.exists(FILENAME)) |
14 | - | newHarvest.close() |
14 | + | |
15 | local newHarvest = io.open(FILENAME, 'w') | |
16 | newHarvest:close() | |
17 | - | local readFile = fs.open(FILENAME, 'r') |
17 | + | |
18 | - | local oldCode = readFile.readAll() |
18 | + | |
19 | - | readFile.close() |
19 | + | local readFile = io.open(FILENAME, 'r') |
20 | local oldCode = readFile:read("*a") | |
21 | - | local file = fs.open(FILENAME, 'w') |
21 | + | readFile:close() |
22 | ||
23 | local file = io.open(FILENAME, 'w') | |
24 | ||
25 | - | file.write(oldCode) |
25 | + | |
26 | then | |
27 | file:write(oldCode) | |
28 | - | file.write(code) |
28 | + | |
29 | else | |
30 | file:write(code) | |
31 | print('WRITING UPDATE') | |
32 | byteDiff = string.len(code) - string.len(oldCode) | |
33 | ||
34 | if byteDiff >= 0 | |
35 | then | |
36 | print(tostring(math.abs(byteDiff)) .. ' bytes added') | |
37 | else | |
38 | print(tostring(math.abs(byteDiff)) .. ' bytes removed') | |
39 | end | |
40 | - | file.close() |
40 | + | |
41 | - | res.close() |
41 | + | |
42 | file:close() |