mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-12 22:26:56 -04:00
JRE17 auto-unpacker on new source
This commit is contained in:
parent
40aa51f78f
commit
e06c6f9fea
@ -0,0 +1,49 @@
|
||||
package net.kdt.pojavlaunch;
|
||||
|
||||
import static net.kdt.pojavlaunch.Architecture.archAsString;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.util.Log;
|
||||
|
||||
import net.kdt.pojavlaunch.multirt.MultiRTUtils;
|
||||
import net.kdt.pojavlaunch.multirt.Runtime;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class JRE17Util {
|
||||
private static final String NEW_JRE_NAME = "Internal-17";
|
||||
public static boolean checkInternalNewJre(Context context, MultiRTUtils.RuntimeProgressReporter reporter) {
|
||||
AssetManager assetManager = context.getAssets();
|
||||
String launcher_jre17_version;
|
||||
String installed_jre17_version = MultiRTUtils.__internal__readBinpackVersion(NEW_JRE_NAME);
|
||||
try {
|
||||
launcher_jre17_version = Tools.read(assetManager.open("components/jre-new/version"));
|
||||
}catch (IOException exc) {
|
||||
//we don't have a runtime included!
|
||||
return installed_jre17_version != null; //if we have one installed -> return true -> proceed (no updates but the current one should be functional)
|
||||
//if we don't -> return false -> Cannot find compatible Java runtime
|
||||
}
|
||||
if(!launcher_jre17_version.equals(installed_jre17_version)) // this implicitly checks for null, so it will unpack the runtime even if we don't have one installed
|
||||
return unpackJre17(context, assetManager, launcher_jre17_version, reporter);
|
||||
else return true;
|
||||
}
|
||||
private static boolean unpackJre17(Context context, AssetManager assetManager, String rt_version, MultiRTUtils.RuntimeProgressReporter feedback) {
|
||||
try {
|
||||
MultiRTUtils.installRuntimeNamedBinpack(context.getApplicationInfo().nativeLibraryDir,
|
||||
assetManager.open("components/jre-new/universal.tar.xz"),
|
||||
assetManager.open("components/jre-new/bin-" + archAsString(Tools.DEVICE_ARCHITECTURE) + ".tar.xz"),
|
||||
"Internal-17", rt_version, feedback);
|
||||
MultiRTUtils.postPrepare(context,"Internal-17");
|
||||
return true;
|
||||
}catch (IOException e) {
|
||||
Log.e("JRE17Auto", "Internal JRE unpack failed", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static boolean isInternalNewJRE(String s_runtime) {
|
||||
Runtime runtime = MultiRTUtils.read(s_runtime);
|
||||
if(runtime == null) return false;
|
||||
return NEW_JRE_NAME.equals(runtime.name);
|
||||
}
|
||||
}
|
@ -102,19 +102,16 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
|
||||
if(runtime.javaVersion < verInfo.javaVersion.majorVersion) {
|
||||
String appropriateRuntime = MultiRTUtils.getNearestJreName(verInfo.javaVersion.majorVersion);
|
||||
if(appropriateRuntime != null) {
|
||||
if(JRE17Util.isInternalNewJRE(appropriateRuntime)) {
|
||||
JRE17Util.checkInternalNewJre(mActivity, ((resId, stuff) -> publishProgress(mActivity.getString(resId,stuff))));
|
||||
}
|
||||
minecraftProfile.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX+appropriateRuntime;
|
||||
LauncherProfiles.update();
|
||||
}else{
|
||||
mActivity.runOnUiThread(()->{
|
||||
AlertDialog.Builder bldr = new AlertDialog.Builder(mActivity);
|
||||
bldr.setTitle(R.string.global_error);
|
||||
bldr.setMessage(mActivity.getString(R.string.multirt_nocompartiblert, verInfo.javaVersion.majorVersion));
|
||||
bldr.setPositiveButton(android.R.string.ok,(dialog, which)->{
|
||||
dialog.dismiss();
|
||||
});
|
||||
bldr.show();
|
||||
});
|
||||
throw new SilentException();
|
||||
if(verInfo.javaVersion.majorVersion <= 17) { // there's a chance we have an internal one for this case
|
||||
if(!JRE17Util.checkInternalNewJre(mActivity, ((resId, stuff) -> publishProgress(mActivity.getString(resId,stuff)))))
|
||||
showRuntimeFail();
|
||||
}else showRuntimeFail();
|
||||
}
|
||||
} //if else, we are satisfied
|
||||
}
|
||||
@ -273,6 +270,18 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
|
||||
return throwable;
|
||||
}
|
||||
}
|
||||
private void showRuntimeFail() throws SilentException{
|
||||
mActivity.runOnUiThread(()->{
|
||||
AlertDialog.Builder bldr = new AlertDialog.Builder(mActivity);
|
||||
bldr.setTitle(R.string.global_error);
|
||||
bldr.setMessage(mActivity.getString(R.string.multirt_nocompartiblert, verInfo.javaVersion.majorVersion));
|
||||
bldr.setPositiveButton(android.R.string.ok,(dialog, which)->{
|
||||
dialog.dismiss();
|
||||
});
|
||||
bldr.show();
|
||||
});
|
||||
throw new SilentException();
|
||||
}
|
||||
private int addProgress = 0;
|
||||
public static class SilentException extends Exception{}
|
||||
public void zeroProgress() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user