mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 21:53:05 +01:00
Use profile name that conforms with the standard
This commit is contained in:
parent
a920f3edfe
commit
db410cb01e
@ -704,7 +704,7 @@ static void unblock_friend(Tox *m, uint32_t bnum)
|
||||
uint32_t friendnum = tox_friend_add_norequest(m, (uint8_t *) Blocked.list[bnum].pub_key, &err);
|
||||
|
||||
if (err != TOX_ERR_FRIEND_ADD_OK) {
|
||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to unblock friend (error %d)\n", err);
|
||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to unblock friend (error %d)", err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
74
src/toxic.c
74
src/toxic.c
@ -77,8 +77,8 @@ char *DATA_FILE = NULL;
|
||||
char *BLOCK_FILE = NULL;
|
||||
ToxWindow *prompt = NULL;
|
||||
|
||||
#define DATANAME "data"
|
||||
#define BLOCKNAME "data-blocklist"
|
||||
#define DATANAME "toxic_profile.tox"
|
||||
#define BLOCKNAME "toxic_blocklist"
|
||||
|
||||
#define AUTOSAVE_FREQ 60
|
||||
#define MIN_PASSWORD_LEN 6
|
||||
@ -1076,26 +1076,67 @@ static void parse_args(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
static int init_default_data_files(void)
|
||||
/* Looks for an old default profile data file and blocklist, and renames them to the new default names.
|
||||
* Saves the old data files under the names "toxic_data.old" and "toxic_data_blocklist.old".
|
||||
*
|
||||
* Returns 0 on success.
|
||||
* Returns -1 on failure.
|
||||
*/
|
||||
#define OLD_DATA_NAME "data"
|
||||
#define OLD_DATA_BLOCKLIST_NAME "data-blocklist"
|
||||
static int rename_old_profile(const char *user_config_dir)
|
||||
{
|
||||
if (arg_opts.use_custom_data)
|
||||
char old_data_file[strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(OLD_DATA_NAME) + 1];
|
||||
snprintf(old_data_file, sizeof(old_data_file), "%s%s%s", user_config_dir, CONFIGDIR, OLD_DATA_NAME);
|
||||
|
||||
if (!file_exists(old_data_file))
|
||||
return 0;
|
||||
|
||||
if (rename(old_data_file, DATA_FILE) != 0)
|
||||
return -1;
|
||||
|
||||
queue_init_message("Data file has been moved to %s", DATA_FILE);
|
||||
|
||||
char old_data_blocklist[strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(OLD_DATA_BLOCKLIST_NAME) + 1];
|
||||
snprintf(old_data_blocklist, sizeof(old_data_blocklist), "%s%s%s", user_config_dir, CONFIGDIR, OLD_DATA_BLOCKLIST_NAME);
|
||||
|
||||
if (!file_exists(old_data_blocklist))
|
||||
return 0;
|
||||
|
||||
if (rename(old_data_blocklist, BLOCK_FILE) != 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Initializes the default config directory and data files used by toxic.
|
||||
*
|
||||
* Exits the process with an error on failure.
|
||||
*/
|
||||
static void init_default_data_files(void)
|
||||
{
|
||||
if (arg_opts.use_custom_data)
|
||||
return;
|
||||
|
||||
char *user_config_dir = get_user_config_dir();
|
||||
|
||||
if (user_config_dir == NULL)
|
||||
exit_toxic_err("failed in init_default_data_files()", FATALERR_FILEOP);
|
||||
|
||||
int config_err = create_user_config_dirs(user_config_dir);
|
||||
|
||||
if (config_err) {
|
||||
if (config_err == -1) {
|
||||
DATA_FILE = strdup(DATANAME);
|
||||
BLOCK_FILE = strdup(BLOCKNAME);
|
||||
|
||||
if (DATA_FILE == NULL || BLOCK_FILE == NULL)
|
||||
exit_toxic_err("failed in load_data_structures", FATALERR_MEMORY);
|
||||
exit_toxic_err("failed in init_default_data_files()", FATALERR_MEMORY);
|
||||
} else {
|
||||
DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(DATANAME) + 1);
|
||||
BLOCK_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(BLOCKNAME) + 1);
|
||||
|
||||
if (DATA_FILE == NULL || BLOCK_FILE == NULL)
|
||||
exit_toxic_err("failed in load_data_structures", FATALERR_MEMORY);
|
||||
exit_toxic_err("failed in init_default_data_files()", FATALERR_MEMORY);
|
||||
|
||||
strcpy(DATA_FILE, user_config_dir);
|
||||
strcat(DATA_FILE, CONFIGDIR);
|
||||
@ -1106,8 +1147,11 @@ static int init_default_data_files(void)
|
||||
strcat(BLOCK_FILE, BLOCKNAME);
|
||||
}
|
||||
|
||||
/* For backwards compatibility with old toxic profile names. TODO: remove this some day */
|
||||
if (rename_old_profile(user_config_dir) == -1)
|
||||
queue_init_message("Warning: Profile backwards compatibility failed.");
|
||||
|
||||
free(user_config_dir);
|
||||
return config_err;
|
||||
}
|
||||
|
||||
#define REC_TOX_DO_LOOPS_PER_SEC 25
|
||||
@ -1138,11 +1182,11 @@ void DnD_callback(const char* asdv, DropType dt)
|
||||
|
||||
// pthread_mutex_lock(&Winthread.lock);
|
||||
// line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, asdv);
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
// pthread_mutex_unlock(&Winthread.lock);
|
||||
}
|
||||
#endif /* X11 */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
parse_args(argc, argv);
|
||||
|
||||
@ -1159,7 +1203,8 @@ int main(int argc, char *argv[])
|
||||
/* Make sure all written files are read/writeable only by the current user. */
|
||||
umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
|
||||
int config_err = init_default_data_files();
|
||||
init_default_data_files();
|
||||
|
||||
bool datafile_exists = file_exists(DATA_FILE);
|
||||
|
||||
if (datafile_exists)
|
||||
@ -1227,13 +1272,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
init_notify(60, 3000);
|
||||
|
||||
const char *msg;
|
||||
|
||||
if (config_err) {
|
||||
msg = "Unable to determine configuration directory. Defaulting to 'data' for data file...";
|
||||
queue_init_message("%s", msg);
|
||||
}
|
||||
|
||||
if (settings_err == -1)
|
||||
queue_init_message("Failed to load user settings");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user