From a74a689c9048cc67f4854678fbfefa361631a5e7 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 27 Nov 2023 22:21:40 -0500 Subject: [PATCH] Update UniFile Which has more correct nullability for some methods and case insensitivity for listFiles where possible. --- .../more/settings/screen/SettingsDataScreen.kt | 5 +++-- .../eu/kanade/tachiyomi/data/backup/BackupCreateJob.kt | 2 +- .../eu/kanade/tachiyomi/data/backup/BackupCreator.kt | 4 ++-- .../kanade/tachiyomi/data/download/DownloadProvider.kt | 4 ++-- .../eu/kanade/tachiyomi/data/download/Downloader.kt | 10 +++++----- .../kanade/tachiyomi/util/system/ContextExtensions.kt | 2 +- .../main/java/tachiyomi/core/util/system/ImageUtil.kt | 2 +- gradle/libs.versions.toml | 2 +- .../tachiyomi/source/local/image/LocalCoverManager.kt | 2 +- 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt index 341cf2bb5b..8d84859a3d 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt @@ -99,8 +99,9 @@ object SettingsDataScreen : SearchableSettings { context.contentResolver.takePersistableUriPermission(uri, flags) - val file = UniFile.fromUri(context, uri) - storageDirPref.set(file.uri.toString()) + UniFile.fromUri(context, uri)?.let { + storageDirPref.set(it.uri.toString()) + } Injekt.get().invalidateCache() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateJob.kt index 825d66c935..bc37b8c757 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateJob.kt @@ -58,7 +58,7 @@ class BackupCreateJob(private val context: Context, workerParams: WorkerParamete if (isAutoBackup) { backupPreferences.lastAutoBackupTimestamp().set(Date().time) } else { - notifier.showBackupComplete(UniFile.fromUri(context, location.toUri())) + notifier.showBackupComplete(UniFile.fromUri(context, location.toUri())!!) } Result.success() } catch (e: Exception) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreator.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreator.kt index a8cd3b773c..de907c91ea 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreator.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreator.kt @@ -95,14 +95,14 @@ class BackupCreator( val dir = UniFile.fromUri(context, uri) // Delete older backups - dir.listFiles { _, filename -> Backup.filenameRegex.matches(filename) } + dir?.listFiles { _, filename -> Backup.filenameRegex.matches(filename) } .orEmpty() .sortedByDescending { it.name } .drop(MAX_AUTO_BACKUPS - 1) .forEach { it.delete() } // Create new file to place backup - dir.createFile(Backup.getFilename()) + dir?.createFile(Backup.getFilename()) } else { UniFile.fromUri(context, uri) } 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 77dbfd2641..218661aa00 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 @@ -37,8 +37,8 @@ class DownloadProvider( internal fun getMangaDir(mangaTitle: String, source: Source): UniFile { try { return downloadsDir!! - .createDirectory(getSourceDirName(source)) - .createDirectory(getMangaDirName(mangaTitle)) + .createDirectory(getSourceDirName(source))!! + .createDirectory(getMangaDirName(mangaTitle))!! } catch (e: Throwable) { logcat(LogPriority.ERROR, e) { "Invalid download directory" } throw Exception(context.stringResource(MR.strings.invalid_location, downloadsDir ?: "")) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt index 74a90b3ba8..df45585ea3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt @@ -335,7 +335,7 @@ class Downloader( } val chapterDirname = provider.getChapterDirName(download.chapter.name, download.chapter.scanlator) - val tmpDir = mangaDir.createDirectory(chapterDirname + TMP_DIR_SUFFIX) + val tmpDir = mangaDir.createDirectory(chapterDirname + TMP_DIR_SUFFIX)!! try { // If the page list already exists, start from the file @@ -480,7 +480,7 @@ class Downloader( page.progress = 0 return flow { val response = source.getImage(page) - val file = tmpDir.createFile("$filename.tmp") + val file = tmpDir.createFile("$filename.tmp")!! try { response.body.source().saveTo(file.openOutputStream()) val extension = getImageExtension(response, file) @@ -512,7 +512,7 @@ class Downloader( * @param filename the filename of the image. */ private fun copyImageFromCache(cacheFile: File, tmpDir: UniFile, filename: String): UniFile { - val tmpFile = tmpDir.createFile("$filename.tmp") + val tmpFile = tmpDir.createFile("$filename.tmp")!! cacheFile.inputStream().use { input -> tmpFile.openOutputStream().use { output -> input.copyTo(output) @@ -603,7 +603,7 @@ class Downloader( dirname: String, tmpDir: UniFile, ) { - val zip = mangaDir.createFile("$dirname.cbz$TMP_DIR_SUFFIX") + val zip = mangaDir.createFile("$dirname.cbz$TMP_DIR_SUFFIX")!! ZipOutputStream(BufferedOutputStream(zip.openOutputStream())).use { zipOut -> zipOut.setMethod(ZipEntry.STORED) @@ -643,7 +643,7 @@ class Downloader( val comicInfo = getComicInfo(manga, chapter, chapterUrl, categories) // Remove the old file dir.findFile(COMIC_INFO_FILE)?.delete() - dir.createFile(COMIC_INFO_FILE).openOutputStream().use { + dir.createFile(COMIC_INFO_FILE)!!.openOutputStream().use { val comicInfoString = xml.encodeToString(ComicInfo.serializer(), comicInfo) it.write(comicInfoString.toByteArray()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index 14f6373664..5f91bfbacc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -165,7 +165,7 @@ fun Context.createReaderThemeContext(): Context { * @return document size of [uri] or null if size can't be obtained */ fun Context.getUriSize(uri: Uri): Long? { - return UniFile.fromUri(this, uri).length().takeIf { it >= 0 } + return UniFile.fromUri(this, uri)?.length()?.takeIf { it >= 0 } } /** diff --git a/core/src/main/java/tachiyomi/core/util/system/ImageUtil.kt b/core/src/main/java/tachiyomi/core/util/system/ImageUtil.kt index f72a963b7d..0aa7f9f59c 100644 --- a/core/src/main/java/tachiyomi/core/util/system/ImageUtil.kt +++ b/core/src/main/java/tachiyomi/core/util/system/ImageUtil.kt @@ -245,7 +245,7 @@ object ImageUtil { // Remove pre-existing split if exists (this split shouldn't exist under normal circumstances) tmpDir.findFile(splitImageName)?.delete() - val splitFile = tmpDir.createFile(splitImageName) + val splitFile = tmpDir.createFile(splitImageName)!! val region = Rect(0, splitData.topOffset, splitData.splitWidth, splitData.bottomOffset) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7c72d2304c..889ac693d3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -30,7 +30,7 @@ quickjs-android = "app.cash.quickjs:quickjs-android:0.9.2" jsoup = "org.jsoup:jsoup:1.16.2" disklrucache = "com.jakewharton:disklrucache:2.0.2" -unifile = "com.github.tachiyomiorg:unifile:17bec43" +unifile = "com.github.tachiyomiorg:unifile:7c257e1c64" junrar = "com.github.junrar:junrar:7.5.5" sqlite-framework = { module = "androidx.sqlite:sqlite-framework", version.ref = "sqlite" } diff --git a/source-local/src/androidMain/kotlin/tachiyomi/source/local/image/LocalCoverManager.kt b/source-local/src/androidMain/kotlin/tachiyomi/source/local/image/LocalCoverManager.kt index d793357f51..0f5a4c3435 100644 --- a/source-local/src/androidMain/kotlin/tachiyomi/source/local/image/LocalCoverManager.kt +++ b/source-local/src/androidMain/kotlin/tachiyomi/source/local/image/LocalCoverManager.kt @@ -34,7 +34,7 @@ actual class LocalCoverManager( return null } - val targetFile = find(manga.url) ?: directory.createFile(DEFAULT_COVER_NAME) + val targetFile = find(manga.url) ?: directory.createFile(DEFAULT_COVER_NAME)!! inputStream.use { input -> targetFile.openOutputStream().use { output ->