mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-04-15 18:57:23 +02:00
implement root file/folder deleting
This commit is contained in:
parent
638d3dc070
commit
8f336838f5
@ -164,8 +164,8 @@ class RootHelpers(val activity: Activity) {
|
|||||||
// inspired by Amaze File Manager
|
// inspired by Amaze File Manager
|
||||||
private fun tryMountAsRW(path: String, callback: (mountPoint: String?) -> Unit) {
|
private fun tryMountAsRW(path: String, callback: (mountPoint: String?) -> Unit) {
|
||||||
val mountPoints = ArrayList<String>()
|
val mountPoints = ArrayList<String>()
|
||||||
|
val cmd = "mount"
|
||||||
val command = object : Command(0, "mount") {
|
val command = object : Command(0, cmd) {
|
||||||
override fun commandOutput(id: Int, line: String) {
|
override fun commandOutput(id: Int, line: String) {
|
||||||
mountPoints.add(line)
|
mountPoints.add(line)
|
||||||
super.commandOutput(id, line)
|
super.commandOutput(id, line)
|
||||||
@ -203,8 +203,8 @@ class RootHelpers(val activity: Activity) {
|
|||||||
runCommand(command)
|
runCommand(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun mountAsRW(commandString: String, callback: (mountPoint: String) -> Unit) {
|
private fun mountAsRW(cmd: String, callback: (mountPoint: String) -> Unit) {
|
||||||
val command = object : Command(0, commandString) {
|
val command = object : Command(0, cmd) {
|
||||||
override fun commandOutput(id: Int, line: String) {
|
override fun commandOutput(id: Int, line: String) {
|
||||||
callback(line)
|
callback(line)
|
||||||
super.commandOutput(id, line)
|
super.commandOutput(id, line)
|
||||||
@ -215,6 +215,19 @@ class RootHelpers(val activity: Activity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun deleteFiles(fileDirItems: ArrayList<FileDirItem>) {
|
fun deleteFiles(fileDirItems: ArrayList<FileDirItem>) {
|
||||||
|
tryMountAsRW(fileDirItems.first().path) {
|
||||||
|
fileDirItems.forEach {
|
||||||
|
val targetPath = it.path.trim('/')
|
||||||
|
if (targetPath.isEmpty()) {
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
|
||||||
|
val mainCommand = if (it.isDirectory) "rm -rf" else "rm"
|
||||||
|
val cmd = "$mainCommand \"/$targetPath\""
|
||||||
|
val command = object : Command(0, cmd) {}
|
||||||
|
|
||||||
|
runCommand(command)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user