Fix/extracting assets from apks (#644)

* Get rid of multiple static "assets/" usage

* Correctly add new zip entry

The name of the entry has to be a "/" separated path, otherwise, the files can't be found.
This commit is contained in:
schroda
2023-08-07 05:21:31 +02:00
committed by GitHub
parent 2889029b70
commit f6fec2424c
@@ -213,7 +213,7 @@ object Extension {
var zipEntry = zipInputStream.nextEntry
while (zipEntry != null) {
if (zipEntry.name.startsWith("assets/")) {
val assetFile = File(assetsFolder, zipEntry.name.substringAfter("assets/"))
val assetFile = File(assetsFolder, zipEntry.name)
assetFile.parentFile.mkdirs()
FileOutputStream(assetFile).use { outputStream ->
zipInputStream.copyTo(outputStream)
@@ -236,7 +236,7 @@ object Extension {
}
assetsFolder.walkTopDown().forEach { file ->
if (file.isFile) {
jarZipOutputStream.putNextEntry(ZipEntry("assets/${file.relativeTo(assetsFolder)}"))
jarZipOutputStream.putNextEntry(ZipEntry(file.relativeTo(assetsFolder).toString().replace("\\", "/")))
file.inputStream().use { inputStream ->
inputStream.copyTo(jarZipOutputStream)
}