This commit is contained in:
ShirosakiMio 2024-09-11 21:16:35 +08:00
parent 42591b72c3
commit bcd47df4a7
2 changed files with 22 additions and 11 deletions

View File

@ -176,7 +176,10 @@ class MainActivity : FCLActivity(), OnSelectListener, View.OnClickListener {
.setView(layout)
.setPositiveButton(com.tungsten.fcllibrary.R.string.dialog_positive) { _: DialogInterface?, _: Int ->
JarExecutorHelper.exec(
this@MainActivity, null, 8, editText.text.toString()
this@MainActivity,
null,
JarExecutorHelper.getJava(null),
editText.text.toString()
)
}
.setNegativeButton(com.tungsten.fcllibrary.R.string.dialog_negative, null)

View File

@ -59,16 +59,7 @@ public class JarExecutorHelper {
}
private static void launchJarExecutor(Context context, File file) {
int version = getJavaVersion(file);
int javaVersion = getNearestJavaVersion(version);
Profile profile = Profiles.getSelectedProfile();
if (profile != null) {
String java = profile.getGlobal().getJava();
if (!java.equals(JavaVersion.JAVA_AUTO.getVersionName())) {
javaVersion = JavaVersion.getJavaFromVersionName(java).getVersion();
}
}
exec(context, file, javaVersion, null);
exec(context, file, getJava(file), null);
}
public static void exec(Context context, File file, int javaVersion, String args) {
@ -90,6 +81,22 @@ public class JarExecutorHelper {
}
}
public static int getJava(File file) {
int javaVersion = JavaVersion.JAVA_VERSION_8;
if (file != null) {
int version = getJavaVersion(file);
javaVersion = getNearestJavaVersion(version);
}
Profile profile = Profiles.getSelectedProfile();
if (profile != null) {
String java = profile.getGlobal().getJava();
if (!java.equals(JavaVersion.JAVA_AUTO.getVersionName())) {
javaVersion = JavaVersion.getJavaFromVersionName(java).getVersion();
}
}
return javaVersion;
}
private static int getNearestJavaVersion(int majorVersion) {
if (majorVersion > JavaVersion.JAVA_VERSION_17)
return JavaVersion.JAVA_VERSION_21;
@ -135,6 +142,7 @@ public class JarExecutorHelper {
return -1;
}
}
private static int classVersionToJavaVersion(int majorVersion) {
if (majorVersion < 46)
return 2;