Merge pull request #3227 from PojavLauncherTeam/jre17-autounpack-u

Jre17 autounpack u
This commit is contained in:
ArtDev 2022-05-13 14:48:25 +03:00 committed by GitHub
commit 9a79678c9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 84 additions and 10 deletions

View file

@ -73,6 +73,17 @@ jobs:
name: jre8-pojav
run_id: 2140559381
- name: Get JRE17
uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: build.yml
path: app_pojavlauncher/src/main/assets/components/jre-new
workflow_conclusion: success
repo: PojavLauncherTeam/android-openjdk-build-multiarch
branch: buildjre17
name: jre17-pojav
- name: Build JRE JAR files
run: |
cp -R gl4es/libs/* app_pojavlauncher/src/main/jniLibs/
@ -100,6 +111,7 @@ jobs:
- name: Build APK without runtime
run: |
rm -r app_pojavlauncher/src/main/assets/components/jre
rm -r app_pojavlauncher/src/main/assets/components/jre-new
./gradlew assembleDebug
mv app_pojavlauncher/build/outputs/apk/debug/app_pojavlauncher-debug.apk out/app-debug-noruntime.apk

View file

@ -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 {
public 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);
}
}

View file

@ -102,19 +102,20 @@ 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("0",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("0",mActivity.getString(resId,stuff)))))
showRuntimeFail();
else {
minecraftProfile.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX+JRE17Util.NEW_JRE_NAME;
LauncherProfiles.update();
}
}else showRuntimeFail();
}
} //if else, we are satisfied
}
@ -273,6 +274,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() {