Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import cpw.mods.modlauncher.Launcher;
import io.github.zekerzhayard.forgewrapper.installer.detector.DetectorLoader;
import io.github.zekerzhayard.forgewrapper.installer.detector.IFileDetector;
import io.github.zekerzhayard.forgewrapper.installer.util.ModuleUtil;
Expand Down Expand Up @@ -47,7 +46,6 @@ public static void main(String[] args) throws Throwable {

try (URLClassLoader ucl = URLClassLoader.newInstance(new URL[] {
Main.class.getProtectionDomain().getCodeSource().getLocation(),
Launcher.class.getProtectionDomain().getCodeSource().getLocation(),
installerJar.toUri().toURL()
}, ModuleUtil.getPlatformClassLoader())) {
Class<?> installer = ucl.loadClass("io.github.zekerzhayard.forgewrapper.installer.Installer");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package io.github.zekerzhayard.forgewrapper.installer.detector;

import java.net.URL;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;

import cpw.mods.modlauncher.Launcher;

public interface IFileDetector {
/**
* @return The name of the detector.
Expand All @@ -29,7 +28,28 @@ default Path getLibraryDir() {
return Paths.get(libraryDir).toAbsolutePath();
}
try {
Path launcher = Paths.get(Launcher.class.getProtectionDomain().getCodeSource().getLocation().toURI());
URL launcherLocation = null;
String[] classNames = {
"cpw.mods.modlauncher.Launcher",
"net.neoforged.fml.loading.FMLLoader"
};

for (String className : classNames) {
try {
Class<?> clazz = Class.forName(className);
// Return the location of the loaded class
if (clazz.getProtectionDomain().getCodeSource() != null) {
launcherLocation = clazz.getProtectionDomain().getCodeSource().getLocation();
}
} catch (ClassNotFoundException e) {
// ignore and try next
}
}

if (launcherLocation == null) {
throw new UnsupportedOperationException("Could not detect the libraries folder - it can be manually specified with `-Dforgewrapper.librariesDir=` (Java runtime argument)");
}
Path launcher = Paths.get(launcherLocation.toURI());

while (!launcher.getFileName().toString().equals("libraries")) {
launcher = launcher.getParent();
Expand Down