Fix download chapter dir when scanlator is empty or changed (#7780)
(cherry picked from commit 1f9f9662bc5abe75f24dae30d48e843005d86394) # Conflicts: # app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt
This commit is contained in:
parent
0632d3a605
commit
66ee19daaf
@ -104,8 +104,13 @@ class SyncChaptersWithSource(
|
||||
toAdd.add(toAddChapter)
|
||||
} else {
|
||||
if (shouldUpdateDbChapter.await(dbChapter, chapter)) {
|
||||
if (dbChapter.name != chapter.name && downloadManager.isChapterDownloaded(dbChapter.name, dbChapter.scanlator, /* SY --> */ manga.ogTitle /* SY <-- */, manga.source)) {
|
||||
downloadManager.renameChapter(source, manga, dbChapter.toDbChapter(), chapter.toDbChapter())
|
||||
downloadManager.run {
|
||||
val shouldRenameChapter = provider.isChapterDirNameChanged(dbChapter, chapter) &&
|
||||
isChapterDownloaded(dbChapter.name, dbChapter.scanlator, /* SY --> */ manga.ogTitle /* SY <-- */, manga.source)
|
||||
|
||||
if (shouldRenameChapter) {
|
||||
renameChapter(source, manga, dbChapter.toDbChapter(), chapter.toDbChapter())
|
||||
}
|
||||
}
|
||||
var toChangeChapter = dbChapter.copy(
|
||||
name = chapter.name,
|
||||
|
@ -37,7 +37,7 @@ data class Chapter(
|
||||
url = sChapter.url,
|
||||
dateUpload = sChapter.date_upload,
|
||||
chapterNumber = sChapter.chapter_number,
|
||||
scanlator = sChapter.scanlator,
|
||||
scanlator = sChapter.scanlator?.ifBlank { null },
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import logcat.LogPriority
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import eu.kanade.domain.chapter.model.Chapter as DomainChapter
|
||||
|
||||
/**
|
||||
* This class is used to provide the directories where the downloads should be saved.
|
||||
@ -168,6 +169,10 @@ class DownloadProvider(private val context: Context) {
|
||||
)
|
||||
}
|
||||
|
||||
fun isChapterDirNameChanged(oldChapter: DomainChapter, newChapter: DomainChapter): Boolean {
|
||||
return oldChapter.name != newChapter.name || oldChapter.scanlator != newChapter.scanlator
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns valid downloaded chapter directory names.
|
||||
*
|
||||
@ -176,15 +181,21 @@ class DownloadProvider(private val context: Context) {
|
||||
*/
|
||||
fun getValidChapterDirNames(chapterName: String, chapterScanlator: String?): List<String> {
|
||||
val chapterDirName = getChapterDirName(chapterName, chapterScanlator)
|
||||
return listOf(
|
||||
return buildList(5) {
|
||||
// Folder of images
|
||||
chapterDirName,
|
||||
add(chapterDirName)
|
||||
|
||||
// Archived chapters
|
||||
"$chapterDirName.cbz",
|
||||
add("$chapterDirName.cbz")
|
||||
|
||||
if (chapterScanlator == null) {
|
||||
// Previously null scanlator fields were converted to "" due to a bug
|
||||
add("_$chapterDirName")
|
||||
add("_$chapterDirName.cbz")
|
||||
}
|
||||
|
||||
// Legacy chapter directory name used in v0.9.2 and before
|
||||
DiskUtil.buildValidFilename(chapterName),
|
||||
)
|
||||
add(DiskUtil.buildValidFilename(chapterName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user