|
|
|
|
@ -7,18 +7,13 @@ import androidx.annotation.WorkerThread
|
|
|
|
|
import androidx.collection.ArraySet
|
|
|
|
|
import androidx.core.net.toFile
|
|
|
|
|
import androidx.core.net.toUri
|
|
|
|
|
import java.io.File
|
|
|
|
|
import java.io.IOException
|
|
|
|
|
import java.util.*
|
|
|
|
|
import java.util.zip.ZipEntry
|
|
|
|
|
import java.util.zip.ZipFile
|
|
|
|
|
import kotlin.coroutines.CoroutineContext
|
|
|
|
|
import kotlinx.coroutines.*
|
|
|
|
|
import org.koitharu.kotatsu.core.exceptions.UnsupportedFileException
|
|
|
|
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
|
|
|
|
import org.koitharu.kotatsu.local.data.CbzFilter
|
|
|
|
|
import org.koitharu.kotatsu.local.data.LocalStorageManager
|
|
|
|
|
import org.koitharu.kotatsu.local.data.MangaIndex
|
|
|
|
|
import org.koitharu.kotatsu.local.data.TempFileFilter
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.*
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.longHashCode
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.toCamelCase
|
|
|
|
|
@ -26,6 +21,12 @@ import org.koitharu.kotatsu.utils.AlphanumComparator
|
|
|
|
|
import org.koitharu.kotatsu.utils.ext.deleteAwait
|
|
|
|
|
import org.koitharu.kotatsu.utils.ext.readText
|
|
|
|
|
import org.koitharu.kotatsu.utils.ext.resolveName
|
|
|
|
|
import java.io.File
|
|
|
|
|
import java.io.IOException
|
|
|
|
|
import java.util.*
|
|
|
|
|
import java.util.zip.ZipEntry
|
|
|
|
|
import java.util.zip.ZipFile
|
|
|
|
|
import kotlin.coroutines.CoroutineContext
|
|
|
|
|
|
|
|
|
|
private const val MAX_PARALLELISM = 4
|
|
|
|
|
|
|
|
|
|
@ -245,7 +246,7 @@ class LocalMangaRepository(private val storageManager: LocalStorageManager) : Ma
|
|
|
|
|
withContext(Dispatchers.IO) {
|
|
|
|
|
val name = contentResolver.resolveName(uri)
|
|
|
|
|
?: throw IOException("Cannot fetch name from uri: $uri")
|
|
|
|
|
if (!isFileSupported(name)) {
|
|
|
|
|
if (!filenameFilter.isFileSupported(name)) {
|
|
|
|
|
throw UnsupportedFileException("Unsupported file on $uri")
|
|
|
|
|
}
|
|
|
|
|
val dest = File(
|
|
|
|
|
@ -262,15 +263,21 @@ class LocalMangaRepository(private val storageManager: LocalStorageManager) : Ma
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun isFileSupported(name: String): Boolean {
|
|
|
|
|
val ext = name.substringAfterLast('.').lowercase(Locale.ROOT)
|
|
|
|
|
return ext == "cbz" || ext == "zip"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
suspend fun getOutputDir(): File? {
|
|
|
|
|
return storageManager.getDefaultWriteableDir()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
suspend fun cleanup() {
|
|
|
|
|
val dirs = storageManager.getWriteableDirs()
|
|
|
|
|
runInterruptible(Dispatchers.IO) {
|
|
|
|
|
dirs.flatMap { dir ->
|
|
|
|
|
dir.listFiles(TempFileFilter())?.toList().orEmpty()
|
|
|
|
|
}.forEach { file ->
|
|
|
|
|
file.delete()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private suspend fun getAllFiles() = storageManager.getReadableDirs().flatMap { dir ->
|
|
|
|
|
dir.listFiles(filenameFilter)?.toList().orEmpty()
|
|
|
|
|
}
|
|
|
|
|
|