|
|
|
@ -10,10 +10,13 @@ import android.provider.OpenableColumns
|
|
|
|
import androidx.core.database.getStringOrNull
|
|
|
|
import androidx.core.database.getStringOrNull
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.runInterruptible
|
|
|
|
import kotlinx.coroutines.runInterruptible
|
|
|
|
|
|
|
|
import okhttp3.internal.closeQuietly
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.Blocking
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.core.fs.FileSequence
|
|
|
|
import org.koitharu.kotatsu.core.fs.FileSequence
|
|
|
|
import java.io.File
|
|
|
|
import java.io.File
|
|
|
|
import java.io.FileFilter
|
|
|
|
import java.io.FileFilter
|
|
|
|
|
|
|
|
import java.io.InputStream
|
|
|
|
import java.nio.file.attribute.BasicFileAttributes
|
|
|
|
import java.nio.file.attribute.BasicFileAttributes
|
|
|
|
import java.util.zip.ZipEntry
|
|
|
|
import java.util.zip.ZipEntry
|
|
|
|
import java.util.zip.ZipFile
|
|
|
|
import java.util.zip.ZipFile
|
|
|
|
@ -32,10 +35,19 @@ fun File.takeIfWriteable() = takeIf { it.exists() && it.canWrite() }
|
|
|
|
|
|
|
|
|
|
|
|
fun File.isNotEmpty() = length() != 0L
|
|
|
|
fun File.isNotEmpty() = length() != 0L
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Blocking
|
|
|
|
fun ZipFile.readText(entry: ZipEntry) = getInputStream(entry).bufferedReader().use {
|
|
|
|
fun ZipFile.readText(entry: ZipEntry) = getInputStream(entry).bufferedReader().use {
|
|
|
|
it.readText()
|
|
|
|
it.readText()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Blocking
|
|
|
|
|
|
|
|
fun ZipFile.getInputStreamOrClose(entry: ZipEntry): InputStream = try {
|
|
|
|
|
|
|
|
getInputStream(entry)
|
|
|
|
|
|
|
|
} catch (e: Throwable) {
|
|
|
|
|
|
|
|
closeQuietly()
|
|
|
|
|
|
|
|
throw e
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun File.getStorageName(context: Context): String = runCatching {
|
|
|
|
fun File.getStorageName(context: Context): String = runCatching {
|
|
|
|
val manager = context.getSystemService(Context.STORAGE_SERVICE) as StorageManager
|
|
|
|
val manager = context.getSystemService(Context.STORAGE_SERVICE) as StorageManager
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
|
|