Fix temporary download directory cleanup

This commit is contained in:
FooIbar committed 2024-03-09 16:22:57 +08:00
1 parent 49d4ae078f
commit a16c021000
3 files changed
+8 -3

No files matched your search

@@ -29,6 +29,7 @@ import arrow.fx.coroutines.parMapNotNull
import com.hippo.ehviewer.EhDB
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.data.BaseGalleryInfo
import com.hippo.ehviewer.client.data.GalleryInfo
import com.hippo.ehviewer.dao.DownloadInfo
import com.hippo.ehviewer.dao.DownloadLabel
import com.hippo.ehviewer.image.Image
@@ -368,6 +369,7 @@ object DownloadManager : OnSpiderListener, CoroutineScope {
if (deleteFiles) {
info.downloadDir?.delete()
info.tempDownloadDir?.delete()
EhDB.removeDownloadDirname(info.gid)
}
}
@@ -788,3 +790,4 @@ var downloadLocation: UniFile
val DownloadInfo.downloadDir get() = dirname?.let { downloadLocation / it }
val DownloadInfo.archiveFile get() = downloadDir?.findFile("$gid.cbz")
val GalleryInfo.tempDownloadDir get() = AppConfig.getTempDir("$gid")
@@ -32,9 +32,9 @@ import com.hippo.ehviewer.client.getImageKey
import com.hippo.ehviewer.coil.read
import com.hippo.ehviewer.coil.suspendEdit
import com.hippo.ehviewer.download.downloadLocation
import com.hippo.ehviewer.download.tempDownloadDir
import com.hippo.ehviewer.image.UniFileSource
import com.hippo.ehviewer.jni.archiveFdBatch
import com.hippo.ehviewer.util.AppConfig
import com.hippo.ehviewer.util.FileUtils
import com.hippo.ehviewer.util.sendTo
import com.hippo.unifile.UniFile
@@ -79,7 +79,7 @@ class SpiderDen(val info: GalleryInfo) {
downloadDir = getGalleryDownloadDir(gid)?.takeIf { it.ensureDir() }
}
if (saveAsCbz && tempDownloadDir == null) {
tempDownloadDir = AppConfig.getTempDir("$gid")?.takeIf { it.ensureDir() }
tempDownloadDir = info.tempDownloadDir?.takeIf { it.ensureDir() }
}
}
}
@@ -308,7 +308,7 @@ class SpiderDen(val info: GalleryInfo) {
suspend fun initDownloadDirIfExist() {
downloadDir = getGalleryDownloadDir(gid)?.takeIf { it.isDirectory }
tempDownloadDir = AppConfig.getTempDir("$gid")?.takeIf { it.isDirectory }
tempDownloadDir = info.tempDownloadDir?.takeIf { it.isDirectory }
}
suspend fun initDownloadDir() {
@@ -53,6 +53,7 @@ import com.hippo.ehviewer.download.DownloadManager
import com.hippo.ehviewer.download.DownloadService
import com.hippo.ehviewer.download.downloadDir
import com.hippo.ehviewer.download.downloadLocation
import com.hippo.ehviewer.download.tempDownloadDir
import com.hippo.ehviewer.ui.destinations.ReaderScreenDestination
import com.hippo.ehviewer.ui.tools.DialogState
import com.hippo.ehviewer.ui.tools.LabeledCheckbox
@@ -389,6 +390,7 @@ suspend fun DialogState.confirmRemoveDownloadRange(list: Collection<DownloadInfo
list.forEach { info ->
// Delete file
info.downloadDir?.delete()
info.tempDownloadDir?.delete()
// Remove download path
EhDB.removeDownloadDirname(info.gid)
}