mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-28 03:57:50 +02:00
Refactor archive support with libarchive (#949)
* Refactor archive support with libarchive * Revert string resource changs * Only mark archive formats as supported Comic book archives should not be compressed. * Fixup * Remove epub from archive format list * Move to mihon package * Format * Cleanup
This commit is contained in:
@ -5,9 +5,9 @@ import tachiyomi.core.common.storage.extension
|
||||
|
||||
object Archive {
|
||||
|
||||
private val SUPPORTED_ARCHIVE_TYPES = listOf("zip", "cbz", "rar", "cbr", "epub")
|
||||
private val SUPPORTED_ARCHIVE_TYPES = listOf("zip", "cbz", "rar", "cbr", "7z", "cb7", "tar", "cbt")
|
||||
|
||||
fun isSupported(file: UniFile): Boolean {
|
||||
return file.extension in SUPPORTED_ARCHIVE_TYPES
|
||||
return file.extension?.lowercase() in SUPPORTED_ARCHIVE_TYPES
|
||||
}
|
||||
}
|
||||
|
@ -2,25 +2,22 @@ package tachiyomi.source.local.io
|
||||
|
||||
import com.hippo.unifile.UniFile
|
||||
import tachiyomi.core.common.storage.extension
|
||||
import tachiyomi.source.local.io.Archive.isSupported as isArchiveSupported
|
||||
|
||||
sealed interface Format {
|
||||
data class Directory(val file: UniFile) : Format
|
||||
data class Zip(val file: UniFile) : Format
|
||||
data class Rar(val file: UniFile) : Format
|
||||
data class Archive(val file: UniFile) : Format
|
||||
data class Epub(val file: UniFile) : Format
|
||||
|
||||
class UnknownFormatException : Exception()
|
||||
|
||||
companion object {
|
||||
|
||||
fun valueOf(file: UniFile) = with(file) {
|
||||
when {
|
||||
isDirectory -> Directory(this)
|
||||
extension.equals("zip", true) || extension.equals("cbz", true) -> Zip(this)
|
||||
extension.equals("rar", true) || extension.equals("cbr", true) -> Rar(this)
|
||||
extension.equals("epub", true) -> Epub(this)
|
||||
else -> throw UnknownFormatException()
|
||||
}
|
||||
fun valueOf(file: UniFile) = when {
|
||||
file.isDirectory -> Directory(file)
|
||||
file.extension.equals("epub", true) -> Epub(file)
|
||||
isArchiveSupported(file) -> Archive(file)
|
||||
else -> throw UnknownFormatException()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user