mirror of
				https://github.com/SimpleMobileTools/Simple-File-Manager.git
				synced 2025-06-05 22:09:15 +02:00 
			
		
		
		
	Add incorrect password toast when decompressing multiple protected zips
This commit is contained in:
		| @@ -44,12 +44,14 @@ import kotlinx.android.synthetic.main.item_file_dir_list.view.item_icon | |||||||
| import kotlinx.android.synthetic.main.item_file_dir_list.view.item_name | import kotlinx.android.synthetic.main.item_file_dir_list.view.item_name | ||||||
| import kotlinx.android.synthetic.main.item_file_grid.view.* | import kotlinx.android.synthetic.main.item_file_grid.view.* | ||||||
| import kotlinx.android.synthetic.main.item_section.view.* | import kotlinx.android.synthetic.main.item_section.view.* | ||||||
|  | import net.lingala.zip4j.exception.ZipException | ||||||
|  | import net.lingala.zip4j.io.inputstream.ZipInputStream | ||||||
|  | import net.lingala.zip4j.model.LocalFileHeader | ||||||
| import java.io.BufferedInputStream | import java.io.BufferedInputStream | ||||||
| import java.io.Closeable | import java.io.Closeable | ||||||
| import java.io.File | import java.io.File | ||||||
| import java.util.* | import java.util.* | ||||||
| import java.util.zip.ZipEntry | import java.util.zip.ZipEntry | ||||||
| import java.util.zip.ZipInputStream |  | ||||||
| import java.util.zip.ZipOutputStream | import java.util.zip.ZipOutputStream | ||||||
|  |  | ||||||
| class ItemsAdapter( | class ItemsAdapter( | ||||||
| @@ -547,13 +549,11 @@ class ItemsAdapter( | |||||||
|                     val fileDirItems = ArrayList<FileDirItem>() |                     val fileDirItems = ArrayList<FileDirItem>() | ||||||
|                     var entry = zipInputStream.nextEntry |                     var entry = zipInputStream.nextEntry | ||||||
|                     while (entry != null) { |                     while (entry != null) { | ||||||
|                         val currPath = if (entry.isDirectory) path else "${path.getParentPath().trimEnd('/')}/${entry.name}" |                         val currPath = if (entry.isDirectory) path else "${path.getParentPath().trimEnd('/')}/${entry.fileName}" | ||||||
|                         val fileDirItem = FileDirItem(currPath, entry.name, entry.isDirectory, 0, entry.size) |                         val fileDirItem = FileDirItem(currPath, entry.fileName, entry.isDirectory, 0, entry.uncompressedSize) | ||||||
|                         fileDirItems.add(fileDirItem) |                         fileDirItems.add(fileDirItem) | ||||||
|                         zipInputStream.closeEntry() |  | ||||||
|                         entry = zipInputStream.nextEntry |                         entry = zipInputStream.nextEntry | ||||||
|                     } |                     } | ||||||
|                     zipInputStream.closeEntry() |  | ||||||
|                     val destinationPath = fileDirItems.first().getParentPath().trimEnd('/') |                     val destinationPath = fileDirItems.first().getParentPath().trimEnd('/') | ||||||
|                     activity.runOnUiThread { |                     activity.runOnUiThread { | ||||||
|                         activity.checkConflicts(fileDirItems, destinationPath, 0, LinkedHashMap()) { |                         activity.checkConflicts(fileDirItems, destinationPath, 0, LinkedHashMap()) { | ||||||
| @@ -562,6 +562,12 @@ class ItemsAdapter( | |||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|  |                 } catch (zipException: ZipException) { | ||||||
|  |                     if (zipException.type == ZipException.Type.WRONG_PASSWORD) { | ||||||
|  |                         activity.showErrorToast(activity.getString(R.string.invalid_password)) | ||||||
|  |                     } else { | ||||||
|  |                         activity.showErrorToast(zipException) | ||||||
|  |                     } | ||||||
|                 } catch (exception: Exception) { |                 } catch (exception: Exception) { | ||||||
|                     activity.showErrorToast(exception) |                     activity.showErrorToast(exception) | ||||||
|                 } |                 } | ||||||
| @@ -579,7 +585,7 @@ class ItemsAdapter( | |||||||
|                     val newFolderName = zipFileName.subSequence(0, zipFileName.length - 4) |                     val newFolderName = zipFileName.subSequence(0, zipFileName.length - 4) | ||||||
|                     while (entry != null) { |                     while (entry != null) { | ||||||
|                         val parentPath = path.getParentPath() |                         val parentPath = path.getParentPath() | ||||||
|                         val newPath = "$parentPath/$newFolderName/${entry.name.trimEnd('/')}" |                         val newPath = "$parentPath/$newFolderName/${entry.fileName.trimEnd('/')}" | ||||||
|  |  | ||||||
|                         val resolution = getConflictResolution(conflictResolutions, newPath) |                         val resolution = getConflictResolution(conflictResolutions, newPath) | ||||||
|                         val doesPathExist = activity.getDoesFilePathExist(newPath) |                         val doesPathExist = activity.getDoesFilePathExist(newPath) | ||||||
| @@ -606,7 +612,6 @@ class ItemsAdapter( | |||||||
|                             extractEntry(newPath, entry, zipInputStream) |                             extractEntry(newPath, entry, zipInputStream) | ||||||
|                         } |                         } | ||||||
|  |  | ||||||
|                         zipInputStream.closeEntry() |  | ||||||
|                         entry = zipInputStream.nextEntry |                         entry = zipInputStream.nextEntry | ||||||
|                     } |                     } | ||||||
|                     callback(true) |                     callback(true) | ||||||
| @@ -618,7 +623,7 @@ class ItemsAdapter( | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun extractEntry(newPath: String, entry: ZipEntry, zipInputStream: ZipInputStream) { |     private fun extractEntry(newPath: String, entry: LocalFileHeader, zipInputStream: ZipInputStream) { | ||||||
|         if (entry.isDirectory) { |         if (entry.isDirectory) { | ||||||
|             if (!activity.createDirectorySync(newPath) && !activity.getDoesFilePathExist(newPath)) { |             if (!activity.createDirectorySync(newPath) && !activity.getDoesFilePathExist(newPath)) { | ||||||
|                 val error = String.format(activity.getString(R.string.could_not_create_file), newPath) |                 val error = String.format(activity.getString(R.string.could_not_create_file), newPath) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user