Move run java runtime mode

This commit is contained in:
khanhduytran0 2020-09-07 14:44:21 +07:00
parent 94c08b52a5
commit 88ab3875b5
6 changed files with 48 additions and 6 deletions

View file

@ -37,7 +37,7 @@ public class InstallModActivity extends AppCompatActivity
@Override
public void run() {
launchJavaRuntime(modFile);
finish();
// finish();
}
}).start();
}
@ -99,7 +99,7 @@ public class InstallModActivity extends AppCompatActivity
JREUtils.setJavaEnvironment(this);
JREUtils.redirectStdio();
JREUtils.redirectStdio(false);
JREUtils.setJavaEnvironment(this);
JREUtils.initJavaRuntime();
JREUtils.chdir(Tools.MAIN_PATH);

View file

@ -19,8 +19,8 @@ public class JREUtils
dlopen(Tools.homeJreDir + "/lib/libawt_headless.so");
}
public static File redirectStdio() throws ErrnoException {
File logFile = new File(Tools.datapath, "currentlog.txt");
public static File redirectStdio(boolean current) throws ErrnoException {
File logFile = new File(Tools.datapath, (current ? "current" : "latest") + "log.txt");
FileDescriptor fd = Os.open(logFile.getAbsolutePath(), OsConstants.O_WRONLY | OsConstants.O_CREAT | OsConstants.O_TRUNC, 0666);
Os.dup2(fd, OsConstants.STDERR_FILENO);

View file

@ -837,7 +837,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
private FileObserver mLogObserver;
private void runCraft() throws Throwable {
if (Tools.LAUNCH_TYPE != Tools.LTYPE_PROCESS) {
final File currLogFile = JREUtils.redirectStdio();
final File currLogFile = JREUtils.redirectStdio(false);
// DEPRECATED constructor (String) api 29
mLogObserver = new FileObserver(currLogFile.getAbsolutePath(), FileObserver.MODIFY){
@Override

View file

@ -2,12 +2,38 @@ package net.kdt.pojavlaunch;
import android.app.*;
import android.os.*;
import android.view.*;
// This is for test only!
public class NativeMainActivity extends NativeActivity
{
private MCProfile.Builder mProfile;
private JMinecraftVersionList.Version mVersionInfo;
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
mProfile = PojavProfile.getCurrentProfileContent(this);
mVersionInfo = Tools.getVersionInfo(mProfile.getVersion());
}
@Override
public void surfaceCreated(SurfaceHolder holder)
{
super.surfaceCreated(holder);
new Thread() {
@Override
public void run() {
try {
JREUtils.redirectStdio(false);
Tools.launchMinecraft(NativeMainActivity.this, mProfile, mVersionInfo);
} catch (Throwable th) {
Tools.showError(NativeMainActivity.this, th, true);
}
}
}.start();
}
}

View file

@ -72,7 +72,7 @@ public final class Tools
public static final int LAUNCH_TYPE = LTYPE_INVOCATION;
public static ShellProcessOperation mLaunchShell;
public static void launchMinecraft(Activity ctx, MCProfile.Builder profile, JMinecraftVersionList.Version versionInfo) throws Throwable {
public static void launchMinecraft(final Activity ctx, MCProfile.Builder profile, JMinecraftVersionList.Version versionInfo) throws Throwable {
String[] launchArgs = getMinecraftArgs(profile, versionInfo);
List<String> javaArgList = new ArrayList<String>();
@ -186,6 +186,21 @@ public final class Tools
VMLauncher.launchJVM(javaArgList.toArray(new String[0]));
}
}
ctx.runOnUiThread(new Runnable(){
@Override
public void run() {
AlertDialog.Builder dialog = new AlertDialog.Builder(ctx);
dialog.setMessage(R.string.mcn_javaexit_title);
dialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface p1, int p2){
ctx.finish();
}
});
}
});
}
public static String[] getMinecraftArgs(MCProfile.Builder profile, JMinecraftVersionList.Version versionInfo)

View file

@ -145,6 +145,7 @@
</string>
-->
<!-- MainActivity: strings -->
<string name="mcn_javaexit_title">Application exited</string>
<string name="mcn_exit_title">Game exited</string>
<string name="mcn_exit_call">Exit</string>
<string name="mcn_exit_crash">Game Crash detected! Click OK to exit.</string>