mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-31 04:06:43 +01:00
do not lowercase deleted path urls + some safety checks
This commit is contained in:
parent
7658651ebf
commit
732e703d88
7 changed files with 19 additions and 10 deletions
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)}"
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue