2017-12-07 07:00:18 +00:00
|
|
|
/* 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 de.fabianonline.telegram_backup.CommandLineController
|
|
|
|
import de.fabianonline.telegram_backup.Utils
|
|
|
|
import de.fabianonline.telegram_backup.Version
|
2018-03-08 21:13:30 +00:00
|
|
|
import java.util.concurrent.TimeUnit
|
2017-12-07 07:00:18 +00:00
|
|
|
import org.slf4j.LoggerFactory
|
|
|
|
import ch.qos.logback.classic.Logger
|
|
|
|
import ch.qos.logback.classic.LoggerContext
|
|
|
|
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
|
|
|
|
import ch.qos.logback.classic.spi.ILoggingEvent
|
|
|
|
import ch.qos.logback.core.ConsoleAppender
|
|
|
|
import ch.qos.logback.classic.Level
|
|
|
|
|
2017-12-12 21:04:20 +00:00
|
|
|
fun main(args: Array<String>) {
|
2018-03-16 05:59:18 +00:00
|
|
|
val clr = CommandLineRunner(args)
|
|
|
|
|
|
|
|
clr.setupLogging()
|
|
|
|
clr.checkVersion()
|
|
|
|
clr.run()
|
|
|
|
}
|
2017-12-07 07:00:18 +00:00
|
|
|
|
2018-03-16 05:59:18 +00:00
|
|
|
class CommandLineRunner(args: Array<String>) {
|
|
|
|
val logger = LoggerFactory.getLogger(CommandLineRunner::class.java) as Logger
|
|
|
|
val options = CommandLineOptions(args)
|
|
|
|
|
|
|
|
fun run() {
|
2017-12-12 21:04:20 +00:00
|
|
|
// Always use the console for now.
|
2018-03-16 05:59:18 +00:00
|
|
|
try {
|
|
|
|
CommandLineController(options)
|
|
|
|
} catch (e: Throwable) {
|
|
|
|
println("An error occured!")
|
|
|
|
e.printStackTrace()
|
|
|
|
logger.error("Exception caught!", e)
|
|
|
|
System.exit(1)
|
|
|
|
}
|
2017-12-12 21:04:20 +00:00
|
|
|
}
|
2018-03-16 05:59:18 +00:00
|
|
|
|
2017-12-12 21:04:20 +00:00
|
|
|
fun setupLogging() {
|
2018-04-06 04:19:49 +00:00
|
|
|
if (options.booleans.hasKey('anonymize')) {
|
|
|
|
Utils.anonymize = true
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 21:04:20 +00:00
|
|
|
logger.trace("Setting up Loggers...")
|
|
|
|
val rootLogger = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME) as Logger
|
|
|
|
val rootContext = rootLogger.getLoggerContext()
|
|
|
|
rootContext.reset()
|
2017-12-07 07:00:18 +00:00
|
|
|
|
2017-12-12 21:04:20 +00:00
|
|
|
val encoder = PatternLayoutEncoder()
|
|
|
|
encoder.setContext(rootContext)
|
|
|
|
encoder.setPattern("%d{HH:mm:ss.SSS} %-5level %-35.-35(%logger{0}.%method): %message%n")
|
|
|
|
encoder.start()
|
2017-12-07 07:00:18 +00:00
|
|
|
|
2017-12-12 21:04:20 +00:00
|
|
|
val appender = ConsoleAppender<ILoggingEvent>()
|
|
|
|
appender.setContext(rootContext)
|
|
|
|
appender.setEncoder(encoder)
|
|
|
|
appender.start()
|
2017-12-07 07:00:18 +00:00
|
|
|
|
2017-12-12 21:04:20 +00:00
|
|
|
rootLogger.addAppender(appender)
|
|
|
|
rootLogger.setLevel(Level.OFF)
|
2017-12-07 07:00:18 +00:00
|
|
|
|
2018-03-16 05:59:18 +00:00
|
|
|
if (options.cmd_trace) {
|
2017-12-12 21:04:20 +00:00
|
|
|
(LoggerFactory.getLogger("de.fabianonline.telegram_backup") as Logger).setLevel(Level.TRACE)
|
2018-03-16 05:59:18 +00:00
|
|
|
} else if (options.cmd_debug) {
|
2017-12-12 21:04:20 +00:00
|
|
|
(LoggerFactory.getLogger("de.fabianonline.telegram_backup") as Logger).setLevel(Level.DEBUG)
|
|
|
|
}
|
2017-12-07 07:00:18 +00:00
|
|
|
|
2018-03-16 05:59:18 +00:00
|
|
|
if (options.cmd_trace_telegram) {
|
2017-12-12 21:04:20 +00:00
|
|
|
(LoggerFactory.getLogger("com.github.badoualy") as Logger).setLevel(Level.TRACE)
|
|
|
|
}
|
|
|
|
}
|
2017-12-07 07:00:18 +00:00
|
|
|
|
2017-12-12 21:04:20 +00:00
|
|
|
fun checkVersion(): Boolean {
|
|
|
|
val v = Utils.getNewestVersion()
|
|
|
|
if (v != null && v.isNewer) {
|
2018-03-08 21:13:30 +00:00
|
|
|
println()
|
|
|
|
println()
|
|
|
|
println()
|
|
|
|
println("A newer version is vailable!")
|
|
|
|
println("You are using: " + Config.APP_APPVER)
|
|
|
|
println("Available: " + v.version)
|
|
|
|
println("Get it here: " + v.url)
|
|
|
|
println()
|
|
|
|
println()
|
|
|
|
println("Changes in this version:")
|
|
|
|
println(v.body)
|
|
|
|
println()
|
|
|
|
println()
|
|
|
|
println()
|
|
|
|
TimeUnit.SECONDS.sleep(5)
|
2017-12-12 21:04:20 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2017-12-07 07:00:18 +00:00
|
|
|
}
|