diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/util/SelfDependencyPatcher.java b/HMCL/src/main/java/org/jackhuang/hmcl/util/SelfDependencyPatcher.java index edaa668e4..c3b892fd8 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/util/SelfDependencyPatcher.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/util/SelfDependencyPatcher.java @@ -61,6 +61,7 @@ import java.util.List; import java.util.*; import java.util.concurrent.CancellationException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.Level; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.Collectors.toSet; @@ -102,14 +103,26 @@ public final class SelfDependencyPatcher { private static final Path DEPENDENCIES_DIR_PATH = HMCL_DIRECTORY.resolve("dependencies").resolve(Platform.getPlatform().toString()).resolve("openjfx"); static List readDependencies() { + ArrayList dependencies; //noinspection ConstantConditions try (Reader reader = new InputStreamReader(SelfDependencyPatcher.class.getResourceAsStream(DEPENDENCIES_LIST_FILE), UTF_8)) { - Map> allDependencies = - new Gson().fromJson(reader, new TypeToken>>(){}.getType()); - return allDependencies.get(Platform.getPlatform().toString()); + Map> allDependencies = + new Gson().fromJson(reader, new TypeToken>>(){}.getType()); + dependencies = allDependencies.get(Platform.getPlatform().toString()); } catch (IOException e) { throw new UncheckedIOException(e); } + + try { + ClassLoader classLoader = SelfDependencyPatcher.class.getClassLoader(); + Class.forName("netscape.javascript.JSObject", false, classLoader); + Class.forName("org.w3c.dom.html.HTMLDocument", false, classLoader); + } catch (Throwable e) { + LOG.log(Level.WARNING, "Disable javafx.web because JRE is incomplete", e); + dependencies.removeIf(it -> "javafx.web".equals(it.module) || "javafx.media".equals(it.module)); + } + + return dependencies; } public String module; diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java index 298182a63..b14c909ec 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java @@ -19,6 +19,7 @@ package org.jackhuang.hmcl.util.io; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipFile; +import org.jackhuang.hmcl.util.Lang; import org.jackhuang.hmcl.util.platform.OperatingSystem; import java.io.File; @@ -43,7 +44,7 @@ public final class CompressingUtils { private static final FileSystemProvider ZIPFS_PROVIDER = FileSystemProvider.installedProviders().stream() .filter(it -> "jar".equalsIgnoreCase(it.getScheme())) .findFirst() - .orElseThrow(() -> new IllegalStateException("Zipfs not supported")); + .orElse(null); private CompressingUtils() { } @@ -197,6 +198,9 @@ public final class CompressingUtils { if (useTempFile) env.put("useTempFile", true); try { + if (ZIPFS_PROVIDER == null) + throw new FileSystemNotFoundException("Module jdk.zipfs does not exist"); + return ZIPFS_PROVIDER.newFileSystem(zipFile, env); } catch (ZipError error) { // Since Java 8 throws ZipError stupidly @@ -204,7 +208,7 @@ public final class CompressingUtils { } catch (UnsupportedOperationException ex) { throw new ZipException("Not a zip file"); } catch (FileSystemNotFoundException ex) { - throw new ZipException("Java Environment is broken"); + throw Lang.apply(new ZipException("Java Environment is broken"), it -> it.initCause(ex)); } }