Merge branch 'v3_openjdk' of https://github.com/PojavLauncherTeam/PojavLauncher into v3_openjdk

This commit is contained in:
khanhduytran0 2020-12-12 11:48:20 +07:00
commit add686aa3c
3 changed files with 57 additions and 12 deletions

View File

@ -11,6 +11,8 @@ import com.google.gson.*;
import com.oracle.dalvik.*;
import java.io.*;
import java.lang.reflect.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.*;
import java.util.*;
import java.util.zip.*;
@ -669,7 +671,25 @@ public final class Tools
File file = new File(nameOutput);
DownloadUtils.downloadFile(urlInput, file);
}
public abstract static class DownloaderFeedback {
public abstract void updateProgress(int curr, int max);
}
public static void downloadFileMonitored(String urlInput,String nameOutput, DownloaderFeedback monitor) throws IOException {
if(!new File(nameOutput).exists()){
new File(nameOutput).getParentFile().mkdirs();
}
HttpURLConnection conn = (HttpURLConnection) new URL(urlInput).openConnection();
InputStream readStr = conn.getInputStream();
FileOutputStream fos = new FileOutputStream(new File(nameOutput));
int cur = 0; int oval=0; int len = conn.getContentLength(); byte[] buf = new byte[65535];
while((cur = readStr.read(buf)) != -1) {
oval += cur;
fos.write(buf,0,cur);
monitor.updateProgress(oval,len);
}
fos.close();
conn.disconnect();
}
public static class ZipTool
{
private ZipTool(){}

View File

@ -18,7 +18,7 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
{
private BaseLauncherActivity mActivity;
private boolean launchWithError = false;
MinecraftDownloaderTask thiz = this;
public MinecraftDownloaderTask(BaseLauncherActivity activity) {
mActivity = activity;
}
@ -35,7 +35,6 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
Throwable throwable = null;
try {
final String downVName = "/" + p1[0] + "/" + p1[0];
//Downloading libraries
String minecraftMainJar = Tools.versnDir + downVName + ".jar";
JAssets assets = null;
@ -48,9 +47,16 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
if (verInfo.url != null && !new File(verJsonDir).exists()) {
publishProgress("1", "Downloading " + p1[0] + " configuration...");
Tools.downloadFile(
Tools.downloadFileMonitored(
verInfo.url,
verJsonDir
verJsonDir,
new Tools.DownloaderFeedback(){
@Override
public void updateProgress(int curr, int max) {
publishProgress("0", "Downloading " + p1[0] + " configuration ("+curr+"/"+max+")");
}
}
);
}
@ -60,7 +66,8 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
File outLib;
String libPathURL;
setMax(verInfo.libraries.length + 4 + assets.objects.size());
setMax(verInfo.libraries.length);
zeroProgress();
for (final DependentLibrary libItem : verInfo.libraries) {
if (// libItem.name.startsWith("com.google.code.gson:gson") ||
@ -98,9 +105,15 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
}
try {
libPathURL = libItem.downloads.artifact.url;
Tools.downloadFile(
Tools.downloadFileMonitored(
libPathURL,
outLib.getAbsolutePath()
outLib.getAbsolutePath(),
new Tools.DownloaderFeedback() {
@Override
public void updateProgress(int curr, int max) {
publishProgress("0", mActivity.getString(R.string.mcl_launch_download_lib, libItem.name)+" ("+curr+"/"+max+") ");
}
}
);
} catch (Throwable th) {
if (!skipIfFailed) {
@ -113,14 +126,21 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
}
}
}
setMax(3);
zeroProgress();
publishProgress("1", mActivity.getString(R.string.mcl_launch_download_client, p1[0]));
File minecraftMainFile = new File(minecraftMainJar);
if (!minecraftMainFile.exists() || minecraftMainFile.length() == 0l) {
try {
Tools.downloadFile(
Tools.downloadFileMonitored(
verInfo.downloads.values().toArray(new MinecraftClientInfo[0])[0].url,
minecraftMainJar
minecraftMainJar,
new Tools.DownloaderFeedback() {
@Override
public void updateProgress(int curr, int max) {
publishProgress("0", mActivity.getString(R.string.mcl_launch_download_client, p1[0])+" ("+curr+"/"+max+") ");
}
}
);
} catch (Throwable th) {
if (verInfo.inheritsFrom != null) {
@ -161,6 +181,8 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
}
});
publishProgress("1", mActivity.getString(R.string.mcl_launch_download_assets));
setMax(assets.objects.size());
zeroProgress();
try {
downloadAssets(assets, verInfo.assets, new File(Tools.ASSETS_PATH));
} catch (Exception e) {
@ -262,7 +284,7 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
mActivity.mTask = null;
}
public static final String MINECRAFT_RES = "http://resources.download.minecraft.net/";
public static final String MINECRAFT_RES = "https://resources.download.minecraft.net/";
public JAssets downloadIndex(String versionName, File output) throws Throwable {
if (!output.exists()) {

View File

@ -139,6 +139,7 @@ void sendData(int type, int i1, int i2, int i3, int i4) {
}
void closeGLFWWindow() {
/*
jclass glfwClazz = (*runtimeJNIEnvPtr_JRE)->FindClass(runtimeJNIEnvPtr_JRE, "org/lwjgl/glfw/GLFW");
assert(glfwClazz != NULL);
jmethodID glfwMethod = (*runtimeJNIEnvPtr_JRE)->GetStaticMethodID(runtimeJNIEnvPtr_JRE, glfwMethod, "glfwSetWindowShouldClose", "(JZ)V");
@ -149,6 +150,8 @@ void closeGLFWWindow() {
glfwClazz, glfwMethod,
(jlong) showingWindow, JNI_TRUE
);
*/
exit(-1);
}
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeAttachThreadToOther(JNIEnv* env, jclass clazz, jboolean isAndroid, jboolean isUseStackQueueBool) {