Handle renaming existing downloaded CBZ chapters on update

(cherry picked from commit c4a476d0d25ea724f658ab5fa2df889fab19bbf3)
This commit is contained in:
arkon 2022-01-01 15:20:35 -05:00 committed by Jobobby04
parent 56dd6c5920
commit 55ca111b52

View File

@ -381,15 +381,19 @@ class DownloadManager(
*/
fun renameChapter(source: Source, manga: Manga, oldChapter: Chapter, newChapter: Chapter) {
val oldNames = provider.getValidChapterDirNames(oldChapter)
val newName = provider.getChapterDirName(newChapter)
val mangaDir = provider.getMangaDir(manga, source)
// Assume there's only 1 version of the chapter name formats present
val oldFolder = oldNames.asSequence()
val oldDownload = oldNames.asSequence()
.mapNotNull { mangaDir.findFile(it) }
.firstOrNull()
.firstOrNull() ?: return
if (oldFolder?.renameTo(newName) == true) {
var newName = provider.getChapterDirName(newChapter)
if (oldDownload.isFile && oldDownload.name?.endsWith(".cbz") == true) {
newName += ".cbz"
}
if (oldDownload.renameTo(newName)) {
cache.removeChapter(oldChapter, manga)
cache.addChapter(newName, mangaDir, manga)
} else {