-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLibraryHandler.java
More file actions
84 lines (68 loc) · 3.27 KB
/
LibraryHandler.java
File metadata and controls
84 lines (68 loc) · 3.27 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
package io.github.fabriccompatibiltylayers.modremappingapi.impl;
import fr.catcore.modremapperapi.utils.Constants;
import io.github.fabriccompatibiltylayers.modremappingapi.api.v1.ModRemapper;
import io.github.fabriccompatibiltylayers.modremappingapi.api.v1.RemapLibrary;
import io.github.fabriccompatibiltylayers.modremappingapi.impl.utils.CacheUtils;
import io.github.fabriccompatibiltylayers.modremappingapi.impl.utils.FileUtils;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.tinyremapper.TinyRemapper;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class LibraryHandler {
private final Map<RemapLibrary, Path> remapLibraries = new HashMap<>();
private String sourceNamespace;
public LibraryHandler() {}
public void init(String sourceNamespace) {
this.sourceNamespace = sourceNamespace;
Path sourceLibraryPath = CacheUtils.getLibraryPath(this.sourceNamespace);
if (!Files.exists(sourceLibraryPath)) {
try {
Files.createDirectories(sourceLibraryPath);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public void gatherRemapLibraries(List<ModRemapper> remappers) {
try {
for (ModRemapper remapper : remappers) {
List<RemapLibrary> libraries = new ArrayList<>();
remapper.addRemapLibraries(libraries, FabricLoader.getInstance().getEnvironmentType());
Map<RemapLibrary, Path> temp = CacheUtils.computeExtraLibraryPaths(libraries, sourceNamespace);
for (Map.Entry<RemapLibrary, Path> entry : temp.entrySet()) {
RemapLibrary library = entry.getKey();
Path path = entry.getValue();
if (Files.exists(path)) continue;
if (!library.url.isEmpty()) {
Constants.MAIN_LOGGER.info("Downloading remapping library '" + library.fileName + "' from url '" + library.url + "'");
FileUtils.downloadFile(library.url, path);
FileUtils.removeEntriesFromZip(path, library.toExclude);
Constants.MAIN_LOGGER.info("Remapping library ready for use.");
} else if (library.path != null) {
Constants.MAIN_LOGGER.info("Extracting remapping library '" + library.fileName + "' from mod jar.");
FileUtils.copyZipFile(library.path, path);
Constants.MAIN_LOGGER.info("Remapping library ready for use.");
}
}
remapLibraries.putAll(temp);
}
} catch (IOException | URISyntaxException e) {
throw new RuntimeException(e);
}
}
public void addLibrariesToRemapClasspath(TinyRemapper remapper) {
for (Path libPath : remapLibraries.values()) {
if (Files.exists(libPath)) {
remapper.readClassPathAsync(libPath);
} else {
Constants.MAIN_LOGGER.info("Library " + libPath + " does not exist.");
}
}
}
}