Skip to content

drop untar implementation #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,4 @@ dependencies {
implementation "androidx.appcompat:appcompat:$androidx_appcompat_version"
implementation "androidx.legacy:legacy-support-v4:$androidx_supportv4_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_plugin_version"
implementation "org.apache.commons:commons-compress:$commons_compress_version"
}
1 change: 0 additions & 1 deletion app/src/main/java/org/koreader/launcher/LuaInterface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,4 @@ interface LuaInterface {
fun startTestActivity()
fun showFrontlightDialog(title: String, dim: String, warmth: String, okButton: String, cancelButton: String)
fun showToast(message: String, longTimeout: Boolean)
fun untar(filePath: String, outputPath: String): Boolean
}
4 changes: 0 additions & 4 deletions app/src/main/java/org/koreader/launcher/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,6 @@ class MainActivity : NativeActivity(), LuaInterface,
startActivity(intent)
}

override fun untar(filePath: String, outputPath: String): Boolean {
return File(filePath).uncompress(outputPath)
}

/*---------------------------------------------------------------
* private methods *
*--------------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ package org.koreader.launcher.extensions
import android.annotation.SuppressLint
import android.os.Build
import android.system.Os
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream
import org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream
import org.apache.commons.compress.utils.IOUtils
import java.io.*

@SuppressLint("DiscouragedPrivateApi")
Expand Down Expand Up @@ -53,69 +48,3 @@ fun File.write(value: Int) {
e.printStackTrace()
}
}

fun File.uncompress(extractTo: String, deleteIfOk: Boolean = false): Boolean {
val success = try {
uncompress(this.absolutePath, extractTo)
} catch (e: IOException) {
e.printStackTrace()
false
}

if (success and deleteIfOk) {
try {
delete()
} catch (e: IOException) {
e.printStackTrace()
}
}
return success
}

@Throws(IOException::class)
private fun uncompress(archive: String, extractTo: String): Boolean {
return getTarInput(archive)?.use {
val output = File(extractTo)
if (!output.exists()) {
output.mkdir()
}
var tarEntry = it.nextTarEntry
while (tarEntry != null) {
val destPath = File(extractTo, tarEntry.name)
destPath.parentFile?.let { parent ->
if (!parent.exists()) {
parent.mkdirs()
}
}
if (!tarEntry.isDirectory) {
if (destPath.exists()) {
destPath.delete()
}
if (destPath.createNewFile()) {
FileOutputStream(destPath).use { out -> IOUtils.copy(it, out, 4096) }
}
}
tarEntry = it.nextTarEntry
}
it.close()
true
} ?:false
}

private fun getTarInput(archive: String): TarArchiveInputStream? {
val input = File(archive)
val validExtensions = arrayOf("bz2", "gz", "lz", "tgz")
return if (validExtensions.contains(input.extension)) {
TarArchiveInputStream(
when (input.extension) {
"bz2" -> BZip2CompressorInputStream(BufferedInputStream(FileInputStream(input)))
"lz" -> LZMACompressorInputStream(BufferedInputStream(FileInputStream(input)))
else -> GzipCompressorInputStream(BufferedInputStream(FileInputStream(input)))
},
// ignore illegal values for group/userid, mode, device numbers and timestamp
true
)
} else {
null
}
}
17 changes: 0 additions & 17 deletions assets/android.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2606,23 +2606,6 @@ local function run(android_app_state)
end)
end

android.untar = function(file, output)
if not file or not output then return false end
return JNI:context(android.app.activity.vm, function(jni)
local i = jni.env[0].NewStringUTF(jni.env, file)
local o = jni.env[0].NewStringUTF(jni.env, output)
local ok = jni:callBooleanMethod(
android.app.activity.clazz,
"untar",
"(Ljava/lang/String;Ljava/lang/String;)Z",
i, o
)
jni.env[0].DeleteLocalRef(jni.env, i)
jni.env[0].DeleteLocalRef(jni.env, o)
return ok
end)
end

local function subprocess(jni, argv)
local args_array = jni.env[0].NewObjectArray(jni.env, #argv,
jni.env[0].FindClass(jni.env, "java/lang/String"), nil)
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ buildscript {
ext.androidx_core_version = '1.6.0'
ext.androidx_appcompat_version = '1.3.1'
ext.androidx_supportv4_version = '1.0.0'
ext.commons_compress_version = '1.20'

repositories {
google()
Expand Down