Fix download not working on sd card (#8527)

Also create comicinfo file inside chapter folder instead of manga folder since it also contains some chapter specific data
This commit is contained in:
AntsyLich 2022-11-13 21:40:33 +06:00 committed by GitHub
parent dad24e785b
commit 51c964de3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,7 +10,6 @@ import eu.kanade.domain.manga.model.COMIC_INFO_FILE
import eu.kanade.domain.manga.model.ComicInfo import eu.kanade.domain.manga.model.ComicInfo
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.domain.manga.model.getComicInfo import eu.kanade.domain.manga.model.getComicInfo
import eu.kanade.domain.track.interactor.GetTracks
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.cache.ChapterCache
import eu.kanade.tachiyomi.data.database.models.toDomainChapter import eu.kanade.tachiyomi.data.database.models.toDomainChapter
@ -45,7 +44,6 @@ import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.io.BufferedOutputStream import java.io.BufferedOutputStream
import java.io.File import java.io.File
import java.io.FileOutputStream
import java.util.zip.CRC32 import java.util.zip.CRC32
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream import java.util.zip.ZipOutputStream
@ -71,7 +69,6 @@ class Downloader(
private val sourceManager: SourceManager = Injekt.get(), private val sourceManager: SourceManager = Injekt.get(),
private val chapterCache: ChapterCache = Injekt.get(), private val chapterCache: ChapterCache = Injekt.get(),
private val downloadPreferences: DownloadPreferences = Injekt.get(), private val downloadPreferences: DownloadPreferences = Injekt.get(),
private val getTracks: GetTracks = Injekt.get(),
) { ) {
/** /**
@ -527,6 +524,14 @@ class Downloader(
// Ensure that the chapter folder has all the images. // Ensure that the chapter folder has all the images.
val downloadedImages = tmpDir.listFiles().orEmpty().filterNot { it.name!!.endsWith(".tmp") || (it.name!!.contains("__") && !it.name!!.contains("__001.jpg")) } val downloadedImages = tmpDir.listFiles().orEmpty().filterNot { it.name!!.endsWith(".tmp") || (it.name!!.contains("__") && !it.name!!.contains("__001.jpg")) }
val chapterUrl = download.source.getChapterUrl(download.chapter)
createComicInfoFile(
tmpDir,
download.manga,
download.chapter.toDomainChapter()!!,
chapterUrl,
)
download.status = if (downloadedImages.size == download.pages!!.size) { download.status = if (downloadedImages.size == download.pages!!.size) {
// Only rename the directory if it's downloaded. // Only rename the directory if it's downloaded.
if (downloadPreferences.saveChaptersAsCBZ().get()) { if (downloadPreferences.saveChaptersAsCBZ().get()) {
@ -538,14 +543,6 @@ class Downloader(
DiskUtil.createNoMediaFile(tmpDir, context) DiskUtil.createNoMediaFile(tmpDir, context)
val chapterUrl = download.source.getChapterUrl(download.chapter)
createComicInfoFile(
mangaDir,
download.manga,
download.chapter.toDomainChapter()!!,
chapterUrl,
)
Download.State.DOWNLOADED Download.State.DOWNLOADED
} else { } else {
Download.State.ERROR Download.State.ERROR
@ -600,12 +597,12 @@ class Downloader(
chapter: Chapter, chapter: Chapter,
chapterUrl: String, chapterUrl: String,
) { ) {
File("${dir.filePath}/$COMIC_INFO_FILE").outputStream().also { val comicInfo = getComicInfo(manga, chapter, chapterUrl)
// Force overwrite old file val comicInfoString = xml.encodeToString(ComicInfo.serializer(), comicInfo)
(it as? FileOutputStream)?.channel?.truncate(0) // Remove the old file
}.use { dir.findFile(COMIC_INFO_FILE)?.delete()
val comicInfo = getComicInfo(manga, chapter, chapterUrl) dir.createFile(COMIC_INFO_FILE).openOutputStream().use {
it.write(xml.encodeToString(ComicInfo.serializer(), comicInfo).toByteArray()) it.write(comicInfoString.toByteArray())
} }
} }