mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 20:31:02 -05:00
Remove download source folder when empty (#7928)
This commit is contained in:
parent
da95ecb686
commit
5a320d87e8
2 changed files with 14 additions and 0 deletions
|
@ -6,6 +6,7 @@ import com.hippo.unifile.UniFile
|
||||||
import eu.kanade.domain.manga.model.Manga
|
import eu.kanade.domain.manga.model.Manga
|
||||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
|
@ -113,6 +114,15 @@ class DownloadCache(
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if source has download
|
||||||
|
*
|
||||||
|
* @param source the source to check.
|
||||||
|
*/
|
||||||
|
fun sourceHasDownload(source: Source): Boolean {
|
||||||
|
return rootDir.files[source.id]?.files?.size?.let { it > 0 } ?: false
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the cache needs a renewal and performs it if needed.
|
* Checks if the cache needs a renewal and performs it if needed.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -281,6 +281,10 @@ class DownloadManager(
|
||||||
cache.removeChapters(filteredChapters, manga)
|
cache.removeChapters(filteredChapters, manga)
|
||||||
if (cache.getDownloadCount(manga) == 0) { // Delete manga directory if empty
|
if (cache.getDownloadCount(manga) == 0) { // Delete manga directory if empty
|
||||||
chapterDirs.firstOrNull()?.parentFile?.delete()
|
chapterDirs.firstOrNull()?.parentFile?.delete()
|
||||||
|
cache.removeManga(manga)
|
||||||
|
}
|
||||||
|
if (!cache.sourceHasDownload(source)) { // Delete source directory if empty
|
||||||
|
provider.findSourceDir(source)?.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filteredChapters
|
return filteredChapters
|
||||||
|
|
Loading…
Reference in a new issue