|
@@ -1,4 +1,4 @@
|
|
|
-package io.legado.app.utils
|
|
|
|
|
|
|
+package io.legado.app.utils.compress
|
|
|
|
|
|
|
|
import androidx.annotation.Keep
|
|
import androidx.annotation.Keep
|
|
|
import com.github.junrar.Archive
|
|
import com.github.junrar.Archive
|
|
@@ -9,20 +9,30 @@ import java.io.FileOutputStream
|
|
|
import java.io.InputStream
|
|
import java.io.InputStream
|
|
|
|
|
|
|
|
@Keep
|
|
@Keep
|
|
|
-@Suppress("unused","MemberVisibilityCanBePrivate")
|
|
|
|
|
|
|
+@Suppress("unused", "MemberVisibilityCanBePrivate")
|
|
|
object RarUtils {
|
|
object RarUtils {
|
|
|
- fun unRarToPath(inputStream: InputStream,path:String){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Throws(NullPointerException::class, SecurityException::class)
|
|
|
|
|
+ fun unRarToPath(inputStream: InputStream, path: String) {
|
|
|
unRarToPath(inputStream, File(path))
|
|
unRarToPath(inputStream, File(path))
|
|
|
}
|
|
}
|
|
|
- fun unRarToPath(byteArray: ByteArray,path:String){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Throws(NullPointerException::class, SecurityException::class)
|
|
|
|
|
+ fun unRarToPath(byteArray: ByteArray, path: String) {
|
|
|
unRarToPath(byteArray, File(path))
|
|
unRarToPath(byteArray, File(path))
|
|
|
}
|
|
}
|
|
|
- fun unRarToPath(zipPath:String,path:String){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Throws(NullPointerException::class, SecurityException::class)
|
|
|
|
|
+ fun unRarToPath(zipPath: String, path: String) {
|
|
|
unRarToPath(zipPath, File(path))
|
|
unRarToPath(zipPath, File(path))
|
|
|
}
|
|
}
|
|
|
- fun unRarToPath(file: File,path:String){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Throws(NullPointerException::class, SecurityException::class)
|
|
|
|
|
+ fun unRarToPath(file: File, path: String) {
|
|
|
unRarToPath(file, File(path))
|
|
unRarToPath(file, File(path))
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Throws(NullPointerException::class, SecurityException::class)
|
|
|
fun unRarToPath(inputStream: InputStream, destDir: File?) {
|
|
fun unRarToPath(inputStream: InputStream, destDir: File?) {
|
|
|
Archive(inputStream).use {
|
|
Archive(inputStream).use {
|
|
|
unRarToPath(it, destDir)
|
|
unRarToPath(it, destDir)
|
|
@@ -30,28 +40,36 @@ object RarUtils {
|
|
|
inputStream.close()
|
|
inputStream.close()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Throws(NullPointerException::class, SecurityException::class)
|
|
|
fun unRarToPath(byteArray: ByteArray, destDir: File?) {
|
|
fun unRarToPath(byteArray: ByteArray, destDir: File?) {
|
|
|
Archive(ByteArrayInputStream(byteArray)).use {
|
|
Archive(ByteArrayInputStream(byteArray)).use {
|
|
|
unRarToPath(it, destDir)
|
|
unRarToPath(it, destDir)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fun unRarToPath(filePath:String, destDir: File?) {
|
|
|
|
|
|
|
+ @Throws(NullPointerException::class, SecurityException::class)
|
|
|
|
|
+ fun unRarToPath(filePath: String, destDir: File?) {
|
|
|
Archive(File(filePath)).use {
|
|
Archive(File(filePath)).use {
|
|
|
unRarToPath(it, destDir)
|
|
unRarToPath(it, destDir)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Throws(NullPointerException::class, SecurityException::class)
|
|
|
fun unRarToPath(file: File, destDir: File?) {
|
|
fun unRarToPath(file: File, destDir: File?) {
|
|
|
Archive(file).use {
|
|
Archive(file).use {
|
|
|
unRarToPath(it, destDir)
|
|
unRarToPath(it, destDir)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Throws(NullPointerException::class, SecurityException::class)
|
|
|
fun unRarToPath(archive: Archive, destDir: File?) {
|
|
fun unRarToPath(archive: Archive, destDir: File?) {
|
|
|
|
|
+ destDir ?: throw NullPointerException("解决路径不能为空")
|
|
|
var entry: FileHeader?
|
|
var entry: FileHeader?
|
|
|
while (archive.nextFileHeader().also { entry = it } != null) {
|
|
while (archive.nextFileHeader().also { entry = it } != null) {
|
|
|
val entryFile = File(destDir, entry!!.fileName)
|
|
val entryFile = File(destDir, entry!!.fileName)
|
|
|
|
|
+ if (!entryFile.canonicalPath.startsWith(destDir.canonicalPath)) {
|
|
|
|
|
+ throw SecurityException("压缩文件只能解压到指定路径")
|
|
|
|
|
+ }
|
|
|
if (entry!!.isDirectory) {
|
|
if (entry!!.isDirectory) {
|
|
|
if (!entryFile.exists()) {
|
|
if (!entryFile.exists()) {
|
|
|
entryFile.mkdirs()
|
|
entryFile.mkdirs()
|