1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-22 08:46:15 +00:00

WIP: Even moar rewriting.

This commit is contained in:
Fabian Schlenz 2018-03-20 06:44:36 +01:00
parent eea08a5559
commit ebff71b208
18 changed files with 83 additions and 263 deletions

View File

@ -30,6 +30,8 @@ import org.slf4j.LoggerFactory
import org.slf4j.Logger import org.slf4j.Logger
class CommandLineController(val options: CommandLineOptions) { class CommandLineController(val options: CommandLineOptions) {
val logger = LoggerFactory.getLogger(CommandLineController::class.java)
init { init {
val storage: ApiStorage val storage: ApiStorage
val app: TelegramApp val app: TelegramApp
@ -37,7 +39,7 @@ class CommandLineController(val options: CommandLineOptions) {
val file_base: String val file_base: String
val phone_number: String val phone_number: String
val handler: TelegramUpdateHandler val handler: TelegramUpdateHandler
val client: TelegramClient var client: TelegramClient
val user_manager: UserManager val user_manager: UserManager
val inisettings: IniSettings val inisettings: IniSettings
val database: Database val database: Database
@ -91,11 +93,8 @@ class CommandLineController(val options: CommandLineOptions) {
logger.info("Initializing ApiStorage") logger.info("Initializing ApiStorage")
storage = ApiStorage(file_base) storage = ApiStorage(file_base)
logger.info("Initializing TelegramUpdateHandler")
handler = TelegramUpdateHandler()
logger.info("Creating Client") logger.info("Creating Client")
client = Kotlogram.getDefaultClient(app, storage, Kotlogram.PROD_DC4, handler) client = Kotlogram.getDefaultClient(app, storage, Kotlogram.PROD_DC4, null)
// From now on we have a new catch-all-block that will terminate it's TelegramClient when an exception happens. // From now on we have a new catch-all-block that will terminate it's TelegramClient when an exception happens.
try { try {
@ -126,9 +125,9 @@ class CommandLineController(val options: CommandLineOptions) {
if (options.val_test != null) { if (options.val_test != null) {
if (options.val_test == 1) { if (options.val_test == 1) {
TestFeatures.test1() TestFeatures(database).test1()
} else if (options.val_test == 2) { } else if (options.val_test == 2) {
TestFeatures.test2() TestFeatures(database).test2()
} else { } else {
System.out.println("Unknown test " + options.val_test) System.out.println("Unknown test " + options.val_test)
} }
@ -139,7 +138,7 @@ class CommandLineController(val options: CommandLineOptions) {
logger.debug("options.val_export: {}", export) logger.debug("options.val_export: {}", export)
if (export != null) { if (export != null) {
if (export.toLowerCase().equals("html")) { if (export.toLowerCase().equals("html")) {
HTMLExporter().export() HTMLExporter(database, user_manager, ini=inisettings, file_base=file_base).export()
System.exit(0) System.exit(0)
} else { } else {
show_error("Unknown export format '${export}'.") show_error("Unknown export format '${export}'.")
@ -184,22 +183,24 @@ class CommandLineController(val options: CommandLineOptions) {
} else { } else {
println("Skipping media download because download_media is set to false.") println("Skipping media download because download_media is set to false.")
} }
if (options.cmd_daemon) {
logger.info("Initializing TelegramUpdateHandler")
handler = TelegramUpdateHandler(user_manager, database)
client.close()
logger.info("Creating new client")
client = Kotlogram.getDefaultClient(app, storage, Kotlogram.PROD_DC4, handler)
println("DAEMON mode requested - keeping running.")
}
} catch (e: Throwable) { } catch (e: Throwable) {
println("An error occured!") println("An error occured!")
e.printStackTrace() e.printStackTrace()
logger.error("Exception caught!", e) logger.error("Exception caught!", e)
// If we encountered an exception, we definitely don't want to start the daemon mode now.
options.cmd_daemon = false
} finally { } finally {
if (options.cmd_daemon) { client.close()
handler.activate() println()
println("DAEMON mode requested - keeping running.") println("----- EXIT -----")
} else { System.exit(0)
client.close()
println()
println("----- EXIT -----")
System.exit(0)
}
} }
} }

View File

@ -26,7 +26,6 @@ class CommandLineOptions(args: Array<String>) {
var cmd_version = false var cmd_version = false
var cmd_license = false var cmd_license = false
var cmd_daemon = false var cmd_daemon = false
var cmd_anonymize = false
var cmd_stats = false var cmd_stats = false
var cmd_list_channels = false var cmd_list_channels = false
var val_account: String? = null var val_account: String? = null
@ -84,7 +83,7 @@ class CommandLineOptions(args: Array<String>) {
last_cmd = "--test" last_cmd = "--test"
continue@loop continue@loop
} }
"--anonymize" -> cmd_anonymize = true "--anonymize" -> Utils.anonymize = true
"--stats" -> cmd_stats = true "--stats" -> cmd_stats = true
"--list-channels" -> cmd_list_channels = true "--list-channels" -> cmd_list_channels = true
else -> throw RuntimeException("Unknown command " + arg) else -> throw RuntimeException("Unknown command " + arg)

View File

@ -69,7 +69,7 @@ class Database constructor(val file_base: String, val user_manager: UserManager)
} }
// Run updates // Run updates
val updates = DatabaseUpdates(conn!!, this) val updates = DatabaseUpdates(conn, this)
updates.doUpdates() updates.doUpdates()
println("Database is ready.") println("Database is ready.")
@ -489,13 +489,7 @@ class Database constructor(val file_base: String, val user_manager: UserManager)
ps_insert_or_replace.close() ps_insert_or_replace.close()
} }
fun fetchSetting(key: String): String? { fun fetchSetting(key: String): String? = queryString("SELECT value FROM settings WHERE key='${key}'")
val rs = stmt.executeQuery("SELECT value FROM settings WHERE key='${key}'")
rs.next()
val result = rs.getString(1)
rs.close()
return result
}
fun saveSetting(key: String, value: String?) { fun saveSetting(key: String, value: String?) {
val ps = conn.prepareStatement("INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)") val ps = conn.prepareStatement("INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)")

View File

@ -18,7 +18,6 @@ package de.fabianonline.telegram_backup
import de.fabianonline.telegram_backup.UserManager import de.fabianonline.telegram_backup.UserManager
import de.fabianonline.telegram_backup.Database import de.fabianonline.telegram_backup.Database
import de.fabianonline.telegram_backup.StickerConverter
import de.fabianonline.telegram_backup.DownloadProgressInterface import de.fabianonline.telegram_backup.DownloadProgressInterface
import de.fabianonline.telegram_backup.mediafilemanager.FileManagerFactory import de.fabianonline.telegram_backup.mediafilemanager.FileManagerFactory
import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager

View File

@ -1,6 +1,15 @@
package de.fabianonline.telegram_backup package de.fabianonline.telegram_backup
import com.github.badoualy.telegram.api.Kotlogram
import com.github.badoualy.telegram.api.TelegramApp
import com.github.badoualy.telegram.api.TelegramClient
import com.github.badoualy.telegram.tl.api.TLUser
import com.github.badoualy.telegram.tl.api.account.TLPassword
import com.github.badoualy.telegram.tl.api.auth.TLSentCode import com.github.badoualy.telegram.tl.api.auth.TLSentCode
import com.github.badoualy.telegram.tl.core.TLBytes
import com.github.badoualy.telegram.tl.exception.RpcErrorException
import java.security.MessageDigest
import java.util.*
class LoginManager(val app: TelegramApp, val target_dir: String, val phoneToUse: String?) { class LoginManager(val app: TelegramApp, val target_dir: String, val phoneToUse: String?) {
fun run() { fun run() {
@ -31,7 +40,7 @@ class LoginManager(val app: TelegramApp, val target_dir: String, val phoneToUse:
val pw = getPassword() val pw = getPassword()
verify_password(client, pw) verify_password(client, pw)
} }
System.out.println("Everything seems fine. Please run this tool again with '--account +" + user.user!!.getPhone().anonymize() + " to use this account.") System.out.println("Everything seems fine. Please run this tool again with '--account ${phone} to use this account.")
} }
private fun send_code_to_phone_number(client: TelegramClient, phone: String): TLSentCode { private fun send_code_to_phone_number(client: TelegramClient, phone: String): TLSentCode {

View File

@ -1,52 +0,0 @@
/* Telegram_Backup
* Copyright (C) 2016 Fabian Schlenz
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
package de.fabianonline.telegram_backup
import com.github.badoualy.telegram.tl.api.*
import java.lang.StringBuilder
import java.io.File
object StickerConverter {
fun makeFilenameWithPath(attr: TLDocumentAttributeSticker): String {
val file = StringBuilder()
file.append(makePath())
file.append(makeFilename(attr))
return file.toString()
}
fun makeFilename(attr: TLDocumentAttributeSticker): String {
val file = StringBuilder()
if (attr.getStickerset() is TLInputStickerSetShortName) {
file.append((attr.getStickerset() as TLInputStickerSetShortName).getShortName())
} else if (attr.getStickerset() is TLInputStickerSetID) {
file.append((attr.getStickerset() as TLInputStickerSetID).getId())
}
file.append("_")
file.append(attr.getAlt().hashCode())
file.append(".webp")
return file.toString()
}
fun makePath(): String {
val path = Config.FILE_BASE +
File.separatorChar +
Config.FILE_STICKER_BASE +
File.separatorChar
File(path).mkdirs()
return path
}
}

View File

@ -26,48 +26,39 @@ import de.fabianonline.telegram_backup.Database
import de.fabianonline.telegram_backup.UserManager import de.fabianonline.telegram_backup.UserManager
import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager
import de.fabianonline.telegram_backup.mediafilemanager.FileManagerFactory import de.fabianonline.telegram_backup.mediafilemanager.FileManagerFactory
import org.slf4j.LoggerFactory
internal class TelegramUpdateHandler : UpdateCallback { internal class TelegramUpdateHandler(val user_manager: UserManager, val db: Database) : UpdateCallback {
private var user: UserManager? = null val logger = LoggerFactory.getLogger(TelegramUpdateHandler::class.java)
private var db: Database? = null
var debug = false
fun activate() {
this.user = UserManager.getInstance()
this.db = Database.getInstance()
}
override fun onUpdates(client: TelegramClient, updates: TLUpdates) { override fun onUpdates(client: TelegramClient, updates: TLUpdates) {
if (db == null) return
if (debug) System.out.println("onUpdates - " + updates.getUpdates().size + " Updates, " + updates.getUsers().size + " Users, " + updates.getChats().size + " Chats") logger.debug("onUpdates - " + updates.getUpdates().size + " Updates, " + updates.getUsers().size + " Users, " + updates.getChats().size + " Chats")
for (update in updates.getUpdates()) { for (update in updates.getUpdates()) {
processUpdate(update, client) processUpdate(update, client)
if (debug) System.out.println(" " + update.javaClass.getName()) logger.debug(" " + update.javaClass.getName())
} }
db!!.saveUsers(updates.getUsers()) db.saveUsers(updates.getUsers())
db!!.saveChats(updates.getChats()) db.saveChats(updates.getChats())
} }
override fun onUpdatesCombined(client: TelegramClient, updates: TLUpdatesCombined) { override fun onUpdatesCombined(client: TelegramClient, updates: TLUpdatesCombined) {
if (db == null) return logger.debug("onUpdatesCombined")
if (debug) System.out.println("onUpdatesCombined")
for (update in updates.getUpdates()) { for (update in updates.getUpdates()) {
processUpdate(update, client) processUpdate(update, client)
} }
db!!.saveUsers(updates.getUsers()) db.saveUsers(updates.getUsers())
db!!.saveChats(updates.getChats()) db.saveChats(updates.getChats())
} }
override fun onUpdateShort(client: TelegramClient, update: TLUpdateShort) { override fun onUpdateShort(client: TelegramClient, update: TLUpdateShort) {
if (db == null) return logger.debug("onUpdateShort")
if (debug) System.out.println("onUpdateShort")
processUpdate(update.getUpdate(), client) processUpdate(update.getUpdate(), client)
if (debug) System.out.println(" " + update.getUpdate().javaClass.getName()) logger.debug(" " + update.getUpdate().javaClass.getName())
} }
override fun onShortChatMessage(client: TelegramClient, message: TLUpdateShortChatMessage) { override fun onShortChatMessage(client: TelegramClient, message: TLUpdateShortChatMessage) {
if (db == null) return logger.debug("onShortChatMessage - " + message.getMessage())
if (debug) System.out.println("onShortChatMessage - " + message.getMessage())
val msg = TLMessage( val msg = TLMessage(
message.getOut(), message.getOut(),
message.getMentioned(), message.getMentioned(),
@ -85,21 +76,20 @@ internal class TelegramUpdateHandler : UpdateCallback {
message.getEntities(), null, null) message.getEntities(), null, null)
val vector = TLVector<TLAbsMessage>(TLAbsMessage::class.java) val vector = TLVector<TLAbsMessage>(TLAbsMessage::class.java)
vector.add(msg) vector.add(msg)
db!!.saveMessages(vector, Kotlogram.API_LAYER) db.saveMessages(vector, Kotlogram.API_LAYER)
System.out.print('.') System.out.print('.')
} }
override fun onShortMessage(client: TelegramClient, message: TLUpdateShortMessage) { override fun onShortMessage(client: TelegramClient, message: TLUpdateShortMessage) {
val m = message val m = message
if (db == null) return logger.debug("onShortMessage - " + m.getOut() + " - " + m.getUserId() + " - " + m.getMessage())
if (debug) System.out.println("onShortMessage - " + m.getOut() + " - " + m.getUserId() + " - " + m.getMessage())
val from_id: Int val from_id: Int
val to_id: Int val to_id: Int
if (m.getOut() == true) { if (m.getOut() == true) {
from_id = user!!.user!!.getId() from_id = user_manager.id
to_id = m.getUserId() to_id = m.getUserId()
} else { } else {
to_id = user!!.user!!.getId() to_id = user_manager.id
from_id = m.getUserId() from_id = m.getUserId()
} }
val msg = TLMessage( val msg = TLMessage(
@ -119,18 +109,16 @@ internal class TelegramUpdateHandler : UpdateCallback {
m.getEntities(), null, null) m.getEntities(), null, null)
val vector = TLVector<TLAbsMessage>(TLAbsMessage::class.java) val vector = TLVector<TLAbsMessage>(TLAbsMessage::class.java)
vector.add(msg) vector.add(msg)
db!!.saveMessages(vector, Kotlogram.API_LAYER) db.saveMessages(vector, Kotlogram.API_LAYER)
System.out.print('.') System.out.print('.')
} }
override fun onShortSentMessage(client: TelegramClient, message: TLUpdateShortSentMessage) { override fun onShortSentMessage(client: TelegramClient, message: TLUpdateShortSentMessage) {
if (db == null) return logger.debug("onShortSentMessage")
System.out.println("onShortSentMessage")
} }
override fun onUpdateTooLong(client: TelegramClient) { override fun onUpdateTooLong(client: TelegramClient) {
if (db == null) return logger.debug("onUpdateTooLong")
System.out.println("onUpdateTooLong")
} }
private fun processUpdate(update: TLAbsUpdate, client: TelegramClient) { private fun processUpdate(update: TLAbsUpdate, client: TelegramClient) {
@ -138,10 +126,10 @@ internal class TelegramUpdateHandler : UpdateCallback {
val abs_msg = update.getMessage() val abs_msg = update.getMessage()
val vector = TLVector<TLAbsMessage>(TLAbsMessage::class.java) val vector = TLVector<TLAbsMessage>(TLAbsMessage::class.java)
vector.add(abs_msg) vector.add(abs_msg)
db!!.saveMessages(vector, Kotlogram.API_LAYER) db.saveMessages(vector, Kotlogram.API_LAYER)
System.out.print('.') System.out.print('.')
if (abs_msg is TLMessage) { if (abs_msg is TLMessage) {
val fm = FileManagerFactory.getFileManager(abs_msg, user!!, client) val fm = FileManagerFactory.getFileManager(abs_msg, user_manager)
if (fm != null && !fm.isEmpty && !fm.downloaded) { if (fm != null && !fm.isEmpty && !fm.downloaded) {
try { try {
fm.download() fm.download()

View File

@ -10,7 +10,7 @@ import java.sql.ResultSet
import java.io.IOException import java.io.IOException
import java.nio.charset.Charset import java.nio.charset.Charset
internal object TestFeatures { internal class TestFeatures(val db: Database) {
fun test1() { fun test1() {
// Tests entries in a cache4.db in the current working directory for compatibility // Tests entries in a cache4.db in the current working directory for compatibility
try { try {
@ -24,31 +24,22 @@ internal object TestFeatures {
var conn: Connection var conn: Connection
var stmt: Statement? = null var stmt: Statement? = null
try { conn = DriverManager.getConnection(path)
conn = DriverManager.getConnection(path) stmt = conn.createStatement()
stmt = conn.createStatement()
} catch (e: SQLException) {
CommandLineController.show_error("Could not connect to SQLITE database.")
}
var unsupported_constructor = 0 var unsupported_constructor = 0
var success = 0 var success = 0
try { val rs = stmt.executeQuery("SELECT data FROM messages")
val rs = stmt!!.executeQuery("SELECT data FROM messages") while (rs.next()) {
while (rs.next()) { try {
try { TLApiContext.getInstance().deserializeMessage(rs.getBytes(1))
TLApiContext.getInstance().deserializeMessage(rs.getBytes(1)) } catch (e: com.github.badoualy.telegram.tl.exception.UnsupportedConstructorException) {
} catch (e: com.github.badoualy.telegram.tl.exception.UnsupportedConstructorException) { unsupported_constructor++
unsupported_constructor++ } catch (e: IOException) {
} catch (e: IOException) { System.out.println("IOException: " + e)
System.out.println("IOException: " + e)
}
success++
} }
} catch (e: SQLException) { success++
System.out.println("SQL exception: " + e)
} }
System.out.println("Success: " + success) System.out.println("Success: " + success)
@ -59,7 +50,6 @@ internal object TestFeatures {
// Prints system.encoding and default charset // Prints system.encoding and default charset
System.out.println("Default Charset: " + Charset.defaultCharset()) System.out.println("Default Charset: " + Charset.defaultCharset())
System.out.println("file.encoding: " + System.getProperty("file.encoding")) System.out.println("file.encoding: " + System.getProperty("file.encoding"))
val db = Database.getInstance()
System.out.println("Database encoding: " + db.getEncoding()) System.out.println("Database encoding: " + db.getEncoding())
} }
} }

View File

@ -48,7 +48,7 @@ class UserManager(val client: TelegramClient) {
tl_user = full_user.getUser().getAsUser() tl_user = full_user.getUser().getAsUser()
} }
fun toString(): String { override fun toString(): String {
val sb = StringBuilder() val sb = StringBuilder()
sb.append(tl_user.getFirstName() ?: "") sb.append(tl_user.getFirstName() ?: "")
if (tl_user.getLastName() != null) { if (tl_user.getLastName() != null) {

View File

@ -32,6 +32,8 @@ object Utils {
@JvmField public val VERSION_1_NEWER = 1 @JvmField public val VERSION_1_NEWER = 1
@JvmField public val VERSION_2_NEWER = 2 @JvmField public val VERSION_2_NEWER = 2
var anonymize = false
private val logger = LoggerFactory.getLogger(Utils::class.java) as Logger private val logger = LoggerFactory.getLogger(Utils::class.java) as Logger
fun print_accounts(file_base: String) { fun print_accounts(file_base: String) {
@ -193,7 +195,7 @@ object Utils {
} }
fun String.anonymize(): String { fun String.anonymize(): String {
return if (!CommandLineOptions.cmd_anonymize) this else this.replace(Regex("[0-9]"), "1").replace(Regex("[A-Z]"), "A").replace(Regex("[a-z]"), "a") + " (ANONYMIZED)" return if (Utils.anonymize) this else this.replace(Regex("[0-9]"), "1").replace(Regex("[A-Z]"), "A").replace(Regex("[a-z]"), "a") + " (ANONYMIZED)"
} }
fun Any.toJson(): String = Gson().toJson(this) fun Any.toJson(): String = Gson().toJson(this)

View File

@ -37,18 +37,15 @@ import de.fabianonline.telegram_backup.*
import org.slf4j.Logger import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
class HTMLExporter { class HTMLExporter(val db: Database, val user: UserManager, val ini: IniSettings, val file_base: String) {
val db = Database.getInstance()
val user = UserManager.getInstance()
@Throws(IOException::class) @Throws(IOException::class)
fun export() { fun export() {
try { try {
val pagination = if (IniSettings.pagination) IniSettings.pagination_size else -1 val pagination = if (ini.pagination) ini.pagination_size else -1
// Create base dir // Create base dir
logger.debug("Creating base dir") logger.debug("Creating base dir")
val base = user.fileBase + "files" + File.separatorChar val base = file_base + "files" + File.separatorChar
File(base).mkdirs() File(base).mkdirs()
File(base + "dialogs").mkdirs() File(base + "dialogs").mkdirs()

View File

@ -17,33 +17,16 @@
package de.fabianonline.telegram_backup.mediafilemanager package de.fabianonline.telegram_backup.mediafilemanager
import de.fabianonline.telegram_backup.UserManager import de.fabianonline.telegram_backup.UserManager
import de.fabianonline.telegram_backup.Database
import de.fabianonline.telegram_backup.StickerConverter
import de.fabianonline.telegram_backup.DownloadProgressInterface
import de.fabianonline.telegram_backup.Config import de.fabianonline.telegram_backup.Config
import de.fabianonline.telegram_backup.DownloadManager
import com.github.badoualy.telegram.api.TelegramClient
import com.github.badoualy.telegram.tl.core.TLIntVector
import com.github.badoualy.telegram.tl.core.TLObject
import com.github.badoualy.telegram.tl.api.messages.TLAbsMessages
import com.github.badoualy.telegram.tl.api.messages.TLAbsDialogs
import com.github.badoualy.telegram.tl.api.* import com.github.badoualy.telegram.tl.api.*
import com.github.badoualy.telegram.tl.api.upload.TLFile
import com.github.badoualy.telegram.tl.exception.RpcErrorException import com.github.badoualy.telegram.tl.exception.RpcErrorException
import com.github.badoualy.telegram.tl.api.request.TLRequestUploadGetFile
import java.io.IOException import java.io.IOException
import java.io.File import java.io.File
import java.io.FileOutputStream
import java.util.ArrayList
import java.util.LinkedList
import java.net.URL
import java.util.concurrent.TimeoutException import java.util.concurrent.TimeoutException
import org.apache.commons.io.FileUtils abstract class AbstractMediaFileManager(protected var message: TLMessage, protected var user: UserManager, val file_base: String) {
abstract class AbstractMediaFileManager(protected var message: TLMessage, protected var user: UserManager) {
open var isEmpty = false open var isEmpty = false
abstract val size: Int abstract val size: Int
abstract val extension: String abstract val extension: String
@ -56,7 +39,7 @@ abstract class AbstractMediaFileManager(protected var message: TLMessage, protec
open val targetPath: String open val targetPath: String
get() { get() {
val path = user.fileBase + Config.FILE_FILES_BASE + File.separatorChar val path = file_base + Config.FILE_FILES_BASE + File.separatorChar
File(path).mkdirs() File(path).mkdirs()
return path return path
} }

View File

@ -17,32 +17,15 @@
package de.fabianonline.telegram_backup.mediafilemanager package de.fabianonline.telegram_backup.mediafilemanager
import de.fabianonline.telegram_backup.UserManager import de.fabianonline.telegram_backup.UserManager
import de.fabianonline.telegram_backup.Database
import de.fabianonline.telegram_backup.StickerConverter
import de.fabianonline.telegram_backup.DownloadProgressInterface
import de.fabianonline.telegram_backup.DownloadManager import de.fabianonline.telegram_backup.DownloadManager
import com.github.badoualy.telegram.api.TelegramClient
import com.github.badoualy.telegram.tl.core.TLIntVector
import com.github.badoualy.telegram.tl.core.TLObject
import com.github.badoualy.telegram.tl.api.messages.TLAbsMessages
import com.github.badoualy.telegram.tl.api.messages.TLAbsDialogs
import com.github.badoualy.telegram.tl.api.* import com.github.badoualy.telegram.tl.api.*
import com.github.badoualy.telegram.tl.api.upload.TLFile
import com.github.badoualy.telegram.tl.exception.RpcErrorException import com.github.badoualy.telegram.tl.exception.RpcErrorException
import com.github.badoualy.telegram.tl.api.request.TLRequestUploadGetFile
import java.io.IOException import java.io.IOException
import java.io.File
import java.io.FileOutputStream
import java.util.ArrayList
import java.util.LinkedList
import java.net.URL
import java.util.concurrent.TimeoutException import java.util.concurrent.TimeoutException
import org.apache.commons.io.FileUtils open class DocumentFileManager(msg: TLMessage, user: UserManager, file_base: String) : AbstractMediaFileManager(msg, user, file_base) {
open class DocumentFileManager(msg: TLMessage, user: UserManager) : AbstractMediaFileManager(msg, user) {
protected var doc: TLDocument? = null protected var doc: TLDocument? = null
override lateinit var extension: String override lateinit var extension: String

View File

@ -18,7 +18,6 @@ package de.fabianonline.telegram_backup.mediafilemanager
import de.fabianonline.telegram_backup.UserManager import de.fabianonline.telegram_backup.UserManager
import de.fabianonline.telegram_backup.Database import de.fabianonline.telegram_backup.Database
import de.fabianonline.telegram_backup.StickerConverter
import de.fabianonline.telegram_backup.DownloadProgressInterface import de.fabianonline.telegram_backup.DownloadProgressInterface
import com.github.badoualy.telegram.api.TelegramClient import com.github.badoualy.telegram.api.TelegramClient

View File

@ -17,33 +17,15 @@
package de.fabianonline.telegram_backup.mediafilemanager package de.fabianonline.telegram_backup.mediafilemanager
import de.fabianonline.telegram_backup.UserManager import de.fabianonline.telegram_backup.UserManager
import de.fabianonline.telegram_backup.Database
import de.fabianonline.telegram_backup.StickerConverter
import de.fabianonline.telegram_backup.DownloadProgressInterface
import de.fabianonline.telegram_backup.DownloadManager import de.fabianonline.telegram_backup.DownloadManager
import de.fabianonline.telegram_backup.IniSettings import de.fabianonline.telegram_backup.IniSettings
import com.github.badoualy.telegram.api.TelegramClient
import com.github.badoualy.telegram.tl.core.TLIntVector
import com.github.badoualy.telegram.tl.core.TLObject
import com.github.badoualy.telegram.tl.api.messages.TLAbsMessages
import com.github.badoualy.telegram.tl.api.messages.TLAbsDialogs
import com.github.badoualy.telegram.tl.api.* import com.github.badoualy.telegram.tl.api.*
import com.github.badoualy.telegram.tl.api.upload.TLFile
import com.github.badoualy.telegram.tl.exception.RpcErrorException
import com.github.badoualy.telegram.tl.api.request.TLRequestUploadGetFile
import java.io.IOException import java.io.IOException
import java.io.File import java.io.File
import java.io.FileOutputStream
import java.util.ArrayList
import java.util.LinkedList
import java.net.URL
import java.util.concurrent.TimeoutException
import org.apache.commons.io.FileUtils class GeoFileManager(msg: TLMessage, user: UserManager, file_base: String) : AbstractMediaFileManager(msg, user, file_base) {
class GeoFileManager(msg: TLMessage, user: UserManager) : AbstractMediaFileManager(msg, user) {
protected lateinit var geo: TLGeoPoint protected lateinit var geo: TLGeoPoint
// We don't know the size, so we just guess. // We don't know the size, so we just guess.

View File

@ -17,32 +17,15 @@
package de.fabianonline.telegram_backup.mediafilemanager package de.fabianonline.telegram_backup.mediafilemanager
import de.fabianonline.telegram_backup.UserManager import de.fabianonline.telegram_backup.UserManager
import de.fabianonline.telegram_backup.Database
import de.fabianonline.telegram_backup.StickerConverter
import de.fabianonline.telegram_backup.DownloadProgressInterface
import de.fabianonline.telegram_backup.DownloadManager import de.fabianonline.telegram_backup.DownloadManager
import com.github.badoualy.telegram.api.TelegramClient
import com.github.badoualy.telegram.tl.core.TLIntVector
import com.github.badoualy.telegram.tl.core.TLObject
import com.github.badoualy.telegram.tl.api.messages.TLAbsMessages
import com.github.badoualy.telegram.tl.api.messages.TLAbsDialogs
import com.github.badoualy.telegram.tl.api.* import com.github.badoualy.telegram.tl.api.*
import com.github.badoualy.telegram.tl.api.upload.TLFile
import com.github.badoualy.telegram.tl.exception.RpcErrorException import com.github.badoualy.telegram.tl.exception.RpcErrorException
import com.github.badoualy.telegram.tl.api.request.TLRequestUploadGetFile
import java.io.IOException import java.io.IOException
import java.io.File
import java.io.FileOutputStream
import java.util.ArrayList
import java.util.LinkedList
import java.net.URL
import java.util.concurrent.TimeoutException import java.util.concurrent.TimeoutException
import org.apache.commons.io.FileUtils class PhotoFileManager(msg: TLMessage, user: UserManager, file_base: String) : AbstractMediaFileManager(msg, user, file_base) {
class PhotoFileManager(msg: TLMessage, user: UserManager) : AbstractMediaFileManager(msg, user) {
private lateinit var photo: TLPhoto private lateinit var photo: TLPhoto
override var size = 0 override var size = 0
private lateinit var photo_size: TLPhotoSize private lateinit var photo_size: TLPhotoSize

View File

@ -18,7 +18,6 @@ package de.fabianonline.telegram_backup.mediafilemanager
import de.fabianonline.telegram_backup.UserManager import de.fabianonline.telegram_backup.UserManager
import de.fabianonline.telegram_backup.Database import de.fabianonline.telegram_backup.Database
import de.fabianonline.telegram_backup.StickerConverter
import de.fabianonline.telegram_backup.DownloadProgressInterface import de.fabianonline.telegram_backup.DownloadProgressInterface
import de.fabianonline.telegram_backup.DownloadManager import de.fabianonline.telegram_backup.DownloadManager
import de.fabianonline.telegram_backup.Config import de.fabianonline.telegram_backup.Config
@ -50,7 +49,7 @@ import java.util.concurrent.TimeoutException
import org.apache.commons.io.FileUtils import org.apache.commons.io.FileUtils
class StickerFileManager(msg: TLMessage, user: UserManager) : DocumentFileManager(msg, user) { class StickerFileManager(msg: TLMessage, user: UserManager, file_base: String) : DocumentFileManager(msg, user, file_base) {
override val isSticker = true override val isSticker = true
@ -80,7 +79,7 @@ class StickerFileManager(msg: TLMessage, user: UserManager) : DocumentFileManage
override val targetPath: String override val targetPath: String
get() { get() {
val path = user.fileBase + Config.FILE_FILES_BASE + File.separatorChar + Config.FILE_STICKER_BASE + File.separatorChar val path = file_base + Config.FILE_FILES_BASE + File.separatorChar + Config.FILE_STICKER_BASE + File.separatorChar
File(path).mkdirs() File(path).mkdirs()
return path return path
} }
@ -94,19 +93,6 @@ class StickerFileManager(msg: TLMessage, user: UserManager) : DocumentFileManage
override val description: String override val description: String
get() = "Sticker" get() = "Sticker"
@Throws(RpcErrorException::class, IOException::class, TimeoutException::class)
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 true
}
return super.download()
}
companion object { companion object {
private val logger = LoggerFactory.getLogger(StickerFileManager::class.java) private val logger = LoggerFactory.getLogger(StickerFileManager::class.java)
} }

View File

@ -17,33 +17,10 @@
package de.fabianonline.telegram_backup.mediafilemanager package de.fabianonline.telegram_backup.mediafilemanager
import de.fabianonline.telegram_backup.UserManager import de.fabianonline.telegram_backup.UserManager
import de.fabianonline.telegram_backup.Database
import de.fabianonline.telegram_backup.StickerConverter
import de.fabianonline.telegram_backup.DownloadProgressInterface
import de.fabianonline.telegram_backup.DownloadManager
import de.fabianonline.telegram_backup.Config
import com.github.badoualy.telegram.api.TelegramClient
import com.github.badoualy.telegram.tl.core.TLIntVector
import com.github.badoualy.telegram.tl.core.TLObject
import com.github.badoualy.telegram.tl.api.messages.TLAbsMessages
import com.github.badoualy.telegram.tl.api.messages.TLAbsDialogs
import com.github.badoualy.telegram.tl.api.* import com.github.badoualy.telegram.tl.api.*
import com.github.badoualy.telegram.tl.api.upload.TLFile
import com.github.badoualy.telegram.tl.exception.RpcErrorException
import com.github.badoualy.telegram.tl.api.request.TLRequestUploadGetFile
import java.io.IOException class UnsupportedFileManager(msg: TLMessage, user: UserManager, type: String, file_base: String) : AbstractMediaFileManager(msg, user, file_base) {
import java.io.File
import java.io.FileOutputStream
import java.util.ArrayList
import java.util.LinkedList
import java.net.URL
import java.util.concurrent.TimeoutException
import org.apache.commons.io.FileUtils
class UnsupportedFileManager(msg: TLMessage, user: UserManager, type: String) : AbstractMediaFileManager(msg, user) {
override var name = type override var name = type
override val targetFilename = "" override val targetFilename = ""
override val targetPath = "" override val targetPath = ""