mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-10 12:47:26 +01:00
Ensure final download status is always set (#9453)
This commit is contained in:
parent
fce9cb820c
commit
cb2d43c0d1
@ -526,9 +526,15 @@ class Downloader(
|
|||||||
dirname: String,
|
dirname: String,
|
||||||
) {
|
) {
|
||||||
// Page list hasn't been initialized
|
// Page list hasn't been initialized
|
||||||
val downloadPageCount = download.pages?.size ?: return
|
val downloadPageCount = download.pages?.size ?: run {
|
||||||
// Ensure that all pages has been downloaded
|
download.status = Download.State.ERROR
|
||||||
if (download.downloadedImages < downloadPageCount) return
|
return
|
||||||
|
}
|
||||||
|
// Ensure that all pages have been downloaded
|
||||||
|
if (download.downloadedImages != downloadPageCount) {
|
||||||
|
download.status = Download.State.ERROR
|
||||||
|
return
|
||||||
|
}
|
||||||
// Ensure that the chapter folder has all the pages
|
// Ensure that the chapter folder has all the pages
|
||||||
val downloadedImagesCount = tmpDir.listFiles().orEmpty().count {
|
val downloadedImagesCount = tmpDir.listFiles().orEmpty().count {
|
||||||
val fileName = it.name.orEmpty()
|
val fileName = it.name.orEmpty()
|
||||||
@ -540,29 +546,29 @@ class Downloader(
|
|||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (downloadedImagesCount != downloadPageCount) {
|
||||||
download.status = if (downloadedImagesCount == downloadPageCount) {
|
download.status = Download.State.ERROR
|
||||||
createComicInfoFile(
|
return
|
||||||
tmpDir,
|
|
||||||
download.manga,
|
|
||||||
download.chapter,
|
|
||||||
download.source,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Only rename the directory if it's downloaded
|
|
||||||
if (downloadPreferences.saveChaptersAsCBZ().get()) {
|
|
||||||
archiveChapter(mangaDir, dirname, tmpDir)
|
|
||||||
} else {
|
|
||||||
tmpDir.renameTo(dirname)
|
|
||||||
}
|
|
||||||
cache.addChapter(dirname, mangaDir, download.manga)
|
|
||||||
|
|
||||||
DiskUtil.createNoMediaFile(tmpDir, context)
|
|
||||||
|
|
||||||
Download.State.DOWNLOADED
|
|
||||||
} else {
|
|
||||||
Download.State.ERROR
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createComicInfoFile(
|
||||||
|
tmpDir,
|
||||||
|
download.manga,
|
||||||
|
download.chapter,
|
||||||
|
download.source,
|
||||||
|
)
|
||||||
|
|
||||||
|
// Only rename the directory if it's downloaded
|
||||||
|
if (downloadPreferences.saveChaptersAsCBZ().get()) {
|
||||||
|
archiveChapter(mangaDir, dirname, tmpDir)
|
||||||
|
} else {
|
||||||
|
tmpDir.renameTo(dirname)
|
||||||
|
}
|
||||||
|
cache.addChapter(dirname, mangaDir, download.manga)
|
||||||
|
|
||||||
|
DiskUtil.createNoMediaFile(tmpDir, context)
|
||||||
|
|
||||||
|
download.status = Download.State.DOWNLOADED
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user