From adac62560df40f4a68c6c517d28356aa38de48ba Mon Sep 17 00:00:00 2001 From: loadletter Date: Sun, 18 Aug 2013 23:16:39 +0200 Subject: [PATCH 1/2] Use configdir.c instead of hardcoded paths for the list of DHT servers. --- testing/toxic/configdir.h | 4 ++-- testing/toxic/main.c | 35 ++++++++++++----------------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/testing/toxic/configdir.h b/testing/toxic/configdir.h index 17d95107..e886e53a 100644 --- a/testing/toxic/configdir.h +++ b/testing/toxic/configdir.h @@ -19,9 +19,9 @@ */ #ifdef _win32 -#define CONFIGDIR "\\toxic\\" +#define CONFIGDIR "\\tox\\" #else -#define CONFIGDIR "/toxic/" +#define CONFIGDIR "/tox/" #endif #ifndef S_ISDIR diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 72d8633b..3ed2fa5e 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -27,7 +27,7 @@ /* Export for use in Callbacks */ char *DATA_FILE = NULL; -char dir[256]; +char *SRVLIST_FILE = NULL; void on_window_resize(int sig) { @@ -36,17 +36,6 @@ void on_window_resize(int sig) clear(); } -void setdir() -{ -#ifdef WIN32 - strcpy(dir, "%appdata%/.tox/"); -#elif defined(MAC_OSX) - strcpy(dir, "~/Library/Application Support/.tox/"); -#elif defined(linux) - strcpy(dir, "~/.tox/"); -#endif -} - static void init_term() { /* Setup terminal */ @@ -103,16 +92,12 @@ static Messenger *init_tox() /* Connects to a random DHT server listed in the DHTservers file */ int init_connection(void) { + FILE *fp = NULL; + if (DHT_isconnected()) return 0; -#if WIN32 - FILE *fp = fopen("%appdata%/.tox/DHTservers", "r"); -#elif MAC_OSX - FILE *fp = fopen("~/Library/Application Support/.tox/DHTservers", "r"); -#else - FILE *fp = fopen("~/.tox/DHTservers", "r"); -#endif + fp = fopen(SRVLIST_FILE, "r"); if (!fp) return 1; @@ -279,7 +264,6 @@ static void load_data(Messenger *m, char *path) int main(int argc, char *argv[]) { - setdir(); char *user_config_dir = get_user_config_dir(); int config_err = 0; @@ -306,16 +290,20 @@ int main(int argc, char *argv[]) config_err = create_user_config_dir(user_config_dir); if (config_err) { - strcat(DATA_FILE, dir); DATA_FILE = strdup("data"); + SRVLIST_FILE = strdup("../../other/DHTservers"); } else { DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1); strcpy(DATA_FILE, user_config_dir); strcat(DATA_FILE, CONFIGDIR); - strcat(DATA_FILE, dir); - DATA_FILE = strdup("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"); } } @@ -352,5 +340,6 @@ int main(int argc, char *argv[]) cleanupMessenger(m); free(DATA_FILE); + free(SRVLIST_FILE); return 0; } From e8b8dfebb3fce4a7e2dc6cb362351dd0a21c2af4 Mon Sep 17 00:00:00 2001 From: loadletter Date: Sun, 18 Aug 2013 23:20:34 +0200 Subject: [PATCH 2/2] Modified cmakefile to move the serverlist to the proper directory. Tested on GNU/Linux. --- other/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/other/CMakeLists.txt b/other/CMakeLists.txt index eaf677ed..871a9e92 100644 --- a/other/CMakeLists.txt +++ b/other/CMakeLists.txt @@ -6,16 +6,16 @@ SET(USER_NAME $ENV{USERNAME} CACHE STRING UserName) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_bootstrap.cmake) if(WIN32) - file(MAKE_DIRECTORY "C:/Users/${USER_NAME}/AppData/Roaming/.tox") - file(INSTALL DHTservers DESTINATION "C:/Users/${USER_NAME}/AppData/Roaming/.tox") + file(MAKE_DIRECTORY "C:/Users/${USER_NAME}/AppData/Roaming/.config/tox") + file(INSTALL DHTservers DESTINATION "C:/Users/${USER_NAME}/AppData/Roaming/.config/tox") else() set(HOME "$ENV{HOME}") if(APPLE) - file(MAKE_DIRECTORY ${HOME}/Library/Application\ Support/.tox) - file(INSTALL DHTservers DESTINATION ${HOME}/Library/Application\ Support/.tox) + file(MAKE_DIRECTORY ${HOME}/Library/Application\ Support/.config/tox) + file(INSTALL DHTservers DESTINATION ${HOME}/Library/Application\ Support/.config/tox) else() - file(MAKE_DIRECTORY ${HOME}/.tox) - file(INSTALL DHTservers DESTINATION ${HOME}/.tox) + file(MAKE_DIRECTORY ${HOME}/.config/tox) + file(INSTALL DHTservers DESTINATION ${HOME}/.config/tox) endif() endif()