Skip to content

Commit 62eed30

Browse files
committed
Update RDI. Rewrite version json downloader.
1 parent 7d9146f commit 62eed30

File tree

14 files changed

+246
-206
lines changed

14 files changed

+246
-206
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
allprojects {
66
apply plugin: "java"
7-
7+
88
repositories {
99
mavenCentral()
1010
maven { url "https://jitpack.io/" }
@@ -23,8 +23,8 @@ allprojects {
2323
implementation "org.ow2.asm:asm-tree:${project.asm_version}"
2424
implementation "org.ow2.asm:asm-util:${project.asm_version}"
2525

26-
implementation "com.github.MCPHackers.RetroDebugInjector:rdi-nio:${project.rdi_version}"
27-
implementation "com.github.MCPHackers.RetroDebugInjector:rdi:${project.rdi_version}"
26+
implementation "org.mcphackers.rdi:rdi-nio:${project.rdi_version}"
27+
implementation "org.mcphackers.rdi:rdi:${project.rdi_version}"
2828

2929
implementation "io.github.lassebq:fernflower:${project.fernflower_version}"
3030

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
asm_version=9.7.1
22
fernflower_version=1.0.0
3-
rdi_version=c9cbed5
3+
rdi_version=1.1
44
jansi_version=2.4.1
55
json_version=20250107
66
diffpatch_version=cde1224

src/main/java/org/mcphackers/mcp/tasks/TaskSetup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ protected Stage[] setStages() {
8787

8888
DownloadData dlData = new DownloadData(mcp, versionJson);
8989
dlData.performDownload((dl, totalSize) -> {
90-
libsSize += dl.size();
90+
libsSize += dl.downloadSize();
9191
int percent = (int) ((double) libsSize / totalSize * 97D);
92-
setProgress(getLocalizedStage("download", dl.name()), 3 + percent);
92+
setProgress(getLocalizedStage("download", dl.downloadURL()), 3 + percent);
9393
});
9494
Path natives = MCPPaths.get(mcp, NATIVES);
9595
for (Path nativeArchive : DownloadData.getNatives(MCPPaths.get(mcp, LIB), versionJson)) {

src/main/java/org/mcphackers/mcp/tools/project/IdeaProjectWriter.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package org.mcphackers.mcp.tools.project;
22

3-
import static org.mcphackers.mcp.MCPPaths.PROJECT;
3+
import static org.mcphackers.mcp.MCPPaths.*;
44

55
import java.io.IOException;
66
import java.nio.file.Files;
77
import java.nio.file.Path;
8-
import java.nio.file.Paths;
98

109
import org.mcphackers.mcp.MCP;
1110
import org.mcphackers.mcp.MCPPaths;
@@ -59,10 +58,8 @@ public void writeProjectIML(MCP mcp, Version version, String moduleName, Path pr
5958
writer.writeSelfEndingAttribute("orderEntry type=\"sourceFolder\" forTests=\"false\"");
6059
for (DependDownload dependencyDownload : version.libraries) {
6160
if (Rule.apply(dependencyDownload.rules)) {
62-
String[] path = dependencyDownload.name.split(":");
63-
String lib = path[0].replace('.', '/') + "/" + path[1] + "/" + path[2] + "/" + path[1] + "-" + path[2];
64-
Path libPath = Paths.get(lib);
65-
String libraryName = libPath.getFileName().toString();
61+
String lib = dependencyDownload.getArtifactPath(null);
62+
String libraryName = lib.substring(lib.lastIndexOf("/") + 1, lib.length() - 4);
6663
if (Files.exists(MCPPaths.get(mcp, "libraries/" + lib + ".jar"))) {
6764
writer.writeSelfEndingAttribute("orderEntry type=\"library\" name=\"" + libraryName + "\" level=\"project\"");
6865
}
@@ -129,14 +126,10 @@ public void writeLibraries(MCP mcp, Path projectFolder, Version version) throws
129126
// Write library XML files
130127
for (DependDownload dependencyDownload : version.libraries) {
131128
if (Rule.apply(dependencyDownload.rules)) {
132-
String[] path = dependencyDownload.name.split(":");
133-
String lib = path[0].replace('.', '/') + "/" + path[1] + "/" + path[2] + "/" + path[1] + "-" + path[2];
134-
String src = null;
135-
if (dependencyDownload.downloads != null && dependencyDownload.downloads.classifiers != null && dependencyDownload.downloads.classifiers.sources != null) {
136-
src = dependencyDownload.downloads.classifiers.sources.path;
137-
}
138-
if (Files.exists(MCPPaths.get(mcp, "libraries/" + lib + ".jar"))) {
139-
String libraryName = lib.substring(lib.lastIndexOf("/") + 1);
129+
String lib = dependencyDownload.getArtifactPath(null);
130+
String src = dependencyDownload.getArtifactPath("sources");
131+
if (Files.exists(MCPPaths.get(mcp, "libraries/" + lib))) {
132+
String libraryName = lib.substring(lib.lastIndexOf("/") + 1, lib.length() - 4);
140133
Path libraryXML = librariesFolder.resolve(libraryName + ".xml");
141134
Files.createFile(libraryXML);
142135
try (XMLWriter writer = new XMLWriter(Files.newBufferedWriter(libraryXML))) {
@@ -145,7 +138,7 @@ public void writeLibraries(MCP mcp, Path projectFolder, Version version) throws
145138
writer.startAttribute("library name=\"" + libraryName + "\"");
146139

147140
writer.startAttribute("CLASSES");
148-
writer.writeSelfEndingAttribute("root url=\"jar://$PROJECT_DIR$/../libraries/" + lib + ".jar!/\"");
141+
writer.writeSelfEndingAttribute("root url=\"jar://$PROJECT_DIR$/../libraries/" + lib + "!/\"");
149142
writer.closeAttribute("CLASSES");
150143
writer.writeSelfEndingAttribute("JAVADOC");
151144
if (src != null) {

src/main/java/org/mcphackers/mcp/tools/project/eclipse/EclipseClasspath.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.mcphackers.mcp.MCP;
44
import org.mcphackers.mcp.MCPPaths;
55
import org.mcphackers.mcp.tasks.Task;
6+
import org.mcphackers.mcp.tasks.Task.Side;
67
import org.mcphackers.mcp.tools.project.XMLWriter;
78
import org.mcphackers.mcp.tools.versions.json.DependDownload;
89
import org.mcphackers.mcp.tools.versions.json.Rule;
@@ -35,20 +36,16 @@ public void toXML(XMLWriter writer, Task.Side side) throws IOException {
3536
writer.closeAttribute("attributes");
3637
writer.closeAttribute("classpathentry");
3738
// TODO: Implement proper client/server side libraries
38-
if (!side.equals(Task.Side.SERVER)) {
39+
if (!side.equals(Side.SERVER)) {
3940
for (DependDownload dependencyDownload : this.dependencies) {
4041
if (Rule.apply(dependencyDownload.rules)) {
41-
String[] path = dependencyDownload.name.split(":");
42-
String lib = path[0].replace('.', '/') + "/" + path[1] + "/" + path[2] + "/" + path[1] + "-" + path[2];
43-
String src = null;
44-
if (dependencyDownload.downloads != null && dependencyDownload.downloads.classifiers != null && dependencyDownload.downloads.classifiers.sources != null) {
45-
src = dependencyDownload.downloads.classifiers.sources.path;
46-
}
47-
if (Files.exists(MCPPaths.get(this.mcp, "libraries/" + lib + ".jar"))) {
42+
String lib = dependencyDownload.getArtifactPath(null);
43+
String src = dependencyDownload.getArtifactPath("sources");
44+
if (Files.exists(MCPPaths.get(mcp, "libraries/" + lib))) {
4845
if (src != null) {
49-
writer.writeAttribute("classpathentry kind=\"lib\" path=\"libraries/" + lib + ".jar\" sourcepath=\"libraries/" + src + "\"");
46+
writer.writeAttribute("classpathentry kind=\"lib\" path=\"libraries/" + lib + "\" sourcepath=\"libraries/" + src + "\"");
5047
} else {
51-
writer.writeAttribute("classpathentry kind=\"lib\" path=\"libraries/" + lib + ".jar\"");
48+
writer.writeAttribute("classpathentry kind=\"lib\" path=\"libraries/" + lib + "\"");
5249
}
5350
}
5451
}

src/main/java/org/mcphackers/mcp/tools/versions/DownloadData.java

Lines changed: 39 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,17 @@
1515
import org.mcphackers.mcp.tasks.Task.Side;
1616
import org.mcphackers.mcp.tools.FileUtil;
1717
import org.mcphackers.mcp.tools.Util;
18-
import org.mcphackers.mcp.tools.versions.json.Artifact;
1918
import org.mcphackers.mcp.tools.versions.json.AssetIndex;
2019
import org.mcphackers.mcp.tools.versions.json.AssetIndex.Asset;
2120
import org.mcphackers.mcp.tools.versions.json.DependDownload;
22-
import org.mcphackers.mcp.tools.versions.json.Download;
2321
import org.mcphackers.mcp.tools.versions.json.Rule;
2422
import org.mcphackers.mcp.tools.versions.json.Version;
2523

2624
public class DownloadData {
2725

2826
private final Path gameDir;
29-
public long totalSize;
30-
public List<DownloadEntry> natives = new ArrayList<>();
31-
protected List<DownloadEntry> downloadQueue = new ArrayList<>();
27+
public int totalSize;
28+
protected List<Download> downloadQueue = new ArrayList<>();
3229
protected AssetIndex assets;
3330

3431
public DownloadData(MCP mcp, Version version) {
@@ -37,28 +34,13 @@ public DownloadData(MCP mcp, Version version) {
3734

3835
public DownloadData(Path libraries, Path gameDir, Path client, Path server, Version version) {
3936
this.gameDir = gameDir;
40-
if (version.downloads.client != null && client != null) {
41-
queueDownload(version.downloads.client, client, true); // TODO may want to make verify flag togglable
42-
}
43-
if (version.downloads.server != null && server != null) {
44-
queueDownload(version.downloads.server, server, true);
45-
}
37+
queueDownload(version.downloads.artifacts.get("client"), client);
38+
queueDownload(version.downloads.artifacts.get("server"), server);
4639
for (DependDownload dependencyDownload : version.libraries) {
4740
if (Rule.apply(dependencyDownload.rules)) {
48-
if (dependencyDownload.downloads != null && dependencyDownload.downloads.artifact != null) {
49-
queueDownload(dependencyDownload.downloads.artifact, libraries.resolve(dependencyDownload.downloads.artifact.path), true);
50-
}
51-
52-
if (dependencyDownload.downloads != null && dependencyDownload.downloads.classifiers != null) {
53-
Artifact artifact = dependencyDownload.downloads.classifiers.getNatives();
54-
if (artifact != null) {
55-
natives.add(queueDownload(artifact, libraries.resolve(artifact.path), true));
56-
}
57-
artifact = dependencyDownload.downloads.classifiers.sources;
58-
if (artifact != null) {
59-
queueDownload(artifact, libraries.resolve(artifact.path), true);
60-
}
61-
}
41+
queueDownload(dependencyDownload.getDownload(null), libraries);
42+
queueDownload(dependencyDownload.getDownload(dependencyDownload.getNatives()), libraries);
43+
queueDownload(dependencyDownload.getDownload("sources"), libraries);
6244
}
6345
}
6446
try {
@@ -79,8 +61,7 @@ public static List<String> getLibraries(Version version) {
7961
List<String> retList = new ArrayList<>();
8062
for (DependDownload dependencyDownload : version.libraries) {
8163
if (Rule.apply(dependencyDownload.rules)) {
82-
String[] path = dependencyDownload.name.split(":");
83-
String lib = path[0].replace('.', '/') + "/" + path[1] + "/" + path[2] + "/" + path[1] + "-" + path[2];
64+
String lib = dependencyDownload.getArtifactPath(null);
8465
retList.add(lib);
8566
}
8667
}
@@ -91,8 +72,10 @@ public static List<Path> getLibraries(Path libDir, Version version) {
9172
List<Path> retList = new ArrayList<>();
9273
for (DependDownload dependencyDownload : version.libraries) {
9374
if (Rule.apply(dependencyDownload.rules)) {
94-
String[] path = dependencyDownload.name.split(":");
95-
String lib = path[0].replace('.', '/') + "/" + path[1] + "/" + path[2] + "/" + path[1] + "-" + path[2] + ".jar";
75+
String lib = dependencyDownload.getArtifactPath(null);
76+
if(lib == null) {
77+
continue;
78+
}
9679
retList.add((libDir.resolve(lib)));
9780
}
9881
}
@@ -103,11 +86,13 @@ public static List<Path> getNatives(Path libDir, Version version) {
10386
List<Path> retList = new ArrayList<>();
10487
for (DependDownload dependencyDownload : version.libraries) {
10588
if (Rule.apply(dependencyDownload.rules)) {
106-
if (dependencyDownload.downloads != null && dependencyDownload.downloads.classifiers != null) {
107-
Artifact artifact = dependencyDownload.downloads.classifiers.getNatives();
108-
if (artifact != null) {
109-
retList.add(libDir.resolve(artifact.path));
89+
String natives = dependencyDownload.getNatives();
90+
if (natives != null) {
91+
String lib = dependencyDownload.getArtifactPath(natives);
92+
if(lib == null) {
93+
continue;
11094
}
95+
retList.add(libDir.resolve(lib));
11196
}
11297
}
11398
}
@@ -119,57 +104,43 @@ public void setAssets(AssetIndex assets) {
119104
return;
120105
}
121106
this.assets = assets;
107+
Path dir = gameDir.resolve(assets.map_to_resources ? "resources/" : "assets/objects/");
122108
for (Entry<String, Asset> entry : assets.objects.entrySet()) {
123-
totalSize += entry.getValue().size();
109+
queueDownload(entry.getValue(), dir);
124110
}
125111
}
126112

127-
public DownloadEntry queueDownload(Download dl, Path path, boolean verify) {
113+
public void queueDownload(IDownload dl, Path baseDir) {
128114
if (dl == null) {
129-
return null;
115+
return;
130116
}
131-
DownloadEntry entry = new DownloadEntry(dl, path, verify);
132-
totalSize += dl.size();
133-
downloadQueue.add(entry);
134-
return entry;
117+
totalSize += dl.downloadSize();
118+
downloadQueue.add(new Download(dl, baseDir));
135119
}
136120

137121
public void performDownload(DownloadListener listener) throws IOException {
138-
for (DownloadEntry dl : downloadQueue) {
139-
Path file = dl.path;
140-
Download dlObj = dl.dlObject;
141-
listener.notify(dlObj, totalSize);
142-
if (!Files.exists(file) || (dl.verifySHA1 && !dlObj.sha1.equals(Util.getSHA1(file)))) {
122+
for (Download dl : downloadQueue) {
123+
IDownload download = dl.download;
124+
Path baseDir = dl.dir;
125+
String path = download.downloadPath();
126+
// if downloadPath is null then baseDir is the location of downloaded file.
127+
Path file = path == null ? baseDir : baseDir.resolve(path);
128+
listener.notify(dl.download, totalSize);
129+
if (!Files.exists(file) || (download.verify() && !download.downloadHash().equals(Util.getSHA1(file)))) {
143130
Path parent = file.getParent();
144131
if (parent != null) Files.createDirectories(parent);
145-
FileUtil.downloadFile(dlObj.url, file);
146-
}
147-
}
148-
if (assets != null) {
149-
for (Entry<String, Asset> entry : assets.objects.entrySet()) {
150-
Asset asset = entry.getValue();
151-
String hash = asset.hash.substring(0, 2) + "/" + asset.hash;
152-
String filename = assets.map_to_resources ? "resources/" + entry.getKey() : "assets/objects/" + hash;
153-
Path file = gameDir.resolve(filename);
154-
listener.notify(asset, totalSize);
155-
if (!Files.exists(file)) {
156-
Path parent = file.getParent();
157-
if (parent != null) Files.createDirectories(parent);
158-
FileUtil.downloadFile("https://resources.download.minecraft.net/" + hash, file);
159-
}
132+
FileUtil.downloadFile(download.downloadURL(), file);
160133
}
161134
}
162135
}
163136

164-
public static class DownloadEntry {
165-
public final Download dlObject;
166-
public final Path path;
167-
public final boolean verifySHA1;
137+
private static class Download {
138+
IDownload download;
139+
Path dir;
168140

169-
public DownloadEntry(Download dl, Path filePath, boolean verify) {
170-
path = filePath;
171-
dlObject = dl;
172-
verifySHA1 = verify;
141+
public Download(IDownload dl, Path path) {
142+
download = dl;
143+
dir = path;
173144
}
174145
}
175146
}

src/main/java/org/mcphackers/mcp/tools/versions/IDownload.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
public interface IDownload {
44

5-
String name();
5+
String downloadPath();
66

7-
long size();
7+
String downloadURL();
8+
9+
long downloadSize();
10+
11+
String downloadHash();
12+
13+
boolean verify();
814
}
Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,52 @@
11
package org.mcphackers.mcp.tools.versions.json;
22

33
import org.json.JSONObject;
4+
import org.mcphackers.mcp.tools.versions.IDownload;
45

5-
public class Artifact extends Download {
6+
public class Artifact implements IDownload {
67
public String path;
8+
public String name;
9+
public String sha1;
10+
public String url;
11+
public long size;
712

8-
public static Artifact from(JSONObject obj) {
13+
public static Artifact from(JSONObject obj, String nameStr) {
914
if (obj == null) {
1015
return null;
1116
}
1217
return new Artifact() {
1318
{
14-
path = obj.getString("path");
15-
sha1 = obj.getString("sha1");
16-
url = obj.getString("url");
17-
size = obj.getLong("size");
19+
name = nameStr;
20+
path = obj.optString("path", null);
21+
sha1 = obj.optString("sha1", null);
22+
url = obj.optString("url", null);
23+
size = obj.optLong("size");
1824
}
1925
};
2026
}
2127

2228
@Override
23-
public String name() {
29+
public String downloadPath() {
2430
return path;
2531
}
32+
33+
@Override
34+
public String downloadURL() {
35+
return url;
36+
}
37+
38+
@Override
39+
public long downloadSize() {
40+
return size;
41+
}
42+
43+
@Override
44+
public String downloadHash() {
45+
return sha1;
46+
}
47+
48+
@Override
49+
public boolean verify() {
50+
return true;
51+
}
2652
}

0 commit comments

Comments
 (0)