From ee091aee0fda89b1f5a4be2288a3417eee2e62af Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:50:20 +0800 Subject: [PATCH] Rescan download directory when restoring downloads (#1372) --- .../kotlin/com/hippo/ehviewer/download/DownloadManager.kt | 4 ++++ .../kotlin/com/hippo/ehviewer/ui/settings/DownloadScreen.kt | 3 +++ 2 files changed, 7 insertions(+) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/download/DownloadManager.kt b/app/src/main/kotlin/com/hippo/ehviewer/download/DownloadManager.kt index c8a0168c7..30dbf64a7 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/download/DownloadManager.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/download/DownloadManager.kt @@ -834,6 +834,10 @@ var downloadLocation = with(Settings) { field = value } +fun invalidateDownloadDirCache() { + downloadLocation = downloadLocation.uri.asUniFile() +} + val DownloadInfo.downloadDir get() = dirname?.let { downloadLocation.findFile(it) } val DownloadInfo.archiveFile get() = downloadDir?.run { findFile("$gid.cbz") ?: findFile("$gid.zip") } val GalleryInfo.tempDownloadDir get() = AppConfig.getTempDir("$gid")?.asUniFile() diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/DownloadScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/DownloadScreen.kt index 76f244a72..64ad19385 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/DownloadScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/DownloadScreen.kt @@ -37,6 +37,7 @@ import com.hippo.ehviewer.dao.DownloadInfo import com.hippo.ehviewer.download.DownloadManager import com.hippo.ehviewer.download.downloadDir import com.hippo.ehviewer.download.downloadLocation +import com.hippo.ehviewer.download.invalidateDownloadDirCache import com.hippo.ehviewer.spider.COMIC_INFO_FILE import com.hippo.ehviewer.spider.SpiderDen import com.hippo.ehviewer.spider.SpiderQueen.Companion.SPIDER_INFO_FILENAME @@ -215,6 +216,8 @@ fun DownloadScreen(navigator: DestinationsNavigator) = composing(navigator) { }.getOrNull() } runSuspendCatching { + // Rescan download directory for new files added by the user + invalidateDownloadDirCache() val result = downloadLocation.listFiles().parMapNotNull { getRestoreItem(it) }.also { fillGalleryListByApi(it, EhUrl.referer) }