From a9bf677e78a2160b773ef7d7efcdadbba35a8c9a Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 Sep 2017 22:20:35 +0200 Subject: [PATCH] implement Decompressing --- .../filemanager/adapters/ItemsAdapter.kt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index 88ef7f0d..8a063322 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -33,6 +33,7 @@ import java.io.FileInputStream import java.io.FileOutputStream import java.util.* import java.util.zip.ZipEntry +import java.util.zip.ZipFile import java.util.zip.ZipOutputStream @@ -243,9 +244,45 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList): Boolean { + sourcePaths.map { File(it) } + .forEach { + try { + val zipFile = ZipFile(it) + val entries = zipFile.entries() + while (entries.hasMoreElements()) { + val entry = entries.nextElement() + val file = File(it.parent, entry.name) + if (entry.isDirectory) { + file.mkdirs() + } else { + file.parentFile.mkdirs() + val ins = zipFile.getInputStream(entry) + ins.use { + ins.copyTo(FileOutputStream(file)) + } + } + } + } catch (e: Exception) { + activity.showErrorToast(e.toString()) + return false + } + } + return true + } + fun zipPaths(sourcePaths: List, targetPath: String): Boolean { val queue = LinkedList() val out = FileOutputStream(File(targetPath))