-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
219 lines (178 loc) · 4.93 KB
/
types.go
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package main
import (
"time"
)
type VersionManifest struct {
Latest map[string]string `json:"latest"`
Versions []VInfoMin `json:"versions"`
}
type VInfoMin struct {
Id string `json:"id"`
Time time.Time `json:"time"`
Release time.Time `json:"releaseTime"`
Type string `json:"type"`
// url for <version>.json
URL string `json:"url"`
}
type Download struct {
URL string `json:"url"`
Size int64 `json:"size"`
SHA1 string `json:"sha1"`
}
func (dl Download) Match(info FInfo) bool {
if dl.Size != 0 && info.Size != dl.Size {
return false
}
if dl.SHA1 != "" && info.Hash != dl.SHA1 {
return false
}
return true
}
func (dl Download) ToFInfo() FInfo {
return FInfo{
Hash: dl.SHA1,
Size: dl.Size,
}
}
type Prefix struct {
Latest map[string]string `json:"latest"`
latestTime map[string]time.Time //not in json
Versions []*VInfoMin `json:"versions"`
}
func NewPrefix() *Prefix {
return &Prefix{
Latest: make(map[string]string),
latestTime: make(map[string]time.Time),
Versions: make([]*VInfoMin, 0, 10),
}
}
type VersionSlice []*VInfoMin
func (p VersionSlice) Len() int { return len(p) }
func (p VersionSlice) Less(i, j int) bool { return p[i].Time.After(p[j].Time) }
func (p VersionSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
type VInfoFull struct {
VInfoMin
LVersion int `json:"minimumLauncherVersion"`
Assets string `json:"assets"`
AssetIndex AssetDownload `json:"assetIndex"`
Downloads struct {
Client Download `json:"client"`
Server Download `json:"server"`
}
Libs []LibInfo `json:"libraries"`
MainClass string `json:"mainClass"`
OldArguments string `json:"minecraftArguments"`
// irregular structure, store does not use it anyways
Arguments interface{} `json:"arguments"`
// nobody cares
Loggging interface{} `json:"loggging"`
}
type AssetDownload struct {
Download
ID string `json:"id"`
TotalSize int64 `json:"totalSize"`
}
type LibDownload struct {
Download
Path string `json:"path"`
}
type LibInfo struct {
Name string `json:"name"`
Url string `json:"url"`
Downloads *struct {
Artifact LibDownload `json:"artifact"`
Classifiers map[string]LibDownload `json:"classifiers"`
} `json:"downloads"`
Extract struct {
Exclude []string `json:"exclude"`
} `json:"extract"`
Natives map[string]string `json:"natives"`
Rules []Rule `json:"rules"`
}
type OsRule struct {
Name string `json:"name"`
Version string `json:"version"`
Arch string `json:"arch"`
}
type Rule struct {
Action string `json:"action"`
Os OsRule `json:"os"`
Features map[string]interface{} `json:"features"`
}
type ObjectList struct {
Data FIndex `json:"objects"`
}
func NewObjectList() *ObjectList {
return &ObjectList{make(FIndex)}
}
type FInfo struct {
Hash string `json:"hash"`
Size int64 `json:"size"`
}
type FIndex map[string]FInfo
type Customs struct {
Mutables []string `json:"mutables"`
Index FIndex `json:"index"`
}
func NewCustoms() *Customs {
return &Customs{make([]string, 0, 10), make(FIndex)}
}
type FilesInfo struct {
Main FInfo `json:"main"`
Libs FIndex `json:"libs"`
Files *Customs `json:"files"`
}
func NewFilesInfo() *FilesInfo {
return &FilesInfo{
Libs: make(FIndex),
Files: NewCustoms(),
}
}
type PrefixInfo struct {
About string `json:"about"`
Type string `json:"type"`
}
type PrefixInfoExt struct {
PrefixInfo
Latest map[string]string `json:"latest"`
}
type PrefixList struct {
Prefixes map[string]PrefixInfo `json:"prefixes"`
}
func NewPrefixList() *PrefixList {
return &PrefixList{make(map[string]PrefixInfo)}
}
var helpMessage = `Usage: %s [options] [command] [args]
Commands:
check [<prefix1>/]<version1> [[<prefix2>/]<version2>] [...]
Check whatever specified clients are consistent,
if possible download missing files from official repos.
If prefix isn't provided will search in default.
collect
Check all client versions,
geneate new versions.json in all prefixes.
clone <off_version1> [<off_version2>] [...]
Clone clients from official repos to default prefix.
help
Show this message.
cleanup
Alias to "--cleanup collect"
Options:
-v
Be more verbose.
--root=<path>
Overwrite storage root, default may be set by $TTYH_STORE env variable.
--ignore=<prefix1>/<version1>[,<prefix2>/<version2>][...]
Don't check specified versions while collect.
--prefix=<prefix>
Set default prefix for clone or check. Predefined is "default".
--last=<prefix1>/<type1>:<version1>[,<prefix2>/<type2>:<version2>][...]
Overwrite latest versions in versions.json manually.
Default choice based on releaseTime in <version>.json.
--cleanup
After collect delete all libraries and assets,
that aren't required by any client.
Cleanup will be abort if any of clients is inconsistent.
--replace
Replace existing libraries if they do not match expectations.
`