mirror of
https://github.com/mihonapp/mihon.git
synced 2025-02-07 15:54:58 +01:00
notify user of slow compression methods
This commit is contained in:
parent
9bfb34982e
commit
463e6f85f6
@ -7,9 +7,13 @@ 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 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.i18n.stringResource
|
||||
import tachiyomi.core.storage.UniFileTempFileManager
|
||||
import tachiyomi.core.util.lang.launchUI
|
||||
import tachiyomi.core.util.lang.withIOContext
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
@ -77,6 +81,7 @@ class ChapterLoader(
|
||||
/**
|
||||
* Returns the page loader to use for this [chapter].
|
||||
*/
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
private fun getPageLoader(chapter: ReaderChapter): PageLoader {
|
||||
val dbChapter = chapter.chapter
|
||||
val isDownloaded = downloadManager.isChapterDownloaded(
|
||||
@ -101,8 +106,13 @@ class ChapterLoader(
|
||||
is Format.Zip -> ZipPageLoader(tempFileManager.createTempFile(format.file))
|
||||
is Format.SevenZip -> try {
|
||||
SevenZipPageLoader(tempFileManager.createTempFile(format.file))
|
||||
{
|
||||
GlobalScope.launchUI{
|
||||
context.toast(context.stringResource(MR.strings.loader_7zip_slow_archives, it))
|
||||
}
|
||||
}
|
||||
} catch (e: UnsupportedCompressionAlgorithmException) {
|
||||
error(context.stringResource(MR.strings.loader_ppmd_error))
|
||||
error(context.stringResource(MR.strings.loader_7zip_ppmd_error))
|
||||
}
|
||||
is Format.Rar -> try {
|
||||
RarPageLoader(tempFileManager.createTempFile(format.file))
|
||||
|
@ -9,14 +9,17 @@ import java.io.File
|
||||
/**
|
||||
* Loader used to load a chapter from a .7z or .cb7 file.
|
||||
*/
|
||||
internal class SevenZipPageLoader(file: File) : PageLoader() {
|
||||
internal class SevenZipPageLoader(
|
||||
private val file: File,
|
||||
private val notifySlowArchive: (method: String) -> Unit
|
||||
) : PageLoader() {
|
||||
|
||||
private val zip by lazy { SevenZFile(file) }
|
||||
|
||||
override var isLocal: Boolean = true
|
||||
|
||||
override suspend fun getPages(): List<ReaderPage> {
|
||||
return zip.getImages()
|
||||
return zip.getImages(notifySlowArchive)
|
||||
.mapIndexed { i, entry ->
|
||||
ReaderPage(i).apply {
|
||||
stream = { entry.copyOf().inputStream() }
|
||||
|
@ -3,12 +3,19 @@ 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.util.system.ImageUtil
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
object SevenZUtil {
|
||||
fun SevenZFile.getImages(): Sequence<ByteArray> {
|
||||
private val GoodMethods = arrayOf(
|
||||
SevenZMethod.LZMA2,
|
||||
SevenZMethod.DEFLATE,
|
||||
SevenZMethod.COPY,
|
||||
)
|
||||
|
||||
fun SevenZFile.getImages(notifySlowArchives: (method: String) -> Unit): Sequence<ByteArray> {
|
||||
return generateSequence {
|
||||
try {
|
||||
getNextEntry()
|
||||
@ -16,6 +23,11 @@ object SevenZUtil {
|
||||
throw UnsupportedCompressionAlgorithmException()
|
||||
}
|
||||
}.filter { !it.isDirectory && ImageUtil.isImage(it.name) { getInputStream(it) } }
|
||||
.onEachIndexed { i, it ->
|
||||
if (i > 0) return@onEachIndexed
|
||||
val method = it.contentMethods.first().method
|
||||
if(method !in GoodMethods) notifySlowArchives(method.name)
|
||||
}
|
||||
.sortedWith { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) }
|
||||
.map(::getInputStream)
|
||||
.map { it.use(InputStream::readBytes) } // ByteArray
|
||||
|
@ -776,7 +776,8 @@
|
||||
<string name="page_list_empty_error">No pages found</string>
|
||||
<string name="loader_not_implemented_error">Source not found</string>
|
||||
<string name="loader_rar5_error">RARv5 format is not supported</string>
|
||||
<string name="loader_ppmd_error">PPMd compression is not supported</string>
|
||||
<string name="loader_7zip_ppmd_error">PPMd compression is not supported</string>
|
||||
<string name="loader_7zip_slow_archives">%s Archive, expect slow loading times.</string>
|
||||
|
||||
<!-- Updates -->
|
||||
<string name="updating_library">Updating library</string>
|
||||
|
@ -344,7 +344,7 @@ actual class LocalSource(
|
||||
}
|
||||
is Format.SevenZip -> {
|
||||
SevenZFile(tempFileManager.createTempFile(format.file)).use { archive ->
|
||||
val entry = archive.getImages().firstOrNull()
|
||||
val entry = archive.getImages {} .firstOrNull()
|
||||
|
||||
entry?.let { coverManager.update(manga, it.inputStream()) }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user