From a8ca7b690fe56f8588d3fff9dbfef95062e6442f Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 20 Oct 2022 22:34:27 -0400 Subject: [PATCH] Avoid crashing if invalid download and backup location is set Fixes #8252 --- .../kanade/presentation/more/settings/screen/AboutScreen.kt | 2 +- .../more/settings/screen/SettingsBackupScreen.kt | 6 ++++-- .../more/settings/screen/SettingsDownloadScreen.kt | 4 ++-- .../eu/kanade/tachiyomi/data/download/DownloadProvider.kt | 2 +- i18n/src/main/res/values/strings.xml | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt index 5ec60104e..9724b8e65 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt @@ -205,7 +205,7 @@ class AboutScreen : Screen { BuildConfig.DEBUG -> { "Debug ${BuildConfig.COMMIT_SHA}".let { if (withBuildDate) { - "$it (${getFormattedBuildTime()}" + "$it (${getFormattedBuildTime()})" } else { it } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt index 9f540cb17..119cdd447 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt @@ -380,8 +380,10 @@ class SettingsBackupScreen : SearchableSettings { Preference.PreferenceItem.TextPreference( title = stringResource(R.string.pref_backup_directory), subtitle = remember(backupDir) { - UniFile.fromUri(context, backupDir.toUri()).filePath!! + "/automatic" - }, + (UniFile.fromUri(context, backupDir.toUri())?.filePath)?.let { + "$it/automatic" + } + } ?: stringResource(R.string.invalid_location, backupDir), onClick = { try { pickBackupLocation.launch(null) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt index cfd281846..e8a1e313f 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt @@ -102,8 +102,8 @@ class SettingsDownloadScreen : SearchableSettings { pref = currentDirPref, title = stringResource(R.string.pref_download_directory), subtitle = remember(currentDir) { - UniFile.fromUri(context, currentDir.toUri()).filePath!! - }, + UniFile.fromUri(context, currentDir.toUri())?.filePath + } ?: stringResource(R.string.invalid_location, currentDir), entries = mapOf( defaultDirPair, customDirEntryKey to stringResource(R.string.custom_dir), diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt index 5d5e2e894..1f97830de 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt @@ -57,7 +57,7 @@ class DownloadProvider(private val context: Context) { .createDirectory(getMangaDirName(mangaTitle)) } catch (e: Throwable) { logcat(LogPriority.ERROR, e) { "Invalid download directory" } - throw Exception(context.getString(R.string.invalid_download_dir)) + throw Exception(context.getString(R.string.invalid_location, downloadsDir)) } } diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index 11870a69c..08d6c4b08 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -422,6 +422,7 @@ Allow deleting bookmarked chapters Excluded categories Custom location + Invalid location: %s Disabled Last read chapter Second to last read chapter @@ -658,7 +659,6 @@ Error saving cover Error sharing cover Are you sure you want to delete the selected chapters? - Invalid download location Chapter settings Are you sure you want to save these settings as default? Also apply to all manga in my library