-
Notifications
You must be signed in to change notification settings - Fork 3
/
fabric_installer.go
90 lines (79 loc) · 2.34 KB
/
fabric_installer.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
package installer
import (
"fmt"
"net/url"
"path/filepath"
)
type (
FabricInstallerVersion struct {
Url string `json:"url"`
Maven string `json:"maven"`
Version string `json:"version"`
Stable bool `json:"stable"`
}
FabricInstaller struct {
MetaUrl string // Default is "https://meta.fabricmc.net"
}
)
var DefaultFabricInstaller = &FabricInstaller{
MetaUrl: "https://meta.fabricmc.net",
}
var _ Installer = DefaultFabricInstaller
func init() {
Installers["fabric"] = DefaultFabricInstaller
}
const fabricServerLauncherProfile = "fabric-server-launcher.properties"
const fabricServerLauncherLink = "https://meta.fabricmc.net/v2/versions/loader/%s/%s/stable/server/jar"
func (r *FabricInstaller) Install(path, name string, target string) (installed string, err error) {
return r.InstallWithLoader(path, name, target, "")
}
func (r *FabricInstaller) InstallWithLoader(path, name string, target string, loader string) (installed string, err error) {
foundVersion := target
if target == "" || target == "latest" || target == "latest-snapshot" {
var versions VanillaVersions
loger.Info("Getting minecraft version manifest...")
if versions, err = VanillaIns.GetVersions(); err != nil {
return
}
if target == "latest-snapshot" {
target = versions.Latest.Snapshot
foundVersion += "(" + target + ")"
} else {
target = versions.Latest.Release
foundVersion += "(" + target + ")"
}
}
if loader == "" {
loader = "stable"
}
serverLauncherUrl := fmt.Sprintf(fabricServerLauncherLink, target, loader)
loger.Infof("Getting fabric server launcher %s at %q...", foundVersion, serverLauncherUrl)
installed = filepath.Join(path, name+".jar")
if err = DefaultHTTPClient.Download(serverLauncherUrl, installed, 0644, nil, -1,
downloadingCallback(serverLauncherUrl)); err != nil {
return
}
return installed, nil
}
func (r *FabricInstaller) ListVersions(snapshot bool) (versions []string, err error) {
vs, err := r.GetInstallers()
if err != nil {
return
}
for _, v := range vs {
if v.Stable || snapshot {
versions = append(versions, v.Version)
}
}
return
}
func (r *FabricInstaller) GetInstallers() (res []FabricInstallerVersion, err error) {
tg, err := url.JoinPath(r.MetaUrl, "v2", "versions", "installer")
if err != nil {
return
}
if err = DefaultHTTPClient.GetJson(tg, &res); err != nil {
return
}
return
}