forked from PojavLauncherTeam/PojavLauncher
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat[jre_unpack]: add the ability to include multiple integrated runt…
…imes
- Loading branch information
Showing
7 changed files
with
158 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 0 additions & 98 deletions
98
app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JRE17Util.java
This file was deleted.
Oops, something went wrong.
115 changes: 115 additions & 0 deletions
115
app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/NewJREUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<InternalRuntime> 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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters