33import static net .kdt .pojavlaunch .Architecture .archAsString ;
44import static net .kdt .pojavlaunch .Architecture .getDeviceArchitecture ;
55import static net .kdt .pojavlaunch .Tools .NATIVE_LIB_DIR ;
6- import static net .kdt .pojavlaunch .Tools .downloadFile ;
76import static net .kdt .pojavlaunch .Tools .isOnline ;
87
98import android .app .Activity ;
9+ import android .content .Context ;
1010import android .content .res .AssetManager ;
1111import android .util .Log ;
1212
13- import androidx .appcompat .app .AlertDialog ;
14-
1513import com .kdt .mcgui .ProgressLayout ;
1614
1715import net .kdt .pojavlaunch .multirt .MultiRTUtils ;
1816import net .kdt .pojavlaunch .multirt .Runtime ;
1917import net .kdt .pojavlaunch .progresskeeper .DownloaderProgressWrapper ;
20- import net .kdt .pojavlaunch .progresskeeper .ProgressKeeper ;
2118import net .kdt .pojavlaunch .utils .DownloadUtils ;
22- import net .kdt .pojavlaunch .utils .JREUtils ;
2319import net .kdt .pojavlaunch .utils .MathUtils ;
2420import net .kdt .pojavlaunch .value .launcherprofiles .LauncherProfiles ;
2521import net .kdt .pojavlaunch .value .launcherprofiles .MinecraftProfile ;
2622
27- import java .io .BufferedInputStream ;
2823import java .io .File ;
2924import java .io .FileInputStream ;
3025import java .io .IOException ;
31- import java .io .InputStream ;
3226import java .util .Arrays ;
3327import java .util .List ;
3428
@@ -72,7 +66,7 @@ private static InternalRuntime getInternalRuntime(Runtime runtime) {
7266 }
7367
7468 private static MathUtils .RankedValue <Runtime > getNearestInstalledRuntime (int targetVersion ) {
75- List <Runtime > runtimes = MultiRTUtils .getRuntimes ();
69+ List <Runtime > runtimes = MultiRTUtils .getInstalledRuntimes ();
7670 return MathUtils .findNearestPositive (targetVersion , runtimes , (runtime )->runtime .javaVersion );
7771 }
7872
@@ -169,8 +163,8 @@ private static void showRuntimeFail(Activity activity, JMinecraftVersionList.Ver
169163 activity .getString (R .string .multirt_nocompatiblert , verInfo .javaVersion .majorVersion ));
170164 }
171165
172- public static boolean isValidJavaVersion (int version ) {
173- for (InternalRuntime javaVersion : InternalRuntime .values ()) {
166+ public static boolean isJavaVersionAvailableForDownload (int version ) {
167+ for (ExternalRuntime javaVersion : ExternalRuntime .values ()) {
174168 if (javaVersion .majorVersion == version ) {
175169 return true ;
176170 }
@@ -179,34 +173,35 @@ public static boolean isValidJavaVersion(int version) {
179173 }
180174
181175 private static String getJreSource (int javaVersion , String arch ){
182- return String .format ("https://github.com/AngelAuraMC/angelauramc-openjdk-build/releases/latest/ download/jre%s-android-%s.tar.xz" , javaVersion , arch );
176+ return String .format ("https://github.com/AngelAuraMC/angelauramc-openjdk-build/releases/download/download_jre%1$s/ jre%1$ s-android-%2$ s.tar.xz" , javaVersion , arch );
183177 }
184178 /**
185179 * @return whether installation was successful or not
186180 */
187- private static boolean tryDownloadRuntime (Activity activity , int gameRequiredVersion ){
188- if (!isOnline (activity )) return false ;
181+ private static void tryDownloadRuntime (Context activity , int javaVersion ){
182+ if (!isOnline (activity )) throw new RuntimeException ( activity . getString ( R . string . multirt_no_internet )) ;
189183 String arch = archAsString (getDeviceArchitecture ());
190- if (!isValidJavaVersion (gameRequiredVersion )) return false ;
184+ // Checks for using this method
185+ if (!isJavaVersionAvailableForDownload (javaVersion )) throw new RuntimeException ("This is not an available JRE version" );
186+ if ((getDeviceArchitecture () == Architecture .ARCH_X86 && javaVersion >= 21 )) throw new RuntimeException ("x86 is not supported on Java" +javaVersion );
191187 try {
192- File outputFile = new File (Tools .DIR_CACHE , String .format ("jre%s-android-%s.tar.xz" , gameRequiredVersion , arch ));
188+ File outputFile = new File (Tools .DIR_CACHE , String .format ("jre%s-android-%s.tar.xz" , javaVersion , arch ));
193189 DownloaderProgressWrapper monitor = new DownloaderProgressWrapper (R .string .newdl_downloading_jre_runtime ,
194190 ProgressLayout .UNPACK_RUNTIME );
195- monitor .extraString = Integer .toString (gameRequiredVersion );
191+ monitor .extraString = Integer .toString (javaVersion );
196192 DownloadUtils .downloadFileMonitored (
197- getJreSource (gameRequiredVersion , arch ),
193+ getJreSource (javaVersion , arch ),
198194 outputFile ,
199195 null ,
200196 monitor
201197 );
202- String jreName = "External-" + gameRequiredVersion ;
198+ String jreName = "External-" + javaVersion ;
203199 MultiRTUtils .installRuntimeNamed (NATIVE_LIB_DIR , new FileInputStream (outputFile ), jreName );
204200 MultiRTUtils .postPrepare (jreName );
205201 outputFile .delete ();
206202 } catch (IOException e ) {
207- throw new RuntimeException ("Failed to download Java " +gameRequiredVersion +" for " +arch , e );
203+ throw new RuntimeException ("Failed to download Java " +javaVersion +" for " +arch , e );
208204 }
209- return true ;
210205 }
211206
212207 private enum InternalRuntime {
@@ -223,4 +218,24 @@ private enum InternalRuntime {
223218 }
224219 }
225220
221+ public enum ExternalRuntime {
222+ JRE_8 (8 , "External-8" ),
223+ JRE_17 (17 , "External-17" ),
224+ JRE_21 (21 , "External-21" ),
225+ JRE_25 (25 , "External-25" );
226+ public final int majorVersion ;
227+ public final String name ;
228+ public final String downloadLink ;
229+ public boolean isDownloading = false ;
230+
231+ ExternalRuntime (int majorVersion , String name ) {
232+ this .majorVersion = majorVersion ;
233+ this .name = name ;
234+ this .downloadLink = getJreSource (majorVersion , archAsString (getDeviceArchitecture ()));
235+ }
236+ public void downloadRuntime (Context activity ){
237+ tryDownloadRuntime (activity , majorVersion );
238+ }
239+ }
240+
226241}
0 commit comments