@@ -46,12 +46,8 @@ import com.simplemobiletools.filemanager.pro.models.ListItem
4646import com.stericson.RootTools.RootTools
4747import net.lingala.zip4j.exception.ZipException
4848import net.lingala.zip4j.io.inputstream.ZipInputStream
49- import net.lingala.zip4j.io.outputstream.ZipOutputStream
5049import net.lingala.zip4j.model.LocalFileHeader
51- import net.lingala.zip4j.model.ZipParameters
52- import net.lingala.zip4j.model.enums.EncryptionMethod
5350import java.io.BufferedInputStream
54- import java.io.Closeable
5551import java.io.File
5652import java.util.*
5753
@@ -476,7 +472,7 @@ class ItemsAdapter(
476472 return
477473 }
478474
479- CompressAsDialog (activity, firstPath) { destination, password ->
475+ CompressAsDialog (activity, firstPath) { destination, compressionFormat, password ->
480476 activity.handleAndroidSAFDialog(firstPath) { granted ->
481477 if (! granted) {
482478 return @handleAndroidSAFDialog
@@ -489,7 +485,7 @@ class ItemsAdapter(
489485 activity.toast(R .string.compressing)
490486 val paths = getSelectedFileDirItems().map { it.path }
491487 ensureBackgroundThread {
492- if (compressPaths(paths, destination, password)) {
488+ if (CompressionHelper . compressPaths(activity, paths, destination, compressionFormat , password)) {
493489 activity.runOnUiThread {
494490 activity.toast(R .string.compression_successful)
495491 listener?.refreshFragment()
@@ -638,89 +634,6 @@ class ItemsAdapter(
638634 }
639635 }
640636
641- @SuppressLint(" NewApi" )
642- private fun compressPaths (sourcePaths : List <String >, targetPath : String , password : String? = null): Boolean {
643- val queue = LinkedList <String >()
644- val fos = activity.getFileOutputStreamSync(targetPath, " application/zip" ) ? : return false
645-
646- val zout = password?.let { ZipOutputStream (fos, password.toCharArray()) } ? : ZipOutputStream (fos)
647- var res: Closeable = fos
648-
649- fun zipEntry (name : String ) = ZipParameters ().also {
650- it.fileNameInZip = name
651- if (password != null ) {
652- it.isEncryptFiles = true
653- it.encryptionMethod = EncryptionMethod .AES
654- }
655- }
656-
657- try {
658- sourcePaths.forEach { currentPath ->
659- var name: String
660- var mainFilePath = currentPath
661- val base = " ${mainFilePath.getParentPath()} /"
662- res = zout
663- queue.push(mainFilePath)
664- if (activity.getIsPathDirectory(mainFilePath)) {
665- name = " ${mainFilePath.getFilenameFromPath()} /"
666- zout.putNextEntry(
667- ZipParameters ().also {
668- it.fileNameInZip = name
669- }
670- )
671- }
672-
673- while (! queue.isEmpty()) {
674- mainFilePath = queue.pop()
675- if (activity.getIsPathDirectory(mainFilePath)) {
676- if (activity.isRestrictedSAFOnlyRoot(mainFilePath)) {
677- activity.getAndroidSAFFileItems(mainFilePath, true ) { files ->
678- for (file in files) {
679- name = file.path.relativizeWith(base)
680- if (activity.getIsPathDirectory(file.path)) {
681- queue.push(file.path)
682- name = " ${name.trimEnd(' /' )} /"
683- zout.putNextEntry(zipEntry(name))
684- } else {
685- zout.putNextEntry(zipEntry(name))
686- activity.getFileInputStreamSync(file.path)!! .copyTo(zout)
687- zout.closeEntry()
688- }
689- }
690- }
691- } else {
692- val mainFile = File (mainFilePath)
693- for (file in mainFile.listFiles()) {
694- name = file.path.relativizeWith(base)
695- if (activity.getIsPathDirectory(file.absolutePath)) {
696- queue.push(file.absolutePath)
697- name = " ${name.trimEnd(' /' )} /"
698- zout.putNextEntry(zipEntry(name))
699- } else {
700- zout.putNextEntry(zipEntry(name))
701- activity.getFileInputStreamSync(file.path)!! .copyTo(zout)
702- zout.closeEntry()
703- }
704- }
705- }
706-
707- } else {
708- name = if (base == currentPath) currentPath.getFilenameFromPath() else mainFilePath.relativizeWith(base)
709- zout.putNextEntry(zipEntry(name))
710- activity.getFileInputStreamSync(mainFilePath)!! .copyTo(zout)
711- zout.closeEntry()
712- }
713- }
714- }
715- } catch (exception: Exception ) {
716- activity.showErrorToast(exception)
717- return false
718- } finally {
719- res.close()
720- }
721- return true
722- }
723-
724637 private fun askConfirmDelete () {
725638 activity.handleDeletePasswordProtection {
726639 val itemsCnt = selectedKeys.size
0 commit comments