From f94c09a83c0888c8c73d764e1f37cd1afa0519db Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 24 Apr 2017 22:14:09 +0200 Subject: [PATCH] adding a couple more checks at saving edited file --- .../gallery/activities/ViewPagerActivity.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 7cbaf3ed0..990660a9c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -232,18 +232,26 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun saveImageAs() { val currPath = getCurrentPath() SaveAsDialog(this, currPath) { + val selectedFile = File(it) + val tmpFile = File(selectedFile.parent, "tmp_${it.getFilenameFromPath()}") try { - val selectedFile = File(it) - val tmpFile = File(selectedFile.parent, "tmp_${it.getFilenameFromPath()}") val bitmap = BitmapFactory.decodeFile(currPath) getFileOutputStream(tmpFile) { saveFile(tmpFile, bitmap, it) - renameFile(tmpFile, selectedFile) { } + if (needsStupidWritePermissions(selectedFile.absolutePath)) { + deleteFile(selectedFile) {} + } + + renameFile(tmpFile, selectedFile) { + deleteFile(tmpFile) {} + } } } catch (e: OutOfMemoryError) { toast(R.string.out_of_memory_error) + deleteFile(tmpFile) {} } catch (e: Exception) { toast(R.string.unknown_error_occurred) + deleteFile(tmpFile) {} } } }