-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathLibraryImpl.java
75 lines (61 loc) · 1.99 KB
/
LibraryImpl.java
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
package me.earth.headlessmc.launcher.version;
import lombok.CustomLog;
import lombok.Data;
import lombok.val;
import me.earth.headlessmc.launcher.os.OS;
import java.io.File;
import java.util.Map;
@Data
@CustomLog
class LibraryImpl implements Library {
private static final String URL = "https://libraries.minecraft.net/";
private final Map<String, String> natives;
private final Extractor extractor;
private final String name;
private final Rule rule;
private final String baseUrl;
private final String url;
private final String path;
private final boolean nativeLibrary;
@Override
public String getPath(OS os) {
String result = getPathWithDefaultPathSeparator(os);
if (File.separatorChar != '/') {
result = result.replace("/", File.separator);
}
return result;
}
private String getPathWithDefaultPathSeparator(OS os) {
if (path != null) {
return path.replace("${arch}", os.isArch() ? "64" : "32");
}
val split = name.split(":");
val sb = new StringBuilder()
.append(split[0].replace(".", File.separator))
.append(File.separator)
.append(split[1])
.append(File.separator)
.append(split[2])
.append(File.separator)
.append(split[1])
.append("-")
.append(split[2]);
String n = natives.get(os.getType().getName());
if (n != null && nativeLibrary) {
sb.append("-")
.append(n.replace("${arch}", os.isArch() ? "64" : "32"));
}
return sb.append(".jar").toString();
}
@Override
public String getUrl(String path) {
if (url != null) {
return url;
}
if (baseUrl == null) {
log.debug("Assuming " + getName() + " has base url " + URL);
return URL + path.replace(File.separator, "/");
}
return baseUrl + path.replace(File.separator, "/");
}
}