Skip to content

Commit 68e25f2

Browse files
committed
Improve libraries folder detection
1 parent 4eec3c9 commit 68e25f2

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.gson.JsonNull;
2929
import com.google.gson.JsonObject;
3030
import com.google.gson.JsonParser;
31+
3132
import cpw.mods.modlauncher.Launcher;
3233

3334
public interface IFileDetector {
@@ -52,9 +53,17 @@ default Path getLibraryDir() {
5253
return Paths.get(libraryDir).toAbsolutePath();
5354
}
5455
try {
55-
Path launcher = Paths.get(Launcher.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toAbsolutePath();
56-
// /<version> /modlauncher/mods /cpw /libraries
57-
return launcher.getParent().getParent().getParent().getParent().getParent().toAbsolutePath();
56+
Path launcher = Paths.get(Launcher.class.getProtectionDomain().getCodeSource().getLocation().toURI());
57+
58+
while (!launcher.getFileName().toString().equals("libraries")) {
59+
launcher = launcher.getParent();
60+
61+
if (launcher == null || launcher.getFileName() == null) {
62+
throw new UnsupportedOperationException("Could not detect the libraries folder - it can be manually specified with `-Dforgewrapper.librariesDir=` (Java runtime argument)");
63+
}
64+
}
65+
66+
return launcher.toAbsolutePath();
5867
} catch (URISyntaxException e) {
5968
throw new RuntimeException(e);
6069
}

0 commit comments

Comments
 (0)