-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-edit+
106 lines (87 loc) · 2.2 KB
/
install-edit+
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
if not http then
error("http api required.")
end
local branch="master"
local args={...}
local verToBranch={release="master",beta="dev"}
local bindir, apidir
local function fixDir(dir)
local d=dir:match("^(.-)[/|\\]?$")
return d
end
for i=1,#args do
local arg,val=args[i]:match("-(%w+)=?(.*)")
if arg then
arg=arg:lower()
if arg=="ver" then
if val then
val=val:lower()
if verToBranch[val] then
branch=verToBranch[val]
else
error("invalid version '"..val.."'")
end
else
error("Must specify a version 'release' or 'beta' to argument 'ver'!")
end
elseif arg=="apidir" then
if fs.exists(val) then
apidir=fixDir(val)
else
error("Specified apidir does not exist!")
end
elseif arg=="bindir" then
if fs.exists(val) then
bindir=fixDir(val)
else
error("Specified apidir does not exist!")
end
else
error("unknown argument '"..arg.."'")
end
end
end
function grabFileText(name)
write("downloading '"..name.."'...")
local req=http.get("https://raw.githubusercontent.com/GopherAtl/edit-plus/"..branch.."/"..name)
if req==nil then
error("Cound't make request!")
end
if req.getResponseCode()~=200 then
req.close()
error("Unexpected response code "..req.getResponseCode())
end
local text=req.readAll()
req.close()
print("success! "..#text.." bytes")
return text
end
function grabFile(name,targetDir)
local text=grabFileText(name)
local path=(targetDir or shell.dir())
local file=fs.open(fs.combine(path,name),"w")
if not file then
error("Couldn't open file '"..name.."' for writing!")
end
file.write(text)
file.close()
end
bindir=bindir or shell.dir()
apidir=apidir or bindir
local filelist=grabFileText("filelist.txt")
for ftype,file in filelist:gmatch("(...):(%S*)") do
grabFile(file,ftype=="bin" and bindir or apidir)
end
local settings = {
recentFiles = { },
syntaxStyle = "pastebin",
bindir=bindir,
apidir=apidir,
}
local file=fs.open(bindir.."/.edit+","w")
if not file then
error("Error!","Couldn't open settings file to write!")
else
file.write(textutils.serialize(settings))
file.close()
end