summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/toxic/configdir.c91
-rw-r--r--testing/toxic/configdir.h27
-rw-r--r--testing/toxic/main.c20
3 files changed, 137 insertions, 1 deletions
diff --git a/testing/toxic/configdir.c b/testing/toxic/configdir.c
new file mode 100644
index 00000000..c9f7de85
--- /dev/null
+++ b/testing/toxic/configdir.c
@@ -0,0 +1,91 @@
1/*
2 * Copyright (C) 2013 Tox project All Rights Reserved.
3 *
4 * This file is part of Tox.
5 *
6 * Tox is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Tox is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#include <string.h>
22#include <stdlib.h>
23#include <stdio.h>
24
25#ifdef _win32
26#include <shlobj.h>
27#endif
28
29#ifdef __APPLE__
30#include <sys/types.h>
31#include <unistd.h>
32#include <pwd.h>
33#endif
34
35char *get_user_config_dir(void)
36{
37 char *user_config_dir;
38
39 #ifdef _win32
40
41 char appdata[MAX_PATH];
42 HRESULT result = SHGetFolderPath(
43 NULL,
44 CSIDL_APPDATA, // TODO: Maybe use CSIDL_LOCAL_APPDATA instead? Not sure.
45 NULL,
46 SHGFP_TYPE_CURRENT,
47 appdata
48 )
49 if (!result) return NULL;
50
51 user_config_dir = malloc(strlen(appdata) + strlen(CONFIGDIR) + 1);
52 if (user_config_dir) {
53 strcpy(user_config_dir, appdata);
54 strcat(user_config_dir, CONFIGDIR);
55 }
56 return user_config_dir;
57
58 #elif defined __APPLE__
59
60 struct passwd *pass = getpwuid(getuid());
61 if (!pass) return NULL;
62 char *home = pass->pw_dir;
63 user_config_dir = malloc(strlen(home) + strlen("/Library/Application Support") + strlen(CONFIGDIR) + 1);
64
65 if(user_config_dir) {
66 strcpy(user_config_dir, home);
67 strcat(user_config_dir, "/Library/Application Support");
68 strcat(user_config_dir, CONFIGDIR);
69 }
70 return user_config_dir;
71
72 #else
73
74 if (getenv("XDG_CONFIG_HOME")) {
75 user_config_dir = malloc(strlen(getenv("XDG_CONFIG_HOME")) + strlen(CONFIGDIR) + 1);
76 if (user_config_dir) {
77 strcpy(user_config_dir, getenv("XDG_CONFIG_HOME"));
78 strcat(user_config_dir, CONFIGDIR);
79 }
80 } else {
81 user_config_dir = malloc(strlen(getenv("HOME")) + strlen("/.config") + strlen(CONFIGDIR) + 1);
82 if (user_config_dir) {
83 strcpy(user_config_dir, getenv("HOME"));
84 strcat(user_config_dir, "/.config");
85 strcat(user_config_dir, CONFIGDIR);
86 }
87 }
88 return user_config_dir;
89
90 #endif
91} \ No newline at end of file
diff --git a/testing/toxic/configdir.h b/testing/toxic/configdir.h
new file mode 100644
index 00000000..441ffdab
--- /dev/null
+++ b/testing/toxic/configdir.h
@@ -0,0 +1,27 @@
1/*
2 * Copyright (C) 2013 Tox project All Rights Reserved.
3 *
4 * This file is part of Tox.
5 *
6 * Tox is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Tox is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifdef _win32
22#define CONFIGDIR "\\toxic\\"
23#else
24#define CONFIGDIR "/toxic/"
25#endif
26
27char *get_user_config_dir(void); \ No newline at end of file
diff --git a/testing/toxic/main.c b/testing/toxic/main.c
index b2310c80..ec439c84 100644
--- a/testing/toxic/main.c
+++ b/testing/toxic/main.c
@@ -11,6 +11,7 @@
11#include "../../core/Messenger.h" 11#include "../../core/Messenger.h"
12#include "../../core/network.h" 12#include "../../core/network.h"
13 13
14#include "configdir.h"
14#include "windows.h" 15#include "windows.h"
15 16
16extern ToxWindow new_prompt(); 17extern ToxWindow new_prompt();
@@ -331,7 +332,24 @@ int main(int argc, char *argv[])
331{ 332{
332 int ch; 333 int ch;
333 int f_flag = 0; 334 int f_flag = 0;
334 char *filename = "data"; 335 char *configdir = get_user_config_dir();
336 char *default_file = "data";
337 int mkdir_err
338 #ifdef _win32
339 mkdir_err = _mkdir(configdir);
340 #else
341 mkdir_err = mkdir(configdir, 0700);
342 #endif
343
344 char *filename;
345 if(mkdir_err == -1) {
346 filename = default_file;
347 } else {
348 filename = malloc(strlen(configdir) + strlen(default_file) + 1);
349 strcpy(filename, configdir);
350 strcat(filename, default_file);
351 }
352
335 ToxWindow* a; 353 ToxWindow* a;
336 354
337 int i = 0; 355 int i = 0;