From 48abbc98c9d30b8938d245b17634d11d0dd05610 Mon Sep 17 00:00:00 2001 From: tdzl2003 Date: Sun, 8 Jul 2018 17:06:32 +0800 Subject: [PATCH] Try to optimize android update with many images. --- .../modules/update/DownloadTask.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java b/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java index 761f6f0..a565b3d 100644 --- a/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java +++ b/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java @@ -25,6 +25,7 @@ import java.nio.charset.StandardCharsets; import java.util.Iterator; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import java.util.HashMap; import okio.BufferedSink; import okio.BufferedSource; @@ -249,16 +250,17 @@ class DownloadTask extends AsyncTask { } } - private void copyFromResource(String assets, File output) throws IOException { + private void copyFromResource(HashMap map) throws IOException { ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(context.getPackageResourcePath()))); ZipEntry ze; while ((ze = zis.getNextEntry()) != null) { String fn = ze.getName(); - if (fn.equals(assets)) { + File target = map.get(fn); + if (target != null) { 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 { removeDirectory(param.unzipDirectory); param.unzipDirectory.mkdirs(); + HashMap copyList = new HashMap(); + while ((ze = zis.getNextEntry()) != null) { String fn = ze.getName(); @@ -292,7 +296,8 @@ class DownloadTask extends AsyncTask { if (from.isEmpty()) { 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; } @@ -321,6 +326,8 @@ class DownloadTask extends AsyncTask { zis.close(); + copyFromResource(copyList); + if (UpdateContext.DEBUG) { Log.d("RNUpdate", "Unzip finished"); }