summaryrefslogtreecommitdiff
path: root/testing/toxic/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/toxic/main.c')
-rw-r--r--testing/toxic/main.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/testing/toxic/main.c b/testing/toxic/main.c
index bf5e1e6b..162cce68 100644
--- a/testing/toxic/main.c
+++ b/testing/toxic/main.c
@@ -3,11 +3,19 @@
3 */ 3 */
4 4
5#include <curses.h> 5#include <curses.h>
6#include <errno.h>
6#include <stdio.h> 7#include <stdio.h>
7#include <stdlib.h> 8#include <stdlib.h>
8#include <stdbool.h> 9#include <stdbool.h>
9#include <stdint.h> 10#include <stdint.h>
10 11
12#ifdef _win32
13#include <direct.h>
14#else
15#include <sys/stat.h>
16#include <sys/types.h>
17#endif
18
11#include "../../core/Messenger.h" 19#include "../../core/Messenger.h"
12#include "../../core/network.h" 20#include "../../core/network.h"
13 21
@@ -335,26 +343,19 @@ int main(int argc, char *argv[])
335{ 343{
336 int ch; 344 int ch;
337 int f_flag = 0; 345 int f_flag = 0;
338 char *configdir = get_user_config_dir(); 346 char *user_config_dir = get_user_config_dir();
339 char *default_file = "data";
340 int mkdir_err
341 #ifdef _win32
342 mkdir_err = _mkdir(configdir);
343 #else
344 mkdir_err = mkdir(configdir, 0700);
345 #endif
346
347 char *filename; 347 char *filename;
348 if(mkdir_err == -1) { 348 int config_err = create_user_config_dir(user_config_dir);
349 filename = default_file; 349 if(config_err) {
350 filename = "data";
350 } else { 351 } else {
351 filename = malloc(strlen(configdir) + strlen(default_file) + 1); 352 filename = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1);
352 strcpy(filename, configdir); 353 strcpy(filename, user_config_dir);
353 strcat(filename, default_file); 354 strcat(filename, CONFIGDIR);
355 strcat(filename, "data");
354 } 356 }
355 357
356 ToxWindow* a; 358 ToxWindow* a;
357
358 int i = 0; 359 int i = 0;
359 for (i = 0; i < argc; ++i) { 360 for (i = 0; i < argc; ++i) {
360 if (argv[i] == NULL) 361 if (argv[i] == NULL)
@@ -372,6 +373,7 @@ int main(int argc, char *argv[])
372 init_term(); 373 init_term();
373 init_tox(); 374 init_tox();
374 load_data(filename); 375 load_data(filename);
376 free(filename);
375 init_windows(); 377 init_windows();
376 init_window_status(); 378 init_window_status();
377 379
@@ -381,6 +383,13 @@ int main(int argc, char *argv[])
381 "defaulting to 'data' for a keyfile...\n"); 383 "defaulting to 'data' for a keyfile...\n");
382 attroff(COLOR_PAIR(3) | A_BOLD); 384 attroff(COLOR_PAIR(3) | A_BOLD);
383 } 385 }
386
387 if(config_err) {
388 attron(COLOR_PAIR(3) | A_BOLD);
389 wprintw(prompt->window, "Unable to determine configuration directory!\n"
390 "defaulting to 'data' for a keyfile...\n");
391 attroff(COLOR_PAIR(3) | A_BOLD);
392 }
384 393
385 while(true) { 394 while(true) {
386 /* Update tox */ 395 /* Update tox */