Initial save downloaded gallery as cbz archive (#808)
* Initial save downloaded gallery as cbz archive * Make save as cbz archive opt-in
This commit is contained in:
1 parent
284fb4242b
commit
d0fbb3539f
7 files changed
+39
-1
No files matched your search
@@ -152,6 +152,7 @@ object Settings : DataStorePreferences(null) {
|
||||
var harmonizeCategoryColor by boolPref("harmonize_category_color", true)
|
||||
var preloadThumbAggressively by boolPref("preload_thumb_aggressively", false)
|
||||
var downloadOriginImage by boolPref("download_origin_image", false)
|
||||
var saveAsCbz by boolPref("save_as_cbz", false)
|
||||
var archiveMetadata by boolPref("archive_metadata", true)
|
||||
var enableCronet by boolPref("enable_cronet", true)
|
||||
var recentFavCat by intPref("recent_fav_cat", FavListUrlBuilder.FAV_CAT_LOCAL)
|
||||
|
||||
@@ -612,6 +612,10 @@ object DownloadManager : OnSpiderListener, CoroutineScope {
|
||||
mCurrentSpider?.let { spider ->
|
||||
mCurrentSpider = null
|
||||
spider.removeOnSpiderListener(DownloadManager)
|
||||
if (finished == total && Settings.saveAsCbz) {
|
||||
// Delay file deletion to `SpiderQueen.stop` as they may still be in use by reader
|
||||
spider.mSpiderDen.archive()
|
||||
}
|
||||
SpiderQueen.releaseSpiderQueen(spider, SpiderQueen.MODE_DOWNLOAD)
|
||||
}
|
||||
mCurrentTask?.let { info ->
|
||||
|
||||
@@ -238,6 +238,22 @@ class SpiderDen(val info: GalleryInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun archive() {
|
||||
downloadDir?.run {
|
||||
val filename = "${info.gid}.cbz"
|
||||
findFile(filename) ?: createFile(filename)?.let { file ->
|
||||
runCatching {
|
||||
val success = exportAsCbz(file)
|
||||
check(success)
|
||||
}.onFailure {
|
||||
logcat(it)
|
||||
file.delete()
|
||||
throw it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun exportAsCbz(file: UniFile) = resourceScope {
|
||||
val comicInfo = closeable {
|
||||
val f = downloadDir!! / COMIC_INFO_FILE
|
||||
|
||||
@@ -242,7 +242,17 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
|
||||
launchIO {
|
||||
queenScope.cancel()
|
||||
runCatching {
|
||||
writeSpiderInfoToLocal()
|
||||
val dir = mSpiderDen.downloadDir
|
||||
if (Settings.saveAsCbz && dir?.findFile("${galleryInfo.gid}.cbz") != null) {
|
||||
dir.listFiles().forEach {
|
||||
if (it.name?.matches(filenamePattern) == true) {
|
||||
it.delete()
|
||||
}
|
||||
}
|
||||
dir.findFile(SPIDER_INFO_FILENAME)?.delete()
|
||||
} else {
|
||||
writeSpiderInfoToLocal()
|
||||
}
|
||||
}.onFailure {
|
||||
logcat(it)
|
||||
}
|
||||
@@ -469,6 +479,7 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
|
||||
const val STATE_FAILED = 3
|
||||
const val SPIDER_INFO_FILENAME = ".ehviewer"
|
||||
private val sQueenMap = LongSparseArray<SpiderQueen>()
|
||||
private val filenamePattern = Regex("^\\d{8}\\.\\w{3,4}")
|
||||
|
||||
fun obtainSpiderQueen(galleryInfo: GalleryInfo, @Mode mode: Int): SpiderQueen {
|
||||
val gid = galleryInfo.gid
|
||||
|
||||
@@ -146,6 +146,10 @@ fun DownloadScreen(navigator: DestinationsNavigator) {
|
||||
summary = stringResource(id = R.string.settings_download_download_origin_image_summary),
|
||||
value = Settings::downloadOriginImage,
|
||||
)
|
||||
SwitchPreference(
|
||||
title = stringResource(id = R.string.settings_download_save_as_cbz),
|
||||
value = Settings::saveAsCbz,
|
||||
)
|
||||
SwitchPreference(
|
||||
title = stringResource(id = R.string.settings_download_archive_metadata),
|
||||
summary = stringResource(id = R.string.settings_download_archive_metadata_summary),
|
||||
|
||||
@@ -330,6 +330,7 @@
|
||||
<string name="settings_download_preload_image_summary">向后预载 %s 张图片</string>
|
||||
<string name="settings_download_download_origin_image">下载原图</string>
|
||||
<string name="settings_download_download_origin_image_summary">警告!可能需要 GP</string>
|
||||
<string name="settings_download_save_as_cbz">保存为 CBZ 压缩包</string>
|
||||
<string name="settings_download_archive_metadata">压缩包元数据</string>
|
||||
<string name="settings_download_archive_metadata_summary">下载压缩包时生成 ComicInfo.xml</string>
|
||||
<string name="settings_download_media_scan">允许媒体扫描</string>
|
||||
|
||||
@@ -377,6 +377,7 @@
|
||||
<string name="settings_download_preload_image_summary">Preload next %s image</string>
|
||||
<string name="settings_download_download_origin_image">Download original image</string>
|
||||
<string name="settings_download_download_origin_image_summary">Caution! May require GP</string>
|
||||
<string name="settings_download_save_as_cbz">Save as CBZ archive</string>
|
||||
<string name="settings_download_archive_metadata">Archive metadata</string>
|
||||
<string name="settings_download_archive_metadata_summary">Generate ComicInfo.xml on archive download</string>
|
||||
<string name="settings_download_restore_download_items">Restore download items</string>
|
||||
|
||||
Reference in new issue
Block a user