mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-30 13:13:58 +01:00
Improve fabric loader processor by better utilizing fabric meta API
Removes a bunch of hardcoded workarounds :)
This commit is contained in:
parent
7707e5e45e
commit
3a7c250736
@ -174,6 +174,11 @@ public class PackageBuilder {
|
|||||||
if (processor != null) {
|
if (processor != null) {
|
||||||
LoaderResult result = processor.process(file, manifest, mapper, baseDir);
|
LoaderResult result = processor.process(file, manifest, mapper, baseDir);
|
||||||
|
|
||||||
|
if (result == null) {
|
||||||
|
log.warning("Loader " + file.getName() + " failed to process.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
loaderLibraries.addAll(result.getLoaderLibraries());
|
loaderLibraries.addAll(result.getLoaderLibraries());
|
||||||
installerLibraries.addAll(result.getProcessorLibraries());
|
installerLibraries.addAll(result.getProcessorLibraries());
|
||||||
jarMavens.addAll(result.getJarMavens());
|
jarMavens.addAll(result.getJarMavens());
|
||||||
|
@ -1,23 +1,19 @@
|
|||||||
package com.skcraft.launcher.builder.loaders;
|
package com.skcraft.launcher.builder.loaders;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.io.Closer;
|
import com.google.common.io.Closer;
|
||||||
import com.skcraft.launcher.builder.BuilderUtils;
|
import com.skcraft.launcher.builder.BuilderUtils;
|
||||||
import com.skcraft.launcher.model.loader.MavenUrl;
|
import com.skcraft.launcher.model.loader.FabricMod;
|
||||||
import com.skcraft.launcher.model.loader.profiles.FabricInstallProfile;
|
|
||||||
import com.skcraft.launcher.model.minecraft.Library;
|
import com.skcraft.launcher.model.minecraft.Library;
|
||||||
|
import com.skcraft.launcher.model.minecraft.VersionManifest;
|
||||||
import com.skcraft.launcher.model.modpack.Manifest;
|
import com.skcraft.launcher.model.modpack.Manifest;
|
||||||
import com.skcraft.launcher.util.HttpRequest;
|
import com.skcraft.launcher.util.HttpRequest;
|
||||||
import lombok.extern.java.Log;
|
import lombok.extern.java.Log;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
@ -30,76 +26,39 @@ public class FabricLoaderProcessor implements ILoaderProcessor {
|
|||||||
Closer closer = Closer.create();
|
Closer closer = Closer.create();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ZipEntry installerEntry = BuilderUtils.getZipEntry(jarFile, "fabric-installer.json");
|
String loaderVersion;
|
||||||
|
|
||||||
if (installerEntry != null) {
|
ZipEntry modEntry = BuilderUtils.getZipEntry(jarFile, "fabric.mod.json");
|
||||||
InputStreamReader reader = new InputStreamReader(jarFile.getInputStream(installerEntry));
|
if (modEntry != null) {
|
||||||
FabricInstallProfile profile = mapper.readValue(
|
InputStreamReader reader = new InputStreamReader(jarFile.getInputStream(modEntry));
|
||||||
BuilderUtils.readStringFromStream(closer.register(reader)), FabricInstallProfile.class);
|
FabricMod loaderMod = mapper.readValue(
|
||||||
|
BuilderUtils.readStringFromStream(closer.register(reader)), FabricMod.class);
|
||||||
|
|
||||||
// Check version
|
loaderVersion = loaderMod.getVersion();
|
||||||
if (profile.getVersion() != 1) {
|
} else {
|
||||||
log.warning(String.format("Fabric installer metadata version is %d - we expect version 1.",
|
log.warning("Fabric loader has no 'fabric.mod.json' file, is it really a Fabric Loader jar?");
|
||||||
profile.getVersion()));
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add libraries (TODO: Add server-only libraries to somewhere)
|
log.info("Downloading fabric metadata...");
|
||||||
Iterable<Library> libraries = Iterables.concat(profile.getLibraries().getClient(),
|
URL metaUrl = HttpRequest.url(
|
||||||
profile.getLibraries().getCommon());
|
String.format("https://meta.fabricmc.net/v2/versions/loader/%s/%s/profile/json",
|
||||||
for (Library library : libraries) {
|
manifest.getGameVersion(), loaderVersion));
|
||||||
result.getLoaderLibraries().add(library);
|
VersionManifest fabricManifest = HttpRequest.get(metaUrl)
|
||||||
log.info("Adding loader library " + library.getName());
|
.execute()
|
||||||
}
|
.expectResponseCode(200)
|
||||||
|
.returnContent()
|
||||||
|
.asJson(VersionManifest.class);
|
||||||
|
|
||||||
// Add actual loader jar into library path
|
for (Library library : fabricManifest.getLibraries()) {
|
||||||
if (profile.getLoader() != null) {
|
result.getLoaderLibraries().add(library);
|
||||||
result.getLoaderLibraries().add(profile.getLoader());
|
log.info("Adding loader library " + library.getName());
|
||||||
log.info(String.format("Adding Fabric Loader '%s'", profile.getLoader().getName()));
|
}
|
||||||
} else {
|
|
||||||
log.warning("Fabric loader metadata is missing a `loader` section, making up a fake library");
|
|
||||||
Library loader = new Library();
|
|
||||||
loader.setName("faked:loader:" + FilenameUtils.getBaseName(loaderJar.getName()));
|
|
||||||
|
|
||||||
Library.Downloads downloads = new Library.Downloads();
|
String mainClass = fabricManifest.getMainClass();
|
||||||
downloads.setArtifact(new Library.Artifact());
|
if (mainClass != null) {
|
||||||
downloads.getArtifact().setPath(loaderJar.getName());
|
manifest.getVersionManifest().setMainClass(mainClass);
|
||||||
downloads.getArtifact().setUrl("");
|
log.info("Using main class " + mainClass);
|
||||||
loader.setDownloads(downloads);
|
|
||||||
|
|
||||||
result.getLoaderLibraries().add(loader);
|
|
||||||
// Little bit of a hack here, pretending the filesystem is a maven
|
|
||||||
result.getJarMavens().add(new URL("file:" + loaderJar.getParentFile().getAbsolutePath() + "/"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set main class
|
|
||||||
String mainClass = profile.getMainClass().getClient();
|
|
||||||
if (mainClass != null) {
|
|
||||||
manifest.getVersionManifest().setMainClass(mainClass);
|
|
||||||
log.info("Using main class " + mainClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add intermediary library
|
|
||||||
log.info("Downloading fabric metadata...");
|
|
||||||
URL url = HttpRequest.url("https://meta.fabricmc.net/v2/versions/intermediary/"
|
|
||||||
+ manifest.getVersionManifest().getId());
|
|
||||||
List<MavenUrl> versions = HttpRequest.get(url)
|
|
||||||
.execute()
|
|
||||||
.expectResponseCode(200)
|
|
||||||
.returnContent()
|
|
||||||
.asJson(new TypeReference<List<MavenUrl>>() {});
|
|
||||||
|
|
||||||
if (versions != null && versions.size() > 0) {
|
|
||||||
MavenUrl intermediaryLib = versions.get(0);
|
|
||||||
|
|
||||||
if (intermediaryLib.getUrl() == null) {
|
|
||||||
// FIXME temporary hack since maven URL is missing, hopefully can go away soon
|
|
||||||
// waiting on PR FabricMC/fabric-meta#9
|
|
||||||
intermediaryLib.setUrl("https://maven.fabricmc.net/");
|
|
||||||
}
|
|
||||||
|
|
||||||
result.getLoaderLibraries().add(intermediaryLib.toLibrary());
|
|
||||||
log.info("Added intermediary " + intermediaryLib.getName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
log.warning("HTTP request to fabric metadata API was interrupted, this will probably not work!");
|
log.warning("HTTP request to fabric metadata API was interrupted, this will probably not work!");
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.skcraft.launcher.model.loader;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class FabricMod {
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String version;
|
||||||
|
}
|
@ -1,18 +0,0 @@
|
|||||||
package com.skcraft.launcher.model.loader.profiles;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
import com.skcraft.launcher.model.loader.ExtendedSidedData;
|
|
||||||
import com.skcraft.launcher.model.loader.SidedData;
|
|
||||||
import com.skcraft.launcher.model.minecraft.Library;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public class FabricInstallProfile {
|
|
||||||
private int version;
|
|
||||||
private Library loader;
|
|
||||||
private ExtendedSidedData<List<Library>> libraries;
|
|
||||||
private SidedData<String> mainClass;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user