1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

Try to optimize android update with many images.

This commit is contained in:
tdzl2003 2018-07-08 17:06:32 +08:00
parent 818968aba7
commit 48abbc98c9

View File

@ -25,6 +25,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Iterator; import java.util.Iterator;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import java.util.HashMap;
import okio.BufferedSink; import okio.BufferedSink;
import okio.BufferedSource; import okio.BufferedSource;
@ -249,16 +250,17 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, Void, Void> {
} }
} }
private void copyFromResource(String assets, File output) throws IOException { private void copyFromResource(HashMap<String, File> map) throws IOException {
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(context.getPackageResourcePath()))); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(context.getPackageResourcePath())));
ZipEntry ze; ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) { while ((ze = zis.getNextEntry()) != null) {
String fn = ze.getName(); String fn = ze.getName();
if (fn.equals(assets)) { File target = map.get(fn);
if (target != null) {
if (UpdateContext.DEBUG) { if (UpdateContext.DEBUG) {
Log.d("RNUpdate", "Copying from resource " + assets + " to " + output); Log.d("RNUpdate", "Copying from resource " + fn + " to " + target);
} }
unzipToFile(zis, output); unzipToFile(zis, target);
} }
} }
} }
@ -274,6 +276,8 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, Void, Void> {
removeDirectory(param.unzipDirectory); removeDirectory(param.unzipDirectory);
param.unzipDirectory.mkdirs(); param.unzipDirectory.mkdirs();
HashMap<String, File> copyList = new HashMap<String, File>();
while ((ze = zis.getNextEntry()) != null) while ((ze = zis.getNextEntry()) != null)
{ {
String fn = ze.getName(); String fn = ze.getName();
@ -292,7 +296,8 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, Void, Void> {
if (from.isEmpty()) { if (from.isEmpty()) {
from = to; from = to;
} }
copyFromResource(from, new File(param.unzipDirectory, to)); copyList.put(from, new File(param.unzipDirectory, to));
//copyFromResource(from, new File(param.unzipDirectory, to));
} }
continue; continue;
} }
@ -321,6 +326,8 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, Void, Void> {
zis.close(); zis.close();
copyFromResource(copyList);
if (UpdateContext.DEBUG) { if (UpdateContext.DEBUG) {
Log.d("RNUpdate", "Unzip finished"); Log.d("RNUpdate", "Unzip finished");
} }