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 @@
+/*
+ * Copyright (C) 2013 Tox project All Rights Reserved.
+ *
+ * This file is part of Tox.
+ *
+ * Tox is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Tox is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Tox. If not, see .
+ *
+ */
+
+#include
+#include
+#include
+
+#ifdef _win32
+#include
+#endif
+
+#ifdef __APPLE__
+#include
+#include
+#include
+#endif
+
+char *get_user_config_dir(void)
+{
+ char *user_config_dir;
+
+ #ifdef _win32
+
+ char appdata[MAX_PATH];
+ HRESULT result = SHGetFolderPath(
+ NULL,
+ CSIDL_APPDATA, // TODO: Maybe use CSIDL_LOCAL_APPDATA instead? Not sure.
+ NULL,
+ SHGFP_TYPE_CURRENT,
+ appdata
+ )
+ if (!result) return NULL;
+
+ user_config_dir = malloc(strlen(appdata) + strlen(CONFIGDIR) + 1);
+ if (user_config_dir) {
+ strcpy(user_config_dir, appdata);
+ strcat(user_config_dir, CONFIGDIR);
+ }
+ return user_config_dir;
+
+ #elif defined __APPLE__
+
+ struct passwd *pass = getpwuid(getuid());
+ if (!pass) return NULL;
+ char *home = pass->pw_dir;
+ user_config_dir = malloc(strlen(home) + strlen("/Library/Application Support") + strlen(CONFIGDIR) + 1);
+
+ if(user_config_dir) {
+ strcpy(user_config_dir, home);
+ strcat(user_config_dir, "/Library/Application Support");
+ strcat(user_config_dir, CONFIGDIR);
+ }
+ return user_config_dir;
+
+ #else
+
+ if (getenv("XDG_CONFIG_HOME")) {
+ user_config_dir = malloc(strlen(getenv("XDG_CONFIG_HOME")) + strlen(CONFIGDIR) + 1);
+ if (user_config_dir) {
+ strcpy(user_config_dir, getenv("XDG_CONFIG_HOME"));
+ strcat(user_config_dir, CONFIGDIR);
+ }
+ } else {
+ user_config_dir = malloc(strlen(getenv("HOME")) + strlen("/.config") + strlen(CONFIGDIR) + 1);
+ if (user_config_dir) {
+ strcpy(user_config_dir, getenv("HOME"));
+ strcat(user_config_dir, "/.config");
+ strcat(user_config_dir, CONFIGDIR);
+ }
+ }
+ return user_config_dir;
+
+ #endif
+}
\ 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 @@
+/*
+ * Copyright (C) 2013 Tox project All Rights Reserved.
+ *
+ * This file is part of Tox.
+ *
+ * Tox is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Tox is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Tox. If not, see .
+ *
+ */
+
+#ifdef _win32
+#define CONFIGDIR "\\toxic\\"
+#else
+#define CONFIGDIR "/toxic/"
+#endif
+
+char *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 @@
#include "../../core/Messenger.h"
#include "../../core/network.h"
+#include "configdir.h"
#include "windows.h"
extern ToxWindow new_prompt();
@@ -331,7 +332,24 @@ int main(int argc, char *argv[])
{
int ch;
int f_flag = 0;
- char *filename = "data";
+ char *configdir = get_user_config_dir();
+ char *default_file = "data";
+ int mkdir_err
+ #ifdef _win32
+ mkdir_err = _mkdir(configdir);
+ #else
+ mkdir_err = mkdir(configdir, 0700);
+ #endif
+
+ char *filename;
+ if(mkdir_err == -1) {
+ filename = default_file;
+ } else {
+ filename = malloc(strlen(configdir) + strlen(default_file) + 1);
+ strcpy(filename, configdir);
+ strcat(filename, default_file);
+ }
+
ToxWindow* a;
int i = 0;