package com.thebrokenrail.freshcoffee; import com.thebrokenrail.freshcoffee.config.HardcodedConfig; import com.thebrokenrail.freshcoffee.dialog.Dialog; import com.thebrokenrail.freshcoffee.download.AdoptOpenJDK; import com.thebrokenrail.freshcoffee.util.PlatformUtil; import com.thebrokenrail.freshcoffee.util.PreviewUtil; import com.thebrokenrail.freshcoffee.util.ReLaunchUtil; import com.thebrokenrail.freshcoffee.util.Util; import com.thebrokenrail.freshcoffee.util.ExtractUtil; import com.thebrokenrail.freshcoffee.util.limit.LimitUtil; import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; import java.io.File; import java.net.MalformedURLException; import java.net.URL; public class FreshCoffee implements PreLaunchEntrypoint { @Override public void onPreLaunch() { if (Util.JAVA_VERSION < LimitUtil.getMinimumJavaVersion().getValue() || Util.JAVA_VERSION > LimitUtil.getMaximumJavaVersion().getValue() || (PreviewUtil.arePreviewFeaturesRequired() && !PreviewUtil.arePreviewFeaturesEnabled())) { if (LimitUtil.getMinimumJavaVersion().getValue() > LimitUtil.getMaximumJavaVersion().getValue()) { Dialog.getInstance().showErrorDialog(String.format(HardcodedConfig.MINIMUM_HIGHER_THAN_MAXIMUM_MESSAGE, LimitUtil.getMinimumJavaVersion().toString(), LimitUtil.getMaximumJavaVersion().toString())); System.exit(1); } ReLaunchUtil.reLaunch(true); // Download Available JDKs AdoptOpenJDK.JDK jdk = AdoptOpenJDK.get().get(PlatformUtil.getPlatform()); if (jdk != null) { int choice = Dialog.getInstance().showOptionDialog(String.format(HardcodedConfig.OUTDATED_JAVA_WITH_OFFER_MESSAGE, LimitUtil.getMinimumJavaVersion().toString(), Util.humanReadableByteCount(jdk.binary.packageObj.size, false)), HardcodedConfig.EXIT_BUTTON, HardcodedConfig.INSTALL_BUTTON); if (choice != 0) { // Install URL url = null; try { url = new URL(jdk.binary.packageObj.link); } catch (MalformedURLException e) { Util.getLogger().error("AdoptOpenJDK API Returned Invalid URL: " + jdk.binary.packageObj.link); } if (url != null) { File dir = Util.getJavaDir(jdk.version.semver); if (dir.exists()) { Util.removeInvalidJDK(dir); } ExtractUtil.extract(url, dir); ReLaunchUtil.reLaunch(false); } System.exit(1); } else { // Exit System.exit(0); } } else { Dialog.getInstance().showErrorDialog(String.format(HardcodedConfig.OUTDATED_JAVA_MESSAGE, LimitUtil.getMinimumJavaVersion().toString())); System.exit(0); } } } }