Workaround for cbz long filename error

This commit is contained in:
Jobobby04 2021-10-23 14:04:33 -04:00
parent ed5c3f327c
commit bb409e5ced

View File

@ -484,9 +484,12 @@ class Downloader(
// Only rename the directory if it's downloaded. // Only rename the directory if it's downloaded.
if (download.status == Download.State.DOWNLOADED) { if (download.status == Download.State.DOWNLOADED) {
if (preferences.saveChaptersAsCBZ().get()) { var zip: UniFile? = null
val zip = mangaDir.createFile("$dirname.cbz.tmp") if (
val zipOut = ZipOutputStream(BufferedOutputStream(zip.openOutputStream())) preferences.saveChaptersAsCBZ().get() &&
mangaDir.createFile("$dirname.cbz.tmp").also { zip = it } != null
) {
ZipOutputStream(zip!!.openOutputStream().buffered()).use { zipOut ->
val compressionLevel = preferences.saveChaptersAsCBZLevel().get() val compressionLevel = preferences.saveChaptersAsCBZLevel().get()
zipOut.setLevel(compressionLevel) zipOut.setLevel(compressionLevel)
@ -496,7 +499,7 @@ class Downloader(
} }
tmpDir.listFiles()?.forEach { img -> tmpDir.listFiles()?.forEach { img ->
val input = img.openInputStream() img.openInputStream().use { input ->
val data = input.readBytes() val data = input.readBytes()
val entry = ZipEntry(img.name) val entry = ZipEntry(img.name)
if (compressionLevel == 0) { if (compressionLevel == 0) {
@ -509,10 +512,12 @@ class Downloader(
} }
zipOut.putNextEntry(entry) zipOut.putNextEntry(entry)
zipOut.write(data) zipOut.write(data)
input.close() zipOut.closeEntry()
} }
zipOut.close() }
zip.renameTo("$dirname.cbz") }
zip!!.renameTo("$dirname.cbz")
tmpDir.delete() tmpDir.delete()
} else { } else {
tmpDir.renameTo(dirname) tmpDir.renameTo(dirname)