- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.app.lua
More file actions
Latest commit
139 lines (104 loc) · 3.34 KB
/
Copy pathgithub.app.lua
File metadata and controls
139 lines (104 loc) · 3.34 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
-- Reanmachine TekOS
-- APP: Github
-- Constants
asset_type_app="app"
asset_type_lib="lib"
github_content_path="https://raw.githubusercontent.com"
-- Functions
functionget_asset_remote_path(name, asset_type)
ifasset_type==asset_type_appthen
returnname..".app.lua"
end
ifasset_type==asset_type_libthen
returnname..".lib.lua"
end
error("Unknown asset type: "..asset_type)
end
functionget_asset_target_path(name, asset_type)
ifasset_type==asset_type_appthen
return"/"..name
end
ifasset_type==asset_type_libthen
return"/libs/"..name
end
error("Unknown asset type: "..asset_type)
end
---
-- Downloads a file from a github project
-- @param project The project identity (eg Reanmachine/something)
-- @param revision The revision to get (if none, will use 'master')
-- @param file The file to download (relative path from project root)
-- @param dest The destination file to download it into locally
functionget_github_resource(project, revision, file)
ifnotprojectthenerror("project cannot be nil") end
iftype(project) ~="string" thenerror("project must be a string") end
-- Default the revision to master
ifnotrevisionthen
revision="master"
end
localproject_content_path=github_content_path.."/"..project
localproject_revision_path=project_content_path.."/"..revision
localproject_file_path=project_revision_path.."/"..file
localweb_result=http.get(project_file_path)
ifnotweb_resultthen
return {found=false, code=0, data=""}
end
localfound=web_result.getResponseCode() ==200
return {found=found, code=web_result.getResponseCode(), data=web_result.readAll()}
end
functionget_asset(project, revision, name, asset_type)
localtarget_file=get_asset_remote_path(name, asset_type)
localresult=get_github_resource(project, revision, target_file)
ifnotresultornotresult.foundthen
localreason=nil
ifresult.code==404thenreason="File not Found" end
ifresult.code==403thenreason="Forbidden" end
localmessage=string.format(
"Unable to Retrieve %s '%s' from repository '%s'",
asset_type,
name,
project)
ifnotreasonthen
print(message..": "..reason)
else
print(message)
end
returnfalse
end
localtarget_path=get_asset_target_path(name, asset_type)
localtarget_output=fs.open(target_path, "w")
target_output.write(result.data)
target_output.flush()
target_output.close()
print(string.format(
"%s '%s' downloaded successfully to '%s'",
asset_type,
name,
target_path))
end
functionusage()
print("github <project> <type> <name>")
print(" <project> - The GitHub User/Repository path of the project. (eg: mojang/minecraft)")
print(" <type> - 'app' or 'lib' to denote package type.")
print(" <name> - The name relative to the root of the project.")
end
-- Application Logic
localarg= { ... }
if#arg<3then
print("ERROR: not enough arugments")
usage()
exit()
end
localproject=arg[1]
localasset_type=arg[2]
localasset_name=arg[3]
ifasset_type==asset_type_appthen
print(string.format("Downloading App '%s' from '%s'...", asset_name, project))
elseifasset_type==asset_type_libthen
print(string.format("Downloading Lib '%s' from '%s'...", asset_name, project))
else
print("ERROR: invalid asset type '"..asset_type.."'")
usage()
exit()
end
get_asset(project, nil, asset_name, asset_type)