1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 22:43:01 +01:00

Merge with upstream

This commit is contained in:
Michael Rose 2013-08-19 14:40:15 +02:00
commit 514d1952d0
3 changed files with 22 additions and 27 deletions

View File

@ -98,14 +98,18 @@ char *get_user_config_dir(void)
snprintf(user_config_dir, len, "%s/Library/Application Support", home); snprintf(user_config_dir, len, "%s/Library/Application Support", home);
# else /* __APPLE__ */ # else /* __APPLE__ */
len = strlen(home) + strlen("/.config") + 1;
user_config_dir = malloc(len);
if (user_config_dir == NULL) { if (!(user_config_dir = getenv("XDG_CONFIG_HOME"))) {
return NULL; len = strlen(home) + strlen("/.config") + 1;
user_config_dir = malloc(len);
if (user_config_dir == NULL) {
return NULL;
}
snprintf(user_config_dir, len, "%s/.config", home);
} }
snprintf(user_config_dir, len, "%s/.config", home);
# endif /* __APPLE__ */ # endif /* __APPLE__ */
return user_config_dir; return user_config_dir;

View File

@ -19,9 +19,9 @@
*/ */
#ifdef _win32 #ifdef _win32
#define CONFIGDIR "\\toxic\\" #define CONFIGDIR "\\tox\\"
#else #else
#define CONFIGDIR "/toxic/" #define CONFIGDIR "/tox/"
#endif #endif
#ifndef S_ISDIR #ifndef S_ISDIR

31
main.c
View File

@ -27,7 +27,7 @@
/* Export for use in Callbacks */ /* Export for use in Callbacks */
char *DATA_FILE = NULL; char *DATA_FILE = NULL;
char dir[256]; char *SRVLIST_FILE = NULL;
void on_window_resize(int sig) void on_window_resize(int sig)
{ {
@ -36,17 +36,6 @@ void on_window_resize(int sig)
clear(); clear();
} }
void setdir()
{
#ifdef WIN32
strcpy(dir, "%appdata%/.tox/");
#elif defined(__APPLE__)
strcpy(dir, "~/Library/Application Support/.tox/");
#elif defined(linux)
strcpy(dir, "~/.tox/");
#endif
}
static void init_term() static void init_term()
{ {
/* Setup terminal */ /* Setup terminal */
@ -103,16 +92,12 @@ static Messenger *init_tox()
/* Connects to a random DHT server listed in the DHTservers file */ /* Connects to a random DHT server listed in the DHTservers file */
int init_connection(void) int init_connection(void)
{ {
FILE *fp = NULL;
if (DHT_isconnected()) if (DHT_isconnected())
return 0; return 0;
#if WIN32 fp = fopen(SRVLIST_FILE, "r");
FILE *fp = fopen("%appdata%/.tox/DHTservers", "r");
#elif defined(__APPLE__)
FILE *fp = fopen("~/Library/Application Support/.tox/DHTservers", "r");
#else
FILE *fp = fopen("~/.tox/DHTservers", "r");
#endif
if (!fp) if (!fp)
return 1; return 1;
@ -279,7 +264,6 @@ static void load_data(Messenger *m, char *path)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
setdir();
char *user_config_dir = get_user_config_dir(); char *user_config_dir = get_user_config_dir();
int config_err = 0; int config_err = 0;
@ -307,11 +291,17 @@ int main(int argc, char *argv[])
if (config_err) { if (config_err) {
DATA_FILE = strdup("data"); DATA_FILE = strdup("data");
SRVLIST_FILE = strdup("../../other/DHTservers");
} else { } else {
DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1); DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1);
strcpy(DATA_FILE, user_config_dir); strcpy(DATA_FILE, user_config_dir);
strcat(DATA_FILE, CONFIGDIR); strcat(DATA_FILE, CONFIGDIR);
strcat(DATA_FILE, "data"); strcat(DATA_FILE, "data");
SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1);
strcpy(SRVLIST_FILE, user_config_dir);
strcat(SRVLIST_FILE, CONFIGDIR);
strcat(SRVLIST_FILE, "DHTservers");
} }
} }
@ -348,5 +338,6 @@ int main(int argc, char *argv[])
cleanupMessenger(m); cleanupMessenger(m);
free(DATA_FILE); free(DATA_FILE);
free(SRVLIST_FILE);
return 0; return 0;
} }