From 20bec66a9de5ae34dd437714ff5f80801e2e92b8 Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 25 Apr 2023 22:07:34 -0400 Subject: [PATCH] Handle archives with nested directories properly Closes #9389 --- .../eu/kanade/tachiyomi/ui/reader/loader/RarPageLoader.kt | 6 ++++-- .../eu/kanade/tachiyomi/ui/reader/loader/ZipPageLoader.kt | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/RarPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/RarPageLoader.kt index 724283e56..7231a45a0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/RarPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/RarPageLoader.kt @@ -26,9 +26,11 @@ internal class RarPageLoader(file: File) : PageLoader() { rar.fileHeaders.asSequence() .filterNot { it.isDirectory } .forEach { header -> - val pageFile = File(tmpDir, header.fileName).also { it.createNewFile() } + val pageOutputStream = File(tmpDir, header.fileName.substringAfterLast("/")) + .also { it.createNewFile() } + .outputStream() getStream(rar, header).use { - it.copyTo(pageFile.outputStream()) + it.copyTo(pageOutputStream) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ZipPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ZipPageLoader.kt index 8ebe393be..a9a4e91ff 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ZipPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ZipPageLoader.kt @@ -24,7 +24,8 @@ internal class ZipPageLoader(file: File) : PageLoader() { generateSequence { zipInputStream.nextEntry } .filterNot { it.isDirectory } .forEach { entry -> - File(tmpDir, entry.name).also { it.createNewFile() } + File(tmpDir, entry.name.substringAfterLast("/")) + .also { it.createNewFile() } .outputStream().use { pageOutputStream -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { pageOutputStream.write(zipInputStream.readNBytes(entry.size.toInt()))