do not lowercase deleted path urls + some safety checks

This commit is contained in:
tibbi 2016-11-19 22:59:44 +01:00
parent 7658651ebf
commit 732e703d88
7 changed files with 19 additions and 10 deletions

View file

@ -204,7 +204,11 @@ class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesLis
private fun deleteItem(file: File) {
if (needsStupidWritePermissions(file.absolutePath)) {
if (!isShowingPermDialog(file)) {
getFileDocument(file.absolutePath, mConfig.treeUri).delete()
val document = getFileDocument(file.absolutePath, mConfig.treeUri)
// double check we have the uri to the proper file path, not some parent folder
if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath()))
document.delete()
}
} else {
file.delete()

View file

@ -231,12 +231,17 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media
for (delPath in mToBeDeleted) {
val file = File(delPath)
if (file.exists() && file.isPhotoVideo()) {
if (needsStupidWritePermissions(delPath)) {
if (needsStupidWritePermissions(file.absolutePath)) {
if (isShowingPermDialog(file))
return
if (getFileDocument(delPath, mConfig.treeUri).delete()) {
wereFilesDeleted = true
val document = getFileDocument(file.absolutePath, mConfig.treeUri)
// double check we have the uri to the proper file path, not some parent folder
if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath())) {
if (document.delete()) {
wereFilesDeleted = true
}
}
} else {
if (file.delete())
@ -251,8 +256,8 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media
finish()
}
}
mToBeDeleted.clear()
}
mToBeDeleted.clear()
}
private val undoDeletion = View.OnClickListener {

View file

@ -343,7 +343,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun deleteDirectoryIfEmpty() {
val file = File(mDirectory)
if (file.isDirectory && file.listFiles().size == 0) {
if (file.isDirectory && file.listFiles().isEmpty()) {
file.delete()
}

View file

@ -187,7 +187,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
private fun prepareForDeleting() {
val selections = multiSelector.selectedPositions
val paths = ArrayList<String>(selections.size)
selections.forEach { paths.add(dirs[it].path.toLowerCase()) }
selections.forEach { paths.add(dirs[it].path) }
listener?.prepareForDeleting(paths)
}

View file

@ -137,7 +137,7 @@ class MediaAdapter(val activity: SimpleActivity, val media: MutableList<Medium>,
private fun prepareForDeleting() {
val selections = multiSelector.selectedPositions
val paths = ArrayList<String>(selections.size)
selections.forEach { paths.add(media[it].path.toLowerCase()) }
selections.forEach { paths.add(media[it].path) }
listener?.prepareForDeleting(paths)
}

View file

@ -65,7 +65,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
val newImageCnt = directory.mediaCnt + 1
directory.mediaCnt = newImageCnt
directory.addSize(file.length())
} else if (!mToBeDeleted.contains(parentDir.toLowerCase())) {
} else if (!mToBeDeleted.contains(parentDir)) {
var dirName = context.getHumanizedFilename(parentDir)
if (mConfig.getIsFolderHidden(parentDir)) {
dirName += " ${context.resources.getString(R.string.hidden)}"

View file

@ -51,7 +51,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
do {
val curPath = cursor.getString(pathIndex) ?: continue
if (curPath.matches(pattern.toRegex()) && !mToBeDeleted.contains(curPath.toLowerCase())) {
if (curPath.matches(pattern.toRegex()) && !mToBeDeleted.contains(curPath)) {
val file = File(curPath)
if (file.exists()) {
val dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_MODIFIED)