Albirew/tachiyomi
Archivé
1
0
Bifurcation 0

Avoid crashing if picture can't be saved (related to #6905)

Cette révision appartient à :
arkon 2022-04-13 18:45:49 -04:00
Parent d443245d66
révision 5da2c82f47
2 fichiers modifiés avec 14 ajouts et 10 suppressions

Voir le fichier

@ -13,6 +13,8 @@ import eu.kanade.tachiyomi.util.storage.DiskUtil
import eu.kanade.tachiyomi.util.storage.cacheImageDir import eu.kanade.tachiyomi.util.storage.cacheImageDir
import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.ImageUtil import eu.kanade.tachiyomi.util.system.ImageUtil
import eu.kanade.tachiyomi.util.system.logcat
import logcat.LogPriority
import okio.IOException import okio.IOException
import java.io.ByteArrayInputStream import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
@ -30,11 +32,7 @@ class ImageSaver(
val type = ImageUtil.findImageType(data) ?: throw Exception("Not an image") val type = ImageUtil.findImageType(data) ?: throw Exception("Not an image")
val filename = DiskUtil.buildValidFilename("${image.name}.${type.extension}") val filename = DiskUtil.buildValidFilename("${image.name}.${type.extension}")
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || image.location !is Location.Pictures) {
return save(data(), image.location.directory(context), filename)
}
if (image.location !is Location.Pictures) {
return save(data(), image.location.directory(context), filename) return save(data(), image.location.directory(context), filename)
} }
@ -54,13 +52,18 @@ class ImageSaver(
val picture = context.contentResolver.insert( val picture = context.contentResolver.insert(
pictureDir, pictureDir,
contentValues, contentValues,
) ?: throw IOException("Couldn't create file") ) ?: throw IOException(context.getString(R.string.error_saving_picture))
data().use { input -> try {
@Suppress("BlockingMethodInNonBlockingContext") data().use { input ->
context.contentResolver.openOutputStream(picture, "w").use { output -> @Suppress("BlockingMethodInNonBlockingContext")
input.copyTo(output!!) context.contentResolver.openOutputStream(picture, "w").use { output ->
input.copyTo(output!!)
}
} }
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
throw IOException(context.getString(R.string.error_saving_picture))
} }
DiskUtil.scanMedia(context, picture) DiskUtil.scanMedia(context, picture)

Voir le fichier

@ -669,6 +669,7 @@
<!-- Image notifier --> <!-- Image notifier -->
<string name="picture_saved">Picture saved</string> <string name="picture_saved">Picture saved</string>
<string name="error_saving_picture">Error saving picture</string>
<!-- Reader activity --> <!-- Reader activity -->
<string name="custom_filter">Custom filter</string> <string name="custom_filter">Custom filter</string>