- Java architecture check is now performed in the Runtime Manager dialog.
- Required Java version is now stated when launching 1.17+ without it installed.
- [Mod installer] Java version is now checked before displaying the file picker. Java 8 is now automatically selected.
- [Mod installer] Brought back "Launch with custom arguments", can be accessed by long-pressing the "Install .jar" button.
This commit is contained in:
khanhduytran0 2022-01-30 16:44:49 +07:00
parent 658c937d73
commit 9114ddacf6
8 changed files with 45 additions and 29 deletions

View File

@ -65,6 +65,10 @@ public abstract class BaseLauncherActivity extends BaseActivity {
public static final int RUN_MOD_INSTALLER = 2050;
private void installMod(boolean customJavaArgs) {
if (MultiRTUtils.getExactJREName(8) == null) {
Toast.makeText(this, R.string.multirt_nojava8rt, Toast.LENGTH_LONG).show();
return;
}
if (customJavaArgs) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.alerttitle_installmod);
@ -149,6 +153,11 @@ public abstract class BaseLauncherActivity extends BaseActivity {
mRuntimeConfigDialog = new MultiRTConfigDialog();
mRuntimeConfigDialog.prepare(this);
((Button)findViewById(R.id.installJarButton)).setOnLongClickListener(view -> {
installMod(true);
return true;
});
//TODO ADD CRASH CHECK AND FOCUS
System.out.println("call to onResumeFragments; E");
}

View File

@ -183,7 +183,7 @@ public class BaseMainActivity extends BaseActivity {
checkLWJGL3Installed();
JREUtils.jreReleaseList = JREUtils.readJREReleaseProperties();
JREUtils.checkJavaArchitecture(this, JREUtils.jreReleaseList.get("OS_ARCH"));
Logger.getInstance().appendToLog("Architecture: " + Architecture.archAsString(Tools.DEVICE_ARCHITECTURE));
checkJavaArgsIsLaunchable(JREUtils.jreReleaseList.get("JAVA_VERSION"));
// appendlnToLog("Info: Custom Java arguments: \"" + LauncherPreferences.PREF_CUSTOM_JAVA_ARGS + "\"");

View File

@ -67,8 +67,15 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc
Logger.getInstance().reset();
try {
JREUtils.jreReleaseList = JREUtils.readJREReleaseProperties(LauncherPreferences.PREF_DEFAULT_RUNTIME);
if (JREUtils.jreReleaseList.get("JAVA_VERSION").equals("1.8.0")) {
MultiRTUtils.setRuntimeNamed(this,LauncherPreferences.PREF_DEFAULT_RUNTIME);
} else {
MultiRTUtils.setRuntimeNamed(this,MultiRTUtils.getExactJREName(8));
JREUtils.jreReleaseList = JREUtils.readJREReleaseProperties();
}
loggerView = findViewById(R.id.launcherLoggerView);
MultiRTUtils.setRuntimeNamed(this,LauncherPreferences.PREF_DEFAULT_RUNTIME);
gestureDetector = new GestureDetector(this, new SingleTapConfirm());
findViewById(R.id.installmod_mouse_pri).setOnTouchListener(this);
@ -278,14 +285,6 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc
public int launchJavaRuntime(File modFile, String javaArgs) {
JREUtils.redirectAndPrintJRELog(this);
try {
JREUtils.jreReleaseList = JREUtils.readJREReleaseProperties();
// Fail immediately when Java 8 is not selected
// TODO: auto override Java 8 if installed
if (!JREUtils.jreReleaseList.get("JAVA_VERSION").equals("1.8.0")) {
throw new RuntimeException("Cannot use the mod installer. In order to use the mod installer, you need to install Java 8 and specify it in the Preferences menu.");
}
List<String> javaArgList = new ArrayList<String>();
// Enable Caciocavallo

View File

@ -63,6 +63,15 @@ public class MultiRTUtils {
return ret;
}
public static String getExactJREName(int majorVersion) {
List<Runtime> runtimes = getRuntimes();
for(Runtime r : runtimes) {
if(r.javaVersion == majorVersion) {
return r.name;
}
}
return null;
}
public static String getNearestJREName(int majorVersion) {
List<Runtime> runtimes = getRuntimes();
int diff_factor = Integer.MAX_VALUE;

View File

@ -14,6 +14,7 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;
import net.kdt.pojavlaunch.Architecture;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
@ -71,7 +72,7 @@ public class RTRecyclerViewAdapter extends RecyclerView.Adapter<RTRecyclerViewAd
public void bindRuntime(MultiRTUtils.Runtime rt, int pos) {
currentRuntime = rt;
currentPosition = pos;
if(rt.versionString != null) {
if(rt.versionString != null && Tools.DEVICE_ARCHITECTURE == Architecture.archAsInt(rt.arch)) {
javaVersionView.setText(ctx.getString(R.string.multirt_java_ver, rt.name, rt.javaVersion));
fullJavaVersionView.setText(rt.versionString);
fullJavaVersionView.setTextColor(defaultColors);
@ -80,8 +81,12 @@ public class RTRecyclerViewAdapter extends RecyclerView.Adapter<RTRecyclerViewAd
setDefaultButton.setEnabled(!default_);
setDefaultButton.setText(default_?R.string.multirt_config_setdefault_already:R.string.multirt_config_setdefault);
}else{
if(rt.versionString == null){
fullJavaVersionView.setText(R.string.multirt_runtime_corrupt);
}else{
fullJavaVersionView.setText(ctx.getString(R.string.multirt_runtime_incompatiblearch, rt.arch));
}
javaVersionView.setText(rt.name);
fullJavaVersionView.setText(R.string.multirt_runtime_corrupt);
fullJavaVersionView.setTextColor(Color.RED);
setDefaultButton.setVisibility(View.GONE);
}

View File

@ -107,7 +107,7 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
mActivity.runOnUiThread(()->{
AlertDialog.Builder bldr = new AlertDialog.Builder(mActivity);
bldr.setTitle(R.string.global_error);
bldr.setMessage(R.string.multirt_nocompartiblert);
bldr.setMessage(mActivity.getString(R.string.multirt_nocompartiblert, verInfo.javaVersion.majorVersion));
bldr.setPositiveButton(android.R.string.ok,(dialog, which)->{
dialog.dismiss();
});

View File

@ -35,19 +35,6 @@ public class JREUtils {
private static String nativeLibDir;
public static Map<String, String> jreReleaseList;
/**
* Checks if the java architecture is correct for the device architecture.
* @param activity Some context to load resources from
* @param jreArch The java architecture to compare as a String.
*/
public static void checkJavaArchitecture(Activity activity, String jreArch) {
Logger.getInstance().appendToLog("Architecture: " + archAsString(Tools.DEVICE_ARCHITECTURE));
if(Tools.DEVICE_ARCHITECTURE == Architecture.archAsInt(jreArch)) return;
Logger.getInstance().appendToLog("Architecture " + archAsString(Tools.DEVICE_ARCHITECTURE) + " is incompatible with Java Runtime " + jreArch);
Tools.dialogOnUiThread(activity, "", activity.getString(R.string.mcn_check_fail_incompatiblearch, archAsString(Tools.DEVICE_ARCHITECTURE), jreArch));
}
public static String findInLdLibPath(String libName) {
if(Os.getenv("LD_LIBRARY_PATH")==null) {
try {
@ -104,8 +91,14 @@ public class JREUtils {
}
public static Map<String, String> readJREReleaseProperties() throws IOException {
return readJREReleaseProperties(Tools.DIR_HOME_JRE);
}
public static Map<String, String> readJREReleaseProperties(String name) throws IOException {
Map<String, String> jreReleaseMap = new ArrayMap<>();
BufferedReader jreReleaseReader = new BufferedReader(new FileReader(Tools.DIR_HOME_JRE + "/release"));
if (!name.contains("/")) {
name = Tools.MULTIRT_HOME + "/" + name;
}
BufferedReader jreReleaseReader = new BufferedReader(new FileReader(name + "/release"));
String currLine;
while ((currLine = jreReleaseReader.readLine()) != null) {
if (!currLine.isEmpty() || currLine.contains("=")) {

View File

@ -131,7 +131,6 @@
<string name="mcn_exit_call">Exit</string>
<string name="mcn_exit_confirm">Are you sure want to force close?</string>
<string name="mcn_check_fail_lwjgl">LWJGL3 was not installed!</string>
<string name="mcn_check_fail_incompatiblearch">Architecture %1$s is incompatible with Java Runtime %2$s.</string>
<string name="mcn_check_fail_vulkan_support">Vulkan Zink renderer is not supported on this device!</string>
<!-- MainActivity: Control buttons -->
@ -238,6 +237,7 @@
<string name="mcl_memory_allocation_subtitle">Controls how much memory is given to Minecraft</string>
<string name="multirt_java_ver">%s (Java %d)</string>
<string name="multirt_runtime_corrupt">Corrupted Java Runtime</string>
<string name="multirt_runtime_incompatiblearch">Incompatible architecture: %s</string>
<string name="multirt_config_title">Java VMs</string>
<string name="multirt_config_add">Add new</string>
<string name="multirt_config_add_subtitle">Import new Java VM</string>
@ -247,7 +247,8 @@
<string name="multirt_config_setdefault">Set default</string>
<string name="multirt_config_setdefault_already">Default</string>
<string name="multirt_config_removeerror_last">You must have at least one Java Runtime installed</string>
<string name="multirt_nocompartiblert">Can\'t find any compartible Java Runtime</string>
<string name="multirt_nocompartiblert">Can\'t find any compartible Java Runtime. This version requires Java %d or newer.</string>
<string name="multirt_nojava8rt">Can\'t find Java 8. In order to use this option, you need to install Java 8.</string>
<string name="compat_117_message">Minecraft 21w10a+ requires the OpenGL 3.2 core profile. Sadly, GL4ES wrapper doesn\'t fully support it at the moment, but there are some additional resources you can install to run these versions. Press OK to confirm installation, and press Cancel to abort launch.</string>
<string name="compat_11x_playanyway">Play anyway</string>