X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fenvironment.cpp;h=a84a7d42bc7ba0b10fc25b465aa2098fbff582ae;hb=ff48e71434a414958e6e56628ccf04284d030784;hp=99aa6c26769bffb13f137ac861b8f76fcc5cbf3a;hpb=6f51c7f28dc9f56ae64e7da7d42dcbaa068da65a;p=xonotic%2Fnetradiant.git diff --git a/radiant/environment.cpp b/radiant/environment.cpp index 99aa6c26..a84a7d42 100644 --- a/radiant/environment.cpp +++ b/radiant/environment.cpp @@ -20,6 +20,7 @@ */ #include "environment.h" +#include "globaldefs.h" #include "stream/textstream.h" #include "string/string.h" @@ -30,22 +31,26 @@ #include "cmdlib.h" int g_argc; -char** g_argv; +char const** g_argv; -void args_init( int argc, char* argv[] ){ +void args_init( int argc, char const* argv[] ){ int i, j, k; 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; } } @@ -54,8 +59,9 @@ void args_init( int argc, char* argv[] ){ g_argv = argv; } -char *gamedetect_argv_buffer[1024]; -void gamedetect_found_game( char *game, char *path ){ +char const *gamedetect_argv_buffer[1024]; + +void gamedetect_found_game( char const *game, char *path ){ int argc; static char buf[128]; @@ -79,7 +85,7 @@ void gamedetect_found_game( char *game, char *path ){ g_argv = gamedetect_argv_buffer; } -bool gamedetect_check_game( char *gamefile, const char *checkfile1, const char *checkfile2, char *buf /* must have 64 bytes free after bufpos */, int bufpos ){ +bool gamedetect_check_game( char const *gamefile, const char *checkfile1, const char *checkfile2, char *buf /* must have 64 bytes free after bufpos */, int bufpos ){ buf[bufpos] = '/'; strcpy( buf + bufpos + 1, checkfile1 ); @@ -108,12 +114,14 @@ void gamedetect(){ bool nogamedetect = true; 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 ) ); @@ -128,17 +136,17 @@ void gamedetect(){ // TODO add more games to this // try to detect Nexuiz installs -#if defined( WIN32 ) +#if GDEF_OS_WINDOWS if ( gamedetect_check_game( "nexuiz.game", "data/common-spog.pk3", "nexuiz.exe", buf, p - buf ) ) -#elif defined( __APPLE__ ) +#elif GDEF_OS_MACOS if ( gamedetect_check_game( "nexuiz.game", "data/common-spog.pk3", "Nexuiz.app/Contents/Info.plist", buf, p - buf ) ) #else if ( gamedetect_check_game( "nexuiz.game", "data/common-spog.pk3", "nexuiz-linux-glx.sh", buf, p - buf ) ) #endif { return; } - // try to detect Q2World installs - if ( gamedetect_check_game( "q2w.game", "default/quake2world.version", NULL, buf, p - buf ) ) { + // try to detect Quetoo installs + if ( gamedetect_check_game( "quetoo.game", "default/icons/quetoo.png", NULL, buf, p - buf ) ) { return; } @@ -180,7 +188,7 @@ bool portable_app_setup(){ return false; } -#if defined( POSIX ) +#if GDEF_OS_POSIX #include #include @@ -189,7 +197,7 @@ bool portable_app_setup(){ #include const char* LINK_NAME = -#if defined ( __linux__ ) +#if GDEF_OS_LINUX "/proc/self/exe" #else // FreeBSD and OSX "/proc/curproc/file" @@ -197,7 +205,7 @@ const char* LINK_NAME = ; /// brief Returns the filename of the executable belonging to the current process, or 0 if not found. -char* getexename( char *buf ){ +char const* getexename( char *buf ){ /* Now read the symbolic link */ int ret = readlink( LINK_NAME, buf, PATH_MAX ); @@ -225,7 +233,7 @@ char* getexename( char *buf ){ return buf; } -void environment_init( int argc, char* argv[] ){ +void environment_init( int argc, char const* argv[] ){ // Give away unnecessary root privileges. // Important: must be done before calling gtk_init(). char *loginname; @@ -246,14 +254,14 @@ void environment_init( int argc, char* argv[] ){ if ( !portable_app_setup() ) { StringOutputStream home( 256 ); - home << DirectoryCleaned( g_get_home_dir() ) << ".netradiant/"; + home << DirectoryCleaned( g_get_user_config_dir() ) << "netradiant/"; Q_mkdir( home.c_str() ); home_path = home.c_str(); } gamedetect(); } -#elif defined( WIN32 ) +#elif GDEF_OS_WINDOWS #include @@ -269,7 +277,7 @@ void cmdMap(){ } } -void environment_init( int argc, char* argv[] ){ +void environment_init( int argc, char const* argv[] ){ args_init( argc, argv ); { @@ -292,15 +300,7 @@ void environment_init( int argc, char* argv[] ){ 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();