mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 16:16:04 -04:00
Add progress reporter for libraries
This commit is contained in:
parent
0451b78e04
commit
f078673ac0
@ -11,6 +11,8 @@ import com.google.gson.*;
|
|||||||
import com.oracle.dalvik.*;
|
import com.oracle.dalvik.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.charset.*;
|
import java.nio.charset.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.zip.*;
|
import java.util.zip.*;
|
||||||
@ -669,7 +671,25 @@ public final class Tools
|
|||||||
File file = new File(nameOutput);
|
File file = new File(nameOutput);
|
||||||
DownloadUtils.downloadFile(urlInput, file);
|
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
|
public static class ZipTool
|
||||||
{
|
{
|
||||||
private ZipTool(){}
|
private ZipTool(){}
|
||||||
|
@ -18,7 +18,7 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
|
|||||||
{
|
{
|
||||||
private BaseLauncherActivity mActivity;
|
private BaseLauncherActivity mActivity;
|
||||||
private boolean launchWithError = false;
|
private boolean launchWithError = false;
|
||||||
|
MinecraftDownloaderTask thiz = this;
|
||||||
public MinecraftDownloaderTask(BaseLauncherActivity activity) {
|
public MinecraftDownloaderTask(BaseLauncherActivity activity) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
}
|
}
|
||||||
@ -35,7 +35,6 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
|
|||||||
Throwable throwable = null;
|
Throwable throwable = null;
|
||||||
try {
|
try {
|
||||||
final String downVName = "/" + p1[0] + "/" + p1[0];
|
final String downVName = "/" + p1[0] + "/" + p1[0];
|
||||||
|
|
||||||
//Downloading libraries
|
//Downloading libraries
|
||||||
String minecraftMainJar = Tools.versnDir + downVName + ".jar";
|
String minecraftMainJar = Tools.versnDir + downVName + ".jar";
|
||||||
JAssets assets = null;
|
JAssets assets = null;
|
||||||
@ -48,9 +47,16 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
|
|||||||
|
|
||||||
if (verInfo.url != null && !new File(verJsonDir).exists()) {
|
if (verInfo.url != null && !new File(verJsonDir).exists()) {
|
||||||
publishProgress("1", "Downloading " + p1[0] + " configuration...");
|
publishProgress("1", "Downloading " + p1[0] + " configuration...");
|
||||||
Tools.downloadFile(
|
|
||||||
|
Tools.downloadFileMonitored(
|
||||||
verInfo.url,
|
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;
|
File outLib;
|
||||||
String libPathURL;
|
String libPathURL;
|
||||||
|
|
||||||
setMax(verInfo.libraries.length + 4 + assets.objects.size());
|
setMax(verInfo.libraries.length);
|
||||||
|
zeroProgress();
|
||||||
for (final DependentLibrary libItem : verInfo.libraries) {
|
for (final DependentLibrary libItem : verInfo.libraries) {
|
||||||
|
|
||||||
if (// libItem.name.startsWith("com.google.code.gson:gson") ||
|
if (// libItem.name.startsWith("com.google.code.gson:gson") ||
|
||||||
@ -98,9 +105,15 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
libPathURL = libItem.downloads.artifact.url;
|
libPathURL = libItem.downloads.artifact.url;
|
||||||
Tools.downloadFile(
|
Tools.downloadFileMonitored(
|
||||||
libPathURL,
|
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) {
|
} catch (Throwable th) {
|
||||||
if (!skipIfFailed) {
|
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]));
|
publishProgress("1", mActivity.getString(R.string.mcl_launch_download_client, p1[0]));
|
||||||
File minecraftMainFile = new File(minecraftMainJar);
|
File minecraftMainFile = new File(minecraftMainJar);
|
||||||
if (!minecraftMainFile.exists() || minecraftMainFile.length() == 0l) {
|
if (!minecraftMainFile.exists() || minecraftMainFile.length() == 0l) {
|
||||||
try {
|
try {
|
||||||
Tools.downloadFile(
|
Tools.downloadFileMonitored(
|
||||||
verInfo.downloads.values().toArray(new MinecraftClientInfo[0])[0].url,
|
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) {
|
} catch (Throwable th) {
|
||||||
if (verInfo.inheritsFrom != null) {
|
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));
|
publishProgress("1", mActivity.getString(R.string.mcl_launch_download_assets));
|
||||||
|
setMax(assets.objects.size());
|
||||||
|
zeroProgress();
|
||||||
try {
|
try {
|
||||||
downloadAssets(assets, verInfo.assets, new File(Tools.ASSETS_PATH));
|
downloadAssets(assets, verInfo.assets, new File(Tools.ASSETS_PATH));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -262,7 +284,7 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
|
|||||||
mActivity.mTask = null;
|
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 {
|
public JAssets downloadIndex(String versionName, File output) throws Throwable {
|
||||||
if (!output.exists()) {
|
if (!output.exists()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user