This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
FreshCoffee/src/main/java/com/thebrokenrail/freshcoffee/FreshCoffee.java

69 lines
3.0 KiB
Java
Raw Normal View History

2020-08-23 02:05:06 +00:00
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;
2020-10-20 16:26:56 +00:00
import com.thebrokenrail.freshcoffee.util.PreviewUtil;
2020-08-23 02:05:06 +00:00
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() {
2020-10-20 16:26:56 +00:00
if (Util.JAVA_VERSION < LimitUtil.getMinimumJavaVersion().getValue() || Util.JAVA_VERSION > LimitUtil.getMaximumJavaVersion().getValue() || (PreviewUtil.arePreviewFeaturesRequired() && !PreviewUtil.arePreviewFeaturesEnabled())) {
2020-08-23 02:05:06 +00:00
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);
}
2020-08-23 20:46:02 +00:00
ReLaunchUtil.reLaunch(true);
2020-08-23 02:05:06 +00:00
// 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()) {
2020-08-23 20:35:51 +00:00
Util.removeInvalidJDK(dir);
2020-08-23 02:05:06 +00:00
}
ExtractUtil.extract(url, dir);
2020-08-23 20:46:02 +00:00
ReLaunchUtil.reLaunch(false);
2020-08-23 03:27:37 +00:00
}
2020-08-23 02:05:06 +00:00
System.exit(1);
} else {
// Exit
System.exit(0);
}
} else {
Dialog.getInstance().showErrorDialog(String.format(HardcodedConfig.OUTDATED_JAVA_MESSAGE, LimitUtil.getMinimumJavaVersion().toString()));
System.exit(0);
}
}
}
}