From 3a77e91bd998bc17a73c7551b81aa8f1ed14cc90 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Wed, 21 Feb 2018 06:27:35 +0100 Subject: [PATCH] Mark files that failed to download with an 'x' in the progress window. Also modified the legend to emphasize the fact that the file will again be tried to download during the next run. --- .../telegram_backup/CommandLineDownloadProgress.kt | 2 +- .../de/fabianonline/telegram_backup/DownloadManager.kt | 8 ++++++-- .../mediafilemanager/AbstractMediaFileManager.kt | 2 +- .../mediafilemanager/DocumentFileManager.kt | 3 ++- .../telegram_backup/mediafilemanager/GeoFileManager.kt | 4 ++-- .../telegram_backup/mediafilemanager/PhotoFileManager.kt | 5 +++-- .../mediafilemanager/StickerFileManager.kt | 6 +++--- .../mediafilemanager/UnsupportedFileManager.kt | 2 +- 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/CommandLineDownloadProgress.kt b/src/main/kotlin/de/fabianonline/telegram_backup/CommandLineDownloadProgress.kt index ac84c58..30acdba 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/CommandLineDownloadProgress.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/CommandLineDownloadProgress.kt @@ -51,7 +51,7 @@ internal class CommandLineDownloadProgress : DownloadProgressInterface { println("'S' - Sticker 'A' - Audio 'G' - Geolocation") println("'.' - Previously downloaded file 'e' - Empty file") println("' ' - Ignored media type (weblinks or contacts, for example)") - println("'x' - File skipped because of timeout errors") + println("'x' - File skipped because of errors - will be tried again at next run") println("" + count + " Files to check / download") } diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt index ca60e7e..4b745a1 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/DownloadManager.kt @@ -364,8 +364,12 @@ class DownloadManager(internal var client: TelegramClient?, p: DownloadProgressI prog!!.onMediaAlreadyPresent(m) } else { try { - m.download() - prog!!.onMediaDownloaded(m) + val result = m.download() + if (result) { + prog!!.onMediaDownloaded(m) + } else { + prog!!.onMediaSkipped() + } } catch (e: TimeoutException) { // do nothing - skip this file prog!!.onMediaSkipped() diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/AbstractMediaFileManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/AbstractMediaFileManager.kt index 605c220..68d495a 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/AbstractMediaFileManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/AbstractMediaFileManager.kt @@ -78,7 +78,7 @@ abstract class AbstractMediaFileManager(protected var message: TLMessage, protec abstract val name: String abstract val description: String @Throws(RpcErrorException::class, IOException::class, TimeoutException::class) - abstract fun download() + abstract fun download(): Boolean protected fun extensionFromMimetype(mime: String): String { when (mime) { diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/DocumentFileManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/DocumentFileManager.kt index bda9f1f..e032d9c 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/DocumentFileManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/DocumentFileManager.kt @@ -97,9 +97,10 @@ open class DocumentFileManager(msg: TLMessage, user: UserManager, client: Telegr } @Throws(RpcErrorException::class, IOException::class, TimeoutException::class) - override fun download() { + override fun download(): Boolean { if (doc != null) { DownloadManager.downloadFile(targetPathAndFilename, size, doc!!.getDcId(), doc!!.getId(), doc!!.getAccessHash()) } + return true } } diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/GeoFileManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/GeoFileManager.kt index b0e3f75..15726c8 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/GeoFileManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/GeoFileManager.kt @@ -72,11 +72,11 @@ class GeoFileManager(msg: TLMessage, user: UserManager, client: TelegramClient) } @Throws(IOException::class) - override fun download() { + override fun download(): Boolean { val url = "https://maps.googleapis.com/maps/api/staticmap?" + "center=" + geo.getLat() + "," + geo.getLong() + "&" + "zoom=14&size=300x150&scale=2&format=png&" + "key=" + Config.SECRET_GMAPS - DownloadManager.downloadExternalFile(targetPathAndFilename, url) + return DownloadManager.downloadExternalFile(targetPathAndFilename, url) } } diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/PhotoFileManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/PhotoFileManager.kt index eedffe4..e5c5c77 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/PhotoFileManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/PhotoFileManager.kt @@ -77,9 +77,10 @@ class PhotoFileManager(msg: TLMessage, user: UserManager, client: TelegramClient } @Throws(RpcErrorException::class, IOException::class, TimeoutException::class) - override fun download() { - if (isEmpty) return + override fun download(): Boolean { + if (isEmpty) return true val loc = photo_size.getLocation() as TLFileLocation DownloadManager.downloadFile(targetPathAndFilename, size, loc.getDcId(), loc.getVolumeId(), loc.getLocalId(), loc.getSecret()) + return true } } diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/StickerFileManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/StickerFileManager.kt index f0361a0..04f08b9 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/StickerFileManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/StickerFileManager.kt @@ -95,16 +95,16 @@ class StickerFileManager(msg: TLMessage, user: UserManager, client: TelegramClie get() = "Sticker" @Throws(RpcErrorException::class, IOException::class, TimeoutException::class) - override fun download() { + override fun download(): Boolean { val old_file = Config.FILE_BASE + File.separatorChar + Config.FILE_STICKER_BASE + File.separatorChar + targetFilename logger.trace("Old filename exists: {}", File(old_file).exists()) if (File(old_file).exists()) { Files.copy(Paths.get(old_file), Paths.get(targetPathAndFilename), StandardCopyOption.REPLACE_EXISTING) - return + return true } - super.download() + return super.download() } companion object { diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/UnsupportedFileManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/UnsupportedFileManager.kt index 928df48..dec94cf 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/UnsupportedFileManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/UnsupportedFileManager.kt @@ -54,5 +54,5 @@ class UnsupportedFileManager(msg: TLMessage, user: UserManager, client: Telegram override val letter = " " override val description = "Unsupported / non-downloadable Media" - override fun download() {} + override fun download(): Boolean = true }