From 64737e32dbb19489db94413f23db0095d596e99a Mon Sep 17 00:00:00 2001 From: darkrose Date: Sat, 22 Jul 2017 00:01:25 +1000 Subject: [PATCH] some path tweaks --- src/cmake_config.h.in | 3 ++- src/path.c | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/cmake_config.h.in b/src/cmake_config.h.in index 9336362..86d1944 100644 --- a/src/cmake_config.h.in +++ b/src/cmake_config.h.in @@ -10,12 +10,13 @@ #define USE_MUMBLE @USE_MUMBLE@ #define USE_FREETYPE @USE_FREETYPE@ #define USE_GETTEXT @USE_GETTEXT@ +#define DATA_PATH "@SHAREDIR@" #ifdef NDEBUG #define BUILD_TYPE "Release" #else #define BUILD_TYPE "Debug" #endif -#define BUILD_INFO "VER="VERSION_STRING" RUN_IN_PLACE=@RUN_IN_PLACE@ USE_GETTEXT=@USE_GETTEXT@ INSTALL_PREFIX=@CMAKE_INSTALL_PREFIX@ BUILD_TYPE="BUILD_TYPE +#define BUILD_INFO "VER=" VERSION_STRING " USE_GETTEXT=@USE_GETTEXT@ INSTALL_PREFIX=@CMAKE_INSTALL_PREFIX@ DATA_PATH=" DATA_PATH " BUILD_TYPE=" BUILD_TYPE #endif diff --git a/src/path.c b/src/path.c index 6df1225..a8c4b7b 100644 --- a/src/path.c +++ b/src/path.c @@ -210,7 +210,12 @@ int path_init() char buff[2048]; #ifndef WIN32 + +#ifdef DATA_PATH + path.data_global = strdup(DATA_PATH); +#else path.data_global = strdup("/usr/games/voxelands"); +#endif if (getcwd(buff,2048)) { path.cwd = strdup(buff); @@ -276,8 +281,24 @@ int path_init() #endif - if (snprintf(buff,2048,"%s/data",path.cwd) < 2048 && path_check(NULL,buff) == 2) + if (snprintf(buff,2048,"%s/data",path.cwd) < 2048 && path_check(NULL,buff) == 2) { path.data = strdup(buff); +#ifndef WIN32 + }else{ + char* a = NULL; + char* b = strstr(path.cwd,"/bin"); + while (b) { + a = b; + b = strstr(a+1,"/bin"); + } + if (a) { + *a = 0; + if (snprintf(buff,2048,"%s/data",path.cwd) < 2048 && path_check(NULL,buff) == 2) + path.data = strdup(buff); + *a = '/'; + } +#endif + } return 0; }