Fix download chapter dir when scanlator is empty or changed

This commit is contained in:
Jays2Kings 2022-08-22 01:06:37 -04:00
parent 61d0023e2f
commit 80f2423f98
2 changed files with 6 additions and 5 deletions

View file

@ -229,10 +229,10 @@ class DownloadProvider(private val context: Context) {
*
* @param chapter the chapter to query.
*/
fun getChapterDirName(chapter: Chapter): String {
fun getChapterDirName(chapter: Chapter, includeBlank: Boolean = false): String {
return DiskUtil.buildValidFilename(
if (chapter.scanlator != null) "${chapter.scanlator}_${chapter.name}"
else chapter.name,
if (!chapter.scanlator.isNullOrBlank()) "${chapter.scanlator}_${chapter.name}"
else (if (includeBlank) "_" else "") + chapter.name,
)
}
@ -244,8 +244,9 @@ class DownloadProvider(private val context: Context) {
fun getValidChapterDirNames(chapter: Chapter): List<String> {
return listOf(
getChapterDirName(chapter),
getChapterDirName(chapter, true),
// Legacy chapter directory name used in v0.8.4 and before
DiskUtil.buildValidFilename(chapter.name),
)
).distinct()
}
}

View file

@ -67,7 +67,7 @@ fun syncChaptersWithSource(
ChapterRecognition.parseChapterNumber(sourceChapter, manga)
if (shouldUpdateDbChapter(dbChapter, sourceChapter)) {
if (dbChapter.name != sourceChapter.name &&
if ((dbChapter.name != sourceChapter.name || dbChapter.scanlator != sourceChapter.scanlator) &&
downloadManager.isChapterDownloaded(dbChapter, manga)
) {
downloadManager.renameChapter(source, manga, dbChapter, sourceChapter)