Skip to content

Commit

Permalink
Fix #3192 (Do not crash: Loading module backup from Google Drive fail…
Browse files Browse the repository at this point in the history
…ed due to connectivity issue)
  • Loading branch information
tuomas2 committed Feb 1, 2024
1 parent a8157af commit a22f885
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ import net.bible.service.sword.mybible.addMyBibleBook
import net.bible.service.sword.mysword.addManuallyInstalledMySwordBooks
import net.bible.service.sword.mysword.addMySwordBook
import org.crosswire.jsword.book.Books
import org.crosswire.jsword.book.sword.GenBookBackend
import org.crosswire.jsword.book.sword.SwordGenBook
import java.io.BufferedInputStream
import java.io.FileNotFoundException
import java.io.InputStream
import java.util.UUID
import kotlin.coroutines.resume
Expand Down Expand Up @@ -287,10 +287,12 @@ class ZipHandler(
enum class InstallResult {ERROR, INVALID_MODULE, CANCEL, OK, IGNORE}
}

open class SqliteInstallError: Error()
class CantRead: SqliteInstallError()
class InvalidFile(val filename: String): SqliteInstallError()
class CantWrite: SqliteInstallError()
open class InstallZipError: Error()

class CantRead: InstallZipError()
class FileNotFound: InstallZipError()
class InvalidFile(val filename: String): InstallZipError()
class CantWrite: InstallZipError()

class InstallZip : ActivityBase() {
private lateinit var binding: ActivityInstallZipBinding
Expand Down Expand Up @@ -368,10 +370,11 @@ class InstallZip : ActivityBase() {
if (result.resultCode == Activity.RESULT_OK) {
try {
installFromFile(result.data!!.data!!)
} catch (e: SqliteInstallError) {
} catch (e: InstallZipError) {
Log.e(TAG, "Error occurred in installing module", e)
val msg = when(e) {
is CantRead -> getString(R.string.sqlite_cant_read)
is FileNotFound -> getString(R.string.sqlite_cant_read)
is InvalidFile -> getString(R.string.sqlite_invalid_file, e.filename)
is CantWrite -> getString(R.string.sqlite_cant_write)
else -> throw RuntimeException(e)
Expand Down Expand Up @@ -417,7 +420,11 @@ class InstallZip : ActivityBase() {
return installEpub(uri)
}

val inputStream = BufferedInputStream(contentResolver.openInputStream(uri))
val inputStream = try {
BufferedInputStream(contentResolver.openInputStream(uri))
} catch (e: FileNotFoundException) {
throw FileNotFound()
}
val fileTypeFromContent = determineFileType(inputStream)

if (fileTypeFromContent == BackupControl.AbDbFileType.ZIP)
Expand Down

0 comments on commit a22f885

Please sign in to comment.