mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 07:39:00 -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;
|
package net.kdt.pojavlaunch;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.GestureDetector;
|
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.JREUtils;
|
||||||
import net.kdt.pojavlaunch.utils.MathUtils;
|
import net.kdt.pojavlaunch.utils.MathUtils;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.lwjgl.glfw.CallbackBridge;
|
import org.lwjgl.glfw.CallbackBridge;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -47,7 +51,7 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc
|
|||||||
private ImageView mMousePointerImageView;
|
private ImageView mMousePointerImageView;
|
||||||
private GestureDetector mGestureDetector;
|
private GestureDetector mGestureDetector;
|
||||||
|
|
||||||
private boolean mSkipDetectMod, mIsVirtualMouseEnabled;
|
private boolean mIsVirtualMouseEnabled;
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@Override
|
@Override
|
||||||
@ -147,40 +151,23 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
placeMouseAt(CallbackBridge.physicalWidth / 2f, CallbackBridge.physicalHeight / 2f);
|
placeMouseAt(CallbackBridge.physicalWidth / 2f, CallbackBridge.physicalHeight / 2f);
|
||||||
|
Bundle extras = getIntent().getExtras();
|
||||||
final File modFile = (File) getIntent().getExtras().getSerializable("modFile");
|
if(extras == null) {
|
||||||
final String javaArgs = getIntent().getExtras().getString("javaArgs");
|
finish();
|
||||||
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();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final String javaArgs = extras.getString("javaArgs");
|
||||||
// No skip detection
|
final Uri resourceUri = (Uri) extras.getParcelable("modUri");
|
||||||
openLogOutput(null);
|
if(extras.getBoolean("openLogOutput", false)) openLogOutput(null);
|
||||||
new Thread(() -> {
|
if (javaArgs != null) {
|
||||||
try {
|
startModInstaller(null, javaArgs);
|
||||||
// Due to time, the code here became, like, actually useless
|
}else if(resourceUri != null) {
|
||||||
// So it was removed
|
ProgressDialog barrierDialog = Tools.getWaitingDialog(this, R.string.multirt_progress_caching);
|
||||||
// Tbh this whole class needs a refactor...
|
PojavApplication.sExecutorService.execute(()->{
|
||||||
doCustomInstall(runtime, modFile, javaArgs);
|
startModInstallerWithUri(resourceUri);
|
||||||
} catch (Throwable e) {
|
runOnUiThread(barrierDialog::dismiss);
|
||||||
Logger.appendToLog("Install failed:");
|
});
|
||||||
Logger.appendToLog(Log.getStackTraceString(e));
|
}
|
||||||
Tools.showError(JavaGUILauncherActivity.this, e);
|
|
||||||
}
|
|
||||||
}, "Installer").start();
|
|
||||||
} catch (Throwable th) {
|
} catch (Throwable th) {
|
||||||
Tools.showError(this, th, true);
|
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
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.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) {
|
public void toggleKeyboard(View view) {
|
||||||
mTouchCharInput.switchKeyboardState();
|
mTouchCharInput.switchKeyboardState();
|
||||||
}
|
}
|
||||||
|
@ -980,7 +980,6 @@ public final class Tools {
|
|||||||
.setView(editText)
|
.setView(editText)
|
||||||
.setPositiveButton(android.R.string.ok, (di, i) -> {
|
.setPositiveButton(android.R.string.ok, (di, i) -> {
|
||||||
Intent intent = new Intent(activity, JavaGUILauncherActivity.class);
|
Intent intent = new Intent(activity, JavaGUILauncherActivity.class);
|
||||||
intent.putExtra("skipDetectMod", true);
|
|
||||||
intent.putExtra("javaArgs", editText.getText().toString());
|
intent.putExtra("javaArgs", editText.getText().toString());
|
||||||
activity.startActivity(intent);
|
activity.startActivity(intent);
|
||||||
});
|
});
|
||||||
@ -988,9 +987,9 @@ public final class Tools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Display and return a progress dialog, instructing to wait */
|
/** 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);
|
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.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
||||||
barrier.setCancelable(false);
|
barrier.setCancelable(false);
|
||||||
barrier.show();
|
barrier.show();
|
||||||
@ -998,30 +997,13 @@ public final class Tools {
|
|||||||
return barrier;
|
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){
|
public static void launchModInstaller(Activity activity, @NonNull Uri uri){
|
||||||
final ProgressDialog alertDialog = getWaitingDialog(activity);
|
Intent intent = new Intent(activity, JavaGUILauncherActivity.class);
|
||||||
|
intent.putExtra("modUri", uri);
|
||||||
alertDialog.setMessage(activity.getString(R.string.multirt_progress_caching));
|
activity.startActivity(intent);
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,12 +57,10 @@ public class ForgeUtils {
|
|||||||
intent.putExtra("javaArgs", "-javaagent:"+ Tools.DIR_DATA+"/forge_installer/forge_installer.jar"
|
intent.putExtra("javaArgs", "-javaagent:"+ Tools.DIR_DATA+"/forge_installer/forge_installer.jar"
|
||||||
+ (createProfile ? "=NPS" : "") + // No Profile Suppression
|
+ (createProfile ? "=NPS" : "") + // No Profile Suppression
|
||||||
" -jar "+modInstallerJar.getAbsolutePath());
|
" -jar "+modInstallerJar.getAbsolutePath());
|
||||||
intent.putExtra("skipDetectMod", true);
|
|
||||||
}
|
}
|
||||||
public static void addAutoInstallArgs(Intent intent, File modInstallerJar, String modpackFixupId) {
|
public static void addAutoInstallArgs(Intent intent, File modInstallerJar, String modpackFixupId) {
|
||||||
intent.putExtra("javaArgs", "-javaagent:"+ Tools.DIR_DATA+"/forge_installer/forge_installer.jar"
|
intent.putExtra("javaArgs", "-javaagent:"+ Tools.DIR_DATA+"/forge_installer/forge_installer.jar"
|
||||||
+ "=\"" + modpackFixupId +"\"" +
|
+ "=\"" + modpackFixupId +"\"" +
|
||||||
" -jar "+modInstallerJar.getAbsolutePath());
|
" -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"
|
intent.putExtra("javaArgs", "-javaagent:"+ Tools.DIR_DATA+"/forge_installer/forge_installer.jar"
|
||||||
+ "=OFNPS" +// No Profile Suppression
|
+ "=OFNPS" +// No Profile Suppression
|
||||||
" -jar "+modInstallerJar.getAbsolutePath());
|
" -jar "+modInstallerJar.getAbsolutePath());
|
||||||
intent.putExtra("skipDetectMod", true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class OptiFineVersions {
|
public static class OptiFineVersions {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user