Workaround for cbz long filename error
This commit is contained in:
parent
ed5c3f327c
commit
bb409e5ced
@ -484,35 +484,40 @@ 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() &&
|
||||||
val compressionLevel = preferences.saveChaptersAsCBZLevel().get()
|
mangaDir.createFile("$dirname.cbz.tmp").also { zip = it } != null
|
||||||
|
) {
|
||||||
|
ZipOutputStream(zip!!.openOutputStream().buffered()).use { zipOut ->
|
||||||
|
val compressionLevel = preferences.saveChaptersAsCBZLevel().get()
|
||||||
|
|
||||||
zipOut.setLevel(compressionLevel)
|
zipOut.setLevel(compressionLevel)
|
||||||
|
|
||||||
if (compressionLevel == 0) {
|
|
||||||
zipOut.setMethod(ZipEntry.STORED)
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpDir.listFiles()?.forEach { img ->
|
|
||||||
val input = img.openInputStream()
|
|
||||||
val data = input.readBytes()
|
|
||||||
val entry = ZipEntry(img.name)
|
|
||||||
if (compressionLevel == 0) {
|
if (compressionLevel == 0) {
|
||||||
val crc = CRC32()
|
zipOut.setMethod(ZipEntry.STORED)
|
||||||
val size = img.length()
|
}
|
||||||
crc.update(data)
|
|
||||||
entry.crc = crc.value
|
tmpDir.listFiles()?.forEach { img ->
|
||||||
entry.compressedSize = size
|
img.openInputStream().use { input ->
|
||||||
entry.size = size
|
val data = input.readBytes()
|
||||||
|
val entry = ZipEntry(img.name)
|
||||||
|
if (compressionLevel == 0) {
|
||||||
|
val crc = CRC32()
|
||||||
|
val size = img.length()
|
||||||
|
crc.update(data)
|
||||||
|
entry.crc = crc.value
|
||||||
|
entry.compressedSize = size
|
||||||
|
entry.size = size
|
||||||
|
}
|
||||||
|
zipOut.putNextEntry(entry)
|
||||||
|
zipOut.write(data)
|
||||||
|
zipOut.closeEntry()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
zipOut.putNextEntry(entry)
|
|
||||||
zipOut.write(data)
|
|
||||||
input.close()
|
|
||||||
}
|
}
|
||||||
zipOut.close()
|
|
||||||
zip.renameTo("$dirname.cbz")
|
zip!!.renameTo("$dirname.cbz")
|
||||||
tmpDir.delete()
|
tmpDir.delete()
|
||||||
} else {
|
} else {
|
||||||
tmpDir.renameTo(dirname)
|
tmpDir.renameTo(dirname)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user