Update UniFile

Which has more correct nullability for some methods and case insensitivity for listFiles where possible.
This commit is contained in:
arkon 2023-11-27 22:21:40 -05:00
parent d85a76484c
commit a74a689c90
9 changed files with 17 additions and 16 deletions

View File

@ -99,8 +99,9 @@ object SettingsDataScreen : SearchableSettings {
context.contentResolver.takePersistableUriPermission(uri, flags) context.contentResolver.takePersistableUriPermission(uri, flags)
val file = UniFile.fromUri(context, uri) UniFile.fromUri(context, uri)?.let {
storageDirPref.set(file.uri.toString()) storageDirPref.set(it.uri.toString())
}
Injekt.get<DownloadCache>().invalidateCache() Injekt.get<DownloadCache>().invalidateCache()
} }
} }

View File

@ -58,7 +58,7 @@ class BackupCreateJob(private val context: Context, workerParams: WorkerParamete
if (isAutoBackup) { if (isAutoBackup) {
backupPreferences.lastAutoBackupTimestamp().set(Date().time) backupPreferences.lastAutoBackupTimestamp().set(Date().time)
} else { } else {
notifier.showBackupComplete(UniFile.fromUri(context, location.toUri())) notifier.showBackupComplete(UniFile.fromUri(context, location.toUri())!!)
} }
Result.success() Result.success()
} catch (e: Exception) { } catch (e: Exception) {

View File

@ -95,14 +95,14 @@ class BackupCreator(
val dir = UniFile.fromUri(context, uri) val dir = UniFile.fromUri(context, uri)
// Delete older backups // Delete older backups
dir.listFiles { _, filename -> Backup.filenameRegex.matches(filename) } dir?.listFiles { _, filename -> Backup.filenameRegex.matches(filename) }
.orEmpty() .orEmpty()
.sortedByDescending { it.name } .sortedByDescending { it.name }
.drop(MAX_AUTO_BACKUPS - 1) .drop(MAX_AUTO_BACKUPS - 1)
.forEach { it.delete() } .forEach { it.delete() }
// Create new file to place backup // Create new file to place backup
dir.createFile(Backup.getFilename()) dir?.createFile(Backup.getFilename())
} else { } else {
UniFile.fromUri(context, uri) UniFile.fromUri(context, uri)
} }

View File

@ -37,8 +37,8 @@ class DownloadProvider(
internal fun getMangaDir(mangaTitle: String, source: Source): UniFile { internal fun getMangaDir(mangaTitle: String, source: Source): UniFile {
try { try {
return downloadsDir!! return downloadsDir!!
.createDirectory(getSourceDirName(source)) .createDirectory(getSourceDirName(source))!!
.createDirectory(getMangaDirName(mangaTitle)) .createDirectory(getMangaDirName(mangaTitle))!!
} catch (e: Throwable) { } catch (e: Throwable) {
logcat(LogPriority.ERROR, e) { "Invalid download directory" } logcat(LogPriority.ERROR, e) { "Invalid download directory" }
throw Exception(context.stringResource(MR.strings.invalid_location, downloadsDir ?: "")) throw Exception(context.stringResource(MR.strings.invalid_location, downloadsDir ?: ""))

View File

@ -335,7 +335,7 @@ class Downloader(
} }
val chapterDirname = provider.getChapterDirName(download.chapter.name, download.chapter.scanlator) 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 { try {
// If the page list already exists, start from the file // If the page list already exists, start from the file
@ -480,7 +480,7 @@ class Downloader(
page.progress = 0 page.progress = 0
return flow { return flow {
val response = source.getImage(page) val response = source.getImage(page)
val file = tmpDir.createFile("$filename.tmp") val file = tmpDir.createFile("$filename.tmp")!!
try { try {
response.body.source().saveTo(file.openOutputStream()) response.body.source().saveTo(file.openOutputStream())
val extension = getImageExtension(response, file) val extension = getImageExtension(response, file)
@ -512,7 +512,7 @@ class Downloader(
* @param filename the filename of the image. * @param filename the filename of the image.
*/ */
private fun copyImageFromCache(cacheFile: File, tmpDir: UniFile, filename: String): UniFile { 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 -> cacheFile.inputStream().use { input ->
tmpFile.openOutputStream().use { output -> tmpFile.openOutputStream().use { output ->
input.copyTo(output) input.copyTo(output)
@ -603,7 +603,7 @@ class Downloader(
dirname: String, dirname: String,
tmpDir: UniFile, 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 -> ZipOutputStream(BufferedOutputStream(zip.openOutputStream())).use { zipOut ->
zipOut.setMethod(ZipEntry.STORED) zipOut.setMethod(ZipEntry.STORED)
@ -643,7 +643,7 @@ class Downloader(
val comicInfo = getComicInfo(manga, chapter, chapterUrl, categories) val comicInfo = getComicInfo(manga, chapter, chapterUrl, categories)
// Remove the old file // Remove the old file
dir.findFile(COMIC_INFO_FILE)?.delete() 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) val comicInfoString = xml.encodeToString(ComicInfo.serializer(), comicInfo)
it.write(comicInfoString.toByteArray()) it.write(comicInfoString.toByteArray())
} }

View File

@ -165,7 +165,7 @@ fun Context.createReaderThemeContext(): Context {
* @return document size of [uri] or null if size can't be obtained * @return document size of [uri] or null if size can't be obtained
*/ */
fun Context.getUriSize(uri: Uri): Long? { fun Context.getUriSize(uri: Uri): Long? {
return UniFile.fromUri(this, uri).length().takeIf { it >= 0 } return UniFile.fromUri(this, uri)?.length()?.takeIf { it >= 0 }
} }
/** /**

View File

@ -245,7 +245,7 @@ object ImageUtil {
// Remove pre-existing split if exists (this split shouldn't exist under normal circumstances) // Remove pre-existing split if exists (this split shouldn't exist under normal circumstances)
tmpDir.findFile(splitImageName)?.delete() tmpDir.findFile(splitImageName)?.delete()
val splitFile = tmpDir.createFile(splitImageName) val splitFile = tmpDir.createFile(splitImageName)!!
val region = Rect(0, splitData.topOffset, splitData.splitWidth, splitData.bottomOffset) val region = Rect(0, splitData.topOffset, splitData.splitWidth, splitData.bottomOffset)

View File

@ -30,7 +30,7 @@ quickjs-android = "app.cash.quickjs:quickjs-android:0.9.2"
jsoup = "org.jsoup:jsoup:1.16.2" jsoup = "org.jsoup:jsoup:1.16.2"
disklrucache = "com.jakewharton:disklrucache:2.0.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" junrar = "com.github.junrar:junrar:7.5.5"
sqlite-framework = { module = "androidx.sqlite:sqlite-framework", version.ref = "sqlite" } sqlite-framework = { module = "androidx.sqlite:sqlite-framework", version.ref = "sqlite" }

View File

@ -34,7 +34,7 @@ actual class LocalCoverManager(
return null 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 -> inputStream.use { input ->
targetFile.openOutputStream().use { output -> targetFile.openOutputStream().use { output ->