Cleanup Save as CBZ

This commit is contained in:
Jobobby04 2020-08-22 18:08:07 -04:00
parent 79e4e3d2a0
commit 3967a569c4
4 changed files with 19 additions and 15 deletions

View File

@ -81,7 +81,7 @@ class DownloadCache(
if (sourceDir != null) {
val mangaDir = sourceDir.files[provider.getMangaDirName(manga)]
if (mangaDir != null) {
return provider.getValidChapterDirNames(chapter).any { it in mangaDir.files }
return provider.getValidChapterDirNames(chapter).any { it in mangaDir.files || "$it.cbz" in mangaDir.files }
}
}
return false
@ -196,6 +196,8 @@ class DownloadCache(
provider.getValidChapterDirNames(chapter).forEach {
if (it in mangaDir.files) {
mangaDir.files -= it
} else if ("$it.cbz" in mangaDir.files) {
mangaDir.files -= "$it.cbz"
}
}
}
@ -226,6 +228,8 @@ class DownloadCache(
provider.getValidChapterDirNames(chapter).forEach {
if (it in mangaDir.files) {
mangaDir.files -= it
} else if ("$it.cbz" in mangaDir.files) {
mangaDir.files -= "$it.cbz"
}
}
}

View File

@ -287,12 +287,12 @@ class DownloadManager(/* SY private */ val context: Context) {
// Assume there's only 1 version of the chapter name formats present
val oldFolder = oldNames.asSequence()
.mapNotNull { mangaDir.findFile(it) }
.mapNotNull { mangaDir.findFile(it) ?: mangaDir.findFile("$it.cbz") }
.firstOrNull()
if (oldFolder?.renameTo(newName) == true) {
if (oldFolder?.renameTo(newName + if (oldFolder.name?.endsWith(".cbz") == true) ".cbz" else "") == true) {
cache.removeChapter(oldChapter, manga)
cache.addChapter(newName, mangaDir, manga)
cache.addChapter(newName + if (oldFolder.name?.endsWith(".cbz") == true) ".cbz" else "", mangaDir, manga)
} else {
Timber.e("Could not rename downloaded chapter: %s.", oldNames.joinToString())
}

View File

@ -60,7 +60,7 @@ class Downloader(
private val sourceManager: SourceManager
) {
private val preferences: PreferencesHelper = Injekt.get()
private val preferences: PreferencesHelper by injectLazy()
private val chapterCache: ChapterCache by injectLazy()
@ -473,14 +473,14 @@ class Downloader(
// Only rename the directory if it's downloaded.
if (download.status == Download.DOWNLOADED) {
mangaDir.findFile(dirname + ".tmp")?.delete()
if (preferences.saveChaptersAsCBZ().get()) {
val zip = mangaDir.createFile(dirname + ".tmp")
val zip = mangaDir.createFile("$dirname.cbz.tmp")
val zipOut = ZipOutputStream(BufferedOutputStream(zip.openOutputStream()))
val compressionLevel = preferences.saveChaptersAsCBZLevel().get()
zipOut.setLevel(preferences.saveChaptersAsCBZLevel().get())
zipOut.setLevel(compressionLevel)
if (preferences.saveChaptersAsCBZLevel().get() == 0) {
if (compressionLevel == 0) {
zipOut.setMethod(ZipEntry.STORED)
}
@ -488,7 +488,7 @@ class Downloader(
val input = img.openInputStream()
val data = input.readBytes()
val entry = ZipEntry(img.name)
if (preferences.saveChaptersAsCBZLevel().get() == 0) {
if (compressionLevel == 0) {
val crc = CRC32()
val size = img.length()
crc.update(data)
@ -501,7 +501,7 @@ class Downloader(
input.close()
}
zipOut.close()
zip.renameTo(dirname + ".cbz")
zip.renameTo("$dirname.cbz")
tmpDir.delete()
} else {
tmpDir.renameTo(dirname)

View File

@ -178,6 +178,10 @@
<string name="pref_source_navigation">Replace latest button</string>
<string name="pref_source_navigation_summery">Replace latest button with a custom browse view that includes both latest and browse</string>
<!-- Download settings -->
<string name="save_chapter_as_cbz">Save Chapters as CBZ</string>
<string name="save_chapter_as_cbz_level">CBZ Compression level</string>
<!-- Reader Settings -->
<string name="download_threads">Download threads</string>
<string name="download_threads_summary">Higher values can speed up image downloading significantly, but can also trigger bans. Recommended value is 2 or 3. Current value is: %s</string>
@ -478,8 +482,4 @@
<item quantity="other">%2$s, %1$d pages</item>
</plurals>
<string name="save_chapter_as_cbz">Save Chapters as CBZ</string>
<string name="save_chapter_as_cbz_level">CBZ Compression level</string>
</resources>