mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-01-28 17:29:36 +01:00
add handling for root file copy
This commit is contained in:
parent
20183d448d
commit
7e1982b3f1
@ -252,8 +252,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons)
|
FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons)
|
||||||
)
|
)
|
||||||
|
|
||||||
startAboutActivity(R.string.app_name, LICENSE_MULTISELECT or LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT,
|
startAboutActivity(R.string.app_name, LICENSE_MULTISELECT or LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT, BuildConfig.VERSION_NAME, faqItems)
|
||||||
BuildConfig.VERSION_NAME, faqItems)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
|
@ -28,8 +28,8 @@ import com.simplemobiletools.filemanager.R
|
|||||||
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||||
import com.simplemobiletools.filemanager.dialogs.CompressAsDialog
|
import com.simplemobiletools.filemanager.dialogs.CompressAsDialog
|
||||||
import com.simplemobiletools.filemanager.extensions.*
|
import com.simplemobiletools.filemanager.extensions.*
|
||||||
|
import com.simplemobiletools.filemanager.helpers.RootHelpers
|
||||||
import com.simplemobiletools.filemanager.interfaces.ItemOperationsListener
|
import com.simplemobiletools.filemanager.interfaces.ItemOperationsListener
|
||||||
import com.stericson.RootTools.RootTools
|
|
||||||
import kotlinx.android.synthetic.main.list_item.view.*
|
import kotlinx.android.synthetic.main.list_item.view.*
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -189,12 +189,14 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
|||||||
|
|
||||||
private fun copyMoveTo(isCopyOperation: Boolean) {
|
private fun copyMoveTo(isCopyOperation: Boolean) {
|
||||||
val files = ArrayList<FileDirItem>()
|
val files = ArrayList<FileDirItem>()
|
||||||
selectedPositions.forEach { files.add(fileDirItems[it]) }
|
selectedPositions.forEach {
|
||||||
|
files.add(fileDirItems[it])
|
||||||
|
}
|
||||||
|
|
||||||
val firstFile = files[0]
|
val firstFile = files[0]
|
||||||
val source = if (firstFile.isDirectory) firstFile.path else firstFile.getParentPath()
|
val source = if (firstFile.isDirectory) firstFile.path else firstFile.getParentPath()
|
||||||
FilePickerDialog(activity, source, false, activity.config.shouldShowHidden, true) {
|
FilePickerDialog(activity, source, false, activity.config.shouldShowHidden, true) {
|
||||||
if (activity.isPathOnRoot(it)) {
|
if (activity.isPathOnRoot(it) || activity.isPathOnRoot(firstFile.path)) {
|
||||||
copyRootItems(files, it)
|
copyRootItems(files, it)
|
||||||
} else {
|
} else {
|
||||||
activity.copyMoveFilesTo(files, source, it, isCopyOperation, false, activity.config.shouldShowHidden) {
|
activity.copyMoveFilesTo(files, source, it, isCopyOperation, false, activity.config.shouldShowHidden) {
|
||||||
@ -208,22 +210,18 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
|||||||
private fun copyRootItems(files: ArrayList<FileDirItem>, destinationPath: String) {
|
private fun copyRootItems(files: ArrayList<FileDirItem>, destinationPath: String) {
|
||||||
activity.toast(R.string.copying)
|
activity.toast(R.string.copying)
|
||||||
Thread {
|
Thread {
|
||||||
var fileCnt = files.count()
|
val fileCnt = files.size
|
||||||
files.forEach {
|
RootHelpers(activity).copyFiles(files, destinationPath) {
|
||||||
if (RootTools.copyFile(it.path, destinationPath, false, true)) {
|
when (it) {
|
||||||
fileCnt--
|
fileCnt -> activity.toast(R.string.copying_success)
|
||||||
|
0 -> activity.toast(R.string.copy_failed)
|
||||||
|
else -> activity.toast(R.string.copying_success_partial)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
when {
|
activity.runOnUiThread {
|
||||||
fileCnt <= 0 -> activity.toast(R.string.copying_success)
|
listener?.refreshItems()
|
||||||
fileCnt == files.count() -> activity.toast(R.string.copy_failed)
|
finishActMode()
|
||||||
else -> activity.toast(R.string.copying_success_partial)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
activity.runOnUiThread {
|
|
||||||
listener?.refreshItems()
|
|
||||||
finishActMode()
|
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
@ -255,4 +255,23 @@ class RootHelpers(val activity: Activity) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun copyFiles(fileDirItems: ArrayList<FileDirItem>, destination: String, successes: Int = 0, callback: (Int) -> Unit) {
|
||||||
|
val fileDirItem = fileDirItems.first()
|
||||||
|
val mainCommand = if (fileDirItem.isDirectory) "cp -R" else "cp"
|
||||||
|
val cmd = "$mainCommand \"${fileDirItem.path}\" \"$destination\""
|
||||||
|
val command = object : Command(0, cmd) {
|
||||||
|
override fun commandCompleted(id: Int, exitcode: Int) {
|
||||||
|
val newSuccesses = successes + (if (exitcode == 0) 1 else 0)
|
||||||
|
if (fileDirItems.size == 1) {
|
||||||
|
callback(newSuccesses)
|
||||||
|
} else {
|
||||||
|
fileDirItems.removeAt(0)
|
||||||
|
copyFiles(fileDirItems, destination, newSuccesses, callback)
|
||||||
|
}
|
||||||
|
super.commandCompleted(id, exitcode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
runCommand(command)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user