X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=tools%2Fquake3%2Fq3map2%2Fpath_init.c;h=4994c5f5712af05ac4fa3c7e967e97d86ecffaed;hb=e8f94f12dd4cd3eb53b57ecd619db9b3fbe692ff;hp=5369c31240ce8a95ba8d25686a07ad2db64b7fc1;hpb=50e0a3fb240f3fa5377f7a9b32042dbc5d33d650;p=xonotic%2Fnetradiant.git diff --git a/tools/quake3/q3map2/path_init.c b/tools/quake3/q3map2/path_init.c index 5369c312..4994c5f5 100644 --- a/tools/quake3/q3map2/path_init.c +++ b/tools/quake3/q3map2/path_init.c @@ -62,28 +62,15 @@ PathLokiGetHomeDir() gets the user's home dir (for ~/.q3a) */ -#ifdef WIN32 -#include -#endif -char *LokiGetHomeDir( void ) +char *LokiGetHomeDir(void) { #ifndef Q_UNIX - #ifndef WIN32 - return NULL; - #else - static char buf[MAX_OS_PATH]; - TCHAR mydocsdir[MAX_PATH + 1]; - if(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir)) - { - snprintf(buf, "%s/My Games", mydocsdir); - return buf; - } - return NULL; - #endif + return NULL; #else char *home; uid_t id; struct passwd *pwd; + static char homeBuf[MAX_OS_PATH]; /* get the home environment variable */ @@ -103,9 +90,11 @@ char *LokiGetHomeDir( void ) } endpwent(); } + + snprintf(homeBuf, sizeof(homeBuf), "%s/.", home); /* return it */ - return home; + return homeBuf; #endif } @@ -118,31 +107,32 @@ initializes some paths on linux/os x void LokiInitPaths( char *argv0 ) { - #ifndef Q_UNIX - /* this is kinda crap, but hey */ - strcpy( installPath, "../" ); + char *home; + if(!homePath) + { /* get home dir */ home = LokiGetHomeDir(); if( home == NULL ) home = "."; - + /* set home path */ homePath = home; + } + else + home = homePath; + + #ifndef Q_UNIX + /* this is kinda crap, but hey */ + strcpy( installPath, "../" ); #else char temp[ MAX_OS_PATH ]; char last0[ 2 ]; - char *home; char *path; char *last; qboolean found; - /* get home dir */ - home = LokiGetHomeDir(); - if( home == NULL ) - home = "."; - /* do some path divining */ strcpy( temp, argv0 ); if( strrchr( argv0, '/' ) ) @@ -199,9 +189,6 @@ void LokiInitPaths( char *argv0 ) *(strrchr( installPath, '/' )) = '\0'; *(strrchr( installPath, '/' ) + 1) = '\0'; } - - /* set home path */ - homePath = home; #endif } @@ -296,6 +283,7 @@ void AddHomeBasePath( char *path ) { int i; char temp[ MAX_OS_PATH ]; + int homePathLen; if(!homePath) return; @@ -304,20 +292,31 @@ void AddHomeBasePath( char *path ) if( path == NULL || path[ 0 ] == '\0' ) return; - /* concatenate home dir and path */ - sprintf( temp, "%s/%s", homePath, path ); - -#ifdef WIN32 + /* strip leading dot, if homePath does not end in /. */ + homePathLen = strlen(homePath); + if(!strcmp(path, ".")) + { + /* -fs_homebase . means that -fs_home is to be used as is */ + strcpy(temp, homePath); + } + else if(homePathLen >= 2 && !strcmp(homePath + homePathLen - 2, "/.")) { - /* on Win32, we ONLY add it if the directory already exists */ - GDir *dir; - dir = g_dir_open (temp, 0, NULL); - if(!dir) - return; - g_dir_close(dir); + /* remove trailing /. of homePath */ + homePathLen -= 2; + + /* concatenate home dir and path */ + sprintf( temp, "%.*s/%s", homePathLen, homePath, path ); } -#endif + else + { + /* remove leading . of path */ + if(path[0] == '.') + ++path; + /* concatenate home dir and path */ + sprintf( temp, "%s/%s", homePath, path ); + } + /* make a hole */ for( i = (MAX_BASE_PATHS - 2); i >= 0; i-- ) basePaths[ i + 1 ] = basePaths[ i ]; @@ -444,7 +443,17 @@ void InitPaths( int *argc, char **argv ) argv[ i ] = NULL; } - /* -fs_nohomebase */ + /* -fs_home */ + else if( strcmp( argv[ i ], "-fs_home" ) == 0 ) + { + if( ++i >= *argc ) + Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); + argv[ i - 1 ] = NULL; + homePath = argv[i]; + argv[ i ] = NULL; + } + + /* -fs_homebase */ else if( strcmp( argv[ i ], "-fs_homebase" ) == 0 ) { if( ++i >= *argc ) @@ -453,6 +462,17 @@ void InitPaths( int *argc, char **argv ) homeBasePath = argv[i]; argv[ i ] = NULL; } + + /* -fs_homepath - sets both of them */ + else if( strcmp( argv[ i ], "-fs_homepath" ) == 0 ) + { + if( ++i >= *argc ) + Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); + argv[ i - 1 ] = NULL; + homePath = argv[i]; + homeBasePath = "."; + argv[ i ] = NULL; + } } /* remove processed arguments */