Add workaround for telepathy haze
Use home directory for storing configs, in case purple settings are in a tmp directory
This commit is contained in:
parent
6e501a2a56
commit
6614c25cbc
3 changed files with 44 additions and 15 deletions
|
@ -386,6 +386,41 @@ void read_secret_chat_file (struct tgl_state *TLS) {
|
|||
close (secret_chat_fd);
|
||||
}
|
||||
|
||||
gchar *get_config_dir (struct tgl_state *TLS, char const *username) {
|
||||
gchar *dir = g_strconcat (purple_user_dir(), G_DIR_SEPARATOR_S, config_dir,
|
||||
G_DIR_SEPARATOR_S, username, NULL);
|
||||
|
||||
if (g_str_has_prefix (dir, g_get_tmp_dir())) {
|
||||
// telepathy-haze will set purple user dir to a tmp path,
|
||||
// but we need the files to be persistent
|
||||
g_free (dir);
|
||||
dir = g_strconcat (g_get_home_dir(), G_DIR_SEPARATOR_S, ".telegram-purple",
|
||||
G_DIR_SEPARATOR_S, username, NULL);
|
||||
}
|
||||
g_mkdir_with_parents (dir, 0700);
|
||||
return dir;
|
||||
}
|
||||
|
||||
gchar *get_download_dir (struct tgl_state *TLS) {
|
||||
assert (TLS->base_path);
|
||||
static gchar *dir;
|
||||
if (dir) {
|
||||
g_free (dir);
|
||||
}
|
||||
dir = g_strconcat (TLS->base_path, G_DIR_SEPARATOR_S, "downloads", NULL);
|
||||
g_mkdir_with_parents (dir, 0700);
|
||||
return dir;
|
||||
}
|
||||
|
||||
void assert_file_exists (PurpleConnection *gc, const char *filepath, const char *format) {
|
||||
if (!g_file_test (filepath, G_FILE_TEST_EXISTS)) {
|
||||
gchar *msg = g_strdup_printf (format, filepath);
|
||||
purple_connection_error_reason (gc, PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR, msg);
|
||||
g_free (msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void telegram_export_authorization (struct tgl_state *TLS);
|
||||
void export_auth_callback (struct tgl_state *TLS, void *extra, int success) {
|
||||
if (!error_if_val_false(TLS, success, "Login Canceled", "Authentication export failed.")) {
|
||||
|
|
|
@ -36,4 +36,9 @@ void request_code_entered (gpointer data, const gchar *code);
|
|||
int generate_ident_icon(struct tgl_state *TLS, unsigned char* sha1_key);
|
||||
|
||||
void request_accept_secret_chat (struct tgl_state *TLS, struct tgl_secret_chat *U);
|
||||
|
||||
gchar *get_config_dir (struct tgl_state *TLS, char const *username);
|
||||
gchar *get_download_dir (struct tgl_state *TLS);
|
||||
void assert_file_exists (PurpleConnection *gc, const char *filepath, const char *format);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -437,28 +437,17 @@ static void tgprpl_login (PurpleAccount * acct) {
|
|||
debug ("tgprpl_login()");
|
||||
|
||||
PurpleConnection *gc = purple_account_get_connection (acct);
|
||||
char const *username = purple_account_get_username (acct);
|
||||
|
||||
struct tgl_state *TLS = tgl_state_alloc ();
|
||||
connection_data *conn = connection_data_init (TLS, gc, acct);
|
||||
purple_connection_set_protocol_data (gc, conn);
|
||||
|
||||
TLS->base_path = g_strdup_printf ("%s/%s/%s", purple_user_dir(), config_dir, username);
|
||||
char *ddir = g_strdup_printf ("%s/%s", TLS->base_path, "downloads");
|
||||
tgl_set_download_directory (TLS, ddir);
|
||||
g_mkdir_with_parents (TLS->base_path, 0700);
|
||||
g_mkdir_with_parents (ddir, 0700);
|
||||
free (ddir);
|
||||
TLS->base_path = get_config_dir(TLS, purple_account_get_username (acct));
|
||||
tgl_set_download_directory (TLS, get_download_dir(TLS));
|
||||
assert_file_exists (gc, pk_path, "Error, server public key not found at %s."
|
||||
" Make sure that Telegram-Purple is installed properly.");
|
||||
debug ("base configuration path: '%s'", TLS->base_path);
|
||||
|
||||
if (!g_file_test(pk_path, G_FILE_TEST_EXISTS)) {
|
||||
gchar *msg = g_strdup_printf ("Error, server public key not found at %s."
|
||||
" Make sure that Telegram-Purple is installed properly.", pk_path);
|
||||
purple_connection_error_reason (gc, PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR, msg);
|
||||
g_free (msg);
|
||||
return;
|
||||
}
|
||||
|
||||
tgl_set_verbosity (TLS, 4);
|
||||
tgl_set_rsa_key (TLS, pk_path);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue