Start work on auto detecting java versions
This commit is contained in:
parent
c136c3f804
commit
608b64d035
@ -4,7 +4,7 @@
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</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" />
|
||||
</component>
|
||||
</project>
|
@ -5,10 +5,10 @@ import org.simpleyaml.configuration.file.YamlFile;
|
||||
import java.io.IOException;
|
||||
|
||||
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() {
|
||||
YML_FILE.setConfigurationFile(JAML.path + "\\config.yml");
|
||||
YML_FILE.setConfigurationFile(JAML.path + "/config.yml");
|
||||
try {
|
||||
if (!YML_FILE.exists()) {
|
||||
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.jdk17", "");
|
||||
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.addDefault("launcher.path","default");
|
||||
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) {
|
||||
YML_FILE.set(path, data);
|
||||
saveConfig();
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package tech.nevets.jaml.gui;
|
||||
|
||||
import tech.nevets.jaml.Config;
|
||||
import tech.nevets.jaml.objects.Profile;
|
||||
import tech.nevets.jaml.objects.Version;
|
||||
import tech.nevets.jaml.util.LoaderUtils;
|
||||
@ -141,6 +142,11 @@ public class NewProfileGui extends JFrame {
|
||||
}
|
||||
ProfileUtils.getProfileList();
|
||||
|
||||
if (ProfileUtils.activeProfile == null) {
|
||||
Config.setValue("launcher.default-profile", profile.getProfileName());
|
||||
ProfileUtils.getActiveProfile();
|
||||
}
|
||||
|
||||
this.dispose();
|
||||
});
|
||||
contentPane.add(button);
|
||||
|
@ -92,7 +92,9 @@ public class StartupGui extends JFrame {
|
||||
|
||||
currentTaskLabel.setText("Loading Active Profile...");
|
||||
task++;
|
||||
ProfileUtils.getActiveProfile();
|
||||
if (ProfileUtils.activeProfile != null) {
|
||||
ProfileUtils.getActiveProfile();
|
||||
}
|
||||
smoothIncrease();
|
||||
|
||||
currentTaskLabel.setText("Getting Game Loaders...");
|
||||
|
48
src/main/java/tech/nevets/jaml/util/JREDetector.java
Normal file
48
src/main/java/tech/nevets/jaml/util/JREDetector.java
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user