Support forceload for downloaded JVMs
This commit is contained in:
parent
5a61749aea
commit
80b960a8c9
|
@ -1,4 +1,4 @@
|
|||
image: gradle:jdk16
|
||||
image: gradle:jdk17
|
||||
|
||||
variables:
|
||||
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
|
||||
|
|
|
@ -23,6 +23,10 @@ Steps:
|
|||
- x64\opengl32.dll to natives\forceload\opengl32.dll
|
||||
- Launch Inceptum as normal
|
||||
|
||||
WARNING: Libraries added this way will also be added to any JVM which is downloaded afterwards.\
|
||||
This is done so they can be loaded from the JVM binaries directory, prioritizing them before system libraries.\
|
||||
This means you WILL need to remove downloaded JVMs if you change this. (Inceptum\natives)
|
||||
|
||||
# Using a portable JVM
|
||||
- Download an [Adoptium JVM build](https://api.adoptium.net/v3/binary/latest/17/ga/windows/x64/jdk/hotspot/normal/eclipse?project=jdk)
|
||||
- Extract the directory inside the zip file into your wrappers directory
|
||||
|
|
|
@ -33,6 +33,7 @@ public class Inceptum {
|
|||
public static final Path NATIVES_DIR = MetaHolder.BASE_PATH.resolve("natives");
|
||||
private static final Path CONFIG_PATH = MetaHolder.BASE_PATH.resolve("glaunch2.json");
|
||||
public static final Path ACCOUNTS_PATH = MetaHolder.BASE_PATH.resolve("accounts.json");
|
||||
public static final Path FORCE_LOAD_PATH = NATIVES_DIR.resolve("forceload");
|
||||
public static final Set<Command> COMMANDS = Set.of(new HelpCommand(), new GuiCommand(), new LaunchCommand(), new UpdateCheckCommand(), new JvmStateCommand());
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("Inceptum");
|
||||
public static final Gson GSON = new GsonBuilder()
|
||||
|
@ -82,10 +83,9 @@ public class Inceptum {
|
|||
if (!Files.exists(INSTANCE_DIR)) Files.createDirectories(INSTANCE_DIR);
|
||||
if (!Files.exists(ASSETS_DIR)) Files.createDirectories(ASSETS_DIR);
|
||||
if (!Files.exists(LIBRARIES_DIR)) Files.createDirectories(LIBRARIES_DIR);
|
||||
if (Files.exists(NATIVES_DIR.resolve("forceload"))) {
|
||||
if (Files.exists(FORCE_LOAD_PATH)) {
|
||||
Inceptum.LOGGER.info("Force-Loading libraries:");
|
||||
Utils.ls(NATIVES_DIR.resolve("forceload"), path -> {
|
||||
//TODO provide a way to inject mesa into minecraft
|
||||
Utils.ls(FORCE_LOAD_PATH, path -> {
|
||||
Inceptum.LOGGER.info("Loading " + path);
|
||||
System.load(path.toString());
|
||||
});
|
||||
|
|
|
@ -24,8 +24,8 @@ public class Steps {
|
|||
new SetupDirsStep(),
|
||||
new DownloadJavaStep(),
|
||||
new DownloadClientStep(),
|
||||
new DownloadAssetsStep(),
|
||||
new DownloadLibrariesStep(),
|
||||
new DownloadAssetsStep(),
|
||||
new WriteMetadataStep())
|
||||
);
|
||||
|
||||
|
|
|
@ -38,5 +38,8 @@ public class DownloadJavaStep implements Step {
|
|||
case "directory" -> Files.createDirectories(tPath);
|
||||
}
|
||||
}
|
||||
if (Files.exists(Inceptum.FORCE_LOAD_PATH)) {
|
||||
Utils.copyContent(Inceptum.FORCE_LOAD_PATH, jvmDir.resolve("bin"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,9 @@ import io.gitlab.jfronny.inceptum.util.Utils;
|
|||
import io.gitlab.jfronny.inceptum.util.VersionInfoLibraryResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
@ -43,9 +40,7 @@ public class DownloadLibrariesStep implements Step {
|
|||
currentState.set("Extracting natives");
|
||||
Inceptum.LOGGER.info(currentState.get());
|
||||
try (FileSystem libFs = Utils.openZipFile(path, false)) {
|
||||
for (Path path1 : Utils.ls(libFs.getPath("."))) {
|
||||
Utils.copyRecursive(path1, Inceptum.NATIVES_DIR.resolve(InstanceMeta.getMinecraftVersion(version.id)));
|
||||
}
|
||||
Utils.copyContent(libFs.getPath("."), Inceptum.NATIVES_DIR.resolve(InstanceMeta.getMinecraftVersion(version.id)));
|
||||
}
|
||||
catch (Throwable t) {
|
||||
Files.delete(path);
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package io.gitlab.jfronny.inceptum.util;
|
||||
|
||||
public interface ThrowingConsumer<T, TEx extends Throwable> {
|
||||
void consume(T val) throws TEx;
|
||||
}
|
|
@ -16,7 +16,6 @@ import java.nio.file.attribute.BasicFileAttributes;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -109,19 +108,25 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static void clearDirectory(Path path) throws IOException {
|
||||
clearDirectory(path, p -> true);
|
||||
}
|
||||
|
||||
public static void clearDirectory(Path path, Predicate<Path> shouldDelete) throws IOException {
|
||||
if (!Files.exists(path)) return;
|
||||
try {
|
||||
Utils.ls(path, p -> {
|
||||
if (Files.isDirectory(p)) {
|
||||
try {
|
||||
deleteRecursive(p);
|
||||
if (shouldDelete.test(p))
|
||||
deleteRecursive(p);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Files.delete(p);
|
||||
if (shouldDelete.test(p))
|
||||
Files.delete(p);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -133,13 +138,18 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static void deleteRecursive(Path path) throws IOException {
|
||||
deleteRecursive(path, p -> true);
|
||||
}
|
||||
|
||||
public static void deleteRecursive(Path path, Predicate<Path> shouldDelete) throws IOException {
|
||||
if (Files.isDirectory(path)) {
|
||||
Files.walkFileTree(path, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
FileVisitResult fv = super.visitFile(file, attrs);
|
||||
if (fv != FileVisitResult.CONTINUE) return fv;
|
||||
Files.delete(file);
|
||||
if (shouldDelete.test(file))
|
||||
Files.delete(file);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -147,7 +157,9 @@ public class Utils {
|
|||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||
FileVisitResult fv = super.postVisitDirectory(dir, exc);
|
||||
if (fv != FileVisitResult.CONTINUE) return fv;
|
||||
Files.delete(dir);
|
||||
if (shouldDelete.test(dir) && ls(dir).isEmpty()) {
|
||||
Files.delete(dir);
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
|
@ -155,20 +167,22 @@ public class Utils {
|
|||
else Files.delete(path);
|
||||
}
|
||||
|
||||
public static void copyRecursive(Path source, Path destination) throws IOException {
|
||||
copyRecursive(source, destination, StandardCopyOption.COPY_ATTRIBUTES);
|
||||
public static void copyContent(Path source, Path destination) throws IOException {
|
||||
copyContent(source, destination, StandardCopyOption.COPY_ATTRIBUTES);
|
||||
}
|
||||
|
||||
public static void copyRecursive(Path source, Path destination, CopyOption... copyOptions) throws IOException {
|
||||
public static void copyContent(Path source, Path destination, CopyOption... copyOptions) throws IOException {
|
||||
if (!Files.exists(destination)) Files.createDirectories(destination);
|
||||
if(Files.isDirectory(source)) {
|
||||
Utils.ls(source, sourcePath -> {
|
||||
try {
|
||||
copyRecursive(sourcePath, destination.resolve(sourcePath.getFileName().toString()), copyOptions);
|
||||
} catch (IOException e) {
|
||||
Inceptum.LOGGER.error("Could not recursively copy", e);
|
||||
try (Stream<Path> paths = Files.walk(source)) {
|
||||
for (Path path : paths.toList()) {
|
||||
if (source.equals(path)) continue;
|
||||
Path d = destination.resolve(source.relativize(path).toString());
|
||||
if (Files.exists(d)) continue;
|
||||
if (Files.isDirectory(d)) Files.createDirectories(d);
|
||||
else Files.copy(path, d);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if(Files.exists(source)) {
|
||||
Path target = destination.resolve(source.getFileName().toString());
|
||||
if (!Files.exists(target)
|
||||
|
@ -177,7 +191,6 @@ public class Utils {
|
|||
} else {
|
||||
throw new FileNotFoundException(source.toAbsolutePath().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void openWebBrowser(URI uri) {
|
||||
|
@ -222,9 +235,9 @@ public class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void ls(Path dir, Consumer<Path> consumer) throws IOException {
|
||||
public static <TEx extends Exception> void ls(Path dir, ThrowingConsumer<Path, TEx> consumer) throws IOException, TEx {
|
||||
try (Stream<Path> sp = Files.list(dir)) {
|
||||
sp.forEach(consumer);
|
||||
for (Path path : sp.toList()) consumer.consume(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public class MainWindow extends Window {
|
|||
try {
|
||||
Utils.clearDirectory(Inceptum.ASSETS_DIR);
|
||||
Utils.clearDirectory(Inceptum.LIBRARIES_DIR);
|
||||
Utils.clearDirectory(Inceptum.NATIVES_DIR);
|
||||
Utils.clearDirectory(Inceptum.NATIVES_DIR, path -> !path.endsWith("forceload"));
|
||||
Utils.clearDirectory(Inceptum.CACHE_DIR);
|
||||
Steps.reDownload();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -25,7 +25,7 @@ public class MetaHolder {
|
|||
.registerTypeAdapter(ComparableVersion.class, new ComparableVersionAdapter())
|
||||
.create()
|
||||
.fromJson(isr, InceptumVersion.class);
|
||||
Path runDir = getDir().resolve("run");
|
||||
Path runDir = getRunDir();
|
||||
BASE_PATH = VERSION.isPublic && !Files.exists(runDir)
|
||||
? getConfigPath().resolve("Inceptum")
|
||||
: runDir;
|
||||
|
@ -48,19 +48,21 @@ public class MetaHolder {
|
|||
};
|
||||
}
|
||||
|
||||
private static Path getDir() {
|
||||
private static Path getRunDir() {
|
||||
Path simpleRunDir = Path.of(".").resolve("run");
|
||||
if (Files.exists(simpleRunDir)) return simpleRunDir;
|
||||
URL url = MetaHolder.class.getProtectionDomain().getCodeSource().getLocation();
|
||||
String p = url.getPath();
|
||||
if (p.endsWith(".jar") && !p.endsWith("/build/libs/wrapper-" + VERSION.version + ".jar")) {
|
||||
try {
|
||||
return new File(url.toURI()).toPath().getParent();
|
||||
return new File(url.toURI()).toPath().getParent().resolve("run");
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
return Path.of(".");
|
||||
return simpleRunDir;
|
||||
}
|
||||
} else {
|
||||
System.out.println("Not running in a jar, using ./run");
|
||||
return Path.of(".");
|
||||
return simpleRunDir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue