]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/environment.cpp
only apply mac fix on macos
[xonotic/netradiant.git] / radiant / environment.cpp
index 1c297f03b353531708a78ab8b5264903d16c5450..b38ef992a59a84654e54bb0d4936b9d37346f585 100644 (file)
@@ -39,14 +39,18 @@ void args_init( int argc, char const* argv[] ){
        for ( i = 1; i < argc; i++ )
        {
                for ( k = i; k < argc; k++ )
+               {
                        if ( argv[k] != 0 ) {
                                break;
                        }
+               }
 
                if ( k > i ) {
                        k -= i;
                        for ( j = i + k; j < argc; j++ )
+                       {
                                argv[j - k] = argv[j];
+                       }
                        argc -= k;
                }
        }
@@ -56,6 +60,7 @@ void args_init( int argc, char const* argv[] ){
 }
 
 char const *gamedetect_argv_buffer[1024];
+
 void gamedetect_found_game( char const *game, char *path ){
        int argc;
        static char buf[128];
@@ -108,12 +113,14 @@ void gamedetect(){
        bool nogamedetect = false;
        int i;
        for ( i = 1; i < g_argc - 1; ++i )
+       {
                if ( g_argv[i][0] == '-' ) {
                        if ( !strcmp( g_argv[i], "-gamedetect" ) ) {
                                nogamedetect = !strcmp( g_argv[i + 1], "false" );
                        }
                        ++i;
                }
+       }
        if ( !nogamedetect ) {
                static char buf[1024 + 64];
                strncpy( buf, environment_get_app_path(), sizeof( buf ) );
@@ -160,6 +167,8 @@ namespace
 {
 CopiedString home_path;
 CopiedString app_path;
+       CopiedString lib_path;
+       CopiedString data_path;
 }
 
 const char* environment_get_home_path(){
@@ -170,10 +179,21 @@ const char* environment_get_app_path(){
        return app_path.c_str();
 }
 
+
+const char *environment_get_lib_path()
+{
+       return lib_path.c_str();
+}
+
+const char *environment_get_data_path()
+{
+       return data_path.c_str();
+}
+
 bool portable_app_setup(){
        StringOutputStream confdir( 256 );
        confdir << app_path.c_str() << "settings/";
-       if ( file_exists( confdir.c_str() ) ) {
+       if ( file_is_directory( confdir.c_str() ) ) {
                home_path = confdir.c_str();
                return true;
        }
@@ -244,9 +264,31 @@ void environment_init( int argc, char const* argv[] ){
                ASSERT_MESSAGE( !string_empty( app_path.c_str() ), "failed to deduce app path" );
        }
 
+       {
+               StringOutputStream buffer;
+               buffer << app_path.c_str() << "../lib/" << RADIANT_BASENAME << "/";
+               if ( file_is_directory( buffer.c_str() ) ) {
+                       lib_path = buffer.c_str();
+               }
+               else {
+                       lib_path = app_path.c_str();
+               }
+       }
+
+       {
+               StringOutputStream buffer;
+               buffer << app_path.c_str() << "../share/" << RADIANT_BASENAME << "/";
+               if ( file_is_directory( buffer.c_str() ) ) {
+                       data_path = buffer.c_str();
+               }
+               else {
+                       data_path = app_path.c_str();
+               }
+       }
+
        if ( !portable_app_setup() ) {
                StringOutputStream home( 256 );
-               home << DirectoryCleaned( g_get_user_config_dir() ) << "netradiant/";
+               home << DirectoryCleaned(g_get_user_config_dir()) << "/" << RADIANT_BASENAME << "/";
                Q_mkdir( home.c_str() );
                home_path = home.c_str();
        }
@@ -275,20 +317,15 @@ void environment_init( int argc, char const* argv[] ){
                StringOutputStream app( 256 );
                app << PathCleaned( filename );
                app_path = app.c_str();
+
+               lib_path = app_path;
+               data_path = app_path;
        }
 
        if ( !portable_app_setup() ) {
                char *appdata = getenv( "APPDATA" );
                StringOutputStream home( 256 );
-               if ( !appdata || string_empty( appdata ) ) {
-                       ERROR_MESSAGE( "Application Data folder not available.\n"
-                                                  "Radiant will use C:\\ for user preferences.\n" );
-                       home << "C:";
-               }
-               else
-               {
-                       home << PathCleaned( appdata );
-               }
+               home << PathCleaned( appdata );
                home << "/NetRadiantSettings/";
                Q_mkdir( home.c_str() );
                home_path = home.c_str();