]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
radiant: get own radiant executable file path
authorThomas Debesse <dev@illwieckz.net>
Sun, 14 Jul 2019 00:35:17 +0000 (02:35 +0200)
committerThomas Debesse <dev@illwieckz.net>
Mon, 22 Jul 2019 02:09:24 +0000 (04:09 +0200)
previous code was getting it to compute app_path, lib_path and data_path
but was not keeping the value

radiant/environment.cpp
radiant/environment.h
radiant/main.cpp
radiant/mainframe.cpp
radiant/mainframe.h

index 29a86226af3f4e211b7417d9a69b0c0ffc80e5e3..9c0f53e47a69a3ade13f32da7fa66e492526bfab 100644 (file)
@@ -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();
@@ -234,7 +240,10 @@ char const* getexename( char *buf ){
 
        /* Ensure proper NUL termination */
        buf[ret] = 0;
+       return buf;
+}
 
+char const* getexepath( char *buf ) {
        /* delete the program name */
        *( strrchr( buf, '/' ) ) = '\0';
 
@@ -262,8 +271,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 +325,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 +341,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;
index d5d30e1cb2d5306a2b87f07c4e9e1097d4b04ca9..61494f861d590bfd4b554d4ab5f8897b6f380bc1 100644 (file)
 #define INCLUDED_ENVIRONMENT_H
 
 void environment_init( int argc, char const* argv[] );
+
+const char* environment_get_app_filepath();
+
 const char* environment_get_home_path();
 const char* environment_get_app_path();
-
 const char *environment_get_lib_path();
-
 const char *environment_get_data_path();
 
 extern int g_argc;
index ff52a200dd867224991a45803dd3d7d5849b5e13..172c3fa92db5532fc1062c61b36221cfe1bc04b7 100644 (file)
@@ -329,6 +329,7 @@ void paths_init(){
 
        Q_mkdir( g_strSettingsPath.c_str() );
 
+       g_strAppFilePath = environment_get_app_filepath();
        g_strAppPath = environment_get_app_path();
        g_strLibPath = environment_get_lib_path();
        g_strDataPath = environment_get_data_path();
index 6fadba47804fbd0c5784e4852127b451a2cbb17b..d3e869000efabaea592091d880bedcc05708add4 100644 (file)
@@ -444,12 +444,18 @@ void setPakPath( int num, const char* path ){
 }
 
 
-// App Path
+// executable file path (full path)
+CopiedString g_strAppFilePath;
 
-CopiedString g_strAppPath;                 ///< holds the full path of the executable
+// directory paths
+CopiedString g_strAppPath; 
 CopiedString g_strLibPath;
 CopiedString g_strDataPath;
 
+const char* AppFilePath_get(){
+       return g_strAppFilePath.c_str();
+}
+
 const char* AppPath_get(){
        return g_strAppPath.c_str();
 }
index 358b9eb7cc144861127a8e5387d84c954d6e46eb..f101c25eabc34f4a740905d56f9902f66a876428 100644 (file)
@@ -212,10 +212,12 @@ const int g_pakPathCount = 5;
 extern CopiedString g_strPakPath[g_pakPathCount];
 const char* PakPath_get( int num );
 
+extern CopiedString g_strAppFilePath;
 extern CopiedString g_strAppPath;
 extern CopiedString g_strLibPath;
 extern CopiedString g_strDataPath;
 
+const char* AppFilePath_get();
 const char* AppPath_get();
 const char *LibPath_get();
 const char *DataPath_get();