mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 13:23:12 +08:00 
			
		
		
		
	Try to optimize android update with many images.
This commit is contained in:
		| @@ -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<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()))); | ||||
|         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<DownloadTaskParams, Void, Void> { | ||||
|         removeDirectory(param.unzipDirectory); | ||||
|         param.unzipDirectory.mkdirs(); | ||||
|  | ||||
|         HashMap<String, File> copyList = new HashMap<String, File>(); | ||||
|  | ||||
|         while ((ze = zis.getNextEntry()) != null) | ||||
|         { | ||||
|             String fn = ze.getName(); | ||||
| @@ -292,7 +296,8 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, Void, Void> { | ||||
|                     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<DownloadTaskParams, Void, Void> { | ||||
|  | ||||
|         zis.close(); | ||||
|  | ||||
|         copyFromResource(copyList); | ||||
|  | ||||
|         if (UpdateContext.DEBUG) { | ||||
|             Log.d("RNUpdate", "Unzip finished"); | ||||
|         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 tdzl2003
					tdzl2003