Add extensions for handling UniFile name/file extensions

This commit is contained in:
arkon 2023-11-26 15:56:43 -05:00
parent f365b53a0f
commit 46aeab9a7a
4 changed files with 16 additions and 4 deletions

View File

@ -40,6 +40,8 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.protobuf.ProtoBuf
import logcat.LogPriority
import tachiyomi.core.storage.extension
import tachiyomi.core.storage.nameWithoutExtension
import tachiyomi.core.util.lang.launchIO
import tachiyomi.core.util.lang.launchNonCancellable
import tachiyomi.core.util.system.logcat
@ -351,8 +353,7 @@ class DownloadCache(
// Folder of images
it.isDirectory -> it.name
// CBZ files
it.isFile && it.name?.endsWith(".cbz") == true ->
it.name!!.substringBeforeLast(".cbz")
it.isFile && it.extension == "cbz" -> it.nameWithoutExtension
// Anything else is irrelevant
else -> null
}

View File

@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.runBlocking
import logcat.LogPriority
import tachiyomi.core.i18n.stringResource
import tachiyomi.core.storage.extension
import tachiyomi.core.util.lang.launchIO
import tachiyomi.core.util.system.logcat
import tachiyomi.domain.category.interactor.GetCategories
@ -340,7 +341,7 @@ class DownloadManager(
.firstOrNull() ?: return
var newName = provider.getChapterDirName(newChapter.name, newChapter.scanlator)
if (oldDownload.isFile && oldDownload.name?.endsWith(".cbz") == true) {
if (oldDownload.isFile && oldDownload.extension == "cbz") {
newName += ".cbz"
}

View File

@ -43,6 +43,7 @@ import okhttp3.Response
import tachiyomi.core.i18n.stringResource
import tachiyomi.core.metadata.comicinfo.COMIC_INFO_FILE
import tachiyomi.core.metadata.comicinfo.ComicInfo
import tachiyomi.core.storage.extension
import tachiyomi.core.util.lang.launchIO
import tachiyomi.core.util.lang.launchNow
import tachiyomi.core.util.lang.withIOContext
@ -353,7 +354,7 @@ class Downloader(
// Delete all temporary (unfinished) files
tmpDir.listFiles()
?.filter { it.name!!.endsWith(".tmp") }
?.filter { it.extension == "tmp" }
?.forEach { it.delete() }
download.status = Download.State.DOWNLOADING

View File

@ -0,0 +1,9 @@
package tachiyomi.core.storage
import com.hippo.unifile.UniFile
val UniFile.extension: String?
get() = name?.substringAfterLast('.')
val UniFile.nameWithoutExtension: String?
get() = name?.substringBeforeLast('.')