mirror of
https://github.com/mihonapp/mihon.git
synced 2025-08-01 04:15:53 +02:00
Compare commits
3 Commits
f768d99fe6
...
16f320d9b3
Author | SHA1 | Date | |
---|---|---|---|
16f320d9b3 | |||
24c38af92f | |||
b8986a558f |
@ -208,7 +208,6 @@ dependencies {
|
||||
// Disk
|
||||
implementation(libs.disklrucache)
|
||||
implementation(libs.unifile)
|
||||
implementation(libs.bundles.sevenzip)
|
||||
implementation(libs.bundles.archive)
|
||||
|
||||
// Preferences
|
||||
|
@ -7,15 +7,14 @@ import eu.kanade.tachiyomi.data.download.DownloadProvider
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||
import tachiyomi.core.common.i18n.stringResource
|
||||
import tachiyomi.core.common.storage.openReadOnlyChannel
|
||||
import tachiyomi.core.common.util.lang.withIOContext
|
||||
import tachiyomi.core.common.util.system.logcat
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import org.apache.commons.compress.archivers.dump.UnsupportedCompressionAlgorithmException
|
||||
import tachiyomi.core.common.i18n.stringResource
|
||||
import tachiyomi.core.common.storage.openReadOnlyChannel
|
||||
import tachiyomi.core.common.util.lang.launchUI
|
||||
import tachiyomi.core.common.util.lang.withIOContext
|
||||
import tachiyomi.core.common.util.system.logcat
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.source.model.StubSource
|
||||
import tachiyomi.i18n.MR
|
||||
@ -102,14 +101,13 @@ class ChapterLoader(
|
||||
when (format) {
|
||||
is Format.Directory -> DirectoryPageLoader(format.file)
|
||||
is Format.Zip -> ZipPageLoader(format.file.openReadOnlyChannel(context))
|
||||
is Format.SevenZip -> try {
|
||||
SevenZipPageLoader(format.file.openReadOnlyChannel(context)) {
|
||||
GlobalScope.launchUI {
|
||||
context.toast(context.stringResource(MR.strings.loader_7zip_slow_archives, it))
|
||||
}
|
||||
is Format.SevenZip -> SevenZipPageLoader(
|
||||
format.file.openReadOnlyChannel(context),
|
||||
Exception(context.stringResource(MR.strings.loader_7zip_unsupported)),
|
||||
) {
|
||||
GlobalScope.launchUI {
|
||||
context.toast(context.stringResource(MR.strings.loader_7zip_slow_method, it))
|
||||
}
|
||||
} catch (e: UnsupportedCompressionAlgorithmException) {
|
||||
error(context.stringResource(MR.strings.loader_7zip_ppmd_error))
|
||||
}
|
||||
is Format.Rar -> try {
|
||||
RarPageLoader(format.file.openInputStream())
|
||||
|
@ -4,6 +4,7 @@ import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||
import eu.kanade.tachiyomi.util.storage.SevenZUtil.getImages
|
||||
import org.apache.commons.compress.archivers.sevenz.SevenZFile
|
||||
import java.lang.Exception
|
||||
import java.nio.channels.FileChannel
|
||||
|
||||
/**
|
||||
@ -11,6 +12,7 @@ import java.nio.channels.FileChannel
|
||||
*/
|
||||
internal class SevenZipPageLoader(
|
||||
private val file: FileChannel,
|
||||
private val unsupportedCompressionMethodException: Exception? = null,
|
||||
private val notifySlowArchive: (method: String) -> Unit,
|
||||
) : PageLoader() {
|
||||
|
||||
@ -19,7 +21,7 @@ internal class SevenZipPageLoader(
|
||||
override var isLocal: Boolean = true
|
||||
|
||||
override suspend fun getPages(): List<ReaderPage> {
|
||||
return zip.getImages(notifySlowArchive)
|
||||
return zip.getImages(unsupportedCompressionMethodException, notifySlowArchive)
|
||||
.mapIndexed { i, entry ->
|
||||
ReaderPage(i).apply {
|
||||
stream = { entry.copyOf().inputStream() }
|
||||
|
@ -33,7 +33,6 @@ dependencies {
|
||||
|
||||
implementation(libs.unifile)
|
||||
implementation(libs.bundles.archive)
|
||||
implementation(libs.bundles.sevenzip)
|
||||
|
||||
api(kotlinx.coroutines.core)
|
||||
api(kotlinx.serialization.json)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package eu.kanade.tachiyomi.util.storage
|
||||
|
||||
import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder
|
||||
import org.apache.commons.compress.archivers.dump.UnsupportedCompressionAlgorithmException
|
||||
import org.apache.commons.compress.archivers.sevenz.SevenZFile
|
||||
import org.apache.commons.compress.archivers.sevenz.SevenZMethod
|
||||
import tachiyomi.core.common.util.system.ImageUtil
|
||||
@ -15,17 +14,20 @@ object SevenZUtil {
|
||||
SevenZMethod.COPY,
|
||||
)
|
||||
|
||||
fun SevenZFile.getImages(notifySlowArchives: (method: String) -> Unit): Sequence<ByteArray> {
|
||||
fun SevenZFile.getImages(
|
||||
unsupportedCompressionMethod: Exception? = null,
|
||||
notifySlowArchives: (method: String) -> Unit = {},
|
||||
): Sequence<ByteArray> {
|
||||
return generateSequence {
|
||||
try {
|
||||
getNextEntry()
|
||||
} catch (e: IOException) {
|
||||
throw UnsupportedCompressionAlgorithmException()
|
||||
}
|
||||
runCatching { getNextEntry() }.onFailure {
|
||||
if (it is IOException) {
|
||||
throw unsupportedCompressionMethod!!
|
||||
}
|
||||
}.getOrNull()
|
||||
}.filter { !it.isDirectory && ImageUtil.isImage(it.name) { getInputStream(it) } }
|
||||
.onEachIndexed { i, it ->
|
||||
.onEachIndexed { i, entry ->
|
||||
if (i > 0) return@onEachIndexed
|
||||
val method = it.contentMethods.first().method
|
||||
val method = entry.contentMethods.first().method
|
||||
if (method !in GoodMethods) notifySlowArchives(method.name)
|
||||
}
|
||||
.sortedWith { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) }
|
||||
|
@ -102,7 +102,7 @@ detekt-rules-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatt
|
||||
detekt-rules-compose = { module = "io.nlopez.compose.rules:detekt", version.ref = "detektCompose" }
|
||||
|
||||
[bundles]
|
||||
archive = ["common-compress", "junrar"]
|
||||
archive = ["common-compress", "junrar", "xz"]
|
||||
okhttp = ["okhttp-core", "okhttp-logging", "okhttp-brotli", "okhttp-dnsoverhttps"]
|
||||
js-engine = ["quickjs-android"]
|
||||
sqlite = ["sqlite-framework", "sqlite-ktx", "sqlite-android"]
|
||||
@ -111,5 +111,4 @@ shizuku = ["shizuku-api", "shizuku-provider"]
|
||||
sqldelight = ["sqldelight-android-driver", "sqldelight-coroutines", "sqldelight-android-paging"]
|
||||
voyager = ["voyager-navigator", "voyager-screenmodel", "voyager-tab-navigator", "voyager-transitions"]
|
||||
richtext = ["richtext-commonmark", "richtext-m3"]
|
||||
test = ["junit", "kotest-assertions", "mockk"]
|
||||
sevenzip = ["common-compress", "xz"]
|
||||
test = ["junit", "kotest-assertions", "mockk"]
|
@ -12,7 +12,6 @@ kotlin {
|
||||
api(projects.i18n)
|
||||
|
||||
implementation(libs.unifile)
|
||||
implementation(libs.bundles.sevenzip)
|
||||
implementation(libs.bundles.archive)
|
||||
}
|
||||
}
|
||||
|
@ -343,7 +343,7 @@ actual class LocalSource(
|
||||
}
|
||||
is Format.SevenZip -> {
|
||||
SevenZFile(format.file.openReadOnlyChannel(context)).use { archive ->
|
||||
val entry = archive.getImages {}.firstOrNull()
|
||||
val entry = archive.getImages().firstOrNull()
|
||||
entry?.let { coverManager.update(manga, it.inputStream()) }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user