From 0797b7942eb9cedbc65e55439ee32932fa132b56 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh <40482367+khanhduytran0@users.noreply.github.com> Date: Mon, 17 Jun 2024 21:33:22 +0700 Subject: [PATCH 1/4] Chore: Update feature_request issue form to reduce spamming Spams: #5608 #5566 #5565 #5546 #5523 #5502 #5356 #5270 #5256 #5255 #5231 #5183 #5162 #5159 #5146 #5114 etc --- .github/ISSUE_TEMPLATE/feature_request.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 948fab86a3..5a1cc0f20a 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -11,7 +11,7 @@ body: Give us some details into the problem, and how this affects it. placeholder: 'Example: You should add a version selector because of the text box being too small.' validations: - required: false + required: true - type: textarea attributes: @@ -20,7 +20,7 @@ body: What do you want to see changed, added, or removed? Make sure to be specific. placeholder: 'Example: A scrollable version picker.' validations: - required: false + required: true - type: textarea attributes: From eccef88183a5f6c3f9456d8353cc2736c542f84d Mon Sep 17 00:00:00 2001 From: artdeell Date: Fri, 14 Jun 2024 13:29:59 +0300 Subject: [PATCH 2/4] Feat[jre_unpack]: add the ability to include multiple integrated runtimes --- .gitignore | 1 + .../java/net/kdt/pojavlaunch/JRE17Util.java | 98 --------------- .../java/net/kdt/pojavlaunch/NewJREUtil.java | 115 ++++++++++++++++++ .../kdt/pojavlaunch/multirt/MultiRTUtils.java | 25 ++-- .../pojavlaunch/tasks/AsyncAssetManager.java | 2 +- .../tasks/MinecraftDownloader.java | 4 +- .../net/kdt/pojavlaunch/utils/MathUtils.java | 31 +++++ 7 files changed, 158 insertions(+), 118 deletions(-) delete mode 100644 app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JRE17Util.java create mode 100644 app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/NewJREUtil.java diff --git a/.gitignore b/.gitignore index 798bb76779..ff3508cdb5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /build /*/build app_pojavlauncher/src/main/assets/components/jre +/app_pojavlauncher/src/main/assets/components/jre-new/ local.properties .idea/ app_pojavlauncher/.cxx/ diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JRE17Util.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JRE17Util.java deleted file mode 100644 index 1cd0dca35b..0000000000 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JRE17Util.java +++ /dev/null @@ -1,98 +0,0 @@ -package net.kdt.pojavlaunch; - -import static net.kdt.pojavlaunch.Architecture.archAsString; - -import android.app.Activity; -import android.content.res.AssetManager; -import android.util.Log; - -import net.kdt.pojavlaunch.multirt.MultiRTUtils; -import net.kdt.pojavlaunch.multirt.Runtime; -import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles; -import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile; - -import java.io.IOException; - -public class JRE17Util { - public static final String NEW_JRE_NAME = "Internal-17"; - public static boolean checkInternalNewJre(AssetManager assetManager) { - 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(assetManager, launcher_jre17_version); - else return true; - } - - private static boolean unpackJre17(AssetManager assetManager, String rt_version) { - try { - MultiRTUtils.installRuntimeNamedBinpack( - assetManager.open("components/jre-new/universal.tar.xz"), - assetManager.open("components/jre-new/bin-" + archAsString(Tools.DEVICE_ARCHITECTURE) + ".tar.xz"), - "Internal-17", rt_version); - MultiRTUtils.postPrepare("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); - } - - /** @return true if everything is good, false otherwise. */ - public static boolean installNewJreIfNeeded(Activity activity, JMinecraftVersionList.Version versionInfo) { - //Now we have the reliable information to check if our runtime settings are good enough - if (versionInfo.javaVersion == null || versionInfo.javaVersion.component.equalsIgnoreCase("jre-legacy")) - return true; - - LauncherProfiles.load(); - MinecraftProfile minecraftProfile = LauncherProfiles.getCurrentProfile(); - - String selectedRuntime = Tools.getSelectedRuntime(minecraftProfile); - - Runtime runtime = MultiRTUtils.read(selectedRuntime); - if (runtime.javaVersion >= versionInfo.javaVersion.majorVersion) { - return true; - } - - String appropriateRuntime = MultiRTUtils.getNearestJreName(versionInfo.javaVersion.majorVersion); - if (appropriateRuntime != null) { - if (JRE17Util.isInternalNewJRE(appropriateRuntime)) { - JRE17Util.checkInternalNewJre(activity.getAssets()); - } - minecraftProfile.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX + appropriateRuntime; - LauncherProfiles.load(); - } else { - if (versionInfo.javaVersion.majorVersion <= 17) { // there's a chance we have an internal one for this case - if (!JRE17Util.checkInternalNewJre(activity.getAssets())){ - showRuntimeFail(activity, versionInfo); - return false; - } else { - minecraftProfile.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX + JRE17Util.NEW_JRE_NAME; - LauncherProfiles.load(); - } - } else { - showRuntimeFail(activity, versionInfo); - return false; - } - } - - return true; - } - - private static void showRuntimeFail(Activity activity, JMinecraftVersionList.Version verInfo) { - Tools.dialogOnUiThread(activity, activity.getString(R.string.global_error), - activity.getString(R.string.multirt_nocompartiblert, verInfo.javaVersion.majorVersion)); - } - -} \ No newline at end of file diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/NewJREUtil.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/NewJREUtil.java new file mode 100644 index 0000000000..1f264557b9 --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/NewJREUtil.java @@ -0,0 +1,115 @@ +package net.kdt.pojavlaunch; + +import static net.kdt.pojavlaunch.Architecture.archAsString; + +import android.app.Activity; +import android.content.res.AssetManager; +import android.util.Log; + +import net.kdt.pojavlaunch.multirt.MultiRTUtils; +import net.kdt.pojavlaunch.multirt.Runtime; +import net.kdt.pojavlaunch.utils.MathUtils; +import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles; +import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +public class NewJREUtil { + private static boolean checkInternalRuntime(AssetManager assetManager, InternalRuntime internalRuntime) { + String launcher_runtime_version; + String installed_runtime_version = MultiRTUtils.readInternalRuntimeVersion(internalRuntime.name); + try { + launcher_runtime_version = Tools.read(assetManager.open(internalRuntime.path+"/version")); + }catch (IOException exc) { + //we don't have a runtime included! + //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 + return installed_runtime_version != null; + } + // this implicitly checks for null, so it will unpack the runtime even if we don't have one installed + if(!launcher_runtime_version.equals(installed_runtime_version)) + return unpackInternalRuntime(assetManager, internalRuntime, launcher_runtime_version); + else return true; + } + + private static boolean unpackInternalRuntime(AssetManager assetManager, InternalRuntime internalRuntime, String version) { + try { + MultiRTUtils.installRuntimeNamedBinpack( + assetManager.open(internalRuntime.path+"/universal.tar.xz"), + assetManager.open(internalRuntime.path+"/bin-" + archAsString(Tools.DEVICE_ARCHITECTURE) + ".tar.xz"), + internalRuntime.name, version); + MultiRTUtils.postPrepare(internalRuntime.name); + return true; + }catch (IOException e) { + Log.e("NewJREAuto", "Internal JRE unpack failed", e); + return false; + } + } + public static InternalRuntime getInternalRuntime(String s_runtime) { + Runtime runtime = MultiRTUtils.read(s_runtime); + if(runtime == null) return null; + for(InternalRuntime internalRuntime : InternalRuntime.values()) { + if(internalRuntime.name.equals(runtime.name)) return internalRuntime; + } + return null; + } + + private static InternalRuntime findAppropriateInternalRuntime(int targetVersion) { + List runtimeList = Arrays.asList(InternalRuntime.values()); + return MathUtils.findNearestPositive(targetVersion, runtimeList, (runtime)->runtime.majorVersion); + } + + /** @return true if everything is good, false otherwise. */ + public static boolean installNewJreIfNeeded(Activity activity, JMinecraftVersionList.Version versionInfo) { + //Now we have the reliable information to check if our runtime settings are good enough + if (versionInfo.javaVersion == null || versionInfo.javaVersion.component.equalsIgnoreCase("jre-legacy")) + return true; + + LauncherProfiles.load(); + MinecraftProfile minecraftProfile = LauncherProfiles.getCurrentProfile(); + String selectedRuntime = Tools.getSelectedRuntime(minecraftProfile); + Runtime runtime = MultiRTUtils.read(selectedRuntime); + if (runtime.javaVersion >= versionInfo.javaVersion.majorVersion) { + return true; + } + + String appropriateRuntime = MultiRTUtils.getNearestJreName(versionInfo.javaVersion.majorVersion); + boolean failOnMiss = false; + InternalRuntime internalRuntime; + if(appropriateRuntime == null) { + internalRuntime = NewJREUtil.findAppropriateInternalRuntime(versionInfo.javaVersion.majorVersion); + failOnMiss = true; + }else { + internalRuntime = NewJREUtil.getInternalRuntime(appropriateRuntime); + } + + if((internalRuntime == null || !NewJREUtil.checkInternalRuntime(activity.getAssets(), internalRuntime)) && failOnMiss) { + showRuntimeFail(activity, versionInfo); + return false; + } + + minecraftProfile.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX + appropriateRuntime; + LauncherProfiles.write(); + return true; + } + + private static void showRuntimeFail(Activity activity, JMinecraftVersionList.Version verInfo) { + Tools.dialogOnUiThread(activity, activity.getString(R.string.global_error), + activity.getString(R.string.multirt_nocompartiblert, verInfo.javaVersion.majorVersion)); + } + + private enum InternalRuntime { + JRE_17(17, "Internal-17", "components/jre-new"); + public final int majorVersion; + public final String name; + public final String path; + InternalRuntime(int majorVersion, String name, String path) { + this.majorVersion = majorVersion; + this.name = name; + this.path = path; + } + } + +} \ No newline at end of file diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/MultiRTUtils.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/MultiRTUtils.java index 7d008b3f03..52d07063bc 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/MultiRTUtils.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/multirt/MultiRTUtils.java @@ -10,6 +10,7 @@ import net.kdt.pojavlaunch.R; import net.kdt.pojavlaunch.Tools; +import net.kdt.pojavlaunch.utils.MathUtils; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; @@ -60,19 +61,9 @@ public static String getExactJreName(int majorVersion) { public static String getNearestJreName(int majorVersion) { List runtimes = getRuntimes(); - int diff_factor = Integer.MAX_VALUE; - String result = null; - for(Runtime r : runtimes) { - if(r.javaVersion < majorVersion) continue; // lower - not useful - - int currentFactor = r.javaVersion - majorVersion; - if(diff_factor > currentFactor) { - result = r.name; - diff_factor = currentFactor; - } - } - - return result; + Runtime nearestRuntime = MathUtils.findNearestPositive(majorVersion, runtimes, (runtime)->runtime.javaVersion); + if(nearestRuntime == null) return null; + return nearestRuntime.name; } public static void installRuntimeNamed(String nativeLibDir, InputStream runtimeInputStream, String name) throws IOException { @@ -120,11 +111,11 @@ public static void installRuntimeNamedBinpack(InputStream universalFileInputStre } - public static String __internal__readBinpackVersion(String name) { - File binpack_verfile = new File(RUNTIME_FOLDER,"/" + name + "/pojav_version"); + public static String readInternalRuntimeVersion(String name) { + File versionFile = new File(RUNTIME_FOLDER,"/" + name + "/pojav_version"); try { - if (binpack_verfile.exists()) { - return Tools.read(binpack_verfile.getAbsolutePath()); + if (versionFile.exists()) { + return Tools.read(versionFile.getAbsolutePath()); }else{ return null; } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncAssetManager.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncAssetManager.java index 0b13f357d7..e2cb008277 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncAssetManager.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncAssetManager.java @@ -31,7 +31,7 @@ private AsyncAssetManager(){} public static void unpackRuntime(AssetManager am) { /* Check if JRE is included */ String rt_version = null; - String current_rt_version = MultiRTUtils.__internal__readBinpackVersion("Internal"); + String current_rt_version = MultiRTUtils.readInternalRuntimeVersion("Internal"); try { rt_version = Tools.read(am.open("components/jre/version")); } catch (IOException e) { diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloader.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloader.java index 167c165382..5abaa57fdb 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloader.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloader.java @@ -13,7 +13,7 @@ import net.kdt.pojavlaunch.JAssetInfo; import net.kdt.pojavlaunch.JAssets; import net.kdt.pojavlaunch.JMinecraftVersionList; -import net.kdt.pojavlaunch.JRE17Util; +import net.kdt.pojavlaunch.NewJREUtil; import net.kdt.pojavlaunch.R; import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.mirrors.DownloadMirror; @@ -203,7 +203,7 @@ private boolean downloadAndProcessMetadata(Activity activity, JMinecraftVersionL throw new IOException("Unable to read Version JSON for version " + versionName); } - if(activity != null && !JRE17Util.installNewJreIfNeeded(activity, verInfo)){ + if(activity != null && !NewJREUtil.installNewJreIfNeeded(activity, verInfo)){ return false; } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MathUtils.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MathUtils.java index e292f382c1..f26b3af2e5 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MathUtils.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/MathUtils.java @@ -1,5 +1,7 @@ package net.kdt.pojavlaunch.utils; +import java.util.List; + public class MathUtils { //Ported from https://www.arduino.cc/reference/en/language/functions/math/map/ @@ -14,4 +16,33 @@ public static float dist(float x1, float y1, float x2, float y2) { return (float) Math.hypot(x, y); } + /** + * Find the object T with the closest (or higher) value compared to targetValue + * @param targetValue the target value + * @param objects the list of objects that the search will be performed on + * @param valueProvider the provider for each values + * @return the object which has the closest value to targetValue, or null if values of all + * objects are less than targetValue + * @param the object type that is used for the search. + */ + public static T findNearestPositive(int targetValue, List objects, ValueProvider valueProvider) { + int delta = Integer.MAX_VALUE; + T selectedObject = null; + for(T object : objects) { + int objectValue = valueProvider.getValue(object); + if(objectValue < targetValue) continue; + + int currentDelta = objectValue - targetValue; + if(currentDelta == 0) return object; + if(currentDelta >= delta) continue; + + selectedObject = object; + delta = currentDelta; + } + return selectedObject; + } + + public interface ValueProvider { + int getValue(T object); + } } From 23642033664f0cbbfda6a7ac36a23e50c86e615f Mon Sep 17 00:00:00 2001 From: artdeell Date: Fri, 14 Jun 2024 21:30:50 +0300 Subject: [PATCH 3/4] Feat[jre_unpack]: add Jre 21 path to the launcher and .gitignore --- .gitignore | 1 + .../src/main/java/net/kdt/pojavlaunch/NewJREUtil.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ff3508cdb5..235cf03e66 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /*/build app_pojavlauncher/src/main/assets/components/jre /app_pojavlauncher/src/main/assets/components/jre-new/ +/app_pojavlauncher/src/main/assets/components/jre-21/ local.properties .idea/ app_pojavlauncher/.cxx/ diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/NewJREUtil.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/NewJREUtil.java index 1f264557b9..01bfa3db0b 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/NewJREUtil.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/NewJREUtil.java @@ -101,7 +101,8 @@ private static void showRuntimeFail(Activity activity, JMinecraftVersionList.Ver } private enum InternalRuntime { - JRE_17(17, "Internal-17", "components/jre-new"); + JRE_17(17, "Internal-17", "components/jre-new"), + JRE_21(21, "Internal-21", "components/jre-21"); public final int majorVersion; public final String name; public final String path; From 856bace37c41fc763910025aea8f2368b8791299 Mon Sep 17 00:00:00 2001 From: Mathias-Boulay Date: Sun, 16 Jun 2024 10:56:26 +0200 Subject: [PATCH 4/4] build: use new runtimes --- .github/workflows/android.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 8f7a302211..279950573b 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -43,9 +43,19 @@ jobs: path: app_pojavlauncher/src/main/assets/components/jre-new workflow_conclusion: success repo: PojavLauncherTeam/android-openjdk-build-multiarch - branch: buildjre17 + branch: buildjre17-21 name: jre17-pojav + - name: Get JRE21 + uses: dawidd6/action-download-artifact@v2 + with: + workflow: build.yml + path: app_pojavlauncher/src/main/assets/components/jre-21 + workflow_conclusion: success + repo: PojavLauncherTeam/android-openjdk-build-multiarch + branch: buildjre17-21 + name: jre21-pojav + - uses: gradle/gradle-build-action@v2 with: gradle-version: 7.6.1 @@ -80,19 +90,20 @@ jobs: run: | rm -r app_pojavlauncher/src/main/assets/components/jre rm -r app_pojavlauncher/src/main/assets/components/jre-new + rm -r app_pojavlauncher/src/main/assets/components/jre-21 gradle assembleDebug mv app_pojavlauncher/build/outputs/apk/debug/app_pojavlauncher-debug.apk out/app-debug-noruntime.apk - name: Gen md5sums run: | md5sum out/app-debug.apk > out/app-debug.md5 md5sum out/app-debug-noruntime.apk > out/app-debug-noruntime.md5 - + - name: Upload APK uses: actions/upload-artifact@v3 with: name: app-debug path: out/app-debug.* - + - name: Upload AAB uses: actions/upload-artifact@v3 with: