1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 23:33:28 +01:00

create empty config file if none found && make default time 24 hours

This commit is contained in:
Jfreegman 2014-04-07 18:16:38 -04:00
parent 5976d33fef
commit de3a28c6e6
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
5 changed files with 11 additions and 8 deletions

View File

@ -92,7 +92,7 @@ static void update_friend_last_online(int32_t num, uint64_t timestamp)
friends[num].last_online.tm = *localtime(&timestamp); friends[num].last_online.tm = *localtime(&timestamp);
/* if the format changes make sure TIME_STR_SIZE is the correct size */ /* if the format changes make sure TIME_STR_SIZE is the correct size */
const char *t = user_settings->time == TIME_24 ? "%H:%M" : "%I:%M %p"; const char *t = user_settings->time == TIME_12 ? "%I:%M %p" : "%H:%M";
strftime(friends[num].last_online.hour_min_str, TIME_STR_SIZE, t, strftime(friends[num].last_online.hour_min_str, TIME_STR_SIZE, t,
&friends[num].last_online.tm); &friends[num].last_online.tm);
} }

View File

@ -99,7 +99,7 @@ void write_to_log(const uint8_t *msg, uint8_t *name, struct chatlog *log, bool e
else else
snprintf(name_frmt, sizeof(name_frmt), "%s:", name); snprintf(name_frmt, sizeof(name_frmt), "%s:", name);
const char *t = user_settings->time == TIME_24 ? "%Y/%m/%d [%H:%M:%S]" : "%Y/%m/%d [%I:%M:%S %p]"; const char *t = user_settings->time == TIME_12 ? "%Y/%m/%d [%I:%M:%S %p]" : "%Y/%m/%d [%H:%M:%S]";
uint8_t s[MAX_STR_SIZE]; uint8_t s[MAX_STR_SIZE];
strftime(s, MAX_STR_SIZE, t, get_time()); strftime(s, MAX_STR_SIZE, t, get_time());
fprintf(log->file,"%s %s %s\n", s, name_frmt, msg); fprintf(log->file,"%s %s %s\n", s, name_frmt, msg);

View File

@ -559,12 +559,12 @@ int main(int argc, char *argv[])
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0); line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
} }
/*
if (settings_err == -1) { if (settings_err == -1) {
msg = "Failed to load user settings"; msg = "Failed to load user settings";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0); line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
} }
*/
sort_friendlist_index(); sort_friendlist_index();
prompt_init_statusbar(prompt, m); prompt_init_statusbar(prompt, m);

View File

@ -59,7 +59,7 @@ struct tm *get_time(void)
void get_time_str(uint8_t *buf) void get_time_str(uint8_t *buf)
{ {
const char *t = user_settings->time == TIME_24 ? "[%H:%M:%S] " : "[%I:%M:%S %p] "; const char *t = user_settings->time == TIME_12 ? "[%I:%M:%S %p] " : "[%H:%M:%S] ";
strftime(buf, TIME_STR_SIZE, t, get_time()); strftime(buf, TIME_STR_SIZE, t, get_time());
} }

View File

@ -62,19 +62,21 @@ int settings_load(struct user_settings *s, char *path)
{ {
char *user_config_dir = get_user_config_dir(); char *user_config_dir = get_user_config_dir();
FILE *fp = NULL; FILE *fp = NULL;
char dflt_path[MAX_STR_SIZE];
if (path) { if (path) {
fp = fopen(path, "r"); fp = fopen(path, "r");
} else { } else {
char dflt_path[MAX_STR_SIZE];
snprintf(dflt_path, sizeof(dflt_path), "%s%stoxic.conf", user_config_dir, CONFIGDIR); snprintf(dflt_path, sizeof(dflt_path), "%s%stoxic.conf", user_config_dir, CONFIGDIR);
fp = fopen(dflt_path, "r"); fp = fopen(dflt_path, "r");
} }
free(user_config_dir); free(user_config_dir);
if (fp == NULL) if (fp == NULL) {
return -1; if ((fp = fopen(dflt_path, "w")) == NULL)
return -1;
}
char line[MAX_STR_SIZE]; char line[MAX_STR_SIZE];
@ -99,5 +101,6 @@ int settings_load(struct user_settings *s, char *path)
} }
} }
fclose(fp);
return 0; return 0;
} }