Rescan download directory when restoring downloads (#1372)

This commit is contained in:
FooIbar authored and GitHub committed 2024-07-02 05:50:20 +00:00
1 parent 673c1837e9
commit ee091aee0f
2 files changed
+7

No files matched your search

@@ -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()
@@ -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)
}