X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fenvironment.cpp;h=d6be70d54a6b1eb1db87d3f368d9fc1d2ed49499;hb=32dc1da26645b97a5823ff22175000542225c6dd;hp=29a86226af3f4e211b7417d9a69b0c0ffc80e5e3;hpb=5d619a7d5a3c4fbf8d28df5f8d9bba3571652c4b;p=xonotic%2Fnetradiant.git diff --git a/radiant/environment.cpp b/radiant/environment.cpp index 29a86226..d6be70d5 100644 --- a/radiant/environment.cpp +++ b/radiant/environment.cpp @@ -167,12 +167,19 @@ void gamedetect(){ namespace { + // executable file path + CopiedString app_filepath; + // directory paths CopiedString home_path; CopiedString app_path; CopiedString lib_path; CopiedString data_path; } +const char* environment_get_app_filepath(){ + return app_filepath.c_str(); +} + const char* environment_get_home_path(){ return home_path.c_str(); } @@ -181,7 +188,6 @@ const char* environment_get_app_path(){ return app_path.c_str(); } - const char *environment_get_lib_path() { return lib_path.c_str(); @@ -218,23 +224,27 @@ const char* LINK_NAME = #endif ; -/// brief Returns the filename of the executable belonging to the current process, or 0 if not found. +/// brief Returns the filename of the executable belonging to the current process, or empty string if not found. char const* getexename( char *buf ){ /* Now read the symbolic link */ - int ret = readlink( LINK_NAME, buf, PATH_MAX ); + const int ret = readlink( LINK_NAME, buf, PATH_MAX ); if ( ret == -1 ) { globalOutputStream() << "getexename: falling back to argv[0]: " << makeQuoted( g_argv[0] ); - const char* path = realpath( g_argv[0], buf ); - if ( path == 0 ) { + if( realpath( g_argv[0], buf ) == 0 ) { /* In case of an error, leave the handling up to the caller */ - return ""; + *buf = '\0'; } } + else { + /* Ensure proper NUL termination */ + buf[ret] = 0; + } - /* Ensure proper NUL termination */ - buf[ret] = 0; + return buf; +} +char const* getexepath( char *buf ) { /* delete the program name */ *( strrchr( buf, '/' ) ) = '\0'; @@ -262,8 +272,11 @@ void environment_init( int argc, char const* argv[] ){ { char real[PATH_MAX]; - app_path = getexename( real ); - ASSERT_MESSAGE( !string_empty( app_path.c_str() ), "failed to deduce app path" ); + app_filepath = getexename( real ); + ASSERT_MESSAGE( !string_empty( app_filepath.c_str() ), "failed to deduce app path" ); + + strncpy( real, app_filepath.c_str(), strlen( app_filepath.c_str() ) ); + app_path = getexepath( real ); } { @@ -313,7 +326,14 @@ void environment_init( int argc, char const* argv[] ){ { // get path to the editor char filename[MAX_PATH + 1]; + StringOutputStream app_filepath_stream( 256 ); + StringOutputStream app_path_stream( 256 ); + GetModuleFileName( 0, filename, MAX_PATH ); + + app_filepath_stream << PathCleaned( filename ); + app_filepath = app_filepath_stream.c_str(); + char* last_separator = strrchr( filename, '\\' ); if ( last_separator != 0 ) { *( last_separator + 1 ) = '\0'; @@ -322,9 +342,9 @@ void environment_init( int argc, char const* argv[] ){ { filename[0] = '\0'; } - StringOutputStream app( 256 ); - app << PathCleaned( filename ); - app_path = app.c_str(); + + app_path_stream << PathCleaned( filename ); + app_path = app_path_stream.c_str(); lib_path = app_path; data_path = app_path;