mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
properly get the OutputStream at SD cards too
This commit is contained in:
@ -27,10 +27,7 @@ import com.simplemobiletools.filemanager.dialogs.CompressAsDialog
|
|||||||
import com.simplemobiletools.filemanager.extensions.config
|
import com.simplemobiletools.filemanager.extensions.config
|
||||||
import com.simplemobiletools.filemanager.extensions.isZipFile
|
import com.simplemobiletools.filemanager.extensions.isZipFile
|
||||||
import kotlinx.android.synthetic.main.list_item.view.*
|
import kotlinx.android.synthetic.main.list_item.view.*
|
||||||
import java.io.Closeable
|
import java.io.*
|
||||||
import java.io.File
|
|
||||||
import java.io.FileInputStream
|
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
@ -285,7 +282,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
|||||||
|
|
||||||
fun zipPaths(sourcePaths: List<String>, targetPath: String): Boolean {
|
fun zipPaths(sourcePaths: List<String>, targetPath: String): Boolean {
|
||||||
val queue = LinkedList<File>()
|
val queue = LinkedList<File>()
|
||||||
val out = FileOutputStream(File(targetPath))
|
val out = getFileOutputStream(targetPath)
|
||||||
val zout = ZipOutputStream(out)
|
val zout = ZipOutputStream(out)
|
||||||
var res: Closeable = out
|
var res: Closeable = out
|
||||||
|
|
||||||
@ -333,6 +330,23 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getFileOutputStream(targetPath: String): OutputStream {
|
||||||
|
val targetFile = File(targetPath)
|
||||||
|
|
||||||
|
return if (activity.needsStupidWritePermissions(targetPath)) {
|
||||||
|
val documentFile = activity.getFileDocument(targetFile.parent)
|
||||||
|
if (documentFile == null) {
|
||||||
|
val error = String.format(activity.getString(R.string.could_not_create_file), targetFile.parent)
|
||||||
|
throw IOException(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
val newDocument = documentFile.createFile("application/zip", File(targetPath).name)
|
||||||
|
activity.contentResolver.openOutputStream(newDocument!!.uri)
|
||||||
|
} else {
|
||||||
|
FileOutputStream(targetFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun selectAll() {
|
fun selectAll() {
|
||||||
val cnt = mItems.size
|
val cnt = mItems.size
|
||||||
for (i in 0 until cnt) {
|
for (i in 0 until cnt) {
|
||||||
|
Reference in New Issue
Block a user