Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -3,7 +3,6 @@ package io.legado.app.utils
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.regex.Pattern
|
|
||||||
|
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
|
|
||||||
@@ -15,10 +14,6 @@ object ArchiveUtils {
|
|||||||
appCtx.externalCache.getFile("ArchiveTemp").createFolderReplace().absolutePath
|
appCtx.externalCache.getFile("ArchiveTemp").createFolderReplace().absolutePath
|
||||||
}
|
}
|
||||||
|
|
||||||
val ZIP_REGEX = Regex(".*\\.zip", RegexOption.IGNORE_CASE)
|
|
||||||
val RAR_REGEX = Regex(".*\\.rar", RegexOption.IGNORE_CASE)
|
|
||||||
val SERVEZ_REGEX = Regex(".*\\.7z", RegexOption.IGNORE_CASE)
|
|
||||||
|
|
||||||
fun deCompress(
|
fun deCompress(
|
||||||
archiveUri: Uri,
|
archiveUri: Uri,
|
||||||
path: String = TEMP_PATH
|
path: String = TEMP_PATH
|
||||||
@@ -53,15 +48,17 @@ object ArchiveUtils {
|
|||||||
): FileDoc {
|
): FileDoc {
|
||||||
if (archiveFileDoc.isDir) throw IllegalArgumentException("Unexpected Folder input")
|
if (archiveFileDoc.isDir) throw IllegalArgumentException("Unexpected Folder input")
|
||||||
val name = archiveFileDoc.name
|
val name = archiveFileDoc.name
|
||||||
|
val workPathFileDoc = getCacheFolderFileDoc(name, path)
|
||||||
|
val workPath = workPathFileDoc.toString()
|
||||||
archiveFileDoc.uri.inputStream(appCtx).getOrThrow().use {
|
archiveFileDoc.uri.inputStream(appCtx).getOrThrow().use {
|
||||||
when {
|
when {
|
||||||
ZIP_REGEX.matches(name) -> ZipUtils.unZipToPath(it, path)
|
name.endsWith(".zip", ignoreCase = true) -> ZipUtils.unZipToPath(it, workPath)
|
||||||
RAR_REGEX.matches(name) -> RarUtils.unRarToPath(it, path)
|
name.endsWith(".rar", ignoreCase = true) -> RarUtils.unRarToPath(it, workPath)
|
||||||
SERVEZ_REGEX.matches(name) -> SevenZipUtils.un7zToPath(it, path)
|
name.endsWith(".7z", ignoreCase = true) -> SevenZipUtils.un7zToPath(it, workPath)
|
||||||
else -> throw IllegalArgumentException("Unexpected archive format")
|
else -> throw IllegalArgumentException("Unexpected archive format")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getCacheFolderFileDoc(name, path)
|
return workPathFileDoc
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCacheFolderFileDoc(
|
private fun getCacheFolderFileDoc(
|
||||||
|
|||||||
Reference in New Issue
Block a user