1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-23 01:06:17 +00:00

Rewrote Utils.anonymize(String) to String.anonymize().

This commit is contained in:
Fabian Schlenz 2017-12-13 19:39:27 +01:00
parent 9bee01698f
commit ab6a30c48e
4 changed files with 22 additions and 21 deletions

View File

@ -88,7 +88,7 @@ class CommandLineController {
} }
if (account != null && user.loggedIn) { if (account != null && user.loggedIn) {
if (account != "+" + user.user!!.getPhone()) { if (account != "+" + user.user!!.getPhone()) {
logger.error("Account: {}, user.user!!.getPhone(): +{}", Utils.anonymize(account), Utils.anonymize(user.user!!.getPhone())) logger.error("Account: {}, user.user!!.getPhone(): +{}", account.anonymize(), user.user!!.getPhone().anonymize())
throw RuntimeException("Account / User mismatch") throw RuntimeException("Account / User mismatch")
} }
} }
@ -123,7 +123,7 @@ class CommandLineController {
} }
} }
if (user.loggedIn) { if (user.loggedIn) {
System.out.println("You are logged in as " + Utils.anonymize(user.userString)) System.out.println("You are logged in as ${user.userString.anonymize()}")
} else { } else {
println("You are not logged in.") println("You are not logged in.")
System.exit(1) System.exit(1)
@ -164,12 +164,12 @@ class CommandLineController {
} }
private fun setupFileBase() { private fun setupFileBase() {
logger.debug("Target dir at startup: {}", Utils.anonymize(Config.FILE_BASE)) logger.debug("Target dir at startup: {}", Config.FILE_BASE.anonymize())
if (CommandLineOptions.val_target != null) { if (CommandLineOptions.val_target != null) {
Config.FILE_BASE = CommandLineOptions.val_target!! Config.FILE_BASE = CommandLineOptions.val_target!!
} }
logger.debug("Target dir after options: {}", Utils.anonymize(Config.FILE_BASE)) logger.debug("Target dir after options: {}", Config.FILE_BASE.anonymize())
System.out.println("Base directory for files: " + Utils.anonymize(Config.FILE_BASE)) System.out.println("Base directory for files: " + Config.FILE_BASE.anonymize())
} }
private fun selectAccount(): String? { private fun selectAccount(): String? {
@ -179,11 +179,11 @@ class CommandLineController {
logger.debug("Login requested, doing nothing.") logger.debug("Login requested, doing nothing.")
// do nothing // do nothing
} else if (CommandLineOptions.val_account != null) { } else if (CommandLineOptions.val_account != null) {
logger.debug("Account requested: {}", Utils.anonymize(CommandLineOptions.val_account!!)) logger.debug("Account requested: {}", CommandLineOptions.val_account!!.anonymize())
logger.trace("Checking accounts for match.") logger.trace("Checking accounts for match.")
var found = false var found = false
for (acc in accounts) { for (acc in accounts) {
logger.trace("Checking {}", Utils.anonymize(acc)) logger.trace("Checking {}", acc.anonymize())
if (acc == CommandLineOptions.val_account) { if (acc == CommandLineOptions.val_account) {
found = true found = true
logger.trace("Matches.") logger.trace("Matches.")
@ -191,7 +191,7 @@ class CommandLineController {
} }
} }
if (!found) { if (!found) {
show_error("Couldn't find account '" + Utils.anonymize(CommandLineOptions.val_account!!) + "'. Maybe you want to use '--login' first?") show_error("Couldn't find account '" + CommandLineOptions.val_account!!.anonymize() + "'. Maybe you want to use '--login' first?")
} }
account = CommandLineOptions.val_account!! account = CommandLineOptions.val_account!!
} else if (accounts.size == 0) { } else if (accounts.size == 0) {
@ -200,7 +200,7 @@ class CommandLineController {
return null return null
} else if (accounts.size == 1) { } else if (accounts.size == 1) {
account = accounts.firstElement() account = accounts.firstElement()
System.out.println("Using only available account: " + Utils.anonymize(account)) System.out.println("Using only available account: " + account.anonymize())
} else { } else {
show_error(("You didn't specify which account to use.\n" + show_error(("You didn't specify which account to use.\n" +
"Use '--account <x>' to use account <x>.\n" + "Use '--account <x>' to use account <x>.\n" +
@ -208,7 +208,7 @@ class CommandLineController {
System.exit(1) System.exit(1)
} }
logger.debug("accounts.size: {}", accounts.size) logger.debug("accounts.size: {}", accounts.size)
logger.debug("account: {}", Utils.anonymize(account)) logger.debug("account: {}", account.anonymize())
return account return account
} }
@ -254,7 +254,7 @@ class CommandLineController {
user.verifyPassword(pw) user.verifyPassword(pw)
} }
storage.setPrefix("+" + user.user!!.getPhone()) storage.setPrefix("+" + user.user!!.getPhone())
System.out.println("Everything seems fine. Please run this tool again with '--account +" + Utils.anonymize(user.user!!.getPhone()) + " to use this account.") System.out.println("Everything seems fine. Please run this tool again with '--account +" + user.user!!.getPhone().anonymize() + " to use this account.")
} }
private fun show_help() { private fun show_help() {
@ -284,7 +284,7 @@ class CommandLineController {
val accounts = Utils.getAccounts() val accounts = Utils.getAccounts()
if (accounts.size > 0) { if (accounts.size > 0) {
for (str in accounts) { for (str in accounts) {
System.out.println(" " + Utils.anonymize(str)) System.out.println(" " + str.anonymize())
} }
println("Use '--account <x>' to use one of those accounts.") println("Use '--account <x>' to use one of those accounts.")
} else { } else {

View File

@ -18,6 +18,7 @@ package de.fabianonline.telegram_backup
import de.fabianonline.telegram_backup.DownloadProgressInterface import de.fabianonline.telegram_backup.DownloadProgressInterface
import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager
import de.fabianonline.telegram_backup.Utils
internal class CommandLineDownloadProgress : DownloadProgressInterface { internal class CommandLineDownloadProgress : DownloadProgressInterface {
private var mediaCount = 0 private var mediaCount = 0
@ -28,7 +29,7 @@ internal class CommandLineDownloadProgress : DownloadProgressInterface {
if (source == null) { if (source == null) {
System.out.println("Downloading $count messages.") System.out.println("Downloading $count messages.")
} else { } else {
System.out.println("Downloading " + count + " messages from " + Utils.anonymize(source)) System.out.println("Downloading " + count + " messages from " + source.anonymize())
} }
} }

View File

@ -176,8 +176,8 @@ object Utils {
logger.debug("We couldn't find a real difference, so we're assuming the versions are equal-ish.") logger.debug("We couldn't find a real difference, so we're assuming the versions are equal-ish.")
return VERSIONS_EQUAL return VERSIONS_EQUAL
} }
}
fun anonymize(str: String): String {
return if (!CommandLineOptions.cmd_anonymize) str else str.replace("[0-9]".toRegex(), "1").replace("[A-Z]".toRegex(), "A").replace("[a-z]".toRegex(), "a") + " (ANONYMIZED)" 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)"
} }

View File

@ -18,7 +18,7 @@ package de.fabianonline.telegram_backup.exporter
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.Utils import de.fabianonline.telegram_backup.anonymize
import java.io.File import java.io.File
import java.io.PrintWriter import java.io.PrintWriter
@ -100,7 +100,7 @@ class HTMLExporter {
println("Generating ${dialogs.size} dialog pages...") println("Generating ${dialogs.size} dialog pages...")
for (d in dialogs) { for (d in dialogs) {
i++ i++
logger.trace("Dialog {}/{}: {}", i, dialogs.size, Utils.anonymize("" + d.id)) logger.trace("Dialog {}/{}: {}", i, dialogs.size, d.id.toString().anonymize())
val messages = db.getMessagesForExport(d) val messages = db.getMessagesForExport(d)
scope.clear() scope.clear()
scope.put("user", user) scope.put("user", user)
@ -126,7 +126,7 @@ class HTMLExporter {
println("Generating ${chats.size} chat pages...") println("Generating ${chats.size} chat pages...")
for (c in chats) { for (c in chats) {
i++ i++
logger.trace("Chat {}/{}: {}", i, chats.size, Utils.anonymize("" + c.id)) logger.trace("Chat {}/{}: {}", i, chats.size, c.id.toString().anonymize())
val messages = db.getMessagesForExport(c) val messages = db.getMessagesForExport(c)
scope.clear() scope.clear()
scope.put("user", user) scope.put("user", user)
@ -164,7 +164,7 @@ class HTMLExporter {
@Throws(FileNotFoundException::class) @Throws(FileNotFoundException::class)
private fun getWriter(filename: String): OutputStreamWriter { private fun getWriter(filename: String): OutputStreamWriter {
logger.trace("Creating writer for file {}", Utils.anonymize(filename)) logger.trace("Creating writer for file {}", filename.anonymize())
return OutputStreamWriter(FileOutputStream(filename), Charset.forName("UTF-8").newEncoder()) return OutputStreamWriter(FileOutputStream(filename), Charset.forName("UTF-8").newEncoder())
} }