Start work on auto detecting java versions

This commit is contained in:
Steven Tracey 2022-08-08 14:58:09 -04:00
parent c136c3f804
commit 608b64d035
5 changed files with 62 additions and 5 deletions

View File

@ -4,7 +4,7 @@
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" /> <file type="web" url="file://$PROJECT_DIR$" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -5,10 +5,10 @@ import org.simpleyaml.configuration.file.YamlFile;
import java.io.IOException; import java.io.IOException;
public class Config { public class Config {
private static final YamlFile YML_FILE = new YamlFile(JAML.path + "\\config.yml"); private static final YamlFile YML_FILE = new YamlFile(JAML.path + "/config.yml");
public static void loadConfig() { public static void loadConfig() {
YML_FILE.setConfigurationFile(JAML.path + "\\config.yml"); YML_FILE.setConfigurationFile(JAML.path + "/config.yml");
try { try {
if (!YML_FILE.exists()) { if (!YML_FILE.exists()) {
System.out.println("Config file not found, creating new one..."); System.out.println("Config file not found, creating new one...");
@ -49,7 +49,7 @@ public class Config {
YML_FILE.addDefault("java.jdk16", ""); YML_FILE.addDefault("java.jdk16", "");
YML_FILE.addDefault("java.jdk17", ""); YML_FILE.addDefault("java.jdk17", "");
YML_FILE.addDefault("game.show-snapshots", false); YML_FILE.addDefault("game.show-snapshots", false);
YML_FILE.addDefault("launcher.default-profile", "default"); YML_FILE.addDefault("launcher.default-profile", "");
YML_FILE.setComment("launcher.default-profile", "Set's the profile that will be loaded automatically"); YML_FILE.setComment("launcher.default-profile", "Set's the profile that will be loaded automatically");
YML_FILE.addDefault("launcher.path","default"); YML_FILE.addDefault("launcher.path","default");
YML_FILE.setComment("launcher.path","Path to JAML files\n" + "default: " + JAML.path.toString()); YML_FILE.setComment("launcher.path","Path to JAML files\n" + "default: " + JAML.path.toString());
@ -92,5 +92,6 @@ public class Config {
public static void setValue(String path, Object data) { public static void setValue(String path, Object data) {
YML_FILE.set(path, data); YML_FILE.set(path, data);
saveConfig();
} }
} }

View File

@ -1,5 +1,6 @@
package tech.nevets.jaml.gui; package tech.nevets.jaml.gui;
import tech.nevets.jaml.Config;
import tech.nevets.jaml.objects.Profile; import tech.nevets.jaml.objects.Profile;
import tech.nevets.jaml.objects.Version; import tech.nevets.jaml.objects.Version;
import tech.nevets.jaml.util.LoaderUtils; import tech.nevets.jaml.util.LoaderUtils;
@ -141,6 +142,11 @@ public class NewProfileGui extends JFrame {
} }
ProfileUtils.getProfileList(); ProfileUtils.getProfileList();
if (ProfileUtils.activeProfile == null) {
Config.setValue("launcher.default-profile", profile.getProfileName());
ProfileUtils.getActiveProfile();
}
this.dispose(); this.dispose();
}); });
contentPane.add(button); contentPane.add(button);

View File

@ -92,7 +92,9 @@ public class StartupGui extends JFrame {
currentTaskLabel.setText("Loading Active Profile..."); currentTaskLabel.setText("Loading Active Profile...");
task++; task++;
if (ProfileUtils.activeProfile != null) {
ProfileUtils.getActiveProfile(); ProfileUtils.getActiveProfile();
}
smoothIncrease(); smoothIncrease();
currentTaskLabel.setText("Getting Game Loaders..."); currentTaskLabel.setText("Getting Game Loaders...");

View File

@ -0,0 +1,48 @@
package tech.nevets.jaml.util;
import tech.nevets.jaml.Config;
import tech.nevets.jaml.Launcher;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class JREDetector {
public static void main(String[] args) {
try {
findJavaVersion();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void findJavaVersion() throws IOException {
String javaHomePath = System.getenv("JAVA_HOME");
if (javaHomePath == null) {
System.out.println("No java path found");
return;
}
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command(javaHomePath + "/bin/java.exe", "--version");
Process process = processBuilder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
if (line.contains("18")) {
return;
} else if (line.contains("17")) {
Config.setValue("java.jdk17", javaHomePath + "/bin");
} else if (line.contains("16")) {
Config.setValue("java.jdk16", javaHomePath + "/bin");
} else if (line.contains("8")) {
Config.setValue("java.jdk8", javaHomePath + "/bin");
}
}
process.destroy();
}
}