mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-14 15:17:02 -04:00
Ref[javagui]: changes to the Java GUI installer
This commit is contained in:
parent
8da6924006
commit
c6a6c54f56
@ -1,7 +1,9 @@
|
||||
package net.kdt.pojavlaunch;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ClipboardManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.GestureDetector;
|
||||
@ -24,9 +26,11 @@ import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||
import net.kdt.pojavlaunch.utils.JREUtils;
|
||||
import net.kdt.pojavlaunch.utils.MathUtils;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.lwjgl.glfw.CallbackBridge;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
@ -47,7 +51,7 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc
|
||||
private ImageView mMousePointerImageView;
|
||||
private GestureDetector mGestureDetector;
|
||||
|
||||
private boolean mSkipDetectMod, mIsVirtualMouseEnabled;
|
||||
private boolean mIsVirtualMouseEnabled;
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
@ -147,40 +151,23 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc
|
||||
try {
|
||||
|
||||
placeMouseAt(CallbackBridge.physicalWidth / 2f, CallbackBridge.physicalHeight / 2f);
|
||||
|
||||
final File modFile = (File) getIntent().getExtras().getSerializable("modFile");
|
||||
final String javaArgs = getIntent().getExtras().getString("javaArgs");
|
||||
String jreName = LauncherPreferences.PREF_DEFAULT_RUNTIME;
|
||||
if(modFile != null) {
|
||||
int javaVersion = getJavaVersion(modFile);
|
||||
if(javaVersion != -1) {
|
||||
String autoselectRuntime = MultiRTUtils.getNearestJreName(javaVersion);
|
||||
if (autoselectRuntime != null) jreName = autoselectRuntime;
|
||||
}
|
||||
}
|
||||
final Runtime runtime = MultiRTUtils.forceReread(jreName);
|
||||
|
||||
mSkipDetectMod = getIntent().getExtras().getBoolean("skipDetectMod", false);
|
||||
if(getIntent().getExtras().getBoolean("openLogOutput", false)) openLogOutput(null);
|
||||
if (mSkipDetectMod) {
|
||||
new Thread(() -> launchJavaRuntime(runtime, modFile, javaArgs), "JREMainThread").start();
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if(extras == null) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
// No skip detection
|
||||
openLogOutput(null);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
// Due to time, the code here became, like, actually useless
|
||||
// So it was removed
|
||||
// Tbh this whole class needs a refactor...
|
||||
doCustomInstall(runtime, modFile, javaArgs);
|
||||
} catch (Throwable e) {
|
||||
Logger.appendToLog("Install failed:");
|
||||
Logger.appendToLog(Log.getStackTraceString(e));
|
||||
Tools.showError(JavaGUILauncherActivity.this, e);
|
||||
}
|
||||
}, "Installer").start();
|
||||
final String javaArgs = extras.getString("javaArgs");
|
||||
final Uri resourceUri = (Uri) extras.getParcelable("modUri");
|
||||
if(extras.getBoolean("openLogOutput", false)) openLogOutput(null);
|
||||
if (javaArgs != null) {
|
||||
startModInstaller(null, javaArgs);
|
||||
}else if(resourceUri != null) {
|
||||
ProgressDialog barrierDialog = Tools.getWaitingDialog(this, R.string.multirt_progress_caching);
|
||||
PojavApplication.sExecutorService.execute(()->{
|
||||
startModInstallerWithUri(resourceUri);
|
||||
runOnUiThread(barrierDialog::dismiss);
|
||||
});
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
Tools.showError(this, th, true);
|
||||
}
|
||||
@ -194,6 +181,39 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc
|
||||
});
|
||||
}
|
||||
|
||||
private void startModInstallerWithUri(Uri uri) {
|
||||
try {
|
||||
File cacheFile = new File(getCacheDir(), "mod-installer-temp");
|
||||
InputStream contentStream = getContentResolver().openInputStream(uri);
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(cacheFile)) {
|
||||
IOUtils.copy(contentStream, fileOutputStream);
|
||||
}
|
||||
contentStream.close();
|
||||
startModInstaller(cacheFile, null);
|
||||
}catch (IOException e) {
|
||||
Tools.showError(this, e, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void startModInstaller(File modFile, String javaArgs) {
|
||||
new Thread(() -> {
|
||||
Runtime runtime = pickJreForMod(modFile);
|
||||
launchJavaRuntime(runtime, modFile, javaArgs);
|
||||
}, "JREMainThread").start();
|
||||
}
|
||||
|
||||
private Runtime pickJreForMod(File modFile) {
|
||||
String jreName = LauncherPreferences.PREF_DEFAULT_RUNTIME;
|
||||
if(modFile != null) {
|
||||
int javaVersion = getJavaVersion(modFile);
|
||||
if(javaVersion != -1) {
|
||||
String autoselectRuntime = MultiRTUtils.getNearestJreName(javaVersion);
|
||||
if (autoselectRuntime != null) jreName = autoselectRuntime;
|
||||
}
|
||||
}
|
||||
return MultiRTUtils.forceReread(jreName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
@ -313,13 +333,6 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void doCustomInstall(Runtime runtime, File modFile, String javaArgs) {
|
||||
mSkipDetectMod = true;
|
||||
launchJavaRuntime(runtime, modFile, javaArgs);
|
||||
}
|
||||
|
||||
public void toggleKeyboard(View view) {
|
||||
mTouchCharInput.switchKeyboardState();
|
||||
}
|
||||
|
@ -980,7 +980,6 @@ public final class Tools {
|
||||
.setView(editText)
|
||||
.setPositiveButton(android.R.string.ok, (di, i) -> {
|
||||
Intent intent = new Intent(activity, JavaGUILauncherActivity.class);
|
||||
intent.putExtra("skipDetectMod", true);
|
||||
intent.putExtra("javaArgs", editText.getText().toString());
|
||||
activity.startActivity(intent);
|
||||
});
|
||||
@ -988,9 +987,9 @@ public final class Tools {
|
||||
}
|
||||
|
||||
/** Display and return a progress dialog, instructing to wait */
|
||||
private static ProgressDialog getWaitingDialog(Context ctx){
|
||||
public static ProgressDialog getWaitingDialog(Context ctx, int message){
|
||||
final ProgressDialog barrier = new ProgressDialog(ctx);
|
||||
barrier.setMessage(ctx.getString(R.string.global_waiting));
|
||||
barrier.setMessage(ctx.getString(message));
|
||||
barrier.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
||||
barrier.setCancelable(false);
|
||||
barrier.show();
|
||||
@ -998,30 +997,13 @@ public final class Tools {
|
||||
return barrier;
|
||||
}
|
||||
|
||||
/** Copy the mod file, and launch the mod installer activity */
|
||||
/** Launch the mod installer activity. The Uri must be from our own content provider or
|
||||
* from ACTION_OPEN_DOCUMENT
|
||||
*/
|
||||
public static void launchModInstaller(Activity activity, @NonNull Uri uri){
|
||||
final ProgressDialog alertDialog = getWaitingDialog(activity);
|
||||
|
||||
alertDialog.setMessage(activity.getString(R.string.multirt_progress_caching));
|
||||
sExecutorService.execute(() -> {
|
||||
try {
|
||||
final String name = getFileName(activity, uri);
|
||||
final File modInstallerFile = new File(Tools.DIR_CACHE, name);
|
||||
FileOutputStream fos = new FileOutputStream(modInstallerFile);
|
||||
InputStream input = activity.getContentResolver().openInputStream(uri);
|
||||
IOUtils.copy(input, fos);
|
||||
input.close();
|
||||
fos.close();
|
||||
activity.runOnUiThread(() -> {
|
||||
alertDialog.dismiss();
|
||||
Intent intent = new Intent(activity, JavaGUILauncherActivity.class);
|
||||
intent.putExtra("modFile", modInstallerFile);
|
||||
activity.startActivity(intent);
|
||||
});
|
||||
}catch(IOException e) {
|
||||
Tools.showError(activity, e);
|
||||
}
|
||||
});
|
||||
Intent intent = new Intent(activity, JavaGUILauncherActivity.class);
|
||||
intent.putExtra("modUri", uri);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
|
@ -57,12 +57,10 @@ public class ForgeUtils {
|
||||
intent.putExtra("javaArgs", "-javaagent:"+ Tools.DIR_DATA+"/forge_installer/forge_installer.jar"
|
||||
+ (createProfile ? "=NPS" : "") + // No Profile Suppression
|
||||
" -jar "+modInstallerJar.getAbsolutePath());
|
||||
intent.putExtra("skipDetectMod", true);
|
||||
}
|
||||
public static void addAutoInstallArgs(Intent intent, File modInstallerJar, String modpackFixupId) {
|
||||
intent.putExtra("javaArgs", "-javaagent:"+ Tools.DIR_DATA+"/forge_installer/forge_installer.jar"
|
||||
+ "=\"" + modpackFixupId +"\"" +
|
||||
" -jar "+modInstallerJar.getAbsolutePath());
|
||||
intent.putExtra("skipDetectMod", true);
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ public class OptiFineUtils {
|
||||
intent.putExtra("javaArgs", "-javaagent:"+ Tools.DIR_DATA+"/forge_installer/forge_installer.jar"
|
||||
+ "=OFNPS" +// No Profile Suppression
|
||||
" -jar "+modInstallerJar.getAbsolutePath());
|
||||
intent.putExtra("skipDetectMod", true);
|
||||
}
|
||||
|
||||
public static class OptiFineVersions {
|
||||
|
Loading…
x
Reference in New Issue
Block a user