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:
parent
4849cc6bd2
commit
a5c9411f29
@ -88,12 +88,25 @@ class DownloadCache(
|
|||||||
*
|
*
|
||||||
* @param manga the manga to check.
|
* @param manga the manga to check.
|
||||||
*/
|
*/
|
||||||
fun getDownloadCount(manga: Manga): Int {
|
fun getDownloadCount(manga: Manga, forceCheckFolder: Boolean = false): Int {
|
||||||
checkRenew()
|
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
|
val files = mangaFiles[manga.id] ?: return 0
|
||||||
return files.filter { !it.endsWith(Downloader.TMP_DIR_SUFFIX) }.size
|
return files.filter { !it.endsWith(Downloader.TMP_DIR_SUFFIX) }.size
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the cache needs a renewal and performs it if needed.
|
* Checks if the cache needs a renewal and performs it if needed.
|
||||||
@ -200,7 +213,7 @@ class DownloadCache(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*fun renameFolder(from: String, to: String, source: Long) {
|
/*fun renameFolder(from: String, to: String, source: Long) {
|
||||||
val sourceDir = rootDir.files[source] ?: return
|
val sourceDir = rootDir.files[source] ?: return
|
||||||
val list = sourceDir.files.toMutableMap()
|
val list = sourceDir.files.toMutableMap()
|
||||||
val mangaFiles = sourceDir.files[DiskUtil.buildValidFilename(from)] ?: return
|
val mangaFiles = sourceDir.files[DiskUtil.buildValidFilename(from)] ?: return
|
||||||
@ -211,7 +224,7 @@ class DownloadCache(
|
|||||||
list.remove(DiskUtil.buildValidFilename(from))
|
list.remove(DiskUtil.buildValidFilename(from))
|
||||||
list[to] = newDir
|
list[to] = newDir
|
||||||
sourceDir.files = list
|
sourceDir.files = list
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a manga that has been deleted from this cache.
|
* Removes a manga that has been deleted from this cache.
|
||||||
|
@ -247,7 +247,7 @@ class DownloadManager(val context: Context) {
|
|||||||
val chapterDirs = provider.findChapterDirs(chapters, manga, source) + provider.findTempChapterDirs(chapters, manga, source)
|
val chapterDirs = provider.findChapterDirs(chapters, manga, source) + provider.findTempChapterDirs(chapters, manga, source)
|
||||||
chapterDirs.forEach { it.delete() }
|
chapterDirs.forEach { it.delete() }
|
||||||
cache.removeChapters(chapters, manga)
|
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()
|
chapterDirs.firstOrNull()?.parentFile?.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user