forked from hardcoresushi/DroidFS
Delete file & folder on wipe
This commit is contained in:
parent
5cc9abfd76
commit
c2c1e4b1e9
@ -425,14 +425,14 @@ open class BaseExplorerActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun importDirectory(sourceUri: Uri, callback: (String?, List<Uri>) -> Unit) {
|
fun importDirectory(sourceUri: Uri, callback: (String?, List<Uri>, DocumentFile) -> Unit) {
|
||||||
val tree = DocumentFile.fromTreeUri(this, sourceUri)!! //non-null after Lollipop
|
val tree = DocumentFile.fromTreeUri(this, sourceUri)!! //non-null after Lollipop
|
||||||
val operation = OperationFile.fromExplorerElement(ExplorerElement(tree.name!!, 0, parentPath = currentDirectoryPath))
|
val operation = OperationFile.fromExplorerElement(ExplorerElement(tree.name!!, 0, parentPath = currentDirectoryPath))
|
||||||
checkPathOverwrite(arrayListOf(operation), currentDirectoryPath) { checkedOperation ->
|
checkPathOverwrite(arrayListOf(operation), currentDirectoryPath) { checkedOperation ->
|
||||||
checkedOperation?.let {
|
checkedOperation?.let {
|
||||||
fileOperationService.importDirectory(checkedOperation[0].dstPath!!, tree) { failedItem, uris ->
|
fileOperationService.importDirectory(checkedOperation[0].dstPath!!, tree) { failedItem, uris ->
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
callback(failedItem, uris)
|
callback(failedItem, uris, tree)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import android.view.WindowManager
|
|||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import sushi.hardcore.droidfs.CameraActivity
|
import sushi.hardcore.droidfs.CameraActivity
|
||||||
import sushi.hardcore.droidfs.GocryptfsVolume
|
import sushi.hardcore.droidfs.GocryptfsVolume
|
||||||
import sushi.hardcore.droidfs.OpenActivity
|
import sushi.hardcore.droidfs.OpenActivity
|
||||||
@ -121,7 +122,7 @@ class ExplorerActivity : BaseExplorerActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onImportComplete(failedItem: String?, uris: List<Uri>) {
|
private fun onImportComplete(failedItem: String?, urisToWipe: List<Uri>, rootFile: DocumentFile? = null) {
|
||||||
if (failedItem == null){
|
if (failedItem == null){
|
||||||
ColoredAlertDialogBuilder(this)
|
ColoredAlertDialogBuilder(this)
|
||||||
.setTitle(R.string.success_import)
|
.setTitle(R.string.success_import)
|
||||||
@ -130,9 +131,10 @@ class ExplorerActivity : BaseExplorerActivity() {
|
|||||||
${getString(R.string.ask_for_wipe)}
|
${getString(R.string.ask_for_wipe)}
|
||||||
""".trimIndent())
|
""".trimIndent())
|
||||||
.setPositiveButton(R.string.yes) { _, _ ->
|
.setPositiveButton(R.string.yes) { _, _ ->
|
||||||
fileOperationService.wipeUris(uris) { errorMsg ->
|
fileOperationService.wipeUris(urisToWipe) { errorMsg ->
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
if (errorMsg == null){
|
if (errorMsg == null){
|
||||||
|
rootFile?.delete()
|
||||||
Toast.makeText(this, R.string.wipe_successful, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.wipe_successful, Toast.LENGTH_SHORT).show()
|
||||||
} else {
|
} else {
|
||||||
ColoredAlertDialogBuilder(this)
|
ColoredAlertDialogBuilder(this)
|
||||||
|
@ -288,15 +288,17 @@ class FileOperationService : Service() {
|
|||||||
return@Thread
|
return@Thread
|
||||||
}
|
}
|
||||||
|
|
||||||
updateNotificationProgress(notification, 0, dstDirs.size)
|
|
||||||
|
|
||||||
// create destination folders so the new files can use them
|
// create destination folders so the new files can use them
|
||||||
for (mkdir in dstDirs) {
|
for (dir in dstDirs) {
|
||||||
if (notifications[notification.notificationId]!!) {
|
if (notifications[notification.notificationId]!!) {
|
||||||
cancelNotification(notification)
|
cancelNotification(notification)
|
||||||
return@Thread
|
return@Thread
|
||||||
}
|
}
|
||||||
gocryptfsVolume.mkdir(mkdir)
|
if (!gocryptfsVolume.mkdir(dir)) {
|
||||||
|
cancelNotification(notification)
|
||||||
|
callback(dir, srcUris)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
importFilesFromUris(dstFiles, srcUris, notification) { failedItem ->
|
importFilesFromUris(dstFiles, srcUris, notification) { failedItem ->
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.OpenableColumns
|
import android.provider.OpenableColumns
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import sushi.hardcore.droidfs.ConstValues
|
import sushi.hardcore.droidfs.ConstValues
|
||||||
import sushi.hardcore.droidfs.R
|
import sushi.hardcore.droidfs.R
|
||||||
import java.io.*
|
import java.io.*
|
||||||
@ -23,26 +24,28 @@ object Wiper {
|
|||||||
val size = cursor.getLong(sizeIndex)
|
val size = cursor.getLong(sizeIndex)
|
||||||
cursor.close()
|
cursor.close()
|
||||||
try {
|
try {
|
||||||
var os = context.contentResolver.openOutputStream(uri)
|
var os = context.contentResolver.openOutputStream(uri)!!
|
||||||
val buff = ByteArray(buff_size)
|
val buff = ByteArray(buff_size)
|
||||||
Arrays.fill(buff, 0.toByte())
|
Arrays.fill(buff, 0.toByte())
|
||||||
val writes = ceil(size.toDouble() / buff_size).toInt()
|
val writes = ceil(size.toDouble() / buff_size).toInt()
|
||||||
for (i in 0 until ConstValues.wipe_passes) {
|
for (i in 0 until ConstValues.wipe_passes) {
|
||||||
for (j in 0 until writes) {
|
for (j in 0 until writes) {
|
||||||
os!!.write(buff)
|
os.write(buff)
|
||||||
}
|
}
|
||||||
if (i < ConstValues.wipe_passes - 1) {
|
if (i < ConstValues.wipe_passes - 1) {
|
||||||
//reopening to flush and seek
|
//reopening to flush and seek
|
||||||
os!!.close()
|
os.close()
|
||||||
os = context.contentResolver.openOutputStream(uri)
|
os = context.contentResolver.openOutputStream(uri)!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
context.contentResolver.delete(uri, null, null)
|
context.contentResolver.delete(uri, null, null)
|
||||||
} catch (e: UnsupportedOperationException){
|
} catch (e: UnsupportedOperationException){
|
||||||
|
if (DocumentFile.fromSingleUri(context, uri)?.delete() != true) {
|
||||||
(os as FileOutputStream).channel.truncate(0) //truncate to 0 if cannot delete
|
(os as FileOutputStream).channel.truncate(0) //truncate to 0 if cannot delete
|
||||||
}
|
}
|
||||||
os!!.close()
|
}
|
||||||
|
os.close()
|
||||||
return null
|
return null
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
return e.message
|
return e.message
|
||||||
|
Loading…
Reference in New Issue
Block a user