switch to check folders for downloads whenever delete chapters is called so the manga folder doesnt get deleted by accident

This commit is contained in:
Carlos 2020-05-24 12:30:06 -04:00 committed by Jay
parent 4849cc6bd2
commit a5c9411f29
2 changed files with 38 additions and 25 deletions

View File

@ -88,12 +88,25 @@ class DownloadCache(
*
* @param manga the manga to check.
*/
fun getDownloadCount(manga: Manga): Int {
fun getDownloadCount(manga: Manga, forceCheckFolder: Boolean = false): Int {
checkRenew()
if (forceCheckFolder) {
val mangaDir = provider.findMangaDir(manga, sourceManager.getMangadex())
if (mangaDir != null) {
val listFiles = mangaDir.listFiles { dir, filename -> !filename.endsWith(Downloader.TMP_DIR_SUFFIX) }
if (!listFiles.isNullOrEmpty()) {
return listFiles.size
}
}
return 0
} else {
val files = mangaFiles[manga.id] ?: return 0
return files.filter { !it.endsWith(Downloader.TMP_DIR_SUFFIX) }.size
}
}
/**
* Checks if the cache needs a renewal and performs it if needed.

View File

@ -247,7 +247,7 @@ class DownloadManager(val context: Context) {
val chapterDirs = provider.findChapterDirs(chapters, manga, source) + provider.findTempChapterDirs(chapters, manga, source)
chapterDirs.forEach { it.delete() }
cache.removeChapters(chapters, manga)
if (cache.getDownloadCount(manga) == 0) { // Delete manga directory if empty
if (cache.getDownloadCount(manga, true) == 0) { // Delete manga directory if empty
chapterDirs.firstOrNull()?.parentFile?.delete()
}
}