1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-12-26 06:45:33 +00:00

Added a test feature reachable by using --test 1 to test entries in a local cache4.db file for compatibility.

This commit is contained in:
Fabian Schlenz 2016-09-02 06:50:49 +02:00
parent 1d721323e3
commit 71fb63443b
4 changed files with 71 additions and 0 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ data/
.DS_Store
.idea
src/main/main.iml
cache4.*

View File

@ -128,6 +128,15 @@ public class CommandLineController {
}
}
if (CommandLineOptions.val_test != null) {
if (CommandLineOptions.val_test == 1) {
TestFeatures.test1();
} else {
System.out.println("Unknown test " + CommandLineOptions.val_test);
}
System.exit(1);
}
logger.debug("CommandLineOptions.val_export: {}", CommandLineOptions.val_export);
if (CommandLineOptions.val_export != null) {
if (CommandLineOptions.val_export.toLowerCase().equals("html")) {

View File

@ -33,6 +33,7 @@ class CommandLineOptions {
public static Integer val_limit_messages = null;
public static String val_target = null;
public static String val_export = null;
public static Integer val_test = null;
public static void parseOptions(String[] args) {
String last_cmd = null;
@ -51,6 +52,9 @@ class CommandLineOptions {
case "--export":
val_export = arg; break;
case "--test":
val_test = Integer.parseInt(arg); break;
}
last_cmd = null;
continue;
@ -101,6 +105,9 @@ class CommandLineOptions {
case "--no-media":
cmd_no_media = true; break;
case "--test":
last_cmd = "--test"; continue;
default:
throw new RuntimeException("Unknown command " + arg);

View File

@ -0,0 +1,54 @@
package de.fabianonline.telegram_backup;
import com.github.badoualy.telegram.tl.api.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.io.IOException;
class TestFeatures {
public static void test1() {
// Tests entries in a cache4.db in the current working directory for compatibility
try {
Class.forName("org.sqlite.JDBC");
} catch(ClassNotFoundException e) {
CommandLineController.show_error("Could not load jdbc-sqlite class.");
}
String path = "jdbc:sqlite:cache4.db";
Connection conn = null;
Statement stmt = null;
try {
conn = DriverManager.getConnection(path);
stmt = conn.createStatement();
} catch (SQLException e) {
CommandLineController.show_error("Could not connect to SQLITE database.");
}
int unsupported_constructor = 0;
int success = 0;
try {
ResultSet rs = stmt.executeQuery("SELECT data FROM messages");
while (rs.next()) {
try {
TLApiContext.getInstance().deserializeMessage(rs.getBytes(1));
} catch (com.github.badoualy.telegram.tl.exception.UnsupportedConstructorException e) {
unsupported_constructor++;
} catch (IOException e) {
System.out.println("IOException: " + e);
}
success++;
}
} catch (SQLException e) {
System.out.println("SQL exception: " + e);
}
System.out.println("Success: " + success);
System.out.println("Unsupported constructor: " + unsupported_constructor);
}
}