mirror of
https://github.com/fabianonline/telegram_backup.git
synced 2024-11-23 01:06:17 +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:
parent
1d721323e3
commit
71fb63443b
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ data/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.idea
|
.idea
|
||||||
src/main/main.iml
|
src/main/main.iml
|
||||||
|
cache4.*
|
||||||
|
@ -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);
|
logger.debug("CommandLineOptions.val_export: {}", CommandLineOptions.val_export);
|
||||||
if (CommandLineOptions.val_export != null) {
|
if (CommandLineOptions.val_export != null) {
|
||||||
if (CommandLineOptions.val_export.toLowerCase().equals("html")) {
|
if (CommandLineOptions.val_export.toLowerCase().equals("html")) {
|
||||||
|
@ -33,6 +33,7 @@ class CommandLineOptions {
|
|||||||
public static Integer val_limit_messages = null;
|
public static Integer val_limit_messages = null;
|
||||||
public static String val_target = null;
|
public static String val_target = null;
|
||||||
public static String val_export = null;
|
public static String val_export = null;
|
||||||
|
public static Integer val_test = null;
|
||||||
|
|
||||||
public static void parseOptions(String[] args) {
|
public static void parseOptions(String[] args) {
|
||||||
String last_cmd = null;
|
String last_cmd = null;
|
||||||
@ -51,6 +52,9 @@ class CommandLineOptions {
|
|||||||
|
|
||||||
case "--export":
|
case "--export":
|
||||||
val_export = arg; break;
|
val_export = arg; break;
|
||||||
|
|
||||||
|
case "--test":
|
||||||
|
val_test = Integer.parseInt(arg); break;
|
||||||
}
|
}
|
||||||
last_cmd = null;
|
last_cmd = null;
|
||||||
continue;
|
continue;
|
||||||
@ -102,6 +106,9 @@ class CommandLineOptions {
|
|||||||
case "--no-media":
|
case "--no-media":
|
||||||
cmd_no_media = true; break;
|
cmd_no_media = true; break;
|
||||||
|
|
||||||
|
case "--test":
|
||||||
|
last_cmd = "--test"; continue;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unknown command " + arg);
|
throw new RuntimeException("Unknown command " + arg);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user