From 6940ad3fd9d37d81988c9f42c26e5ada0c178d8a Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 4 Mar 2020 22:33:16 -0500 Subject: [PATCH] Limit saved page filenames to 127 characters (fixes #2638) --- .../eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index bb2111ae7..d2ca66adc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -448,9 +448,10 @@ class ReaderPresenter( val chapter = page.chapter.chapter // Build destination file. + val filenameSuffix = " - ${page.number}.${type.extension}" val filename = DiskUtil.buildValidFilename( - "${manga.title} - ${chapter.name}".take(225) - ) + " - ${page.number}.${type.extension}" + "${manga.title} - ${chapter.name}".take(MAX_FILE_NAME_LENGTH - filenameSuffix.length) + ) + filenameSuffix val destFile = File(directory, filename) stream().use { input -> @@ -638,4 +639,9 @@ class ReaderPresenter( .subscribeOn(Schedulers.io()) .subscribe() } + + companion object { + // Safe max filename size is 255 bytes and 1 char = 2 bytes + private const val MAX_FILE_NAME_LENGTH = 127 + } }