Skip to content

Commit

Permalink
Edit version json instead of maintaining our own (IrisShaders#16)
Browse files Browse the repository at this point in the history
* Edit version json instead of maintaining owown

* Only apply profile json edition to iris-loader

Code is awful, but passing the boolean feels bad when half of the things passed to the method could be derived from it

* Fix spacing

Co-authored-by: Justsnoopy30 <justsnoopy30@hypercubemc.tk>
  • Loading branch information
altrisi and Justsnoopy30 authored Nov 9, 2021
1 parent 037888e commit 9947fef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
9 changes: 0 additions & 9 deletions src/main/java/net/hypercubemc/iris_installer/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,6 @@ public void start() {
return;
}

// Use IMS's custom fabric loader if "Install as Fabric Mod" is not set
if (!installAsMod) {
Reference.metaServerUrl = "https://raw.githubusercontent.com/IrisShaders/Iris-Installer-Maven/master/";
System.out.println("Using custom loader");
} else {
Reference.metaServerUrl = "https://meta.fabricmc.net/";
System.out.println("Using fabric loader");
}

String loaderName = installAsMod ? "fabric-loader" : "iris-fabric-loader";

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.hypercubemc.iris_installer;

import mjson.Json;
import net.fabricmc.installer.client.ProfileInstaller;
import net.fabricmc.installer.util.Reference;
import net.fabricmc.installer.util.Utils;
Expand All @@ -12,7 +13,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;

public class VanillaLauncherIntegration {
Expand All @@ -34,7 +34,7 @@ public static void installVersion(Path mcDir, String gameVersion, String loaderN
String versionId = String.format("%s-%s-%s", loaderName, loaderVersion, gameVersion);
Path versionsDir = mcDir.resolve("versions");
Path profileDir = versionsDir.resolve(versionId);
Path profileJson = profileDir.resolve(versionId + ".json");
Path profileJsonPath = profileDir.resolve(versionId + ".json");
if (!Files.exists(profileDir)) {
Files.createDirectories(profileDir);
}
Expand All @@ -43,7 +43,27 @@ public static void installVersion(Path mcDir, String gameVersion, String loaderN
Files.deleteIfExists(dummyJar);
Files.createFile(dummyJar);
URL profileUrl = new URL(Reference.getMetaServerEndpoint(String.format("v2/versions/loader/%s/%s/profile/json", gameVersion, loaderVersion)));
Utils.downloadFile(profileUrl, profileJson);
Json profileJson = Json.read(profileUrl);
if (loaderName.equals("iris-fabric-loader")) {
editVersionJson(profileJson);
}
Utils.writeToFile(profileJsonPath, profileJson.toString());
}

private static void editVersionJson(Json profileJson) {
Json.Factory factory = Json.factory();
Map<String, Json> json = profileJson.asJsonMap();
// Replace fabric-loader-etc with iris-fabric-loader-etc
json.compute("id", (ignored, existing) -> factory.string("iris-" + existing.asString()));
// Replace loader maven url and name
for (Json entry : json.get("libraries").asJsonList()) {
final String id = "net.fabricmc:fabric-loader:";
String name = entry.asJsonMap().get("name").asString();
if (name.startsWith("net.fabricmc:fabric-loader:")) {
entry.asJsonMap().put("name", factory.string("net.coderbot:iris-loader:" + name.substring(id.length())));
entry.asJsonMap().put("url", factory.string("https://raw.githubusercontent.com/IrisShaders/Iris-Installer-Maven/master/"));
}
}
}

private static void installProfile(Path mcDir, Path instanceDir, String profileName, String versionId, Icon icon, ProfileInstaller.LauncherType launcherType) throws IOException {
Expand Down

0 comments on commit 9947fef

Please sign in to comment.